]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/mdi.cpp
4428a9edad71f9bd890e41dde5e36727643059f4
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/dialog.h"
17 #include "wx/gtk/win_gtk.h"
19 //-----------------------------------------------------------------------------
21 extern wxList wxPendingDelete
;
23 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
27 static void gtk_page_size_callback( GtkWidget
*WXUNUSED(widget
), GtkAllocation
* alloc
, wxWindow
*win
)
29 if ((win
->m_x
== alloc
->x
) &&
30 (win
->m_y
== alloc
->y
) &&
31 (win
->m_width
== alloc
->width
) &&
32 (win
->m_height
== alloc
->height
))
37 win
->SetSize( alloc
->x
, alloc
->y
, alloc
->width
, alloc
->height
);
40 // page change callback
41 static void gtk_page_change_callback( GtkNotebook
*WXUNUSED(widget
),
42 GtkNotebookPage
*page
,
44 wxMDIClientWindow
*client_win
)
46 wxNode
*node
= client_win
->m_children
.First();
49 wxMDIChildFrame
*child_frame
= (wxMDIChildFrame
*)node
->Data();
50 if (child_frame
->m_page
== page
)
52 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)client_win
->m_parent
;
53 mdi_frame
->m_currentChild
= child_frame
;
54 mdi_frame
->SetMDIMenuBar( child_frame
->m_menuBar
);
61 //-----------------------------------------------------------------------------
63 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
,wxFrame
)
65 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
68 wxMDIParentFrame::wxMDIParentFrame(void)
70 m_clientWindow
= NULL
;
71 m_currentChild
= NULL
;
72 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
;
83 Create( parent
, id
, title
, pos
, size
, style
, name
);
86 wxMDIParentFrame::~wxMDIParentFrame(void)
90 bool wxMDIParentFrame::Create( wxWindow
*parent
,
91 wxWindowID id
, const wxString
& title
,
92 const wxPoint
& pos
, const wxSize
& size
,
93 long style
, const wxString
& name
)
95 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
);
102 void wxMDIParentFrame::GtkOnSize( int x
, int y
, int width
, int height
)
104 wxFrame::GtkOnSize( x
, y
, width
, height
);
110 GetClientSize( &x
, &y
);
111 m_mdiMenuBar
->SetSize( 1, 1, x
-2, 26 );
115 void wxMDIParentFrame::SetMDIMenuBar( wxMenuBar
*menu_bar
)
117 if (m_mdiMenuBar
) m_mdiMenuBar
->Show( FALSE
);
118 m_mdiMenuBar
= menu_bar
;
123 GetClientSize( &x
, &y
);
124 m_mdiMenuBar
->SetSize( 1, 1, x
-2, 26 );
125 m_mdiMenuBar
->Show( TRUE
);
129 void wxMDIParentFrame::GetClientSize(int *width
, int *height
) const
131 wxFrame::GetClientSize( width
, height
);
134 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild(void) const
136 return m_currentChild
;
139 wxMDIClientWindow
*wxMDIParentFrame::GetClientWindow(void) const
141 return m_clientWindow
;
144 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient(void)
146 m_clientWindow
= new wxMDIClientWindow( this );
147 return m_clientWindow
;
150 void wxMDIParentFrame::ActivateNext(void)
153 gtk_notebook_next_page( GTK_NOTEBOOK(m_clientWindow
->m_widget
) );
156 void wxMDIParentFrame::ActivatePrevious(void)
159 gtk_notebook_prev_page( GTK_NOTEBOOK(m_clientWindow
->m_widget
) );
162 void wxMDIParentFrame::OnActivate( wxActivateEvent
& WXUNUSED(event
) )
166 void wxMDIParentFrame::OnSysColourChanged( wxSysColourChangedEvent
& WXUNUSED(event
) )
170 //-----------------------------------------------------------------------------
172 //-----------------------------------------------------------------------------
174 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
,wxPanel
)
176 BEGIN_EVENT_TABLE(wxMDIChildFrame
, wxPanel
)
177 EVT_CLOSE(wxMDIChildFrame::OnCloseWindow
)
178 EVT_SIZE(wxMDIChildFrame::OnSize
)
181 wxMDIChildFrame::wxMDIChildFrame(void)
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
)
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( NULL
);
205 mdi_frame
->m_currentChild
= 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 wxPanel::Create( parent
->GetClientWindow(), id
, wxDefaultPosition
, size
, style
, name
);
220 void wxMDIChildFrame::OnCloseWindow( wxCloseEvent
&event
)
222 if ( GetEventHandler()->OnClose() || event
.GetForce())
228 void wxMDIChildFrame::OnSize( wxSizeEvent
&WXUNUSED(event
) )
230 if ( GetAutoLayout() )
233 // no child: go out !
234 if (!GetChildren()->First())
237 // do we have exactly one child?
238 wxWindow
*child
= NULL
;
239 for(wxNode
*node
= GetChildren()->First(); node
; node
= node
->Next())
241 wxWindow
*win
= (wxWindow
*)node
->Data();
242 if (!IS_KIND_OF(win
,wxFrame
) && !IS_KIND_OF(win
,wxDialog
))
244 if ( child
) // it's the second one: do nothing
251 // yes: set it's size to fill all the frame
252 int client_x
, client_y
;
253 GetClientSize(&client_x
, &client_y
);
254 child
->SetSize( 1, 1, client_x
-2, client_y
);
257 bool wxMDIChildFrame::Destroy(void)
259 if (!wxPendingDelete
.Member(this))
260 wxPendingDelete
.Append(this);
265 static void SetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
267 menu
->SetInvokingWindow( win
);
268 wxNode
*node
= menu
->m_items
.First();
271 wxMenuItem
*menuitem
= (wxMenuItem
*)node
->Data();
272 if (menuitem
->IsSubMenu())
273 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
278 void wxMDIChildFrame::SetMenuBar( wxMenuBar
*menu_bar
)
280 m_menuBar
= menu_bar
;
284 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)m_parent
->m_parent
;
286 if (m_menuBar
->m_parent
!= this)
288 wxNode
*node
= m_menuBar
->m_menus
.First();
291 wxMenu
*menu
= (wxMenu
*)node
->Data();
292 SetInvokingWindow( menu
, this );
296 m_menuBar
->m_parent
= mdi_frame
;
298 mdi_frame
->SetMDIMenuBar( m_menuBar
);
300 gtk_myfixed_put( GTK_MYFIXED(mdi_frame
->m_mainWindow
),
301 m_menuBar
->m_widget
, m_menuBar
->m_x
, m_menuBar
->m_y
);
305 void wxMDIChildFrame::Activate(void)
309 //-----------------------------------------------------------------------------
311 //-----------------------------------------------------------------------------
313 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
,wxWindow
)
315 wxMDIClientWindow::wxMDIClientWindow(void)
319 wxMDIClientWindow::wxMDIClientWindow( wxMDIParentFrame
*parent
, long style
)
321 CreateClient( parent
, style
);
324 wxMDIClientWindow::~wxMDIClientWindow(void)
328 bool wxMDIClientWindow::CreateClient( wxMDIParentFrame
*parent
, long style
)
332 PreCreation( parent
, -1, wxPoint(10,10), wxSize(100,100), style
, "wxMDIClientWindow" );
334 m_widget
= gtk_notebook_new();
336 gtk_signal_connect( GTK_OBJECT(m_widget
), "switch_page",
337 GTK_SIGNAL_FUNC(gtk_page_change_callback
), (gpointer
)this );
339 gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget
), 1 );
348 void wxMDIClientWindow::AddChild( wxWindow
*child
)
350 if (!child
->IsKindOf(CLASSINFO(wxMDIChildFrame
)))
352 wxFAIL_MSG("wxNotebook::AddChild: Child has to be wxMDIChildFrame");
356 m_children
.Append( child
);
359 wxMDIChildFrame
* mdi_child
= (wxMDIChildFrame
*) child
;
360 s
= mdi_child
->m_title
;
361 if (s
.IsNull()) s
= "MDI child";
363 GtkWidget
*label_widget
;
364 label_widget
= gtk_label_new( s
);
365 gtk_misc_set_alignment( GTK_MISC(label_widget
), 0.0, 0.5 );
367 gtk_signal_connect( GTK_OBJECT(child
->m_widget
), "size_allocate",
368 GTK_SIGNAL_FUNC(gtk_page_size_callback
), (gpointer
)child
);
370 gtk_notebook_append_page( GTK_NOTEBOOK(m_widget
), child
->m_widget
, label_widget
);
372 mdi_child
->m_page
= (GtkNotebookPage
*) (g_list_last(GTK_NOTEBOOK(m_widget
)->children
)->data
);
374 gtk_notebook_set_page( GTK_NOTEBOOK(m_widget
), m_children
.Number()-1 );