]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/mdi.cpp
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "mdi.h"
16 #include "wx/gtk/win_gtk.h"
18 //-----------------------------------------------------------------------------
20 extern wxList wxPendingDelete
;
22 //-----------------------------------------------------------------------------
24 //-----------------------------------------------------------------------------
26 static void gtk_page_size_callback( GtkWidget
*WXUNUSED(widget
), GtkAllocation
* alloc
, wxWindow
*win
)
28 if ((win
->m_x
== alloc
->x
) &&
29 (win
->m_y
== alloc
->y
) &&
30 (win
->m_width
== alloc
->width
) &&
31 (win
->m_height
== alloc
->height
))
36 win
->SetSize( alloc
->x
, alloc
->y
, alloc
->width
, alloc
->height
);
39 // page change callback
40 static void gtk_page_change_callback( GtkNotebook
*WXUNUSED(widget
),
41 GtkNotebookPage
*page
,
43 wxMDIClientWindow
*client_win
)
45 wxNode
*node
= client_win
->m_children
.First();
48 wxMDIChildFrame
*child_frame
= (wxMDIChildFrame
*)node
->Data();
49 if (child_frame
->m_page
== page
)
51 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)client_win
->m_parent
;
52 mdi_frame
->m_currentChild
= child_frame
;
53 mdi_frame
->SetMDIMenuBar( child_frame
->m_menuBar
);
60 //-----------------------------------------------------------------------------
62 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
,wxFrame
)
64 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
67 wxMDIParentFrame::wxMDIParentFrame(void)
69 m_clientWindow
= NULL
;
70 m_currentChild
= NULL
;
71 m_parentFrameActive
= TRUE
;
75 wxMDIParentFrame::wxMDIParentFrame( wxWindow
*parent
,
76 wxWindowID id
, const wxString
& title
,
77 const wxPoint
& pos
, const wxSize
& size
,
78 long style
, const wxString
& name
)
80 m_clientWindow
= NULL
;
81 m_currentChild
= NULL
;
82 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 void wxMDIParentFrame::SetToolBar( wxToolBar
*toolbar
)
140 wxWindow
*wxMDIParentFrame::GetToolBar(void) const
145 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild(void) const
147 return m_currentChild
;
150 wxMDIClientWindow
*wxMDIParentFrame::GetClientWindow(void) const
152 return m_clientWindow
;
155 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient(void)
157 m_clientWindow
= new wxMDIClientWindow( this );
158 return m_clientWindow
;
161 void wxMDIParentFrame::ActivateNext(void)
164 gtk_notebook_next_page( GTK_NOTEBOOK(m_clientWindow
->m_widget
) );
167 void wxMDIParentFrame::ActivatePrevious(void)
170 gtk_notebook_prev_page( GTK_NOTEBOOK(m_clientWindow
->m_widget
) );
173 void wxMDIParentFrame::OnActivate( wxActivateEvent
& WXUNUSED(event
) )
177 void wxMDIParentFrame::OnSysColourChanged( wxSysColourChangedEvent
& WXUNUSED(event
) )
181 //-----------------------------------------------------------------------------
183 //-----------------------------------------------------------------------------
185 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
,wxPanel
)
187 BEGIN_EVENT_TABLE(wxMDIChildFrame
, wxPanel
)
188 EVT_CLOSE(wxMDIChildFrame::OnCloseWindow
)
191 wxMDIChildFrame::wxMDIChildFrame(void)
197 wxMDIChildFrame::wxMDIChildFrame( wxMDIParentFrame
*parent
,
198 wxWindowID id
, const wxString
& title
,
199 const wxPoint
& WXUNUSED(pos
), const wxSize
& size
,
200 long style
, const wxString
& name
)
204 Create( parent
, id
, title
, wxDefaultPosition
, size
, style
, name
);
207 wxMDIChildFrame::~wxMDIChildFrame(void)
211 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)m_parent
->m_parent
;
212 if (mdi_frame
->m_currentChild
== this)
214 mdi_frame
->SetMDIMenuBar( NULL
);
215 mdi_frame
->m_currentChild
= NULL
;
221 bool wxMDIChildFrame::Create( wxMDIParentFrame
*parent
,
222 wxWindowID id
, const wxString
& title
,
223 const wxPoint
& WXUNUSED(pos
), const wxSize
& size
,
224 long style
, const wxString
& name
)
227 return wxPanel::Create( parent
->GetClientWindow(), id
, wxDefaultPosition
, size
, style
, name
);
230 void wxMDIChildFrame::OnCloseWindow( wxCloseEvent
&event
)
232 if ( GetEventHandler()->OnClose() || event
.GetForce())
238 bool wxMDIChildFrame::Destroy(void)
240 if (!wxPendingDelete
.Member(this))
241 wxPendingDelete
.Append(this);
246 static void SetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
248 menu
->SetInvokingWindow( win
);
249 wxNode
*node
= menu
->m_items
.First();
252 wxMenuItem
*menuitem
= (wxMenuItem
*)node
->Data();
253 if (menuitem
->m_isSubMenu
) SetInvokingWindow( menuitem
->m_subMenu
, win
);
258 void wxMDIChildFrame::SetMenuBar( wxMenuBar
*menu_bar
)
260 m_menuBar
= menu_bar
;
264 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)m_parent
->m_parent
;
266 if (m_menuBar
->m_parent
!= this)
268 wxNode
*node
= m_menuBar
->m_menus
.First();
271 wxMenu
*menu
= (wxMenu
*)node
->Data();
272 SetInvokingWindow( menu
, this );
276 m_menuBar
->m_parent
= mdi_frame
;
278 mdi_frame
->SetMDIMenuBar( m_menuBar
);
280 gtk_myfixed_put( GTK_MYFIXED(mdi_frame
->m_mainWindow
),
281 m_menuBar
->m_widget
, m_menuBar
->m_x
, m_menuBar
->m_y
);
285 void wxMDIChildFrame::Activate(void)
289 //-----------------------------------------------------------------------------
291 //-----------------------------------------------------------------------------
293 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
,wxWindow
)
295 wxMDIClientWindow::wxMDIClientWindow(void)
299 wxMDIClientWindow::wxMDIClientWindow( wxMDIParentFrame
*parent
, long style
)
301 CreateClient( parent
, style
);
304 wxMDIClientWindow::~wxMDIClientWindow(void)
308 bool wxMDIClientWindow::CreateClient( wxMDIParentFrame
*parent
, long style
)
312 PreCreation( parent
, -1, wxPoint(10,10), wxSize(100,100), style
, "wxMDIClientWindow" );
314 m_widget
= gtk_notebook_new();
316 gtk_signal_connect( GTK_OBJECT(m_widget
), "switch_page",
317 GTK_SIGNAL_FUNC(gtk_page_change_callback
), (gpointer
)this );
319 gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget
), 1 );
328 void wxMDIClientWindow::AddChild( wxWindow
*child
)
330 if (!child
->IsKindOf(CLASSINFO(wxMDIChildFrame
)))
332 wxFAIL_MSG("wxNotebook::AddChild: Child has to be wxMDIChildFrame");
336 m_children
.Append( child
);
339 wxMDIChildFrame
* mdi_child
= (wxMDIChildFrame
*) child
;
340 s
= mdi_child
->m_title
;
341 if (s
.IsNull()) s
= "MDI child";
343 GtkWidget
*label_widget
;
344 label_widget
= gtk_label_new( s
);
345 gtk_misc_set_alignment( GTK_MISC(label_widget
), 0.0, 0.5 );
347 gtk_signal_connect( GTK_OBJECT(child
->m_widget
), "size_allocate",
348 GTK_SIGNAL_FUNC(gtk_page_size_callback
), (gpointer
)child
);
350 gtk_notebook_append_page( GTK_NOTEBOOK(m_widget
), child
->m_widget
, label_widget
);
352 mdi_child
->m_page
= (GtkNotebookPage
*) (g_list_last(GTK_NOTEBOOK(m_widget
)->children
)->data
);
354 gtk_notebook_set_page( GTK_NOTEBOOK(m_widget
), m_children
.Number()-1 );