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