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