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