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