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