removed USE_SHARED_LIBRARY(IES)
[wxWidgets.git] / src / motif / frame.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: motif/frame.cpp
3 // Purpose: wxFrame
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 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "frame.h"
22 #endif
23
24 #include "wx/frame.h"
25 #include "wx/statusbr.h"
26 #include "wx/toolbar.h"
27 #include "wx/menuitem.h"
28 #include "wx/menu.h"
29 #include "wx/dcclient.h"
30 #include "wx/dialog.h"
31 #include "wx/settings.h"
32 #include "wx/app.h"
33 #include "wx/utils.h"
34
35 #ifdef __VMS__
36 #pragma message disable nosimpint
37 #endif
38
39 #if defined(__ultrix) || defined(__sgi)
40 #include <Xm/Frame.h>
41 #endif
42
43 #include <Xm/Xm.h>
44 #include <X11/Shell.h>
45 #if XmVersion >= 1002
46 #include <Xm/XmAll.h>
47 #else
48 #include <Xm/Frame.h>
49 #endif
50 #include <Xm/MwmUtil.h>
51 #include <Xm/BulletinB.h>
52 #include <Xm/Form.h>
53 #include <Xm/MainW.h>
54 #include <Xm/RowColumn.h>
55 #include <Xm/Label.h>
56 #include <Xm/AtomMgr.h>
57 #include <Xm/LabelG.h>
58 #include <Xm/Frame.h>
59 #if XmVersion > 1000
60 #include <Xm/Protocols.h>
61 #endif
62
63 #ifdef __VMS__
64 #pragma message enable nosimpint
65 #endif
66
67 #include "wx/motif/private.h"
68
69 // ----------------------------------------------------------------------------
70 // private functions
71 // ----------------------------------------------------------------------------
72
73 static void wxCloseFrameCallback(Widget, XtPointer, XmAnyCallbackStruct *cbs);
74 static void wxFrameFocusProc(Widget workArea, XtPointer clientData,
75 XmAnyCallbackStruct *cbs);
76 static void wxFrameMapProc(Widget frameShell, XtPointer clientData,
77 XCrossingEvent * event);
78
79 // ----------------------------------------------------------------------------
80 // globals
81 // ----------------------------------------------------------------------------
82
83 extern wxList wxModelessWindows;
84 extern wxList wxPendingDelete;
85
86 // TODO: this should be tidied so that any frame can be the
87 // top frame
88 static bool wxTopLevelUsed = FALSE;
89
90 // ----------------------------------------------------------------------------
91 // wxWin macros
92 // ----------------------------------------------------------------------------
93
94 BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
95 EVT_ACTIVATE(wxFrame::OnActivate)
96 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
97 END_EVENT_TABLE()
98
99 IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow)
100
101 // ============================================================================
102 // implementation
103 // ============================================================================
104
105 // ----------------------------------------------------------------------------
106 // frame construction
107 // ----------------------------------------------------------------------------
108
109 void wxFrame::Init()
110 {
111 m_iconized = FALSE;
112
113 //// Motif-specific
114 m_frameShell = (WXWidget) NULL;
115 m_frameWidget = (WXWidget) NULL;;
116 m_workArea = (WXWidget) NULL;;
117 m_clientArea = (WXWidget) NULL;;
118 m_visibleStatus = TRUE;
119 }
120
121 bool wxFrame::Create(wxWindow *parent,
122 wxWindowID id,
123 const wxString& title,
124 const wxPoint& pos,
125 const wxSize& size,
126 long style,
127 const wxString& name)
128 {
129 if ( parent )
130 AddChild(this);
131 else
132 wxTopLevelWindows.Append(this);
133
134 wxModelessWindows.Append(this);
135
136 SetName(name);
137
138 m_windowStyle = style;
139
140 m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE);
141 m_foregroundColour = *wxBLACK;
142 m_font = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT);
143
144 if ( id > -1 )
145 m_windowId = id;
146 else
147 m_windowId = (int)NewControlId();
148
149 int x = pos.x, y = pos.y;
150 int width = size.x, height = size.y;
151
152 // Set reasonable values for position and size if defaults have been
153 // requested
154 //
155 // MB TODO: something better than these arbitrary values ?
156 // VZ should use X resources for this...
157 if ( width == -1 )
158 width = 400;
159 if ( height == -1 )
160 height = 400;
161
162 int displayW, displayH;
163 wxDisplaySize( &displayW, &displayH );
164
165 if ( x == -1 )
166 {
167 x = (displayW - width) / 2;
168 if (x < 10) x = 10;
169 }
170 if ( y == -1 )
171 {
172 y = (displayH - height) / 2;
173 if (y < 10) y = 10;
174 }
175
176 // VZ: what does this do??
177 if (wxTopLevelUsed)
178 {
179 // Change suggested by Matthew Flatt
180 m_frameShell = (WXWidget)XtAppCreateShell
181 (
182 name,
183 wxTheApp->GetClassName(),
184 topLevelShellWidgetClass,
185 (Display*) wxGetDisplay(),
186 NULL,
187 0
188 );
189 }
190 else
191 {
192 m_frameShell = wxTheApp->GetTopLevelWidget();
193 wxTopLevelUsed = TRUE;
194 }
195
196 XtVaSetValues((Widget) m_frameShell,
197 // Allows menu to resize
198 XmNallowShellResize, True,
199 XmNdeleteResponse, XmDO_NOTHING,
200 XmNmappedWhenManaged, False,
201 XmNiconic, (style & wxICONIZE) ? TRUE : FALSE,
202 NULL);
203
204 if (!title.IsEmpty())
205 XtVaSetValues((Widget) m_frameShell,
206 XmNtitle, title.c_str(),
207 NULL);
208
209 m_frameWidget = (WXWidget) XtVaCreateManagedWidget("main_window",
210 xmMainWindowWidgetClass, (Widget) m_frameShell,
211 XmNresizePolicy, XmRESIZE_NONE,
212 NULL);
213
214 m_workArea = (WXWidget) XtVaCreateWidget("form",
215 xmFormWidgetClass, (Widget) m_frameWidget,
216 XmNresizePolicy, XmRESIZE_NONE,
217 NULL);
218
219 m_clientArea = (WXWidget) XtVaCreateWidget("client",
220 xmBulletinBoardWidgetClass, (Widget) m_workArea,
221 XmNmarginWidth, 0,
222 XmNmarginHeight, 0,
223 XmNrightAttachment, XmATTACH_FORM,
224 XmNleftAttachment, XmATTACH_FORM,
225 XmNtopAttachment, XmATTACH_FORM,
226 XmNbottomAttachment, XmATTACH_FORM,
227 // XmNresizePolicy, XmRESIZE_ANY,
228 NULL);
229
230 wxLogTrace(wxTRACE_Messages,
231 "Created frame (0x%08x) with work area 0x%08x and client "
232 "area 0x%08x", m_frameWidget, m_workArea, m_clientArea);
233
234 XtAddEventHandler((Widget) m_clientArea, ExposureMask,FALSE,
235 wxUniversalRepaintProc, (XtPointer) this);
236
237 XtVaSetValues((Widget) m_frameWidget,
238 XmNworkWindow, (Widget) m_workArea,
239 NULL);
240
241 XtManageChild((Widget) m_clientArea);
242 XtManageChild((Widget) m_workArea);
243
244 wxAddWindowToTable((Widget) m_workArea, this);
245
246 XtTranslations ptr;
247
248 XtOverrideTranslations((Widget) m_workArea,
249 ptr = XtParseTranslationTable("<Configure>: resize()"));
250
251 XtFree((char *)ptr);
252
253 XtAddCallback((Widget) m_workArea, XmNfocusCallback,
254 (XtCallbackProc)wxFrameFocusProc, (XtPointer)this);
255
256 /* Part of show-&-hide fix */
257 XtAddEventHandler((Widget) m_frameShell, StructureNotifyMask,
258 False, (XtEventHandler)wxFrameMapProc,
259 (XtPointer)m_workArea);
260
261 if (x > -1)
262 XtVaSetValues((Widget) m_frameShell, XmNx, x, NULL);
263 if (y > -1)
264 XtVaSetValues((Widget) m_frameShell, XmNy, y, NULL);
265 if (width > -1)
266 XtVaSetValues((Widget) m_frameShell, XmNwidth, width, NULL);
267 if (height > -1)
268 XtVaSetValues((Widget) m_frameShell, XmNheight, height, NULL);
269
270 m_mainWidget = m_frameWidget;
271
272 ChangeFont(FALSE);
273
274 // This patch comes from Torsten Liermann lier@lier1.muc.de
275 if (XmIsMotifWMRunning( (Widget) m_frameShell ))
276 {
277 int decor = 0;
278 if (style & wxRESIZE_BORDER)
279 decor |= MWM_DECOR_RESIZEH;
280 if (style & wxSYSTEM_MENU)
281 decor |= MWM_DECOR_MENU;
282 if ((style & wxCAPTION) ||
283 (style & wxTINY_CAPTION_HORIZ) ||
284 (style & wxTINY_CAPTION_VERT))
285 decor |= MWM_DECOR_TITLE;
286 if (style & wxTHICK_FRAME)
287 decor |= MWM_DECOR_BORDER;
288 if (style & wxTHICK_FRAME)
289 decor |= MWM_DECOR_BORDER;
290 if (style & wxMINIMIZE_BOX)
291 decor |= MWM_DECOR_MINIMIZE;
292 if (style & wxMAXIMIZE_BOX)
293 decor |= MWM_DECOR_MAXIMIZE;
294 XtVaSetValues((Widget) m_frameShell,XmNmwmDecorations,decor,NULL);
295 }
296 // This allows non-Motif window managers to support at least the
297 // no-decorations case.
298 else
299 {
300 if (style == 0)
301 XtVaSetValues((Widget) m_frameShell,XmNoverrideRedirect,TRUE,NULL);
302 }
303 XtRealizeWidget((Widget) m_frameShell);
304
305 // Intercept CLOSE messages from the window manager
306 Atom WM_DELETE_WINDOW = XmInternAtom(XtDisplay((Widget) m_frameShell), "WM_DELETE_WINDOW", False);
307 #if (XmREVISION > 1 || XmVERSION > 1)
308 XmAddWMProtocolCallback((Widget) m_frameShell, WM_DELETE_WINDOW, (XtCallbackProc) wxCloseFrameCallback, (XtPointer)this);
309 #else
310 #if XmREVISION == 1
311 XmAddWMProtocolCallback((Widget) m_frameShell, WM_DELETE_WINDOW, (XtCallbackProc) wxCloseFrameCallback, (caddr_t)this);
312 #else
313 XmAddWMProtocolCallback((Widget) m_frameShell, WM_DELETE_WINDOW, (void (*)())wxCloseFrameCallback, (caddr_t)this);
314 #endif
315 #endif
316
317 ChangeBackgroundColour();
318
319 PreResize();
320
321 wxSizeEvent sizeEvent(wxSize(width, height), GetId());
322 sizeEvent.SetEventObject(this);
323
324 GetEventHandler()->ProcessEvent(sizeEvent);
325
326 return TRUE;
327 }
328
329 wxFrame::~wxFrame()
330 {
331 m_isBeingDeleted = TRUE;
332
333 if (m_clientArea)
334 XtRemoveEventHandler((Widget) m_clientArea, ExposureMask, FALSE,
335 wxUniversalRepaintProc, (XtPointer) this);
336
337 if (GetMainWidget())
338 Show(FALSE);
339
340 if (m_frameMenuBar)
341 {
342 m_frameMenuBar->DestroyMenuBar();
343
344 // Hack to stop core dump on Ultrix, OSF, for some strange reason.
345 #if MOTIF_MENUBAR_DELETE_FIX
346 GetMenuBar()->SetMainWidget((WXWidget) NULL);
347 #endif
348 delete m_frameMenuBar;
349 m_frameMenuBar = NULL;
350 }
351
352 wxTopLevelWindows.DeleteObject(this);
353 wxModelessWindows.DeleteObject(this);
354
355 if (m_frameStatusBar)
356 {
357 delete m_frameStatusBar;
358 m_frameStatusBar = NULL;
359 }
360
361 DestroyChildren();
362
363 if (m_workArea)
364 {
365 wxDeleteWindowFromTable((Widget) m_workArea);
366
367 XtDestroyWidget ((Widget) m_workArea);
368 }
369
370 if (m_frameWidget)
371 {
372 wxDeleteWindowFromTable((Widget) m_frameWidget);
373 XtDestroyWidget ((Widget) m_frameWidget);
374 }
375
376 if (m_frameShell)
377 XtDestroyWidget ((Widget) m_frameShell);
378
379 SetMainWidget((WXWidget) NULL);
380
381 /* Check if it's the last top-level window */
382
383 if (wxTheApp && (wxTopLevelWindows.Number() == 0))
384 {
385 wxTheApp->SetTopWindow(NULL);
386
387 if (wxTheApp->GetExitOnFrameDelete())
388 {
389 // Signal to the app that we're going to close
390 wxTheApp->ExitMainLoop();
391 }
392 }
393 }
394
395 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
396 void wxFrame::DoGetClientSize(int *x, int *y) const
397 {
398 Dimension xx, yy;
399 XtVaGetValues((Widget) m_workArea, XmNwidth, &xx, XmNheight, &yy, NULL);
400
401 if (m_frameStatusBar)
402 {
403 int sbw, sbh;
404 m_frameStatusBar->GetSize(& sbw, & sbh);
405 yy -= sbh;
406 }
407 #if wxUSE_TOOLBAR
408 if (m_frameToolBar)
409 {
410 int tbw, tbh;
411 m_frameToolBar->GetSize(& tbw, & tbh);
412 if (m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL)
413 xx -= tbw;
414 else
415 yy -= tbh;
416 }
417 #endif // wxUSE_TOOLBAR
418 /*
419 if (GetMenuBar() != (wxMenuBar*) NULL)
420 {
421 // it seems that if a frame holds a panel, the menu bar size
422 // gets automatically taken care of --- grano@cs.helsinki.fi 4.4.95
423 bool hasSubPanel = FALSE;
424 for(wxNode* node = GetChildren().First(); node; node = node->Next())
425 {
426 wxWindow *win = (wxWindow *)node->Data();
427 hasSubPanel = (win->IsKindOf(CLASSINFO(wxPanel)) && !win->IsKindOf(CLASSINFO(wxDialog)));
428
429 if (hasSubPanel)
430 break;
431 }
432 if (! hasSubPanel) {
433 Dimension ys;
434 XtVaGetValues((Widget) GetMenuBarWidget(), XmNheight, &ys, NULL);
435 yy -= ys;
436 }
437 }
438 */
439
440 *x = xx; *y = yy;
441 }
442
443 // Set the client size (i.e. leave the calculation of borders etc.
444 // to wxWindows)
445 void wxFrame::DoSetClientSize(int width, int height)
446 {
447 // Calculate how large the new main window should be
448 // by finding the difference between the client area and the
449 // main window area, and adding on to the new client area
450 if (width > -1)
451 XtVaSetValues((Widget) m_workArea, XmNwidth, width, NULL);
452
453 if (height > -1)
454 {
455 if (m_frameStatusBar)
456 {
457 int sbw, sbh;
458 m_frameStatusBar->GetSize(& sbw, & sbh);
459 height += sbh;
460 }
461 #if wxUSE_TOOLBAR
462 if (m_frameToolBar)
463 {
464 int tbw, tbh;
465 m_frameToolBar->GetSize(& tbw, & tbh);
466 if (m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL)
467 width += tbw;
468 else
469 height += tbh;
470 }
471 #endif // wxUSE_TOOLBAR
472
473 XtVaSetValues((Widget) m_workArea, XmNheight, height, NULL);
474 }
475 PreResize();
476
477 wxSizeEvent sizeEvent(wxSize(width, height), GetId());
478 sizeEvent.SetEventObject(this);
479
480 GetEventHandler()->ProcessEvent(sizeEvent);
481
482 }
483
484 void wxFrame::DoGetSize(int *width, int *height) const
485 {
486 Dimension xx, yy;
487 XtVaGetValues((Widget) m_frameShell, XmNwidth, &xx, XmNheight, &yy, NULL);
488 *width = xx; *height = yy;
489 }
490
491 void wxFrame::DoGetPosition(int *x, int *y) const
492 {
493 Window parent_window = XtWindow((Widget) m_frameShell),
494 next_parent = XtWindow((Widget) m_frameShell),
495 root = RootWindowOfScreen(XtScreen((Widget) m_frameShell));
496
497 // search for the parent that is child of ROOT, because the WM may
498 // reparent twice and notify only the next parent (like FVWM)
499 while (next_parent != root) {
500 Window *theChildren; unsigned int n;
501 parent_window = next_parent;
502 XQueryTree(XtDisplay((Widget) m_frameShell), parent_window, &root,
503 &next_parent, &theChildren, &n);
504 XFree(theChildren); // not needed
505 }
506 int xx, yy; unsigned int dummy;
507 XGetGeometry(XtDisplay((Widget) m_frameShell), parent_window, &root,
508 &xx, &yy, &dummy, &dummy, &dummy, &dummy);
509 if (x) *x = xx;
510 if (y) *y = yy;
511 }
512
513 void wxFrame::DoSetSize(int x, int y, int width, int height, int WXUNUSED(sizeFlags))
514 {
515 if (x > -1)
516 XtVaSetValues((Widget) m_frameShell, XmNx, x, NULL);
517 if (y > -1)
518 XtVaSetValues((Widget) m_frameShell, XmNy, y, NULL);
519 if (width > -1)
520 XtVaSetValues((Widget) m_frameWidget, XmNwidth, width, NULL);
521 if (height > -1)
522 XtVaSetValues((Widget) m_frameWidget, XmNheight, height, NULL);
523
524 if (!(height == -1 && width == -1))
525 {
526 PreResize();
527
528 wxSizeEvent sizeEvent(wxSize(width, height), GetId());
529 sizeEvent.SetEventObject(this);
530
531 GetEventHandler()->ProcessEvent(sizeEvent);
532 }
533 }
534
535 bool wxFrame::Show(bool show)
536 {
537 if (!m_frameShell)
538 return wxWindow::Show(show);
539
540 m_visibleStatus = show; /* show-&-hide fix */
541
542 m_isShown = show;
543 if (show) {
544 XtMapWidget((Widget) m_frameShell);
545 XRaiseWindow(XtDisplay((Widget) m_frameShell), XtWindow((Widget) m_frameShell));
546 } else {
547 XtUnmapWidget((Widget) m_frameShell);
548 // XmUpdateDisplay(wxTheApp->topLevel); // Experimental: may be responsible for crashes
549 }
550 return TRUE;
551 }
552
553 void wxFrame::Iconize(bool iconize)
554 {
555 if (!iconize)
556 Show(TRUE);
557
558 if (m_frameShell)
559 XtVaSetValues((Widget) m_frameShell, XmNiconic, (Boolean)iconize, NULL);
560 }
561
562 void wxFrame::Restore()
563 {
564 if ( m_frameShell )
565 XtVaSetValues((Widget) m_frameShell, XmNiconic, FALSE, NULL);
566 }
567
568 void wxFrame::Maximize(bool maximize)
569 {
570 Show(TRUE);
571
572 if ( maximize )
573 Restore();
574 }
575
576 bool wxFrame::IsIconized() const
577 {
578 if (!m_frameShell)
579 return FALSE;
580
581 Boolean iconic;
582 XtVaGetValues((Widget) m_frameShell, XmNiconic, &iconic, NULL);
583 return iconic;
584 }
585
586 // Is it maximized?
587 bool wxFrame::IsMaximized() const
588 {
589 // No maximizing in Motif (?)
590 return FALSE;
591 }
592
593 void wxFrame::SetTitle(const wxString& title)
594 {
595 if (title == m_title)
596 return;
597
598 m_title = title;
599
600 if (!title.IsNull())
601 XtVaSetValues((Widget) m_frameShell,
602 XmNtitle, title.c_str(),
603 XmNiconName, title.c_str(),
604 NULL);
605 }
606
607 void wxFrame::SetIcon(const wxIcon& icon)
608 {
609 m_icon = icon;
610
611 if (!m_frameShell)
612 return;
613
614 if (!icon.Ok() || !icon.GetPixmap())
615 return;
616
617 XtVaSetValues((Widget) m_frameShell, XtNiconPixmap, icon.GetPixmap(), NULL);
618 }
619
620 void wxFrame::PositionStatusBar()
621 {
622 if (!m_frameStatusBar)
623 return;
624
625 int w, h;
626 GetClientSize(&w, &h);
627 int sw, sh;
628 m_frameStatusBar->GetSize(&sw, &sh);
629
630 // Since we wish the status bar to be directly under the client area,
631 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
632 m_frameStatusBar->SetSize(0, h, w, sh);
633 }
634
635 WXWidget wxFrame::GetMenuBarWidget() const
636 {
637 if (GetMenuBar())
638 return GetMenuBar()->GetMainWidget();
639 else
640 return (WXWidget) NULL;
641 }
642
643 void wxFrame::SetMenuBar(wxMenuBar *menuBar)
644 {
645 if (!menuBar)
646 {
647 m_frameMenuBar = NULL;
648 return;
649 }
650
651 // Currently can't set it twice
652 // wxASSERT_MSG( (m_frameMenuBar == (wxMenuBar*) NULL), "Cannot set the menubar more than once");
653
654 if (m_frameMenuBar)
655 {
656 m_frameMenuBar->DestroyMenuBar();
657 delete m_frameMenuBar;
658 }
659
660 m_frameMenuBar = menuBar;
661 m_frameMenuBar->CreateMenuBar(this);
662 }
663
664 // Responds to colour changes, and passes event on to children.
665 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
666 {
667 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
668 Refresh();
669
670 if ( m_frameStatusBar )
671 {
672 wxSysColourChangedEvent event2;
673 event2.SetEventObject( m_frameStatusBar );
674 m_frameStatusBar->ProcessEvent(event2);
675 }
676
677 // Propagate the event to the non-top-level children
678 wxWindow::OnSysColourChanged(event);
679 }
680
681 // Default activation behaviour - set the focus for the first child
682 // subwindow found.
683 void wxFrame::OnActivate(wxActivateEvent& event)
684 {
685 if (!event.GetActive())
686 return;
687
688 for(wxNode *node = GetChildren().First(); node; node = node->Next())
689 {
690 // Find a child that's a subwindow, but not a dialog box.
691 wxWindow *child = (wxWindow *)node->Data();
692 if (!child->IsKindOf(CLASSINFO(wxFrame)) &&
693 !child->IsKindOf(CLASSINFO(wxDialog)))
694 {
695 child->SetFocus();
696 return;
697 }
698 }
699 }
700
701 #if wxUSE_TOOLBAR
702
703 wxToolBar* wxFrame::CreateToolBar(long style,
704 wxWindowID id,
705 const wxString& name)
706 {
707 if ( wxFrameBase::CreateToolBar(style, id, name) )
708 {
709 PositionToolBar();
710 }
711
712 return m_frameToolBar;
713 }
714
715 void wxFrame::PositionToolBar()
716 {
717 if (GetToolBar())
718 {
719 int cw, ch;
720 GetClientSize(& cw, &ch);
721
722 int tw, th;
723 GetToolBar()->GetSize(& tw, & th);
724
725 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
726 {
727 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
728 // means, pretend we don't have toolbar/status bar, so we
729 // have the original client size.
730 GetToolBar()->SetSize(0, 0, tw, ch + th, wxSIZE_NO_ADJUSTMENTS);
731 }
732 else
733 {
734 // Use the 'real' position
735 GetToolBar()->SetSize(0, 0, cw, th, wxSIZE_NO_ADJUSTMENTS);
736 }
737 }
738 }
739 #endif // wxUSE_TOOLBAR
740
741 void wxFrame::Raise()
742 {
743 Window parent_window = XtWindow((Widget) m_frameShell),
744 next_parent = XtWindow((Widget) m_frameShell),
745 root = RootWindowOfScreen(XtScreen((Widget) m_frameShell));
746 // search for the parent that is child of ROOT, because the WM may
747 // reparent twice and notify only the next parent (like FVWM)
748 while (next_parent != root) {
749 Window *theChildren; unsigned int n;
750 parent_window = next_parent;
751 XQueryTree(XtDisplay((Widget) m_frameShell), parent_window, &root,
752 &next_parent, &theChildren, &n);
753 XFree(theChildren); // not needed
754 }
755 XRaiseWindow(XtDisplay((Widget) m_frameShell), parent_window);
756 }
757
758 void wxFrame::Lower()
759 {
760 Window parent_window = XtWindow((Widget) m_frameShell),
761 next_parent = XtWindow((Widget) m_frameShell),
762 root = RootWindowOfScreen(XtScreen((Widget) m_frameShell));
763 // search for the parent that is child of ROOT, because the WM may
764 // reparent twice and notify only the next parent (like FVWM)
765 while (next_parent != root) {
766 Window *theChildren; unsigned int n;
767 parent_window = next_parent;
768 XQueryTree(XtDisplay((Widget) m_frameShell), parent_window, &root,
769 &next_parent, &theChildren, &n);
770 XFree(theChildren); // not needed
771 }
772 XLowerWindow(XtDisplay((Widget) m_frameShell), parent_window);
773 }
774
775 void wxFrameFocusProc(Widget WXUNUSED(workArea), XtPointer WXUNUSED(clientData),
776 XmAnyCallbackStruct *WXUNUSED(cbs))
777 {
778 // wxDebugMsg("focus proc from frame %ld\n",(long)frame);
779 // TODO
780 // wxFrame *frame = (wxFrame *)clientData;
781 // frame->GetEventHandler()->OnSetFocus();
782 }
783
784 /* MATTEW: Used to insure that hide-&-show within an event cycle works */
785 static void wxFrameMapProc(Widget frameShell, XtPointer clientData,
786 XCrossingEvent * event)
787 {
788 wxFrame *frame = (wxFrame *)wxGetWindowFromTable((Widget)clientData);
789
790 if (frame) {
791 XEvent *e = (XEvent *)event;
792
793 if (e->xany.type == MapNotify)
794 {
795 // Iconize fix
796 XtVaSetValues(frameShell, XmNiconic, (Boolean)False, NULL);
797 if (!frame->GetVisibleStatus())
798 {
799 /* We really wanted this to be hidden! */
800 XtUnmapWidget((Widget) frame->GetShellWidget());
801 }
802 }
803 else if (e->xany.type == UnmapNotify)
804 // Iconize fix
805 XtVaSetValues(frameShell, XmNiconic, (Boolean)True, NULL);
806 }
807 }
808
809 //// Motif-specific
810 bool wxFrame::PreResize()
811 {
812 #if wxUSE_TOOLBAR
813 PositionToolBar();
814 #endif // wxUSE_TOOLBAR
815
816 #if wxUSE_STATUSBAR
817 PositionStatusBar();
818 #endif // wxUSE_STATUSBAR
819
820 return TRUE;
821 }
822
823 WXWidget wxFrame::GetClientWidget() const
824 {
825 return m_clientArea;
826 }
827
828 void wxFrame::ChangeFont(bool WXUNUSED(keepOriginalSize))
829 {
830 // TODO
831 }
832
833 void wxFrame::ChangeBackgroundColour()
834 {
835 if (GetClientWidget())
836 DoChangeBackgroundColour(GetClientWidget(), m_backgroundColour);
837 }
838
839 void wxFrame::ChangeForegroundColour()
840 {
841 if (GetClientWidget())
842 DoChangeForegroundColour(GetClientWidget(), m_foregroundColour);
843 }
844
845 void wxCloseFrameCallback(Widget WXUNUSED(widget), XtPointer client_data, XmAnyCallbackStruct *WXUNUSED(cbs))
846 {
847 wxFrame *frame = (wxFrame *)client_data;
848
849 wxCloseEvent closeEvent(wxEVT_CLOSE_WINDOW, frame->GetId());
850 closeEvent.SetEventObject(frame);
851
852 // May delete the frame (with delayed deletion)
853 frame->GetEventHandler()->ProcessEvent(closeEvent);
854 }
855