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