]>
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 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
,wxFrame
)
42 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
45 wxMDIParentFrame::wxMDIParentFrame()
47 m_justInserted
= FALSE
;
48 m_clientWindow
= (wxMDIClientWindow
*) NULL
;
51 wxMDIParentFrame::wxMDIParentFrame( wxWindow
*parent
,
52 wxWindowID id
, const wxString
& title
,
53 const wxPoint
& pos
, const wxSize
& size
,
54 long style
, const wxString
& name
)
56 m_justInserted
= FALSE
;
57 m_clientWindow
= (wxMDIClientWindow
*) NULL
;
58 Create( parent
, id
, title
, pos
, size
, style
, name
);
61 wxMDIParentFrame::~wxMDIParentFrame()
65 bool wxMDIParentFrame::Create( wxWindow
*parent
,
66 wxWindowID id
, const wxString
& title
,
67 const wxPoint
& pos
, const wxSize
& size
,
68 long style
, const wxString
& name
)
70 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
);
77 void wxMDIParentFrame::GtkOnSize( int x
, int y
, int width
, int height
)
79 wxFrame::GtkOnSize( x
, y
, width
, height
);
81 wxMDIChildFrame
*child_frame
= GetActiveChild();
82 if (!child_frame
) return;
84 wxMenuBar
*menu_bar
= child_frame
->m_menuBar
;
85 if (!menu_bar
) return;
86 if (!menu_bar
->m_widget
) return;
90 menu_bar
->m_width
= m_width
;
91 menu_bar
->m_height
= wxMENU_HEIGHT
;
92 gtk_myfixed_move( GTK_MYFIXED(m_mainWidget
), menu_bar
->m_widget
, 0, 0 );
93 gtk_widget_set_usize( menu_bar
->m_widget
, m_width
, wxMENU_HEIGHT
);
96 void wxMDIParentFrame::OnInternalIdle()
98 /* if a an MDI child window has just been inserted
99 it has to be brought to the top in idle time. we
100 simply set the last notebook page active as new
101 pages can only be appended at the end */
105 GtkNotebook
*notebook
= GTK_NOTEBOOK(m_clientWindow
->m_widget
);
106 gtk_notebook_set_page( notebook
, g_list_length( notebook
->children
) - 1 );
108 m_justInserted
= FALSE
;
112 wxFrame::OnInternalIdle();
114 wxMDIChildFrame
*active_child_frame
= GetActiveChild();
116 wxNode
*node
= m_clientWindow
->m_children
.First();
119 wxMDIChildFrame
*child_frame
= (wxMDIChildFrame
*)node
->Data();
120 if (child_frame
->m_menuBar
)
122 if (child_frame
== active_child_frame
)
123 gtk_widget_show( child_frame
->m_menuBar
->m_widget
);
125 gtk_widget_hide( child_frame
->m_menuBar
->m_widget
);
130 /* show/hide parent menu bar as required */
131 if (m_frameMenuBar
) m_frameMenuBar
->Show( (active_child_frame
== NULL
) );
134 void wxMDIParentFrame::GetClientSize(int *width
, int *height
) const
136 wxFrame::GetClientSize( width
, height
);
139 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
141 if (!m_clientWindow
) return (wxMDIChildFrame
*) NULL
;
143 GtkNotebook
*notebook
= GTK_NOTEBOOK(m_clientWindow
->m_widget
);
144 if (!notebook
) return (wxMDIChildFrame
*) NULL
;
146 #if (GTK_MINOR_VERSION > 0)
147 gint i
= gtk_notebook_get_current_page( notebook
);
149 gint i
= gtk_notebook_current_page( notebook
);
151 if (i
< 0) return (wxMDIChildFrame
*) NULL
;
153 GtkNotebookPage
* page
= (GtkNotebookPage
*) (g_list_nth(notebook
->children
,i
)->data
);
154 if (!page
) return (wxMDIChildFrame
*) NULL
;
156 wxNode
*node
= m_clientWindow
->m_children
.First();
159 wxMDIChildFrame
*child_frame
= (wxMDIChildFrame
*)node
->Data();
160 if (child_frame
->m_page
== page
)
165 return (wxMDIChildFrame
*) NULL
;
168 wxMDIClientWindow
*wxMDIParentFrame::GetClientWindow() const
170 return m_clientWindow
;
173 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
175 m_clientWindow
= new wxMDIClientWindow( this );
176 return m_clientWindow
;
179 void wxMDIParentFrame::ActivateNext()
182 gtk_notebook_next_page( GTK_NOTEBOOK(m_clientWindow
->m_widget
) );
185 void wxMDIParentFrame::ActivatePrevious()
188 gtk_notebook_prev_page( GTK_NOTEBOOK(m_clientWindow
->m_widget
) );
191 void wxMDIParentFrame::OnActivate( wxActivateEvent
& WXUNUSED(event
) )
195 void wxMDIParentFrame::OnSysColourChanged( wxSysColourChangedEvent
& WXUNUSED(event
) )
199 //-----------------------------------------------------------------------------
201 //-----------------------------------------------------------------------------
203 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
,wxFrame
)
205 BEGIN_EVENT_TABLE(wxMDIChildFrame
, wxFrame
)
206 EVT_ACTIVATE(wxMDIChildFrame::OnActivate
)
209 wxMDIChildFrame::wxMDIChildFrame()
211 m_menuBar
= (wxMenuBar
*) NULL
;
212 m_page
= (GtkNotebookPage
*) NULL
;
215 wxMDIChildFrame::wxMDIChildFrame( wxMDIParentFrame
*parent
,
216 wxWindowID id
, const wxString
& title
,
217 const wxPoint
& WXUNUSED(pos
), const wxSize
& size
,
218 long style
, const wxString
& name
)
220 m_menuBar
= (wxMenuBar
*) NULL
;
221 m_page
= (GtkNotebookPage
*) NULL
;
222 Create( parent
, id
, title
, wxDefaultPosition
, size
, style
, name
);
225 wxMDIChildFrame::~wxMDIChildFrame()
231 bool wxMDIChildFrame::Create( wxMDIParentFrame
*parent
,
232 wxWindowID id
, const wxString
& title
,
233 const wxPoint
& WXUNUSED(pos
), const wxSize
& size
,
234 long style
, const wxString
& name
)
238 return wxWindow::Create( parent
->GetClientWindow(), id
, wxDefaultPosition
, size
, style
, name
);
241 void wxMDIChildFrame::GetClientSize( int *width
, int *height
) const
243 wxWindow::GetClientSize( width
, height
);
246 void wxMDIChildFrame::AddChild( wxWindow
*child
)
248 wxWindow::AddChild( child
);
251 static void SetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
253 menu
->SetInvokingWindow( win
);
254 wxNode
*node
= menu
->GetItems().First();
257 wxMenuItem
*menuitem
= (wxMenuItem
*)node
->Data();
258 if (menuitem
->IsSubMenu())
259 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
264 void wxMDIChildFrame::SetMenuBar( wxMenuBar
*menu_bar
)
266 m_menuBar
= menu_bar
;
270 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)m_parent
->m_parent
;
272 if (m_menuBar
->m_parent
!= this)
274 wxNode
*node
= m_menuBar
->GetMenus().First();
277 wxMenu
*menu
= (wxMenu
*)node
->Data();
278 SetInvokingWindow( menu
, this );
282 m_menuBar
->m_parent
= mdi_frame
;
285 /* the menu bar of the child window is shown in idle time as needed */
286 gtk_widget_hide( m_menuBar
->m_widget
);
288 /* insert the invisible menu bar into the _parent_ mdi frame */
289 gtk_myfixed_put( GTK_MYFIXED(mdi_frame
->m_mainWidget
), m_menuBar
->m_widget
, 0, 0 );
290 gtk_widget_set_usize( menu_bar
->m_widget
, mdi_frame
->m_width
, wxMENU_HEIGHT
);
294 wxMenuBar
*wxMDIChildFrame::GetMenuBar() const
299 void wxMDIChildFrame::Activate()
303 void wxMDIChildFrame::OnActivate( wxActivateEvent
&WXUNUSED(event
) )
307 //-----------------------------------------------------------------------------
309 //-----------------------------------------------------------------------------
311 static void gtk_page_size_callback( GtkWidget
*WXUNUSED(widget
), GtkAllocation
* alloc
, wxWindow
*win
)
313 if ((win
->m_x
== alloc
->x
) &&
314 (win
->m_y
== alloc
->y
) &&
315 (win
->m_width
== alloc
->width
) &&
316 (win
->m_height
== alloc
->height
) &&
322 win
->SetSize( alloc
->x
, alloc
->y
, alloc
->width
, alloc
->height
);
325 //-----------------------------------------------------------------------------
326 // InsertChild callback for wxMDIClientWindow
327 //-----------------------------------------------------------------------------
329 static void wxInsertChildInMDI( wxMDIClientWindow
* parent
, wxMDIChildFrame
* child
)
331 wxString s
= child
->m_title
;
332 if (s
.IsNull()) s
= _("MDI child");
334 GtkWidget
*label_widget
= gtk_label_new( s
);
335 gtk_misc_set_alignment( GTK_MISC(label_widget
), 0.0, 0.5 );
337 gtk_signal_connect( GTK_OBJECT(child
->m_widget
), "size_allocate",
338 GTK_SIGNAL_FUNC(gtk_page_size_callback
), (gpointer
)child
);
340 GtkNotebook
*notebook
= GTK_NOTEBOOK(parent
->m_widget
);
342 gtk_notebook_append_page( notebook
, child
->m_widget
, label_widget
);
344 child
->m_page
= (GtkNotebookPage
*) (g_list_last(notebook
->children
)->data
);
346 wxMDIParentFrame
*parent_frame
= (wxMDIParentFrame
*) parent
->m_parent
;
347 parent_frame
->m_justInserted
= TRUE
;
350 //-----------------------------------------------------------------------------
352 //-----------------------------------------------------------------------------
354 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
,wxWindow
)
356 wxMDIClientWindow::wxMDIClientWindow()
360 wxMDIClientWindow::wxMDIClientWindow( wxMDIParentFrame
*parent
, long style
)
362 CreateClient( parent
, style
);
365 wxMDIClientWindow::~wxMDIClientWindow()
369 bool wxMDIClientWindow::CreateClient( wxMDIParentFrame
*parent
, long style
)
373 m_insertCallback
= (wxInsertChildFunction
)wxInsertChildInMDI
;
375 PreCreation( parent
, -1, wxPoint(10,10), wxSize(100,100), style
, "wxMDIClientWindow" );
377 m_widget
= gtk_notebook_new();
379 gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget
), 1 );
381 m_parent
->AddChild( this );
383 (m_parent
->m_insertCallback
)( m_parent
, this );