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