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