]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/mdi.cpp
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "mdi.h"
15 #include "wx/dialog.h"
17 #include "wx/gtk/win_gtk.h"
20 //-----------------------------------------------------------------------------
22 extern wxList wxPendingDelete
;
24 //-----------------------------------------------------------------------------
26 //-----------------------------------------------------------------------------
28 static void gtk_page_size_callback( GtkWidget
*WXUNUSED(widget
), GtkAllocation
* alloc
, wxWindow
*win
)
30 if ((win
->m_x
== alloc
->x
) &&
31 (win
->m_y
== alloc
->y
) &&
32 (win
->m_width
== alloc
->width
) &&
33 (win
->m_height
== alloc
->height
))
38 win
->SetSize( alloc
->x
, alloc
->y
, alloc
->width
, alloc
->height
);
41 // page change callback
42 static void gtk_page_change_callback( GtkNotebook
*WXUNUSED(widget
),
43 GtkNotebookPage
*page
,
45 wxMDIClientWindow
*client_win
)
47 wxNode
*node
= client_win
->m_children
.First();
50 wxMDIChildFrame
*child_frame
= (wxMDIChildFrame
*)node
->Data();
51 if (child_frame
->m_page
== page
)
53 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)client_win
->m_parent
;
54 mdi_frame
->m_currentChild
= child_frame
;
55 mdi_frame
->SetMDIMenuBar( child_frame
->m_menuBar
);
62 //-----------------------------------------------------------------------------
64 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
,wxFrame
)
66 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
69 wxMDIParentFrame::wxMDIParentFrame(void)
71 m_clientWindow
= (wxMDIClientWindow
*) NULL
;
72 m_currentChild
= (wxMDIChildFrame
*) NULL
;
73 m_parentFrameActive
= TRUE
;
76 wxMDIParentFrame::wxMDIParentFrame( wxWindow
*parent
,
77 wxWindowID id
, const wxString
& title
,
78 const wxPoint
& pos
, const wxSize
& size
,
79 long style
, const wxString
& name
)
81 m_clientWindow
= (wxMDIClientWindow
*) NULL
;
82 m_currentChild
= (wxMDIChildFrame
*) NULL
;
83 m_parentFrameActive
= TRUE
;
84 Create( parent
, id
, title
, pos
, size
, style
, name
);
87 wxMDIParentFrame::~wxMDIParentFrame(void)
91 bool wxMDIParentFrame::Create( wxWindow
*parent
,
92 wxWindowID id
, const wxString
& title
,
93 const wxPoint
& pos
, const wxSize
& size
,
94 long style
, const wxString
& name
)
96 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
);
103 void wxMDIParentFrame::GtkOnSize( int x
, int y
, int width
, int height
)
105 wxFrame::GtkOnSize( x
, y
, width
, height
);
111 GetClientSize( &x
, &y
);
112 m_mdiMenuBar
->SetSize( 1, 1, x
-2, 26 );
116 void wxMDIParentFrame::SetMDIMenuBar( wxMenuBar
*menu_bar
)
118 if (m_mdiMenuBar
) m_mdiMenuBar
->Show( FALSE
);
119 m_mdiMenuBar
= menu_bar
;
124 GetClientSize( &x
, &y
);
125 m_mdiMenuBar
->SetSize( 1, 1, x
-2, 26 );
126 m_mdiMenuBar
->Show( TRUE
);
130 void wxMDIParentFrame::GetClientSize(int *width
, int *height
) const
132 wxFrame::GetClientSize( width
, height
);
135 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild(void) const
137 return m_currentChild
;
140 wxMDIClientWindow
*wxMDIParentFrame::GetClientWindow(void) const
142 return m_clientWindow
;
145 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient(void)
147 m_clientWindow
= new wxMDIClientWindow( this );
148 return m_clientWindow
;
151 void wxMDIParentFrame::ActivateNext(void)
154 gtk_notebook_next_page( GTK_NOTEBOOK(m_clientWindow
->m_widget
) );
157 void wxMDIParentFrame::ActivatePrevious(void)
160 gtk_notebook_prev_page( GTK_NOTEBOOK(m_clientWindow
->m_widget
) );
163 void wxMDIParentFrame::OnActivate( wxActivateEvent
& WXUNUSED(event
) )
167 void wxMDIParentFrame::OnSysColourChanged( wxSysColourChangedEvent
& WXUNUSED(event
) )
171 //-----------------------------------------------------------------------------
173 //-----------------------------------------------------------------------------
175 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
,wxFrame
)
177 BEGIN_EVENT_TABLE(wxMDIChildFrame
, wxFrame
)
178 EVT_ACTIVATE(wxMDIChildFrame::OnActivate
)
181 wxMDIChildFrame::wxMDIChildFrame(void)
183 m_menuBar
= (wxMenuBar
*) NULL
;
184 m_page
= (GtkNotebookPage
*) NULL
;
187 wxMDIChildFrame::wxMDIChildFrame( wxMDIParentFrame
*parent
,
188 wxWindowID id
, const wxString
& title
,
189 const wxPoint
& WXUNUSED(pos
), const wxSize
& size
,
190 long style
, const wxString
& name
)
192 m_menuBar
= (wxMenuBar
*) NULL
;
193 m_page
= (GtkNotebookPage
*) NULL
;
194 Create( parent
, id
, title
, wxDefaultPosition
, size
, style
, name
);
197 wxMDIChildFrame::~wxMDIChildFrame(void)
201 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)m_parent
->m_parent
;
202 if (mdi_frame
->m_currentChild
== this)
204 mdi_frame
->SetMDIMenuBar( (wxMenuBar
*) NULL
);
205 mdi_frame
->m_currentChild
= (wxMDIChildFrame
*) NULL
;
211 bool wxMDIChildFrame::Create( wxMDIParentFrame
*parent
,
212 wxWindowID id
, const wxString
& title
,
213 const wxPoint
& WXUNUSED(pos
), const wxSize
& size
,
214 long style
, const wxString
& name
)
217 return wxWindow::Create( parent
->GetClientWindow(), id
, wxDefaultPosition
, size
, style
, name
);
220 void wxMDIChildFrame::GetClientSize( int *width
, int *height
) const
222 wxWindow::GetClientSize( width
, height
);
225 void wxMDIChildFrame::AddChild( wxWindow
*child
)
227 wxWindow::AddChild( child
);
230 static void SetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
232 menu
->SetInvokingWindow( win
);
233 wxNode
*node
= menu
->m_items
.First();
236 wxMenuItem
*menuitem
= (wxMenuItem
*)node
->Data();
237 if (menuitem
->IsSubMenu())
238 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
243 void wxMDIChildFrame::SetMenuBar( wxMenuBar
*menu_bar
)
245 m_menuBar
= menu_bar
;
249 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)m_parent
->m_parent
;
251 if (m_menuBar
->m_parent
!= this)
253 wxNode
*node
= m_menuBar
->m_menus
.First();
256 wxMenu
*menu
= (wxMenu
*)node
->Data();
257 SetInvokingWindow( menu
, this );
261 m_menuBar
->m_parent
= mdi_frame
;
263 mdi_frame
->SetMDIMenuBar( m_menuBar
);
265 gtk_myfixed_put( GTK_MYFIXED(mdi_frame
->m_mainWindow
),
266 m_menuBar
->m_widget
, m_menuBar
->m_x
, m_menuBar
->m_y
);
270 wxMenuBar
*wxMDIChildFrame::GetMenuBar()
275 void wxMDIChildFrame::Activate(void)
279 void wxMDIChildFrame::OnActivate( wxActivateEvent
&WXUNUSED(event
) )
283 //-----------------------------------------------------------------------------
285 //-----------------------------------------------------------------------------
287 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
,wxWindow
)
289 wxMDIClientWindow::wxMDIClientWindow(void)
293 wxMDIClientWindow::wxMDIClientWindow( wxMDIParentFrame
*parent
, long style
)
295 CreateClient( parent
, style
);
298 wxMDIClientWindow::~wxMDIClientWindow(void)
302 bool wxMDIClientWindow::CreateClient( wxMDIParentFrame
*parent
, long style
)
306 PreCreation( parent
, -1, wxPoint(10,10), wxSize(100,100), style
, "wxMDIClientWindow" );
308 m_widget
= gtk_notebook_new();
310 gtk_signal_connect( GTK_OBJECT(m_widget
), "switch_page",
311 GTK_SIGNAL_FUNC(gtk_page_change_callback
), (gpointer
)this );
313 gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget
), 1 );
322 void wxMDIClientWindow::AddChild( wxWindow
*child
)
324 if (!child
->IsKindOf(CLASSINFO(wxMDIChildFrame
)))
326 wxFAIL_MSG("wxNotebook::AddChild: Child has to be wxMDIChildFrame");
330 m_children
.Append( child
);
333 wxMDIChildFrame
* mdi_child
= (wxMDIChildFrame
*) child
;
334 s
= mdi_child
->m_title
;
335 if (s
.IsNull()) s
= _("MDI child");
337 GtkWidget
*label_widget
;
338 label_widget
= gtk_label_new( s
);
339 gtk_misc_set_alignment( GTK_MISC(label_widget
), 0.0, 0.5 );
341 gtk_signal_connect( GTK_OBJECT(child
->m_widget
), "size_allocate",
342 GTK_SIGNAL_FUNC(gtk_page_size_callback
), (gpointer
)child
);
344 gtk_notebook_append_page( GTK_NOTEBOOK(m_widget
), child
->m_widget
, label_widget
);
346 mdi_child
->m_page
= (GtkNotebookPage
*) (g_list_last(GTK_NOTEBOOK(m_widget
)->children
)->data
);
348 gtk_notebook_set_page( GTK_NOTEBOOK(m_widget
), m_children
.Number()-1 );
350 gtk_page_change_callback( (GtkNotebook
*) NULL
, mdi_child
->m_page
, 0, this );