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