]> git.saurik.com Git - wxWidgets.git/blob - src/motif/mdi.cpp
Removed lots of wxMotif compile warnings. Copied new install.txt into old
[wxWidgets.git] / src / motif / mdi.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: mdi.cpp
3 // Purpose: MDI classes
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 17/09/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "mdi.h"
14 #endif
15
16 #include "wx/mdi.h"
17 #include "wx/menu.h"
18 #include "wx/settings.h"
19
20 #include <Xm/Xm.h>
21 #include <Xm/BulletinB.h>
22 #include <Xm/Form.h>
23 #include <Xm/MainW.h>
24 #include <Xm/RowColumn.h>
25 #include <Xm/CascadeBG.h>
26 #include <Xm/Text.h>
27 #include <Xm/PushBG.h>
28 #include <Xm/AtomMgr.h>
29 #include <Xm/Protocols.h>
30
31 #include "wx/motif/private.h"
32
33 extern wxList wxModelessWindows;
34
35 // Implemented in frame.cpp
36 extern void wxFrameFocusProc(Widget workArea, XtPointer clientData,
37 XmAnyCallbackStruct *cbs);
38
39 #define wxID_NOTEBOOK_CLIENT_AREA wxID_HIGHEST + 100
40
41 #if !USE_SHARED_LIBRARY
42 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame, wxFrame)
43 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame, wxFrame)
44 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow, wxNotebook)
45
46 BEGIN_EVENT_TABLE(wxMDIParentFrame, wxFrame)
47 EVT_SIZE(wxMDIParentFrame::OnSize)
48 EVT_ACTIVATE(wxMDIParentFrame::OnActivate)
49 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged)
50 END_EVENT_TABLE()
51
52 BEGIN_EVENT_TABLE(wxMDIClientWindow, wxNotebook)
53 EVT_SCROLL(wxMDIClientWindow::OnScroll)
54 EVT_NOTEBOOK_PAGE_CHANGED(wxID_NOTEBOOK_CLIENT_AREA, wxMDIClientWindow::OnPageChanged)
55 END_EVENT_TABLE()
56
57 #endif // USE_SHARED_LIBRARY
58
59 // Parent frame
60
61 wxMDIParentFrame::wxMDIParentFrame()
62 {
63 m_clientWindow = (wxMDIClientWindow*) NULL;
64 m_activeChild = (wxMDIChildFrame*) NULL;
65 m_activeMenuBar = (wxMenuBar*) NULL;
66 }
67
68 bool wxMDIParentFrame::Create(wxWindow *parent,
69 wxWindowID id,
70 const wxString& title,
71 const wxPoint& pos,
72 const wxSize& size,
73 long style,
74 const wxString& name)
75 {
76 m_clientWindow = (wxMDIClientWindow*) NULL;
77 m_activeChild = (wxMDIChildFrame*) NULL;
78 m_activeMenuBar = (wxMenuBar*) NULL;
79
80 bool success = wxFrame::Create(parent, id, title, pos, size, style, name);
81 if (success)
82 {
83 // TODO: app cannot override OnCreateClient since
84 // wxMDIParentFrame::OnCreateClient will still be called
85 // (we're in the constructor). How to resolve?
86
87 m_clientWindow = OnCreateClient();
88
89 // Uses own style for client style
90 m_clientWindow->CreateClient(this, GetWindowStyleFlag());
91
92 int w, h;
93 GetClientSize(& w, & h);
94 m_clientWindow->SetSize(0, 0, w, h);
95 return TRUE;
96 }
97 else
98 return FALSE;
99 }
100
101 wxMDIParentFrame::~wxMDIParentFrame()
102 {
103 // Make sure we delete the client window last of all
104 RemoveChild(m_clientWindow);
105
106 DestroyChildren();
107
108 delete m_clientWindow;
109 m_clientWindow = NULL;
110 }
111
112 void wxMDIParentFrame::SetMenuBar(wxMenuBar *menu_bar)
113 {
114 m_frameMenuBar = menu_bar;
115
116 SetChildMenuBar((wxMDIChildFrame*) NULL);
117 }
118
119 void wxMDIParentFrame::OnSize(wxSizeEvent& WXUNUSED(event))
120 {
121 #if wxUSE_CONSTRAINTS
122 if (GetAutoLayout())
123 Layout();
124 #endif
125 int x = 0;
126 int y = 0;
127 int width, height;
128 GetClientSize(&width, &height);
129
130 if ( GetClientWindow() )
131 GetClientWindow()->SetSize(x, y, width, height);
132 }
133
134 void wxMDIParentFrame::GetClientSize(int *width, int *height) const
135 {
136 wxFrame::GetClientSize(width, height);
137 }
138
139 void wxMDIParentFrame::OnActivate(wxActivateEvent& WXUNUSED(event))
140 {
141 // Do nothing
142 }
143
144 // Returns the active MDI child window
145 wxMDIChildFrame *wxMDIParentFrame::GetActiveChild() const
146 {
147 return m_activeChild;
148 }
149
150 // Create the client window class (don't Create the window,
151 // just return a new class)
152 wxMDIClientWindow *wxMDIParentFrame::OnCreateClient()
153 {
154 return new wxMDIClientWindow ;
155 }
156
157 // Set the child's menu into the parent frame
158 void wxMDIParentFrame::SetChildMenuBar(wxMDIChildFrame* child)
159 {
160 wxMenuBar* oldMenuBar = m_activeMenuBar;
161
162 if (child == (wxMDIChildFrame*) NULL) // No child: use parent frame
163 {
164 if (GetMenuBar() && (GetMenuBar() != m_activeMenuBar))
165 {
166 // if (m_activeMenuBar)
167 // m_activeMenuBar->DestroyMenuBar();
168
169 m_activeMenuBar = GetMenuBar();
170 m_activeMenuBar->CreateMenuBar(this);
171 /*
172 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
173 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
174 */
175 if (oldMenuBar && oldMenuBar->GetMainWidget())
176 XtUnmapWidget((Widget) oldMenuBar->GetMainWidget());
177
178 }
179 }
180 else if (child->GetMenuBar() == (wxMenuBar*) NULL) // No child menu bar: use parent frame
181 {
182 if (GetMenuBar() && (GetMenuBar() != m_activeMenuBar))
183 {
184 // if (m_activeMenuBar)
185 // m_activeMenuBar->DestroyMenuBar();
186 m_activeMenuBar = GetMenuBar();
187 m_activeMenuBar->CreateMenuBar(this);
188 /*
189 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
190 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
191 */
192 if (oldMenuBar && oldMenuBar->GetMainWidget())
193 XtUnmapWidget((Widget) oldMenuBar->GetMainWidget());
194 }
195 }
196 else // The child has a menubar
197 {
198 if (child->GetMenuBar() != m_activeMenuBar)
199 {
200 // if (m_activeMenuBar)
201 // m_activeMenuBar->DestroyMenuBar();
202
203 m_activeMenuBar = child->GetMenuBar();
204 m_activeMenuBar->CreateMenuBar(this);
205 /*
206 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
207 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
208 */
209 if (oldMenuBar && oldMenuBar->GetMainWidget())
210 XtUnmapWidget((Widget) oldMenuBar->GetMainWidget());
211 }
212 }
213 }
214
215 // Redirect events to active child first
216 bool wxMDIParentFrame::ProcessEvent(wxEvent& event)
217 {
218 // Stops the same event being processed repeatedly
219 static wxEventType inEvent = wxEVT_NULL;
220 if (inEvent == event.GetEventType())
221 return FALSE;
222
223 inEvent = event.GetEventType();
224
225 bool res = FALSE;
226 if (m_activeChild && event.IsKindOf(CLASSINFO(wxCommandEvent)))
227 {
228 res = m_activeChild->GetEventHandler()->ProcessEvent(event);
229 }
230
231 if (!res)
232 res = GetEventHandler()->wxEvtHandler::ProcessEvent(event);
233
234 inEvent = wxEVT_NULL;
235
236 return res;
237 }
238
239 void wxMDIParentFrame::DoSetSize(int x, int y,
240 int width, int height,
241 int sizeFlags)
242 {
243 wxWindow::DoSetSize(x, y, width, height, sizeFlags);
244 }
245
246 void wxMDIParentFrame::DoSetClientSize(int width, int height)
247 {
248 wxWindow::DoSetClientSize(width, height);
249 }
250
251 // Responds to colour changes, and passes event on to children.
252 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
253 {
254 // TODO
255
256 // Propagate the event to the non-top-level children
257 wxFrame::OnSysColourChanged(event);
258 }
259
260 // MDI operations
261 void wxMDIParentFrame::Cascade()
262 {
263 // TODO
264 }
265
266 void wxMDIParentFrame::Tile()
267 {
268 // TODO
269 }
270
271 void wxMDIParentFrame::ArrangeIcons()
272 {
273 // TODO
274 }
275
276 void wxMDIParentFrame::ActivateNext()
277 {
278 // TODO
279 }
280
281 void wxMDIParentFrame::ActivatePrevious()
282 {
283 // TODO
284 }
285
286 // Child frame
287
288 wxMDIChildFrame::wxMDIChildFrame()
289 {
290 m_mdiParentFrame = (wxMDIParentFrame*) NULL;
291 }
292
293 bool wxMDIChildFrame::Create(wxMDIParentFrame *parent,
294 wxWindowID id,
295 const wxString& title,
296 const wxPoint& pos,
297 const wxSize& size,
298 long style,
299 const wxString& name)
300 {
301 SetName(name);
302 SetWindowStyleFlag(style);
303
304 m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE);
305 m_foregroundColour = *wxBLACK;
306 m_font = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT);
307
308 if ( id > -1 )
309 m_windowId = id;
310 else
311 m_windowId = (int)NewControlId();
312
313 wxMDIClientWindow* clientWindow = parent->GetClientWindow();
314
315 wxASSERT_MSG( (clientWindow != (wxWindow*) NULL), "Missing MDI client window.");
316
317 if (clientWindow) clientWindow->AddChild(this);
318
319 SetMDIParentFrame(parent);
320
321 int width = size.x;
322 int height = size.y;
323 if (width == -1)
324 width = 200; // TODO: give reasonable default
325 if (height == -1)
326 height = 200; // TODO: give reasonable default
327
328 // We're deactivating the old child
329 wxMDIChildFrame* oldActiveChild = parent->GetActiveChild();
330 if (oldActiveChild)
331 {
332 wxActivateEvent event(wxEVT_ACTIVATE, FALSE, oldActiveChild->GetId());
333 event.SetEventObject( oldActiveChild );
334 oldActiveChild->GetEventHandler()->ProcessEvent(event);
335 }
336
337 // This is the currently active child
338 parent->SetActiveChild((wxMDIChildFrame*) this);
339
340 // This time we'll try a bog-standard bulletin board for
341 // the 'frame'. A main window doesn't seem to work.
342
343 m_mainWidget = (WXWidget) XtVaCreateWidget("client",
344 xmBulletinBoardWidgetClass, (Widget) clientWindow->GetTopWidget(),
345 XmNmarginWidth, 0,
346 XmNmarginHeight, 0,
347 /*
348 XmNrightAttachment, XmATTACH_FORM,
349 XmNleftAttachment, XmATTACH_FORM,
350 XmNtopAttachment, XmATTACH_FORM,
351 XmNbottomAttachment, XmATTACH_FORM,
352 */
353 XmNresizePolicy, XmRESIZE_NONE,
354 NULL);
355
356 XtAddEventHandler((Widget) m_mainWidget, ExposureMask,FALSE,
357 wxUniversalRepaintProc, (XtPointer) this);
358
359 SetCanAddEventHandler(TRUE);
360 AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
361
362 ChangeBackgroundColour();
363
364 XtManageChild((Widget) m_mainWidget);
365
366 SetTitle(title);
367
368 clientWindow->AddPage(this, title, TRUE);
369 clientWindow->Refresh();
370
371 // Positions the toolbar and status bar -- but we don't have any.
372 // PreResize();
373
374 wxModelessWindows.Append(this);
375 return TRUE;
376 }
377
378
379 wxMDIChildFrame::~wxMDIChildFrame()
380 {
381 if (m_mainWidget)
382 XtRemoveEventHandler((Widget) m_mainWidget, ExposureMask,FALSE,
383 wxUniversalRepaintProc, (XtPointer) this);
384
385 if (GetMDIParentFrame())
386 {
387 wxMDIParentFrame* parentFrame = GetMDIParentFrame();
388
389 if (parentFrame->GetActiveChild() == this)
390 parentFrame->SetActiveChild((wxMDIChildFrame*) NULL);
391 wxMDIClientWindow* clientWindow = parentFrame->GetClientWindow();
392
393 // Remove page if still there
394 if (clientWindow->RemovePage(this))
395 clientWindow->Refresh();
396
397 // Set the selection to the first remaining page
398 if (clientWindow->GetPageCount() > 0)
399 {
400 wxMDIChildFrame* child = (wxMDIChildFrame*) clientWindow->GetPage(0);
401 parentFrame->SetActiveChild(child);
402 parentFrame->SetChildMenuBar(child);
403 }
404 else
405 {
406 parentFrame->SetActiveChild((wxMDIChildFrame*) NULL);
407 parentFrame->SetChildMenuBar((wxMDIChildFrame*) NULL);
408 }
409 }
410 }
411
412 #if 0
413 // Implementation: intercept and act upon raise and lower commands.
414 void wxMDIChildFrame::OnRaise()
415 {
416 wxMDIParentFrame* parentFrame = (wxMDIParentFrame*) GetParent() ;
417 wxMDIChildFrame* oldActiveChild = parentFrame->GetActiveChild();
418 parentFrame->SetActiveChild(this);
419
420 if (oldActiveChild)
421 {
422 wxActivateEvent event(wxEVT_ACTIVATE, FALSE, oldActiveChild->GetId());
423 event.SetEventObject( oldActiveChild );
424 oldActiveChild->GetEventHandler()->ProcessEvent(event);
425 }
426
427 wxActivateEvent event(wxEVT_ACTIVATE, TRUE, this->GetId());
428 event.SetEventObject( this );
429 this->GetEventHandler()->ProcessEvent(event);
430 }
431
432 void wxMDIChildFrame::OnLower()
433 {
434 wxMDIParentFrame* parentFrame = (wxMDIParentFrame*) GetParent() ;
435 wxMDIChildFrame* oldActiveChild = parentFrame->GetActiveChild();
436
437 if (oldActiveChild == this)
438 {
439 wxActivateEvent event(wxEVT_ACTIVATE, FALSE, oldActiveChild->GetId());
440 event.SetEventObject( oldActiveChild );
441 oldActiveChild->GetEventHandler()->ProcessEvent(event);
442 }
443 // TODO: unfortunately we don't now know which is the top-most child,
444 // so make the active child NULL.
445 parentFrame->SetActiveChild((wxMDIChildFrame*) NULL);
446 }
447 #endif
448
449 // Set the client size (i.e. leave the calculation of borders etc.
450 // to wxWindows)
451 void wxMDIChildFrame::DoSetClientSize(int width, int height)
452 {
453 wxWindow::DoSetClientSize(width, height);
454 }
455
456 void wxMDIChildFrame::GetClientSize(int* width, int* height) const
457 {
458 wxWindow::GetSize(width, height);
459 }
460
461 void wxMDIChildFrame::DoSetSize(int x, int y, int width, int height, int sizeFlags)
462 {
463 wxWindow::DoSetSize(x, y, width, height, sizeFlags);
464 }
465
466 void wxMDIChildFrame::GetSize(int* width, int* height) const
467 {
468 wxWindow::GetSize(width, height);
469 }
470
471 void wxMDIChildFrame::GetPosition(int *x, int *y) const
472 {
473 wxWindow::GetPosition(x, y);
474 }
475
476 bool wxMDIChildFrame::Show(bool show)
477 {
478 m_visibleStatus = show; /* show-&-hide fix */
479 return wxWindow::Show(show);
480 }
481
482 void wxMDIChildFrame::SetMenuBar(wxMenuBar *menuBar)
483 {
484 // Don't create the underlying menubar yet; need to recreate
485 // it every time the child is activated.
486 m_frameMenuBar = menuBar;
487
488 // We make the assumption that if you're setting the menubar,
489 // this is the currently active child.
490 GetMDIParentFrame()->SetChildMenuBar(this);
491 }
492
493 // Set icon
494 void wxMDIChildFrame::SetIcon(const wxIcon& icon)
495 {
496 m_icon = icon;
497 if (m_icon.Ok())
498 {
499 // Not appropriate since there are no icons in
500 // a tabbed window
501 }
502 }
503
504 void wxMDIChildFrame::SetTitle(const wxString& title)
505 {
506 m_title = title;
507 wxMDIClientWindow* clientWindow = GetMDIParentFrame()->GetClientWindow();
508 int pageNo = clientWindow->FindPagePosition(this);
509 if (pageNo > -1)
510 clientWindow->SetPageText(pageNo, title);
511 }
512
513 // MDI operations
514 void wxMDIChildFrame::Maximize()
515 {
516 // TODO
517 }
518
519 void wxMDIChildFrame::Iconize(bool WXUNUSED(iconize))
520 {
521 // TODO
522 }
523
524 bool wxMDIChildFrame::IsIconized() const
525 {
526 return FALSE;
527 }
528
529 // Is it maximized? Always maximized under Motif, using the
530 // tabbed MDI implementation.
531 bool wxMDIChildFrame::IsMaximized(void) const
532 {
533 return TRUE;
534 }
535
536 void wxMDIChildFrame::Restore()
537 {
538 // TODO
539 }
540
541 void wxMDIChildFrame::Activate()
542 {
543 // TODO
544 }
545
546 void wxMDIChildFrame::CaptureMouse()
547 {
548 wxWindow::CaptureMouse();
549 }
550
551 void wxMDIChildFrame::ReleaseMouse()
552 {
553 wxWindow::ReleaseMouse();
554 }
555
556 void wxMDIChildFrame::Raise()
557 {
558 wxWindow::Raise();
559 }
560
561 void wxMDIChildFrame::Lower(void)
562 {
563 wxWindow::Raise();
564 }
565
566 void wxMDIChildFrame::SetSizeHints(int WXUNUSED(minW), int WXUNUSED(minH), int WXUNUSED(maxW), int WXUNUSED(maxH), int WXUNUSED(incW), int WXUNUSED(incH))
567 {
568 }
569
570 // Client window
571
572 wxMDIClientWindow::wxMDIClientWindow()
573 {
574 }
575
576 wxMDIClientWindow::~wxMDIClientWindow()
577 {
578 // By the time this destructor is called, the child frames will have been
579 // deleted and removed from the notebook/client window.
580 DestroyChildren();
581
582 m_mainWidget = (WXWidget) 0;
583 }
584
585 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame *parent, long style)
586 {
587 SetWindowStyleFlag(style);
588
589 // m_windowParent = parent;
590 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE);
591
592 bool success = wxNotebook::Create(parent, wxID_NOTEBOOK_CLIENT_AREA, wxPoint(0, 0), wxSize(100, 100), 0);
593 if (success)
594 {
595 wxFont font(10, wxSWISS, wxNORMAL, wxNORMAL);
596 wxFont selFont(10, wxSWISS, wxNORMAL, wxBOLD);
597 GetTabView()->SetTabFont(font);
598 GetTabView()->SetSelectedTabFont(selFont);
599 GetTabView()->SetTabSize(120, 18);
600 GetTabView()->SetTabSelectionHeight(20);
601 return TRUE;
602 }
603 else
604 return FALSE;
605 }
606
607 void wxMDIClientWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags)
608 {
609 wxWindow::DoSetSize(x, y, width, height, sizeFlags);
610 }
611
612 void wxMDIClientWindow::DoSetClientSize(int width, int height)
613 {
614 wxWindow::DoSetClientSize(width, height);
615 }
616
617 void wxMDIClientWindow::GetClientSize(int *width, int *height) const
618 {
619 wxWindow::GetClientSize(width, height);
620 }
621
622 void wxMDIClientWindow::GetSize(int *width, int *height) const
623 {
624 wxWindow::GetSize(width, height);
625 }
626
627 void wxMDIClientWindow::GetPosition(int *x, int *y) const
628 {
629 wxWindow::GetPosition(x, y);
630 }
631
632 // Explicitly call default scroll behaviour
633 void wxMDIClientWindow::OnScroll(wxScrollEvent& WXUNUSED(event))
634 {
635 Default(); // Default processing
636 }
637
638 void wxMDIClientWindow::OnPageChanged(wxNotebookEvent& event)
639 {
640 // Notify child that it has been activated
641 if (event.GetOldSelection() != -1)
642 {
643 wxMDIChildFrame* oldChild = (wxMDIChildFrame*) GetPage(event.GetOldSelection());
644 if (oldChild)
645 {
646 wxActivateEvent event(wxEVT_ACTIVATE, FALSE, oldChild->GetId());
647 event.SetEventObject( oldChild );
648 oldChild->GetEventHandler()->ProcessEvent(event);
649 }
650 }
651 if (event.GetSelection() != -1)
652 {
653 wxMDIChildFrame* activeChild = (wxMDIChildFrame*) GetPage(event.GetSelection());
654 if (activeChild)
655 {
656 wxActivateEvent event(wxEVT_ACTIVATE, TRUE, activeChild->GetId());
657 event.SetEventObject( activeChild );
658 activeChild->GetEventHandler()->ProcessEvent(event);
659
660 if (activeChild->GetMDIParentFrame())
661 {
662 activeChild->GetMDIParentFrame()->SetActiveChild(activeChild);
663 activeChild->GetMDIParentFrame()->SetChildMenuBar(activeChild);
664 }
665 }
666 }
667 event.Skip();
668 }