]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
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" | |
e3e65dac | 16 | #include "wx/dialog.h" |
716b7364 RR |
17 | #include "wx/gtk/win_gtk.h" |
18 | ||
19 | //----------------------------------------------------------------------------- | |
20 | ||
21 | extern wxList wxPendingDelete; | |
c801d85f KB |
22 | |
23 | //----------------------------------------------------------------------------- | |
24 | // wxMDIParentFrame | |
25 | //----------------------------------------------------------------------------- | |
26 | ||
33d0b396 RR |
27 | static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win ) |
28 | { | |
29 | if ((win->m_x == alloc->x) && | |
30 | (win->m_y == alloc->y) && | |
31 | (win->m_width == alloc->width) && | |
32 | (win->m_height == alloc->height)) | |
33 | { | |
34 | return; | |
35 | }; | |
36 | ||
37 | win->SetSize( alloc->x, alloc->y, alloc->width, alloc->height ); | |
38 | }; | |
39 | ||
716b7364 RR |
40 | // page change callback |
41 | static void gtk_page_change_callback( GtkNotebook *WXUNUSED(widget), | |
42 | GtkNotebookPage *page, | |
43 | gint WXUNUSED(nPage), | |
44 | wxMDIClientWindow *client_win ) | |
45 | { | |
46 | wxNode *node = client_win->m_children.First(); | |
47 | while (node) | |
48 | { | |
49 | wxMDIChildFrame *child_frame = (wxMDIChildFrame *)node->Data(); | |
50 | if (child_frame->m_page == page) | |
51 | { | |
52 | wxMDIParentFrame *mdi_frame = (wxMDIParentFrame*)client_win->m_parent; | |
53 | mdi_frame->m_currentChild = child_frame; | |
54 | mdi_frame->SetMDIMenuBar( child_frame->m_menuBar ); | |
55 | return; | |
56 | }; | |
57 | node = node->Next(); | |
58 | } | |
59 | } | |
60 | ||
33d0b396 RR |
61 | //----------------------------------------------------------------------------- |
62 | ||
c801d85f KB |
63 | IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame,wxFrame) |
64 | ||
716b7364 RR |
65 | BEGIN_EVENT_TABLE(wxMDIParentFrame, wxFrame) |
66 | END_EVENT_TABLE() | |
67 | ||
c801d85f KB |
68 | wxMDIParentFrame::wxMDIParentFrame(void) |
69 | { | |
70 | m_clientWindow = NULL; | |
71 | m_currentChild = NULL; | |
72 | m_parentFrameActive = TRUE; | |
73 | }; | |
74 | ||
75 | wxMDIParentFrame::wxMDIParentFrame( wxWindow *parent, | |
debe6624 | 76 | wxWindowID id, const wxString& title, |
c801d85f | 77 | const wxPoint& pos, const wxSize& size, |
debe6624 | 78 | long style, const wxString& name ) |
c801d85f KB |
79 | { |
80 | m_clientWindow = NULL; | |
81 | m_currentChild = NULL; | |
82 | m_parentFrameActive = TRUE; | |
83 | Create( parent, id, title, pos, size, style, name ); | |
84 | }; | |
85 | ||
86 | wxMDIParentFrame::~wxMDIParentFrame(void) | |
87 | { | |
88 | }; | |
89 | ||
90 | bool wxMDIParentFrame::Create( wxWindow *parent, | |
debe6624 | 91 | wxWindowID id, const wxString& title, |
c801d85f | 92 | const wxPoint& pos, const wxSize& size, |
debe6624 | 93 | long style, const wxString& name ) |
c801d85f KB |
94 | { |
95 | wxFrame::Create( parent, id, title, pos, size, style, name ); | |
96 | ||
97 | OnCreateClient(); | |
98 | ||
99 | return TRUE; | |
100 | }; | |
101 | ||
716b7364 | 102 | void wxMDIParentFrame::GtkOnSize( int x, int y, int width, int height ) |
c801d85f | 103 | { |
716b7364 RR |
104 | wxFrame::GtkOnSize( x, y, width, height ); |
105 | ||
106 | if (m_mdiMenuBar) | |
107 | { | |
108 | int x = 0; | |
109 | int y = 0; | |
110 | GetClientSize( &x, &y ); | |
111 | m_mdiMenuBar->SetSize( 1, 1, x-2, 26 ); | |
112 | } | |
c801d85f KB |
113 | }; |
114 | ||
716b7364 RR |
115 | void wxMDIParentFrame::SetMDIMenuBar( wxMenuBar *menu_bar ) |
116 | { | |
117 | if (m_mdiMenuBar) m_mdiMenuBar->Show( FALSE ); | |
118 | m_mdiMenuBar = menu_bar; | |
119 | if (m_mdiMenuBar) | |
120 | { | |
121 | int x = 0; | |
122 | int y = 0; | |
123 | GetClientSize( &x, &y ); | |
124 | m_mdiMenuBar->SetSize( 1, 1, x-2, 26 ); | |
125 | m_mdiMenuBar->Show( TRUE ); | |
126 | } | |
127 | }; | |
128 | ||
129 | void wxMDIParentFrame::GetClientSize(int *width, int *height ) const | |
c801d85f | 130 | { |
716b7364 | 131 | wxFrame::GetClientSize( width, height ); |
c801d85f KB |
132 | }; |
133 | ||
c801d85f KB |
134 | wxMDIChildFrame *wxMDIParentFrame::GetActiveChild(void) const |
135 | { | |
136 | return m_currentChild; | |
137 | }; | |
138 | ||
139 | wxMDIClientWindow *wxMDIParentFrame::GetClientWindow(void) const | |
140 | { | |
141 | return m_clientWindow; | |
142 | }; | |
143 | ||
144 | wxMDIClientWindow *wxMDIParentFrame::OnCreateClient(void) | |
145 | { | |
146 | m_clientWindow = new wxMDIClientWindow( this ); | |
147 | return m_clientWindow; | |
148 | }; | |
149 | ||
150 | void wxMDIParentFrame::ActivateNext(void) | |
151 | { | |
716b7364 RR |
152 | if (m_clientWindow) |
153 | gtk_notebook_next_page( GTK_NOTEBOOK(m_clientWindow->m_widget) ); | |
c801d85f KB |
154 | }; |
155 | ||
156 | void wxMDIParentFrame::ActivatePrevious(void) | |
716b7364 RR |
157 | { |
158 | if (m_clientWindow) | |
159 | gtk_notebook_prev_page( GTK_NOTEBOOK(m_clientWindow->m_widget) ); | |
160 | }; | |
161 | ||
162 | void wxMDIParentFrame::OnActivate( wxActivateEvent& WXUNUSED(event) ) | |
c801d85f KB |
163 | { |
164 | }; | |
165 | ||
166 | void wxMDIParentFrame::OnSysColourChanged( wxSysColourChangedEvent& WXUNUSED(event) ) | |
167 | { | |
168 | }; | |
169 | ||
170 | //----------------------------------------------------------------------------- | |
171 | // wxMDIChildFrame | |
172 | //----------------------------------------------------------------------------- | |
173 | ||
174 | IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame,wxPanel) | |
175 | ||
716b7364 RR |
176 | BEGIN_EVENT_TABLE(wxMDIChildFrame, wxPanel) |
177 | EVT_CLOSE(wxMDIChildFrame::OnCloseWindow) | |
e3e65dac | 178 | EVT_SIZE(wxMDIChildFrame::OnSize) |
9746a2ba | 179 | EVT_ACTIVATE(wxMDIChildFrame::OnActivate) |
716b7364 RR |
180 | END_EVENT_TABLE() |
181 | ||
c801d85f KB |
182 | wxMDIChildFrame::wxMDIChildFrame(void) |
183 | { | |
716b7364 RR |
184 | m_menuBar = NULL; |
185 | m_page = NULL; | |
c801d85f KB |
186 | }; |
187 | ||
188 | wxMDIChildFrame::wxMDIChildFrame( wxMDIParentFrame *parent, | |
debe6624 | 189 | wxWindowID id, const wxString& title, |
33d0b396 | 190 | const wxPoint& WXUNUSED(pos), const wxSize& size, |
debe6624 | 191 | long style, const wxString& name ) |
c801d85f | 192 | { |
716b7364 RR |
193 | m_menuBar = NULL; |
194 | m_page = NULL; | |
33d0b396 | 195 | Create( parent, id, title, wxDefaultPosition, size, style, name ); |
c801d85f KB |
196 | }; |
197 | ||
198 | wxMDIChildFrame::~wxMDIChildFrame(void) | |
199 | { | |
716b7364 RR |
200 | if (m_menuBar) |
201 | { | |
202 | wxMDIParentFrame *mdi_frame = (wxMDIParentFrame*)m_parent->m_parent; | |
203 | if (mdi_frame->m_currentChild == this) | |
204 | { | |
205 | mdi_frame->SetMDIMenuBar( NULL ); | |
206 | mdi_frame->m_currentChild = NULL; | |
207 | }; | |
208 | delete m_menuBar; | |
209 | } | |
c801d85f KB |
210 | }; |
211 | ||
212 | bool wxMDIChildFrame::Create( wxMDIParentFrame *parent, | |
debe6624 | 213 | wxWindowID id, const wxString& title, |
33d0b396 | 214 | const wxPoint& WXUNUSED(pos), const wxSize& size, |
debe6624 | 215 | long style, const wxString& name ) |
c801d85f KB |
216 | { |
217 | m_title = title; | |
33d0b396 | 218 | return wxPanel::Create( parent->GetClientWindow(), id, wxDefaultPosition, size, style, name ); |
c801d85f KB |
219 | }; |
220 | ||
716b7364 | 221 | void wxMDIChildFrame::OnCloseWindow( wxCloseEvent &event ) |
c801d85f | 222 | { |
716b7364 RR |
223 | if ( GetEventHandler()->OnClose() || event.GetForce()) |
224 | { | |
225 | this->Destroy(); | |
226 | } | |
227 | }; | |
228 | ||
e3e65dac RR |
229 | void wxMDIChildFrame::OnSize( wxSizeEvent &WXUNUSED(event) ) |
230 | { | |
231 | if ( GetAutoLayout() ) | |
232 | Layout(); | |
233 | else { | |
234 | // no child: go out ! | |
235 | if (!GetChildren()->First()) | |
236 | return; | |
237 | ||
238 | // do we have exactly one child? | |
239 | wxWindow *child = NULL; | |
240 | for(wxNode *node = GetChildren()->First(); node; node = node->Next()) | |
241 | { | |
242 | wxWindow *win = (wxWindow *)node->Data(); | |
243 | if (!IS_KIND_OF(win,wxFrame) && !IS_KIND_OF(win,wxDialog)) | |
244 | { | |
245 | if ( child ) // it's the second one: do nothing | |
246 | return; | |
247 | ||
248 | child = win; | |
249 | }; | |
250 | }; | |
251 | ||
252 | // yes: set it's size to fill all the frame | |
253 | int client_x, client_y; | |
254 | GetClientSize(&client_x, &client_y); | |
255 | child->SetSize( 1, 1, client_x-2, client_y); | |
256 | } | |
257 | }; | |
9746a2ba | 258 | |
716b7364 RR |
259 | bool wxMDIChildFrame::Destroy(void) |
260 | { | |
261 | if (!wxPendingDelete.Member(this)) | |
262 | wxPendingDelete.Append(this); | |
263 | ||
264 | return TRUE; | |
265 | } | |
266 | ||
267 | static void SetInvokingWindow( wxMenu *menu, wxWindow *win ) | |
268 | { | |
269 | menu->SetInvokingWindow( win ); | |
270 | wxNode *node = menu->m_items.First(); | |
271 | while (node) | |
272 | { | |
273 | wxMenuItem *menuitem = (wxMenuItem*)node->Data(); | |
46dc76ba RR |
274 | if (menuitem->IsSubMenu()) |
275 | SetInvokingWindow( menuitem->GetSubMenu(), win ); | |
716b7364 RR |
276 | node = node->Next(); |
277 | }; | |
278 | }; | |
279 | ||
280 | void wxMDIChildFrame::SetMenuBar( wxMenuBar *menu_bar ) | |
281 | { | |
282 | m_menuBar = menu_bar; | |
283 | ||
284 | if (m_menuBar) | |
285 | { | |
286 | wxMDIParentFrame *mdi_frame = (wxMDIParentFrame*)m_parent->m_parent; | |
287 | ||
288 | if (m_menuBar->m_parent != this) | |
289 | { | |
290 | wxNode *node = m_menuBar->m_menus.First(); | |
291 | while (node) | |
292 | { | |
293 | wxMenu *menu = (wxMenu*)node->Data(); | |
294 | SetInvokingWindow( menu, this ); | |
295 | node = node->Next(); | |
296 | }; | |
297 | ||
298 | m_menuBar->m_parent = mdi_frame; | |
299 | } | |
300 | mdi_frame->SetMDIMenuBar( m_menuBar ); | |
301 | ||
302 | gtk_myfixed_put( GTK_MYFIXED(mdi_frame->m_mainWindow), | |
303 | m_menuBar->m_widget, m_menuBar->m_x, m_menuBar->m_y ); | |
304 | } | |
c801d85f KB |
305 | }; |
306 | ||
307 | void wxMDIChildFrame::Activate(void) | |
308 | { | |
309 | }; | |
310 | ||
9746a2ba RR |
311 | void wxMDIChildFrame::OnActivate( wxActivateEvent &WXUNUSED(event) ) |
312 | { | |
313 | }; | |
314 | ||
c801d85f KB |
315 | //----------------------------------------------------------------------------- |
316 | // wxMDIClientWindow | |
317 | //----------------------------------------------------------------------------- | |
318 | ||
319 | IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow,wxWindow) | |
320 | ||
321 | wxMDIClientWindow::wxMDIClientWindow(void) | |
322 | { | |
323 | }; | |
324 | ||
debe6624 | 325 | wxMDIClientWindow::wxMDIClientWindow( wxMDIParentFrame *parent, long style ) |
c801d85f KB |
326 | { |
327 | CreateClient( parent, style ); | |
328 | }; | |
329 | ||
330 | wxMDIClientWindow::~wxMDIClientWindow(void) | |
331 | { | |
332 | }; | |
333 | ||
debe6624 | 334 | bool wxMDIClientWindow::CreateClient( wxMDIParentFrame *parent, long style ) |
c801d85f KB |
335 | { |
336 | m_needParent = TRUE; | |
337 | ||
338 | PreCreation( parent, -1, wxPoint(10,10), wxSize(100,100), style, "wxMDIClientWindow" ); | |
339 | ||
340 | m_widget = gtk_notebook_new(); | |
341 | ||
716b7364 RR |
342 | gtk_signal_connect( GTK_OBJECT(m_widget), "switch_page", |
343 | GTK_SIGNAL_FUNC(gtk_page_change_callback), (gpointer)this ); | |
344 | ||
345 | gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget), 1 ); | |
346 | ||
c801d85f KB |
347 | PostCreation(); |
348 | ||
349 | Show( TRUE ); | |
350 | ||
351 | return TRUE; | |
352 | }; | |
353 | ||
354 | void wxMDIClientWindow::AddChild( wxWindow *child ) | |
355 | { | |
716b7364 | 356 | if (!child->IsKindOf(CLASSINFO(wxMDIChildFrame))) |
c801d85f | 357 | { |
716b7364 RR |
358 | wxFAIL_MSG("wxNotebook::AddChild: Child has to be wxMDIChildFrame"); |
359 | return; | |
c801d85f KB |
360 | }; |
361 | ||
716b7364 RR |
362 | m_children.Append( child ); |
363 | ||
364 | wxString s; | |
365 | wxMDIChildFrame* mdi_child = (wxMDIChildFrame*) child; | |
366 | s = mdi_child->m_title; | |
c801d85f KB |
367 | if (s.IsNull()) s = "MDI child"; |
368 | ||
369 | GtkWidget *label_widget; | |
370 | label_widget = gtk_label_new( s ); | |
371 | gtk_misc_set_alignment( GTK_MISC(label_widget), 0.0, 0.5 ); | |
33d0b396 RR |
372 | |
373 | gtk_signal_connect( GTK_OBJECT(child->m_widget), "size_allocate", | |
374 | GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)child ); | |
46dc76ba | 375 | |
c801d85f | 376 | gtk_notebook_append_page( GTK_NOTEBOOK(m_widget), child->m_widget, label_widget ); |
716b7364 RR |
377 | |
378 | mdi_child->m_page = (GtkNotebookPage*) (g_list_last(GTK_NOTEBOOK(m_widget)->children)->data); | |
379 | ||
380 | gtk_notebook_set_page( GTK_NOTEBOOK(m_widget), m_children.Number()-1 ); | |
7b5408ea RR |
381 | |
382 | gtk_page_change_callback( NULL, mdi_child->m_page, 0, this ); | |
c801d85f KB |
383 | }; |
384 | ||
385 |