(svn r8991) [cpp_gui] -Codechange: composite widgets (incl. windows) now must implement CreateWidgets() method which is called from the default OnCreate() implementation cpp_gui
authorKUDr
Sat, 03 Mar 2007 11:20:46 +0000
branchcpp_gui
changeset 6279 c75b2c7222ff
parent 6278 c09f5e53af9b
child 6280 57f6156a327d
(svn r8991) [cpp_gui] -Codechange: composite widgets (incl. windows) now must implement CreateWidgets() method which is called from the default OnCreate() implementation
src/intro_gui.cpp
src/widget/widget.h
src/widget/widget_caption.cpp
src/widget/widget_composite.cpp
src/window.cpp
src/window.h
--- a/src/intro_gui.cpp	Sat Mar 03 02:47:45 2007 +0000
+++ b/src/intro_gui.cpp	Sat Mar 03 11:20:46 2007 +0000
@@ -168,7 +168,7 @@
 	{
 	}
 
-	/*virtual*/ void OnCreate(gui::EvtCreate &e)
+	/*virtual*/ void CreateWidgets()
 	{
 		/* set common window properties */
 		SetTopLeft(Point16(140, 40));
@@ -192,8 +192,6 @@
 		/* connect control callbacks */
 		m_button1->AddReflectHandlerT(&WindowT::Button1_OnClick);
 //		m_button1->AddOnClickHandlerT(&WindowT::Button1_OnClick);
-
-		super::OnCreate(e);
 	}
 
 	void Button1_OnClick(gui::EvtClick &e)
--- a/src/widget/widget.h	Sat Mar 03 02:47:45 2007 +0000
+++ b/src/widget/widget.h	Sat Mar 03 11:20:46 2007 +0000
@@ -195,6 +195,7 @@
 
 	/*virtual*/ Widget* WidgetFromPt(const Point16 &pt);
 
+	virtual void CreateWidgets() = 0;
 	virtual void Close();
 
 	/*virtual*/ void OnCreate(EvtCreate &ev);
@@ -301,6 +302,7 @@
 		, m_text_color(text_color)
 	{}
 
+	/*virtual*/ void CreateWidgets();
 	/*virtual*/ void DrawBackground(EvtPaint &ev);
 
 	/*virtual*/ void OnCreate(EvtCreate &ev);
--- a/src/widget/widget_caption.cpp	Sat Mar 03 02:47:45 2007 +0000
+++ b/src/widget/widget_caption.cpp	Sat Mar 03 11:20:46 2007 +0000
@@ -20,6 +20,11 @@
 
 namespace gui {
 
+/*virtual*/ void CaptionBar::CreateWidgets()
+{
+
+}
+
 /*virtual*/ void CaptionBar::DrawBackground(EvtPaint &ev)
 {
 	BaseWindow *w = GetWindow();
--- a/src/widget/widget_composite.cpp	Sat Mar 03 02:47:45 2007 +0000
+++ b/src/widget/widget_composite.cpp	Sat Mar 03 11:20:46 2007 +0000
@@ -83,7 +83,10 @@
 
 /*virtual*/ void CompositeWidget::OnCreate(EvtCreate &ev)
 {
-	/* notify all children */
+	/* this is composite widget - it should create its own children */
+	CreateWidgets();
+
+	/* notify all children that we are creating */
 	for (WidgetIterator it_next = m_widgets.begin(); it_next != m_widgets.end(); ) {
 		/* save the iterator (it can be invalidated) and move forward */
 		WidgetIterator it = it_next++;
@@ -92,6 +95,7 @@
 		/* tell him we are creating window */
 		wd_child->OnCreate(ev);
 	}
+
 	super::OnCreate(ev);
 }
 
--- a/src/window.cpp	Sat Mar 03 02:47:45 2007 +0000
+++ b/src/window.cpp	Sat Mar 03 11:20:46 2007 +0000
@@ -226,13 +226,18 @@
 	window_number = num;
 	flash_timeout = 3; // just opened windows have a white border
 	caption_color = 0xFF;
+	wndproc = &BaseWindow::DefaultWndProc;
 
 	/* add our new window into z-order list */
 	BaseWindow::s_list.Add(this);
-	wndproc = &BaseWindow::DefaultWndProc;
+
+	/* Finalize the creation process */
+	CallEventNP(WE_CREATE);
+
+	/* window should have some widgets now */
+	assert(widget != NULL || m_widgets.size() > 0);
 
 	SetDirty();
-	CallEventNP(WE_CREATE);
 	return true;
 }
 
@@ -256,11 +261,19 @@
 	/* add our new window into z-order list */
 	BaseWindow::s_list.Add(this);
 
+	/* Finalize the creation process */
+	CallEventNP(WE_CREATE);
+
 	SetDirty();
-	CallEventNP(WE_CREATE);
 	return true;
 }
 
+/*virtual*/ void BaseWindow::CreateWidgets()
+{
+	/* only old windows are allowed to use this fake 'CreateWidgets()' method << new gui must have its own */
+	assert(widget != NULL);
+}
+
 /**
 * Open a new window. If there is no space for a new window, close an open
 * window. Try to avoid stickied windows, but if there is no else, close one of
--- a/src/window.h	Sat Mar 03 02:47:45 2007 +0000
+++ b/src/window.h	Sat Mar 03 11:20:46 2007 +0000
@@ -450,6 +450,8 @@
 	virtual bool Create(WindowNumber num);
 	virtual bool Create(const WindowDesc *desc, WindowNumber num = 0);
 
+	/*virtual*/ void CreateWidgets(); ///< @TODO remove it when old gui infrastructure will no longer be used
+
 	static BaseWindow* Allocate(int x, int y, int width, int height, WindowProc *proc, WindowClass cls, const OldWidget *widget);
 	static BaseWindow* Allocate(const WindowDesc *desc, int window_number = 0);
 	static BaseWindow* AllocateFront(const WindowDesc *desc, int window_number = 0);