]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/mdi.cpp
82f5e1c2601d7202f9cb8a0f2caa77c2e3085897
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 gint i
= gtk_notebook_get_current_page( notebook
);
147 if (i
< 0) return (wxMDIChildFrame
*) NULL
;
149 GtkNotebookPage
* page
= (GtkNotebookPage
*) (g_list_nth(notebook
->children
,i
)->data
);
150 if (!page
) return (wxMDIChildFrame
*) NULL
;
152 wxNode
*node
= m_clientWindow
->m_children
.First();
155 wxMDIChildFrame
*child_frame
= (wxMDIChildFrame
*)node
->Data();
156 if (child_frame
->m_page
== page
)
161 return (wxMDIChildFrame
*) NULL
;
164 wxMDIClientWindow
*wxMDIParentFrame::GetClientWindow() const
166 return m_clientWindow
;
169 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
171 m_clientWindow
= new wxMDIClientWindow( this );
172 return m_clientWindow
;
175 void wxMDIParentFrame::ActivateNext()
178 gtk_notebook_next_page( GTK_NOTEBOOK(m_clientWindow
->m_widget
) );
181 void wxMDIParentFrame::ActivatePrevious()
184 gtk_notebook_prev_page( GTK_NOTEBOOK(m_clientWindow
->m_widget
) );
187 void wxMDIParentFrame::OnActivate( wxActivateEvent
& WXUNUSED(event
) )
191 void wxMDIParentFrame::OnSysColourChanged( wxSysColourChangedEvent
& WXUNUSED(event
) )
195 //-----------------------------------------------------------------------------
197 //-----------------------------------------------------------------------------
199 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
,wxFrame
)
201 BEGIN_EVENT_TABLE(wxMDIChildFrame
, wxFrame
)
202 EVT_ACTIVATE(wxMDIChildFrame::OnActivate
)
205 wxMDIChildFrame::wxMDIChildFrame()
207 m_menuBar
= (wxMenuBar
*) NULL
;
208 m_page
= (GtkNotebookPage
*) NULL
;
211 wxMDIChildFrame::wxMDIChildFrame( wxMDIParentFrame
*parent
,
212 wxWindowID id
, const wxString
& title
,
213 const wxPoint
& WXUNUSED(pos
), const wxSize
& size
,
214 long style
, const wxString
& name
)
216 m_menuBar
= (wxMenuBar
*) NULL
;
217 m_page
= (GtkNotebookPage
*) NULL
;
218 Create( parent
, id
, title
, wxDefaultPosition
, size
, style
, name
);
221 wxMDIChildFrame::~wxMDIChildFrame()
227 bool wxMDIChildFrame::Create( wxMDIParentFrame
*parent
,
228 wxWindowID id
, const wxString
& title
,
229 const wxPoint
& WXUNUSED(pos
), const wxSize
& size
,
230 long style
, const wxString
& name
)
234 return wxWindow::Create( parent
->GetClientWindow(), id
, wxDefaultPosition
, size
, style
, name
);
237 void wxMDIChildFrame::GetClientSize( int *width
, int *height
) const
239 wxWindow::GetClientSize( width
, height
);
242 void wxMDIChildFrame::AddChild( wxWindow
*child
)
244 wxWindow::AddChild( child
);
247 static void SetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
249 menu
->SetInvokingWindow( win
);
250 wxNode
*node
= menu
->GetItems().First();
253 wxMenuItem
*menuitem
= (wxMenuItem
*)node
->Data();
254 if (menuitem
->IsSubMenu())
255 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
260 void wxMDIChildFrame::SetMenuBar( wxMenuBar
*menu_bar
)
262 m_menuBar
= menu_bar
;
266 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)m_parent
->m_parent
;
268 if (m_menuBar
->m_parent
!= this)
270 wxNode
*node
= m_menuBar
->GetMenus().First();
273 wxMenu
*menu
= (wxMenu
*)node
->Data();
274 SetInvokingWindow( menu
, this );
278 m_menuBar
->m_parent
= mdi_frame
;
281 /* the menu bar of the child window is shown in idle time as needed */
282 gtk_widget_hide( m_menuBar
->m_widget
);
284 /* insert the invisible menu bar into the _parent_ mdi frame */
285 gtk_myfixed_put( GTK_MYFIXED(mdi_frame
->m_mainWidget
), m_menuBar
->m_widget
, 0, 0 );
286 gtk_widget_set_usize( menu_bar
->m_widget
, mdi_frame
->m_width
, wxMENU_HEIGHT
);
290 wxMenuBar
*wxMDIChildFrame::GetMenuBar() const
295 void wxMDIChildFrame::Activate()
299 void wxMDIChildFrame::OnActivate( wxActivateEvent
&WXUNUSED(event
) )
303 //-----------------------------------------------------------------------------
305 //-----------------------------------------------------------------------------
307 static void gtk_page_size_callback( GtkWidget
*WXUNUSED(widget
), GtkAllocation
* alloc
, wxWindow
*win
)
309 if ((win
->m_x
== alloc
->x
) &&
310 (win
->m_y
== alloc
->y
) &&
311 (win
->m_width
== alloc
->width
) &&
312 (win
->m_height
== alloc
->height
) &&
318 win
->SetSize( alloc
->x
, alloc
->y
, alloc
->width
, alloc
->height
);
321 //-----------------------------------------------------------------------------
322 // InsertChild callback for wxMDIClientWindow
323 //-----------------------------------------------------------------------------
325 static void wxInsertChildInMDI( wxMDIClientWindow
* parent
, wxMDIChildFrame
* child
)
327 wxString s
= child
->m_title
;
328 if (s
.IsNull()) s
= _("MDI child");
330 GtkWidget
*label_widget
= gtk_label_new( s
);
331 gtk_misc_set_alignment( GTK_MISC(label_widget
), 0.0, 0.5 );
333 gtk_signal_connect( GTK_OBJECT(child
->m_widget
), "size_allocate",
334 GTK_SIGNAL_FUNC(gtk_page_size_callback
), (gpointer
)child
);
336 GtkNotebook
*notebook
= GTK_NOTEBOOK(parent
->m_widget
);
338 gtk_notebook_append_page( notebook
, child
->m_widget
, label_widget
);
340 child
->m_page
= (GtkNotebookPage
*) (g_list_last(notebook
->children
)->data
);
342 wxMDIParentFrame
*parent_frame
= (wxMDIParentFrame
*) parent
->m_parent
;
343 parent_frame
->m_justInserted
= TRUE
;
346 //-----------------------------------------------------------------------------
348 //-----------------------------------------------------------------------------
350 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
,wxWindow
)
352 wxMDIClientWindow::wxMDIClientWindow()
356 wxMDIClientWindow::wxMDIClientWindow( wxMDIParentFrame
*parent
, long style
)
358 CreateClient( parent
, style
);
361 wxMDIClientWindow::~wxMDIClientWindow()
365 bool wxMDIClientWindow::CreateClient( wxMDIParentFrame
*parent
, long style
)
369 m_insertCallback
= (wxInsertChildFunction
)wxInsertChildInMDI
;
371 PreCreation( parent
, -1, wxPoint(10,10), wxSize(100,100), style
, "wxMDIClientWindow" );
373 m_widget
= gtk_notebook_new();
375 gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget
), 1 );
377 m_parent
->AddChild( this );
379 (m_parent
->m_insertCallback
)( m_parent
, this );