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