]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/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
;
74 wxMDIParentFrame::wxMDIParentFrame( wxWindow
*parent
,
75 wxWindowID id
, const wxString
& title
,
76 const wxPoint
& pos
, const wxSize
& size
,
77 long style
, const wxString
& name
)
79 m_clientWindow
= NULL
;
80 m_currentChild
= NULL
;
81 m_parentFrameActive
= TRUE
;
82 Create( parent
, id
, title
, pos
, size
, style
, name
);
85 wxMDIParentFrame::~wxMDIParentFrame(void)
89 bool wxMDIParentFrame::Create( wxWindow
*parent
,
90 wxWindowID id
, const wxString
& title
,
91 const wxPoint
& pos
, const wxSize
& size
,
92 long style
, const wxString
& name
)
94 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
);
101 void wxMDIParentFrame::GtkOnSize( int x
, int y
, int width
, int height
)
103 wxFrame::GtkOnSize( x
, y
, width
, height
);
109 GetClientSize( &x
, &y
);
110 m_mdiMenuBar
->SetSize( 1, 1, x
-2, 26 );
114 void wxMDIParentFrame::SetMDIMenuBar( wxMenuBar
*menu_bar
)
116 if (m_mdiMenuBar
) m_mdiMenuBar
->Show( FALSE
);
117 m_mdiMenuBar
= menu_bar
;
122 GetClientSize( &x
, &y
);
123 m_mdiMenuBar
->SetSize( 1, 1, x
-2, 26 );
124 m_mdiMenuBar
->Show( TRUE
);
128 void wxMDIParentFrame::GetClientSize(int *width
, int *height
) const
130 wxFrame::GetClientSize( width
, height
);
133 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild(void) const
135 return m_currentChild
;
138 wxMDIClientWindow
*wxMDIParentFrame::GetClientWindow(void) const
140 return m_clientWindow
;
143 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient(void)
145 m_clientWindow
= new wxMDIClientWindow( this );
146 return m_clientWindow
;
149 void wxMDIParentFrame::ActivateNext(void)
152 gtk_notebook_next_page( GTK_NOTEBOOK(m_clientWindow
->m_widget
) );
155 void wxMDIParentFrame::ActivatePrevious(void)
158 gtk_notebook_prev_page( GTK_NOTEBOOK(m_clientWindow
->m_widget
) );
161 void wxMDIParentFrame::OnActivate( wxActivateEvent
& WXUNUSED(event
) )
165 void wxMDIParentFrame::OnSysColourChanged( wxSysColourChangedEvent
& WXUNUSED(event
) )
169 //-----------------------------------------------------------------------------
171 //-----------------------------------------------------------------------------
173 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
,wxPanel
)
175 BEGIN_EVENT_TABLE(wxMDIChildFrame
, wxPanel
)
176 EVT_CLOSE(wxMDIChildFrame::OnCloseWindow
)
179 wxMDIChildFrame::wxMDIChildFrame(void)
185 wxMDIChildFrame::wxMDIChildFrame( wxMDIParentFrame
*parent
,
186 wxWindowID id
, const wxString
& title
,
187 const wxPoint
& WXUNUSED(pos
), const wxSize
& size
,
188 long style
, const wxString
& name
)
192 Create( parent
, id
, title
, wxDefaultPosition
, size
, style
, name
);
195 wxMDIChildFrame::~wxMDIChildFrame(void)
199 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)m_parent
->m_parent
;
200 if (mdi_frame
->m_currentChild
== this)
202 mdi_frame
->SetMDIMenuBar( NULL
);
203 mdi_frame
->m_currentChild
= NULL
;
209 bool wxMDIChildFrame::Create( wxMDIParentFrame
*parent
,
210 wxWindowID id
, const wxString
& title
,
211 const wxPoint
& WXUNUSED(pos
), const wxSize
& size
,
212 long style
, const wxString
& name
)
215 return wxPanel::Create( parent
->GetClientWindow(), id
, wxDefaultPosition
, size
, style
, name
);
218 void wxMDIChildFrame::OnCloseWindow( wxCloseEvent
&event
)
220 if ( GetEventHandler()->OnClose() || event
.GetForce())
226 bool wxMDIChildFrame::Destroy(void)
228 if (!wxPendingDelete
.Member(this))
229 wxPendingDelete
.Append(this);
234 static void SetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
236 menu
->SetInvokingWindow( win
);
237 wxNode
*node
= menu
->m_items
.First();
240 wxMenuItem
*menuitem
= (wxMenuItem
*)node
->Data();
241 if (menuitem
->IsSubMenu())
242 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
247 void wxMDIChildFrame::SetMenuBar( wxMenuBar
*menu_bar
)
249 m_menuBar
= menu_bar
;
253 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)m_parent
->m_parent
;
255 if (m_menuBar
->m_parent
!= this)
257 wxNode
*node
= m_menuBar
->m_menus
.First();
260 wxMenu
*menu
= (wxMenu
*)node
->Data();
261 SetInvokingWindow( menu
, this );
265 m_menuBar
->m_parent
= mdi_frame
;
267 mdi_frame
->SetMDIMenuBar( m_menuBar
);
269 gtk_myfixed_put( GTK_MYFIXED(mdi_frame
->m_mainWindow
),
270 m_menuBar
->m_widget
, m_menuBar
->m_x
, m_menuBar
->m_y
);
274 void wxMDIChildFrame::Activate(void)
278 //-----------------------------------------------------------------------------
280 //-----------------------------------------------------------------------------
282 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
,wxWindow
)
284 wxMDIClientWindow::wxMDIClientWindow(void)
288 wxMDIClientWindow::wxMDIClientWindow( wxMDIParentFrame
*parent
, long style
)
290 CreateClient( parent
, style
);
293 wxMDIClientWindow::~wxMDIClientWindow(void)
297 bool wxMDIClientWindow::CreateClient( wxMDIParentFrame
*parent
, long style
)
301 PreCreation( parent
, -1, wxPoint(10,10), wxSize(100,100), style
, "wxMDIClientWindow" );
303 m_widget
= gtk_notebook_new();
305 gtk_signal_connect( GTK_OBJECT(m_widget
), "switch_page",
306 GTK_SIGNAL_FUNC(gtk_page_change_callback
), (gpointer
)this );
308 gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget
), 1 );
317 void wxMDIClientWindow::AddChild( wxWindow
*child
)
319 if (!child
->IsKindOf(CLASSINFO(wxMDIChildFrame
)))
321 wxFAIL_MSG("wxNotebook::AddChild: Child has to be wxMDIChildFrame");
325 m_children
.Append( child
);
328 wxMDIChildFrame
* mdi_child
= (wxMDIChildFrame
*) child
;
329 s
= mdi_child
->m_title
;
330 if (s
.IsNull()) s
= "MDI child";
332 GtkWidget
*label_widget
;
333 label_widget
= gtk_label_new( s
);
334 gtk_misc_set_alignment( GTK_MISC(label_widget
), 0.0, 0.5 );
336 gtk_signal_connect( GTK_OBJECT(child
->m_widget
), "size_allocate",
337 GTK_SIGNAL_FUNC(gtk_page_size_callback
), (gpointer
)child
);
339 gtk_notebook_append_page( GTK_NOTEBOOK(m_widget
), child
->m_widget
, label_widget
);
341 mdi_child
->m_page
= (GtkNotebookPage
*) (g_list_last(GTK_NOTEBOOK(m_widget
)->children
)->data
);
343 gtk_notebook_set_page( GTK_NOTEBOOK(m_widget
), m_children
.Number()-1 );