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