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