Commit | Line | Data |
---|---|---|
0e320a79 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: frame.cpp | |
0d53fc34 | 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 | |
51c1d535 DW |
16 | #include "wx/defs.h" |
17 | #include "wx/object.h" | |
18 | #include "wx/dynarray.h" | |
19 | #include "wx/list.h" | |
20 | #include "wx/hash.h" | |
21 | #include "wx/string.h" | |
22 | #include "wx/intl.h" | |
23 | #include "wx/log.h" | |
24 | #include "wx/event.h" | |
21802234 DW |
25 | #include "wx/setup.h" |
26 | #include "wx/frame.h" | |
27 | #include "wx/menu.h" | |
28 | #include "wx/app.h" | |
29 | #include "wx/utils.h" | |
30 | #include "wx/dialog.h" | |
31 | #include "wx/settings.h" | |
32 | #include "wx/dcclient.h" | |
2aa60728 | 33 | #include "wx/mdi.h" |
21802234 DW |
34 | #endif // WX_PRECOMP |
35 | ||
36 | #include "wx/os2/private.h" | |
f38374d0 DW |
37 | |
38 | #if wxUSE_STATUSBAR | |
39 | #include "wx/statusbr.h" | |
ea51d98d | 40 | #include "wx/generic/statusbr.h" |
f38374d0 DW |
41 | #endif // wxUSE_STATUSBAR |
42 | ||
43 | #if wxUSE_TOOLBAR | |
44 | #include "wx/toolbar.h" | |
45 | #endif // wxUSE_TOOLBAR | |
46 | ||
0e320a79 | 47 | #include "wx/menuitem.h" |
21802234 | 48 | #include "wx/log.h" |
0e320a79 | 49 | |
f38374d0 DW |
50 | // ---------------------------------------------------------------------------- |
51 | // globals | |
52 | // ---------------------------------------------------------------------------- | |
53 | ||
21802234 DW |
54 | extern wxWindowList wxModelessWindows; |
55 | extern wxList WXDLLEXPORT wxPendingDelete; | |
19193a2c KB |
56 | |
57 | #if wxUSE_MENUS_NATIVE | |
21802234 | 58 | extern wxMenu *wxCurrentPopupMenu; |
19193a2c | 59 | #endif |
0e320a79 | 60 | |
19193a2c KB |
61 | extern void wxAssociateWinWithHandle( HWND hWnd |
62 | ,wxWindowOS2* pWin | |
b7084589 | 63 | ); |
51c1d535 | 64 | |
f38374d0 DW |
65 | // ---------------------------------------------------------------------------- |
66 | // event tables | |
67 | // ---------------------------------------------------------------------------- | |
68 | ||
0d53fc34 VS |
69 | BEGIN_EVENT_TABLE(wxFrame, wxFrameBase) |
70 | EVT_ACTIVATE(wxFrame::OnActivate) | |
71 | EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged) | |
0e320a79 DW |
72 | END_EVENT_TABLE() |
73 | ||
8d7ddd02 | 74 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow) |
0e320a79 | 75 | |
f38374d0 DW |
76 | // ============================================================================ |
77 | // implementation | |
78 | // ============================================================================ | |
0e320a79 | 79 | |
f38374d0 DW |
80 | // ---------------------------------------------------------------------------- |
81 | // static class members | |
82 | // ---------------------------------------------------------------------------- | |
7e99520b | 83 | #if wxUSE_STATUSBAR |
0e320a79 | 84 | |
f38374d0 | 85 | #if wxUSE_NATIVE_STATUSBAR |
0d53fc34 | 86 | bool wxFrame::m_bUseNativeStatusBar = TRUE; |
f38374d0 | 87 | #else |
0d53fc34 | 88 | bool wxFrame::m_bUseNativeStatusBar = FALSE; |
f38374d0 | 89 | #endif |
0e320a79 | 90 | |
7e99520b DW |
91 | #endif //wxUSE_STATUSBAR |
92 | ||
f38374d0 DW |
93 | // ---------------------------------------------------------------------------- |
94 | // creation/destruction | |
95 | // ---------------------------------------------------------------------------- | |
96 | ||
0d53fc34 | 97 | void wxFrame::Init() |
0e320a79 | 98 | { |
ea51d98d DW |
99 | m_nFsStatusBarFields = 0; |
100 | m_nFsStatusBarHeight = 0; | |
101 | m_nFsToolBarHeight = 0; | |
5d44b24e | 102 | m_hWndToolTip = 0L; |
0cf6acbf | 103 | m_bWasMinimized = FALSE; |
5d44b24e DW |
104 | m_pWinLastFocused = NULL; |
105 | ||
106 | ||
107 | m_frameMenuBar = NULL; | |
108 | m_frameToolBar = NULL; | |
109 | m_frameStatusBar = NULL; | |
40bd6154 | 110 | |
5d44b24e DW |
111 | m_hTitleBar = NULLHANDLE; |
112 | m_hHScroll = NULLHANDLE; | |
113 | m_hVScroll = NULLHANDLE; | |
51c1d535 | 114 | |
40bd6154 DW |
115 | // |
116 | // Initialize SWP's | |
117 | // | |
40bd6154 DW |
118 | memset(&m_vSwpTitleBar, 0, sizeof(SWP)); |
119 | memset(&m_vSwpMenuBar, 0, sizeof(SWP)); | |
120 | memset(&m_vSwpHScroll, 0, sizeof(SWP)); | |
121 | memset(&m_vSwpVScroll, 0, sizeof(SWP)); | |
122 | memset(&m_vSwpStatusBar, 0, sizeof(SWP)); | |
123 | memset(&m_vSwpToolBar, 0, sizeof(SWP)); | |
5d44b24e DW |
124 | m_bIconized = FALSE; |
125 | ||
0d53fc34 | 126 | } // end of wxFrame::Init |
ea51d98d | 127 | |
0d53fc34 | 128 | bool wxFrame::Create( |
ea51d98d DW |
129 | wxWindow* pParent |
130 | , wxWindowID vId | |
131 | , const wxString& rsTitle | |
132 | , const wxPoint& rPos | |
133 | , const wxSize& rSize | |
5d44b24e | 134 | , long lStyle |
ea51d98d DW |
135 | , const wxString& rsName |
136 | ) | |
f38374d0 | 137 | { |
5d44b24e DW |
138 | if (!wxTopLevelWindow::Create( pParent |
139 | ,vId | |
140 | ,rsTitle | |
141 | ,rPos | |
142 | ,rSize | |
143 | ,lStyle | |
144 | ,rsName | |
145 | )) | |
146 | return FALSE; | |
5d44b24e DW |
147 | wxModelessWindows.Append(this); |
148 | return TRUE; | |
0d53fc34 | 149 | } // end of wxFrame::Create |
0e320a79 | 150 | |
0d53fc34 | 151 | wxFrame::~wxFrame() |
0e320a79 | 152 | { |
ea51d98d | 153 | m_isBeingDeleted = TRUE; |
ea51d98d | 154 | DeleteAllBars(); |
0d53fc34 | 155 | } // end of wxFrame::~wxFrame |
0e320a79 | 156 | |
ea51d98d | 157 | // |
0e320a79 | 158 | // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc. |
ea51d98d | 159 | // |
0d53fc34 | 160 | void wxFrame::DoGetClientSize( |
80d83cbc DW |
161 | int* pX |
162 | , int* pY | |
163 | ) const | |
0e320a79 | 164 | { |
5d44b24e DW |
165 | wxTopLevelWindow::DoGetClientSize( pX |
166 | ,pY | |
167 | ); | |
5fb9d2be DW |
168 | // |
169 | // No need to use statusbar code as in WIN32 as the FORMATFRAME | |
170 | // window procedure ensures PM knows about the new frame client | |
5d44b24e DW |
171 | // size internally. A ::WinQueryWindowRect (that is called in |
172 | // wxWindow's GetClient size from above) is all that is needed! | |
5fb9d2be | 173 | // |
0d53fc34 | 174 | } // end of wxFrame::DoGetClientSize |
0e320a79 | 175 | |
a885d89a | 176 | // |
0e320a79 DW |
177 | // Set the client size (i.e. leave the calculation of borders etc. |
178 | // to wxWindows) | |
80d83cbc | 179 | // |
0d53fc34 | 180 | void wxFrame::DoSetClientSize( |
80d83cbc DW |
181 | int nWidth |
182 | , int nHeight | |
183 | ) | |
0e320a79 | 184 | { |
5d44b24e | 185 | wxStatusBar* pStatusBar = GetStatusBar(); |
21802234 | 186 | |
80d83cbc | 187 | // |
5d44b24e DW |
188 | // Statusbars are not part of the OS/2 Client but parent frame |
189 | // so no statusbar consideration | |
80d83cbc | 190 | // |
5d44b24e DW |
191 | wxTopLevelWindow::DoSetClientSize( nWidth |
192 | ,nHeight | |
193 | ); | |
0d53fc34 | 194 | } // end of wxFrame::DoSetClientSize |
80d83cbc | 195 | |
f38374d0 | 196 | // ---------------------------------------------------------------------------- |
5d44b24e | 197 | // wxFrame: various geometry-related functions |
f38374d0 DW |
198 | // ---------------------------------------------------------------------------- |
199 | ||
5d44b24e | 200 | void wxFrame::Raise() |
0e320a79 | 201 | { |
5d44b24e DW |
202 | wxFrameBase::Raise(); |
203 | ::WinSetWindowPos( (HWND) GetParent()->GetHWND() | |
204 | ,HWND_TOP | |
205 | ,0 | |
206 | ,0 | |
207 | ,0 | |
208 | ,0 | |
209 | ,SWP_ZORDER | |
210 | ); | |
211 | } | |
21802234 | 212 | |
21802234 | 213 | #if wxUSE_STATUSBAR |
0d53fc34 | 214 | wxStatusBar* wxFrame::OnCreateStatusBar( |
0fe536e3 | 215 | int nNumber |
a885d89a | 216 | , long lulStyle |
0fe536e3 DW |
217 | , wxWindowID vId |
218 | , const wxString& rName | |
219 | ) | |
0e320a79 | 220 | { |
0fe536e3 | 221 | wxStatusBar* pStatusBar = NULL; |
f6bcfd97 BP |
222 | SWP vSwp; |
223 | ERRORID vError; | |
224 | wxString sError; | |
0e320a79 | 225 | |
0fe536e3 | 226 | pStatusBar = wxFrameBase::OnCreateStatusBar( nNumber |
a885d89a | 227 | ,lulStyle |
0fe536e3 DW |
228 | ,vId |
229 | ,rName | |
5b3ed311 DW |
230 | ); |
231 | ||
232 | if( !pStatusBar ) | |
f6bcfd97 | 233 | return NULL; |
f6bcfd97 | 234 | |
54ffa107 DW |
235 | wxClientDC vDC(pStatusBar); |
236 | int nY; | |
237 | ||
238 | // | |
239 | // Set the height according to the font and the border size | |
240 | // | |
241 | vDC.SetFont(pStatusBar->GetFont()); // Screws up the menues for some reason | |
242 | vDC.GetTextExtent( "X" | |
243 | ,NULL | |
244 | ,&nY | |
245 | ); | |
246 | ||
247 | int nHeight = ((11 * nY) / 10 + 2 * pStatusBar->GetBorderY()); | |
248 | ||
249 | pStatusBar->SetSize( -1 | |
250 | ,-1 | |
251 | ,-1 | |
252 | ,nHeight | |
253 | ); | |
254 | ||
51c1d535 DW |
255 | ::WinSetParent( pStatusBar->GetHWND() |
256 | ,m_hFrame | |
257 | ,FALSE | |
258 | ); | |
259 | ::WinSetOwner( pStatusBar->GetHWND() | |
260 | ,m_hFrame | |
261 | ); | |
7e99520b | 262 | // |
5b3ed311 | 263 | // to show statusbar |
f6bcfd97 | 264 | // |
51c1d535 DW |
265 | if(::WinIsWindowShowing(m_hFrame)) |
266 | ::WinSendMsg(m_hFrame, WM_UPDATEFRAME, (MPARAM)~0, 0); | |
7e99520b | 267 | |
0fe536e3 | 268 | return pStatusBar; |
0d53fc34 | 269 | } // end of wxFrame::OnCreateStatusBar |
0e320a79 | 270 | |
0d53fc34 | 271 | void wxFrame::PositionStatusBar() |
0e320a79 | 272 | { |
f6bcfd97 BP |
273 | SWP vSwp; |
274 | ERRORID vError; | |
275 | wxString sError; | |
276 | ||
0fe536e3 DW |
277 | // |
278 | // Native status bar positions itself | |
279 | // | |
280 | if (m_frameStatusBar) | |
f38374d0 | 281 | { |
a885d89a | 282 | int nWidth; |
987da0d4 | 283 | int nY; |
a885d89a | 284 | int nStatbarWidth; |
0fe536e3 DW |
285 | int nStatbarHeight; |
286 | HWND hWndClient; | |
287 | RECTL vRect; | |
51c1d535 | 288 | RECTL vFRect; |
0fe536e3 | 289 | |
51c1d535 | 290 | ::WinQueryWindowRect(m_hFrame, &vRect); |
987da0d4 | 291 | nY = vRect.yTop; |
51c1d535 DW |
292 | ::WinMapWindowPoints(m_hFrame, HWND_DESKTOP, (PPOINTL)&vRect, 2); |
293 | vFRect = vRect; | |
294 | ::WinCalcFrameRect(m_hFrame, &vRect, TRUE); | |
0fe536e3 | 295 | nWidth = vRect.xRight - vRect.xLeft; |
987da0d4 | 296 | nY = nY - (vRect.yBottom - vFRect.yBottom); |
a885d89a | 297 | |
0fe536e3 DW |
298 | m_frameStatusBar->GetSize( &nStatbarWidth |
299 | ,&nStatbarHeight | |
300 | ); | |
f38374d0 | 301 | |
987da0d4 | 302 | nY= nY - nStatbarHeight; |
0fe536e3 | 303 | // |
f38374d0 DW |
304 | // Since we wish the status bar to be directly under the client area, |
305 | // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. | |
0fe536e3 | 306 | // |
51c1d535 | 307 | m_frameStatusBar->SetSize( vRect.xLeft - vFRect.xLeft |
987da0d4 | 308 | ,nY |
0fe536e3 DW |
309 | ,nWidth |
310 | ,nStatbarHeight | |
311 | ); | |
f6bcfd97 BP |
312 | if (!::WinQueryWindowPos(m_frameStatusBar->GetHWND(), &vSwp)) |
313 | { | |
314 | vError = ::WinGetLastError(vHabmain); | |
315 | sError = wxPMErrorToStr(vError); | |
51c1d535 | 316 | wxLogError("Error setting parent for StautsBar. Error: %s\n", sError); |
f6bcfd97 BP |
317 | return; |
318 | } | |
f38374d0 | 319 | } |
0d53fc34 | 320 | } // end of wxFrame::PositionStatusBar |
21802234 | 321 | #endif // wxUSE_STATUSBAR |
0e320a79 | 322 | |
19193a2c | 323 | #if wxUSE_MENUS_NATIVE |
0d53fc34 | 324 | void wxFrame::DetachMenuBar() |
0e320a79 | 325 | { |
21802234 | 326 | if (m_frameMenuBar) |
0e320a79 | 327 | { |
29435d81 | 328 | m_frameMenuBar->Detach(); |
0e320a79 | 329 | m_frameMenuBar = NULL; |
21802234 | 330 | } |
0d53fc34 | 331 | } // end of wxFrame::DetachMenuBar |
21802234 | 332 | |
0d53fc34 | 333 | void wxFrame::SetMenuBar( |
a885d89a | 334 | wxMenuBar* pMenuBar |
0fe536e3 | 335 | ) |
21802234 | 336 | { |
c3cea748 DW |
337 | ERRORID vError; |
338 | wxString sError; | |
dae16775 DW |
339 | HWND hTitlebar = NULLHANDLE; |
340 | HWND hHScroll = NULLHANDLE; | |
341 | HWND hVScroll = NULLHANDLE; | |
342 | HWND hMenuBar = NULLHANDLE; | |
343 | SWP vSwp; | |
344 | SWP vSwpTitlebar; | |
345 | SWP vSwpVScroll; | |
346 | SWP vSwpHScroll; | |
347 | SWP vSwpMenu; | |
c3cea748 | 348 | |
0fe536e3 | 349 | if (!pMenuBar) |
21802234 DW |
350 | { |
351 | DetachMenuBar(); | |
29a99be3 | 352 | |
64e0c5c6 DW |
353 | // |
354 | // Actually remove the menu from the frame | |
355 | // | |
356 | m_hMenu = (WXHMENU)0; | |
357 | InternalSetMenuBar(); | |
29a99be3 | 358 | } |
64e0c5c6 | 359 | else // set new non NULL menu bar |
c3cea748 | 360 | { |
64e0c5c6 | 361 | m_frameMenuBar = NULL; |
c3cea748 | 362 | |
64e0c5c6 DW |
363 | // |
364 | // Can set a menubar several times. | |
365 | // TODO: how to prevent a memory leak if you have a currently-unattached | |
366 | // menubar? wxWindows assumes that the frame will delete the menu (otherwise | |
367 | // there are problems for MDI). | |
368 | // | |
369 | if (pMenuBar->GetHMenu()) | |
370 | { | |
371 | m_hMenu = pMenuBar->GetHMenu(); | |
372 | } | |
373 | else | |
374 | { | |
375 | pMenuBar->Detach(); | |
376 | m_hMenu = pMenuBar->Create(); | |
377 | if (!m_hMenu) | |
378 | return; | |
379 | } | |
380 | InternalSetMenuBar(); | |
381 | m_frameMenuBar = pMenuBar; | |
0367c1c0 | 382 | pMenuBar->Attach((wxFrame*)this); |
c3cea748 | 383 | } |
0d53fc34 | 384 | } // end of wxFrame::SetMenuBar |
0e320a79 | 385 | |
0d53fc34 | 386 | void wxFrame::AttachMenuBar( |
893758d5 DW |
387 | wxMenuBar* pMenubar |
388 | ) | |
389 | { | |
19193a2c KB |
390 | wxFrameBase::AttachMenuBar(pMenubar); |
391 | ||
893758d5 DW |
392 | m_frameMenuBar = pMenubar; |
393 | ||
394 | if (!pMenubar) | |
395 | { | |
396 | // | |
397 | // Actually remove the menu from the frame | |
398 | // | |
399 | m_hMenu = (WXHMENU)0; | |
400 | InternalSetMenuBar(); | |
401 | } | |
402 | else // Set new non NULL menu bar | |
403 | { | |
404 | // | |
405 | // Can set a menubar several times. | |
406 | // | |
407 | if (pMenubar->GetHMenu()) | |
408 | { | |
409 | m_hMenu = pMenubar->GetHMenu(); | |
410 | } | |
411 | else | |
412 | { | |
413 | if (pMenubar->IsAttached()) | |
414 | pMenubar->Detach(); | |
415 | ||
416 | m_hMenu = pMenubar->Create(); | |
417 | ||
418 | if (!m_hMenu) | |
419 | return; | |
420 | } | |
421 | InternalSetMenuBar(); | |
422 | } | |
0d53fc34 | 423 | } // end of wxFrame::AttachMenuBar |
893758d5 | 424 | |
0d53fc34 | 425 | void wxFrame::InternalSetMenuBar() |
0e320a79 | 426 | { |
64e0c5c6 DW |
427 | ERRORID vError; |
428 | wxString sError; | |
429 | // | |
430 | // Set the parent and owner of the menubar to be the frame | |
431 | // | |
51c1d535 | 432 | if (!::WinSetParent(m_hMenu, m_hFrame, FALSE)) |
64e0c5c6 DW |
433 | { |
434 | vError = ::WinGetLastError(vHabmain); | |
435 | sError = wxPMErrorToStr(vError); | |
436 | wxLogError("Error setting parent for submenu. Error: %s\n", sError); | |
437 | } | |
438 | ||
51c1d535 | 439 | if (!::WinSetOwner(m_hMenu, m_hFrame)) |
64e0c5c6 DW |
440 | { |
441 | vError = ::WinGetLastError(vHabmain); | |
442 | sError = wxPMErrorToStr(vError); | |
443 | wxLogError("Error setting parent for submenu. Error: %s\n", sError); | |
444 | } | |
b7084589 | 445 | ::WinSendMsg(m_hFrame, WM_UPDATEFRAME, (MPARAM)FCF_MENU, (MPARAM)0); |
0d53fc34 | 446 | } // end of wxFrame::InternalSetMenuBar |
19193a2c | 447 | #endif // wxUSE_MENUS_NATIVE |
0e320a79 | 448 | |
a885d89a DW |
449 | // |
450 | // Responds to colour changes, and passes event on to children | |
451 | // | |
0d53fc34 | 452 | void wxFrame::OnSysColourChanged( |
a885d89a DW |
453 | wxSysColourChangedEvent& rEvent |
454 | ) | |
0e320a79 | 455 | { |
a756f210 | 456 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); |
0e320a79 DW |
457 | Refresh(); |
458 | ||
7e99520b | 459 | #if wxUSE_STATUSBAR |
a885d89a | 460 | if (m_frameStatusBar) |
0e320a79 | 461 | { |
a885d89a DW |
462 | wxSysColourChangedEvent vEvent2; |
463 | ||
464 | vEvent2.SetEventObject(m_frameStatusBar); | |
465 | m_frameStatusBar->GetEventHandler()->ProcessEvent(vEvent2); | |
0e320a79 | 466 | } |
7e99520b | 467 | #endif //wxUSE_STATUSBAR |
0e320a79 | 468 | |
a885d89a | 469 | // |
0e320a79 | 470 | // Propagate the event to the non-top-level children |
a885d89a DW |
471 | // |
472 | wxWindow::OnSysColourChanged(rEvent); | |
0d53fc34 | 473 | } // end of wxFrame::OnSysColourChanged |
21802234 | 474 | |
542875a8 | 475 | // Pass TRUE to show full screen, FALSE to restore. |
0d53fc34 | 476 | bool wxFrame::ShowFullScreen( |
542875a8 DW |
477 | bool bShow |
478 | , long lStyle | |
479 | ) | |
480 | { | |
64e0c5c6 | 481 | if (bShow) |
542875a8 DW |
482 | { |
483 | if (IsFullScreen()) | |
484 | return FALSE; | |
485 | ||
64e0c5c6 DW |
486 | m_bFsIsShowing = TRUE; |
487 | m_lFsStyle = lStyle; | |
542875a8 | 488 | |
7e99520b | 489 | #if wxUSE_TOOLBAR |
19193a2c | 490 | wxToolBar* pTheToolBar = GetToolBar(); |
7e99520b DW |
491 | #endif //wxUSE_TOOLBAR |
492 | ||
493 | #if wxUSE_STATUSBAR | |
19193a2c | 494 | wxStatusBar* pTheStatusBar = GetStatusBar(); |
7e99520b | 495 | #endif //wxUSE_STATUSBAR |
542875a8 | 496 | |
64e0c5c6 | 497 | int nDummyWidth; |
542875a8 | 498 | |
7e99520b | 499 | #if wxUSE_TOOLBAR |
64e0c5c6 DW |
500 | if (pTheToolBar) |
501 | pTheToolBar->GetSize(&nDummyWidth, &m_nFsToolBarHeight); | |
7e99520b DW |
502 | #endif //wxUSE_TOOLBAR |
503 | ||
504 | #if wxUSE_STATUSBAR | |
64e0c5c6 DW |
505 | if (pTheStatusBar) |
506 | pTheStatusBar->GetSize(&nDummyWidth, &m_nFsStatusBarHeight); | |
7e99520b | 507 | #endif //wxUSE_STATUSBAR |
542875a8 | 508 | |
7e99520b | 509 | #if wxUSE_TOOLBAR |
64e0c5c6 DW |
510 | // |
511 | // Zap the toolbar, menubar, and statusbar | |
512 | // | |
513 | if ((lStyle & wxFULLSCREEN_NOTOOLBAR) && pTheToolBar) | |
542875a8 | 514 | { |
64e0c5c6 DW |
515 | pTheToolBar->SetSize(-1,0); |
516 | pTheToolBar->Show(FALSE); | |
542875a8 | 517 | } |
7e99520b | 518 | #endif //wxUSE_TOOLBAR |
542875a8 | 519 | |
64e0c5c6 DW |
520 | if (lStyle & wxFULLSCREEN_NOMENUBAR) |
521 | { | |
b7084589 DW |
522 | ::WinSetParent(m_hMenu, m_hFrame, FALSE); |
523 | ::WinSetOwner(m_hMenu, m_hFrame); | |
524 | ::WinSendMsg((HWND)m_hFrame, WM_UPDATEFRAME, (MPARAM)FCF_MENU, (MPARAM)0); | |
64e0c5c6 | 525 | } |
542875a8 | 526 | |
7e99520b | 527 | #if wxUSE_STATUSBAR |
64e0c5c6 | 528 | // |
542875a8 | 529 | // Save the number of fields in the statusbar |
64e0c5c6 DW |
530 | // |
531 | if ((lStyle & wxFULLSCREEN_NOSTATUSBAR) && pTheStatusBar) | |
542875a8 | 532 | { |
64e0c5c6 | 533 | m_nFsStatusBarFields = pTheStatusBar->GetFieldsCount(); |
542875a8 | 534 | SetStatusBar((wxStatusBar*) NULL); |
64e0c5c6 | 535 | delete pTheStatusBar; |
542875a8 DW |
536 | } |
537 | else | |
64e0c5c6 | 538 | m_nFsStatusBarFields = 0; |
7e99520b | 539 | #endif //wxUSE_STATUSBAR |
542875a8 | 540 | |
64e0c5c6 DW |
541 | // |
542 | // Zap the frame borders | |
543 | // | |
542875a8 | 544 | |
64e0c5c6 DW |
545 | // |
546 | // Save the 'normal' window style | |
547 | // | |
b7084589 | 548 | m_lFsOldWindowStyle = ::WinQueryWindowULong(m_hFrame, QWL_STYLE); |
542875a8 | 549 | |
64e0c5c6 | 550 | // |
b7084589 | 551 | // Save the old position, width & height, maximize state |
64e0c5c6 DW |
552 | // |
553 | m_vFsOldSize = GetRect(); | |
554 | m_bFsIsMaximized = IsMaximized(); | |
542875a8 | 555 | |
64e0c5c6 | 556 | // |
b7084589 | 557 | // Decide which window style flags to turn off |
64e0c5c6 DW |
558 | // |
559 | LONG lNewStyle = m_lFsOldWindowStyle; | |
560 | LONG lOffFlags = 0; | |
542875a8 | 561 | |
64e0c5c6 DW |
562 | if (lStyle & wxFULLSCREEN_NOBORDER) |
563 | lOffFlags |= FCF_BORDER; | |
564 | if (lStyle & wxFULLSCREEN_NOCAPTION) | |
565 | lOffFlags |= (FCF_TASKLIST | FCF_SYSMENU); | |
542875a8 | 566 | |
64e0c5c6 | 567 | lNewStyle &= (~lOffFlags); |
542875a8 | 568 | |
64e0c5c6 DW |
569 | // |
570 | // Change our window style to be compatible with full-screen mode | |
571 | // | |
b7084589 | 572 | ::WinSetWindowULong((HWND)m_hFrame, QWL_STYLE, (ULONG)lNewStyle); |
542875a8 | 573 | |
64e0c5c6 DW |
574 | // |
575 | // Resize to the size of the desktop | |
576 | int nWidth; | |
577 | int nHeight; | |
542875a8 | 578 | |
64e0c5c6 | 579 | RECTL vRect; |
542875a8 | 580 | |
64e0c5c6 DW |
581 | ::WinQueryWindowRect(HWND_DESKTOP, &vRect); |
582 | nWidth = vRect.xRight - vRect.xLeft; | |
583 | // | |
584 | // Rmember OS/2 is backwards! | |
585 | // | |
586 | nHeight = vRect.yTop - vRect.yBottom; | |
542875a8 | 587 | |
64e0c5c6 DW |
588 | SetSize( nWidth |
589 | ,nHeight | |
590 | ); | |
542875a8 | 591 | |
64e0c5c6 DW |
592 | // |
593 | // Now flush the window style cache and actually go full-screen | |
594 | // | |
595 | ::WinSetWindowPos( (HWND) GetParent()->GetHWND() | |
596 | ,HWND_TOP | |
597 | ,0 | |
598 | ,0 | |
599 | ,nWidth | |
600 | ,nHeight | |
601 | ,SWP_SIZE | SWP_SHOW | |
602 | ); | |
603 | ||
604 | wxSizeEvent vEvent( wxSize( nWidth | |
605 | ,nHeight | |
606 | ) | |
607 | ,GetId() | |
608 | ); | |
542875a8 | 609 | |
64e0c5c6 | 610 | GetEventHandler()->ProcessEvent(vEvent); |
542875a8 DW |
611 | return TRUE; |
612 | } | |
613 | else | |
614 | { | |
615 | if (!IsFullScreen()) | |
616 | return FALSE; | |
617 | ||
64e0c5c6 | 618 | m_bFsIsShowing = FALSE; |
542875a8 | 619 | |
7e99520b | 620 | #if wxUSE_TOOLBAR |
64e0c5c6 | 621 | wxToolBar* pTheToolBar = GetToolBar(); |
542875a8 | 622 | |
64e0c5c6 DW |
623 | // |
624 | // Restore the toolbar, menubar, and statusbar | |
625 | // | |
626 | if (pTheToolBar && (m_lFsStyle & wxFULLSCREEN_NOTOOLBAR)) | |
542875a8 | 627 | { |
64e0c5c6 DW |
628 | pTheToolBar->SetSize(-1, m_nFsToolBarHeight); |
629 | pTheToolBar->Show(TRUE); | |
542875a8 | 630 | } |
7e99520b | 631 | #endif //wxUSE_TOOLBAR |
542875a8 | 632 | |
7e99520b | 633 | #if wxUSE_STATUSBAR |
64e0c5c6 | 634 | if ((m_lFsStyle & wxFULLSCREEN_NOSTATUSBAR) && (m_nFsStatusBarFields > 0)) |
542875a8 | 635 | { |
64e0c5c6 | 636 | CreateStatusBar(m_nFsStatusBarFields); |
5b3ed311 | 637 | // PositionStatusBar(); |
542875a8 | 638 | } |
7e99520b | 639 | #endif //wxUSE_STATUSBAR |
542875a8 | 640 | |
64e0c5c6 DW |
641 | if ((m_lFsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0)) |
642 | { | |
b7084589 DW |
643 | ::WinSetParent(m_hMenu, m_hFrame, FALSE); |
644 | ::WinSetOwner(m_hMenu, m_hFrame); | |
645 | ::WinSendMsg(m_hFrame, WM_UPDATEFRAME, (MPARAM)FCF_MENU, (MPARAM)0); | |
64e0c5c6 DW |
646 | } |
647 | Maximize(m_bFsIsMaximized); | |
648 | ||
b7084589 | 649 | ::WinSetWindowULong( m_hFrame |
64e0c5c6 DW |
650 | ,QWL_STYLE |
651 | ,(ULONG)m_lFsOldWindowStyle | |
652 | ); | |
653 | ::WinSetWindowPos( (HWND) GetParent()->GetHWND() | |
654 | ,HWND_TOP | |
655 | ,m_vFsOldSize.x | |
656 | ,m_vFsOldSize.y | |
657 | ,m_vFsOldSize.width | |
658 | ,m_vFsOldSize.height | |
659 | ,SWP_SIZE | SWP_SHOW | |
660 | ); | |
542875a8 DW |
661 | return TRUE; |
662 | } | |
0d53fc34 | 663 | } // end of wxFrame::ShowFullScreen |
542875a8 | 664 | |
a885d89a DW |
665 | // |
666 | // Frame window | |
667 | // | |
a885d89a | 668 | // |
0e320a79 DW |
669 | // Default activation behaviour - set the focus for the first child |
670 | // subwindow found. | |
a885d89a | 671 | // |
0d53fc34 | 672 | void wxFrame::OnActivate( |
a885d89a DW |
673 | wxActivateEvent& rEvent |
674 | ) | |
0e320a79 | 675 | { |
c4955899 | 676 | if ( rEvent.GetActive() ) |
0e320a79 | 677 | { |
c4955899 DW |
678 | // restore focus to the child which was last focused |
679 | wxLogTrace(_T("focus"), _T("wxFrame %08x activated."), m_hWnd); | |
21802234 | 680 | |
c4955899 DW |
681 | wxWindow* pParent = m_pWinLastFocused ? m_pWinLastFocused->GetParent() |
682 | : NULL; | |
683 | if (!pParent) | |
684 | { | |
685 | pParent = this; | |
686 | } | |
21802234 | 687 | |
c4955899 DW |
688 | wxSetFocusToChild( pParent |
689 | ,&m_pWinLastFocused | |
690 | ); | |
691 | } | |
692 | else // deactivating | |
693 | { | |
694 | // | |
695 | // Remember the last focused child if it is our child | |
696 | // | |
697 | m_pWinLastFocused = FindFocus(); | |
698 | ||
699 | for (wxWindowList::Node* pNode = GetChildren().GetFirst(); | |
700 | pNode; | |
701 | pNode = pNode->GetNext()) | |
702 | { | |
703 | // FIXME all this is totally bogus - we need to do the same as wxPanel, | |
704 | // but how to do it without duplicating the code? | |
705 | ||
706 | // restore focus | |
707 | wxWindow* pChild = pNode->GetData(); | |
708 | ||
709 | if (!pChild->IsTopLevel() | |
21802234 | 710 | #if wxUSE_TOOLBAR |
c4955899 | 711 | && !wxDynamicCast(pChild, wxToolBar) |
21802234 DW |
712 | #endif // wxUSE_TOOLBAR |
713 | #if wxUSE_STATUSBAR | |
c4955899 | 714 | && !wxDynamicCast(pChild, wxStatusBar) |
21802234 | 715 | #endif // wxUSE_STATUSBAR |
c4955899 DW |
716 | ) |
717 | { | |
718 | pChild->SetFocus(); | |
719 | return; | |
720 | } | |
21802234 | 721 | } |
0e320a79 | 722 | } |
0d53fc34 | 723 | } // end of wxFrame::OnActivate |
0e320a79 | 724 | |
f38374d0 DW |
725 | // ---------------------------------------------------------------------------- |
726 | // wxFrame size management: we exclude the areas taken by menu/status/toolbars | |
727 | // from the client area, so the client area is what's really available for the | |
728 | // frame contents | |
729 | // ---------------------------------------------------------------------------- | |
0e320a79 DW |
730 | |
731 | // Checks if there is a toolbar, and returns the first free client position | |
0d53fc34 | 732 | wxPoint wxFrame::GetClientAreaOrigin() const |
0e320a79 | 733 | { |
a885d89a DW |
734 | wxPoint vPoint(0, 0); |
735 | ||
7e99520b | 736 | #if wxUSE_TOOLBAR |
0e320a79 DW |
737 | if (GetToolBar()) |
738 | { | |
a885d89a DW |
739 | int nWidth; |
740 | int nHeight; | |
741 | ||
742 | GetToolBar()->GetSize( &nWidth | |
743 | ,&nHeight | |
744 | ); | |
0e320a79 DW |
745 | |
746 | if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) | |
747 | { | |
a885d89a | 748 | vPoint.x += nWidth; |
0e320a79 DW |
749 | } |
750 | else | |
751 | { | |
a885d89a DW |
752 | // PM is backwards from windows |
753 | vPoint.y += nHeight; | |
0e320a79 DW |
754 | } |
755 | } | |
7e99520b | 756 | #endif //wxUSE_TOOLBAR |
a885d89a | 757 | return vPoint; |
0d53fc34 | 758 | } // end of wxFrame::GetClientAreaOrigin |
0e320a79 | 759 | |
f38374d0 DW |
760 | // ---------------------------------------------------------------------------- |
761 | // tool/status bar stuff | |
762 | // ---------------------------------------------------------------------------- | |
763 | ||
21802234 | 764 | #if wxUSE_TOOLBAR |
f38374d0 | 765 | |
0d53fc34 | 766 | wxToolBar* wxFrame::CreateToolBar( |
a885d89a DW |
767 | long lStyle |
768 | , wxWindowID vId | |
769 | , const wxString& rName | |
770 | ) | |
0e320a79 | 771 | { |
a885d89a DW |
772 | if (wxFrameBase::CreateToolBar( lStyle |
773 | ,vId | |
774 | ,rName | |
775 | )) | |
0e320a79 | 776 | { |
0e320a79 | 777 | PositionToolBar(); |
0e320a79 | 778 | } |
f38374d0 | 779 | return m_frameToolBar; |
0d53fc34 | 780 | } // end of wxFrame::CreateToolBar |
0e320a79 | 781 | |
0d53fc34 | 782 | void wxFrame::PositionToolBar() |
0e320a79 | 783 | { |
a885d89a DW |
784 | HWND hWndClient; |
785 | RECTL vRect; | |
786 | ||
40bd6154 | 787 | ::WinQueryWindowRect(GetHwnd(), &vRect); |
0e320a79 | 788 | |
f38374d0 | 789 | #if wxUSE_STATUSBAR |
a885d89a | 790 | if (GetStatusBar()) |
0e320a79 | 791 | { |
a885d89a DW |
792 | int nStatusX; |
793 | int nStatusY; | |
794 | ||
795 | GetStatusBar()->GetClientSize( &nStatusX | |
796 | ,&nStatusY | |
797 | ); | |
798 | // PM is backwards from windows | |
799 | vRect.yBottom += nStatusY; | |
0e320a79 | 800 | } |
f38374d0 | 801 | #endif // wxUSE_STATUSBAR |
0e320a79 | 802 | |
1c84ee88 | 803 | if ( m_frameToolBar ) |
0e320a79 | 804 | { |
a885d89a DW |
805 | int nToolbarWidth; |
806 | int nToolbarHeight; | |
807 | ||
1c84ee88 | 808 | m_frameToolBar->GetSize( &nToolbarWidth |
a885d89a DW |
809 | ,&nToolbarHeight |
810 | ); | |
0e320a79 | 811 | |
a885d89a | 812 | if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) |
0e320a79 | 813 | { |
a885d89a | 814 | nToolbarHeight = vRect.yBottom; |
0e320a79 DW |
815 | } |
816 | else | |
817 | { | |
a885d89a | 818 | nToolbarWidth = vRect.xRight; |
21802234 | 819 | } |
f38374d0 | 820 | |
a885d89a DW |
821 | // |
822 | // Use the 'real' PM position here | |
823 | // | |
824 | GetToolBar()->SetSize( 0 | |
825 | ,0 | |
826 | ,nToolbarWidth | |
827 | ,nToolbarHeight | |
828 | ,wxSIZE_NO_ADJUSTMENTS | |
829 | ); | |
21802234 | 830 | } |
0d53fc34 | 831 | } // end of wxFrame::PositionToolBar |
21802234 DW |
832 | #endif // wxUSE_TOOLBAR |
833 | ||
f38374d0 DW |
834 | // ---------------------------------------------------------------------------- |
835 | // frame state (iconized/maximized/...) | |
836 | // ---------------------------------------------------------------------------- | |
837 | ||
a885d89a | 838 | // |
21802234 DW |
839 | // propagate our state change to all child frames: this allows us to emulate X |
840 | // Windows behaviour where child frames float independently of the parent one | |
841 | // on the desktop, but are iconized/restored with it | |
a885d89a | 842 | // |
0d53fc34 | 843 | void wxFrame::IconizeChildFrames( |
a885d89a DW |
844 | bool bIconize |
845 | ) | |
21802234 | 846 | { |
a885d89a DW |
847 | for (wxWindowList::Node* pNode = GetChildren().GetFirst(); |
848 | pNode; | |
849 | pNode = pNode->GetNext() ) | |
21802234 | 850 | { |
a885d89a | 851 | wxWindow* pWin = pNode->GetData(); |
0cf6acbf | 852 | wxFrame* pFrame = wxDynamicCast(pWin, wxFrame); |
21802234 | 853 | |
0cf6acbf DW |
854 | if ( pFrame |
855 | #if wxUSE_MDI_ARCHITECTURE | |
856 | && !wxDynamicCast(pFrame, wxMDIChildFrame) | |
857 | #endif // wxUSE_MDI_ARCHITECTURE | |
858 | ) | |
21802234 | 859 | { |
0cf6acbf DW |
860 | // |
861 | // We don't want to restore the child frames which had been | |
862 | // iconized even before we were iconized, so save the child frame | |
863 | // status when iconizing the parent frame and check it when | |
864 | // restoring it. | |
865 | // | |
866 | if (bIconize) | |
867 | { | |
868 | pFrame->m_bWasMinimized = pFrame->IsIconized(); | |
869 | } | |
870 | ||
871 | // | |
872 | // This test works for both iconizing and restoring | |
873 | // | |
874 | if (!pFrame->m_bWasMinimized) | |
875 | pFrame->Iconize(bIconize); | |
0e320a79 DW |
876 | } |
877 | } | |
0d53fc34 | 878 | } // end of wxFrame::IconizeChildFrames |
0e320a79 | 879 | |
5d44b24e DW |
880 | WXHICON wxFrame::GetDefaultIcon() const |
881 | { | |
882 | return (WXHICON)(wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON | |
883 | : wxDEFAULT_FRAME_ICON); | |
884 | } | |
21802234 DW |
885 | // =========================================================================== |
886 | // message processing | |
887 | // =========================================================================== | |
888 | ||
889 | // --------------------------------------------------------------------------- | |
890 | // preprocessing | |
891 | // --------------------------------------------------------------------------- | |
0d53fc34 | 892 | bool wxFrame::OS2TranslateMessage( |
a885d89a DW |
893 | WXMSG* pMsg |
894 | ) | |
21802234 | 895 | { |
a885d89a | 896 | // |
21802234 | 897 | // try the menu bar accels |
a885d89a DW |
898 | // |
899 | wxMenuBar* pMenuBar = GetMenuBar(); | |
900 | ||
19193a2c | 901 | if (!pMenuBar) |
21802234 DW |
902 | return FALSE; |
903 | ||
19193a2c | 904 | #if wxUSE_ACCEL && wxUSE_MENUS_NATIVE |
a885d89a | 905 | const wxAcceleratorTable& rAcceleratorTable = pMenuBar->GetAccelTable(); |
e604d44b | 906 | return rAcceleratorTable.Translate(GetHWND(), pMsg); |
7e99520b DW |
907 | #else |
908 | return FALSE; | |
909 | #endif //wxUSE_ACCEL | |
0d53fc34 | 910 | } // end of wxFrame::OS2TranslateMessage |
21802234 DW |
911 | |
912 | // --------------------------------------------------------------------------- | |
913 | // our private (non virtual) message handlers | |
914 | // --------------------------------------------------------------------------- | |
0d53fc34 | 915 | bool wxFrame::HandlePaint() |
21802234 | 916 | { |
a885d89a DW |
917 | RECTL vRect; |
918 | ||
e604d44b | 919 | if (::WinQueryUpdateRect(GetHWND(), &vRect)) |
29435d81 | 920 | { |
a885d89a | 921 | if (m_bIconized) |
29435d81 | 922 | { |
a885d89a DW |
923 | // |
924 | // Icons in PM are the same as "pointers" | |
925 | // | |
3437f881 | 926 | const wxIcon& vIcon = GetIcon(); |
a885d89a | 927 | HPOINTER hIcon; |
29435d81 | 928 | |
3437f881 | 929 | if (vIcon.Ok()) |
b7084589 | 930 | hIcon = (HPOINTER)::WinSendMsg(m_hFrame, WM_QUERYICON, 0L, 0L); |
a885d89a DW |
931 | else |
932 | hIcon = (HPOINTER)m_hDefaultIcon; | |
933 | ||
934 | // | |
21802234 DW |
935 | // Hold a pointer to the dc so long as the OnPaint() message |
936 | // is being processed | |
a885d89a DW |
937 | // |
938 | RECTL vRect2; | |
64e0c5c6 | 939 | HPS hPs = ::WinBeginPaint(GetHwnd(), NULLHANDLE, &vRect2); |
29435d81 | 940 | |
a885d89a | 941 | // |
29435d81 | 942 | // Erase background before painting or we get white background |
a885d89a DW |
943 | // |
944 | OS2DefWindowProc(WM_ERASEBACKGROUND, (MPARAM)hPs, (MPARAM)&vRect2); | |
29435d81 | 945 | |
a885d89a | 946 | if (hIcon) |
29435d81 | 947 | { |
a885d89a DW |
948 | HWND hWndClient; |
949 | RECTL vRect3; | |
21802234 | 950 | |
40bd6154 | 951 | ::WinQueryWindowRect(GetHwnd(), &vRect3); |
29435d81 | 952 | |
a885d89a DW |
953 | static const int nIconWidth = 32; |
954 | static const int nIconHeight = 32; | |
955 | int nIconX = (int)((vRect3.xRight - nIconWidth)/2); | |
956 | int nIconY = (int)((vRect3.yBottom + nIconHeight)/2); | |
29435d81 | 957 | |
a885d89a | 958 | ::WinDrawPointer(hPs, nIconX, nIconY, hIcon, DP_NORMAL); |
29435d81 | 959 | } |
a885d89a | 960 | ::WinEndPaint(hPs); |
29435d81 DW |
961 | return TRUE; |
962 | } | |
963 | else | |
964 | { | |
8330166c DW |
965 | if (!wxWindow::HandlePaint()) |
966 | { | |
967 | HPS hPS; | |
968 | RECTL vRect; | |
969 | ||
970 | hPS = ::WinBeginPaint( GetHwnd() | |
971 | ,NULLHANDLE | |
972 | ,&vRect | |
973 | ); | |
974 | if(hPS) | |
975 | { | |
976 | ::GpiCreateLogColorTable( hPS | |
977 | ,0L | |
978 | ,LCOLF_CONSECRGB | |
979 | ,0L | |
980 | ,(LONG)wxTheColourDatabase->m_nSize | |
981 | ,(PLONG)wxTheColourDatabase->m_palTable | |
982 | ); | |
983 | ::GpiCreateLogColorTable( hPS | |
984 | ,0L | |
985 | ,LCOLF_RGB | |
986 | ,0L | |
987 | ,0L | |
988 | ,NULL | |
989 | ); | |
990 | ||
991 | ::WinFillRect( hPS | |
992 | ,&vRect | |
993 | ,GetBackgroundColour().GetPixel() | |
994 | ); | |
995 | ::WinEndPaint(hPS); | |
996 | } | |
997 | } | |
998 | return TRUE; | |
29435d81 DW |
999 | } |
1000 | } | |
1001 | else | |
1002 | { | |
1003 | // nothing to paint - processed | |
1004 | return TRUE; | |
1005 | } | |
29435d81 | 1006 | return FALSE; |
0d53fc34 | 1007 | } // end of wxFrame::HandlePaint |
21802234 | 1008 | |
0d53fc34 | 1009 | bool wxFrame::HandleSize( |
a885d89a DW |
1010 | int nX |
1011 | , int nY | |
1012 | , WXUINT nId | |
1013 | ) | |
21802234 | 1014 | { |
a885d89a | 1015 | bool bProcessed = FALSE; |
21802234 | 1016 | |
a885d89a | 1017 | switch (nId) |
21802234 | 1018 | { |
a885d89a DW |
1019 | case kSizeNormal: |
1020 | // | |
1021 | // Only do it it if we were iconized before, otherwise resizing the | |
21802234 DW |
1022 | // parent frame has a curious side effect of bringing it under it's |
1023 | // children | |
a885d89a | 1024 | if (!m_bIconized ) |
21802234 DW |
1025 | break; |
1026 | ||
a885d89a | 1027 | // |
21802234 | 1028 | // restore all child frames too |
a885d89a | 1029 | // |
21802234 | 1030 | IconizeChildFrames(FALSE); |
3febf684 | 1031 | (void)SendIconizeEvent(FALSE); |
21802234 | 1032 | |
a885d89a | 1033 | // |
21802234 | 1034 | // fall through |
a885d89a | 1035 | // |
21802234 | 1036 | |
a885d89a DW |
1037 | case kSizeMax: |
1038 | m_bIconized = FALSE; | |
21802234 DW |
1039 | break; |
1040 | ||
a885d89a DW |
1041 | case kSizeMin: |
1042 | // | |
1043 | // Iconize all child frames too | |
1044 | // | |
21802234 | 1045 | IconizeChildFrames(TRUE); |
3febf684 | 1046 | (void)SendIconizeEvent(); |
a885d89a | 1047 | m_bIconized = TRUE; |
21802234 DW |
1048 | break; |
1049 | } | |
f38374d0 | 1050 | |
a885d89a | 1051 | if (!m_bIconized) |
21802234 | 1052 | { |
a885d89a | 1053 | // |
29435d81 | 1054 | // forward WM_SIZE to status bar control |
a885d89a | 1055 | // |
f38374d0 DW |
1056 | #if wxUSE_NATIVE_STATUSBAR |
1057 | if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95))) | |
1058 | { | |
a885d89a DW |
1059 | wxSizeEvent vEvent( wxSize( nX |
1060 | ,nY | |
1061 | ) | |
1062 | ,m_frameStatusBar->GetId() | |
1063 | ); | |
f38374d0 | 1064 | |
a885d89a DW |
1065 | vEvent.SetEventObject(m_frameStatusBar); |
1066 | m_frameStatusBar->OnSize(vEvent); | |
f38374d0 DW |
1067 | } |
1068 | #endif // wxUSE_NATIVE_STATUSBAR | |
1069 | ||
51c1d535 | 1070 | PositionStatusBar(); |
7e99520b | 1071 | #if wxUSE_TOOLBAR |
21802234 | 1072 | PositionToolBar(); |
7e99520b DW |
1073 | #endif // wxUSE_TOOLBAR |
1074 | ||
598d8cac DW |
1075 | bProcessed = wxWindow::HandleSize( nX |
1076 | ,nY | |
1077 | ,nId | |
1078 | ); | |
21802234 | 1079 | } |
a885d89a | 1080 | return bProcessed; |
0d53fc34 | 1081 | } // end of wxFrame::HandleSize |
21802234 | 1082 | |
0d53fc34 | 1083 | bool wxFrame::HandleCommand( |
a885d89a DW |
1084 | WXWORD nId |
1085 | , WXWORD nCmd | |
1086 | , WXHWND hControl | |
1087 | ) | |
21802234 | 1088 | { |
a885d89a | 1089 | if (hControl) |
21802234 | 1090 | { |
a885d89a | 1091 | // |
21802234 | 1092 | // In case it's e.g. a toolbar. |
a885d89a DW |
1093 | // |
1094 | wxWindow* pWin = wxFindWinFromHandle(hControl); | |
1095 | ||
1096 | if (pWin) | |
1097 | return pWin->OS2Command( nCmd | |
1098 | ,nId | |
1099 | ); | |
21802234 DW |
1100 | } |
1101 | ||
a885d89a DW |
1102 | // |
1103 | // Handle here commands from menus and accelerators | |
1104 | // | |
5b3ed311 | 1105 | if (nCmd == CMDSRC_MENU || nCmd == CMDSRC_ACCELERATOR) |
21802234 | 1106 | { |
19193a2c | 1107 | #if wxUSE_MENUS_NATIVE |
a885d89a | 1108 | if (wxCurrentPopupMenu) |
21802234 | 1109 | { |
a885d89a DW |
1110 | wxMenu* pPopupMenu = wxCurrentPopupMenu; |
1111 | ||
21802234 DW |
1112 | wxCurrentPopupMenu = NULL; |
1113 | ||
a885d89a DW |
1114 | return pPopupMenu->OS2Command( nCmd |
1115 | ,nId | |
1116 | ); | |
19193a2c | 1117 | return TRUE; |
21802234 | 1118 | } |
19193a2c | 1119 | #endif |
21802234 | 1120 | |
a885d89a | 1121 | if (ProcessCommand(nId)) |
21802234 DW |
1122 | { |
1123 | return TRUE; | |
1124 | } | |
1125 | } | |
21802234 | 1126 | return FALSE; |
0d53fc34 | 1127 | } // end of wxFrame::HandleCommand |
21802234 | 1128 | |
0d53fc34 | 1129 | bool wxFrame::HandleMenuSelect( |
a885d89a DW |
1130 | WXWORD nItem |
1131 | , WXWORD nFlags | |
1132 | , WXHMENU hMenu | |
1133 | ) | |
21802234 | 1134 | { |
e604d44b DW |
1135 | if( !nFlags ) |
1136 | { | |
1137 | MENUITEM mItem; | |
1138 | MRESULT rc; | |
1139 | ||
51c1d535 | 1140 | rc = ::WinSendMsg(hMenu, MM_QUERYITEM, MPFROM2SHORT(nItem, TRUE), (MPARAM)&mItem); |
e604d44b DW |
1141 | |
1142 | if(rc && !(mItem.afStyle & (MIS_SUBMENU | MIS_SEPARATOR))) | |
1143 | { | |
1144 | wxMenuEvent vEvent(wxEVT_MENU_HIGHLIGHT, nItem); | |
1145 | ||
1146 | vEvent.SetEventObject(this); | |
1147 | GetEventHandler()->ProcessEvent(vEvent); // return value would be ignored by PM | |
1148 | } | |
1149 | } | |
1150 | return TRUE; | |
0d53fc34 | 1151 | } // end of wxFrame::HandleMenuSelect |
21802234 DW |
1152 | |
1153 | // --------------------------------------------------------------------------- | |
51c1d535 | 1154 | // Main Frame window proc |
21802234 | 1155 | // --------------------------------------------------------------------------- |
51c1d535 DW |
1156 | MRESULT EXPENTRY wxFrameMainWndProc( |
1157 | HWND hWnd | |
1158 | , ULONG ulMsg | |
1159 | , MPARAM wParam | |
1160 | , MPARAM lParam | |
1161 | ) | |
1162 | { | |
1163 | MRESULT rc = (MRESULT)0; | |
1164 | bool bProcessed = FALSE; | |
1165 | wxFrame* pWnd = NULL; | |
1166 | ||
1167 | pWnd = (wxFrame*) wxFindWinFromHandle((WXHWND) hWnd); | |
1168 | switch (ulMsg) | |
1169 | { | |
1170 | case WM_QUERYFRAMECTLCOUNT: | |
1171 | if(pWnd && pWnd->m_fnOldWndProc) | |
1172 | { | |
1173 | USHORT uItemCount = SHORT1FROMMR(pWnd->m_fnOldWndProc(hWnd, ulMsg, wParam, lParam)); | |
1174 | ||
1175 | rc = MRFROMSHORT(uItemCount); | |
1176 | } | |
1177 | break; | |
1178 | ||
1179 | case WM_FORMATFRAME: | |
1180 | ///////////////////////////////////////////////////////////////////////////////// | |
1181 | // Applications that subclass frame controls may find that the frame is already | |
1182 | // subclassed the number of frame controls is variable. | |
1183 | // The WM_FORMATFRAME and WM_QUERYFRAMECTLCOUNT messages must always be | |
1184 | // subclassed by calling the previous window procedure and modifying its result. | |
1185 | //////////////////////////////////////////////////////////////////////////////// | |
1186 | { | |
1187 | int nItemCount; | |
1188 | int i; | |
1189 | PSWP pSWP = NULL; | |
1190 | SWP vSwpStb; | |
1191 | RECTL vRectl; | |
1192 | RECTL vRstb; | |
1193 | int nHeight=0; | |
1194 | ||
1195 | pSWP = (PSWP)PVOIDFROMMP(wParam); | |
1196 | nItemCount = SHORT1FROMMR(pWnd->m_fnOldWndProc(hWnd, ulMsg, wParam, lParam)); | |
1197 | if(pWnd->m_frameStatusBar) | |
1198 | { | |
1199 | ::WinQueryWindowRect(pWnd->m_frameStatusBar->GetHWND(), &vRstb); | |
1200 | pWnd->m_frameStatusBar->GetSize(NULL, &nHeight); | |
1201 | ::WinQueryWindowRect(pWnd->m_hFrame, &vRectl); | |
1202 | ::WinMapWindowPoints(pWnd->m_hFrame, HWND_DESKTOP, (PPOINTL)&vRectl, 2); | |
1203 | vRstb = vRectl; | |
1204 | ::WinCalcFrameRect(pWnd->m_hFrame, &vRectl, TRUE); | |
1205 | ||
1206 | vSwpStb.x = vRectl.xLeft - vRstb.xLeft; | |
1207 | vSwpStb.y = vRectl.yBottom - vRstb.yBottom; | |
1208 | vSwpStb.cx = vRectl.xRight - vRectl.xLeft - 1; //?? -1 ?? | |
1209 | vSwpStb.cy = nHeight; | |
1210 | vSwpStb.fl = SWP_SIZE |SWP_MOVE | SWP_SHOW; | |
1211 | vSwpStb.hwnd = pWnd->m_frameStatusBar->GetHWND(); | |
1212 | vSwpStb.hwndInsertBehind = HWND_TOP; | |
1213 | } | |
1214 | ::WinQueryWindowRect(pWnd->m_hFrame, &vRectl); | |
1215 | ::WinMapWindowPoints(pWnd->m_hFrame, HWND_DESKTOP, (PPOINTL)&vRectl, 2); | |
1216 | ::WinCalcFrameRect(pWnd->m_hFrame, &vRectl, TRUE); | |
1217 | ::WinMapWindowPoints(HWND_DESKTOP, pWnd->m_hFrame, (PPOINTL)&vRectl, 2); | |
1218 | for(i = 0; i < nItemCount; i++) | |
1219 | { | |
1220 | if(pWnd->m_hWnd && pSWP[i].hwnd == pWnd->m_hWnd) | |
1221 | { | |
1222 | pSWP[i].x = vRectl.xLeft; | |
1223 | pSWP[i].y = vRectl.yBottom + nHeight; | |
1224 | pSWP[i].cx = vRectl.xRight - vRectl.xLeft; | |
1225 | pSWP[i].cy = vRectl.yTop - vRectl.yBottom - nHeight; | |
1226 | pSWP[i].fl = SWP_SIZE | SWP_MOVE | SWP_SHOW; | |
1227 | pSWP[i].hwndInsertBehind = HWND_TOP; | |
1228 | } | |
1229 | } | |
1230 | bProcessed = TRUE; | |
1231 | rc = MRFROMSHORT(nItemCount); | |
1232 | } | |
1233 | break; | |
1234 | ||
1235 | default: | |
1236 | if(pWnd && pWnd->m_fnOldWndProc) | |
1237 | rc = pWnd->m_fnOldWndProc(hWnd, ulMsg, wParam, lParam); | |
1238 | else | |
1239 | rc = ::WinDefWindowProc(hWnd, ulMsg, wParam, lParam); | |
1240 | } | |
1241 | return rc; | |
1242 | } // end of wxFrameMainWndProc | |
1243 | ||
1244 | MRESULT EXPENTRY wxFrameWndProc( | |
1245 | HWND hWnd | |
1246 | , ULONG ulMsg | |
1247 | , MPARAM wParam | |
1248 | , MPARAM lParam | |
1249 | ) | |
1250 | { | |
1251 | // | |
1252 | // Trace all ulMsgs - useful for the debugging | |
1253 | // | |
1254 | HWND parentHwnd; | |
1255 | wxFrame* pWnd = NULL; | |
1256 | ||
1257 | parentHwnd = WinQueryWindow(hWnd,QW_PARENT); | |
1258 | pWnd = (wxFrame*) wxFindWinFromHandle((WXHWND) hWnd); | |
1259 | ||
1260 | // | |
1261 | // When we get the first message for the HWND we just created, we associate | |
1262 | // it with wxWindow stored in wxWndHook | |
1263 | // | |
51c1d535 DW |
1264 | |
1265 | MRESULT rc = (MRESULT)0; | |
1266 | bool bProcessed = FALSE; | |
1267 | ||
1268 | // | |
1269 | // Stop right here if we don't have a valid handle in our wxWindow object. | |
1270 | // | |
1271 | if (pWnd && !pWnd->GetHWND()) | |
1272 | { | |
1273 | pWnd->SetHWND((WXHWND) hWnd); | |
1274 | rc = pWnd->OS2DefWindowProc(ulMsg, wParam, lParam ); | |
1275 | pWnd->SetHWND(0); | |
1276 | } | |
1277 | else | |
1278 | { | |
d08f23a7 DW |
1279 | if (pWnd) |
1280 | rc = pWnd->OS2WindowProc(ulMsg, wParam, lParam); | |
1281 | else | |
1282 | rc = ::WinDefWindowProc(hWnd, ulMsg, wParam, lParam); | |
51c1d535 DW |
1283 | } |
1284 | return rc; | |
1285 | } // end of wxFrameWndProc | |
21802234 | 1286 | |
0d53fc34 | 1287 | MRESULT wxFrame::OS2WindowProc( |
a885d89a DW |
1288 | WXUINT uMessage |
1289 | , WXWPARAM wParam | |
1290 | , WXLPARAM lParam | |
1291 | ) | |
21802234 | 1292 | { |
a885d89a DW |
1293 | MRESULT mRc = 0L; |
1294 | bool bProcessed = FALSE; | |
21802234 | 1295 | |
a885d89a | 1296 | switch (uMessage) |
21802234 DW |
1297 | { |
1298 | case WM_CLOSE: | |
a885d89a DW |
1299 | // |
1300 | // If we can't close, tell the system that we processed the | |
21802234 | 1301 | // message - otherwise it would close us |
a885d89a DW |
1302 | // |
1303 | bProcessed = !Close(); | |
21802234 DW |
1304 | break; |
1305 | ||
d08f23a7 | 1306 | case WM_PAINT: |
8d854fa9 DW |
1307 | bProcessed = HandlePaint(); |
1308 | mRc = (MRESULT)FALSE; | |
1309 | break; | |
d08f23a7 | 1310 | |
8d854fa9 DW |
1311 | case WM_ERASEBACKGROUND: |
1312 | // | |
1313 | // Returning TRUE to requests PM to paint the window background | |
1314 | // in SYSCLR_WINDOW. We capture this here because the PS returned | |
1315 | // in Frames is the PS for the whole frame, which we can't really | |
1316 | // use at all. If you want to paint a different background, do it | |
1317 | // in an OnPaint using a wxPaintDC. | |
1318 | // | |
1319 | mRc = (MRESULT)(TRUE); | |
d08f23a7 DW |
1320 | break; |
1321 | ||
8d854fa9 | 1322 | case WM_COMMAND: |
21802234 | 1323 | { |
a885d89a DW |
1324 | WORD wId; |
1325 | WORD wCmd; | |
1326 | WXHWND hWnd; | |
1327 | ||
1328 | UnpackCommand( (WXWPARAM)wParam | |
d08f23a7 DW |
1329 | ,(WXLPARAM)lParam |
1330 | ,&wId | |
1331 | ,&hWnd | |
1332 | ,&wCmd | |
1333 | ); | |
5b3ed311 | 1334 | |
a885d89a DW |
1335 | bProcessed = HandleCommand( wId |
1336 | ,wCmd | |
1337 | ,(WXHWND)hWnd | |
1338 | ); | |
21802234 DW |
1339 | } |
1340 | break; | |
1341 | ||
1342 | case WM_MENUSELECT: | |
1343 | { | |
a885d89a DW |
1344 | WXWORD wItem; |
1345 | WXWORD wFlags; | |
1346 | WXHMENU hMenu; | |
1347 | ||
1348 | UnpackMenuSelect( wParam | |
1349 | ,lParam | |
1350 | ,&wItem | |
1351 | ,&wFlags | |
1352 | ,&hMenu | |
1353 | ); | |
1354 | bProcessed = HandleMenuSelect( wItem | |
1355 | ,wFlags | |
1356 | ,hMenu | |
1357 | ); | |
e604d44b | 1358 | mRc = (MRESULT)TRUE; |
21802234 DW |
1359 | } |
1360 | break; | |
1361 | ||
d08f23a7 DW |
1362 | case WM_SIZE: |
1363 | { | |
1364 | SHORT nScxold = SHORT1FROMMP(wParam); // Old horizontal size. | |
1365 | SHORT nScyold = SHORT2FROMMP(wParam); // Old vertical size. | |
1366 | SHORT nScxnew = SHORT1FROMMP(lParam); // New horizontal size. | |
1367 | SHORT nScynew = SHORT2FROMMP(lParam); // New vertical size. | |
1368 | ||
1369 | lParam = MRFROM2SHORT( nScxnew - 20 | |
1370 | ,nScynew - 30 | |
1371 | ); | |
1372 | } | |
1373 | bProcessed = HandleSize(LOWORD(lParam), HIWORD(lParam), (WXUINT)wParam); | |
1374 | mRc = (MRESULT)FALSE; | |
21802234 DW |
1375 | break; |
1376 | ||
a885d89a | 1377 | case CM_QUERYDRAGIMAGE: |
21802234 | 1378 | { |
3437f881 | 1379 | const wxIcon& vIcon = GetIcon(); |
a885d89a DW |
1380 | HPOINTER hIcon; |
1381 | ||
3437f881 | 1382 | if (vIcon.Ok()) |
e604d44b | 1383 | hIcon = (HPOINTER)::WinSendMsg(GetHWND(), WM_QUERYICON, 0L, 0L); |
a885d89a DW |
1384 | else |
1385 | hIcon = (HPOINTER)m_hDefaultIcon; | |
1386 | mRc = (MRESULT)hIcon; | |
1387 | bProcessed = mRc != 0; | |
21802234 DW |
1388 | } |
1389 | break; | |
21802234 | 1390 | } |
f38374d0 | 1391 | |
a885d89a DW |
1392 | if (!bProcessed ) |
1393 | mRc = wxWindow::OS2WindowProc( uMessage | |
1394 | ,wParam | |
1395 | ,lParam | |
1396 | ); | |
e604d44b | 1397 | return (MRESULT)mRc; |
0d53fc34 | 1398 | } // wxFrame::OS2WindowProc |
21802234 | 1399 | |
0d53fc34 | 1400 | void wxFrame::SetClient(WXHWND c_Hwnd) |
5b3ed311 | 1401 | { |
51c1d535 | 1402 | // Duh...nothing to do under OS/2 |
5b3ed311 DW |
1403 | } |
1404 | ||
0d53fc34 | 1405 | void wxFrame::SetClient( |
51c1d535 DW |
1406 | wxWindow* pWindow |
1407 | ) | |
5b3ed311 | 1408 | { |
51c1d535 DW |
1409 | wxWindow* pOldClient = this->GetClient(); |
1410 | bool bClientHasFocus = pOldClient && (pOldClient == wxWindow::FindFocus()); | |
5b3ed311 | 1411 | |
51c1d535 | 1412 | if(pOldClient == pWindow) // nothing to do |
5b3ed311 | 1413 | return; |
51c1d535 DW |
1414 | if(pWindow == NULL) // just need to remove old client |
1415 | { | |
1416 | if(pOldClient == NULL) // nothing to do | |
1417 | return; | |
5b3ed311 | 1418 | |
51c1d535 | 1419 | if(bClientHasFocus ) |
5b3ed311 DW |
1420 | this->SetFocus(); |
1421 | ||
51c1d535 DW |
1422 | pOldClient->Enable( FALSE ); |
1423 | pOldClient->Show( FALSE ); | |
1424 | ::WinSetWindowUShort(pOldClient->GetHWND(), QWS_ID, (USHORT)pOldClient->GetId()); | |
5b3ed311 | 1425 | // to avoid OS/2 bug need to update frame |
b7084589 | 1426 | ::WinSendMsg((HWND)this->GetFrame(), WM_UPDATEFRAME, (MPARAM)~0, 0); |
5b3ed311 | 1427 | return; |
51c1d535 | 1428 | } |
5b3ed311 | 1429 | |
51c1d535 DW |
1430 | // |
1431 | // Else need to change client | |
1432 | // | |
1433 | if(bClientHasFocus) | |
5b3ed311 DW |
1434 | this->SetFocus(); |
1435 | ||
51c1d535 DW |
1436 | ::WinEnableWindowUpdate((HWND)GetHWND(), FALSE); |
1437 | if(pOldClient) | |
1438 | { | |
1439 | pOldClient->Enable(FALSE); | |
1440 | pOldClient->Show(FALSE); | |
1441 | ::WinSetWindowUShort(pOldClient->GetHWND(), QWS_ID, (USHORT)pOldClient->GetId()); | |
1442 | } | |
1443 | pWindow->Reparent(this); | |
1444 | ::WinSetWindowUShort(pWindow->GetHWND(), QWS_ID, FID_CLIENT); | |
1445 | ::WinEnableWindowUpdate((HWND)GetHWND(), TRUE); | |
1446 | pWindow->Enable(); | |
1447 | pWindow->Show(); // ensure client is showing | |
1448 | if( this->IsShown() ) | |
1449 | { | |
1450 | this->Show(); | |
b7084589 | 1451 | ::WinSendMsg(m_hFrame, WM_UPDATEFRAME, (MPARAM)~0, 0); |
51c1d535 | 1452 | } |
5b3ed311 DW |
1453 | } |
1454 | ||
0d53fc34 | 1455 | wxWindow* wxFrame::GetClient() |
5b3ed311 | 1456 | { |
b7084589 | 1457 | return wxFindWinFromHandle((WXHWND)::WinWindowFromID(m_hFrame, FID_CLIENT)); |
5b3ed311 | 1458 | } |