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