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