]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/mdi.cpp
made the code more wxMSW compatible
[wxWidgets.git] / src / gtk1 / mdi.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: mdi.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Created: 01/02/97
6 // Id:
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifdef __GNUG__
12 #pragma implementation "mdi.h"
13 #endif
14
15 #include "wx/mdi.h"
16 #include "wx/gtk/win_gtk.h"
17
18 //-----------------------------------------------------------------------------
19
20 extern wxList wxPendingDelete;
21
22 //-----------------------------------------------------------------------------
23 // wxMDIParentFrame
24 //-----------------------------------------------------------------------------
25
26 static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win )
27 {
28 if ((win->m_x == alloc->x) &&
29 (win->m_y == alloc->y) &&
30 (win->m_width == alloc->width) &&
31 (win->m_height == alloc->height))
32 {
33 return;
34 };
35
36 win->SetSize( alloc->x, alloc->y, alloc->width, alloc->height );
37 };
38
39 // page change callback
40 static void gtk_page_change_callback( GtkNotebook *WXUNUSED(widget),
41 GtkNotebookPage *page,
42 gint WXUNUSED(nPage),
43 wxMDIClientWindow *client_win )
44 {
45 wxNode *node = client_win->m_children.First();
46 while (node)
47 {
48 wxMDIChildFrame *child_frame = (wxMDIChildFrame *)node->Data();
49 if (child_frame->m_page == page)
50 {
51 wxMDIParentFrame *mdi_frame = (wxMDIParentFrame*)client_win->m_parent;
52 mdi_frame->m_currentChild = child_frame;
53 mdi_frame->SetMDIMenuBar( child_frame->m_menuBar );
54 return;
55 };
56 node = node->Next();
57 }
58 }
59
60 //-----------------------------------------------------------------------------
61
62 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame,wxFrame)
63
64 BEGIN_EVENT_TABLE(wxMDIParentFrame, wxFrame)
65 END_EVENT_TABLE()
66
67 wxMDIParentFrame::wxMDIParentFrame(void)
68 {
69 m_clientWindow = NULL;
70 m_currentChild = NULL;
71 m_parentFrameActive = TRUE;
72 m_toolBar = NULL;
73 };
74
75 wxMDIParentFrame::wxMDIParentFrame( wxWindow *parent,
76 wxWindowID id, const wxString& title,
77 const wxPoint& pos, const wxSize& size,
78 long style, const wxString& name )
79 {
80 m_clientWindow = NULL;
81 m_currentChild = NULL;
82 m_parentFrameActive = TRUE;
83 m_toolBar = NULL;
84 Create( parent, id, title, pos, size, style, name );
85 };
86
87 wxMDIParentFrame::~wxMDIParentFrame(void)
88 {
89 };
90
91 bool wxMDIParentFrame::Create( wxWindow *parent,
92 wxWindowID id, const wxString& title,
93 const wxPoint& pos, const wxSize& size,
94 long style, const wxString& name )
95 {
96 wxFrame::Create( parent, id, title, pos, size, style, name );
97
98 OnCreateClient();
99
100 return TRUE;
101 };
102
103 void wxMDIParentFrame::GtkOnSize( int x, int y, int width, int height )
104 {
105 wxFrame::GtkOnSize( x, y, width, height );
106
107 if (m_mdiMenuBar)
108 {
109 int x = 0;
110 int y = 0;
111 GetClientSize( &x, &y );
112 m_mdiMenuBar->SetSize( 1, 1, x-2, 26 );
113 }
114 };
115
116 void wxMDIParentFrame::SetMDIMenuBar( wxMenuBar *menu_bar )
117 {
118 if (m_mdiMenuBar) m_mdiMenuBar->Show( FALSE );
119 m_mdiMenuBar = menu_bar;
120 if (m_mdiMenuBar)
121 {
122 int x = 0;
123 int y = 0;
124 GetClientSize( &x, &y );
125 m_mdiMenuBar->SetSize( 1, 1, x-2, 26 );
126 m_mdiMenuBar->Show( TRUE );
127 }
128 };
129
130 void wxMDIParentFrame::GetClientSize(int *width, int *height ) const
131 {
132 wxFrame::GetClientSize( width, height );
133 };
134
135 void wxMDIParentFrame::SetToolBar( wxToolBar *toolbar )
136 {
137 m_toolBar = toolbar;
138 };
139
140 wxWindow *wxMDIParentFrame::GetToolBar(void) const
141 {
142 return m_toolBar;
143 };
144
145 wxMDIChildFrame *wxMDIParentFrame::GetActiveChild(void) const
146 {
147 return m_currentChild;
148 };
149
150 wxMDIClientWindow *wxMDIParentFrame::GetClientWindow(void) const
151 {
152 return m_clientWindow;
153 };
154
155 wxMDIClientWindow *wxMDIParentFrame::OnCreateClient(void)
156 {
157 m_clientWindow = new wxMDIClientWindow( this );
158 return m_clientWindow;
159 };
160
161 void wxMDIParentFrame::ActivateNext(void)
162 {
163 if (m_clientWindow)
164 gtk_notebook_next_page( GTK_NOTEBOOK(m_clientWindow->m_widget) );
165 };
166
167 void wxMDIParentFrame::ActivatePrevious(void)
168 {
169 if (m_clientWindow)
170 gtk_notebook_prev_page( GTK_NOTEBOOK(m_clientWindow->m_widget) );
171 };
172
173 void wxMDIParentFrame::OnActivate( wxActivateEvent& WXUNUSED(event) )
174 {
175 };
176
177 void wxMDIParentFrame::OnSysColourChanged( wxSysColourChangedEvent& WXUNUSED(event) )
178 {
179 };
180
181 //-----------------------------------------------------------------------------
182 // wxMDIChildFrame
183 //-----------------------------------------------------------------------------
184
185 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame,wxPanel)
186
187 BEGIN_EVENT_TABLE(wxMDIChildFrame, wxPanel)
188 EVT_CLOSE(wxMDIChildFrame::OnCloseWindow)
189 END_EVENT_TABLE()
190
191 wxMDIChildFrame::wxMDIChildFrame(void)
192 {
193 m_menuBar = NULL;
194 m_page = NULL;
195 };
196
197 wxMDIChildFrame::wxMDIChildFrame( wxMDIParentFrame *parent,
198 wxWindowID id, const wxString& title,
199 const wxPoint& WXUNUSED(pos), const wxSize& size,
200 long style, const wxString& name )
201 {
202 m_menuBar = NULL;
203 m_page = NULL;
204 Create( parent, id, title, wxDefaultPosition, size, style, name );
205 };
206
207 wxMDIChildFrame::~wxMDIChildFrame(void)
208 {
209 if (m_menuBar)
210 {
211 wxMDIParentFrame *mdi_frame = (wxMDIParentFrame*)m_parent->m_parent;
212 if (mdi_frame->m_currentChild == this)
213 {
214 mdi_frame->SetMDIMenuBar( NULL );
215 mdi_frame->m_currentChild = NULL;
216 };
217 delete m_menuBar;
218 }
219 };
220
221 bool wxMDIChildFrame::Create( wxMDIParentFrame *parent,
222 wxWindowID id, const wxString& title,
223 const wxPoint& WXUNUSED(pos), const wxSize& size,
224 long style, const wxString& name )
225 {
226 m_title = title;
227 return wxPanel::Create( parent->GetClientWindow(), id, wxDefaultPosition, size, style, name );
228 };
229
230 void wxMDIChildFrame::OnCloseWindow( wxCloseEvent &event )
231 {
232 if ( GetEventHandler()->OnClose() || event.GetForce())
233 {
234 this->Destroy();
235 }
236 };
237
238 bool wxMDIChildFrame::Destroy(void)
239 {
240 if (!wxPendingDelete.Member(this))
241 wxPendingDelete.Append(this);
242
243 return TRUE;
244 }
245
246 static void SetInvokingWindow( wxMenu *menu, wxWindow *win )
247 {
248 menu->SetInvokingWindow( win );
249 wxNode *node = menu->m_items.First();
250 while (node)
251 {
252 wxMenuItem *menuitem = (wxMenuItem*)node->Data();
253 if (menuitem->m_isSubMenu) SetInvokingWindow( menuitem->m_subMenu, win );
254 node = node->Next();
255 };
256 };
257
258 void wxMDIChildFrame::SetMenuBar( wxMenuBar *menu_bar )
259 {
260 m_menuBar = menu_bar;
261
262 if (m_menuBar)
263 {
264 wxMDIParentFrame *mdi_frame = (wxMDIParentFrame*)m_parent->m_parent;
265
266 if (m_menuBar->m_parent != this)
267 {
268 wxNode *node = m_menuBar->m_menus.First();
269 while (node)
270 {
271 wxMenu *menu = (wxMenu*)node->Data();
272 SetInvokingWindow( menu, this );
273 node = node->Next();
274 };
275
276 m_menuBar->m_parent = mdi_frame;
277 }
278 mdi_frame->SetMDIMenuBar( m_menuBar );
279
280 gtk_myfixed_put( GTK_MYFIXED(mdi_frame->m_mainWindow),
281 m_menuBar->m_widget, m_menuBar->m_x, m_menuBar->m_y );
282 }
283 };
284
285 void wxMDIChildFrame::Activate(void)
286 {
287 };
288
289 //-----------------------------------------------------------------------------
290 // wxMDIClientWindow
291 //-----------------------------------------------------------------------------
292
293 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow,wxWindow)
294
295 wxMDIClientWindow::wxMDIClientWindow(void)
296 {
297 };
298
299 wxMDIClientWindow::wxMDIClientWindow( wxMDIParentFrame *parent, long style )
300 {
301 CreateClient( parent, style );
302 };
303
304 wxMDIClientWindow::~wxMDIClientWindow(void)
305 {
306 };
307
308 bool wxMDIClientWindow::CreateClient( wxMDIParentFrame *parent, long style )
309 {
310 m_needParent = TRUE;
311
312 PreCreation( parent, -1, wxPoint(10,10), wxSize(100,100), style, "wxMDIClientWindow" );
313
314 m_widget = gtk_notebook_new();
315
316 gtk_signal_connect( GTK_OBJECT(m_widget), "switch_page",
317 GTK_SIGNAL_FUNC(gtk_page_change_callback), (gpointer)this );
318
319 gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget), 1 );
320
321 PostCreation();
322
323 Show( TRUE );
324
325 return TRUE;
326 };
327
328 void wxMDIClientWindow::AddChild( wxWindow *child )
329 {
330 if (!child->IsKindOf(CLASSINFO(wxMDIChildFrame)))
331 {
332 wxFAIL_MSG("wxNotebook::AddChild: Child has to be wxMDIChildFrame");
333 return;
334 };
335
336 m_children.Append( child );
337
338 wxString s;
339 wxMDIChildFrame* mdi_child = (wxMDIChildFrame*) child;
340 s = mdi_child->m_title;
341 if (s.IsNull()) s = "MDI child";
342
343 GtkWidget *label_widget;
344 label_widget = gtk_label_new( s );
345 gtk_misc_set_alignment( GTK_MISC(label_widget), 0.0, 0.5 );
346
347 gtk_signal_connect( GTK_OBJECT(child->m_widget), "size_allocate",
348 GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)child );
349
350 gtk_notebook_append_page( GTK_NOTEBOOK(m_widget), child->m_widget, label_widget );
351
352 mdi_child->m_page = (GtkNotebookPage*) (g_list_last(GTK_NOTEBOOK(m_widget)->children)->data);
353
354 gtk_notebook_set_page( GTK_NOTEBOOK(m_widget), m_children.Number()-1 );
355 };
356
357