]>
Commit | Line | Data |
---|---|---|
0e320a79 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: frame.cpp | |
3 | // Purpose: wxFrame | |
f0a56ab0 | 4 | // Author: David Webster |
0e320a79 | 5 | // Modified by: |
29435d81 | 6 | // Created: 10/27/99 |
0e320a79 | 7 | // RCS-ID: $Id$ |
f0a56ab0 | 8 | // Copyright: (c) David Webster |
0e320a79 DW |
9 | // Licence: wxWindows licence |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
21802234 DW |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifndef WX_PRECOMP | |
16 | #include "wx/setup.h" | |
17 | #include "wx/frame.h" | |
18 | #include "wx/menu.h" | |
19 | #include "wx/app.h" | |
20 | #include "wx/utils.h" | |
21 | #include "wx/dialog.h" | |
22 | #include "wx/settings.h" | |
23 | #include "wx/dcclient.h" | |
24 | #endif // WX_PRECOMP | |
25 | ||
26 | #include "wx/os2/private.h" | |
f38374d0 DW |
27 | |
28 | #if wxUSE_STATUSBAR | |
29 | #include "wx/statusbr.h" | |
ea51d98d | 30 | #include "wx/generic/statusbr.h" |
f38374d0 DW |
31 | #endif // wxUSE_STATUSBAR |
32 | ||
33 | #if wxUSE_TOOLBAR | |
34 | #include "wx/toolbar.h" | |
35 | #endif // wxUSE_TOOLBAR | |
36 | ||
0e320a79 | 37 | #include "wx/menuitem.h" |
21802234 | 38 | #include "wx/log.h" |
0e320a79 | 39 | |
f38374d0 DW |
40 | // ---------------------------------------------------------------------------- |
41 | // globals | |
42 | // ---------------------------------------------------------------------------- | |
43 | ||
21802234 DW |
44 | extern wxWindowList wxModelessWindows; |
45 | extern wxList WXDLLEXPORT wxPendingDelete; | |
46 | extern wxChar wxFrameClassName[]; | |
47 | extern wxMenu *wxCurrentPopupMenu; | |
0e320a79 | 48 | |
f38374d0 DW |
49 | // ---------------------------------------------------------------------------- |
50 | // event tables | |
51 | // ---------------------------------------------------------------------------- | |
52 | ||
f38374d0 DW |
53 | BEGIN_EVENT_TABLE(wxFrame, wxFrameBase) |
54 | EVT_ACTIVATE(wxFrame::OnActivate) | |
55 | EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged) | |
0e320a79 DW |
56 | END_EVENT_TABLE() |
57 | ||
58 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow) | |
0e320a79 | 59 | |
f38374d0 DW |
60 | // ============================================================================ |
61 | // implementation | |
62 | // ============================================================================ | |
0e320a79 | 63 | |
f38374d0 DW |
64 | // ---------------------------------------------------------------------------- |
65 | // static class members | |
66 | // ---------------------------------------------------------------------------- | |
0e320a79 | 67 | |
f38374d0 | 68 | #if wxUSE_NATIVE_STATUSBAR |
a885d89a | 69 | bool wxFrame::m_bUseNativeStatusBar = TRUE; |
f38374d0 | 70 | #else |
a885d89a | 71 | bool wxFrame::m_bUseNativeStatusBar = FALSE; |
f38374d0 | 72 | #endif |
0e320a79 | 73 | |
f38374d0 DW |
74 | // ---------------------------------------------------------------------------- |
75 | // creation/destruction | |
76 | // ---------------------------------------------------------------------------- | |
77 | ||
78 | void wxFrame::Init() | |
0e320a79 | 79 | { |
80d83cbc | 80 | m_bIconized = FALSE; |
f38374d0 | 81 | |
21802234 | 82 | #if wxUSE_TOOLTIPS |
a885d89a | 83 | m_hWndToolTip = 0; |
21802234 | 84 | #endif |
ea51d98d DW |
85 | // Data to save/restore when calling ShowFullScreen |
86 | m_lFsStyle = 0L; | |
87 | m_lFsOldWindowStyle = 0L; | |
88 | m_nFsStatusBarFields = 0; | |
89 | m_nFsStatusBarHeight = 0; | |
90 | m_nFsToolBarHeight = 0; | |
91 | m_bFsIsMaximized = FALSE; | |
92 | m_bFsIsShowing = FALSE; | |
93 | } // end of wxFrame::Init | |
94 | ||
95 | bool wxFrame::Create( | |
96 | wxWindow* pParent | |
97 | , wxWindowID vId | |
98 | , const wxString& rsTitle | |
99 | , const wxPoint& rPos | |
100 | , const wxSize& rSize | |
a885d89a | 101 | , long lulStyle |
ea51d98d DW |
102 | , const wxString& rsName |
103 | ) | |
f38374d0 | 104 | { |
ea51d98d DW |
105 | int nX = rPos.x; |
106 | int nY = rPos.y; | |
107 | int nWidth = rSize.x; | |
108 | int nHeight = rSize.y; | |
ea51d98d DW |
109 | |
110 | SetName(rsName); | |
a885d89a | 111 | m_windowStyle = lulStyle; |
ea51d98d DW |
112 | m_frameMenuBar = NULL; |
113 | m_frameToolBar = NULL; | |
114 | m_frameStatusBar = NULL; | |
115 | ||
116 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); | |
117 | ||
118 | if (vId > -1 ) | |
119 | m_windowId = vId; | |
120 | else | |
121 | m_windowId = (int)NewControlId(); | |
122 | ||
80d83cbc | 123 | if (pParent) |
ea51d98d DW |
124 | pParent->AddChild(this); |
125 | ||
126 | m_bIconized = FALSE; | |
127 | ||
ea51d98d DW |
128 | if ((m_windowStyle & wxFRAME_FLOAT_ON_PARENT) == 0) |
129 | pParent = NULL; | |
130 | ||
131 | if (!pParent) | |
132 | wxTopLevelWindows.Append(this); | |
133 | ||
134 | OS2Create( m_windowId | |
135 | ,pParent | |
136 | ,wxFrameClassName | |
137 | ,this | |
138 | ,rsTitle | |
139 | ,nX | |
140 | ,nY | |
141 | ,nWidth | |
142 | ,nHeight | |
a885d89a | 143 | ,lulStyle |
ea51d98d DW |
144 | ); |
145 | ||
146 | wxModelessWindows.Append(this); | |
147 | return TRUE; | |
148 | } // end of wxFrame::Create | |
0e320a79 DW |
149 | |
150 | wxFrame::~wxFrame() | |
151 | { | |
ea51d98d DW |
152 | m_isBeingDeleted = TRUE; |
153 | wxTopLevelWindows.DeleteObject(this); | |
0e320a79 | 154 | |
ea51d98d | 155 | DeleteAllBars(); |
29435d81 | 156 | |
ea51d98d DW |
157 | if (wxTheApp && (wxTopLevelWindows.Number() == 0)) |
158 | { | |
159 | wxTheApp->SetTopWindow(NULL); | |
0e320a79 | 160 | |
ea51d98d DW |
161 | if (wxTheApp->GetExitOnFrameDelete()) |
162 | { | |
80d83cbc | 163 | ::WinPostMsg(GetHwnd(), WM_QUIT, 0, 0); |
ea51d98d DW |
164 | } |
165 | } | |
166 | wxModelessWindows.DeleteObject(this); | |
167 | ||
168 | // | |
169 | // For some reason, wxWindows can activate another task altogether | |
170 | // when a frame is destroyed after a modal dialog has been invoked. | |
171 | // Try to bring the parent to the top. | |
172 | // | |
173 | // MT:Only do this if this frame is currently the active window, else weird | |
174 | // things start to happen. | |
175 | // | |
176 | if (wxGetActiveWindow() == this) | |
0e320a79 | 177 | { |
ea51d98d DW |
178 | if (GetParent() && GetParent()->GetHWND()) |
179 | { | |
ea51d98d DW |
180 | ::WinSetWindowPos( (HWND) GetParent()->GetHWND() |
181 | ,HWND_TOP | |
80d83cbc DW |
182 | ,0 |
183 | ,0 | |
184 | ,0 | |
185 | ,0 | |
186 | ,SWP_ZORDER | |
ea51d98d DW |
187 | ); |
188 | } | |
0e320a79 | 189 | } |
ea51d98d | 190 | } // end of wxFrame::~wxFrame |
0e320a79 | 191 | |
ea51d98d | 192 | // |
0e320a79 | 193 | // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc. |
ea51d98d | 194 | // |
80d83cbc DW |
195 | void wxFrame::DoGetClientSize( |
196 | int* pX | |
197 | , int* pY | |
198 | ) const | |
0e320a79 | 199 | { |
80d83cbc | 200 | // |
a885d89a | 201 | // OS/2 PM's coordinates go from bottom-left not |
80d83cbc DW |
202 | // top-left thus the += instead of the -= |
203 | // | |
204 | RECTL vRect; | |
205 | HWND hWndClient; | |
206 | ||
207 | // | |
208 | // PM has no GetClientRect that inherantly knows about the client window | |
209 | // We have to explicitly go fetch it! | |
210 | // | |
a885d89a | 211 | hWndClient = ::WinWindowFromID(GetHwnd(), FID_CLIENT); |
80d83cbc | 212 | ::WinQueryWindowRect(hWndClient, &vRect); |
21802234 | 213 | |
f38374d0 | 214 | #if wxUSE_STATUSBAR |
80d83cbc DW |
215 | if ( GetStatusBar() ) |
216 | { | |
a885d89a | 217 | int nStatusX; |
80d83cbc DW |
218 | int nStatusY; |
219 | ||
220 | GetStatusBar()->GetClientSize( &nStatusX | |
221 | ,&nStatusY | |
222 | ); | |
223 | vRect.yBottom += nStatusY; | |
224 | } | |
f38374d0 | 225 | #endif // wxUSE_STATUSBAR |
21802234 | 226 | |
80d83cbc | 227 | wxPoint vPoint(GetClientAreaOrigin()); |
a885d89a DW |
228 | |
229 | vRect.yBottom += vPoint.y; | |
230 | vRect.xRight -= vPoint.x; | |
21802234 | 231 | |
80d83cbc DW |
232 | if (pX) |
233 | *pX = vRect.xRight; | |
234 | if (pY) | |
235 | *pY = vRect.yBottom; | |
236 | } // end of wxFrame::DoGetClientSize | |
0e320a79 | 237 | |
a885d89a | 238 | // |
0e320a79 DW |
239 | // Set the client size (i.e. leave the calculation of borders etc. |
240 | // to wxWindows) | |
80d83cbc DW |
241 | // |
242 | void wxFrame::DoSetClientSize( | |
243 | int nWidth | |
244 | , int nHeight | |
245 | ) | |
0e320a79 | 246 | { |
80d83cbc DW |
247 | HWND hWnd = GetHwnd(); |
248 | HWND hWndClient; | |
249 | RECTL vRect; | |
a7ef993c | 250 | RECTL vRect2; |
0e320a79 | 251 | |
a885d89a | 252 | hWndClient = ::WinWindowFromID(GetHwnd(), FID_CLIENT); |
80d83cbc | 253 | ::WinQueryWindowRect(hWndClient, &vRect); |
21802234 | 254 | |
80d83cbc | 255 | ::WinQueryWindowRect(hWnd, &vRect2); |
21802234 | 256 | |
80d83cbc DW |
257 | // |
258 | // Find the difference between the entire window (title bar and all) | |
259 | // and the client area; add this to the new client size to move the | |
260 | // window. Remember OS/2's backwards y coord system! | |
261 | // | |
262 | int nActualWidth = vRect2.xRight - vRect2.xLeft - vRect.xRight + nWidth; | |
263 | int nActualHeight = vRect2.yTop + vRect2.yTop - vRect.yTop + nHeight; | |
29435d81 | 264 | |
f38374d0 | 265 | #if wxUSE_STATUSBAR |
80d83cbc DW |
266 | if ( GetStatusBar() ) |
267 | { | |
268 | int nStatusX; | |
269 | int nStatusY; | |
270 | ||
271 | GetStatusBar()->GetClientSize( &nStatusX | |
272 | ,&nStatusY | |
273 | ); | |
274 | nActualHeight += nStatusY; | |
275 | } | |
f38374d0 | 276 | #endif // wxUSE_STATUSBAR |
29435d81 | 277 | |
80d83cbc DW |
278 | wxPoint vPoint(GetClientAreaOrigin()); |
279 | nActualWidth += vPoint.y; | |
280 | nActualHeight += vPoint.x; | |
281 | ||
282 | POINTL vPointl; | |
283 | ||
284 | vPointl.x = vRect2.xLeft; | |
285 | vPoint.y = vRect2.yTop; | |
286 | ||
287 | ::WinSetWindowPos( hWnd | |
288 | ,HWND_TOP | |
289 | ,vPointl.x | |
290 | ,vPointl.y | |
291 | ,nActualWidth | |
292 | ,nActualHeight | |
293 | ,SWP_MOVE | SWP_SIZE | SWP_SHOW | |
294 | ); | |
295 | ||
296 | wxSizeEvent vEvent( wxSize( nWidth | |
297 | ,nHeight | |
298 | ) | |
299 | ,m_windowId | |
300 | ); | |
301 | vEvent.SetEventObject(this); | |
302 | GetEventHandler()->ProcessEvent(vEvent); | |
303 | } // end of wxFrame::DoSetClientSize | |
304 | ||
305 | void wxFrame::DoGetSize( | |
306 | int* pWidth | |
307 | , int* pHeight | |
308 | ) const | |
309 | { | |
310 | RECTL vRect; | |
21802234 | 311 | |
80d83cbc DW |
312 | ::WinQueryWindowRect(GetHwnd(), &vRect); |
313 | *pWidth = vRect.xRight - vRect.xLeft; | |
314 | *pHeight = vRect.yTop - vRect.yBottom; | |
315 | } // end of wxFrame::DoGetSize | |
21802234 | 316 | |
80d83cbc DW |
317 | void wxFrame::DoGetPosition( |
318 | int* pX | |
319 | , int* pY | |
320 | ) const | |
321 | { | |
322 | RECTL vRect; | |
a885d89a | 323 | POINTL vPoint; |
29435d81 | 324 | |
80d83cbc DW |
325 | ::WinQueryWindowRect(GetHwnd(), &vRect); |
326 | vPoint.x = vRect.xLeft; | |
0e320a79 | 327 | |
80d83cbc DW |
328 | // |
329 | // OS/2 is backwards [WIN32 it is vRect.yTop] | |
330 | // | |
331 | vPoint.y = vRect.yBottom; | |
0e320a79 | 332 | |
80d83cbc DW |
333 | *pX = vPoint.x; |
334 | *pY = vPoint.y; | |
335 | } // end of wxFrame::DoGetPosition | |
0e320a79 | 336 | |
f38374d0 DW |
337 | // ---------------------------------------------------------------------------- |
338 | // variations around ::ShowWindow() | |
339 | // ---------------------------------------------------------------------------- | |
340 | ||
80d83cbc | 341 | void wxFrame::DoShowWindow( |
426d5745 | 342 | int bShowCmd |
80d83cbc | 343 | ) |
0e320a79 | 344 | { |
426d5745 DW |
345 | HWND hClient; |
346 | ||
7bed7a50 DW |
347 | // |
348 | // Send anything to initialize the frame | |
349 | // | |
350 | ::WinSendMsg( GetHwnd() | |
351 | ,WM_UPDATEFRAME | |
352 | ,(MPARAM)FCF_MENU | |
353 | ,(MPARAM)0 | |
354 | ); | |
426d5745 DW |
355 | hClient = ::WinWindowFromID(GetHwnd(), FID_CLIENT); |
356 | ::WinShowWindow(GetHwnd(), (BOOL)bShowCmd); | |
357 | ::WinShowWindow(hClient, (BOOL)bShowCmd); | |
80d83cbc | 358 | } // end of wxFrame::DoShowWindow |
21802234 | 359 | |
80d83cbc DW |
360 | bool wxFrame::Show( |
361 | bool bShow | |
362 | ) | |
0e320a79 | 363 | { |
426d5745 DW |
364 | SWP vSwp; |
365 | ||
366 | DoShowWindow((int)bShow); | |
21802234 | 367 | |
80d83cbc | 368 | if (bShow) |
f38374d0 | 369 | { |
80d83cbc DW |
370 | wxActivateEvent vEvent(wxEVT_ACTIVATE, TRUE, m_windowId); |
371 | ||
426d5745 | 372 | ::WinQueryWindowPos(GetHwnd(), &vSwp); |
d8530167 | 373 | m_bIconized = vSwp.fl & SWP_MINIMIZE; |
80d83cbc DW |
374 | ::WinSetWindowPos( (HWND) GetHWND() |
375 | ,HWND_TOP | |
426d5745 DW |
376 | ,vSwp.x |
377 | ,vSwp.y | |
378 | ,vSwp.cx | |
379 | ,vSwp.cy | |
380 | ,SWP_ZORDER | SWP_ACTIVATE | SWP_SHOW | SWP_MOVE | |
80d83cbc DW |
381 | ); |
382 | vEvent.SetEventObject(this); | |
383 | GetEventHandler()->ProcessEvent(vEvent); | |
f38374d0 DW |
384 | } |
385 | else | |
386 | { | |
80d83cbc | 387 | // |
f38374d0 | 388 | // Try to highlight the correct window (the parent) |
80d83cbc DW |
389 | // |
390 | if (GetParent()) | |
f38374d0 | 391 | { |
80d83cbc DW |
392 | HWND hWndParent = GetHwndOf(GetParent()); |
393 | ||
426d5745 | 394 | ::WinQueryWindowPos(hWndParent, &vSwp); |
d8530167 | 395 | m_bIconized = vSwp.fl & SWP_MINIMIZE; |
f38374d0 | 396 | if (hWndParent) |
80d83cbc DW |
397 | ::WinSetWindowPos( hWndParent |
398 | ,HWND_TOP | |
426d5745 DW |
399 | ,vSwp.x |
400 | ,vSwp.y | |
401 | ,vSwp.cx | |
402 | ,vSwp.cy | |
403 | ,SWP_ZORDER | SWP_ACTIVATE | SWP_SHOW | SWP_MOVE | |
80d83cbc | 404 | ); |
f38374d0 DW |
405 | } |
406 | } | |
f38374d0 | 407 | return TRUE; |
80d83cbc | 408 | } // end of wxFrame::Show |
f38374d0 | 409 | |
80d83cbc DW |
410 | void wxFrame::Iconize( |
411 | bool bIconize | |
412 | ) | |
f38374d0 | 413 | { |
80d83cbc DW |
414 | DoShowWindow(bIconize ? SWP_MINIMIZE : SWP_RESTORE); |
415 | } // end of wxFrame::Iconize | |
0e320a79 | 416 | |
80d83cbc DW |
417 | void wxFrame::Maximize( |
418 | bool bMaximize) | |
0e320a79 | 419 | { |
80d83cbc DW |
420 | DoShowWindow(bMaximize ? SWP_MAXIMIZE : SWP_RESTORE); |
421 | } // end of wxFrame::Maximize | |
f38374d0 DW |
422 | |
423 | void wxFrame::Restore() | |
424 | { | |
80d83cbc DW |
425 | DoShowWindow(SWP_RESTORE); |
426 | } // end of wxFrame::Restore | |
0e320a79 DW |
427 | |
428 | bool wxFrame::IsIconized() const | |
429 | { | |
80d83cbc DW |
430 | SWP vSwp; |
431 | bool bIconic; | |
432 | ||
a885d89a DW |
433 | ::WinQueryWindowPos(GetHwnd(), &vSwp); |
434 | ||
80d83cbc DW |
435 | if (vSwp.fl & SWP_MINIMIZE) |
436 | ((wxFrame*)this)->m_bIconized = TRUE; | |
437 | else | |
438 | ((wxFrame*)this)->m_bIconized = FALSE; | |
439 | return m_bIconized; | |
440 | } // end of wxFrame::IsIconized | |
0e320a79 | 441 | |
21802234 DW |
442 | // Is it maximized? |
443 | bool wxFrame::IsMaximized() const | |
0e320a79 | 444 | { |
80d83cbc DW |
445 | SWP vSwp; |
446 | bool bIconic; | |
447 | ||
a885d89a | 448 | ::WinQueryWindowPos(GetHwnd(), &vSwp); |
80d83cbc DW |
449 | return (vSwp.fl & SWP_MAXIMIZE); |
450 | } // end of wxFrame::IsMaximized | |
0e320a79 | 451 | |
0fe536e3 DW |
452 | void wxFrame::SetIcon( |
453 | const wxIcon& rIcon | |
454 | ) | |
0e320a79 | 455 | { |
0fe536e3 | 456 | wxFrameBase::SetIcon(rIcon); |
f38374d0 | 457 | |
426d5745 | 458 | if ((m_icon.GetHICON()) != NULLHANDLE) |
f38374d0 | 459 | { |
f23208ca DW |
460 | ::WinSendMsg( GetHwnd() |
461 | ,WM_SETICON | |
426d5745 | 462 | ,(MPARAM)((HPOINTER)m_icon.GetHICON()) |
f23208ca DW |
463 | ,NULL |
464 | ); | |
465 | ::WinSendMsg( GetHwnd() | |
466 | ,WM_UPDATEFRAME | |
467 | ,(MPARAM)FCF_ICON | |
468 | ,(MPARAM)0 | |
469 | ); | |
f38374d0 | 470 | } |
0fe536e3 | 471 | } // end of wxFrame::SetIcon |
0e320a79 | 472 | |
21802234 | 473 | #if wxUSE_STATUSBAR |
0fe536e3 DW |
474 | wxStatusBar* wxFrame::OnCreateStatusBar( |
475 | int nNumber | |
a885d89a | 476 | , long lulStyle |
0fe536e3 DW |
477 | , wxWindowID vId |
478 | , const wxString& rName | |
479 | ) | |
0e320a79 | 480 | { |
0fe536e3 | 481 | wxStatusBar* pStatusBar = NULL; |
0e320a79 | 482 | |
0fe536e3 | 483 | pStatusBar = wxFrameBase::OnCreateStatusBar( nNumber |
a885d89a | 484 | ,lulStyle |
0fe536e3 DW |
485 | ,vId |
486 | ,rName | |
487 | ); | |
488 | return pStatusBar; | |
489 | } // end of wxFrame::OnCreateStatusBar | |
0e320a79 DW |
490 | |
491 | void wxFrame::PositionStatusBar() | |
492 | { | |
0fe536e3 DW |
493 | // |
494 | // Native status bar positions itself | |
495 | // | |
496 | if (m_frameStatusBar) | |
f38374d0 | 497 | { |
a885d89a | 498 | int nWidth; |
0fe536e3 | 499 | int nHeight; |
a885d89a | 500 | int nStatbarWidth; |
0fe536e3 DW |
501 | int nStatbarHeight; |
502 | HWND hWndClient; | |
503 | RECTL vRect; | |
504 | ||
a885d89a | 505 | hWndClient = ::WinWindowFromID(GetHwnd(), FID_CLIENT); |
0fe536e3 DW |
506 | ::WinQueryWindowRect(hWndClient, &vRect); |
507 | nWidth = vRect.xRight - vRect.xLeft; | |
a885d89a DW |
508 | nHeight = vRect.yTop - vRect.yBottom; |
509 | ||
0fe536e3 DW |
510 | m_frameStatusBar->GetSize( &nStatbarWidth |
511 | ,&nStatbarHeight | |
512 | ); | |
f38374d0 | 513 | |
0fe536e3 | 514 | // |
f38374d0 DW |
515 | // Since we wish the status bar to be directly under the client area, |
516 | // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. | |
0fe536e3 DW |
517 | // |
518 | m_frameStatusBar->SetSize( 0 | |
519 | ,nHeight | |
520 | ,nWidth | |
521 | ,nStatbarHeight | |
522 | ); | |
f38374d0 | 523 | } |
0fe536e3 | 524 | } // end of wxFrame::PositionStatusBar |
21802234 | 525 | #endif // wxUSE_STATUSBAR |
0e320a79 | 526 | |
21802234 | 527 | void wxFrame::DetachMenuBar() |
0e320a79 | 528 | { |
21802234 | 529 | if (m_frameMenuBar) |
0e320a79 | 530 | { |
29435d81 | 531 | m_frameMenuBar->Detach(); |
0e320a79 | 532 | m_frameMenuBar = NULL; |
21802234 | 533 | } |
0fe536e3 | 534 | } // end of wxFrame::DetachMenuBar |
21802234 | 535 | |
0fe536e3 | 536 | void wxFrame::SetMenuBar( |
a885d89a | 537 | wxMenuBar* pMenuBar |
0fe536e3 | 538 | ) |
21802234 | 539 | { |
0fe536e3 | 540 | if (!pMenuBar) |
21802234 DW |
541 | { |
542 | DetachMenuBar(); | |
0e320a79 DW |
543 | return; |
544 | } | |
c3d43472 | 545 | |
29a99be3 | 546 | m_frameMenuBar = NULL; |
0e320a79 | 547 | |
29a99be3 DW |
548 | // Can set a menubar several times. |
549 | // TODO: how to prevent a memory leak if you have a currently-unattached | |
550 | // menubar? wxWindows assumes that the frame will delete the menu (otherwise | |
551 | // there are problems for MDI). | |
552 | if (pMenuBar->GetHMenu()) | |
0fe536e3 | 553 | { |
29a99be3 | 554 | m_hMenu = pMenuBar->GetHMenu(); |
0fe536e3 | 555 | } |
29a99be3 DW |
556 | else |
557 | { | |
558 | pMenuBar->Detach(); | |
21802234 | 559 | |
29a99be3 DW |
560 | m_hMenu = pMenuBar->Create(); |
561 | ||
562 | if (!m_hMenu) | |
563 | return; | |
564 | } | |
21802234 DW |
565 | |
566 | InternalSetMenuBar(); | |
567 | ||
a885d89a DW |
568 | m_frameMenuBar = pMenuBar; |
569 | pMenuBar->Attach(this); | |
0fe536e3 | 570 | } // end of wxFrame::SetMenuBar |
0e320a79 | 571 | |
21802234 | 572 | void wxFrame::InternalSetMenuBar() |
0e320a79 | 573 | { |
f23208ca | 574 | WinSendMsg((HWND)GetHwnd(), WM_UPDATEFRAME, (MPARAM)FCF_MENU, (MPARAM)0); |
0fe536e3 | 575 | } // end of wxFrame::InternalSetMenuBar |
0e320a79 | 576 | |
a885d89a DW |
577 | // |
578 | // Responds to colour changes, and passes event on to children | |
579 | // | |
580 | void wxFrame::OnSysColourChanged( | |
581 | wxSysColourChangedEvent& rEvent | |
582 | ) | |
0e320a79 DW |
583 | { |
584 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); | |
585 | Refresh(); | |
586 | ||
a885d89a | 587 | if (m_frameStatusBar) |
0e320a79 | 588 | { |
a885d89a DW |
589 | wxSysColourChangedEvent vEvent2; |
590 | ||
591 | vEvent2.SetEventObject(m_frameStatusBar); | |
592 | m_frameStatusBar->GetEventHandler()->ProcessEvent(vEvent2); | |
0e320a79 DW |
593 | } |
594 | ||
a885d89a | 595 | // |
0e320a79 | 596 | // Propagate the event to the non-top-level children |
a885d89a DW |
597 | // |
598 | wxWindow::OnSysColourChanged(rEvent); | |
599 | } // end of wxFrame::OnSysColourChanged | |
21802234 | 600 | |
542875a8 DW |
601 | // Pass TRUE to show full screen, FALSE to restore. |
602 | bool wxFrame::ShowFullScreen( | |
603 | bool bShow | |
604 | , long lStyle | |
605 | ) | |
606 | { | |
607 | /* | |
608 | // TODO | |
609 | if (show) | |
610 | { | |
611 | if (IsFullScreen()) | |
612 | return FALSE; | |
613 | ||
614 | m_fsIsShowing = TRUE; | |
615 | m_fsStyle = style; | |
616 | ||
617 | wxToolBar *theToolBar = GetToolBar(); | |
618 | wxStatusBar *theStatusBar = GetStatusBar(); | |
619 | ||
620 | int dummyWidth; | |
621 | ||
622 | if (theToolBar) | |
623 | theToolBar->GetSize(&dummyWidth, &m_fsToolBarHeight); | |
624 | if (theStatusBar) | |
625 | theStatusBar->GetSize(&dummyWidth, &m_fsStatusBarHeight); | |
626 | ||
627 | // zap the toolbar, menubar, and statusbar | |
628 | ||
629 | if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar) | |
630 | { | |
631 | theToolBar->SetSize(-1,0); | |
632 | theToolBar->Show(FALSE); | |
633 | } | |
634 | ||
635 | if (style & wxFULLSCREEN_NOMENUBAR) | |
636 | SetMenu((HWND)GetHWND(), (HMENU) NULL); | |
637 | ||
638 | // Save the number of fields in the statusbar | |
639 | if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar) | |
640 | { | |
641 | m_fsStatusBarFields = theStatusBar->GetFieldsCount(); | |
642 | SetStatusBar((wxStatusBar*) NULL); | |
643 | delete theStatusBar; | |
644 | } | |
645 | else | |
646 | m_fsStatusBarFields = 0; | |
647 | ||
648 | // zap the frame borders | |
649 | ||
650 | // save the 'normal' window style | |
651 | m_fsOldWindowStyle = GetWindowLong((HWND)GetHWND(), GWL_STYLE); | |
652 | ||
653 | // save the old position, width & height, maximize state | |
654 | m_fsOldSize = GetRect(); | |
655 | m_fsIsMaximized = IsMaximized(); | |
656 | ||
657 | // decide which window style flags to turn off | |
658 | LONG newStyle = m_fsOldWindowStyle; | |
659 | LONG offFlags = 0; | |
660 | ||
661 | if (style & wxFULLSCREEN_NOBORDER) | |
662 | offFlags |= WS_BORDER; | |
663 | if (style & wxFULLSCREEN_NOCAPTION) | |
664 | offFlags |= (WS_CAPTION | WS_SYSMENU); | |
665 | ||
666 | newStyle &= (~offFlags); | |
667 | ||
668 | // change our window style to be compatible with full-screen mode | |
669 | SetWindowLong((HWND)GetHWND(), GWL_STYLE, newStyle); | |
670 | ||
671 | // resize to the size of the desktop | |
672 | int width, height; | |
673 | ||
674 | RECT rect; | |
675 | ::GetWindowRect(GetDesktopWindow(), &rect); | |
676 | width = rect.right - rect.left; | |
677 | height = rect.bottom - rect.top; | |
678 | ||
679 | SetSize(width, height); | |
680 | ||
681 | // now flush the window style cache and actually go full-screen | |
682 | SetWindowPos((HWND)GetHWND(), HWND_TOP, 0, 0, width, height, SWP_FRAMECHANGED); | |
683 | ||
684 | wxSizeEvent event(wxSize(width, height), GetId()); | |
685 | GetEventHandler()->ProcessEvent(event); | |
686 | ||
687 | return TRUE; | |
688 | } | |
689 | else | |
690 | { | |
691 | if (!IsFullScreen()) | |
692 | return FALSE; | |
693 | ||
694 | m_fsIsShowing = FALSE; | |
695 | ||
696 | wxToolBar *theToolBar = GetToolBar(); | |
697 | ||
698 | // restore the toolbar, menubar, and statusbar | |
699 | if (theToolBar && (m_fsStyle & wxFULLSCREEN_NOTOOLBAR)) | |
700 | { | |
701 | theToolBar->SetSize(-1, m_fsToolBarHeight); | |
702 | theToolBar->Show(TRUE); | |
703 | } | |
704 | ||
705 | if ((m_fsStyle & wxFULLSCREEN_NOSTATUSBAR) && (m_fsStatusBarFields > 0)) | |
706 | { | |
707 | CreateStatusBar(m_fsStatusBarFields); | |
708 | PositionStatusBar(); | |
709 | } | |
710 | ||
711 | if ((m_fsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0)) | |
712 | SetMenu((HWND)GetHWND(), (HMENU)m_hMenu); | |
713 | ||
714 | Maximize(m_fsIsMaximized); | |
715 | SetWindowLong((HWND)GetHWND(),GWL_STYLE, m_fsOldWindowStyle); | |
716 | SetWindowPos((HWND)GetHWND(),HWND_TOP,m_fsOldSize.x, m_fsOldSize.y, | |
717 | m_fsOldSize.width, m_fsOldSize.height, SWP_FRAMECHANGED); | |
718 | ||
719 | return TRUE; | |
720 | } | |
721 | */ | |
722 | return TRUE; | |
723 | } // end of wxFrame::ShowFullScreen | |
724 | ||
a885d89a DW |
725 | // |
726 | // Frame window | |
727 | // | |
728 | bool wxFrame::OS2Create( | |
729 | int nId | |
730 | , wxWindow* pParent | |
731 | , const wxChar* zWclass | |
732 | , wxWindow* pWxWin | |
733 | , const wxChar* zTitle | |
734 | , int nX | |
735 | , int nY | |
736 | , int nWidth | |
737 | , int nHeight | |
738 | , long ulStyle | |
739 | ) | |
21802234 | 740 | { |
f23208ca DW |
741 | ULONG ulCreateFlags = 0L; |
742 | ULONG ulStyleFlags = 0L; | |
914589c2 | 743 | ULONG ulExtraFlags = 0L; |
f23208ca DW |
744 | FRAMECDATA vFrameCtlData; |
745 | HWND hParent = NULLHANDLE; | |
746 | HWND hClient = NULLHANDLE; | |
747 | HWND hTitlebar = NULLHANDLE; | |
748 | HWND hHScroll = NULLHANDLE; | |
749 | HWND hVScroll = NULLHANDLE; | |
750 | SWP vSwp; | |
751 | SWP vSwpTitlebar; | |
752 | SWP vSwpVScroll; | |
753 | SWP vSwpHScroll; | |
a885d89a DW |
754 | |
755 | m_hDefaultIcon = (WXHICON) (wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON : wxDEFAULT_FRAME_ICON); | |
f23208ca DW |
756 | memset(&vSwp, '\0', sizeof(SWP)); |
757 | memset(&vSwpTitlebar, '\0', sizeof(SWP)); | |
758 | memset(&vSwpVScroll, '\0', sizeof(SWP)); | |
759 | memset(&vSwpHScroll, '\0', sizeof(SWP)); | |
760 | if (pParent) | |
761 | hParent = GetWinHwnd(pParent); | |
762 | else | |
763 | hParent = HWND_DESKTOP; | |
a885d89a | 764 | |
914589c2 | 765 | if (ulStyle == wxDEFAULT_FRAME_STYLE) |
f23208ca DW |
766 | ulCreateFlags = FCF_SIZEBORDER | FCF_TITLEBAR | FCF_SYSMENU | |
767 | FCF_MINMAX | FCF_VERTSCROLL | FCF_HORZSCROLL | FCF_TASKLIST; | |
a885d89a | 768 | else |
a885d89a | 769 | { |
914589c2 | 770 | if ((ulStyle & wxCAPTION) == wxCAPTION) |
f23208ca | 771 | ulCreateFlags = FCF_TASKLIST; |
914589c2 | 772 | else |
f23208ca | 773 | ulCreateFlags = FCF_NOMOVEWITHOWNER; |
914589c2 DW |
774 | |
775 | if (ulStyle & wxMINIMIZE_BOX) | |
f23208ca | 776 | ulCreateFlags |= FCF_MINBUTTON; |
914589c2 | 777 | if (ulStyle & wxMAXIMIZE_BOX) |
f23208ca | 778 | ulCreateFlags |= FCF_MAXBUTTON; |
914589c2 | 779 | if (ulStyle & wxTHICK_FRAME) |
f23208ca | 780 | ulCreateFlags |= FCF_DLGBORDER; |
914589c2 | 781 | if (ulStyle & wxSYSTEM_MENU) |
f23208ca | 782 | ulCreateFlags |= FCF_SYSMENU; |
914589c2 | 783 | if (ulStyle & wxCAPTION) |
f23208ca | 784 | ulCreateFlags |= FCF_TASKLIST; |
914589c2 DW |
785 | if (ulStyle & wxCLIP_CHILDREN) |
786 | { | |
787 | // Invalid for frame windows under PM | |
788 | } | |
a885d89a | 789 | |
914589c2 | 790 | if (ulStyle & wxTINY_CAPTION_VERT) |
f23208ca | 791 | ulCreateFlags |= FCF_TASKLIST; |
914589c2 | 792 | if (ulStyle & wxTINY_CAPTION_HORIZ) |
f23208ca DW |
793 | ulCreateFlags |= FCF_TASKLIST; |
794 | ||
914589c2 | 795 | if ((ulStyle & wxTHICK_FRAME) == 0) |
f23208ca | 796 | ulCreateFlags |= FCF_BORDER; |
914589c2 DW |
797 | if (ulStyle & wxFRAME_TOOL_WINDOW) |
798 | ulExtraFlags = kFrameToolWindow; | |
21802234 | 799 | |
914589c2 | 800 | if (ulStyle & wxSTAY_ON_TOP) |
f23208ca | 801 | ulCreateFlags |= FCF_SYSMODAL; |
914589c2 | 802 | } |
f23208ca DW |
803 | if ((ulStyle & wxMINIMIZE) || (ulStyle & wxICONIZE)) |
804 | ulStyleFlags |= WS_MINIMIZED; | |
805 | if (ulStyle & wxMAXIMIZE) | |
806 | ulStyleFlags |= WS_MAXIMIZED; | |
807 | ||
a885d89a DW |
808 | // |
809 | // Clear the visible flag, we always call show | |
810 | // | |
f23208ca | 811 | ulStyleFlags &= (unsigned long)~WS_VISIBLE; |
a885d89a | 812 | m_bIconized = FALSE; |
f23208ca DW |
813 | |
814 | // | |
815 | // Set the frame control block | |
816 | // | |
817 | vFrameCtlData.cb = sizeof(vFrameCtlData); | |
818 | vFrameCtlData.flCreateFlags = ulCreateFlags; | |
819 | vFrameCtlData.hmodResources = 0L; | |
820 | vFrameCtlData.idResources = 0; | |
821 | ||
822 | // | |
823 | // Create the frame window | |
824 | // | |
825 | if (!wxWindow::OS2Create( hParent | |
826 | ,WC_FRAME | |
827 | ,zTitle | |
828 | ,ulStyleFlags | |
829 | ,(long)nX | |
830 | ,(long)nY | |
831 | ,(long)nWidth | |
832 | ,(long)nHeight | |
833 | ,NULLHANDLE | |
834 | ,HWND_TOP | |
835 | ,(long)nId | |
836 | ,(void*)&vFrameCtlData | |
837 | ,NULL | |
838 | )) | |
a885d89a DW |
839 | { |
840 | return FALSE; | |
841 | } | |
f23208ca DW |
842 | |
843 | // | |
844 | // Create the client window. We must call the API from here rather than | |
845 | // the static base class create because we need a separate handle | |
846 | // | |
847 | if ((hClient = ::WinCreateWindow( GetHwnd() // Frame is parent | |
848 | ,zWclass // Custom client class | |
849 | ,NULL // Window title | |
850 | ,0 // No styles | |
851 | ,0, 0, 0, 0 // Window position | |
852 | ,NULLHANDLE // Owner | |
853 | ,HWND_TOP // Sibling | |
854 | ,FID_CLIENT // standard client ID | |
855 | ,NULL // Creation data | |
856 | ,NULL // Window Pres Params | |
857 | )) == 0L) | |
858 | { | |
859 | return FALSE; | |
860 | } | |
3d407eda DW |
861 | // |
862 | // Send anything to initialize the frame | |
863 | // | |
864 | ::WinSendMsg( GetHwnd() | |
865 | ,WM_UPDATEFRAME | |
866 | ,(MPARAM)FCF_TASKLIST | |
867 | ,(MPARAM)0 | |
868 | ); | |
f23208ca DW |
869 | |
870 | // | |
871 | // Now size everything. If adding a menu the client will need to be resized. | |
872 | // | |
873 | if (!::WinSetWindowPos( GetHwnd() | |
874 | ,HWND_TOP | |
875 | ,nX | |
876 | ,nY | |
877 | ,nWidth | |
878 | ,nHeight | |
879 | ,SWP_SIZE | SWP_MOVE | SWP_ACTIVATE | |
880 | )) | |
881 | return FALSE; | |
882 | ||
883 | WinQueryWindowPos(GetHwnd(), &vSwp); | |
884 | ||
885 | if (ulCreateFlags & FCF_TITLEBAR) | |
886 | { | |
887 | hTitlebar = WinWindowFromID(GetHwnd(), FID_TITLEBAR); | |
888 | WinQueryWindowPos(hTitlebar, &vSwpTitlebar); | |
889 | } | |
890 | if (ulCreateFlags & FCF_HORZSCROLL) | |
891 | { | |
892 | hHScroll = WinWindowFromID(GetHwnd(), FID_HORZSCROLL); | |
893 | WinQueryWindowPos(hHScroll, &vSwpHScroll); | |
894 | } | |
895 | if (ulCreateFlags & FCF_VERTSCROLL) | |
896 | { | |
897 | hVScroll = WinWindowFromID(GetHwnd(), FID_VERTSCROLL); | |
898 | WinQueryWindowPos(hVScroll, &vSwpVScroll); | |
899 | } | |
900 | if (!::WinSetWindowPos( hClient | |
901 | ,HWND_TOP | |
902 | ,SV_CXSIZEBORDER | |
903 | ,(SV_CYSIZEBORDER - 1) + vSwpHScroll.cy | |
904 | ,vSwp.cx - ((SV_CXSIZEBORDER * 2) + vSwpVScroll.cx) | |
905 | ,vSwp.cy - ((SV_CYSIZEBORDER * 2) + 1 + vSwpTitlebar.cy + vSwpHScroll.cy) | |
906 | ,SWP_SIZE | SWP_MOVE | |
907 | )) | |
908 | return FALSE; | |
7bed7a50 | 909 | WinQueryWindowPos(hClient, &vSwp); |
a885d89a DW |
910 | return TRUE; |
911 | } // end of wxFrame::OS2Create | |
0e320a79 | 912 | |
a885d89a | 913 | // |
0e320a79 DW |
914 | // Default activation behaviour - set the focus for the first child |
915 | // subwindow found. | |
a885d89a DW |
916 | // |
917 | void wxFrame::OnActivate( | |
918 | wxActivateEvent& rEvent | |
919 | ) | |
0e320a79 | 920 | { |
a885d89a DW |
921 | for (wxWindowList::Node* pNode = GetChildren().GetFirst(); |
922 | pNode; | |
923 | pNode = pNode->GetNext()) | |
0e320a79 | 924 | { |
21802234 DW |
925 | // FIXME all this is totally bogus - we need to do the same as wxPanel, |
926 | // but how to do it without duplicating the code? | |
927 | ||
928 | // restore focus | |
a885d89a | 929 | wxWindow* pChild = pNode->GetData(); |
21802234 | 930 | |
a885d89a | 931 | if (!pChild->IsTopLevel() |
21802234 | 932 | #if wxUSE_TOOLBAR |
a885d89a | 933 | && !wxDynamicCast(pChild, wxToolBar) |
21802234 DW |
934 | #endif // wxUSE_TOOLBAR |
935 | #if wxUSE_STATUSBAR | |
a885d89a | 936 | && !wxDynamicCast(pChild, wxStatusBar) |
21802234 DW |
937 | #endif // wxUSE_STATUSBAR |
938 | ) | |
939 | { | |
a885d89a | 940 | pChild->SetFocus(); |
21802234 DW |
941 | return; |
942 | } | |
0e320a79 | 943 | } |
a885d89a | 944 | } // end of wxFrame::OnActivate |
0e320a79 | 945 | |
f38374d0 DW |
946 | // ---------------------------------------------------------------------------- |
947 | // wxFrame size management: we exclude the areas taken by menu/status/toolbars | |
948 | // from the client area, so the client area is what's really available for the | |
949 | // frame contents | |
950 | // ---------------------------------------------------------------------------- | |
0e320a79 DW |
951 | |
952 | // Checks if there is a toolbar, and returns the first free client position | |
953 | wxPoint wxFrame::GetClientAreaOrigin() const | |
954 | { | |
a885d89a DW |
955 | wxPoint vPoint(0, 0); |
956 | ||
0e320a79 DW |
957 | if (GetToolBar()) |
958 | { | |
a885d89a DW |
959 | int nWidth; |
960 | int nHeight; | |
961 | ||
962 | GetToolBar()->GetSize( &nWidth | |
963 | ,&nHeight | |
964 | ); | |
0e320a79 DW |
965 | |
966 | if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) | |
967 | { | |
a885d89a | 968 | vPoint.x += nWidth; |
0e320a79 DW |
969 | } |
970 | else | |
971 | { | |
a885d89a DW |
972 | // PM is backwards from windows |
973 | vPoint.y += nHeight; | |
0e320a79 DW |
974 | } |
975 | } | |
a885d89a DW |
976 | return vPoint; |
977 | } // end of wxFrame::GetClientAreaOrigin | |
0e320a79 | 978 | |
f38374d0 DW |
979 | // ---------------------------------------------------------------------------- |
980 | // tool/status bar stuff | |
981 | // ---------------------------------------------------------------------------- | |
982 | ||
21802234 | 983 | #if wxUSE_TOOLBAR |
f38374d0 | 984 | |
a885d89a DW |
985 | wxToolBar* wxFrame::CreateToolBar( |
986 | long lStyle | |
987 | , wxWindowID vId | |
988 | , const wxString& rName | |
989 | ) | |
0e320a79 | 990 | { |
a885d89a DW |
991 | if (wxFrameBase::CreateToolBar( lStyle |
992 | ,vId | |
993 | ,rName | |
994 | )) | |
0e320a79 | 995 | { |
0e320a79 | 996 | PositionToolBar(); |
0e320a79 | 997 | } |
f38374d0 | 998 | return m_frameToolBar; |
a885d89a | 999 | } // end of wxFrame::CreateToolBar |
0e320a79 DW |
1000 | |
1001 | void wxFrame::PositionToolBar() | |
1002 | { | |
a885d89a DW |
1003 | HWND hWndClient; |
1004 | RECTL vRect; | |
1005 | ||
1006 | hWndClient = ::WinWindowFromID(GetHwnd(), FID_CLIENT); | |
1007 | ::WinQueryWindowRect(hWndClient, &vRect); | |
0e320a79 | 1008 | |
f38374d0 | 1009 | #if wxUSE_STATUSBAR |
a885d89a | 1010 | if (GetStatusBar()) |
0e320a79 | 1011 | { |
a885d89a DW |
1012 | int nStatusX; |
1013 | int nStatusY; | |
1014 | ||
1015 | GetStatusBar()->GetClientSize( &nStatusX | |
1016 | ,&nStatusY | |
1017 | ); | |
1018 | // PM is backwards from windows | |
1019 | vRect.yBottom += nStatusY; | |
0e320a79 | 1020 | } |
f38374d0 | 1021 | #endif // wxUSE_STATUSBAR |
0e320a79 | 1022 | |
f38374d0 | 1023 | if ( GetToolBar() ) |
0e320a79 | 1024 | { |
a885d89a DW |
1025 | int nToolbarWidth; |
1026 | int nToolbarHeight; | |
1027 | ||
1028 | GetToolBar()->GetSize( &nToolbarWidth | |
1029 | ,&nToolbarHeight | |
1030 | ); | |
0e320a79 | 1031 | |
a885d89a | 1032 | if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) |
0e320a79 | 1033 | { |
a885d89a | 1034 | nToolbarHeight = vRect.yBottom; |
0e320a79 DW |
1035 | } |
1036 | else | |
1037 | { | |
a885d89a | 1038 | nToolbarWidth = vRect.xRight; |
21802234 | 1039 | } |
f38374d0 | 1040 | |
a885d89a DW |
1041 | // |
1042 | // Use the 'real' PM position here | |
1043 | // | |
1044 | GetToolBar()->SetSize( 0 | |
1045 | ,0 | |
1046 | ,nToolbarWidth | |
1047 | ,nToolbarHeight | |
1048 | ,wxSIZE_NO_ADJUSTMENTS | |
1049 | ); | |
21802234 | 1050 | } |
a885d89a | 1051 | } // end of wxFrame::PositionToolBar |
21802234 DW |
1052 | #endif // wxUSE_TOOLBAR |
1053 | ||
f38374d0 DW |
1054 | // ---------------------------------------------------------------------------- |
1055 | // frame state (iconized/maximized/...) | |
1056 | // ---------------------------------------------------------------------------- | |
1057 | ||
a885d89a | 1058 | // |
21802234 DW |
1059 | // propagate our state change to all child frames: this allows us to emulate X |
1060 | // Windows behaviour where child frames float independently of the parent one | |
1061 | // on the desktop, but are iconized/restored with it | |
a885d89a DW |
1062 | // |
1063 | void wxFrame::IconizeChildFrames( | |
1064 | bool bIconize | |
1065 | ) | |
21802234 | 1066 | { |
a885d89a DW |
1067 | for (wxWindowList::Node* pNode = GetChildren().GetFirst(); |
1068 | pNode; | |
1069 | pNode = pNode->GetNext() ) | |
21802234 | 1070 | { |
a885d89a | 1071 | wxWindow* pWin = pNode->GetData(); |
21802234 | 1072 | |
a885d89a | 1073 | if (pWin->IsKindOf(CLASSINFO(wxFrame)) ) |
21802234 | 1074 | { |
a885d89a | 1075 | ((wxFrame *)pWin)->Iconize(bIconize); |
0e320a79 DW |
1076 | } |
1077 | } | |
a885d89a | 1078 | } // end of wxFrame::IconizeChildFrames |
0e320a79 | 1079 | |
21802234 DW |
1080 | // =========================================================================== |
1081 | // message processing | |
1082 | // =========================================================================== | |
1083 | ||
1084 | // --------------------------------------------------------------------------- | |
1085 | // preprocessing | |
1086 | // --------------------------------------------------------------------------- | |
a885d89a DW |
1087 | bool wxFrame::OS2TranslateMessage( |
1088 | WXMSG* pMsg | |
1089 | ) | |
21802234 | 1090 | { |
a885d89a | 1091 | if (wxWindow::OS2TranslateMessage(pMsg)) |
29435d81 | 1092 | return TRUE; |
a885d89a | 1093 | // |
21802234 | 1094 | // try the menu bar accels |
a885d89a DW |
1095 | // |
1096 | wxMenuBar* pMenuBar = GetMenuBar(); | |
1097 | ||
1098 | if (!pMenuBar ) | |
21802234 DW |
1099 | return FALSE; |
1100 | ||
a885d89a DW |
1101 | const wxAcceleratorTable& rAcceleratorTable = pMenuBar->GetAccelTable(); |
1102 | return rAcceleratorTable.Translate(this, pMsg); | |
1103 | } // end of wxFrame::OS2TranslateMessage | |
21802234 DW |
1104 | |
1105 | // --------------------------------------------------------------------------- | |
1106 | // our private (non virtual) message handlers | |
1107 | // --------------------------------------------------------------------------- | |
21802234 DW |
1108 | bool wxFrame::HandlePaint() |
1109 | { | |
a885d89a DW |
1110 | RECTL vRect; |
1111 | ||
1112 | if (::WinQueryUpdateRect(GetHwnd(), &vRect)) | |
29435d81 | 1113 | { |
a885d89a | 1114 | if (m_bIconized) |
29435d81 | 1115 | { |
a885d89a DW |
1116 | // |
1117 | // Icons in PM are the same as "pointers" | |
1118 | // | |
1119 | HPOINTER hIcon; | |
29435d81 | 1120 | |
a885d89a DW |
1121 | if (m_icon.Ok()) |
1122 | hIcon = (HPOINTER)::WinSendMsg(GetHwnd(), WM_QUERYICON, 0L, 0L); | |
1123 | else | |
1124 | hIcon = (HPOINTER)m_hDefaultIcon; | |
1125 | ||
1126 | // | |
21802234 DW |
1127 | // Hold a pointer to the dc so long as the OnPaint() message |
1128 | // is being processed | |
a885d89a DW |
1129 | // |
1130 | RECTL vRect2; | |
1131 | HPS hPs = ::WinBeginPaint(GetHwnd(), NULLHANDLE, &vRect2); | |
29435d81 | 1132 | |
a885d89a | 1133 | // |
29435d81 | 1134 | // Erase background before painting or we get white background |
a885d89a DW |
1135 | // |
1136 | OS2DefWindowProc(WM_ERASEBACKGROUND, (MPARAM)hPs, (MPARAM)&vRect2); | |
29435d81 | 1137 | |
a885d89a | 1138 | if (hIcon) |
29435d81 | 1139 | { |
a885d89a DW |
1140 | HWND hWndClient; |
1141 | RECTL vRect3; | |
21802234 | 1142 | |
a885d89a DW |
1143 | hWndClient = ::WinWindowFromID(GetHwnd(), FID_CLIENT); |
1144 | ::WinQueryWindowRect(hWndClient, &vRect3); | |
29435d81 | 1145 | |
a885d89a DW |
1146 | static const int nIconWidth = 32; |
1147 | static const int nIconHeight = 32; | |
1148 | int nIconX = (int)((vRect3.xRight - nIconWidth)/2); | |
1149 | int nIconY = (int)((vRect3.yBottom + nIconHeight)/2); | |
29435d81 | 1150 | |
a885d89a | 1151 | ::WinDrawPointer(hPs, nIconX, nIconY, hIcon, DP_NORMAL); |
29435d81 | 1152 | } |
a885d89a | 1153 | ::WinEndPaint(hPs); |
29435d81 DW |
1154 | return TRUE; |
1155 | } | |
1156 | else | |
1157 | { | |
1158 | return wxWindow::HandlePaint(); | |
1159 | } | |
1160 | } | |
1161 | else | |
1162 | { | |
1163 | // nothing to paint - processed | |
1164 | return TRUE; | |
1165 | } | |
29435d81 | 1166 | return FALSE; |
a885d89a | 1167 | } // end of wxFrame::HandlePaint |
21802234 | 1168 | |
a885d89a DW |
1169 | bool wxFrame::HandleSize( |
1170 | int nX | |
1171 | , int nY | |
1172 | , WXUINT nId | |
1173 | ) | |
21802234 | 1174 | { |
a885d89a | 1175 | bool bProcessed = FALSE; |
21802234 | 1176 | |
a885d89a | 1177 | switch (nId) |
21802234 | 1178 | { |
a885d89a DW |
1179 | case kSizeNormal: |
1180 | // | |
1181 | // Only do it it if we were iconized before, otherwise resizing the | |
21802234 DW |
1182 | // parent frame has a curious side effect of bringing it under it's |
1183 | // children | |
a885d89a | 1184 | if (!m_bIconized ) |
21802234 DW |
1185 | break; |
1186 | ||
a885d89a | 1187 | // |
21802234 | 1188 | // restore all child frames too |
a885d89a | 1189 | // |
21802234 DW |
1190 | IconizeChildFrames(FALSE); |
1191 | ||
a885d89a | 1192 | // |
21802234 | 1193 | // fall through |
a885d89a | 1194 | // |
21802234 | 1195 | |
a885d89a DW |
1196 | case kSizeMax: |
1197 | m_bIconized = FALSE; | |
21802234 DW |
1198 | break; |
1199 | ||
a885d89a DW |
1200 | case kSizeMin: |
1201 | // | |
1202 | // Iconize all child frames too | |
1203 | // | |
21802234 | 1204 | IconizeChildFrames(TRUE); |
a885d89a | 1205 | m_bIconized = TRUE; |
21802234 DW |
1206 | break; |
1207 | } | |
f38374d0 | 1208 | |
a885d89a | 1209 | if (!m_bIconized) |
21802234 | 1210 | { |
a885d89a | 1211 | // |
29435d81 | 1212 | // forward WM_SIZE to status bar control |
a885d89a | 1213 | // |
f38374d0 DW |
1214 | #if wxUSE_NATIVE_STATUSBAR |
1215 | if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95))) | |
1216 | { | |
a885d89a DW |
1217 | wxSizeEvent vEvent( wxSize( nX |
1218 | ,nY | |
1219 | ) | |
1220 | ,m_frameStatusBar->GetId() | |
1221 | ); | |
f38374d0 | 1222 | |
a885d89a DW |
1223 | vEvent.SetEventObject(m_frameStatusBar); |
1224 | m_frameStatusBar->OnSize(vEvent); | |
f38374d0 DW |
1225 | } |
1226 | #endif // wxUSE_NATIVE_STATUSBAR | |
1227 | ||
21802234 DW |
1228 | PositionStatusBar(); |
1229 | PositionToolBar(); | |
a885d89a DW |
1230 | wxSizeEvent vEvent( wxSize( nX |
1231 | ,nY | |
1232 | ) | |
1233 | ,m_windowId | |
1234 | ); | |
21802234 | 1235 | |
a885d89a DW |
1236 | vEvent.SetEventObject(this); |
1237 | bProcessed = GetEventHandler()->ProcessEvent(vEvent); | |
21802234 | 1238 | } |
a885d89a DW |
1239 | return bProcessed; |
1240 | } // end of wxFrame::HandleSize | |
21802234 | 1241 | |
a885d89a DW |
1242 | bool wxFrame::HandleCommand( |
1243 | WXWORD nId | |
1244 | , WXWORD nCmd | |
1245 | , WXHWND hControl | |
1246 | ) | |
21802234 | 1247 | { |
a885d89a | 1248 | if (hControl) |
21802234 | 1249 | { |
a885d89a | 1250 | // |
21802234 | 1251 | // In case it's e.g. a toolbar. |
a885d89a DW |
1252 | // |
1253 | wxWindow* pWin = wxFindWinFromHandle(hControl); | |
1254 | ||
1255 | if (pWin) | |
1256 | return pWin->OS2Command( nCmd | |
1257 | ,nId | |
1258 | ); | |
21802234 DW |
1259 | } |
1260 | ||
a885d89a DW |
1261 | // |
1262 | // Handle here commands from menus and accelerators | |
1263 | // | |
1264 | if (nCmd == 0 || nCmd == 1) | |
21802234 | 1265 | { |
a885d89a | 1266 | if (wxCurrentPopupMenu) |
21802234 | 1267 | { |
a885d89a DW |
1268 | wxMenu* pPopupMenu = wxCurrentPopupMenu; |
1269 | ||
21802234 DW |
1270 | wxCurrentPopupMenu = NULL; |
1271 | ||
a885d89a DW |
1272 | return pPopupMenu->OS2Command( nCmd |
1273 | ,nId | |
1274 | ); | |
21802234 DW |
1275 | } |
1276 | ||
a885d89a | 1277 | if (ProcessCommand(nId)) |
21802234 DW |
1278 | { |
1279 | return TRUE; | |
1280 | } | |
1281 | } | |
21802234 | 1282 | return FALSE; |
a885d89a | 1283 | } // end of wxFrame::HandleCommand |
21802234 | 1284 | |
a885d89a DW |
1285 | bool wxFrame::HandleMenuSelect( |
1286 | WXWORD nItem | |
1287 | , WXWORD nFlags | |
1288 | , WXHMENU hMenu | |
1289 | ) | |
21802234 | 1290 | { |
a885d89a DW |
1291 | int nMenuItem; |
1292 | ||
1293 | if (nFlags == 0xFFFF && hMenu == 0) | |
21802234 | 1294 | { |
a885d89a DW |
1295 | // |
1296 | // Menu was removed from screen | |
1297 | // | |
1298 | nMenuItem = -1; | |
21802234 | 1299 | } |
a885d89a | 1300 | else if (!(nFlags & MIS_SUBMENU) && !(nFlags & MIS_SEPARATOR)) |
21802234 | 1301 | { |
a885d89a | 1302 | nMenuItem = nItem; |
21802234 | 1303 | } |
21802234 DW |
1304 | else |
1305 | { | |
a885d89a DW |
1306 | // |
1307 | // Don't give hints for separators (doesn't make sense) nor for the | |
21802234 | 1308 | // items opening popup menus (they don't have them anyhow) |
a885d89a | 1309 | // |
21802234 DW |
1310 | return FALSE; |
1311 | } | |
a885d89a | 1312 | wxMenuEvent vEvent(wxEVT_MENU_HIGHLIGHT, nMenuItem); |
21802234 | 1313 | |
a885d89a DW |
1314 | vEvent.SetEventObject(this); |
1315 | return GetEventHandler()->ProcessEvent(vEvent); | |
1316 | } // end of wxFrame::HandleMenuSelect | |
21802234 DW |
1317 | |
1318 | // --------------------------------------------------------------------------- | |
1319 | // the window proc for wxFrame | |
1320 | // --------------------------------------------------------------------------- | |
1321 | ||
a885d89a DW |
1322 | MRESULT wxFrame::OS2WindowProc( |
1323 | WXUINT uMessage | |
1324 | , WXWPARAM wParam | |
1325 | , WXLPARAM lParam | |
1326 | ) | |
21802234 | 1327 | { |
a885d89a DW |
1328 | MRESULT mRc = 0L; |
1329 | bool bProcessed = FALSE; | |
21802234 | 1330 | |
a885d89a | 1331 | switch (uMessage) |
21802234 DW |
1332 | { |
1333 | case WM_CLOSE: | |
a885d89a DW |
1334 | // |
1335 | // If we can't close, tell the system that we processed the | |
21802234 | 1336 | // message - otherwise it would close us |
a885d89a DW |
1337 | // |
1338 | bProcessed = !Close(); | |
21802234 DW |
1339 | break; |
1340 | ||
1341 | case WM_COMMAND: | |
1342 | { | |
a885d89a DW |
1343 | WORD wId; |
1344 | WORD wCmd; | |
1345 | WXHWND hWnd; | |
1346 | ||
1347 | UnpackCommand( (WXWPARAM)wParam | |
1348 | ,(WXLPARAM)lParam | |
1349 | ,&wId | |
1350 | ,&hWnd | |
1351 | ,&wCmd | |
1352 | ); | |
1353 | bProcessed = HandleCommand( wId | |
1354 | ,wCmd | |
1355 | ,(WXHWND)hWnd | |
1356 | ); | |
21802234 DW |
1357 | } |
1358 | break; | |
1359 | ||
1360 | case WM_MENUSELECT: | |
1361 | { | |
a885d89a DW |
1362 | WXWORD wItem; |
1363 | WXWORD wFlags; | |
1364 | WXHMENU hMenu; | |
1365 | ||
1366 | UnpackMenuSelect( wParam | |
1367 | ,lParam | |
1368 | ,&wItem | |
1369 | ,&wFlags | |
1370 | ,&hMenu | |
1371 | ); | |
1372 | bProcessed = HandleMenuSelect( wItem | |
1373 | ,wFlags | |
1374 | ,hMenu | |
1375 | ); | |
21802234 DW |
1376 | } |
1377 | break; | |
1378 | ||
1379 | case WM_PAINT: | |
a885d89a | 1380 | bProcessed = HandlePaint(); |
21802234 DW |
1381 | break; |
1382 | ||
a885d89a | 1383 | case CM_QUERYDRAGIMAGE: |
21802234 | 1384 | { |
a885d89a DW |
1385 | HPOINTER hIcon; |
1386 | ||
1387 | if (m_icon.Ok()) | |
1388 | hIcon = (HPOINTER)::WinSendMsg(GetHwnd(), WM_QUERYICON, 0L, 0L); | |
1389 | else | |
1390 | hIcon = (HPOINTER)m_hDefaultIcon; | |
1391 | mRc = (MRESULT)hIcon; | |
1392 | bProcessed = mRc != 0; | |
21802234 DW |
1393 | } |
1394 | break; | |
1395 | ||
1396 | case WM_SIZE: | |
a885d89a | 1397 | bProcessed = HandleSize(LOWORD(lParam), HIWORD(lParam), (WXUINT)wParam); |
21802234 DW |
1398 | break; |
1399 | } | |
f38374d0 | 1400 | |
a885d89a DW |
1401 | if (!bProcessed ) |
1402 | mRc = wxWindow::OS2WindowProc( uMessage | |
1403 | ,wParam | |
1404 | ,lParam | |
1405 | ); | |
f38374d0 | 1406 | return (MRESULT)0; |
a885d89a | 1407 | } // wxFrame::OS2WindowProc |
21802234 | 1408 |