]>
Commit | Line | Data |
---|---|---|
0e320a79 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: frame.cpp | |
0367c1c0 | 3 | // Purpose: wxFrameOS2 |
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" | |
33 | #endif // WX_PRECOMP | |
34 | ||
35 | #include "wx/os2/private.h" | |
f38374d0 DW |
36 | |
37 | #if wxUSE_STATUSBAR | |
38 | #include "wx/statusbr.h" | |
ea51d98d | 39 | #include "wx/generic/statusbr.h" |
f38374d0 DW |
40 | #endif // wxUSE_STATUSBAR |
41 | ||
42 | #if wxUSE_TOOLBAR | |
43 | #include "wx/toolbar.h" | |
44 | #endif // wxUSE_TOOLBAR | |
45 | ||
0e320a79 | 46 | #include "wx/menuitem.h" |
21802234 | 47 | #include "wx/log.h" |
0e320a79 | 48 | |
f38374d0 DW |
49 | // ---------------------------------------------------------------------------- |
50 | // globals | |
51 | // ---------------------------------------------------------------------------- | |
52 | ||
21802234 DW |
53 | extern wxWindowList wxModelessWindows; |
54 | extern wxList WXDLLEXPORT wxPendingDelete; | |
55 | extern wxChar wxFrameClassName[]; | |
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 | ||
0367c1c0 DW |
69 | BEGIN_EVENT_TABLE(wxFrameOS2, wxFrameBase) |
70 | EVT_ACTIVATE(wxFrameOS2::OnActivate) | |
71 | EVT_SYS_COLOUR_CHANGED(wxFrameOS2::OnSysColourChanged) | |
0e320a79 DW |
72 | END_EVENT_TABLE() |
73 | ||
0367c1c0 | 74 | #ifndef __WXUNIVERSAL__ |
8d7ddd02 | 75 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow) |
0367c1c0 | 76 | #endif |
0e320a79 | 77 | |
f38374d0 DW |
78 | // ============================================================================ |
79 | // implementation | |
80 | // ============================================================================ | |
0e320a79 | 81 | |
f38374d0 DW |
82 | // ---------------------------------------------------------------------------- |
83 | // static class members | |
84 | // ---------------------------------------------------------------------------- | |
7e99520b | 85 | #if wxUSE_STATUSBAR |
0e320a79 | 86 | |
f38374d0 | 87 | #if wxUSE_NATIVE_STATUSBAR |
0367c1c0 | 88 | bool wxFrameOS2::m_bUseNativeStatusBar = TRUE; |
f38374d0 | 89 | #else |
0367c1c0 | 90 | bool wxFrameOS2::m_bUseNativeStatusBar = FALSE; |
f38374d0 | 91 | #endif |
0e320a79 | 92 | |
7e99520b DW |
93 | #endif //wxUSE_STATUSBAR |
94 | ||
f38374d0 DW |
95 | // ---------------------------------------------------------------------------- |
96 | // creation/destruction | |
97 | // ---------------------------------------------------------------------------- | |
98 | ||
0367c1c0 | 99 | void wxFrameOS2::Init() |
0e320a79 | 100 | { |
80d83cbc | 101 | m_bIconized = FALSE; |
f38374d0 | 102 | |
21802234 | 103 | #if wxUSE_TOOLTIPS |
a885d89a | 104 | m_hWndToolTip = 0; |
21802234 | 105 | #endif |
ea51d98d DW |
106 | // Data to save/restore when calling ShowFullScreen |
107 | m_lFsStyle = 0L; | |
108 | m_lFsOldWindowStyle = 0L; | |
109 | m_nFsStatusBarFields = 0; | |
110 | m_nFsStatusBarHeight = 0; | |
111 | m_nFsToolBarHeight = 0; | |
112 | m_bFsIsMaximized = FALSE; | |
113 | m_bFsIsShowing = FALSE; | |
64e0c5c6 DW |
114 | m_bIsShown = FALSE; |
115 | m_pWinLastFocused = (wxWindow *)NULL; | |
40bd6154 | 116 | |
51c1d535 DW |
117 | m_hFrame = NULL; |
118 | m_hTitleBar = NULL; | |
119 | m_hHScroll = NULL; | |
120 | m_hVScroll = NULL; | |
121 | ||
40bd6154 DW |
122 | // |
123 | // Initialize SWP's | |
124 | // | |
125 | memset(&m_vSwp, 0, sizeof(SWP)); | |
126 | memset(&m_vSwpClient, 0, sizeof(SWP)); | |
127 | memset(&m_vSwpTitleBar, 0, sizeof(SWP)); | |
128 | memset(&m_vSwpMenuBar, 0, sizeof(SWP)); | |
129 | memset(&m_vSwpHScroll, 0, sizeof(SWP)); | |
130 | memset(&m_vSwpVScroll, 0, sizeof(SWP)); | |
131 | memset(&m_vSwpStatusBar, 0, sizeof(SWP)); | |
132 | memset(&m_vSwpToolBar, 0, sizeof(SWP)); | |
0367c1c0 | 133 | } // end of wxFrameOS2::Init |
ea51d98d | 134 | |
0367c1c0 | 135 | bool wxFrameOS2::Create( |
ea51d98d DW |
136 | wxWindow* pParent |
137 | , wxWindowID vId | |
138 | , const wxString& rsTitle | |
139 | , const wxPoint& rPos | |
140 | , const wxSize& rSize | |
a885d89a | 141 | , long lulStyle |
ea51d98d DW |
142 | , const wxString& rsName |
143 | ) | |
f38374d0 | 144 | { |
ea51d98d DW |
145 | int nX = rPos.x; |
146 | int nY = rPos.y; | |
147 | int nWidth = rSize.x; | |
148 | int nHeight = rSize.y; | |
51c1d535 | 149 | bool bOk = FALSE; |
ea51d98d DW |
150 | |
151 | SetName(rsName); | |
a885d89a | 152 | m_windowStyle = lulStyle; |
ea51d98d | 153 | m_frameMenuBar = NULL; |
7e99520b | 154 | #if wxUSE_TOOLBAR |
ea51d98d | 155 | m_frameToolBar = NULL; |
7e99520b DW |
156 | #endif //wxUSE_TOOLBAR |
157 | ||
158 | #if wxUSE_STATUSBAR | |
ea51d98d | 159 | m_frameStatusBar = NULL; |
7e99520b | 160 | #endif //wxUSE_STATUSBAR |
ea51d98d DW |
161 | |
162 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); | |
163 | ||
164 | if (vId > -1 ) | |
165 | m_windowId = vId; | |
166 | else | |
167 | m_windowId = (int)NewControlId(); | |
168 | ||
80d83cbc | 169 | if (pParent) |
ea51d98d DW |
170 | pParent->AddChild(this); |
171 | ||
172 | m_bIconized = FALSE; | |
173 | ||
ea51d98d DW |
174 | if ((m_windowStyle & wxFRAME_FLOAT_ON_PARENT) == 0) |
175 | pParent = NULL; | |
176 | ||
51c1d535 DW |
177 | bOk = OS2Create( m_windowId |
178 | ,pParent | |
179 | ,wxFrameClassName | |
180 | ,this | |
181 | ,rsTitle | |
182 | ,nX | |
183 | ,nY | |
184 | ,nWidth | |
185 | ,nHeight | |
186 | ,lulStyle | |
187 | ); | |
188 | if (bOk) | |
189 | { | |
190 | if (!pParent) | |
191 | wxTopLevelWindows.Append(this); | |
192 | wxModelessWindows.Append(this); | |
193 | } | |
194 | return(bOk); | |
0367c1c0 | 195 | } // end of wxFrameOS2::Create |
0e320a79 | 196 | |
0367c1c0 | 197 | wxFrameOS2::~wxFrameOS2() |
0e320a79 | 198 | { |
ea51d98d | 199 | m_isBeingDeleted = TRUE; |
e604d44b | 200 | |
ea51d98d | 201 | wxTopLevelWindows.DeleteObject(this); |
0e320a79 | 202 | |
ea51d98d | 203 | DeleteAllBars(); |
29435d81 | 204 | |
ea51d98d DW |
205 | if (wxTheApp && (wxTopLevelWindows.Number() == 0)) |
206 | { | |
207 | wxTheApp->SetTopWindow(NULL); | |
0e320a79 | 208 | |
ea51d98d DW |
209 | if (wxTheApp->GetExitOnFrameDelete()) |
210 | { | |
4d098649 | 211 | ::WinPostMsg(NULL, WM_QUIT, 0, 0); |
ea51d98d DW |
212 | } |
213 | } | |
5b3ed311 | 214 | |
ea51d98d DW |
215 | wxModelessWindows.DeleteObject(this); |
216 | ||
217 | // | |
218 | // For some reason, wxWindows can activate another task altogether | |
219 | // when a frame is destroyed after a modal dialog has been invoked. | |
220 | // Try to bring the parent to the top. | |
221 | // | |
222 | // MT:Only do this if this frame is currently the active window, else weird | |
223 | // things start to happen. | |
224 | // | |
225 | if (wxGetActiveWindow() == this) | |
0e320a79 | 226 | { |
ea51d98d DW |
227 | if (GetParent() && GetParent()->GetHWND()) |
228 | { | |
ea51d98d DW |
229 | ::WinSetWindowPos( (HWND) GetParent()->GetHWND() |
230 | ,HWND_TOP | |
80d83cbc DW |
231 | ,0 |
232 | ,0 | |
233 | ,0 | |
234 | ,0 | |
235 | ,SWP_ZORDER | |
ea51d98d DW |
236 | ); |
237 | } | |
0e320a79 | 238 | } |
0367c1c0 | 239 | } // end of wxFrameOS2::~wxFrame |
0e320a79 | 240 | |
ea51d98d | 241 | // |
0e320a79 | 242 | // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc. |
ea51d98d | 243 | // |
0367c1c0 | 244 | void wxFrameOS2::DoGetClientSize( |
80d83cbc DW |
245 | int* pX |
246 | , int* pY | |
247 | ) const | |
0e320a79 | 248 | { |
80d83cbc | 249 | RECTL vRect; |
40bd6154 | 250 | ::WinQueryWindowRect(GetHwnd(), &vRect); |
51523f25 | 251 | |
5fb9d2be DW |
252 | // |
253 | // No need to use statusbar code as in WIN32 as the FORMATFRAME | |
254 | // window procedure ensures PM knows about the new frame client | |
255 | // size internally. A ::WinQueryWindowRect is all that is needed! | |
256 | // | |
257 | ||
80d83cbc | 258 | if (pX) |
51c1d535 | 259 | *pX = vRect.xRight - vRect.xLeft; |
80d83cbc | 260 | if (pY) |
51c1d535 | 261 | *pY = vRect.yTop - vRect.yBottom; |
0367c1c0 | 262 | } // end of wxFrameOS2::DoGetClientSize |
0e320a79 | 263 | |
a885d89a | 264 | // |
0e320a79 DW |
265 | // Set the client size (i.e. leave the calculation of borders etc. |
266 | // to wxWindows) | |
80d83cbc | 267 | // |
0367c1c0 | 268 | void wxFrameOS2::DoSetClientSize( |
80d83cbc DW |
269 | int nWidth |
270 | , int nHeight | |
271 | ) | |
0e320a79 | 272 | { |
80d83cbc | 273 | HWND hWnd = GetHwnd(); |
80d83cbc | 274 | RECTL vRect; |
a7ef993c | 275 | RECTL vRect2; |
0e320a79 | 276 | |
40bd6154 | 277 | ::WinQueryWindowRect(GetHwnd(), &vRect); |
51c1d535 | 278 | ::WinQueryWindowRect(GetHwnd(), &vRect2); |
21802234 | 279 | |
80d83cbc DW |
280 | // |
281 | // Find the difference between the entire window (title bar and all) | |
282 | // and the client area; add this to the new client size to move the | |
283 | // window. Remember OS/2's backwards y coord system! | |
284 | // | |
285 | int nActualWidth = vRect2.xRight - vRect2.xLeft - vRect.xRight + nWidth; | |
286 | int nActualHeight = vRect2.yTop + vRect2.yTop - vRect.yTop + nHeight; | |
29435d81 | 287 | |
f38374d0 | 288 | #if wxUSE_STATUSBAR |
80d83cbc DW |
289 | if ( GetStatusBar() ) |
290 | { | |
291 | int nStatusX; | |
292 | int nStatusY; | |
293 | ||
294 | GetStatusBar()->GetClientSize( &nStatusX | |
295 | ,&nStatusY | |
296 | ); | |
297 | nActualHeight += nStatusY; | |
298 | } | |
f38374d0 | 299 | #endif // wxUSE_STATUSBAR |
29435d81 | 300 | |
80d83cbc DW |
301 | wxPoint vPoint(GetClientAreaOrigin()); |
302 | nActualWidth += vPoint.y; | |
303 | nActualHeight += vPoint.x; | |
304 | ||
305 | POINTL vPointl; | |
306 | ||
307 | vPointl.x = vRect2.xLeft; | |
64e0c5c6 | 308 | vPointl.y = vRect2.yTop; |
80d83cbc | 309 | |
64e0c5c6 | 310 | ::WinSetWindowPos( hWnd |
80d83cbc DW |
311 | ,HWND_TOP |
312 | ,vPointl.x | |
313 | ,vPointl.y | |
314 | ,nActualWidth | |
315 | ,nActualHeight | |
316 | ,SWP_MOVE | SWP_SIZE | SWP_SHOW | |
317 | ); | |
318 | ||
319 | wxSizeEvent vEvent( wxSize( nWidth | |
320 | ,nHeight | |
321 | ) | |
322 | ,m_windowId | |
323 | ); | |
324 | vEvent.SetEventObject(this); | |
325 | GetEventHandler()->ProcessEvent(vEvent); | |
0367c1c0 | 326 | } // end of wxFrameOS2::DoSetClientSize |
80d83cbc | 327 | |
0367c1c0 | 328 | void wxFrameOS2::DoGetSize( |
80d83cbc DW |
329 | int* pWidth |
330 | , int* pHeight | |
331 | ) const | |
332 | { | |
333 | RECTL vRect; | |
21802234 | 334 | |
51c1d535 | 335 | ::WinQueryWindowRect(m_hFrame, &vRect); |
80d83cbc DW |
336 | *pWidth = vRect.xRight - vRect.xLeft; |
337 | *pHeight = vRect.yTop - vRect.yBottom; | |
0367c1c0 | 338 | } // end of wxFrameOS2::DoGetSize |
21802234 | 339 | |
0367c1c0 | 340 | void wxFrameOS2::DoGetPosition( |
80d83cbc DW |
341 | int* pX |
342 | , int* pY | |
343 | ) const | |
344 | { | |
345 | RECTL vRect; | |
a885d89a | 346 | POINTL vPoint; |
29435d81 | 347 | |
51c1d535 | 348 | ::WinQueryWindowRect(m_hFrame, &vRect); |
0e320a79 | 349 | |
3febf684 DW |
350 | *pX = vRect.xRight - vRect.xLeft; |
351 | *pY = vRect.yTop - vRect.yBottom; | |
0367c1c0 | 352 | } // end of wxFrameOS2::DoGetPosition |
0e320a79 | 353 | |
f38374d0 DW |
354 | // ---------------------------------------------------------------------------- |
355 | // variations around ::ShowWindow() | |
356 | // ---------------------------------------------------------------------------- | |
357 | ||
0367c1c0 | 358 | void wxFrameOS2::DoShowWindow( |
426d5745 | 359 | int bShowCmd |
80d83cbc | 360 | ) |
0e320a79 | 361 | { |
51c1d535 | 362 | ::WinShowWindow(m_hFrame, (BOOL)bShowCmd); |
64e0c5c6 | 363 | m_bIconized = bShowCmd == SWP_MINIMIZE; |
0367c1c0 | 364 | } // end of wxFrameOS2::DoShowWindow |
21802234 | 365 | |
0367c1c0 | 366 | bool wxFrameOS2::Show( |
80d83cbc DW |
367 | bool bShow |
368 | ) | |
0e320a79 | 369 | { |
426d5745 DW |
370 | SWP vSwp; |
371 | ||
372 | DoShowWindow((int)bShow); | |
21802234 | 373 | |
80d83cbc | 374 | if (bShow) |
f38374d0 | 375 | { |
80d83cbc DW |
376 | wxActivateEvent vEvent(wxEVT_ACTIVATE, TRUE, m_windowId); |
377 | ||
51c1d535 | 378 | ::WinQueryWindowPos(m_hFrame, &vSwp); |
d8530167 | 379 | m_bIconized = vSwp.fl & SWP_MINIMIZE; |
51c1d535 DW |
380 | ::WinSendMsg(m_hFrame, WM_UPDATEFRAME, (MPARAM)~0, 0); |
381 | ::WinEnableWindow(m_hFrame, TRUE); | |
80d83cbc DW |
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 | ); |
a0606634 | 405 | ::WinEnableWindow(hWndParent, TRUE); |
f38374d0 DW |
406 | } |
407 | } | |
f38374d0 | 408 | return TRUE; |
0367c1c0 | 409 | } // end of wxFrameOS2::Show |
f38374d0 | 410 | |
0367c1c0 | 411 | void wxFrameOS2::Iconize( |
80d83cbc DW |
412 | bool bIconize |
413 | ) | |
f38374d0 | 414 | { |
80d83cbc | 415 | DoShowWindow(bIconize ? SWP_MINIMIZE : SWP_RESTORE); |
0367c1c0 | 416 | } // end of wxFrameOS2::Iconize |
0e320a79 | 417 | |
0367c1c0 | 418 | void wxFrameOS2::Maximize( |
80d83cbc | 419 | bool bMaximize) |
0e320a79 | 420 | { |
80d83cbc | 421 | DoShowWindow(bMaximize ? SWP_MAXIMIZE : SWP_RESTORE); |
0367c1c0 | 422 | } // end of wxFrameOS2::Maximize |
f38374d0 | 423 | |
0367c1c0 | 424 | void wxFrameOS2::Restore() |
f38374d0 | 425 | { |
80d83cbc | 426 | DoShowWindow(SWP_RESTORE); |
0367c1c0 | 427 | } // end of wxFrameOS2::Restore |
0e320a79 | 428 | |
0367c1c0 | 429 | bool wxFrameOS2::IsIconized() const |
0e320a79 | 430 | { |
80d83cbc | 431 | SWP vSwp; |
80d83cbc | 432 | |
51c1d535 | 433 | ::WinQueryWindowPos(m_hFrame, &vSwp); |
a885d89a | 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; | |
0367c1c0 | 440 | } // end of wxFrameOS2::IsIconized |
0e320a79 | 441 | |
21802234 | 442 | // Is it maximized? |
0367c1c0 | 443 | bool wxFrameOS2::IsMaximized() const |
0e320a79 | 444 | { |
80d83cbc DW |
445 | SWP vSwp; |
446 | bool bIconic; | |
447 | ||
51c1d535 | 448 | ::WinQueryWindowPos(m_hFrame, &vSwp); |
80d83cbc | 449 | return (vSwp.fl & SWP_MAXIMIZE); |
0367c1c0 | 450 | } // end of wxFrameOS2::IsMaximized |
0e320a79 | 451 | |
0367c1c0 | 452 | void wxFrameOS2::SetIcon( |
0fe536e3 DW |
453 | const wxIcon& rIcon |
454 | ) | |
0e320a79 | 455 | { |
0fe536e3 | 456 | wxFrameBase::SetIcon(rIcon); |
f38374d0 | 457 | |
426d5745 | 458 | if ((m_icon.GetHICON()) != NULLHANDLE) |
f38374d0 | 459 | { |
51c1d535 | 460 | ::WinSendMsg( m_hFrame |
f23208ca | 461 | ,WM_SETICON |
426d5745 | 462 | ,(MPARAM)((HPOINTER)m_icon.GetHICON()) |
f23208ca DW |
463 | ,NULL |
464 | ); | |
51c1d535 | 465 | ::WinSendMsg( m_hFrame |
f23208ca DW |
466 | ,WM_UPDATEFRAME |
467 | ,(MPARAM)FCF_ICON | |
468 | ,(MPARAM)0 | |
469 | ); | |
f38374d0 | 470 | } |
0367c1c0 | 471 | } // end of wxFrameOS2::SetIcon |
0e320a79 | 472 | |
21802234 | 473 | #if wxUSE_STATUSBAR |
0367c1c0 | 474 | wxStatusBar* wxFrameOS2::OnCreateStatusBar( |
0fe536e3 | 475 | int nNumber |
a885d89a | 476 | , long lulStyle |
0fe536e3 DW |
477 | , wxWindowID vId |
478 | , const wxString& rName | |
479 | ) | |
0e320a79 | 480 | { |
0fe536e3 | 481 | wxStatusBar* pStatusBar = NULL; |
f6bcfd97 BP |
482 | SWP vSwp; |
483 | ERRORID vError; | |
484 | wxString sError; | |
0e320a79 | 485 | |
0fe536e3 | 486 | pStatusBar = wxFrameBase::OnCreateStatusBar( nNumber |
a885d89a | 487 | ,lulStyle |
0fe536e3 DW |
488 | ,vId |
489 | ,rName | |
5b3ed311 DW |
490 | ); |
491 | ||
492 | if( !pStatusBar ) | |
f6bcfd97 | 493 | return NULL; |
f6bcfd97 | 494 | |
51c1d535 DW |
495 | ::WinSetParent( pStatusBar->GetHWND() |
496 | ,m_hFrame | |
497 | ,FALSE | |
498 | ); | |
499 | ::WinSetOwner( pStatusBar->GetHWND() | |
500 | ,m_hFrame | |
501 | ); | |
7e99520b | 502 | // |
5b3ed311 | 503 | // to show statusbar |
f6bcfd97 | 504 | // |
51c1d535 DW |
505 | if(::WinIsWindowShowing(m_hFrame)) |
506 | ::WinSendMsg(m_hFrame, WM_UPDATEFRAME, (MPARAM)~0, 0); | |
7e99520b | 507 | |
0fe536e3 | 508 | return pStatusBar; |
0367c1c0 | 509 | } // end of wxFrameOS2::OnCreateStatusBar |
0e320a79 | 510 | |
0367c1c0 | 511 | void wxFrameOS2::PositionStatusBar() |
0e320a79 | 512 | { |
f6bcfd97 BP |
513 | SWP vSwp; |
514 | ERRORID vError; | |
515 | wxString sError; | |
516 | ||
0fe536e3 DW |
517 | // |
518 | // Native status bar positions itself | |
519 | // | |
520 | if (m_frameStatusBar) | |
f38374d0 | 521 | { |
a885d89a | 522 | int nWidth; |
a885d89a | 523 | int nStatbarWidth; |
0fe536e3 DW |
524 | int nStatbarHeight; |
525 | HWND hWndClient; | |
526 | RECTL vRect; | |
51c1d535 | 527 | RECTL vFRect; |
0fe536e3 | 528 | |
51c1d535 DW |
529 | ::WinQueryWindowRect(m_hFrame, &vRect); |
530 | ::WinMapWindowPoints(m_hFrame, HWND_DESKTOP, (PPOINTL)&vRect, 2); | |
531 | vFRect = vRect; | |
532 | ::WinCalcFrameRect(m_hFrame, &vRect, TRUE); | |
0fe536e3 | 533 | nWidth = vRect.xRight - vRect.xLeft; |
a885d89a | 534 | |
0fe536e3 DW |
535 | m_frameStatusBar->GetSize( &nStatbarWidth |
536 | ,&nStatbarHeight | |
537 | ); | |
f38374d0 | 538 | |
0fe536e3 | 539 | // |
f38374d0 DW |
540 | // Since we wish the status bar to be directly under the client area, |
541 | // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. | |
0fe536e3 | 542 | // |
51c1d535 DW |
543 | m_frameStatusBar->SetSize( vRect.xLeft - vFRect.xLeft |
544 | ,vRect.yBottom - vFRect.yBottom | |
0fe536e3 DW |
545 | ,nWidth |
546 | ,nStatbarHeight | |
547 | ); | |
f6bcfd97 BP |
548 | if (!::WinQueryWindowPos(m_frameStatusBar->GetHWND(), &vSwp)) |
549 | { | |
550 | vError = ::WinGetLastError(vHabmain); | |
551 | sError = wxPMErrorToStr(vError); | |
51c1d535 | 552 | wxLogError("Error setting parent for StautsBar. Error: %s\n", sError); |
f6bcfd97 BP |
553 | return; |
554 | } | |
f38374d0 | 555 | } |
0367c1c0 | 556 | } // end of wxFrameOS2::PositionStatusBar |
21802234 | 557 | #endif // wxUSE_STATUSBAR |
0e320a79 | 558 | |
19193a2c | 559 | #if wxUSE_MENUS_NATIVE |
0367c1c0 | 560 | void wxFrameOS2::DetachMenuBar() |
0e320a79 | 561 | { |
21802234 | 562 | if (m_frameMenuBar) |
0e320a79 | 563 | { |
29435d81 | 564 | m_frameMenuBar->Detach(); |
0e320a79 | 565 | m_frameMenuBar = NULL; |
21802234 | 566 | } |
0367c1c0 | 567 | } // end of wxFrameOS2::DetachMenuBar |
21802234 | 568 | |
0367c1c0 | 569 | void wxFrameOS2::SetMenuBar( |
a885d89a | 570 | wxMenuBar* pMenuBar |
0fe536e3 | 571 | ) |
21802234 | 572 | { |
c3cea748 DW |
573 | ERRORID vError; |
574 | wxString sError; | |
dae16775 DW |
575 | HWND hTitlebar = NULLHANDLE; |
576 | HWND hHScroll = NULLHANDLE; | |
577 | HWND hVScroll = NULLHANDLE; | |
578 | HWND hMenuBar = NULLHANDLE; | |
579 | SWP vSwp; | |
580 | SWP vSwpTitlebar; | |
581 | SWP vSwpVScroll; | |
582 | SWP vSwpHScroll; | |
583 | SWP vSwpMenu; | |
c3cea748 | 584 | |
0fe536e3 | 585 | if (!pMenuBar) |
21802234 DW |
586 | { |
587 | DetachMenuBar(); | |
29a99be3 | 588 | |
64e0c5c6 DW |
589 | // |
590 | // Actually remove the menu from the frame | |
591 | // | |
592 | m_hMenu = (WXHMENU)0; | |
593 | InternalSetMenuBar(); | |
29a99be3 | 594 | } |
64e0c5c6 | 595 | else // set new non NULL menu bar |
c3cea748 | 596 | { |
64e0c5c6 | 597 | m_frameMenuBar = NULL; |
c3cea748 | 598 | |
64e0c5c6 DW |
599 | // |
600 | // Can set a menubar several times. | |
601 | // TODO: how to prevent a memory leak if you have a currently-unattached | |
602 | // menubar? wxWindows assumes that the frame will delete the menu (otherwise | |
603 | // there are problems for MDI). | |
604 | // | |
605 | if (pMenuBar->GetHMenu()) | |
606 | { | |
607 | m_hMenu = pMenuBar->GetHMenu(); | |
608 | } | |
609 | else | |
610 | { | |
611 | pMenuBar->Detach(); | |
612 | m_hMenu = pMenuBar->Create(); | |
613 | if (!m_hMenu) | |
614 | return; | |
615 | } | |
616 | InternalSetMenuBar(); | |
617 | m_frameMenuBar = pMenuBar; | |
0367c1c0 | 618 | pMenuBar->Attach((wxFrame*)this); |
c3cea748 | 619 | } |
0367c1c0 | 620 | } // end of wxFrameOS2::SetMenuBar |
0e320a79 | 621 | |
893758d5 DW |
622 | void wxFrameOS2::AttachMenuBar( |
623 | wxMenuBar* pMenubar | |
624 | ) | |
625 | { | |
19193a2c KB |
626 | wxFrameBase::AttachMenuBar(pMenubar); |
627 | ||
893758d5 DW |
628 | m_frameMenuBar = pMenubar; |
629 | ||
630 | if (!pMenubar) | |
631 | { | |
632 | // | |
633 | // Actually remove the menu from the frame | |
634 | // | |
635 | m_hMenu = (WXHMENU)0; | |
636 | InternalSetMenuBar(); | |
637 | } | |
638 | else // Set new non NULL menu bar | |
639 | { | |
640 | // | |
641 | // Can set a menubar several times. | |
642 | // | |
643 | if (pMenubar->GetHMenu()) | |
644 | { | |
645 | m_hMenu = pMenubar->GetHMenu(); | |
646 | } | |
647 | else | |
648 | { | |
649 | if (pMenubar->IsAttached()) | |
650 | pMenubar->Detach(); | |
651 | ||
652 | m_hMenu = pMenubar->Create(); | |
653 | ||
654 | if (!m_hMenu) | |
655 | return; | |
656 | } | |
657 | InternalSetMenuBar(); | |
658 | } | |
659 | } // end of wxFrameOS2::AttachMenuBar | |
660 | ||
0367c1c0 | 661 | void wxFrameOS2::InternalSetMenuBar() |
0e320a79 | 662 | { |
64e0c5c6 DW |
663 | ERRORID vError; |
664 | wxString sError; | |
665 | // | |
666 | // Set the parent and owner of the menubar to be the frame | |
667 | // | |
51c1d535 | 668 | if (!::WinSetParent(m_hMenu, m_hFrame, FALSE)) |
64e0c5c6 DW |
669 | { |
670 | vError = ::WinGetLastError(vHabmain); | |
671 | sError = wxPMErrorToStr(vError); | |
672 | wxLogError("Error setting parent for submenu. Error: %s\n", sError); | |
673 | } | |
674 | ||
51c1d535 | 675 | if (!::WinSetOwner(m_hMenu, m_hFrame)) |
64e0c5c6 DW |
676 | { |
677 | vError = ::WinGetLastError(vHabmain); | |
678 | sError = wxPMErrorToStr(vError); | |
679 | wxLogError("Error setting parent for submenu. Error: %s\n", sError); | |
680 | } | |
b7084589 | 681 | ::WinSendMsg(m_hFrame, WM_UPDATEFRAME, (MPARAM)FCF_MENU, (MPARAM)0); |
0367c1c0 | 682 | } // end of wxFrameOS2::InternalSetMenuBar |
19193a2c | 683 | #endif // wxUSE_MENUS_NATIVE |
0e320a79 | 684 | |
a885d89a DW |
685 | // |
686 | // Responds to colour changes, and passes event on to children | |
687 | // | |
0367c1c0 | 688 | void wxFrameOS2::OnSysColourChanged( |
a885d89a DW |
689 | wxSysColourChangedEvent& rEvent |
690 | ) | |
0e320a79 DW |
691 | { |
692 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); | |
693 | Refresh(); | |
694 | ||
7e99520b | 695 | #if wxUSE_STATUSBAR |
a885d89a | 696 | if (m_frameStatusBar) |
0e320a79 | 697 | { |
a885d89a DW |
698 | wxSysColourChangedEvent vEvent2; |
699 | ||
700 | vEvent2.SetEventObject(m_frameStatusBar); | |
701 | m_frameStatusBar->GetEventHandler()->ProcessEvent(vEvent2); | |
0e320a79 | 702 | } |
7e99520b | 703 | #endif //wxUSE_STATUSBAR |
0e320a79 | 704 | |
a885d89a | 705 | // |
0e320a79 | 706 | // Propagate the event to the non-top-level children |
a885d89a DW |
707 | // |
708 | wxWindow::OnSysColourChanged(rEvent); | |
0367c1c0 | 709 | } // end of wxFrameOS2::OnSysColourChanged |
21802234 | 710 | |
542875a8 | 711 | // Pass TRUE to show full screen, FALSE to restore. |
0367c1c0 | 712 | bool wxFrameOS2::ShowFullScreen( |
542875a8 DW |
713 | bool bShow |
714 | , long lStyle | |
715 | ) | |
716 | { | |
64e0c5c6 | 717 | if (bShow) |
542875a8 DW |
718 | { |
719 | if (IsFullScreen()) | |
720 | return FALSE; | |
721 | ||
64e0c5c6 DW |
722 | m_bFsIsShowing = TRUE; |
723 | m_lFsStyle = lStyle; | |
542875a8 | 724 | |
7e99520b | 725 | #if wxUSE_TOOLBAR |
19193a2c | 726 | wxToolBar* pTheToolBar = GetToolBar(); |
7e99520b DW |
727 | #endif //wxUSE_TOOLBAR |
728 | ||
729 | #if wxUSE_STATUSBAR | |
19193a2c | 730 | wxStatusBar* pTheStatusBar = GetStatusBar(); |
7e99520b | 731 | #endif //wxUSE_STATUSBAR |
542875a8 | 732 | |
64e0c5c6 | 733 | int nDummyWidth; |
542875a8 | 734 | |
7e99520b | 735 | #if wxUSE_TOOLBAR |
64e0c5c6 DW |
736 | if (pTheToolBar) |
737 | pTheToolBar->GetSize(&nDummyWidth, &m_nFsToolBarHeight); | |
7e99520b DW |
738 | #endif //wxUSE_TOOLBAR |
739 | ||
740 | #if wxUSE_STATUSBAR | |
64e0c5c6 DW |
741 | if (pTheStatusBar) |
742 | pTheStatusBar->GetSize(&nDummyWidth, &m_nFsStatusBarHeight); | |
7e99520b | 743 | #endif //wxUSE_STATUSBAR |
542875a8 | 744 | |
7e99520b | 745 | #if wxUSE_TOOLBAR |
64e0c5c6 DW |
746 | // |
747 | // Zap the toolbar, menubar, and statusbar | |
748 | // | |
749 | if ((lStyle & wxFULLSCREEN_NOTOOLBAR) && pTheToolBar) | |
542875a8 | 750 | { |
64e0c5c6 DW |
751 | pTheToolBar->SetSize(-1,0); |
752 | pTheToolBar->Show(FALSE); | |
542875a8 | 753 | } |
7e99520b | 754 | #endif //wxUSE_TOOLBAR |
542875a8 | 755 | |
64e0c5c6 DW |
756 | if (lStyle & wxFULLSCREEN_NOMENUBAR) |
757 | { | |
b7084589 DW |
758 | ::WinSetParent(m_hMenu, m_hFrame, FALSE); |
759 | ::WinSetOwner(m_hMenu, m_hFrame); | |
760 | ::WinSendMsg((HWND)m_hFrame, WM_UPDATEFRAME, (MPARAM)FCF_MENU, (MPARAM)0); | |
64e0c5c6 | 761 | } |
542875a8 | 762 | |
7e99520b | 763 | #if wxUSE_STATUSBAR |
64e0c5c6 | 764 | // |
542875a8 | 765 | // Save the number of fields in the statusbar |
64e0c5c6 DW |
766 | // |
767 | if ((lStyle & wxFULLSCREEN_NOSTATUSBAR) && pTheStatusBar) | |
542875a8 | 768 | { |
64e0c5c6 | 769 | m_nFsStatusBarFields = pTheStatusBar->GetFieldsCount(); |
542875a8 | 770 | SetStatusBar((wxStatusBar*) NULL); |
64e0c5c6 | 771 | delete pTheStatusBar; |
542875a8 DW |
772 | } |
773 | else | |
64e0c5c6 | 774 | m_nFsStatusBarFields = 0; |
7e99520b | 775 | #endif //wxUSE_STATUSBAR |
542875a8 | 776 | |
64e0c5c6 DW |
777 | // |
778 | // Zap the frame borders | |
779 | // | |
542875a8 | 780 | |
64e0c5c6 DW |
781 | // |
782 | // Save the 'normal' window style | |
783 | // | |
b7084589 | 784 | m_lFsOldWindowStyle = ::WinQueryWindowULong(m_hFrame, QWL_STYLE); |
542875a8 | 785 | |
64e0c5c6 | 786 | // |
b7084589 | 787 | // Save the old position, width & height, maximize state |
64e0c5c6 DW |
788 | // |
789 | m_vFsOldSize = GetRect(); | |
790 | m_bFsIsMaximized = IsMaximized(); | |
542875a8 | 791 | |
64e0c5c6 | 792 | // |
b7084589 | 793 | // Decide which window style flags to turn off |
64e0c5c6 DW |
794 | // |
795 | LONG lNewStyle = m_lFsOldWindowStyle; | |
796 | LONG lOffFlags = 0; | |
542875a8 | 797 | |
64e0c5c6 DW |
798 | if (lStyle & wxFULLSCREEN_NOBORDER) |
799 | lOffFlags |= FCF_BORDER; | |
800 | if (lStyle & wxFULLSCREEN_NOCAPTION) | |
801 | lOffFlags |= (FCF_TASKLIST | FCF_SYSMENU); | |
542875a8 | 802 | |
64e0c5c6 | 803 | lNewStyle &= (~lOffFlags); |
542875a8 | 804 | |
64e0c5c6 DW |
805 | // |
806 | // Change our window style to be compatible with full-screen mode | |
807 | // | |
b7084589 | 808 | ::WinSetWindowULong((HWND)m_hFrame, QWL_STYLE, (ULONG)lNewStyle); |
542875a8 | 809 | |
64e0c5c6 DW |
810 | // |
811 | // Resize to the size of the desktop | |
812 | int nWidth; | |
813 | int nHeight; | |
542875a8 | 814 | |
64e0c5c6 | 815 | RECTL vRect; |
542875a8 | 816 | |
64e0c5c6 DW |
817 | ::WinQueryWindowRect(HWND_DESKTOP, &vRect); |
818 | nWidth = vRect.xRight - vRect.xLeft; | |
819 | // | |
820 | // Rmember OS/2 is backwards! | |
821 | // | |
822 | nHeight = vRect.yTop - vRect.yBottom; | |
542875a8 | 823 | |
64e0c5c6 DW |
824 | SetSize( nWidth |
825 | ,nHeight | |
826 | ); | |
542875a8 | 827 | |
64e0c5c6 DW |
828 | // |
829 | // Now flush the window style cache and actually go full-screen | |
830 | // | |
831 | ::WinSetWindowPos( (HWND) GetParent()->GetHWND() | |
832 | ,HWND_TOP | |
833 | ,0 | |
834 | ,0 | |
835 | ,nWidth | |
836 | ,nHeight | |
837 | ,SWP_SIZE | SWP_SHOW | |
838 | ); | |
839 | ||
840 | wxSizeEvent vEvent( wxSize( nWidth | |
841 | ,nHeight | |
842 | ) | |
843 | ,GetId() | |
844 | ); | |
542875a8 | 845 | |
64e0c5c6 | 846 | GetEventHandler()->ProcessEvent(vEvent); |
542875a8 DW |
847 | return TRUE; |
848 | } | |
849 | else | |
850 | { | |
851 | if (!IsFullScreen()) | |
852 | return FALSE; | |
853 | ||
64e0c5c6 | 854 | m_bFsIsShowing = FALSE; |
542875a8 | 855 | |
7e99520b | 856 | #if wxUSE_TOOLBAR |
64e0c5c6 | 857 | wxToolBar* pTheToolBar = GetToolBar(); |
542875a8 | 858 | |
64e0c5c6 DW |
859 | // |
860 | // Restore the toolbar, menubar, and statusbar | |
861 | // | |
862 | if (pTheToolBar && (m_lFsStyle & wxFULLSCREEN_NOTOOLBAR)) | |
542875a8 | 863 | { |
64e0c5c6 DW |
864 | pTheToolBar->SetSize(-1, m_nFsToolBarHeight); |
865 | pTheToolBar->Show(TRUE); | |
542875a8 | 866 | } |
7e99520b | 867 | #endif //wxUSE_TOOLBAR |
542875a8 | 868 | |
7e99520b | 869 | #if wxUSE_STATUSBAR |
64e0c5c6 | 870 | if ((m_lFsStyle & wxFULLSCREEN_NOSTATUSBAR) && (m_nFsStatusBarFields > 0)) |
542875a8 | 871 | { |
64e0c5c6 | 872 | CreateStatusBar(m_nFsStatusBarFields); |
5b3ed311 | 873 | // PositionStatusBar(); |
542875a8 | 874 | } |
7e99520b | 875 | #endif //wxUSE_STATUSBAR |
542875a8 | 876 | |
64e0c5c6 DW |
877 | if ((m_lFsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0)) |
878 | { | |
b7084589 DW |
879 | ::WinSetParent(m_hMenu, m_hFrame, FALSE); |
880 | ::WinSetOwner(m_hMenu, m_hFrame); | |
881 | ::WinSendMsg(m_hFrame, WM_UPDATEFRAME, (MPARAM)FCF_MENU, (MPARAM)0); | |
64e0c5c6 DW |
882 | } |
883 | Maximize(m_bFsIsMaximized); | |
884 | ||
b7084589 | 885 | ::WinSetWindowULong( m_hFrame |
64e0c5c6 DW |
886 | ,QWL_STYLE |
887 | ,(ULONG)m_lFsOldWindowStyle | |
888 | ); | |
889 | ::WinSetWindowPos( (HWND) GetParent()->GetHWND() | |
890 | ,HWND_TOP | |
891 | ,m_vFsOldSize.x | |
892 | ,m_vFsOldSize.y | |
893 | ,m_vFsOldSize.width | |
894 | ,m_vFsOldSize.height | |
895 | ,SWP_SIZE | SWP_SHOW | |
896 | ); | |
542875a8 DW |
897 | return TRUE; |
898 | } | |
0367c1c0 | 899 | } // end of wxFrameOS2::ShowFullScreen |
542875a8 | 900 | |
a885d89a DW |
901 | // |
902 | // Frame window | |
903 | // | |
0367c1c0 | 904 | bool wxFrameOS2::OS2Create( |
a885d89a DW |
905 | int nId |
906 | , wxWindow* pParent | |
907 | , const wxChar* zWclass | |
908 | , wxWindow* pWxWin | |
909 | , const wxChar* zTitle | |
910 | , int nX | |
911 | , int nY | |
912 | , int nWidth | |
913 | , int nHeight | |
914 | , long ulStyle | |
915 | ) | |
21802234 | 916 | { |
f23208ca DW |
917 | ULONG ulCreateFlags = 0L; |
918 | ULONG ulStyleFlags = 0L; | |
914589c2 | 919 | ULONG ulExtraFlags = 0L; |
f23208ca DW |
920 | FRAMECDATA vFrameCtlData; |
921 | HWND hParent = NULLHANDLE; | |
f23208ca DW |
922 | HWND hTitlebar = NULLHANDLE; |
923 | HWND hHScroll = NULLHANDLE; | |
924 | HWND hVScroll = NULLHANDLE; | |
51c1d535 DW |
925 | HWND hFrame = NULLHANDLE; |
926 | HWND hClient = NULLHANDLE; | |
b963e7d5 DW |
927 | SWP vSwp[10]; |
928 | RECTL vRect[10]; | |
40bd6154 | 929 | USHORT uCtlCount; |
51c1d535 DW |
930 | ERRORID vError; |
931 | wxString sError; | |
a885d89a DW |
932 | |
933 | m_hDefaultIcon = (WXHICON) (wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON : wxDEFAULT_FRAME_ICON); | |
a0606634 | 934 | |
f23208ca DW |
935 | if (pParent) |
936 | hParent = GetWinHwnd(pParent); | |
937 | else | |
938 | hParent = HWND_DESKTOP; | |
a885d89a | 939 | |
914589c2 | 940 | if (ulStyle == wxDEFAULT_FRAME_STYLE) |
f23208ca | 941 | ulCreateFlags = FCF_SIZEBORDER | FCF_TITLEBAR | FCF_SYSMENU | |
f6bcfd97 | 942 | FCF_MINMAX | FCF_TASKLIST; |
a885d89a | 943 | else |
a885d89a | 944 | { |
914589c2 | 945 | if ((ulStyle & wxCAPTION) == wxCAPTION) |
f23208ca | 946 | ulCreateFlags = FCF_TASKLIST; |
914589c2 | 947 | else |
f23208ca | 948 | ulCreateFlags = FCF_NOMOVEWITHOWNER; |
914589c2 | 949 | |
f6bcfd97 BP |
950 | if ((ulStyle & wxVSCROLL) == wxVSCROLL) |
951 | ulCreateFlags |= FCF_VERTSCROLL; | |
952 | if ((ulStyle & wxHSCROLL) == wxHSCROLL) | |
953 | ulCreateFlags |= FCF_HORZSCROLL; | |
914589c2 | 954 | if (ulStyle & wxMINIMIZE_BOX) |
f23208ca | 955 | ulCreateFlags |= FCF_MINBUTTON; |
914589c2 | 956 | if (ulStyle & wxMAXIMIZE_BOX) |
f23208ca | 957 | ulCreateFlags |= FCF_MAXBUTTON; |
914589c2 | 958 | if (ulStyle & wxTHICK_FRAME) |
f23208ca | 959 | ulCreateFlags |= FCF_DLGBORDER; |
914589c2 | 960 | if (ulStyle & wxSYSTEM_MENU) |
f23208ca | 961 | ulCreateFlags |= FCF_SYSMENU; |
914589c2 | 962 | if (ulStyle & wxCAPTION) |
f23208ca | 963 | ulCreateFlags |= FCF_TASKLIST; |
914589c2 DW |
964 | if (ulStyle & wxCLIP_CHILDREN) |
965 | { | |
966 | // Invalid for frame windows under PM | |
967 | } | |
a885d89a | 968 | |
914589c2 | 969 | if (ulStyle & wxTINY_CAPTION_VERT) |
f23208ca | 970 | ulCreateFlags |= FCF_TASKLIST; |
914589c2 | 971 | if (ulStyle & wxTINY_CAPTION_HORIZ) |
f23208ca DW |
972 | ulCreateFlags |= FCF_TASKLIST; |
973 | ||
914589c2 | 974 | if ((ulStyle & wxTHICK_FRAME) == 0) |
f23208ca | 975 | ulCreateFlags |= FCF_BORDER; |
914589c2 DW |
976 | if (ulStyle & wxFRAME_TOOL_WINDOW) |
977 | ulExtraFlags = kFrameToolWindow; | |
21802234 | 978 | |
914589c2 | 979 | if (ulStyle & wxSTAY_ON_TOP) |
f23208ca | 980 | ulCreateFlags |= FCF_SYSMODAL; |
914589c2 | 981 | } |
f23208ca DW |
982 | if ((ulStyle & wxMINIMIZE) || (ulStyle & wxICONIZE)) |
983 | ulStyleFlags |= WS_MINIMIZED; | |
984 | if (ulStyle & wxMAXIMIZE) | |
985 | ulStyleFlags |= WS_MAXIMIZED; | |
986 | ||
a885d89a DW |
987 | // |
988 | // Clear the visible flag, we always call show | |
989 | // | |
f23208ca | 990 | ulStyleFlags &= (unsigned long)~WS_VISIBLE; |
a885d89a | 991 | m_bIconized = FALSE; |
f23208ca DW |
992 | |
993 | // | |
994 | // Set the frame control block | |
995 | // | |
996 | vFrameCtlData.cb = sizeof(vFrameCtlData); | |
997 | vFrameCtlData.flCreateFlags = ulCreateFlags; | |
998 | vFrameCtlData.hmodResources = 0L; | |
999 | vFrameCtlData.idResources = 0; | |
1000 | ||
1001 | // | |
51c1d535 DW |
1002 | // Create the frame window: We break ranks with other ports now |
1003 | // and instead of calling down into the base wxWindow class' OS2Create | |
1004 | // we do all our own stuff here. We will set the needed pieces | |
1005 | // of wxWindow manually, here. | |
f23208ca | 1006 | // |
f23208ca | 1007 | |
51c1d535 DW |
1008 | hFrame = ::WinCreateStdWindow( hParent |
1009 | ,ulStyleFlags // frame-window style | |
1010 | ,&ulCreateFlags // window style | |
1011 | ,(PSZ)zWclass // class name | |
1012 | ,(PSZ)zTitle // window title | |
1013 | ,0L // default client style | |
1014 | ,NULLHANDLE // resource in executable file | |
1015 | ,0 // resource id | |
1016 | ,&hClient // receives client window handle | |
1017 | ); | |
1018 | if (!hFrame) | |
f23208ca | 1019 | { |
51c1d535 DW |
1020 | vError = ::WinGetLastError(vHabmain); |
1021 | sError = wxPMErrorToStr(vError); | |
1022 | wxLogError("Error creating frame. Error: %s\n", sError); | |
f23208ca DW |
1023 | return FALSE; |
1024 | } | |
dae16775 | 1025 | |
7e99520b | 1026 | // |
51c1d535 | 1027 | // wxWindow class' m_hWnd set here and needed associations |
5b3ed311 | 1028 | // |
51c1d535 DW |
1029 | m_hFrame = hFrame; |
1030 | m_hWnd = hClient; | |
1031 | wxAssociateWinWithHandle(m_hWnd, this); | |
1032 | wxAssociateWinWithHandle(m_hFrame, this); | |
5b3ed311 | 1033 | |
8d854fa9 DW |
1034 | m_backgroundColour.Set(wxString("GREY")); |
1035 | ||
1036 | LONG lColor = (LONG)m_backgroundColour.GetPixel(); | |
1037 | ||
1038 | if (!::WinSetPresParam( m_hWnd | |
1039 | ,PP_BACKGROUNDCOLOR | |
1040 | ,sizeof(LONG) | |
1041 | ,(PVOID)&lColor | |
1042 | )) | |
1043 | { | |
1044 | vError = ::WinGetLastError(vHabmain); | |
1045 | sError = wxPMErrorToStr(vError); | |
1046 | wxLogError("Error creating frame. Error: %s\n", sError); | |
1047 | return FALSE; | |
1048 | } | |
1049 | ||
51c1d535 DW |
1050 | // |
1051 | // Now need to subclass window. Instead of calling the SubClassWin in wxWindow | |
1052 | // we manually subclass here because we don't want to use the main wxWndProc | |
1053 | // by default | |
1054 | // | |
1055 | m_fnOldWndProc = (WXFARPROC) ::WinSubclassWindow(m_hFrame, (PFNWP)wxFrameMainWndProc); | |
5b3ed311 | 1056 | |
f23208ca DW |
1057 | // |
1058 | // Now size everything. If adding a menu the client will need to be resized. | |
1059 | // | |
e604d44b | 1060 | |
51c1d535 | 1061 | if (!::WinSetWindowPos( m_hFrame |
f23208ca DW |
1062 | ,HWND_TOP |
1063 | ,nX | |
1064 | ,nY | |
1065 | ,nWidth | |
1066 | ,nHeight | |
f6bcfd97 | 1067 | ,SWP_SIZE | SWP_MOVE | SWP_ACTIVATE | SWP_ZORDER |
f23208ca | 1068 | )) |
51c1d535 DW |
1069 | { |
1070 | vError = ::WinGetLastError(vHabmain); | |
1071 | sError = wxPMErrorToStr(vError); | |
1072 | wxLogError("Error sizing frame. Error: %s\n", sError); | |
1073 | return FALSE; | |
1074 | } | |
1075 | // | |
1076 | // We may have to be smarter here when variable sized toolbars are added! | |
1077 | // | |
1078 | if (!::WinSetWindowPos( m_hWnd | |
1079 | ,HWND_TOP | |
fb83aca5 DW |
1080 | ,nX // + 20 |
1081 | ,nY // + 20 | |
1082 | ,nWidth // - 60 | |
1083 | ,nHeight // - 60 | |
51c1d535 DW |
1084 | ,SWP_SIZE | SWP_MOVE | SWP_ACTIVATE | SWP_ZORDER |
1085 | )) | |
1086 | { | |
1087 | vError = ::WinGetLastError(vHabmain); | |
1088 | sError = wxPMErrorToStr(vError); | |
1089 | wxLogError("Error sizing client. Error: %s\n", sError); | |
f23208ca | 1090 | return FALSE; |
51c1d535 | 1091 | } |
a885d89a | 1092 | return TRUE; |
0367c1c0 | 1093 | } // end of wxFrameOS2::OS2Create |
0e320a79 | 1094 | |
a885d89a | 1095 | // |
0e320a79 DW |
1096 | // Default activation behaviour - set the focus for the first child |
1097 | // subwindow found. | |
a885d89a | 1098 | // |
0367c1c0 | 1099 | void wxFrameOS2::OnActivate( |
a885d89a DW |
1100 | wxActivateEvent& rEvent |
1101 | ) | |
0e320a79 | 1102 | { |
c4955899 | 1103 | if ( rEvent.GetActive() ) |
0e320a79 | 1104 | { |
c4955899 DW |
1105 | // restore focus to the child which was last focused |
1106 | wxLogTrace(_T("focus"), _T("wxFrame %08x activated."), m_hWnd); | |
21802234 | 1107 | |
c4955899 DW |
1108 | wxWindow* pParent = m_pWinLastFocused ? m_pWinLastFocused->GetParent() |
1109 | : NULL; | |
1110 | if (!pParent) | |
1111 | { | |
1112 | pParent = this; | |
1113 | } | |
21802234 | 1114 | |
c4955899 DW |
1115 | wxSetFocusToChild( pParent |
1116 | ,&m_pWinLastFocused | |
1117 | ); | |
1118 | } | |
1119 | else // deactivating | |
1120 | { | |
1121 | // | |
1122 | // Remember the last focused child if it is our child | |
1123 | // | |
1124 | m_pWinLastFocused = FindFocus(); | |
1125 | ||
1126 | for (wxWindowList::Node* pNode = GetChildren().GetFirst(); | |
1127 | pNode; | |
1128 | pNode = pNode->GetNext()) | |
1129 | { | |
1130 | // FIXME all this is totally bogus - we need to do the same as wxPanel, | |
1131 | // but how to do it without duplicating the code? | |
1132 | ||
1133 | // restore focus | |
1134 | wxWindow* pChild = pNode->GetData(); | |
1135 | ||
1136 | if (!pChild->IsTopLevel() | |
21802234 | 1137 | #if wxUSE_TOOLBAR |
c4955899 | 1138 | && !wxDynamicCast(pChild, wxToolBar) |
21802234 DW |
1139 | #endif // wxUSE_TOOLBAR |
1140 | #if wxUSE_STATUSBAR | |
c4955899 | 1141 | && !wxDynamicCast(pChild, wxStatusBar) |
21802234 | 1142 | #endif // wxUSE_STATUSBAR |
c4955899 DW |
1143 | ) |
1144 | { | |
1145 | pChild->SetFocus(); | |
1146 | return; | |
1147 | } | |
21802234 | 1148 | } |
0e320a79 | 1149 | } |
0367c1c0 | 1150 | } // end of wxFrameOS2::OnActivate |
0e320a79 | 1151 | |
f38374d0 DW |
1152 | // ---------------------------------------------------------------------------- |
1153 | // wxFrame size management: we exclude the areas taken by menu/status/toolbars | |
1154 | // from the client area, so the client area is what's really available for the | |
1155 | // frame contents | |
1156 | // ---------------------------------------------------------------------------- | |
0e320a79 DW |
1157 | |
1158 | // Checks if there is a toolbar, and returns the first free client position | |
0367c1c0 | 1159 | wxPoint wxFrameOS2::GetClientAreaOrigin() const |
0e320a79 | 1160 | { |
a885d89a DW |
1161 | wxPoint vPoint(0, 0); |
1162 | ||
7e99520b | 1163 | #if wxUSE_TOOLBAR |
0e320a79 DW |
1164 | if (GetToolBar()) |
1165 | { | |
a885d89a DW |
1166 | int nWidth; |
1167 | int nHeight; | |
1168 | ||
1169 | GetToolBar()->GetSize( &nWidth | |
1170 | ,&nHeight | |
1171 | ); | |
0e320a79 DW |
1172 | |
1173 | if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) | |
1174 | { | |
a885d89a | 1175 | vPoint.x += nWidth; |
0e320a79 DW |
1176 | } |
1177 | else | |
1178 | { | |
a885d89a DW |
1179 | // PM is backwards from windows |
1180 | vPoint.y += nHeight; | |
0e320a79 DW |
1181 | } |
1182 | } | |
7e99520b | 1183 | #endif //wxUSE_TOOLBAR |
a885d89a | 1184 | return vPoint; |
0367c1c0 | 1185 | } // end of wxFrameOS2::GetClientAreaOrigin |
0e320a79 | 1186 | |
f38374d0 DW |
1187 | // ---------------------------------------------------------------------------- |
1188 | // tool/status bar stuff | |
1189 | // ---------------------------------------------------------------------------- | |
1190 | ||
21802234 | 1191 | #if wxUSE_TOOLBAR |
f38374d0 | 1192 | |
0367c1c0 | 1193 | wxToolBar* wxFrameOS2::CreateToolBar( |
a885d89a DW |
1194 | long lStyle |
1195 | , wxWindowID vId | |
1196 | , const wxString& rName | |
1197 | ) | |
0e320a79 | 1198 | { |
a885d89a DW |
1199 | if (wxFrameBase::CreateToolBar( lStyle |
1200 | ,vId | |
1201 | ,rName | |
1202 | )) | |
0e320a79 | 1203 | { |
0e320a79 | 1204 | PositionToolBar(); |
0e320a79 | 1205 | } |
f38374d0 | 1206 | return m_frameToolBar; |
0367c1c0 | 1207 | } // end of wxFrameOS2::CreateToolBar |
0e320a79 | 1208 | |
0367c1c0 | 1209 | void wxFrameOS2::PositionToolBar() |
0e320a79 | 1210 | { |
a885d89a DW |
1211 | HWND hWndClient; |
1212 | RECTL vRect; | |
1213 | ||
40bd6154 | 1214 | ::WinQueryWindowRect(GetHwnd(), &vRect); |
0e320a79 | 1215 | |
f38374d0 | 1216 | #if wxUSE_STATUSBAR |
a885d89a | 1217 | if (GetStatusBar()) |
0e320a79 | 1218 | { |
a885d89a DW |
1219 | int nStatusX; |
1220 | int nStatusY; | |
1221 | ||
1222 | GetStatusBar()->GetClientSize( &nStatusX | |
1223 | ,&nStatusY | |
1224 | ); | |
1225 | // PM is backwards from windows | |
1226 | vRect.yBottom += nStatusY; | |
0e320a79 | 1227 | } |
f38374d0 | 1228 | #endif // wxUSE_STATUSBAR |
0e320a79 | 1229 | |
1c84ee88 | 1230 | if ( m_frameToolBar ) |
0e320a79 | 1231 | { |
a885d89a DW |
1232 | int nToolbarWidth; |
1233 | int nToolbarHeight; | |
1234 | ||
1c84ee88 | 1235 | m_frameToolBar->GetSize( &nToolbarWidth |
a885d89a DW |
1236 | ,&nToolbarHeight |
1237 | ); | |
0e320a79 | 1238 | |
a885d89a | 1239 | if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) |
0e320a79 | 1240 | { |
a885d89a | 1241 | nToolbarHeight = vRect.yBottom; |
0e320a79 DW |
1242 | } |
1243 | else | |
1244 | { | |
a885d89a | 1245 | nToolbarWidth = vRect.xRight; |
21802234 | 1246 | } |
f38374d0 | 1247 | |
a885d89a DW |
1248 | // |
1249 | // Use the 'real' PM position here | |
1250 | // | |
1251 | GetToolBar()->SetSize( 0 | |
1252 | ,0 | |
1253 | ,nToolbarWidth | |
1254 | ,nToolbarHeight | |
1255 | ,wxSIZE_NO_ADJUSTMENTS | |
1256 | ); | |
21802234 | 1257 | } |
0367c1c0 | 1258 | } // end of wxFrameOS2::PositionToolBar |
21802234 DW |
1259 | #endif // wxUSE_TOOLBAR |
1260 | ||
f38374d0 DW |
1261 | // ---------------------------------------------------------------------------- |
1262 | // frame state (iconized/maximized/...) | |
1263 | // ---------------------------------------------------------------------------- | |
1264 | ||
a885d89a | 1265 | // |
21802234 DW |
1266 | // propagate our state change to all child frames: this allows us to emulate X |
1267 | // Windows behaviour where child frames float independently of the parent one | |
1268 | // on the desktop, but are iconized/restored with it | |
a885d89a | 1269 | // |
0367c1c0 | 1270 | void wxFrameOS2::IconizeChildFrames( |
a885d89a DW |
1271 | bool bIconize |
1272 | ) | |
21802234 | 1273 | { |
a885d89a DW |
1274 | for (wxWindowList::Node* pNode = GetChildren().GetFirst(); |
1275 | pNode; | |
1276 | pNode = pNode->GetNext() ) | |
21802234 | 1277 | { |
a885d89a | 1278 | wxWindow* pWin = pNode->GetData(); |
21802234 | 1279 | |
a885d89a | 1280 | if (pWin->IsKindOf(CLASSINFO(wxFrame)) ) |
21802234 | 1281 | { |
a885d89a | 1282 | ((wxFrame *)pWin)->Iconize(bIconize); |
0e320a79 DW |
1283 | } |
1284 | } | |
0367c1c0 | 1285 | } // end of wxFrameOS2::IconizeChildFrames |
0e320a79 | 1286 | |
21802234 DW |
1287 | // =========================================================================== |
1288 | // message processing | |
1289 | // =========================================================================== | |
1290 | ||
1291 | // --------------------------------------------------------------------------- | |
1292 | // preprocessing | |
1293 | // --------------------------------------------------------------------------- | |
0367c1c0 | 1294 | bool wxFrameOS2::OS2TranslateMessage( |
a885d89a DW |
1295 | WXMSG* pMsg |
1296 | ) | |
21802234 | 1297 | { |
a885d89a | 1298 | // |
21802234 | 1299 | // try the menu bar accels |
a885d89a DW |
1300 | // |
1301 | wxMenuBar* pMenuBar = GetMenuBar(); | |
1302 | ||
19193a2c | 1303 | if (!pMenuBar) |
21802234 DW |
1304 | return FALSE; |
1305 | ||
19193a2c | 1306 | #if wxUSE_ACCEL && wxUSE_MENUS_NATIVE |
a885d89a | 1307 | const wxAcceleratorTable& rAcceleratorTable = pMenuBar->GetAccelTable(); |
e604d44b | 1308 | return rAcceleratorTable.Translate(GetHWND(), pMsg); |
7e99520b DW |
1309 | #else |
1310 | return FALSE; | |
1311 | #endif //wxUSE_ACCEL | |
0367c1c0 | 1312 | } // end of wxFrameOS2::OS2TranslateMessage |
21802234 DW |
1313 | |
1314 | // --------------------------------------------------------------------------- | |
1315 | // our private (non virtual) message handlers | |
1316 | // --------------------------------------------------------------------------- | |
0367c1c0 | 1317 | bool wxFrameOS2::HandlePaint() |
21802234 | 1318 | { |
a885d89a DW |
1319 | RECTL vRect; |
1320 | ||
e604d44b | 1321 | if (::WinQueryUpdateRect(GetHWND(), &vRect)) |
29435d81 | 1322 | { |
a885d89a | 1323 | if (m_bIconized) |
29435d81 | 1324 | { |
a885d89a DW |
1325 | // |
1326 | // Icons in PM are the same as "pointers" | |
1327 | // | |
1328 | HPOINTER hIcon; | |
29435d81 | 1329 | |
a885d89a | 1330 | if (m_icon.Ok()) |
b7084589 | 1331 | hIcon = (HPOINTER)::WinSendMsg(m_hFrame, WM_QUERYICON, 0L, 0L); |
a885d89a DW |
1332 | else |
1333 | hIcon = (HPOINTER)m_hDefaultIcon; | |
1334 | ||
1335 | // | |
21802234 DW |
1336 | // Hold a pointer to the dc so long as the OnPaint() message |
1337 | // is being processed | |
a885d89a DW |
1338 | // |
1339 | RECTL vRect2; | |
64e0c5c6 | 1340 | HPS hPs = ::WinBeginPaint(GetHwnd(), NULLHANDLE, &vRect2); |
29435d81 | 1341 | |
a885d89a | 1342 | // |
29435d81 | 1343 | // Erase background before painting or we get white background |
a885d89a DW |
1344 | // |
1345 | OS2DefWindowProc(WM_ERASEBACKGROUND, (MPARAM)hPs, (MPARAM)&vRect2); | |
29435d81 | 1346 | |
a885d89a | 1347 | if (hIcon) |
29435d81 | 1348 | { |
a885d89a DW |
1349 | HWND hWndClient; |
1350 | RECTL vRect3; | |
21802234 | 1351 | |
40bd6154 | 1352 | ::WinQueryWindowRect(GetHwnd(), &vRect3); |
29435d81 | 1353 | |
a885d89a DW |
1354 | static const int nIconWidth = 32; |
1355 | static const int nIconHeight = 32; | |
1356 | int nIconX = (int)((vRect3.xRight - nIconWidth)/2); | |
1357 | int nIconY = (int)((vRect3.yBottom + nIconHeight)/2); | |
29435d81 | 1358 | |
a885d89a | 1359 | ::WinDrawPointer(hPs, nIconX, nIconY, hIcon, DP_NORMAL); |
29435d81 | 1360 | } |
a885d89a | 1361 | ::WinEndPaint(hPs); |
29435d81 DW |
1362 | return TRUE; |
1363 | } | |
1364 | else | |
1365 | { | |
8d854fa9 | 1366 | return(wxWindow::HandlePaint()); |
29435d81 DW |
1367 | } |
1368 | } | |
1369 | else | |
1370 | { | |
1371 | // nothing to paint - processed | |
1372 | return TRUE; | |
1373 | } | |
29435d81 | 1374 | return FALSE; |
0367c1c0 | 1375 | } // end of wxFrameOS2::HandlePaint |
21802234 | 1376 | |
0367c1c0 | 1377 | bool wxFrameOS2::HandleSize( |
a885d89a DW |
1378 | int nX |
1379 | , int nY | |
1380 | , WXUINT nId | |
1381 | ) | |
21802234 | 1382 | { |
a885d89a | 1383 | bool bProcessed = FALSE; |
21802234 | 1384 | |
a885d89a | 1385 | switch (nId) |
21802234 | 1386 | { |
a885d89a DW |
1387 | case kSizeNormal: |
1388 | // | |
1389 | // Only do it it if we were iconized before, otherwise resizing the | |
21802234 DW |
1390 | // parent frame has a curious side effect of bringing it under it's |
1391 | // children | |
a885d89a | 1392 | if (!m_bIconized ) |
21802234 DW |
1393 | break; |
1394 | ||
a885d89a | 1395 | // |
21802234 | 1396 | // restore all child frames too |
a885d89a | 1397 | // |
21802234 | 1398 | IconizeChildFrames(FALSE); |
3febf684 | 1399 | (void)SendIconizeEvent(FALSE); |
21802234 | 1400 | |
a885d89a | 1401 | // |
21802234 | 1402 | // fall through |
a885d89a | 1403 | // |
21802234 | 1404 | |
a885d89a DW |
1405 | case kSizeMax: |
1406 | m_bIconized = FALSE; | |
21802234 DW |
1407 | break; |
1408 | ||
a885d89a DW |
1409 | case kSizeMin: |
1410 | // | |
1411 | // Iconize all child frames too | |
1412 | // | |
21802234 | 1413 | IconizeChildFrames(TRUE); |
3febf684 | 1414 | (void)SendIconizeEvent(); |
a885d89a | 1415 | m_bIconized = TRUE; |
21802234 DW |
1416 | break; |
1417 | } | |
f38374d0 | 1418 | |
a885d89a | 1419 | if (!m_bIconized) |
21802234 | 1420 | { |
a885d89a | 1421 | // |
29435d81 | 1422 | // forward WM_SIZE to status bar control |
a885d89a | 1423 | // |
f38374d0 DW |
1424 | #if wxUSE_NATIVE_STATUSBAR |
1425 | if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95))) | |
1426 | { | |
a885d89a DW |
1427 | wxSizeEvent vEvent( wxSize( nX |
1428 | ,nY | |
1429 | ) | |
1430 | ,m_frameStatusBar->GetId() | |
1431 | ); | |
f38374d0 | 1432 | |
a885d89a DW |
1433 | vEvent.SetEventObject(m_frameStatusBar); |
1434 | m_frameStatusBar->OnSize(vEvent); | |
f38374d0 DW |
1435 | } |
1436 | #endif // wxUSE_NATIVE_STATUSBAR | |
1437 | ||
51c1d535 | 1438 | PositionStatusBar(); |
7e99520b | 1439 | #if wxUSE_TOOLBAR |
21802234 | 1440 | PositionToolBar(); |
7e99520b DW |
1441 | #endif // wxUSE_TOOLBAR |
1442 | ||
a885d89a DW |
1443 | wxSizeEvent vEvent( wxSize( nX |
1444 | ,nY | |
1445 | ) | |
1446 | ,m_windowId | |
1447 | ); | |
21802234 | 1448 | |
a885d89a DW |
1449 | vEvent.SetEventObject(this); |
1450 | bProcessed = GetEventHandler()->ProcessEvent(vEvent); | |
21802234 | 1451 | } |
a885d89a | 1452 | return bProcessed; |
0367c1c0 | 1453 | } // end of wxFrameOS2::HandleSize |
21802234 | 1454 | |
0367c1c0 | 1455 | bool wxFrameOS2::HandleCommand( |
a885d89a DW |
1456 | WXWORD nId |
1457 | , WXWORD nCmd | |
1458 | , WXHWND hControl | |
1459 | ) | |
21802234 | 1460 | { |
a885d89a | 1461 | if (hControl) |
21802234 | 1462 | { |
a885d89a | 1463 | // |
21802234 | 1464 | // In case it's e.g. a toolbar. |
a885d89a DW |
1465 | // |
1466 | wxWindow* pWin = wxFindWinFromHandle(hControl); | |
1467 | ||
1468 | if (pWin) | |
1469 | return pWin->OS2Command( nCmd | |
1470 | ,nId | |
1471 | ); | |
21802234 DW |
1472 | } |
1473 | ||
a885d89a DW |
1474 | // |
1475 | // Handle here commands from menus and accelerators | |
1476 | // | |
5b3ed311 | 1477 | if (nCmd == CMDSRC_MENU || nCmd == CMDSRC_ACCELERATOR) |
21802234 | 1478 | { |
19193a2c | 1479 | #if wxUSE_MENUS_NATIVE |
a885d89a | 1480 | if (wxCurrentPopupMenu) |
21802234 | 1481 | { |
a885d89a DW |
1482 | wxMenu* pPopupMenu = wxCurrentPopupMenu; |
1483 | ||
21802234 DW |
1484 | wxCurrentPopupMenu = NULL; |
1485 | ||
a885d89a DW |
1486 | return pPopupMenu->OS2Command( nCmd |
1487 | ,nId | |
1488 | ); | |
19193a2c | 1489 | return TRUE; |
21802234 | 1490 | } |
19193a2c | 1491 | #endif |
21802234 | 1492 | |
a885d89a | 1493 | if (ProcessCommand(nId)) |
21802234 DW |
1494 | { |
1495 | return TRUE; | |
1496 | } | |
1497 | } | |
21802234 | 1498 | return FALSE; |
0367c1c0 | 1499 | } // end of wxFrameOS2::HandleCommand |
21802234 | 1500 | |
0367c1c0 | 1501 | bool wxFrameOS2::HandleMenuSelect( |
a885d89a DW |
1502 | WXWORD nItem |
1503 | , WXWORD nFlags | |
1504 | , WXHMENU hMenu | |
1505 | ) | |
21802234 | 1506 | { |
e604d44b DW |
1507 | if( !nFlags ) |
1508 | { | |
1509 | MENUITEM mItem; | |
1510 | MRESULT rc; | |
1511 | ||
51c1d535 | 1512 | rc = ::WinSendMsg(hMenu, MM_QUERYITEM, MPFROM2SHORT(nItem, TRUE), (MPARAM)&mItem); |
e604d44b DW |
1513 | |
1514 | if(rc && !(mItem.afStyle & (MIS_SUBMENU | MIS_SEPARATOR))) | |
1515 | { | |
1516 | wxMenuEvent vEvent(wxEVT_MENU_HIGHLIGHT, nItem); | |
1517 | ||
1518 | vEvent.SetEventObject(this); | |
1519 | GetEventHandler()->ProcessEvent(vEvent); // return value would be ignored by PM | |
1520 | } | |
1521 | } | |
1522 | return TRUE; | |
0367c1c0 | 1523 | } // end of wxFrameOS2::HandleMenuSelect |
21802234 DW |
1524 | |
1525 | // --------------------------------------------------------------------------- | |
51c1d535 | 1526 | // Main Frame window proc |
21802234 | 1527 | // --------------------------------------------------------------------------- |
51c1d535 DW |
1528 | MRESULT EXPENTRY wxFrameMainWndProc( |
1529 | HWND hWnd | |
1530 | , ULONG ulMsg | |
1531 | , MPARAM wParam | |
1532 | , MPARAM lParam | |
1533 | ) | |
1534 | { | |
1535 | MRESULT rc = (MRESULT)0; | |
1536 | bool bProcessed = FALSE; | |
1537 | wxFrame* pWnd = NULL; | |
1538 | ||
1539 | pWnd = (wxFrame*) wxFindWinFromHandle((WXHWND) hWnd); | |
1540 | switch (ulMsg) | |
1541 | { | |
1542 | case WM_QUERYFRAMECTLCOUNT: | |
1543 | if(pWnd && pWnd->m_fnOldWndProc) | |
1544 | { | |
1545 | USHORT uItemCount = SHORT1FROMMR(pWnd->m_fnOldWndProc(hWnd, ulMsg, wParam, lParam)); | |
1546 | ||
1547 | rc = MRFROMSHORT(uItemCount); | |
1548 | } | |
1549 | break; | |
1550 | ||
1551 | case WM_FORMATFRAME: | |
1552 | ///////////////////////////////////////////////////////////////////////////////// | |
1553 | // Applications that subclass frame controls may find that the frame is already | |
1554 | // subclassed the number of frame controls is variable. | |
1555 | // The WM_FORMATFRAME and WM_QUERYFRAMECTLCOUNT messages must always be | |
1556 | // subclassed by calling the previous window procedure and modifying its result. | |
1557 | //////////////////////////////////////////////////////////////////////////////// | |
1558 | { | |
1559 | int nItemCount; | |
1560 | int i; | |
1561 | PSWP pSWP = NULL; | |
1562 | SWP vSwpStb; | |
1563 | RECTL vRectl; | |
1564 | RECTL vRstb; | |
1565 | int nHeight=0; | |
1566 | ||
1567 | pSWP = (PSWP)PVOIDFROMMP(wParam); | |
1568 | nItemCount = SHORT1FROMMR(pWnd->m_fnOldWndProc(hWnd, ulMsg, wParam, lParam)); | |
1569 | if(pWnd->m_frameStatusBar) | |
1570 | { | |
1571 | ::WinQueryWindowRect(pWnd->m_frameStatusBar->GetHWND(), &vRstb); | |
1572 | pWnd->m_frameStatusBar->GetSize(NULL, &nHeight); | |
1573 | ::WinQueryWindowRect(pWnd->m_hFrame, &vRectl); | |
1574 | ::WinMapWindowPoints(pWnd->m_hFrame, HWND_DESKTOP, (PPOINTL)&vRectl, 2); | |
1575 | vRstb = vRectl; | |
1576 | ::WinCalcFrameRect(pWnd->m_hFrame, &vRectl, TRUE); | |
1577 | ||
1578 | vSwpStb.x = vRectl.xLeft - vRstb.xLeft; | |
1579 | vSwpStb.y = vRectl.yBottom - vRstb.yBottom; | |
1580 | vSwpStb.cx = vRectl.xRight - vRectl.xLeft - 1; //?? -1 ?? | |
1581 | vSwpStb.cy = nHeight; | |
1582 | vSwpStb.fl = SWP_SIZE |SWP_MOVE | SWP_SHOW; | |
1583 | vSwpStb.hwnd = pWnd->m_frameStatusBar->GetHWND(); | |
1584 | vSwpStb.hwndInsertBehind = HWND_TOP; | |
1585 | } | |
1586 | ::WinQueryWindowRect(pWnd->m_hFrame, &vRectl); | |
1587 | ::WinMapWindowPoints(pWnd->m_hFrame, HWND_DESKTOP, (PPOINTL)&vRectl, 2); | |
1588 | ::WinCalcFrameRect(pWnd->m_hFrame, &vRectl, TRUE); | |
1589 | ::WinMapWindowPoints(HWND_DESKTOP, pWnd->m_hFrame, (PPOINTL)&vRectl, 2); | |
1590 | for(i = 0; i < nItemCount; i++) | |
1591 | { | |
1592 | if(pWnd->m_hWnd && pSWP[i].hwnd == pWnd->m_hWnd) | |
1593 | { | |
1594 | pSWP[i].x = vRectl.xLeft; | |
1595 | pSWP[i].y = vRectl.yBottom + nHeight; | |
1596 | pSWP[i].cx = vRectl.xRight - vRectl.xLeft; | |
1597 | pSWP[i].cy = vRectl.yTop - vRectl.yBottom - nHeight; | |
1598 | pSWP[i].fl = SWP_SIZE | SWP_MOVE | SWP_SHOW; | |
1599 | pSWP[i].hwndInsertBehind = HWND_TOP; | |
1600 | } | |
1601 | } | |
1602 | bProcessed = TRUE; | |
1603 | rc = MRFROMSHORT(nItemCount); | |
1604 | } | |
1605 | break; | |
1606 | ||
1607 | default: | |
1608 | if(pWnd && pWnd->m_fnOldWndProc) | |
1609 | rc = pWnd->m_fnOldWndProc(hWnd, ulMsg, wParam, lParam); | |
1610 | else | |
1611 | rc = ::WinDefWindowProc(hWnd, ulMsg, wParam, lParam); | |
1612 | } | |
1613 | return rc; | |
1614 | } // end of wxFrameMainWndProc | |
1615 | ||
1616 | MRESULT EXPENTRY wxFrameWndProc( | |
1617 | HWND hWnd | |
1618 | , ULONG ulMsg | |
1619 | , MPARAM wParam | |
1620 | , MPARAM lParam | |
1621 | ) | |
1622 | { | |
1623 | // | |
1624 | // Trace all ulMsgs - useful for the debugging | |
1625 | // | |
1626 | HWND parentHwnd; | |
1627 | wxFrame* pWnd = NULL; | |
1628 | ||
1629 | parentHwnd = WinQueryWindow(hWnd,QW_PARENT); | |
1630 | pWnd = (wxFrame*) wxFindWinFromHandle((WXHWND) hWnd); | |
1631 | ||
1632 | // | |
1633 | // When we get the first message for the HWND we just created, we associate | |
1634 | // it with wxWindow stored in wxWndHook | |
1635 | // | |
51c1d535 DW |
1636 | |
1637 | MRESULT rc = (MRESULT)0; | |
1638 | bool bProcessed = FALSE; | |
1639 | ||
1640 | // | |
1641 | // Stop right here if we don't have a valid handle in our wxWindow object. | |
1642 | // | |
1643 | if (pWnd && !pWnd->GetHWND()) | |
1644 | { | |
1645 | pWnd->SetHWND((WXHWND) hWnd); | |
1646 | rc = pWnd->OS2DefWindowProc(ulMsg, wParam, lParam ); | |
1647 | pWnd->SetHWND(0); | |
1648 | } | |
1649 | else | |
1650 | { | |
d08f23a7 DW |
1651 | if (pWnd) |
1652 | rc = pWnd->OS2WindowProc(ulMsg, wParam, lParam); | |
1653 | else | |
1654 | rc = ::WinDefWindowProc(hWnd, ulMsg, wParam, lParam); | |
51c1d535 DW |
1655 | } |
1656 | return rc; | |
1657 | } // end of wxFrameWndProc | |
21802234 | 1658 | |
0367c1c0 | 1659 | MRESULT wxFrameOS2::OS2WindowProc( |
a885d89a DW |
1660 | WXUINT uMessage |
1661 | , WXWPARAM wParam | |
1662 | , WXLPARAM lParam | |
1663 | ) | |
21802234 | 1664 | { |
a885d89a DW |
1665 | MRESULT mRc = 0L; |
1666 | bool bProcessed = FALSE; | |
21802234 | 1667 | |
a885d89a | 1668 | switch (uMessage) |
21802234 DW |
1669 | { |
1670 | case WM_CLOSE: | |
a885d89a DW |
1671 | // |
1672 | // If we can't close, tell the system that we processed the | |
21802234 | 1673 | // message - otherwise it would close us |
a885d89a DW |
1674 | // |
1675 | bProcessed = !Close(); | |
21802234 DW |
1676 | break; |
1677 | ||
d08f23a7 | 1678 | case WM_PAINT: |
8d854fa9 DW |
1679 | bProcessed = HandlePaint(); |
1680 | mRc = (MRESULT)FALSE; | |
1681 | break; | |
d08f23a7 | 1682 | |
8d854fa9 DW |
1683 | case WM_ERASEBACKGROUND: |
1684 | // | |
1685 | // Returning TRUE to requests PM to paint the window background | |
1686 | // in SYSCLR_WINDOW. We capture this here because the PS returned | |
1687 | // in Frames is the PS for the whole frame, which we can't really | |
1688 | // use at all. If you want to paint a different background, do it | |
1689 | // in an OnPaint using a wxPaintDC. | |
1690 | // | |
1691 | mRc = (MRESULT)(TRUE); | |
d08f23a7 DW |
1692 | break; |
1693 | ||
8d854fa9 | 1694 | case WM_COMMAND: |
21802234 | 1695 | { |
a885d89a DW |
1696 | WORD wId; |
1697 | WORD wCmd; | |
1698 | WXHWND hWnd; | |
1699 | ||
1700 | UnpackCommand( (WXWPARAM)wParam | |
d08f23a7 DW |
1701 | ,(WXLPARAM)lParam |
1702 | ,&wId | |
1703 | ,&hWnd | |
1704 | ,&wCmd | |
1705 | ); | |
5b3ed311 | 1706 | |
a885d89a DW |
1707 | bProcessed = HandleCommand( wId |
1708 | ,wCmd | |
1709 | ,(WXHWND)hWnd | |
1710 | ); | |
21802234 DW |
1711 | } |
1712 | break; | |
1713 | ||
1714 | case WM_MENUSELECT: | |
1715 | { | |
a885d89a DW |
1716 | WXWORD wItem; |
1717 | WXWORD wFlags; | |
1718 | WXHMENU hMenu; | |
1719 | ||
1720 | UnpackMenuSelect( wParam | |
1721 | ,lParam | |
1722 | ,&wItem | |
1723 | ,&wFlags | |
1724 | ,&hMenu | |
1725 | ); | |
1726 | bProcessed = HandleMenuSelect( wItem | |
1727 | ,wFlags | |
1728 | ,hMenu | |
1729 | ); | |
e604d44b | 1730 | mRc = (MRESULT)TRUE; |
21802234 DW |
1731 | } |
1732 | break; | |
1733 | ||
d08f23a7 DW |
1734 | case WM_SIZE: |
1735 | { | |
1736 | SHORT nScxold = SHORT1FROMMP(wParam); // Old horizontal size. | |
1737 | SHORT nScyold = SHORT2FROMMP(wParam); // Old vertical size. | |
1738 | SHORT nScxnew = SHORT1FROMMP(lParam); // New horizontal size. | |
1739 | SHORT nScynew = SHORT2FROMMP(lParam); // New vertical size. | |
1740 | ||
1741 | lParam = MRFROM2SHORT( nScxnew - 20 | |
1742 | ,nScynew - 30 | |
1743 | ); | |
1744 | } | |
1745 | bProcessed = HandleSize(LOWORD(lParam), HIWORD(lParam), (WXUINT)wParam); | |
1746 | mRc = (MRESULT)FALSE; | |
21802234 DW |
1747 | break; |
1748 | ||
a885d89a | 1749 | case CM_QUERYDRAGIMAGE: |
21802234 | 1750 | { |
a885d89a DW |
1751 | HPOINTER hIcon; |
1752 | ||
1753 | if (m_icon.Ok()) | |
e604d44b | 1754 | hIcon = (HPOINTER)::WinSendMsg(GetHWND(), WM_QUERYICON, 0L, 0L); |
a885d89a DW |
1755 | else |
1756 | hIcon = (HPOINTER)m_hDefaultIcon; | |
1757 | mRc = (MRESULT)hIcon; | |
1758 | bProcessed = mRc != 0; | |
21802234 DW |
1759 | } |
1760 | break; | |
21802234 | 1761 | } |
f38374d0 | 1762 | |
a885d89a DW |
1763 | if (!bProcessed ) |
1764 | mRc = wxWindow::OS2WindowProc( uMessage | |
1765 | ,wParam | |
1766 | ,lParam | |
1767 | ); | |
e604d44b | 1768 | return (MRESULT)mRc; |
0367c1c0 | 1769 | } // wxFrameOS2::OS2WindowProc |
21802234 | 1770 | |
0367c1c0 | 1771 | void wxFrameOS2::SetClient(WXHWND c_Hwnd) |
5b3ed311 | 1772 | { |
51c1d535 | 1773 | // Duh...nothing to do under OS/2 |
5b3ed311 DW |
1774 | } |
1775 | ||
0367c1c0 | 1776 | void wxFrameOS2::SetClient( |
51c1d535 DW |
1777 | wxWindow* pWindow |
1778 | ) | |
5b3ed311 | 1779 | { |
51c1d535 DW |
1780 | wxWindow* pOldClient = this->GetClient(); |
1781 | bool bClientHasFocus = pOldClient && (pOldClient == wxWindow::FindFocus()); | |
5b3ed311 | 1782 | |
51c1d535 | 1783 | if(pOldClient == pWindow) // nothing to do |
5b3ed311 | 1784 | return; |
51c1d535 DW |
1785 | if(pWindow == NULL) // just need to remove old client |
1786 | { | |
1787 | if(pOldClient == NULL) // nothing to do | |
1788 | return; | |
5b3ed311 | 1789 | |
51c1d535 | 1790 | if(bClientHasFocus ) |
5b3ed311 DW |
1791 | this->SetFocus(); |
1792 | ||
51c1d535 DW |
1793 | pOldClient->Enable( FALSE ); |
1794 | pOldClient->Show( FALSE ); | |
1795 | ::WinSetWindowUShort(pOldClient->GetHWND(), QWS_ID, (USHORT)pOldClient->GetId()); | |
5b3ed311 | 1796 | // to avoid OS/2 bug need to update frame |
b7084589 | 1797 | ::WinSendMsg((HWND)this->GetFrame(), WM_UPDATEFRAME, (MPARAM)~0, 0); |
5b3ed311 | 1798 | return; |
51c1d535 | 1799 | } |
5b3ed311 | 1800 | |
51c1d535 DW |
1801 | // |
1802 | // Else need to change client | |
1803 | // | |
1804 | if(bClientHasFocus) | |
5b3ed311 DW |
1805 | this->SetFocus(); |
1806 | ||
51c1d535 DW |
1807 | ::WinEnableWindowUpdate((HWND)GetHWND(), FALSE); |
1808 | if(pOldClient) | |
1809 | { | |
1810 | pOldClient->Enable(FALSE); | |
1811 | pOldClient->Show(FALSE); | |
1812 | ::WinSetWindowUShort(pOldClient->GetHWND(), QWS_ID, (USHORT)pOldClient->GetId()); | |
1813 | } | |
1814 | pWindow->Reparent(this); | |
1815 | ::WinSetWindowUShort(pWindow->GetHWND(), QWS_ID, FID_CLIENT); | |
1816 | ::WinEnableWindowUpdate((HWND)GetHWND(), TRUE); | |
1817 | pWindow->Enable(); | |
1818 | pWindow->Show(); // ensure client is showing | |
1819 | if( this->IsShown() ) | |
1820 | { | |
1821 | this->Show(); | |
b7084589 | 1822 | ::WinSendMsg(m_hFrame, WM_UPDATEFRAME, (MPARAM)~0, 0); |
51c1d535 | 1823 | } |
5b3ed311 DW |
1824 | } |
1825 | ||
0367c1c0 | 1826 | wxWindow* wxFrameOS2::GetClient() |
5b3ed311 | 1827 | { |
b7084589 | 1828 | return wxFindWinFromHandle((WXHWND)::WinWindowFromID(m_hFrame, FID_CLIENT)); |
5b3ed311 | 1829 | } |