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