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