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