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