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