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