]>
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 //-----------------------------------------------------------------------------
24 const int wxMENU_HEIGHT
= 30;
26 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
30 extern wxList wxPendingDelete
;
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
36 static void gtk_page_size_callback( GtkWidget
*WXUNUSED(widget
), GtkAllocation
* alloc
, wxWindow
*win
)
38 if ((win
->m_x
== alloc
->x
) &&
39 (win
->m_y
== alloc
->y
) &&
40 (win
->m_width
== alloc
->width
) &&
41 (win
->m_height
== alloc
->height
))
46 win
->SetSize( alloc
->x
, alloc
->y
, alloc
->width
, alloc
->height
);
49 //-----------------------------------------------------------------------------
50 // page change callback
51 //-----------------------------------------------------------------------------
53 static void gtk_page_change_callback( GtkNotebook
*WXUNUSED(widget
),
54 GtkNotebookPage
*page
,
56 wxMDIClientWindow
*client_win
)
58 wxNode
*node
= client_win
->m_children
.First();
61 wxMDIChildFrame
*child_frame
= (wxMDIChildFrame
*)node
->Data();
62 if (child_frame
->m_page
== page
)
64 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)client_win
->m_parent
;
65 mdi_frame
->m_currentChild
= child_frame
;
66 mdi_frame
->SetMDIMenuBar( child_frame
->m_menuBar
);
73 //-----------------------------------------------------------------------------
75 //-----------------------------------------------------------------------------
77 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
,wxFrame
)
79 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
82 wxMDIParentFrame::wxMDIParentFrame(void)
84 m_clientWindow
= (wxMDIClientWindow
*) NULL
;
85 m_currentChild
= (wxMDIChildFrame
*) NULL
;
86 m_parentFrameActive
= TRUE
;
89 wxMDIParentFrame::wxMDIParentFrame( wxWindow
*parent
,
90 wxWindowID id
, const wxString
& title
,
91 const wxPoint
& pos
, const wxSize
& size
,
92 long style
, const wxString
& name
)
94 m_clientWindow
= (wxMDIClientWindow
*) NULL
;
95 m_currentChild
= (wxMDIChildFrame
*) NULL
;
96 m_parentFrameActive
= TRUE
;
97 Create( parent
, id
, title
, pos
, size
, style
, name
);
100 wxMDIParentFrame::~wxMDIParentFrame(void)
104 bool wxMDIParentFrame::Create( wxWindow
*parent
,
105 wxWindowID id
, const wxString
& title
,
106 const wxPoint
& pos
, const wxSize
& size
,
107 long style
, const wxString
& name
)
109 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
);
116 void wxMDIParentFrame::GtkOnSize( int x
, int y
, int width
, int height
)
118 wxFrame::GtkOnSize( x
, y
, width
, height
);
122 m_mdiMenuBar
->m_x
= 1;
123 m_mdiMenuBar
->m_y
= 1;
124 m_mdiMenuBar
->m_width
= m_width
-2;
125 m_mdiMenuBar
->m_height
= wxMENU_HEIGHT
-2;
126 gtk_myfixed_move( GTK_MYFIXED(m_wxwindow
), m_mdiMenuBar
->m_widget
, 1, 1 );
127 gtk_widget_set_usize( m_mdiMenuBar
->m_widget
, m_width
-2, wxMENU_HEIGHT
-2 );
131 void wxMDIParentFrame::SetMDIMenuBar( wxMenuBar
*menu_bar
)
133 if (m_mdiMenuBar
) m_mdiMenuBar
->Show( FALSE
);
134 m_mdiMenuBar
= menu_bar
;
137 m_mdiMenuBar
->m_x
= 1;
138 m_mdiMenuBar
->m_y
= 1;
139 m_mdiMenuBar
->m_width
= m_width
-2;
140 m_mdiMenuBar
->m_height
= wxMENU_HEIGHT
-2;
141 gtk_myfixed_move( GTK_MYFIXED(m_wxwindow
), m_mdiMenuBar
->m_widget
, 1, 1 );
142 gtk_widget_set_usize( m_mdiMenuBar
->m_widget
, m_width
-2, wxMENU_HEIGHT
-2 );
143 m_mdiMenuBar
->Show( TRUE
);
147 void wxMDIParentFrame::GetClientSize(int *width
, int *height
) const
149 wxFrame::GetClientSize( width
, height
);
152 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild(void) const
154 return m_currentChild
;
157 wxMDIClientWindow
*wxMDIParentFrame::GetClientWindow(void) const
159 return m_clientWindow
;
162 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient(void)
164 m_clientWindow
= new wxMDIClientWindow( this );
165 return m_clientWindow
;
168 void wxMDIParentFrame::ActivateNext(void)
171 gtk_notebook_next_page( GTK_NOTEBOOK(m_clientWindow
->m_widget
) );
174 void wxMDIParentFrame::ActivatePrevious(void)
177 gtk_notebook_prev_page( GTK_NOTEBOOK(m_clientWindow
->m_widget
) );
180 void wxMDIParentFrame::OnActivate( wxActivateEvent
& WXUNUSED(event
) )
184 void wxMDIParentFrame::OnSysColourChanged( wxSysColourChangedEvent
& WXUNUSED(event
) )
188 //-----------------------------------------------------------------------------
190 //-----------------------------------------------------------------------------
192 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
,wxFrame
)
194 BEGIN_EVENT_TABLE(wxMDIChildFrame
, wxFrame
)
195 EVT_ACTIVATE(wxMDIChildFrame::OnActivate
)
198 wxMDIChildFrame::wxMDIChildFrame(void)
200 m_menuBar
= (wxMenuBar
*) NULL
;
201 m_page
= (GtkNotebookPage
*) NULL
;
204 wxMDIChildFrame::wxMDIChildFrame( wxMDIParentFrame
*parent
,
205 wxWindowID id
, const wxString
& title
,
206 const wxPoint
& WXUNUSED(pos
), const wxSize
& size
,
207 long style
, const wxString
& name
)
209 m_menuBar
= (wxMenuBar
*) NULL
;
210 m_page
= (GtkNotebookPage
*) NULL
;
211 Create( parent
, id
, title
, wxDefaultPosition
, size
, style
, name
);
214 wxMDIChildFrame::~wxMDIChildFrame(void)
218 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)m_parent
->m_parent
;
219 if (mdi_frame
->m_currentChild
== this)
221 mdi_frame
->SetMDIMenuBar( (wxMenuBar
*) NULL
);
222 mdi_frame
->m_currentChild
= (wxMDIChildFrame
*) NULL
;
228 bool wxMDIChildFrame::Create( wxMDIParentFrame
*parent
,
229 wxWindowID id
, const wxString
& title
,
230 const wxPoint
& WXUNUSED(pos
), const wxSize
& size
,
231 long style
, const wxString
& name
)
235 return wxWindow::Create( parent
->GetClientWindow(), id
, wxDefaultPosition
, size
, style
, name
);
238 void wxMDIChildFrame::GetClientSize( int *width
, int *height
) const
240 wxWindow::GetClientSize( width
, height
);
243 void wxMDIChildFrame::AddChild( wxWindow
*child
)
245 wxWindow::AddChild( child
);
248 static void SetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
250 menu
->SetInvokingWindow( win
);
251 wxNode
*node
= menu
->m_items
.First();
254 wxMenuItem
*menuitem
= (wxMenuItem
*)node
->Data();
255 if (menuitem
->IsSubMenu())
256 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
261 void wxMDIChildFrame::SetMenuBar( wxMenuBar
*menu_bar
)
263 m_menuBar
= menu_bar
;
267 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)m_parent
->m_parent
;
269 if (m_menuBar
->m_parent
!= this)
271 wxNode
*node
= m_menuBar
->m_menus
.First();
274 wxMenu
*menu
= (wxMenu
*)node
->Data();
275 SetInvokingWindow( menu
, this );
279 m_menuBar
->m_parent
= mdi_frame
;
281 mdi_frame
->SetMDIMenuBar( m_menuBar
);
283 gtk_myfixed_put( GTK_MYFIXED(mdi_frame
->m_wxwindow
),
284 m_menuBar
->m_widget
, m_menuBar
->m_x
, m_menuBar
->m_y
);
288 wxMenuBar
*wxMDIChildFrame::GetMenuBar()
293 void wxMDIChildFrame::Activate(void)
297 void wxMDIChildFrame::OnActivate( wxActivateEvent
&WXUNUSED(event
) )
301 //-----------------------------------------------------------------------------
302 // InsertChild callback for wxMDIClientWindow
303 //-----------------------------------------------------------------------------
305 static void wxInsertChildInMDI( wxMDIClientWindow
* parent
, wxMDIChildFrame
* child
)
307 wxString s
= child
->m_title
;
308 if (s
.IsNull()) s
= _("MDI child");
310 GtkWidget
*label_widget
= gtk_label_new( s
);
311 gtk_misc_set_alignment( GTK_MISC(label_widget
), 0.0, 0.5 );
313 gtk_signal_connect( GTK_OBJECT(child
->m_widget
), "size_allocate",
314 GTK_SIGNAL_FUNC(gtk_page_size_callback
), (gpointer
)child
);
316 GtkNotebook
*notebook
= GTK_NOTEBOOK(parent
->m_widget
);
318 gtk_notebook_append_page( notebook
, child
->m_widget
, label_widget
);
320 child
->m_page
= (GtkNotebookPage
*) (g_list_last(notebook
->children
)->data
);
322 gtk_notebook_set_page( notebook
, parent
->m_children
.Number()-1 );
324 gtk_page_change_callback( (GtkNotebook
*) NULL
, child
->m_page
, 0, parent
);
327 //-----------------------------------------------------------------------------
329 //-----------------------------------------------------------------------------
331 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
,wxWindow
)
333 wxMDIClientWindow::wxMDIClientWindow(void)
337 wxMDIClientWindow::wxMDIClientWindow( wxMDIParentFrame
*parent
, long style
)
339 CreateClient( parent
, style
);
342 wxMDIClientWindow::~wxMDIClientWindow(void)
346 bool wxMDIClientWindow::CreateClient( wxMDIParentFrame
*parent
, long style
)
350 m_insertCallback
= (wxInsertChildFunction
)wxInsertChildInMDI
;
352 PreCreation( parent
, -1, wxPoint(10,10), wxSize(100,100), style
, "wxMDIClientWindow" );
354 m_widget
= gtk_notebook_new();
356 gtk_signal_connect( GTK_OBJECT(m_widget
), "switch_page",
357 GTK_SIGNAL_FUNC(gtk_page_change_callback
), (gpointer
)this );
359 gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget
), 1 );
361 m_parent
->AddChild( this );
363 (m_parent
->m_insertCallback
)( m_parent
, this );