]>
Commit | Line | Data |
---|---|---|
4bb6408c JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: 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 | #ifdef __GNUG__ | |
13 | #pragma implementation "frame.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/frame.h" | |
17 | #include "wx/statusbr.h" | |
18 | #include "wx/toolbar.h" | |
19 | #include "wx/menuitem.h" | |
20 | #include "wx/menu.h" | |
21 | #include "wx/dcclient.h" | |
22 | #include "wx/dialog.h" | |
23 | #include "wx/settings.h" | |
24 | #include "wx/app.h" | |
25 | #include "wx/utils.h" | |
26 | ||
27 | #if defined(__ultrix) || defined(__sgi) | |
28 | #include <Xm/Frame.h> | |
29 | #endif | |
30 | ||
31 | #include <Xm/Xm.h> | |
32 | #include <X11/Shell.h> | |
33 | #if XmVersion >= 1002 | |
34 | #include <Xm/XmAll.h> | |
35 | #else | |
36 | #include <Xm/Frame.h> | |
37 | #endif | |
38 | #include <Xm/MwmUtil.h> | |
39 | #include <Xm/BulletinB.h> | |
40 | #include <Xm/Form.h> | |
41 | #include <Xm/MainW.h> | |
42 | #include <Xm/RowColumn.h> | |
43 | #include <Xm/Label.h> | |
44 | #include <Xm/AtomMgr.h> | |
45 | #include <Xm/LabelG.h> | |
46 | #include <Xm/Frame.h> | |
47 | #if XmVersion > 1000 | |
48 | #include <Xm/Protocols.h> | |
49 | #endif | |
50 | ||
51 | #include "wx/motif/private.h" | |
52 | ||
53 | void wxCloseFrameCallback(Widget, XtPointer, XmAnyCallbackStruct *cbs); | |
8704bf74 | 54 | void wxFrameFocusProc(Widget workArea, XtPointer clientData, |
4bb6408c JS |
55 | XmAnyCallbackStruct *cbs); |
56 | static void wxFrameMapProc(Widget frameShell, XtPointer clientData, | |
57 | XCrossingEvent * event); | |
58 | ||
59 | extern wxList wxModelessWindows; | |
60 | extern wxList wxPendingDelete; | |
61 | ||
62 | // TODO: this should be tidied so that any frame can be the | |
63 | // top frame | |
64 | static bool wxTopLevelUsed = FALSE; | |
65 | ||
66 | #if !USE_SHARED_LIBRARY | |
67 | BEGIN_EVENT_TABLE(wxFrame, wxWindow) | |
68 | EVT_SIZE(wxFrame::OnSize) | |
69 | EVT_ACTIVATE(wxFrame::OnActivate) | |
70 | EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight) | |
71 | EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged) | |
72 | EVT_IDLE(wxFrame::OnIdle) | |
73 | EVT_CLOSE(wxFrame::OnCloseWindow) | |
74 | END_EVENT_TABLE() | |
75 | ||
76 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow) | |
77 | #endif | |
78 | ||
47d67540 | 79 | #if wxUSE_NATIVE_STATUSBAR |
4bb6408c JS |
80 | bool wxFrame::m_useNativeStatusBar = TRUE; |
81 | #else | |
82 | bool wxFrame::m_useNativeStatusBar = FALSE; | |
83 | #endif | |
84 | ||
85 | wxFrame::wxFrame() | |
86 | { | |
87 | m_frameToolBar = NULL ; | |
88 | m_frameMenuBar = NULL; | |
89 | m_frameStatusBar = NULL; | |
90 | ||
91 | m_windowParent = NULL; | |
92 | m_iconized = FALSE; | |
93 | ||
94 | //// Motif-specific | |
95 | m_frameShell = (WXWidget) NULL; | |
96 | m_frameWidget = (WXWidget) NULL;; | |
97 | m_workArea = (WXWidget) NULL;; | |
98 | m_clientArea = (WXWidget) NULL;; | |
99 | m_visibleStatus = TRUE; | |
100 | m_title = ""; | |
101 | } | |
102 | ||
103 | bool wxFrame::Create(wxWindow *parent, | |
104 | wxWindowID id, | |
105 | const wxString& title, | |
106 | const wxPoint& pos, | |
107 | const wxSize& size, | |
108 | long style, | |
109 | const wxString& name) | |
110 | { | |
111 | if (!parent) | |
112 | wxTopLevelWindows.Append(this); | |
113 | ||
114 | SetName(name); | |
115 | ||
116 | m_windowStyle = style; | |
117 | m_frameMenuBar = NULL; | |
118 | m_frameToolBar = NULL ; | |
119 | m_frameStatusBar = NULL; | |
120 | ||
121 | //// Motif-specific | |
122 | m_frameShell = (WXWidget) NULL; | |
123 | m_frameWidget = (WXWidget) NULL;; | |
124 | m_workArea = (WXWidget) NULL;; | |
125 | m_clientArea = (WXWidget) NULL;; | |
126 | m_visibleStatus = TRUE; | |
127 | m_title = ""; | |
128 | ||
0d57be45 JS |
129 | m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE); |
130 | m_foregroundColour = *wxBLACK; | |
4b5f3fe6 | 131 | m_windowFont = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT); |
4bb6408c JS |
132 | |
133 | if ( id > -1 ) | |
134 | m_windowId = id; | |
135 | else | |
136 | m_windowId = (int)NewControlId(); | |
137 | ||
138 | if (parent) parent->AddChild(this); | |
139 | ||
140 | wxModelessWindows.Append(this); | |
141 | ||
142 | int x = pos.x; int y = pos.y; | |
143 | int width = size.x; int height = size.y; | |
144 | ||
145 | if (wxTopLevelUsed) | |
146 | // Change suggested by Matthew Flatt | |
147 | m_frameShell = (WXWidget) XtAppCreateShell(name, wxTheApp->GetClassName(), topLevelShellWidgetClass, (Display*) wxGetDisplay(), NULL, 0); | |
148 | else | |
149 | { | |
150 | m_frameShell = wxTheApp->GetTopLevelWidget(); | |
151 | wxTopLevelUsed = TRUE; | |
152 | } | |
153 | ||
154 | XtVaSetValues((Widget) m_frameShell, | |
155 | // Allows menu to resize | |
156 | XmNallowShellResize, True, | |
157 | XmNdeleteResponse, XmDO_NOTHING, | |
158 | XmNmappedWhenManaged, False, | |
159 | XmNiconic, (style & wxICONIZE) ? TRUE : FALSE, | |
160 | NULL); | |
161 | ||
162 | if (!title.IsNull()) | |
163 | XtVaSetValues((Widget) m_frameShell, | |
164 | XmNtitle, (const char*) title, | |
165 | NULL); | |
166 | ||
167 | m_frameWidget = (WXWidget) XtVaCreateManagedWidget("main_window", | |
168 | xmMainWindowWidgetClass, (Widget) m_frameShell, | |
169 | XmNresizePolicy, XmRESIZE_NONE, | |
170 | NULL); | |
171 | ||
172 | m_workArea = (WXWidget) XtVaCreateWidget("form", | |
173 | xmFormWidgetClass, (Widget) m_frameWidget, | |
174 | XmNresizePolicy, XmRESIZE_NONE, | |
175 | NULL); | |
176 | ||
177 | m_clientArea = (WXWidget) XtVaCreateWidget("client", | |
178 | xmBulletinBoardWidgetClass, (Widget) m_workArea, | |
179 | XmNmarginWidth, 0, | |
180 | XmNmarginHeight, 0, | |
181 | XmNrightAttachment, XmATTACH_FORM, | |
182 | XmNleftAttachment, XmATTACH_FORM, | |
183 | XmNtopAttachment, XmATTACH_FORM, | |
184 | XmNbottomAttachment, XmATTACH_FORM, | |
185 | // XmNresizePolicy, XmRESIZE_ANY, | |
186 | NULL); | |
187 | ||
188 | XtVaSetValues((Widget) m_frameWidget, | |
189 | XmNworkWindow, (Widget) m_workArea, | |
190 | NULL); | |
191 | ||
192 | ||
193 | XtManageChild((Widget) m_clientArea); | |
194 | XtManageChild((Widget) m_workArea); | |
195 | ||
196 | wxASSERT_MSG ((wxWidgetHashTable->Get((long)m_workArea) == (wxObject*) NULL), "Widget table clash in frame.cpp") ; | |
197 | ||
198 | wxAddWindowToTable((Widget) m_workArea, this); | |
199 | ||
200 | XtTranslations ptr ; | |
201 | ||
202 | XtOverrideTranslations((Widget) m_workArea, | |
203 | ptr = XtParseTranslationTable("<Configure>: resize()")); | |
204 | ||
205 | XtFree((char *)ptr); | |
206 | ||
207 | XtAddCallback((Widget) m_workArea, XmNfocusCallback, | |
208 | (XtCallbackProc)wxFrameFocusProc, (XtPointer)this); | |
209 | ||
210 | /* Part of show-&-hide fix */ | |
211 | XtAddEventHandler((Widget) m_frameShell, StructureNotifyMask, | |
212 | False, (XtEventHandler)wxFrameMapProc, | |
213 | (XtPointer)m_workArea); | |
214 | ||
215 | if (x > -1) | |
216 | XtVaSetValues((Widget) m_frameShell, XmNx, x, NULL); | |
217 | if (y > -1) | |
218 | XtVaSetValues((Widget) m_frameShell, XmNy, y, NULL); | |
219 | if (width > -1) | |
220 | XtVaSetValues((Widget) m_frameShell, XmNwidth, width, NULL); | |
221 | if (height > -1) | |
222 | XtVaSetValues((Widget) m_frameShell, XmNheight, height, NULL); | |
223 | ||
224 | m_mainWidget = m_frameWidget; | |
225 | ||
4b5f3fe6 JS |
226 | ChangeFont(FALSE); |
227 | ||
4bb6408c | 228 | // This patch comes from Torsten Liermann lier@lier1.muc.de |
dfc54541 | 229 | if (XmIsMotifWMRunning( (Widget) m_frameShell )) |
4bb6408c JS |
230 | { |
231 | int decor = 0 ; | |
232 | if (style & wxRESIZE_BORDER) | |
233 | decor |= MWM_DECOR_RESIZEH ; | |
234 | if (style & wxSYSTEM_MENU) | |
235 | decor |= MWM_DECOR_MENU; | |
236 | if ((style & wxCAPTION) || | |
237 | (style & wxTINY_CAPTION_HORIZ) || | |
238 | (style & wxTINY_CAPTION_VERT)) | |
239 | decor |= MWM_DECOR_TITLE; | |
240 | if (style & wxTHICK_FRAME) | |
241 | decor |= MWM_DECOR_BORDER; | |
242 | if (style & wxTHICK_FRAME) | |
243 | decor |= MWM_DECOR_BORDER; | |
244 | if (style & wxMINIMIZE_BOX) | |
245 | decor |= MWM_DECOR_MINIMIZE; | |
246 | if (style & wxMAXIMIZE_BOX) | |
247 | decor |= MWM_DECOR_MAXIMIZE; | |
248 | XtVaSetValues((Widget) m_frameShell,XmNmwmDecorations,decor,NULL) ; | |
249 | } | |
250 | // This allows non-Motif window managers to support at least the | |
251 | // no-decorations case. | |
252 | else | |
253 | { | |
254 | if (style == 0) | |
dfc54541 | 255 | XtVaSetValues((Widget) m_frameShell,XmNoverrideRedirect,TRUE,NULL); |
4bb6408c JS |
256 | } |
257 | XtRealizeWidget((Widget) m_frameShell); | |
258 | ||
259 | // Intercept CLOSE messages from the window manager | |
260 | Atom WM_DELETE_WINDOW = XmInternAtom(XtDisplay((Widget) m_frameShell), "WM_DELETE_WINDOW", False); | |
261 | #if (XmREVISION > 1 || XmVERSION > 1) | |
262 | XmAddWMProtocolCallback((Widget) m_frameShell, WM_DELETE_WINDOW, (XtCallbackProc) wxCloseFrameCallback, (XtPointer)this); | |
263 | #else | |
264 | #if XmREVISION == 1 | |
265 | XmAddWMProtocolCallback((Widget) m_frameShell, WM_DELETE_WINDOW, (XtCallbackProc) wxCloseFrameCallback, (caddr_t)this); | |
266 | #else | |
267 | XmAddWMProtocolCallback((Widget) m_frameShell, WM_DELETE_WINDOW, (void (*)())wxCloseFrameCallback, (caddr_t)this); | |
268 | #endif | |
269 | #endif | |
270 | ||
0d57be45 JS |
271 | ChangeBackgroundColour(); |
272 | ||
4bb6408c JS |
273 | PreResize(); |
274 | ||
275 | wxSizeEvent sizeEvent(wxSize(width, height), GetId()); | |
276 | sizeEvent.SetEventObject(this); | |
277 | ||
278 | GetEventHandler()->ProcessEvent(sizeEvent); | |
279 | ||
280 | return TRUE; | |
281 | } | |
282 | ||
283 | wxFrame::~wxFrame() | |
284 | { | |
285 | if (GetMainWidget()) | |
286 | Show(FALSE); | |
287 | ||
288 | if (m_frameMenuBar) | |
289 | { | |
621793f4 JS |
290 | m_frameMenuBar->DestroyMenuBar(); |
291 | ||
4bb6408c JS |
292 | // Hack to stop core dump on Ultrix, OSF, for some strange reason. |
293 | #if MOTIF_MENUBAR_DELETE_FIX | |
294 | GetMenuBar()->SetMainWidget((WXWidget) NULL); | |
295 | #endif | |
296 | delete m_frameMenuBar; | |
297 | m_frameMenuBar = NULL; | |
298 | } | |
299 | ||
300 | wxTopLevelWindows.DeleteObject(this); | |
301 | wxModelessWindows.DeleteObject(this); | |
302 | ||
303 | if (m_frameStatusBar) | |
304 | delete m_frameStatusBar; | |
305 | ||
306 | DestroyChildren(); | |
307 | ||
308 | /* | |
309 | int i; | |
310 | for (i = 0; i < wxMAX_STATUS; i++) | |
311 | if (statusTextWidget[i]) | |
312 | XtDestroyWidget (statusTextWidget[i]); | |
313 | ||
314 | if (statusLineForm) | |
315 | XtDestroyWidget (statusLineForm); | |
316 | ||
317 | if (statusLineWidget) | |
318 | XtDestroyWidget (statusLineWidget); | |
319 | */ | |
320 | ||
8704bf74 JS |
321 | if (m_workArea) |
322 | { | |
323 | wxDeleteWindowFromTable((Widget) m_workArea); | |
4bb6408c | 324 | |
8704bf74 JS |
325 | XtDestroyWidget ((Widget) m_workArea); |
326 | } | |
4bb6408c | 327 | |
8704bf74 JS |
328 | if (m_frameWidget) |
329 | { | |
330 | wxDeleteWindowFromTable((Widget) m_frameWidget); | |
331 | XtDestroyWidget ((Widget) m_frameWidget); | |
332 | } | |
4bb6408c | 333 | |
8704bf74 JS |
334 | if (m_frameShell) |
335 | XtDestroyWidget ((Widget) m_frameShell); | |
4bb6408c JS |
336 | |
337 | SetMainWidget((WXWidget) NULL); | |
338 | ||
339 | /* Check if it's the last top-level window */ | |
340 | ||
341 | if (wxTheApp && (wxTopLevelWindows.Number() == 0)) | |
342 | { | |
343 | wxTheApp->SetTopWindow(NULL); | |
344 | ||
345 | if (wxTheApp->GetExitOnFrameDelete()) | |
346 | { | |
dfc54541 | 347 | // Signal to the app that we're going to close |
4bb6408c JS |
348 | wxTheApp->ExitMainLoop(); |
349 | } | |
350 | } | |
351 | ||
352 | } | |
353 | ||
354 | // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc. | |
355 | void wxFrame::GetClientSize(int *x, int *y) const | |
356 | { | |
357 | Dimension xx, yy; | |
358 | XtVaGetValues((Widget) m_workArea, XmNwidth, &xx, XmNheight, &yy, NULL); | |
359 | ||
89c7e962 | 360 | if (m_frameStatusBar) |
4bb6408c | 361 | { |
89c7e962 JS |
362 | int sbw, sbh; |
363 | m_frameStatusBar->GetSize(& sbw, & sbh); | |
364 | yy -= sbh; | |
4bb6408c | 365 | } |
a4294b78 JS |
366 | if (m_frameToolBar) |
367 | { | |
368 | int tbw, tbh; | |
369 | m_frameToolBar->GetSize(& tbw, & tbh); | |
370 | if (m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL) | |
371 | xx -= tbw; | |
372 | else | |
373 | yy -= tbh; | |
374 | } | |
375 | /* | |
4bb6408c JS |
376 | if (GetMenuBar() != (wxMenuBar*) NULL) |
377 | { | |
378 | // it seems that if a frame holds a panel, the menu bar size | |
379 | // gets automatically taken care of --- grano@cs.helsinki.fi 4.4.95 | |
380 | bool hasSubPanel = FALSE; | |
c0ed460c | 381 | for(wxNode* node = GetChildren().First(); node; node = node->Next()) |
4bb6408c JS |
382 | { |
383 | wxWindow *win = (wxWindow *)node->Data(); | |
384 | hasSubPanel = (win->IsKindOf(CLASSINFO(wxPanel)) && !win->IsKindOf(CLASSINFO(wxDialog))); | |
385 | ||
386 | if (hasSubPanel) | |
387 | break; | |
388 | } | |
389 | if (! hasSubPanel) { | |
390 | Dimension ys; | |
391 | XtVaGetValues((Widget) GetMenuBarWidget(), XmNheight, &ys, NULL); | |
392 | yy -= ys; | |
393 | } | |
394 | } | |
a4294b78 | 395 | */ |
4bb6408c JS |
396 | |
397 | *x = xx; *y = yy; | |
398 | } | |
399 | ||
400 | // Set the client size (i.e. leave the calculation of borders etc. | |
401 | // to wxWindows) | |
402 | void wxFrame::SetClientSize(int width, int height) | |
403 | { | |
404 | // Calculate how large the new main window should be | |
405 | // by finding the difference between the client area and the | |
406 | // main window area, and adding on to the new client area | |
407 | if (width > -1) | |
408 | XtVaSetValues((Widget) m_workArea, XmNwidth, width, NULL); | |
409 | ||
410 | if (height > -1) | |
411 | { | |
a4294b78 | 412 | if (m_frameStatusBar) |
4bb6408c | 413 | { |
a4294b78 JS |
414 | int sbw, sbh; |
415 | m_frameStatusBar->GetSize(& sbw, & sbh); | |
416 | height += sbh; | |
4bb6408c | 417 | } |
a4294b78 JS |
418 | if (m_frameToolBar) |
419 | { | |
420 | int tbw, tbh; | |
421 | m_frameToolBar->GetSize(& tbw, & tbh); | |
422 | if (m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL) | |
423 | width += tbw; | |
424 | else | |
425 | height += tbh; | |
426 | } | |
427 | ||
4bb6408c JS |
428 | XtVaSetValues((Widget) m_workArea, XmNheight, height, NULL); |
429 | } | |
430 | PreResize(); | |
431 | ||
432 | wxSizeEvent sizeEvent(wxSize(width, height), GetId()); | |
433 | sizeEvent.SetEventObject(this); | |
434 | ||
435 | GetEventHandler()->ProcessEvent(sizeEvent); | |
436 | ||
437 | } | |
438 | ||
439 | void wxFrame::GetSize(int *width, int *height) const | |
440 | { | |
441 | Dimension xx, yy; | |
442 | XtVaGetValues((Widget) m_frameShell, XmNwidth, &xx, XmNheight, &yy, NULL); | |
443 | *width = xx; *height = yy; | |
444 | } | |
445 | ||
446 | void wxFrame::GetPosition(int *x, int *y) const | |
447 | { | |
448 | Window parent_window = XtWindow((Widget) m_frameShell), | |
449 | next_parent = XtWindow((Widget) m_frameShell), | |
450 | root = RootWindowOfScreen(XtScreen((Widget) m_frameShell)); | |
451 | ||
452 | // search for the parent that is child of ROOT, because the WM may | |
453 | // reparent twice and notify only the next parent (like FVWM) | |
454 | while (next_parent != root) { | |
455 | Window *theChildren; unsigned int n; | |
456 | parent_window = next_parent; | |
457 | XQueryTree(XtDisplay((Widget) m_frameShell), parent_window, &root, | |
458 | &next_parent, &theChildren, &n); | |
459 | XFree(theChildren); // not needed | |
460 | } | |
461 | int xx, yy; unsigned int dummy; | |
462 | XGetGeometry(XtDisplay((Widget) m_frameShell), parent_window, &root, | |
463 | &xx, &yy, &dummy, &dummy, &dummy, &dummy); | |
464 | if (x) *x = xx; | |
465 | if (y) *y = yy; | |
466 | } | |
467 | ||
468 | void wxFrame::SetSize(int x, int y, int width, int height, int sizeFlags) | |
469 | { | |
470 | if (x > -1) | |
471 | XtVaSetValues((Widget) m_frameShell, XmNx, x, NULL); | |
472 | if (y > -1) | |
473 | XtVaSetValues((Widget) m_frameShell, XmNy, y, NULL); | |
474 | if (width > -1) | |
475 | XtVaSetValues((Widget) m_frameWidget, XmNwidth, width, NULL); | |
476 | if (height > -1) | |
477 | XtVaSetValues((Widget) m_frameWidget, XmNheight, height, NULL); | |
478 | ||
479 | if (!(height == -1 && width == -1)) | |
480 | { | |
481 | PreResize(); | |
7fe7d506 | 482 | /* JACS: not sure if this is necessary |
4bb6408c JS |
483 | wxSizeEvent sizeEvent(wxSize(width, height), GetId()); |
484 | sizeEvent.SetEventObject(this); | |
485 | ||
486 | GetEventHandler()->ProcessEvent(sizeEvent); | |
7fe7d506 | 487 | */ |
4bb6408c JS |
488 | } |
489 | } | |
490 | ||
491 | bool wxFrame::Show(bool show) | |
492 | { | |
621793f4 JS |
493 | if (!m_frameShell) |
494 | return wxWindow::Show(show); | |
495 | ||
4bb6408c JS |
496 | m_visibleStatus = show; /* show-&-hide fix */ |
497 | ||
498 | m_isShown = show; | |
499 | if (show) { | |
500 | XtMapWidget((Widget) m_frameShell); | |
501 | XRaiseWindow(XtDisplay((Widget) m_frameShell), XtWindow((Widget) m_frameShell)); | |
502 | } else { | |
503 | XtUnmapWidget((Widget) m_frameShell); | |
504 | // XmUpdateDisplay(wxTheApp->topLevel); // Experimental: may be responsible for crashes | |
505 | } | |
506 | return TRUE; | |
507 | } | |
508 | ||
509 | void wxFrame::Iconize(bool iconize) | |
510 | { | |
511 | if (!iconize) | |
512 | Show(TRUE); | |
513 | ||
621793f4 JS |
514 | if (m_frameShell) |
515 | XtVaSetValues((Widget) m_frameShell, XmNiconic, (Boolean)iconize, NULL); | |
4bb6408c JS |
516 | } |
517 | ||
518 | // Equivalent to maximize/restore in Windows | |
519 | void wxFrame::Maximize(bool maximize) | |
520 | { | |
521 | Show(TRUE); | |
522 | ||
621793f4 | 523 | if (maximize && m_frameShell) |
4bb6408c JS |
524 | XtVaSetValues((Widget) m_frameShell, XmNiconic, FALSE, NULL); |
525 | } | |
526 | ||
527 | bool wxFrame::IsIconized() const | |
528 | { | |
621793f4 JS |
529 | if (!m_frameShell) |
530 | return FALSE; | |
531 | ||
4bb6408c JS |
532 | Boolean iconic; |
533 | XtVaGetValues((Widget) m_frameShell, XmNiconic, &iconic, NULL); | |
534 | return iconic; | |
535 | } | |
536 | ||
6f63ec3f JS |
537 | // Is it maximized? |
538 | bool wxFrame::IsMaximized(void) const | |
539 | { | |
540 | // No maximizing in Motif (?) | |
541 | return FALSE; | |
542 | } | |
543 | ||
4bb6408c JS |
544 | void wxFrame::SetTitle(const wxString& title) |
545 | { | |
546 | if (title == m_title) | |
547 | return; | |
548 | ||
549 | m_title = title; | |
550 | ||
551 | if (!title.IsNull()) | |
552 | XtVaSetValues((Widget) m_frameShell, | |
553 | XmNtitle, (const char*) title, | |
554 | XmNiconName, (const char*) title, | |
555 | NULL); | |
556 | } | |
557 | ||
558 | void wxFrame::SetIcon(const wxIcon& icon) | |
559 | { | |
560 | m_icon = icon; | |
561 | ||
621793f4 JS |
562 | if (!m_frameShell) |
563 | return; | |
564 | ||
4bb6408c JS |
565 | if (!icon.Ok() || !icon.GetPixmap()) |
566 | return; | |
567 | ||
7fe7d506 | 568 | XtVaSetValues((Widget) m_frameShell, XtNiconPixmap, icon.GetPixmap(), NULL); |
4bb6408c JS |
569 | } |
570 | ||
571 | wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id, | |
572 | const wxString& name) | |
573 | { | |
574 | wxStatusBar *statusBar = NULL; | |
575 | ||
576 | statusBar = new wxStatusBar(this, id, wxPoint(0, 0), wxSize(100, 20), | |
577 | style, name); | |
578 | ||
579 | // Set the height according to the font and the border size | |
580 | wxClientDC dc(statusBar); | |
c0ed460c | 581 | dc.SetFont(statusBar->GetFont()); |
4bb6408c JS |
582 | |
583 | long x, y; | |
584 | dc.GetTextExtent("X", &x, &y); | |
585 | ||
586 | int height = (int)( (y * 1.1) + 2* statusBar->GetBorderY()); | |
587 | ||
588 | statusBar->SetSize(-1, -1, 100, height); | |
589 | ||
590 | statusBar->SetFieldsCount(number); | |
591 | return statusBar; | |
592 | } | |
593 | ||
594 | wxStatusBar* wxFrame::CreateStatusBar(int number, long style, wxWindowID id, | |
595 | const wxString& name) | |
596 | { | |
597 | // Calling CreateStatusBar twice is an error. | |
598 | wxCHECK_MSG( m_frameStatusBar == NULL, FALSE, | |
599 | "recreating status bar in wxFrame" ); | |
600 | ||
601 | m_frameStatusBar = OnCreateStatusBar(number, style, id, | |
602 | name); | |
603 | if ( m_frameStatusBar ) | |
604 | { | |
605 | PositionStatusBar(); | |
606 | return m_frameStatusBar; | |
607 | } | |
608 | else | |
609 | return NULL; | |
610 | } | |
611 | ||
612 | void wxFrame::SetStatusText(const wxString& text, int number) | |
613 | { | |
614 | wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set text for" ); | |
615 | ||
616 | m_frameStatusBar->SetStatusText(text, number); | |
617 | } | |
618 | ||
619 | void wxFrame::SetStatusWidths(int n, const int widths_field[]) | |
620 | { | |
621 | wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set widths for" ); | |
622 | ||
623 | m_frameStatusBar->SetStatusWidths(n, widths_field); | |
624 | PositionStatusBar(); | |
625 | } | |
626 | ||
627 | void wxFrame::PositionStatusBar() | |
628 | { | |
50414e24 JS |
629 | if (!m_frameStatusBar) |
630 | return; | |
631 | ||
4bb6408c JS |
632 | int w, h; |
633 | GetClientSize(&w, &h); | |
634 | int sw, sh; | |
635 | m_frameStatusBar->GetSize(&sw, &sh); | |
636 | ||
637 | // Since we wish the status bar to be directly under the client area, | |
638 | // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. | |
89c7e962 | 639 | m_frameStatusBar->SetSize(0, h, w, sh); |
4bb6408c JS |
640 | } |
641 | ||
642 | WXWidget wxFrame::GetMenuBarWidget() const | |
643 | { | |
4bb6408c JS |
644 | if (GetMenuBar()) |
645 | return GetMenuBar()->GetMainWidget(); | |
646 | else | |
4bb6408c JS |
647 | return (WXWidget) NULL; |
648 | } | |
649 | ||
650 | void wxFrame::SetMenuBar(wxMenuBar *menuBar) | |
651 | { | |
652 | if (!menuBar) | |
653 | { | |
654 | m_frameMenuBar = NULL; | |
655 | return; | |
656 | } | |
657 | ||
658 | // Currently can't set it twice | |
621793f4 | 659 | // wxASSERT_MSG( (m_frameMenuBar == (wxMenuBar*) NULL), "Cannot set the menubar more than once"); |
4bb6408c | 660 | |
621793f4 | 661 | if (m_frameMenuBar) |
4bb6408c | 662 | { |
621793f4 JS |
663 | m_frameMenuBar->DestroyMenuBar(); |
664 | delete m_frameMenuBar; | |
4bb6408c JS |
665 | } |
666 | ||
621793f4 JS |
667 | m_frameMenuBar = menuBar; |
668 | m_frameMenuBar->CreateMenuBar(this); | |
4bb6408c JS |
669 | } |
670 | ||
671 | void wxFrame::Fit() | |
672 | { | |
673 | // Work out max. size | |
c0ed460c | 674 | wxNode *node = GetChildren().First(); |
4bb6408c JS |
675 | int max_width = 0; |
676 | int max_height = 0; | |
677 | while (node) | |
678 | { | |
679 | // Find a child that's a subwindow, but not a dialog box. | |
680 | wxWindow *win = (wxWindow *)node->Data(); | |
681 | ||
682 | if (!win->IsKindOf(CLASSINFO(wxFrame)) && | |
683 | !win->IsKindOf(CLASSINFO(wxDialog))) | |
684 | { | |
685 | int width, height; | |
686 | int x, y; | |
687 | win->GetSize(&width, &height); | |
688 | win->GetPosition(&x, &y); | |
689 | ||
690 | if ((x + width) > max_width) | |
691 | max_width = x + width; | |
692 | if ((y + height) > max_height) | |
693 | max_height = y + height; | |
694 | } | |
695 | node = node->Next(); | |
696 | } | |
697 | SetClientSize(max_width, max_height); | |
698 | } | |
699 | ||
700 | // Responds to colour changes, and passes event on to children. | |
701 | void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) | |
702 | { | |
703 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); | |
704 | Refresh(); | |
705 | ||
706 | if ( m_frameStatusBar ) | |
707 | { | |
708 | wxSysColourChangedEvent event2; | |
709 | event2.SetEventObject( m_frameStatusBar ); | |
710 | m_frameStatusBar->ProcessEvent(event2); | |
711 | } | |
712 | ||
713 | // Propagate the event to the non-top-level children | |
714 | wxWindow::OnSysColourChanged(event); | |
715 | } | |
716 | ||
717 | // Default resizing behaviour - if only ONE subwindow, | |
718 | // resize to client rectangle size | |
719 | void wxFrame::OnSize(wxSizeEvent& event) | |
720 | { | |
721 | // if we're using constraints - do use them | |
47d67540 | 722 | #if wxUSE_CONSTRAINTS |
4bb6408c JS |
723 | if ( GetAutoLayout() ) { |
724 | Layout(); | |
725 | return; | |
726 | } | |
727 | #endif | |
728 | ||
729 | // do we have _exactly_ one child? | |
730 | wxWindow *child = NULL; | |
c0ed460c | 731 | for ( wxNode *node = GetChildren().First(); node; node = node->Next() ) |
4bb6408c JS |
732 | { |
733 | wxWindow *win = (wxWindow *)node->Data(); | |
734 | if ( !win->IsKindOf(CLASSINFO(wxFrame)) && | |
735 | !win->IsKindOf(CLASSINFO(wxDialog)) && | |
736 | (win != GetStatusBar()) && | |
737 | (win != GetToolBar()) ) | |
738 | { | |
739 | if ( child ) | |
740 | return; // it's our second subwindow - nothing to do | |
741 | child = win; | |
742 | } | |
743 | } | |
744 | ||
745 | if ( child ) { | |
746 | // we have exactly one child - set it's size to fill the whole frame | |
747 | int clientW, clientH; | |
748 | GetClientSize(&clientW, &clientH); | |
749 | ||
750 | int x = 0; | |
751 | int y = 0; | |
752 | ||
753 | child->SetSize(x, y, clientW, clientH); | |
754 | } | |
755 | } | |
756 | ||
757 | // Default activation behaviour - set the focus for the first child | |
758 | // subwindow found. | |
759 | void wxFrame::OnActivate(wxActivateEvent& event) | |
760 | { | |
c0ed460c | 761 | for(wxNode *node = GetChildren().First(); node; node = node->Next()) |
4bb6408c JS |
762 | { |
763 | // Find a child that's a subwindow, but not a dialog box. | |
764 | wxWindow *child = (wxWindow *)node->Data(); | |
765 | if (!child->IsKindOf(CLASSINFO(wxFrame)) && | |
766 | !child->IsKindOf(CLASSINFO(wxDialog))) | |
767 | { | |
4bb6408c JS |
768 | child->SetFocus(); |
769 | return; | |
770 | } | |
771 | } | |
772 | } | |
773 | ||
774 | // The default implementation for the close window event - calls | |
775 | // OnClose for backward compatibility. | |
776 | ||
777 | void wxFrame::OnCloseWindow(wxCloseEvent& event) | |
778 | { | |
779 | // Compatibility | |
780 | if ( GetEventHandler()->OnClose() || event.GetForce()) | |
781 | { | |
782 | this->Destroy(); | |
783 | } | |
784 | } | |
785 | ||
786 | bool wxFrame::OnClose() | |
787 | { | |
788 | return TRUE; | |
789 | } | |
790 | ||
791 | // Destroy the window (delayed, if a managed window) | |
792 | bool wxFrame::Destroy() | |
793 | { | |
794 | if (!wxPendingDelete.Member(this)) | |
795 | wxPendingDelete.Append(this); | |
796 | return TRUE; | |
797 | } | |
798 | ||
799 | // Default menu selection behaviour - display a help string | |
800 | void wxFrame::OnMenuHighlight(wxMenuEvent& event) | |
801 | { | |
802 | if (GetStatusBar()) | |
803 | { | |
804 | if (event.GetMenuId() == -1) | |
805 | SetStatusText(""); | |
806 | else | |
807 | { | |
808 | wxMenuBar *menuBar = GetMenuBar(); | |
809 | if (menuBar) | |
810 | { | |
811 | wxString helpString(menuBar->GetHelpString(event.GetMenuId())); | |
812 | if (helpString != "") | |
813 | SetStatusText(helpString); | |
814 | } | |
815 | } | |
816 | } | |
817 | } | |
818 | ||
819 | wxMenuBar *wxFrame::GetMenuBar() const | |
820 | { | |
821 | return m_frameMenuBar; | |
822 | } | |
823 | ||
824 | void wxFrame::Centre(int direction) | |
825 | { | |
826 | int display_width, display_height, width, height, x, y; | |
827 | wxDisplaySize(&display_width, &display_height); | |
828 | ||
829 | GetSize(&width, &height); | |
830 | GetPosition(&x, &y); | |
831 | ||
832 | if (direction & wxHORIZONTAL) | |
833 | x = (int)((display_width - width)/2); | |
834 | if (direction & wxVERTICAL) | |
835 | y = (int)((display_height - height)/2); | |
836 | ||
837 | SetSize(x, y, width, height); | |
838 | } | |
839 | ||
840 | // Call this to simulate a menu command | |
841 | void wxFrame::Command(int id) | |
842 | { | |
843 | ProcessCommand(id); | |
844 | } | |
845 | ||
846 | void wxFrame::ProcessCommand(int id) | |
847 | { | |
848 | wxCommandEvent commandEvent(wxEVENT_TYPE_MENU_COMMAND, id); | |
849 | commandEvent.SetInt( id ); | |
850 | commandEvent.SetEventObject( this ); | |
851 | ||
852 | wxMenuBar *bar = GetMenuBar() ; | |
853 | if (!bar) | |
854 | return; | |
855 | ||
856 | /* TODO: check the menu item if required | |
857 | wxMenuItem *item = bar->FindItemForId(id) ; | |
858 | if (item && item->IsCheckable()) | |
859 | { | |
860 | bar->Check(id,!bar->Checked(id)) ; | |
861 | } | |
862 | */ | |
863 | ||
864 | GetEventHandler()->ProcessEvent(commandEvent); | |
865 | } | |
866 | ||
867 | // Checks if there is a toolbar, and returns the first free client position | |
868 | wxPoint wxFrame::GetClientAreaOrigin() const | |
869 | { | |
870 | wxPoint pt(0, 0); | |
871 | if (GetToolBar()) | |
872 | { | |
873 | int w, h; | |
874 | GetToolBar()->GetSize(& w, & h); | |
875 | ||
876 | if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) | |
877 | { | |
878 | pt.x += w; | |
879 | } | |
880 | else | |
881 | { | |
882 | pt.y += h; | |
883 | } | |
884 | } | |
885 | return pt; | |
886 | } | |
887 | ||
87d1e11f JS |
888 | void wxFrame::ScreenToClient(int *x, int *y) const |
889 | { | |
890 | wxWindow::ScreenToClient(x, y); | |
891 | ||
892 | // We may be faking the client origin. | |
893 | // So a window that's really at (0, 30) may appear | |
894 | // (to wxWin apps) to be at (0, 0). | |
895 | wxPoint pt(GetClientAreaOrigin()); | |
896 | *x -= pt.x; | |
897 | *y -= pt.y; | |
898 | } | |
899 | ||
900 | void wxFrame::ClientToScreen(int *x, int *y) const | |
901 | { | |
902 | // We may be faking the client origin. | |
903 | // So a window that's really at (0, 30) may appear | |
904 | // (to wxWin apps) to be at (0, 0). | |
905 | wxPoint pt1(GetClientAreaOrigin()); | |
906 | *x += pt1.x; | |
907 | *y += pt1.y; | |
908 | ||
909 | wxWindow::ClientToScreen(x, y); | |
910 | } | |
911 | ||
4bb6408c JS |
912 | wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) |
913 | { | |
914 | wxCHECK_MSG( m_frameToolBar == NULL, FALSE, | |
915 | "recreating toolbar in wxFrame" ); | |
916 | ||
917 | wxToolBar* toolBar = OnCreateToolBar(style, id, name); | |
918 | if (toolBar) | |
919 | { | |
920 | SetToolBar(toolBar); | |
921 | PositionToolBar(); | |
922 | return toolBar; | |
923 | } | |
924 | else | |
925 | { | |
926 | return NULL; | |
927 | } | |
928 | } | |
929 | ||
930 | wxToolBar* wxFrame::OnCreateToolBar(long style, wxWindowID id, const wxString& name) | |
931 | { | |
a4294b78 | 932 | return new wxToolBar(this, id, wxPoint(0, 0), wxSize(100, 24), style, name); |
4bb6408c JS |
933 | } |
934 | ||
935 | void wxFrame::PositionToolBar() | |
936 | { | |
937 | int cw, ch; | |
938 | ||
4bb6408c JS |
939 | GetClientSize(& cw, &ch); |
940 | ||
4bb6408c JS |
941 | if (GetToolBar()) |
942 | { | |
943 | int tw, th; | |
944 | GetToolBar()->GetSize(& tw, & th); | |
945 | ||
946 | if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) | |
947 | { | |
948 | // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS | |
949 | // means, pretend we don't have toolbar/status bar, so we | |
950 | // have the original client size. | |
a4294b78 | 951 | GetToolBar()->SetSize(0, 0, tw, ch + th, wxSIZE_NO_ADJUSTMENTS); |
4bb6408c JS |
952 | } |
953 | else | |
954 | { | |
955 | // Use the 'real' position | |
956 | GetToolBar()->SetSize(0, 0, cw, th, wxSIZE_NO_ADJUSTMENTS); | |
957 | } | |
958 | } | |
959 | } | |
960 | ||
961 | void wxFrame::CaptureMouse() | |
962 | { | |
963 | if (m_winCaptured) | |
964 | return; | |
965 | ||
966 | if (GetMainWidget()) | |
967 | XtAddGrab((Widget) m_frameShell, TRUE, FALSE); | |
968 | m_winCaptured = TRUE; | |
969 | } | |
970 | ||
971 | void wxFrame::ReleaseMouse() | |
972 | { | |
973 | if (!m_winCaptured) | |
974 | return; | |
975 | ||
976 | if (GetMainWidget()) | |
977 | XtRemoveGrab((Widget) m_frameShell); | |
978 | m_winCaptured = FALSE; | |
979 | } | |
980 | ||
981 | void wxFrame::Raise(void) | |
982 | { | |
983 | Window parent_window = XtWindow((Widget) m_frameShell), | |
984 | next_parent = XtWindow((Widget) m_frameShell), | |
985 | root = RootWindowOfScreen(XtScreen((Widget) m_frameShell)); | |
986 | // search for the parent that is child of ROOT, because the WM may | |
987 | // reparent twice and notify only the next parent (like FVWM) | |
988 | while (next_parent != root) { | |
989 | Window *theChildren; unsigned int n; | |
990 | parent_window = next_parent; | |
991 | XQueryTree(XtDisplay((Widget) m_frameShell), parent_window, &root, | |
992 | &next_parent, &theChildren, &n); | |
993 | XFree(theChildren); // not needed | |
994 | } | |
995 | XRaiseWindow(XtDisplay((Widget) m_frameShell), parent_window); | |
996 | } | |
997 | ||
998 | void wxFrame::Lower(void) | |
999 | { | |
1000 | Window parent_window = XtWindow((Widget) m_frameShell), | |
1001 | next_parent = XtWindow((Widget) m_frameShell), | |
1002 | root = RootWindowOfScreen(XtScreen((Widget) m_frameShell)); | |
1003 | // search for the parent that is child of ROOT, because the WM may | |
1004 | // reparent twice and notify only the next parent (like FVWM) | |
1005 | while (next_parent != root) { | |
1006 | Window *theChildren; unsigned int n; | |
1007 | parent_window = next_parent; | |
1008 | XQueryTree(XtDisplay((Widget) m_frameShell), parent_window, &root, | |
1009 | &next_parent, &theChildren, &n); | |
1010 | XFree(theChildren); // not needed | |
1011 | } | |
1012 | XLowerWindow(XtDisplay((Widget) m_frameShell), parent_window); | |
1013 | } | |
1014 | ||
1015 | void wxFrame::SetToolBar(wxToolBar *toolbar) | |
1016 | { m_frameToolBar = toolbar; } | |
1017 | ||
1018 | wxToolBar *wxFrame::GetToolBar() const | |
1019 | { return m_frameToolBar; } | |
1020 | ||
8704bf74 | 1021 | void wxFrameFocusProc(Widget workArea, XtPointer clientData, |
4bb6408c JS |
1022 | XmAnyCallbackStruct *cbs) |
1023 | { | |
1024 | wxFrame *frame = (wxFrame *)clientData; | |
1025 | ||
1026 | // wxDebugMsg("focus proc from frame %ld\n",(long)frame); | |
1027 | // TODO | |
1028 | // frame->GetEventHandler()->OnSetFocus(); | |
1029 | } | |
1030 | ||
1031 | /* MATTEW: Used to insure that hide-&-show within an event cycle works */ | |
1032 | static void wxFrameMapProc(Widget frameShell, XtPointer clientData, | |
1033 | XCrossingEvent * event) | |
1034 | { | |
1035 | wxFrame *frame = (wxFrame *)wxWidgetHashTable->Get((long)clientData); | |
1036 | ||
1037 | if (frame) { | |
1038 | XEvent *e = (XEvent *)event; | |
1039 | ||
1040 | if (e->xany.type == MapNotify) | |
1041 | { | |
1042 | // Iconize fix | |
1043 | XtVaSetValues(frameShell, XmNiconic, (Boolean)False, NULL); | |
1044 | if (!frame->GetVisibleStatus()) | |
1045 | { | |
1046 | /* We really wanted this to be hidden! */ | |
1047 | XtUnmapWidget((Widget) frame->GetShellWidget()); | |
1048 | } | |
1049 | } | |
1050 | else if (e->xany.type == UnmapNotify) | |
1051 | // Iconize fix | |
1052 | XtVaSetValues(frameShell, XmNiconic, (Boolean)True, NULL); | |
1053 | } | |
1054 | } | |
1055 | ||
1056 | //// Motif-specific | |
1057 | bool wxFrame::PreResize() | |
1058 | { | |
a4294b78 | 1059 | PositionToolBar(); |
50414e24 | 1060 | PositionStatusBar(); |
4bb6408c JS |
1061 | return TRUE; |
1062 | } | |
1063 | ||
50414e24 JS |
1064 | WXWidget wxFrame::GetClientWidget() const |
1065 | { | |
1066 | return m_clientArea; | |
1067 | } | |
1068 | ||
4b5f3fe6 | 1069 | void wxFrame::ChangeFont(bool keepOriginalSize) |
0d57be45 JS |
1070 | { |
1071 | // TODO | |
1072 | } | |
1073 | ||
1074 | void wxFrame::ChangeBackgroundColour() | |
1075 | { | |
621793f4 JS |
1076 | if (GetClientWidget()) |
1077 | DoChangeBackgroundColour(GetClientWidget(), m_backgroundColour); | |
0d57be45 JS |
1078 | } |
1079 | ||
1080 | void wxFrame::ChangeForegroundColour() | |
1081 | { | |
621793f4 JS |
1082 | if (GetClientWidget()) |
1083 | DoChangeForegroundColour(GetClientWidget(), m_foregroundColour); | |
0d57be45 JS |
1084 | } |
1085 | ||
4bb6408c JS |
1086 | void wxCloseFrameCallback(Widget widget, XtPointer client_data, XmAnyCallbackStruct *cbs) |
1087 | { | |
1088 | wxFrame *frame = (wxFrame *)client_data; | |
1089 | ||
1090 | wxCloseEvent closeEvent(wxEVT_CLOSE_WINDOW, frame->GetId()); | |
1091 | closeEvent.SetEventObject(frame); | |
1092 | ||
1093 | // May delete the frame (with delayed deletion) | |
1094 | frame->GetEventHandler()->ProcessEvent(closeEvent); | |
1095 | } | |
0d57be45 | 1096 |