]>
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/dialog.h"
18 #include "wx/gtk/win_gtk.h"
21 //-----------------------------------------------------------------------------
23 extern wxList wxPendingDelete
;
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29 static void gtk_page_size_callback( GtkWidget
*WXUNUSED(widget
), GtkAllocation
* alloc
, wxWindow
*win
)
31 if ((win
->m_x
== alloc
->x
) &&
32 (win
->m_y
== alloc
->y
) &&
33 (win
->m_width
== alloc
->width
) &&
34 (win
->m_height
== alloc
->height
))
39 win
->SetSize( alloc
->x
, alloc
->y
, alloc
->width
, alloc
->height
);
42 // page change callback
43 static void gtk_page_change_callback( GtkNotebook
*WXUNUSED(widget
),
44 GtkNotebookPage
*page
,
46 wxMDIClientWindow
*client_win
)
48 wxNode
*node
= client_win
->m_children
.First();
51 wxMDIChildFrame
*child_frame
= (wxMDIChildFrame
*)node
->Data();
52 if (child_frame
->m_page
== page
)
54 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)client_win
->m_parent
;
55 mdi_frame
->m_currentChild
= child_frame
;
56 mdi_frame
->SetMDIMenuBar( child_frame
->m_menuBar
);
63 //-----------------------------------------------------------------------------
65 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
,wxFrame
)
67 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
70 wxMDIParentFrame::wxMDIParentFrame(void)
72 m_clientWindow
= (wxMDIClientWindow
*) NULL
;
73 m_currentChild
= (wxMDIChildFrame
*) NULL
;
74 m_parentFrameActive
= TRUE
;
77 wxMDIParentFrame::wxMDIParentFrame( wxWindow
*parent
,
78 wxWindowID id
, const wxString
& title
,
79 const wxPoint
& pos
, const wxSize
& size
,
80 long style
, const wxString
& name
)
82 m_clientWindow
= (wxMDIClientWindow
*) NULL
;
83 m_currentChild
= (wxMDIChildFrame
*) NULL
;
84 m_parentFrameActive
= TRUE
;
85 Create( parent
, id
, title
, pos
, size
, style
, name
);
88 wxMDIParentFrame::~wxMDIParentFrame(void)
92 bool wxMDIParentFrame::Create( wxWindow
*parent
,
93 wxWindowID id
, const wxString
& title
,
94 const wxPoint
& pos
, const wxSize
& size
,
95 long style
, const wxString
& name
)
97 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
);
104 void wxMDIParentFrame::GtkOnSize( int x
, int y
, int width
, int height
)
106 wxFrame::GtkOnSize( x
, y
, width
, height
);
112 GetClientSize( &x
, &y
);
113 m_mdiMenuBar
->SetSize( 1, 1, x
-2, 26 );
117 void wxMDIParentFrame::SetMDIMenuBar( wxMenuBar
*menu_bar
)
119 if (m_mdiMenuBar
) m_mdiMenuBar
->Show( FALSE
);
120 m_mdiMenuBar
= menu_bar
;
125 GetClientSize( &x
, &y
);
126 m_mdiMenuBar
->SetSize( 1, 1, x
-2, 26 );
127 m_mdiMenuBar
->Show( TRUE
);
131 void wxMDIParentFrame::GetClientSize(int *width
, int *height
) const
133 wxFrame::GetClientSize( width
, height
);
136 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild(void) const
138 return m_currentChild
;
141 wxMDIClientWindow
*wxMDIParentFrame::GetClientWindow(void) const
143 return m_clientWindow
;
146 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient(void)
148 m_clientWindow
= new wxMDIClientWindow( this );
149 return m_clientWindow
;
152 void wxMDIParentFrame::ActivateNext(void)
155 gtk_notebook_next_page( GTK_NOTEBOOK(m_clientWindow
->m_widget
) );
158 void wxMDIParentFrame::ActivatePrevious(void)
161 gtk_notebook_prev_page( GTK_NOTEBOOK(m_clientWindow
->m_widget
) );
164 void wxMDIParentFrame::OnActivate( wxActivateEvent
& WXUNUSED(event
) )
168 void wxMDIParentFrame::OnSysColourChanged( wxSysColourChangedEvent
& WXUNUSED(event
) )
172 //-----------------------------------------------------------------------------
174 //-----------------------------------------------------------------------------
176 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
,wxFrame
)
178 BEGIN_EVENT_TABLE(wxMDIChildFrame
, wxFrame
)
179 EVT_ACTIVATE(wxMDIChildFrame::OnActivate
)
182 wxMDIChildFrame::wxMDIChildFrame(void)
184 m_menuBar
= (wxMenuBar
*) NULL
;
185 m_page
= (GtkNotebookPage
*) NULL
;
188 wxMDIChildFrame::wxMDIChildFrame( wxMDIParentFrame
*parent
,
189 wxWindowID id
, const wxString
& title
,
190 const wxPoint
& WXUNUSED(pos
), const wxSize
& size
,
191 long style
, const wxString
& name
)
193 m_menuBar
= (wxMenuBar
*) NULL
;
194 m_page
= (GtkNotebookPage
*) NULL
;
195 Create( parent
, id
, title
, wxDefaultPosition
, size
, style
, name
);
198 wxMDIChildFrame::~wxMDIChildFrame(void)
202 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)m_parent
->m_parent
;
203 if (mdi_frame
->m_currentChild
== this)
205 mdi_frame
->SetMDIMenuBar( (wxMenuBar
*) NULL
);
206 mdi_frame
->m_currentChild
= (wxMDIChildFrame
*) NULL
;
212 bool wxMDIChildFrame::Create( wxMDIParentFrame
*parent
,
213 wxWindowID id
, const wxString
& title
,
214 const wxPoint
& WXUNUSED(pos
), const wxSize
& size
,
215 long style
, const wxString
& name
)
218 return wxWindow::Create( parent
->GetClientWindow(), id
, wxDefaultPosition
, size
, style
, name
);
221 void wxMDIChildFrame::GetClientSize( int *width
, int *height
) const
223 wxWindow::GetClientSize( width
, height
);
226 void wxMDIChildFrame::AddChild( wxWindow
*child
)
228 wxWindow::AddChild( child
);
231 static void SetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
233 menu
->SetInvokingWindow( win
);
234 wxNode
*node
= menu
->m_items
.First();
237 wxMenuItem
*menuitem
= (wxMenuItem
*)node
->Data();
238 if (menuitem
->IsSubMenu())
239 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
244 void wxMDIChildFrame::SetMenuBar( wxMenuBar
*menu_bar
)
246 m_menuBar
= menu_bar
;
250 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)m_parent
->m_parent
;
252 if (m_menuBar
->m_parent
!= this)
254 wxNode
*node
= m_menuBar
->m_menus
.First();
257 wxMenu
*menu
= (wxMenu
*)node
->Data();
258 SetInvokingWindow( menu
, this );
262 m_menuBar
->m_parent
= mdi_frame
;
264 mdi_frame
->SetMDIMenuBar( m_menuBar
);
266 gtk_myfixed_put( GTK_MYFIXED(mdi_frame
->m_mainWindow
),
267 m_menuBar
->m_widget
, m_menuBar
->m_x
, m_menuBar
->m_y
);
271 wxMenuBar
*wxMDIChildFrame::GetMenuBar()
276 void wxMDIChildFrame::Activate(void)
280 void wxMDIChildFrame::OnActivate( wxActivateEvent
&WXUNUSED(event
) )
284 //-----------------------------------------------------------------------------
286 //-----------------------------------------------------------------------------
288 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
,wxWindow
)
290 wxMDIClientWindow::wxMDIClientWindow(void)
294 wxMDIClientWindow::wxMDIClientWindow( wxMDIParentFrame
*parent
, long style
)
296 CreateClient( parent
, style
);
299 wxMDIClientWindow::~wxMDIClientWindow(void)
303 bool wxMDIClientWindow::CreateClient( wxMDIParentFrame
*parent
, long style
)
307 PreCreation( parent
, -1, wxPoint(10,10), wxSize(100,100), style
, "wxMDIClientWindow" );
309 m_widget
= gtk_notebook_new();
311 gtk_signal_connect( GTK_OBJECT(m_widget
), "switch_page",
312 GTK_SIGNAL_FUNC(gtk_page_change_callback
), (gpointer
)this );
314 gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget
), 1 );
323 void wxMDIClientWindow::AddChild( wxWindow
*child
)
325 if (!child
->IsKindOf(CLASSINFO(wxMDIChildFrame
)))
327 wxFAIL_MSG("wxNotebook::AddChild: Child has to be wxMDIChildFrame");
331 m_children
.Append( child
);
334 wxMDIChildFrame
* mdi_child
= (wxMDIChildFrame
*) child
;
335 s
= mdi_child
->m_title
;
336 if (s
.IsNull()) s
= _("MDI child");
338 GtkWidget
*label_widget
;
339 label_widget
= gtk_label_new( s
);
340 gtk_misc_set_alignment( GTK_MISC(label_widget
), 0.0, 0.5 );
342 gtk_signal_connect( GTK_OBJECT(child
->m_widget
), "size_allocate",
343 GTK_SIGNAL_FUNC(gtk_page_size_callback
), (gpointer
)child
);
345 gtk_notebook_append_page( GTK_NOTEBOOK(m_widget
), child
->m_widget
, label_widget
);
347 mdi_child
->m_page
= (GtkNotebookPage
*) (g_list_last(GTK_NOTEBOOK(m_widget
)->children
)->data
);
349 gtk_notebook_set_page( GTK_NOTEBOOK(m_widget
), m_children
.Number()-1 );
351 gtk_page_change_callback( (GtkNotebook
*) NULL
, mdi_child
->m_page
, 0, this );