]>
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"
22 #include "wx/gtk/win_gtk.h"
24 //-----------------------------------------------------------------------------
26 //-----------------------------------------------------------------------------
28 const int wxMENU_HEIGHT
= 27;
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
34 extern wxList wxPendingDelete
;
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
40 static void gtk_page_size_callback( GtkWidget
*WXUNUSED(widget
), GtkAllocation
* alloc
, wxWindow
*win
)
42 if ((win
->m_x
== alloc
->x
) &&
43 (win
->m_y
== alloc
->y
) &&
44 (win
->m_width
== alloc
->width
) &&
45 (win
->m_height
== alloc
->height
) &&
51 win
->SetSize( alloc
->x
, alloc
->y
, alloc
->width
, alloc
->height
);
54 //-----------------------------------------------------------------------------
56 //-----------------------------------------------------------------------------
58 static void gtk_page_change_callback( GtkNotebook
*WXUNUSED(widget
),
59 GtkNotebookPage
*page
,
61 wxMDIClientWindow
*client_win
)
63 wxNode
*node
= client_win
->m_children
.First();
66 wxMDIChildFrame
*child_frame
= (wxMDIChildFrame
*)node
->Data();
67 if (child_frame
->m_page
== page
)
69 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)client_win
->m_parent
;
70 mdi_frame
->m_currentChild
= child_frame
;
71 mdi_frame
->SetMDIMenuBar( child_frame
->m_menuBar
);
78 //-----------------------------------------------------------------------------
80 //-----------------------------------------------------------------------------
82 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
,wxFrame
)
84 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
87 wxMDIParentFrame::wxMDIParentFrame(void)
89 m_clientWindow
= (wxMDIClientWindow
*) NULL
;
90 m_currentChild
= (wxMDIChildFrame
*) NULL
;
91 m_parentFrameActive
= TRUE
;
94 wxMDIParentFrame::wxMDIParentFrame( wxWindow
*parent
,
95 wxWindowID id
, const wxString
& title
,
96 const wxPoint
& pos
, const wxSize
& size
,
97 long style
, const wxString
& name
)
99 m_clientWindow
= (wxMDIClientWindow
*) NULL
;
100 m_currentChild
= (wxMDIChildFrame
*) NULL
;
101 m_parentFrameActive
= TRUE
;
102 Create( parent
, id
, title
, pos
, size
, style
, name
);
105 wxMDIParentFrame::~wxMDIParentFrame(void)
109 bool wxMDIParentFrame::Create( wxWindow
*parent
,
110 wxWindowID id
, const wxString
& title
,
111 const wxPoint
& pos
, const wxSize
& size
,
112 long style
, const wxString
& name
)
114 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
);
121 void wxMDIParentFrame::GtkOnSize( int x
, int y
, int width
, int height
)
123 wxFrame::GtkOnSize( x
, y
, width
, height
);
127 m_mdiMenuBar
->m_x
= 0;
128 m_mdiMenuBar
->m_y
= 0;
129 m_mdiMenuBar
->m_width
= m_width
;
130 m_mdiMenuBar
->m_height
= wxMENU_HEIGHT
;
131 gtk_myfixed_move( GTK_MYFIXED(m_wxwindow
), m_mdiMenuBar
->m_widget
, 0, 0 );
132 gtk_widget_set_usize( m_mdiMenuBar
->m_widget
, m_width
, wxMENU_HEIGHT
);
136 void wxMDIParentFrame::SetMDIMenuBar( wxMenuBar
*menu_bar
)
138 /* hide old child menu bar */
139 if (m_mdiMenuBar
) m_mdiMenuBar
->Show( FALSE
);
141 m_mdiMenuBar
= menu_bar
;
143 /* show and resize new menu child menu bar */
146 m_mdiMenuBar
->m_x
= 0;
147 m_mdiMenuBar
->m_y
= 0;
148 m_mdiMenuBar
->m_width
= m_width
;
149 m_mdiMenuBar
->m_height
= wxMENU_HEIGHT
;
150 gtk_myfixed_move( GTK_MYFIXED(m_wxwindow
), m_mdiMenuBar
->m_widget
, 0, 0 );
151 gtk_widget_set_usize( m_mdiMenuBar
->m_widget
, m_width
, wxMENU_HEIGHT
);
152 m_mdiMenuBar
->Show( TRUE
);
155 /* show/hide parent menu bar as required */
156 if (m_frameMenuBar
) m_frameMenuBar
->Show( (m_mdiMenuBar
== NULL
) );
159 void wxMDIParentFrame::GetClientSize(int *width
, int *height
) const
161 wxFrame::GetClientSize( width
, height
);
164 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild(void) const
166 return m_currentChild
;
169 wxMDIClientWindow
*wxMDIParentFrame::GetClientWindow(void) const
171 return m_clientWindow
;
174 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient(void)
176 m_clientWindow
= new wxMDIClientWindow( this );
177 return m_clientWindow
;
180 void wxMDIParentFrame::ActivateNext(void)
183 gtk_notebook_next_page( GTK_NOTEBOOK(m_clientWindow
->m_widget
) );
186 void wxMDIParentFrame::ActivatePrevious(void)
189 gtk_notebook_prev_page( GTK_NOTEBOOK(m_clientWindow
->m_widget
) );
192 void wxMDIParentFrame::OnActivate( wxActivateEvent
& WXUNUSED(event
) )
196 void wxMDIParentFrame::OnSysColourChanged( wxSysColourChangedEvent
& WXUNUSED(event
) )
200 //-----------------------------------------------------------------------------
202 //-----------------------------------------------------------------------------
204 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
,wxFrame
)
206 BEGIN_EVENT_TABLE(wxMDIChildFrame
, wxFrame
)
207 EVT_ACTIVATE(wxMDIChildFrame::OnActivate
)
210 wxMDIChildFrame::wxMDIChildFrame(void)
212 m_menuBar
= (wxMenuBar
*) NULL
;
213 m_page
= (GtkNotebookPage
*) NULL
;
216 wxMDIChildFrame::wxMDIChildFrame( wxMDIParentFrame
*parent
,
217 wxWindowID id
, const wxString
& title
,
218 const wxPoint
& WXUNUSED(pos
), const wxSize
& size
,
219 long style
, const wxString
& name
)
221 m_menuBar
= (wxMenuBar
*) NULL
;
222 m_page
= (GtkNotebookPage
*) NULL
;
223 Create( parent
, id
, title
, wxDefaultPosition
, size
, style
, name
);
226 wxMDIChildFrame::~wxMDIChildFrame(void)
230 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)m_parent
->m_parent
;
231 if (mdi_frame
->m_currentChild
== this)
233 mdi_frame
->SetMDIMenuBar( (wxMenuBar
*) NULL
);
234 mdi_frame
->m_currentChild
= (wxMDIChildFrame
*) NULL
;
240 bool wxMDIChildFrame::Create( wxMDIParentFrame
*parent
,
241 wxWindowID id
, const wxString
& title
,
242 const wxPoint
& WXUNUSED(pos
), const wxSize
& size
,
243 long style
, const wxString
& name
)
247 return wxWindow::Create( parent
->GetClientWindow(), id
, wxDefaultPosition
, size
, style
, name
);
250 void wxMDIChildFrame::GetClientSize( int *width
, int *height
) const
252 wxWindow::GetClientSize( width
, height
);
255 void wxMDIChildFrame::AddChild( wxWindow
*child
)
257 wxWindow::AddChild( child
);
260 static void SetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
262 menu
->SetInvokingWindow( win
);
263 wxNode
*node
= menu
->m_items
.First();
266 wxMenuItem
*menuitem
= (wxMenuItem
*)node
->Data();
267 if (menuitem
->IsSubMenu())
268 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
273 void wxMDIChildFrame::SetMenuBar( wxMenuBar
*menu_bar
)
275 m_menuBar
= menu_bar
;
279 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)m_parent
->m_parent
;
281 if (m_menuBar
->m_parent
!= this)
283 wxNode
*node
= m_menuBar
->m_menus
.First();
286 wxMenu
*menu
= (wxMenu
*)node
->Data();
287 SetInvokingWindow( menu
, this );
291 m_menuBar
->m_parent
= mdi_frame
;
294 gtk_myfixed_put( GTK_MYFIXED(mdi_frame
->m_wxwindow
),
295 m_menuBar
->m_widget
, m_menuBar
->m_x
, m_menuBar
->m_y
);
297 mdi_frame
->SetMDIMenuBar( m_menuBar
);
301 wxMenuBar
*wxMDIChildFrame::GetMenuBar() const
306 void wxMDIChildFrame::Activate(void)
310 void wxMDIChildFrame::OnActivate( wxActivateEvent
&WXUNUSED(event
) )
314 //-----------------------------------------------------------------------------
315 // InsertChild callback for wxMDIClientWindow
316 //-----------------------------------------------------------------------------
318 static void wxInsertChildInMDI( wxMDIClientWindow
* parent
, wxMDIChildFrame
* child
)
320 wxString s
= child
->m_title
;
321 if (s
.IsNull()) s
= _("MDI child");
323 GtkWidget
*label_widget
= gtk_label_new( s
);
324 gtk_misc_set_alignment( GTK_MISC(label_widget
), 0.0, 0.5 );
326 gtk_signal_connect( GTK_OBJECT(child
->m_widget
), "size_allocate",
327 GTK_SIGNAL_FUNC(gtk_page_size_callback
), (gpointer
)child
);
329 GtkNotebook
*notebook
= GTK_NOTEBOOK(parent
->m_widget
);
331 gtk_notebook_append_page( notebook
, child
->m_widget
, label_widget
);
333 child
->m_page
= (GtkNotebookPage
*) (g_list_last(notebook
->children
)->data
);
335 gtk_notebook_set_page( notebook
, parent
->m_children
.Number()-1 );
337 gtk_page_change_callback( (GtkNotebook
*) NULL
, child
->m_page
, 0, parent
);
340 //-----------------------------------------------------------------------------
342 //-----------------------------------------------------------------------------
344 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
,wxWindow
)
346 wxMDIClientWindow::wxMDIClientWindow(void)
350 wxMDIClientWindow::wxMDIClientWindow( wxMDIParentFrame
*parent
, long style
)
352 CreateClient( parent
, style
);
355 wxMDIClientWindow::~wxMDIClientWindow(void)
359 bool wxMDIClientWindow::CreateClient( wxMDIParentFrame
*parent
, long style
)
363 m_insertCallback
= (wxInsertChildFunction
)wxInsertChildInMDI
;
365 PreCreation( parent
, -1, wxPoint(10,10), wxSize(100,100), style
, "wxMDIClientWindow" );
367 m_widget
= gtk_notebook_new();
369 gtk_signal_connect( GTK_OBJECT(m_widget
), "switch_page",
370 GTK_SIGNAL_FUNC(gtk_page_change_callback
), (gpointer
)this );
372 gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget
), 1 );
374 m_parent
->AddChild( this );
376 (m_parent
->m_insertCallback
)( m_parent
, this );