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