]>
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 | ||
798a4529 | 31 | #include "wx/frame.h" |
4bb6408c JS |
32 | #include "wx/statusbr.h" |
33 | #include "wx/toolbar.h" | |
4bb6408c | 34 | #include "wx/menu.h" |
4bb6408c | 35 | #include "wx/settings.h" |
4bb6408c | 36 | #include "wx/utils.h" |
176513eb | 37 | #include "wx/log.h" |
798a4529 | 38 | #include "wx/app.h" |
4bb6408c | 39 | |
338dd992 | 40 | #ifdef __VMS__ |
1c4f8f8d | 41 | #pragma message disable nosimpint |
338dd992 | 42 | #endif |
1c4f8f8d | 43 | |
4bb6408c | 44 | #if defined(__ultrix) || defined(__sgi) |
1c4f8f8d | 45 | #include <Xm/Frame.h> |
4bb6408c JS |
46 | #endif |
47 | ||
48 | #include <Xm/Xm.h> | |
49 | #include <X11/Shell.h> | |
f618020a | 50 | #include <X11/Core.h> |
4bb6408c | 51 | #if XmVersion >= 1002 |
1c4f8f8d | 52 | #include <Xm/XmAll.h> |
4bb6408c | 53 | #else |
1c4f8f8d | 54 | #include <Xm/Frame.h> |
4bb6408c JS |
55 | #endif |
56 | #include <Xm/MwmUtil.h> | |
57 | #include <Xm/BulletinB.h> | |
58 | #include <Xm/Form.h> | |
59 | #include <Xm/MainW.h> | |
60 | #include <Xm/RowColumn.h> | |
61 | #include <Xm/Label.h> | |
62 | #include <Xm/AtomMgr.h> | |
63 | #include <Xm/LabelG.h> | |
64 | #include <Xm/Frame.h> | |
65 | #if XmVersion > 1000 | |
1c4f8f8d | 66 | #include <Xm/Protocols.h> |
4bb6408c | 67 | #endif |
1c4f8f8d | 68 | |
338dd992 | 69 | #ifdef __VMS__ |
1c4f8f8d | 70 | #pragma message enable nosimpint |
338dd992 | 71 | #endif |
4bb6408c JS |
72 | |
73 | #include "wx/motif/private.h" | |
f618020a | 74 | #include "wx/unix/utilsx11.h" |
4bb6408c | 75 | |
1c4f8f8d VZ |
76 | // ---------------------------------------------------------------------------- |
77 | // private functions | |
78 | // ---------------------------------------------------------------------------- | |
79 | ||
dfe1eee3 | 80 | static void wxFrameMapProc(Widget frameShell, XtPointer clientData, |
798a4529 | 81 | XCrossingEvent* event); |
4bb6408c | 82 | |
1c4f8f8d VZ |
83 | // ---------------------------------------------------------------------------- |
84 | // globals | |
85 | // ---------------------------------------------------------------------------- | |
86 | ||
4bb6408c JS |
87 | extern wxList wxModelessWindows; |
88 | extern wxList wxPendingDelete; | |
89 | ||
90 | // TODO: this should be tidied so that any frame can be the | |
91 | // top frame | |
798a4529 | 92 | // static bool wxTopLevelUsed = FALSE; |
4bb6408c | 93 | |
1c4f8f8d VZ |
94 | // ---------------------------------------------------------------------------- |
95 | // wxWin macros | |
96 | // ---------------------------------------------------------------------------- | |
97 | ||
1c4f8f8d VZ |
98 | BEGIN_EVENT_TABLE(wxFrame, wxFrameBase) |
99 | EVT_ACTIVATE(wxFrame::OnActivate) | |
100 | EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged) | |
4bb6408c JS |
101 | END_EVENT_TABLE() |
102 | ||
c0854a08 | 103 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow) |
4bb6408c | 104 | |
1c4f8f8d VZ |
105 | // ============================================================================ |
106 | // implementation | |
107 | // ============================================================================ | |
1ccbb61a | 108 | |
1c4f8f8d VZ |
109 | // ---------------------------------------------------------------------------- |
110 | // frame construction | |
111 | // ---------------------------------------------------------------------------- | |
dfe1eee3 | 112 | |
1c4f8f8d VZ |
113 | void wxFrame::Init() |
114 | { | |
4bb6408c | 115 | m_iconized = FALSE; |
dfe1eee3 | 116 | |
4bb6408c JS |
117 | //// Motif-specific |
118 | m_frameShell = (WXWidget) NULL; | |
798a4529 | 119 | m_mainWidget = (WXWidget) NULL;; |
4bb6408c JS |
120 | m_workArea = (WXWidget) NULL;; |
121 | m_clientArea = (WXWidget) NULL;; | |
798a4529 | 122 | // m_visibleStatus = TRUE; |
4bb6408c JS |
123 | } |
124 | ||
125 | bool wxFrame::Create(wxWindow *parent, | |
2d120f83 JS |
126 | wxWindowID id, |
127 | const wxString& title, | |
128 | const wxPoint& pos, | |
129 | const wxSize& size, | |
130 | long style, | |
131 | const wxString& name) | |
4bb6408c | 132 | { |
798a4529 MB |
133 | if( !wxTopLevelWindow::Create( parent, id, title, pos, size, style, |
134 | name ) ) | |
135 | return FALSE; | |
dfe1eee3 | 136 | |
798a4529 MB |
137 | m_backgroundColour = |
138 | wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE); | |
2d120f83 | 139 | m_foregroundColour = *wxBLACK; |
a756f210 | 140 | m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); |
dfe1eee3 | 141 | |
447a039f MB |
142 | int x = pos.x, y = pos.y; |
143 | int width = size.x, height = size.y; | |
da8bed9b VZ |
144 | |
145 | // Set reasonable values for position and size if defaults have been | |
146 | // requested | |
447a039f | 147 | // |
da8bed9b VZ |
148 | // MB TODO: something better than these arbitrary values ? |
149 | // VZ should use X resources for this... | |
150 | if ( width == -1 ) | |
151 | width = 400; | |
152 | if ( height == -1 ) | |
153 | height = 400; | |
447a039f MB |
154 | |
155 | int displayW, displayH; | |
156 | wxDisplaySize( &displayW, &displayH ); | |
157 | ||
158 | if ( x == -1 ) | |
159 | { | |
160 | x = (displayW - width) / 2; | |
161 | if (x < 10) x = 10; | |
162 | } | |
163 | if ( y == -1 ) | |
164 | { | |
165 | y = (displayH - height) / 2; | |
da8bed9b | 166 | if (y < 10) y = 10; |
447a039f | 167 | } |
da8bed9b | 168 | |
798a4529 MB |
169 | SetTitle( title ); |
170 | ||
171 | wxLogTrace(wxTRACE_Messages, | |
172 | "Created frame (0x%08x) with work area 0x%08x and client " | |
173 | "area 0x%08x", m_mainWidget, m_workArea, m_clientArea); | |
174 | ||
175 | XtAddEventHandler((Widget) m_clientArea, ExposureMask,FALSE, | |
176 | wxUniversalRepaintProc, (XtPointer) this); | |
177 | ||
178 | if (x > -1) | |
179 | XtVaSetValues((Widget) m_frameShell, XmNx, x, NULL); | |
180 | if (y > -1) | |
181 | XtVaSetValues((Widget) m_frameShell, XmNy, y, NULL); | |
182 | if (width > -1) | |
183 | XtVaSetValues((Widget) m_frameShell, XmNwidth, width, NULL); | |
184 | if (height > -1) | |
185 | XtVaSetValues((Widget) m_frameShell, XmNheight, height, NULL); | |
186 | ||
187 | ChangeFont(FALSE); | |
188 | ||
189 | ChangeBackgroundColour(); | |
190 | ||
191 | PreResize(); | |
192 | ||
193 | wxSizeEvent sizeEvent(wxSize(width, height), GetId()); | |
194 | sizeEvent.SetEventObject(this); | |
195 | ||
196 | GetEventHandler()->ProcessEvent(sizeEvent); | |
197 | ||
198 | return TRUE; | |
199 | } | |
200 | ||
201 | bool wxFrame::DoCreate( wxWindow* parent, wxWindowID id, | |
202 | const wxString& title, | |
203 | const wxPoint& pos, | |
204 | const wxSize& size, | |
205 | long style, | |
206 | const wxString& name ) | |
207 | { | |
208 | static bool wxTopLevelUsed = FALSE; /* this is global */ | |
209 | WXWidget frameShell; | |
210 | ||
2d120f83 | 211 | if (wxTopLevelUsed) |
31528cd3 | 212 | { |
2d120f83 | 213 | // Change suggested by Matthew Flatt |
798a4529 MB |
214 | frameShell = (WXWidget)XtAppCreateShell( name, |
215 | wxTheApp->GetClassName(), | |
216 | topLevelShellWidgetClass, | |
217 | (Display*) wxGetDisplay(), | |
218 | NULL, 0 ); | |
31528cd3 | 219 | } |
2d120f83 JS |
220 | else |
221 | { | |
798a4529 | 222 | frameShell = wxTheApp->GetTopLevelWidget(); |
2d120f83 JS |
223 | wxTopLevelUsed = TRUE; |
224 | } | |
dfe1eee3 | 225 | |
798a4529 | 226 | XtVaSetValues((Widget) frameShell, |
2d120f83 JS |
227 | // Allows menu to resize |
228 | XmNallowShellResize, True, | |
229 | XmNdeleteResponse, XmDO_NOTHING, | |
230 | XmNmappedWhenManaged, False, | |
231 | XmNiconic, (style & wxICONIZE) ? TRUE : FALSE, | |
232 | NULL); | |
dfe1eee3 | 233 | |
798a4529 | 234 | m_frameShell = frameShell; |
dfe1eee3 | 235 | |
798a4529 MB |
236 | m_mainWidget = (WXWidget) XtVaCreateManagedWidget("main_window", |
237 | xmMainWindowWidgetClass, (Widget) frameShell, | |
2d120f83 JS |
238 | XmNresizePolicy, XmRESIZE_NONE, |
239 | NULL); | |
dfe1eee3 | 240 | |
2d120f83 | 241 | m_workArea = (WXWidget) XtVaCreateWidget("form", |
798a4529 | 242 | xmFormWidgetClass, (Widget) m_mainWidget, |
2d120f83 JS |
243 | XmNresizePolicy, XmRESIZE_NONE, |
244 | NULL); | |
dfe1eee3 | 245 | |
2d120f83 JS |
246 | m_clientArea = (WXWidget) XtVaCreateWidget("client", |
247 | xmBulletinBoardWidgetClass, (Widget) m_workArea, | |
248 | XmNmarginWidth, 0, | |
249 | XmNmarginHeight, 0, | |
250 | XmNrightAttachment, XmATTACH_FORM, | |
251 | XmNleftAttachment, XmATTACH_FORM, | |
252 | XmNtopAttachment, XmATTACH_FORM, | |
253 | XmNbottomAttachment, XmATTACH_FORM, | |
2d120f83 | 254 | NULL); |
0492c5a0 | 255 | |
798a4529 | 256 | XtVaSetValues((Widget) m_mainWidget, |
2d120f83 JS |
257 | XmNworkWindow, (Widget) m_workArea, |
258 | NULL); | |
dfe1eee3 | 259 | |
2d120f83 JS |
260 | XtManageChild((Widget) m_clientArea); |
261 | XtManageChild((Widget) m_workArea); | |
dfe1eee3 | 262 | |
798a4529 MB |
263 | XtTranslations ptr = XtParseTranslationTable( "<Configure>: resize()" ); |
264 | XtOverrideTranslations( (Widget) m_workArea, ptr ); | |
265 | XtFree( (char *)ptr ); | |
dfe1eee3 | 266 | |
2d120f83 | 267 | /* Part of show-&-hide fix */ |
798a4529 MB |
268 | XtAddEventHandler( (Widget)frameShell, StructureNotifyMask, |
269 | False, (XtEventHandler)wxFrameMapProc, | |
270 | (XtPointer)this ); | |
dfe1eee3 | 271 | |
798a4529 | 272 | XtRealizeWidget((Widget) frameShell); |
dfe1eee3 | 273 | |
798a4529 MB |
274 | wxAddWindowToTable( (Widget)m_workArea, this); |
275 | wxAddWindowToTable( (Widget)m_clientArea, this); | |
dfe1eee3 | 276 | |
798a4529 | 277 | wxModelessWindows.Append( this ); |
dfe1eee3 | 278 | |
2d120f83 | 279 | return TRUE; |
4bb6408c JS |
280 | } |
281 | ||
282 | wxFrame::~wxFrame() | |
283 | { | |
3ab377bd | 284 | m_isBeingDeleted = TRUE; |
da8bed9b | 285 | |
2e35f56f | 286 | if (m_clientArea) |
dc1efb1d | 287 | { |
2e35f56f JS |
288 | XtRemoveEventHandler((Widget) m_clientArea, ExposureMask, FALSE, |
289 | wxUniversalRepaintProc, (XtPointer) this); | |
dc1efb1d | 290 | } |
2e35f56f | 291 | |
2d120f83 JS |
292 | if (GetMainWidget()) |
293 | Show(FALSE); | |
0492c5a0 | 294 | |
2d120f83 JS |
295 | if (m_frameMenuBar) |
296 | { | |
297 | m_frameMenuBar->DestroyMenuBar(); | |
dfe1eee3 | 298 | |
2d120f83 | 299 | // Hack to stop core dump on Ultrix, OSF, for some strange reason. |
4bb6408c | 300 | #if MOTIF_MENUBAR_DELETE_FIX |
2d120f83 | 301 | GetMenuBar()->SetMainWidget((WXWidget) NULL); |
4bb6408c | 302 | #endif |
2d120f83 JS |
303 | delete m_frameMenuBar; |
304 | m_frameMenuBar = NULL; | |
305 | } | |
dfe1eee3 | 306 | |
2d120f83 | 307 | if (m_frameStatusBar) |
1c4f8f8d | 308 | { |
2d120f83 | 309 | delete m_frameStatusBar; |
1c4f8f8d VZ |
310 | m_frameStatusBar = NULL; |
311 | } | |
798a4529 | 312 | } |
dfe1eee3 | 313 | |
798a4529 MB |
314 | void wxFrame::DoDestroy() |
315 | { | |
316 | Widget frameShell = (Widget)GetShellWidget(); | |
2b5f62a0 | 317 | |
798a4529 MB |
318 | XtRemoveEventHandler( frameShell, StructureNotifyMask, |
319 | False, (XtEventHandler)wxFrameMapProc, | |
320 | (XtPointer)this ); | |
dfe1eee3 | 321 | |
798a4529 | 322 | if( m_clientArea ) |
4bb6408c | 323 | { |
798a4529 MB |
324 | wxDeleteWindowFromTable( (Widget)m_clientArea ); |
325 | XtDestroyWidget( (Widget)m_clientArea ); | |
4bb6408c | 326 | } |
dfe1eee3 | 327 | |
798a4529 | 328 | if( m_workArea ) |
2d120f83 | 329 | { |
798a4529 MB |
330 | XtVaSetValues( (Widget)m_mainWidget, |
331 | XmNworkWindow, (Widget)NULL, | |
332 | NULL ); | |
dfe1eee3 | 333 | |
798a4529 MB |
334 | wxDeleteWindowFromTable( (Widget)m_workArea ); |
335 | XtDestroyWidget( (Widget)m_workArea ); | |
336 | } | |
dfe1eee3 | 337 | |
798a4529 MB |
338 | if( m_mainWidget ) |
339 | XtDestroyWidget( (Widget)m_mainWidget ); | |
dfe1eee3 | 340 | |
798a4529 MB |
341 | if( frameShell ) |
342 | XtDestroyWidget( frameShell ); | |
4bb6408c JS |
343 | } |
344 | ||
345 | // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc. | |
449f38b5 | 346 | void wxFrame::DoGetClientSize(int *x, int *y) const |
4bb6408c | 347 | { |
2d120f83 JS |
348 | Dimension xx, yy; |
349 | XtVaGetValues((Widget) m_workArea, XmNwidth, &xx, XmNheight, &yy, NULL); | |
dfe1eee3 | 350 | |
2d120f83 JS |
351 | if (m_frameStatusBar) |
352 | { | |
353 | int sbw, sbh; | |
354 | m_frameStatusBar->GetSize(& sbw, & sbh); | |
355 | yy -= sbh; | |
356 | } | |
1ccbb61a | 357 | #if wxUSE_TOOLBAR |
2d120f83 JS |
358 | if (m_frameToolBar) |
359 | { | |
360 | int tbw, tbh; | |
361 | m_frameToolBar->GetSize(& tbw, & tbh); | |
362 | if (m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL) | |
363 | xx -= tbw; | |
364 | else | |
365 | yy -= tbh; | |
366 | } | |
1ccbb61a | 367 | #endif // wxUSE_TOOLBAR |
2d120f83 | 368 | *x = xx; *y = yy; |
4bb6408c JS |
369 | } |
370 | ||
371 | // Set the client size (i.e. leave the calculation of borders etc. | |
372 | // to wxWindows) | |
bfc6fde4 | 373 | void wxFrame::DoSetClientSize(int width, int height) |
4bb6408c | 374 | { |
2d120f83 JS |
375 | // Calculate how large the new main window should be |
376 | // by finding the difference between the client area and the | |
377 | // main window area, and adding on to the new client area | |
378 | if (width > -1) | |
379 | XtVaSetValues((Widget) m_workArea, XmNwidth, width, NULL); | |
dfe1eee3 | 380 | |
2d120f83 | 381 | if (height > -1) |
a4294b78 | 382 | { |
2d120f83 JS |
383 | if (m_frameStatusBar) |
384 | { | |
385 | int sbw, sbh; | |
386 | m_frameStatusBar->GetSize(& sbw, & sbh); | |
387 | height += sbh; | |
388 | } | |
1ccbb61a | 389 | #if wxUSE_TOOLBAR |
2d120f83 JS |
390 | if (m_frameToolBar) |
391 | { | |
392 | int tbw, tbh; | |
393 | m_frameToolBar->GetSize(& tbw, & tbh); | |
394 | if (m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL) | |
395 | width += tbw; | |
396 | else | |
397 | height += tbh; | |
398 | } | |
1ccbb61a | 399 | #endif // wxUSE_TOOLBAR |
dfe1eee3 | 400 | |
2d120f83 | 401 | XtVaSetValues((Widget) m_workArea, XmNheight, height, NULL); |
a4294b78 | 402 | } |
2d120f83 | 403 | PreResize(); |
dfe1eee3 | 404 | |
2d120f83 JS |
405 | wxSizeEvent sizeEvent(wxSize(width, height), GetId()); |
406 | sizeEvent.SetEventObject(this); | |
dfe1eee3 | 407 | |
2d120f83 | 408 | GetEventHandler()->ProcessEvent(sizeEvent); |
dfe1eee3 | 409 | |
4bb6408c JS |
410 | } |
411 | ||
449f38b5 | 412 | void wxFrame::DoGetSize(int *width, int *height) const |
4bb6408c | 413 | { |
2d120f83 JS |
414 | Dimension xx, yy; |
415 | XtVaGetValues((Widget) m_frameShell, XmNwidth, &xx, XmNheight, &yy, NULL); | |
416 | *width = xx; *height = yy; | |
4bb6408c JS |
417 | } |
418 | ||
449f38b5 | 419 | void wxFrame::DoGetPosition(int *x, int *y) const |
4bb6408c JS |
420 | { |
421 | Window parent_window = XtWindow((Widget) m_frameShell), | |
2d120f83 JS |
422 | next_parent = XtWindow((Widget) m_frameShell), |
423 | root = RootWindowOfScreen(XtScreen((Widget) m_frameShell)); | |
dfe1eee3 | 424 | |
4bb6408c JS |
425 | // search for the parent that is child of ROOT, because the WM may |
426 | // reparent twice and notify only the next parent (like FVWM) | |
427 | while (next_parent != root) { | |
2d120f83 JS |
428 | Window *theChildren; unsigned int n; |
429 | parent_window = next_parent; | |
430 | XQueryTree(XtDisplay((Widget) m_frameShell), parent_window, &root, | |
431 | &next_parent, &theChildren, &n); | |
432 | XFree(theChildren); // not needed | |
4bb6408c JS |
433 | } |
434 | int xx, yy; unsigned int dummy; | |
435 | XGetGeometry(XtDisplay((Widget) m_frameShell), parent_window, &root, | |
2d120f83 | 436 | &xx, &yy, &dummy, &dummy, &dummy, &dummy); |
4bb6408c JS |
437 | if (x) *x = xx; |
438 | if (y) *y = yy; | |
439 | } | |
440 | ||
af111fc3 | 441 | void wxFrame::DoSetSize(int x, int y, int width, int height, int WXUNUSED(sizeFlags)) |
4bb6408c | 442 | { |
2d120f83 JS |
443 | if (x > -1) |
444 | XtVaSetValues((Widget) m_frameShell, XmNx, x, NULL); | |
445 | if (y > -1) | |
446 | XtVaSetValues((Widget) m_frameShell, XmNy, y, NULL); | |
447 | if (width > -1) | |
798a4529 | 448 | XtVaSetValues((Widget) m_mainWidget, XmNwidth, width, NULL); |
2d120f83 | 449 | if (height > -1) |
798a4529 | 450 | XtVaSetValues((Widget) m_mainWidget, XmNheight, height, NULL); |
dfe1eee3 | 451 | |
2d120f83 JS |
452 | if (!(height == -1 && width == -1)) |
453 | { | |
454 | PreResize(); | |
2d120f83 | 455 | } |
4bb6408c JS |
456 | } |
457 | ||
798a4529 | 458 | bool wxFrame::Show( bool show ) |
4bb6408c | 459 | { |
798a4529 MB |
460 | if( !wxTopLevelWindowMotif::Show( show ) ) |
461 | return FALSE; | |
dfe1eee3 | 462 | |
2d120f83 | 463 | m_isShown = show; |
1c4f8f8d | 464 | |
798a4529 MB |
465 | Widget shell = (Widget)GetShellWidget(); |
466 | if (!shell) | |
467 | return wxWindow::Show(show); | |
dfe1eee3 | 468 | |
798a4529 MB |
469 | SetVisibleStatus(show); |
470 | if (show) | |
471 | { | |
472 | XtMapWidget (shell); | |
473 | XRaiseWindow (XtDisplay(shell), XtWindow(shell)); | |
474 | } | |
475 | else | |
476 | { | |
477 | XtUnmapWidget(shell); | |
478 | } | |
4bb6408c | 479 | |
798a4529 | 480 | return TRUE; |
6f63ec3f JS |
481 | } |
482 | ||
4bb6408c JS |
483 | void wxFrame::SetTitle(const wxString& title) |
484 | { | |
798a4529 MB |
485 | wxString oldTitle = GetTitle(); |
486 | if( title == oldTitle ) | |
2d120f83 | 487 | return; |
dfe1eee3 | 488 | |
798a4529 | 489 | wxTopLevelWindow::SetTitle( title ); |
dfe1eee3 | 490 | |
798a4529 MB |
491 | if( !title.empty() ) |
492 | XtVaSetValues( (Widget)m_frameShell, | |
493 | XmNtitle, title.c_str(), | |
494 | XmNiconName, title.c_str(), | |
495 | NULL ); | |
4bb6408c JS |
496 | } |
497 | ||
f618020a | 498 | void wxFrame::DoSetIcon(const wxIcon& icon) |
4bb6408c | 499 | { |
2d120f83 JS |
500 | if (!m_frameShell) |
501 | return; | |
dfe1eee3 | 502 | |
2d120f83 JS |
503 | if (!icon.Ok() || !icon.GetPixmap()) |
504 | return; | |
dfe1eee3 | 505 | |
2d120f83 | 506 | XtVaSetValues((Widget) m_frameShell, XtNiconPixmap, icon.GetPixmap(), NULL); |
4bb6408c JS |
507 | } |
508 | ||
f618020a MB |
509 | void wxFrame::SetIcon(const wxIcon& icon) |
510 | { | |
511 | SetIcons( wxIconBundle( icon ) ); | |
512 | } | |
513 | ||
514 | void wxFrame::SetIcons(const wxIconBundle& icons) | |
515 | { | |
516 | wxFrameBase::SetIcons( icons ); | |
517 | ||
518 | if (!m_frameShell) | |
519 | return; | |
520 | ||
521 | DoSetIcon( m_icons.GetIcon( -1 ) ); | |
522 | wxSetIconsX11(GetXDisplay(), | |
523 | (WXWindow) XtWindow( (Widget) m_frameShell ), icons); | |
524 | } | |
525 | ||
4bb6408c JS |
526 | void wxFrame::PositionStatusBar() |
527 | { | |
50414e24 | 528 | if (!m_frameStatusBar) |
2d120f83 | 529 | return; |
dfe1eee3 | 530 | |
4bb6408c JS |
531 | int w, h; |
532 | GetClientSize(&w, &h); | |
533 | int sw, sh; | |
534 | m_frameStatusBar->GetSize(&sw, &sh); | |
dfe1eee3 | 535 | |
4bb6408c JS |
536 | // Since we wish the status bar to be directly under the client area, |
537 | // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. | |
89c7e962 | 538 | m_frameStatusBar->SetSize(0, h, w, sh); |
4bb6408c JS |
539 | } |
540 | ||
541 | WXWidget wxFrame::GetMenuBarWidget() const | |
542 | { | |
2d120f83 JS |
543 | if (GetMenuBar()) |
544 | return GetMenuBar()->GetMainWidget(); | |
545 | else | |
546 | return (WXWidget) NULL; | |
4bb6408c JS |
547 | } |
548 | ||
549 | void wxFrame::SetMenuBar(wxMenuBar *menuBar) | |
550 | { | |
551 | if (!menuBar) | |
552 | { | |
553 | m_frameMenuBar = NULL; | |
554 | return; | |
555 | } | |
dfe1eee3 | 556 | |
4bb6408c | 557 | // Currently can't set it twice |
2d120f83 | 558 | // wxASSERT_MSG( (m_frameMenuBar == (wxMenuBar*) NULL), "Cannot set the menubar more than once"); |
dfe1eee3 | 559 | |
621793f4 | 560 | if (m_frameMenuBar) |
4bb6408c | 561 | { |
621793f4 JS |
562 | m_frameMenuBar->DestroyMenuBar(); |
563 | delete m_frameMenuBar; | |
4bb6408c | 564 | } |
dfe1eee3 | 565 | |
621793f4 JS |
566 | m_frameMenuBar = menuBar; |
567 | m_frameMenuBar->CreateMenuBar(this); | |
4bb6408c JS |
568 | } |
569 | ||
4bb6408c JS |
570 | // Responds to colour changes, and passes event on to children. |
571 | void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) | |
572 | { | |
a756f210 | 573 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); |
4bb6408c | 574 | Refresh(); |
dfe1eee3 | 575 | |
4bb6408c JS |
576 | if ( m_frameStatusBar ) |
577 | { | |
578 | wxSysColourChangedEvent event2; | |
579 | event2.SetEventObject( m_frameStatusBar ); | |
580 | m_frameStatusBar->ProcessEvent(event2); | |
581 | } | |
dfe1eee3 | 582 | |
4bb6408c JS |
583 | // Propagate the event to the non-top-level children |
584 | wxWindow::OnSysColourChanged(event); | |
585 | } | |
586 | ||
4bb6408c JS |
587 | // Default activation behaviour - set the focus for the first child |
588 | // subwindow found. | |
589 | void wxFrame::OnActivate(wxActivateEvent& event) | |
590 | { | |
af111fc3 JS |
591 | if (!event.GetActive()) |
592 | return; | |
593 | ||
fd304d98 MB |
594 | for(wxWindowList::Node *node = GetChildren().GetFirst(); node; |
595 | node = node->GetNext()) | |
4bb6408c | 596 | { |
2d120f83 | 597 | // Find a child that's a subwindow, but not a dialog box. |
fd304d98 | 598 | wxWindow *child = node->GetData(); |
798a4529 | 599 | if (!child->IsTopLevel()) |
2d120f83 JS |
600 | { |
601 | child->SetFocus(); | |
602 | return; | |
603 | } | |
4bb6408c | 604 | } |
4bb6408c JS |
605 | } |
606 | ||
46675b46 MB |
607 | void wxFrame::SendSizeEvent() |
608 | { | |
609 | wxSizeEvent event(GetSize(), GetId()); | |
610 | event.SetEventObject(this); | |
611 | GetEventHandler()->AddPendingEvent(event); | |
612 | } | |
613 | ||
1ccbb61a | 614 | #if wxUSE_TOOLBAR |
dfe1eee3 | 615 | |
1c4f8f8d VZ |
616 | wxToolBar* wxFrame::CreateToolBar(long style, |
617 | wxWindowID id, | |
618 | const wxString& name) | |
4bb6408c | 619 | { |
1c4f8f8d | 620 | if ( wxFrameBase::CreateToolBar(style, id, name) ) |
4bb6408c | 621 | { |
4bb6408c | 622 | PositionToolBar(); |
4bb6408c | 623 | } |
4bb6408c | 624 | |
1ccbb61a VZ |
625 | return m_frameToolBar; |
626 | } | |
627 | ||
46675b46 MB |
628 | void wxFrame::SetToolBar(wxToolBar *toolbar) |
629 | { | |
630 | wxFrameBase::SetToolBar(toolbar); | |
631 | SendSizeEvent(); | |
632 | } | |
633 | ||
4bb6408c JS |
634 | void wxFrame::PositionToolBar() |
635 | { | |
798a4529 MB |
636 | wxToolBar* tb = GetToolBar(); |
637 | if (tb) | |
4bb6408c | 638 | { |
1c4f8f8d VZ |
639 | int cw, ch; |
640 | GetClientSize(& cw, &ch); | |
641 | ||
4bb6408c | 642 | int tw, th; |
798a4529 | 643 | tb->GetSize(& tw, & th); |
dfe1eee3 | 644 | |
798a4529 | 645 | if (tb->GetWindowStyleFlag() & wxTB_VERTICAL) |
4bb6408c JS |
646 | { |
647 | // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS | |
648 | // means, pretend we don't have toolbar/status bar, so we | |
649 | // have the original client size. | |
798a4529 | 650 | th = ch + th; |
4bb6408c JS |
651 | } |
652 | else | |
653 | { | |
654 | // Use the 'real' position | |
798a4529 | 655 | tw = cw; |
4bb6408c | 656 | } |
4bb6408c | 657 | |
798a4529 | 658 | tb->SetSize(0, 0, tw, th, wxSIZE_NO_ADJUSTMENTS); |
4bb6408c | 659 | } |
4bb6408c | 660 | } |
798a4529 | 661 | #endif // wxUSE_TOOLBAR |
4bb6408c JS |
662 | |
663 | //// Motif-specific | |
664 | bool wxFrame::PreResize() | |
665 | { | |
1ccbb61a | 666 | #if wxUSE_TOOLBAR |
2d120f83 | 667 | PositionToolBar(); |
1ccbb61a | 668 | #endif // wxUSE_TOOLBAR |
1c4f8f8d VZ |
669 | |
670 | #if wxUSE_STATUSBAR | |
2d120f83 | 671 | PositionStatusBar(); |
1c4f8f8d VZ |
672 | #endif // wxUSE_STATUSBAR |
673 | ||
2d120f83 | 674 | return TRUE; |
4bb6408c JS |
675 | } |
676 | ||
50414e24 JS |
677 | WXWidget wxFrame::GetClientWidget() const |
678 | { | |
2d120f83 | 679 | return m_clientArea; |
50414e24 JS |
680 | } |
681 | ||
af111fc3 | 682 | void wxFrame::ChangeFont(bool WXUNUSED(keepOriginalSize)) |
0d57be45 JS |
683 | { |
684 | // TODO | |
685 | } | |
686 | ||
687 | void wxFrame::ChangeBackgroundColour() | |
688 | { | |
621793f4 JS |
689 | if (GetClientWidget()) |
690 | DoChangeBackgroundColour(GetClientWidget(), m_backgroundColour); | |
0d57be45 JS |
691 | } |
692 | ||
693 | void wxFrame::ChangeForegroundColour() | |
694 | { | |
621793f4 JS |
695 | if (GetClientWidget()) |
696 | DoChangeForegroundColour(GetClientWidget(), m_foregroundColour); | |
0d57be45 JS |
697 | } |
698 | ||
798a4529 MB |
699 | /* MATTEW: Used to insure that hide-&-show within an event cycle works */ |
700 | static void wxFrameMapProc( Widget frameShell, XtPointer clientData, | |
701 | XCrossingEvent* event ) | |
4bb6408c | 702 | { |
798a4529 | 703 | wxFrame *tli = (wxFrame*)clientData; |
dfe1eee3 | 704 | |
798a4529 | 705 | XEvent *e = (XEvent *)event; |
dfe1eee3 | 706 | |
798a4529 | 707 | if( e->xany.type == MapNotify ) |
dc1efb1d | 708 | { |
798a4529 MB |
709 | // Iconize fix |
710 | XtVaSetValues( frameShell, XmNiconic, (Boolean)False, NULL ); | |
711 | if( !tli->GetVisibleStatus() ) | |
dc1efb1d | 712 | { |
798a4529 MB |
713 | /* We really wanted this to be hidden! */ |
714 | XtUnmapWidget( frameShell ); | |
dc1efb1d JS |
715 | } |
716 | } | |
798a4529 MB |
717 | else if( e->xany.type == UnmapNotify ) |
718 | // Iconize fix | |
719 | XtVaSetValues( frameShell, XmNiconic, (Boolean)True, NULL ); | |
dc1efb1d | 720 | } |