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