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