]>
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();
115 bool visible_child_menu
= FALSE
;
117 wxNode
*node
= m_clientWindow
->m_children
.First();
120 wxMDIChildFrame
*child_frame
= (wxMDIChildFrame
*)node
->Data();
121 if (child_frame
->m_menuBar
)
123 if (child_frame
== active_child_frame
)
125 gtk_widget_show( child_frame
->m_menuBar
->m_widget
);
126 visible_child_menu
= TRUE
;
129 gtk_widget_hide( child_frame
->m_menuBar
->m_widget
);
134 /* show/hide parent menu bar as required */
135 if (m_frameMenuBar
) m_frameMenuBar
->Show( !visible_child_menu
);
138 void wxMDIParentFrame::GetClientSize(int *width
, int *height
) const
140 wxFrame::GetClientSize( width
, height
);
143 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
145 if (!m_clientWindow
) return (wxMDIChildFrame
*) NULL
;
147 GtkNotebook
*notebook
= GTK_NOTEBOOK(m_clientWindow
->m_widget
);
148 if (!notebook
) return (wxMDIChildFrame
*) NULL
;
150 #if (GTK_MINOR_VERSION > 0)
151 gint i
= gtk_notebook_get_current_page( notebook
);
153 gint i
= gtk_notebook_current_page( notebook
);
155 if (i
< 0) return (wxMDIChildFrame
*) NULL
;
157 GtkNotebookPage
* page
= (GtkNotebookPage
*) (g_list_nth(notebook
->children
,i
)->data
);
158 if (!page
) return (wxMDIChildFrame
*) NULL
;
160 wxNode
*node
= m_clientWindow
->m_children
.First();
163 wxMDIChildFrame
*child_frame
= (wxMDIChildFrame
*)node
->Data();
164 if (child_frame
->m_page
== page
)
169 return (wxMDIChildFrame
*) NULL
;
172 wxMDIClientWindow
*wxMDIParentFrame::GetClientWindow() const
174 return m_clientWindow
;
177 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
179 m_clientWindow
= new wxMDIClientWindow( this );
180 return m_clientWindow
;
183 void wxMDIParentFrame::ActivateNext()
186 gtk_notebook_next_page( GTK_NOTEBOOK(m_clientWindow
->m_widget
) );
189 void wxMDIParentFrame::ActivatePrevious()
192 gtk_notebook_prev_page( GTK_NOTEBOOK(m_clientWindow
->m_widget
) );
195 void wxMDIParentFrame::OnActivate( wxActivateEvent
& WXUNUSED(event
) )
199 void wxMDIParentFrame::OnSysColourChanged( wxSysColourChangedEvent
& WXUNUSED(event
) )
203 //-----------------------------------------------------------------------------
205 //-----------------------------------------------------------------------------
207 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
,wxFrame
)
209 BEGIN_EVENT_TABLE(wxMDIChildFrame
, wxFrame
)
210 EVT_ACTIVATE(wxMDIChildFrame::OnActivate
)
213 wxMDIChildFrame::wxMDIChildFrame()
215 m_menuBar
= (wxMenuBar
*) NULL
;
216 m_page
= (GtkNotebookPage
*) NULL
;
219 wxMDIChildFrame::wxMDIChildFrame( wxMDIParentFrame
*parent
,
220 wxWindowID id
, const wxString
& title
,
221 const wxPoint
& WXUNUSED(pos
), const wxSize
& size
,
222 long style
, const wxString
& name
)
224 m_menuBar
= (wxMenuBar
*) NULL
;
225 m_page
= (GtkNotebookPage
*) NULL
;
226 Create( parent
, id
, title
, wxDefaultPosition
, size
, style
, name
);
229 wxMDIChildFrame::~wxMDIChildFrame()
235 bool wxMDIChildFrame::Create( wxMDIParentFrame
*parent
,
236 wxWindowID id
, const wxString
& title
,
237 const wxPoint
& WXUNUSED(pos
), const wxSize
& size
,
238 long style
, const wxString
& name
)
242 return wxWindow::Create( parent
->GetClientWindow(), id
, wxDefaultPosition
, size
, style
, name
);
245 void wxMDIChildFrame::GetClientSize( int *width
, int *height
) const
247 wxWindow::GetClientSize( width
, height
);
250 void wxMDIChildFrame::AddChild( wxWindow
*child
)
252 wxWindow::AddChild( child
);
255 static void SetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
257 menu
->SetInvokingWindow( win
);
258 wxNode
*node
= menu
->GetItems().First();
261 wxMenuItem
*menuitem
= (wxMenuItem
*)node
->Data();
262 if (menuitem
->IsSubMenu())
263 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
268 void wxMDIChildFrame::SetMenuBar( wxMenuBar
*menu_bar
)
270 m_menuBar
= menu_bar
;
274 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)m_parent
->m_parent
;
276 if (m_menuBar
->m_parent
!= this)
278 wxNode
*node
= m_menuBar
->GetMenus().First();
281 wxMenu
*menu
= (wxMenu
*)node
->Data();
282 SetInvokingWindow( menu
, this );
286 m_menuBar
->m_parent
= mdi_frame
;
289 /* the menu bar of the child window is shown in idle time as needed */
290 gtk_widget_hide( m_menuBar
->m_widget
);
292 /* insert the invisible menu bar into the _parent_ mdi frame */
293 gtk_myfixed_put( GTK_MYFIXED(mdi_frame
->m_mainWidget
), m_menuBar
->m_widget
, 0, 0 );
294 gtk_widget_set_usize( menu_bar
->m_widget
, mdi_frame
->m_width
, wxMENU_HEIGHT
);
298 wxMenuBar
*wxMDIChildFrame::GetMenuBar() const
303 void wxMDIChildFrame::Activate()
307 void wxMDIChildFrame::OnActivate( wxActivateEvent
&WXUNUSED(event
) )
311 //-----------------------------------------------------------------------------
313 //-----------------------------------------------------------------------------
315 static void gtk_page_size_callback( GtkWidget
*WXUNUSED(widget
), GtkAllocation
* alloc
, wxWindow
*win
)
317 if ((win
->m_x
== alloc
->x
) &&
318 (win
->m_y
== alloc
->y
) &&
319 (win
->m_width
== alloc
->width
) &&
320 (win
->m_height
== alloc
->height
) &&
326 win
->SetSize( alloc
->x
, alloc
->y
, alloc
->width
, alloc
->height
);
329 //-----------------------------------------------------------------------------
330 // InsertChild callback for wxMDIClientWindow
331 //-----------------------------------------------------------------------------
333 static void wxInsertChildInMDI( wxMDIClientWindow
* parent
, wxMDIChildFrame
* child
)
335 wxString s
= child
->m_title
;
336 if (s
.IsNull()) s
= _("MDI child");
338 GtkWidget
*label_widget
= gtk_label_new( s
.mbc_str() );
339 gtk_misc_set_alignment( GTK_MISC(label_widget
), 0.0, 0.5 );
341 gtk_signal_connect( GTK_OBJECT(child
->m_widget
), "size_allocate",
342 GTK_SIGNAL_FUNC(gtk_page_size_callback
), (gpointer
)child
);
344 GtkNotebook
*notebook
= GTK_NOTEBOOK(parent
->m_widget
);
346 gtk_notebook_append_page( notebook
, child
->m_widget
, label_widget
);
348 child
->m_page
= (GtkNotebookPage
*) (g_list_last(notebook
->children
)->data
);
350 wxMDIParentFrame
*parent_frame
= (wxMDIParentFrame
*) parent
->m_parent
;
351 parent_frame
->m_justInserted
= TRUE
;
354 //-----------------------------------------------------------------------------
356 //-----------------------------------------------------------------------------
358 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
,wxWindow
)
360 wxMDIClientWindow::wxMDIClientWindow()
364 wxMDIClientWindow::wxMDIClientWindow( wxMDIParentFrame
*parent
, long style
)
366 CreateClient( parent
, style
);
369 wxMDIClientWindow::~wxMDIClientWindow()
373 bool wxMDIClientWindow::CreateClient( wxMDIParentFrame
*parent
, long style
)
377 m_insertCallback
= (wxInsertChildFunction
)wxInsertChildInMDI
;
379 PreCreation( parent
, -1, wxPoint(10,10), wxSize(100,100), style
, "wxMDIClientWindow" );
381 m_widget
= gtk_notebook_new();
383 gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget
), 1 );
385 m_parent
->AddChild( this );
387 (m_parent
->m_insertCallback
)( m_parent
, this );