]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/mdi.cpp
Dialog items inherit parent's font now
[wxWidgets.git] / src / gtk / mdi.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: mdi.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifdef __GNUG__
11 #pragma implementation "mdi.h"
12 #endif
13
14 #include "wx/mdi.h"
15 #include "wx/dialog.h"
16 #include "wx/menu.h"
17 #include <wx/intl.h>
18
19 #include "glib.h"
20 #include "gdk/gdk.h"
21 #include "gtk/gtk.h"
22 #include "wx/gtk/win_gtk.h"
23
24 //-----------------------------------------------------------------------------
25 // constants
26 //-----------------------------------------------------------------------------
27
28 const int wxMENU_HEIGHT = 27;
29
30 //-----------------------------------------------------------------------------
31 // globals
32 //-----------------------------------------------------------------------------
33
34 extern wxList wxPendingDelete;
35
36 //-----------------------------------------------------------------------------
37 // "size_allocate"
38 //-----------------------------------------------------------------------------
39
40 static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win )
41 {
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) &&
46 (win->m_sizeSet))
47 {
48 return;
49 }
50
51 win->SetSize( alloc->x, alloc->y, alloc->width, alloc->height );
52 }
53
54 //-----------------------------------------------------------------------------
55 // "switch_page"
56 //-----------------------------------------------------------------------------
57
58 static void gtk_page_change_callback( GtkNotebook *WXUNUSED(widget),
59 GtkNotebookPage *page,
60 gint WXUNUSED(nPage),
61 wxMDIClientWindow *client_win )
62 {
63 wxNode *node = client_win->m_children.First();
64 while (node)
65 {
66 wxMDIChildFrame *child_frame = (wxMDIChildFrame *)node->Data();
67 if (child_frame->m_page == page)
68 {
69 wxMDIParentFrame *mdi_frame = (wxMDIParentFrame*)client_win->m_parent;
70 mdi_frame->m_currentChild = child_frame;
71 mdi_frame->SetMDIMenuBar( child_frame->m_menuBar );
72 return;
73 }
74 node = node->Next();
75 }
76 }
77
78 //-----------------------------------------------------------------------------
79 // wxMDIParentFrame
80 //-----------------------------------------------------------------------------
81
82 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame,wxFrame)
83
84 BEGIN_EVENT_TABLE(wxMDIParentFrame, wxFrame)
85 END_EVENT_TABLE()
86
87 wxMDIParentFrame::wxMDIParentFrame(void)
88 {
89 m_clientWindow = (wxMDIClientWindow *) NULL;
90 m_currentChild = (wxMDIChildFrame *) NULL;
91 m_parentFrameActive = TRUE;
92 }
93
94 wxMDIParentFrame::wxMDIParentFrame( wxWindow *parent,
95 wxWindowID id, const wxString& title,
96 const wxPoint& pos, const wxSize& size,
97 long style, const wxString& name )
98 {
99 m_clientWindow = (wxMDIClientWindow *) NULL;
100 m_currentChild = (wxMDIChildFrame *) NULL;
101 m_parentFrameActive = TRUE;
102 Create( parent, id, title, pos, size, style, name );
103 }
104
105 wxMDIParentFrame::~wxMDIParentFrame(void)
106 {
107 }
108
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 )
113 {
114 wxFrame::Create( parent, id, title, pos, size, style, name );
115
116 OnCreateClient();
117
118 return TRUE;
119 }
120
121 void wxMDIParentFrame::GtkOnSize( int x, int y, int width, int height )
122 {
123 wxFrame::GtkOnSize( x, y, width, height );
124
125 if (m_mdiMenuBar)
126 {
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 );
133 }
134 }
135
136 void wxMDIParentFrame::SetMDIMenuBar( wxMenuBar *menu_bar )
137 {
138 /* hide old child menu bar */
139 if (m_mdiMenuBar) m_mdiMenuBar->Show( FALSE );
140
141 m_mdiMenuBar = menu_bar;
142
143 /* show and resize new menu child menu bar */
144 if (m_mdiMenuBar)
145 {
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 );
153 }
154
155 /* show/hide parent menu bar as required */
156 if (m_frameMenuBar) m_frameMenuBar->Show( (m_mdiMenuBar == NULL) );
157 }
158
159 void wxMDIParentFrame::GetClientSize(int *width, int *height ) const
160 {
161 wxFrame::GetClientSize( width, height );
162 }
163
164 wxMDIChildFrame *wxMDIParentFrame::GetActiveChild(void) const
165 {
166 return m_currentChild;
167 }
168
169 wxMDIClientWindow *wxMDIParentFrame::GetClientWindow(void) const
170 {
171 return m_clientWindow;
172 }
173
174 wxMDIClientWindow *wxMDIParentFrame::OnCreateClient(void)
175 {
176 m_clientWindow = new wxMDIClientWindow( this );
177 return m_clientWindow;
178 }
179
180 void wxMDIParentFrame::ActivateNext(void)
181 {
182 if (m_clientWindow)
183 gtk_notebook_next_page( GTK_NOTEBOOK(m_clientWindow->m_widget) );
184 }
185
186 void wxMDIParentFrame::ActivatePrevious(void)
187 {
188 if (m_clientWindow)
189 gtk_notebook_prev_page( GTK_NOTEBOOK(m_clientWindow->m_widget) );
190 }
191
192 void wxMDIParentFrame::OnActivate( wxActivateEvent& WXUNUSED(event) )
193 {
194 }
195
196 void wxMDIParentFrame::OnSysColourChanged( wxSysColourChangedEvent& WXUNUSED(event) )
197 {
198 }
199
200 //-----------------------------------------------------------------------------
201 // wxMDIChildFrame
202 //-----------------------------------------------------------------------------
203
204 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame,wxFrame)
205
206 BEGIN_EVENT_TABLE(wxMDIChildFrame, wxFrame)
207 EVT_ACTIVATE(wxMDIChildFrame::OnActivate)
208 END_EVENT_TABLE()
209
210 wxMDIChildFrame::wxMDIChildFrame(void)
211 {
212 m_menuBar = (wxMenuBar *) NULL;
213 m_page = (GtkNotebookPage *) NULL;
214 }
215
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 )
220 {
221 m_menuBar = (wxMenuBar *) NULL;
222 m_page = (GtkNotebookPage *) NULL;
223 Create( parent, id, title, wxDefaultPosition, size, style, name );
224 }
225
226 wxMDIChildFrame::~wxMDIChildFrame(void)
227 {
228 if (m_menuBar)
229 {
230 wxMDIParentFrame *mdi_frame = (wxMDIParentFrame*)m_parent->m_parent;
231 if (mdi_frame->m_currentChild == this)
232 {
233 mdi_frame->SetMDIMenuBar( (wxMenuBar *) NULL );
234 mdi_frame->m_currentChild = (wxMDIChildFrame *) NULL;
235 }
236 delete m_menuBar;
237 }
238 }
239
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 )
244 {
245 m_title = title;
246
247 return wxWindow::Create( parent->GetClientWindow(), id, wxDefaultPosition, size, style, name );
248 }
249
250 void wxMDIChildFrame::GetClientSize( int *width, int *height ) const
251 {
252 wxWindow::GetClientSize( width, height );
253 }
254
255 void wxMDIChildFrame::AddChild( wxWindow *child )
256 {
257 wxWindow::AddChild( child );
258 }
259
260 static void SetInvokingWindow( wxMenu *menu, wxWindow *win )
261 {
262 menu->SetInvokingWindow( win );
263 wxNode *node = menu->m_items.First();
264 while (node)
265 {
266 wxMenuItem *menuitem = (wxMenuItem*)node->Data();
267 if (menuitem->IsSubMenu())
268 SetInvokingWindow( menuitem->GetSubMenu(), win );
269 node = node->Next();
270 }
271 }
272
273 void wxMDIChildFrame::SetMenuBar( wxMenuBar *menu_bar )
274 {
275 m_menuBar = menu_bar;
276
277 if (m_menuBar)
278 {
279 wxMDIParentFrame *mdi_frame = (wxMDIParentFrame*)m_parent->m_parent;
280
281 if (m_menuBar->m_parent != this)
282 {
283 wxNode *node = m_menuBar->m_menus.First();
284 while (node)
285 {
286 wxMenu *menu = (wxMenu*)node->Data();
287 SetInvokingWindow( menu, this );
288 node = node->Next();
289 }
290
291 m_menuBar->m_parent = mdi_frame;
292 }
293
294 gtk_myfixed_put( GTK_MYFIXED(mdi_frame->m_wxwindow),
295 m_menuBar->m_widget, m_menuBar->m_x, m_menuBar->m_y );
296
297 mdi_frame->SetMDIMenuBar( m_menuBar );
298 }
299 }
300
301 wxMenuBar *wxMDIChildFrame::GetMenuBar()
302 {
303 return m_menuBar;
304 }
305
306 void wxMDIChildFrame::Activate(void)
307 {
308 }
309
310 void wxMDIChildFrame::OnActivate( wxActivateEvent &WXUNUSED(event) )
311 {
312 }
313
314 //-----------------------------------------------------------------------------
315 // InsertChild callback for wxMDIClientWindow
316 //-----------------------------------------------------------------------------
317
318 static void wxInsertChildInMDI( wxMDIClientWindow* parent, wxMDIChildFrame* child )
319 {
320 wxString s = child->m_title;
321 if (s.IsNull()) s = _("MDI child");
322
323 GtkWidget *label_widget = gtk_label_new( s );
324 gtk_misc_set_alignment( GTK_MISC(label_widget), 0.0, 0.5 );
325
326 gtk_signal_connect( GTK_OBJECT(child->m_widget), "size_allocate",
327 GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)child );
328
329 GtkNotebook *notebook = GTK_NOTEBOOK(parent->m_widget);
330
331 gtk_notebook_append_page( notebook, child->m_widget, label_widget );
332
333 child->m_page = (GtkNotebookPage*) (g_list_last(notebook->children)->data);
334
335 gtk_notebook_set_page( notebook, parent->m_children.Number()-1 );
336
337 gtk_page_change_callback( (GtkNotebook *) NULL, child->m_page, 0, parent );
338 }
339
340 //-----------------------------------------------------------------------------
341 // wxMDIClientWindow
342 //-----------------------------------------------------------------------------
343
344 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow,wxWindow)
345
346 wxMDIClientWindow::wxMDIClientWindow(void)
347 {
348 }
349
350 wxMDIClientWindow::wxMDIClientWindow( wxMDIParentFrame *parent, long style )
351 {
352 CreateClient( parent, style );
353 }
354
355 wxMDIClientWindow::~wxMDIClientWindow(void)
356 {
357 }
358
359 bool wxMDIClientWindow::CreateClient( wxMDIParentFrame *parent, long style )
360 {
361 m_needParent = TRUE;
362
363 m_insertCallback = (wxInsertChildFunction)wxInsertChildInMDI;
364
365 PreCreation( parent, -1, wxPoint(10,10), wxSize(100,100), style, "wxMDIClientWindow" );
366
367 m_widget = gtk_notebook_new();
368
369 gtk_signal_connect( GTK_OBJECT(m_widget), "switch_page",
370 GTK_SIGNAL_FUNC(gtk_page_change_callback), (gpointer)this );
371
372 gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget), 1 );
373
374 m_parent->AddChild( this );
375
376 (m_parent->m_insertCallback)( m_parent, this );
377
378 PostCreation();
379
380 Show( TRUE );
381
382 return TRUE;
383 }
384
385
386