]> git.saurik.com Git - wxWidgets.git/blame - src/os2/frame.cpp
no message
[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;
256 RECT 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
a885d89a
DW
588//
589// Frame window
590//
591bool wxFrame::OS2Create(
592 int nId
593, wxWindow* pParent
594, const wxChar* zWclass
595, wxWindow* pWxWin
596, const wxChar* zTitle
597, int nX
598, int nY
599, int nWidth
600, int nHeight
601, long ulStyle
602)
21802234 603{
a885d89a
DW
604 ULONG ulPmFlags = 0;
605 ULONG ulExtraFlags = 0;
606 ULONG ulTempFlags = FCF_TITLEBAR |
607 FCF_SYSMENU |
608 FCF_MINBUTTON |
609 FCF_MAXBUTTON |
610 FCF_SIZEBORDER |
611 FCF_ICON |
612 FCF_MENU |
613 FCF_ACCELTABLE |
614 FCF_SHELLPOSITION |
615 FCF_TASKLIST;
616
617 m_hDefaultIcon = (WXHICON) (wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON : wxDEFAULT_FRAME_ICON);
618
619 if ((ulStyle & wxCAPTION) == wxCAPTION)
620 ulPmFlags = FCF_TASKLIST;
621 else
622 ulPmFlags = FCF_NOMOVEWITHOWNER;
623
624 if (ulStyle & wxMINIMIZE_BOX)
625 ulPmFlags |= FCF_MINBUTTON;
626 if (ulStyle & wxMAXIMIZE_BOX)
627 ulPmFlags |= FCF_MAXBUTTON;
628 if (ulStyle & wxTHICK_FRAME)
629 ulPmFlags |= FCF_DLGBORDER;
630 if (ulStyle & wxSYSTEM_MENU)
631 ulPmFlags |= FCF_SYSMENU;
632 if ((ulStyle & wxMINIMIZE) || (ulStyle & wxICONIZE))
633 ulPmFlags |= WS_MINIMIZED;
634 if (ulStyle & wxMAXIMIZE)
635 ulPmFlags |= WS_MAXIMIZED;
636 if (ulStyle & wxCAPTION)
637 ulPmFlags |= FCF_TASKLIST;
638 if (ulStyle & wxCLIP_CHILDREN)
639 {
640 // Invalid for frame windows under PM
641 }
642
643 //
644 // Keep this in wxFrame because it saves recoding this function
645 // in wxTinyFrame
646 //
21802234 647#if wxUSE_ITSY_BITSY
a885d89a
DW
648 if (ulStyle & wxTINY_CAPTION_VERT)
649 ulExtraFlags |= kVertCaption;
650 if (ulStyle & wxTINY_CAPTION_HORIZ)
651 ulExtraFlags |= kHorzCaption;
21802234 652#else
a885d89a
DW
653 if (ulStyle & wxTINY_CAPTION_VERT)
654 ulPmFlags |= FCF_TASKLIST;
655 if (ulStyle & wxTINY_CAPTION_HORIZ)
656 ulPmFlags |= FCF_TASKLIST;
21802234 657#endif
a885d89a
DW
658 if ((ulStyle & wxTHICK_FRAME) == 0)
659 ulPmFlags |= FCF_BORDER;
660 if (ulStyle & wxFRAME_TOOL_WINDOW)
661 ulExtraFlags = kFrameToolWindow;
21802234 662
a885d89a
DW
663 if (ulStyle & wxSTAY_ON_TOP)
664 ulPmFlags |= FCF_SYSMODAL;
21802234 665
a885d89a
DW
666 if (ulPmFlags & ulTempFlags)
667 ulPmFlags = FCF_STANDARD;
668 //
669 // Clear the visible flag, we always call show
670 //
671 ulPmFlags &= (unsigned long)~WS_VISIBLE;
672 m_bIconized = FALSE;
673 if ( !wxWindow::OS2Create( nId
674 ,pParent
675 ,zWclass
676 ,pWxWin
677 ,zTitle
678 ,nX
679 ,nY
680 ,nWidth
681 ,nHeight
682 ,ulPmFlags
683 ,NULL
684 ,ulExtraFlags))
685 {
686 return FALSE;
687 }
688 return TRUE;
689} // end of wxFrame::OS2Create
0e320a79 690
a885d89a 691//
0e320a79
DW
692// Default activation behaviour - set the focus for the first child
693// subwindow found.
a885d89a
DW
694//
695void wxFrame::OnActivate(
696 wxActivateEvent& rEvent
697)
0e320a79 698{
a885d89a
DW
699 for (wxWindowList::Node* pNode = GetChildren().GetFirst();
700 pNode;
701 pNode = pNode->GetNext())
0e320a79 702 {
21802234
DW
703 // FIXME all this is totally bogus - we need to do the same as wxPanel,
704 // but how to do it without duplicating the code?
705
706 // restore focus
a885d89a 707 wxWindow* pChild = pNode->GetData();
21802234 708
a885d89a 709 if (!pChild->IsTopLevel()
21802234 710#if wxUSE_TOOLBAR
a885d89a 711 && !wxDynamicCast(pChild, wxToolBar)
21802234
DW
712#endif // wxUSE_TOOLBAR
713#if wxUSE_STATUSBAR
a885d89a 714 && !wxDynamicCast(pChild, wxStatusBar)
21802234
DW
715#endif // wxUSE_STATUSBAR
716 )
717 {
a885d89a 718 pChild->SetFocus();
21802234
DW
719 return;
720 }
0e320a79 721 }
a885d89a 722} // end of wxFrame::OnActivate
0e320a79 723
f38374d0
DW
724// ----------------------------------------------------------------------------
725// wxFrame size management: we exclude the areas taken by menu/status/toolbars
726// from the client area, so the client area is what's really available for the
727// frame contents
728// ----------------------------------------------------------------------------
0e320a79
DW
729
730// Checks if there is a toolbar, and returns the first free client position
731wxPoint wxFrame::GetClientAreaOrigin() const
732{
a885d89a
DW
733 wxPoint vPoint(0, 0);
734
0e320a79
DW
735 if (GetToolBar())
736 {
a885d89a
DW
737 int nWidth;
738 int nHeight;
739
740 GetToolBar()->GetSize( &nWidth
741 ,&nHeight
742 );
0e320a79
DW
743
744 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
745 {
a885d89a 746 vPoint.x += nWidth;
0e320a79
DW
747 }
748 else
749 {
a885d89a
DW
750 // PM is backwards from windows
751 vPoint.y += nHeight;
0e320a79
DW
752 }
753 }
a885d89a
DW
754 return vPoint;
755} // end of wxFrame::GetClientAreaOrigin
0e320a79 756
f38374d0
DW
757// ----------------------------------------------------------------------------
758// tool/status bar stuff
759// ----------------------------------------------------------------------------
760
21802234 761#if wxUSE_TOOLBAR
f38374d0 762
a885d89a
DW
763wxToolBar* wxFrame::CreateToolBar(
764 long lStyle
765, wxWindowID vId
766, const wxString& rName
767)
0e320a79 768{
a885d89a
DW
769 if (wxFrameBase::CreateToolBar( lStyle
770 ,vId
771 ,rName
772 ))
0e320a79 773 {
0e320a79 774 PositionToolBar();
0e320a79 775 }
f38374d0 776 return m_frameToolBar;
a885d89a 777} // end of wxFrame::CreateToolBar
0e320a79
DW
778
779void wxFrame::PositionToolBar()
780{
a885d89a
DW
781 HWND hWndClient;
782 RECTL vRect;
783
784 hWndClient = ::WinWindowFromID(GetHwnd(), FID_CLIENT);
785 ::WinQueryWindowRect(hWndClient, &vRect);
0e320a79 786
f38374d0 787#if wxUSE_STATUSBAR
a885d89a 788 if (GetStatusBar())
0e320a79 789 {
a885d89a
DW
790 int nStatusX;
791 int nStatusY;
792
793 GetStatusBar()->GetClientSize( &nStatusX
794 ,&nStatusY
795 );
796 // PM is backwards from windows
797 vRect.yBottom += nStatusY;
0e320a79 798 }
f38374d0 799#endif // wxUSE_STATUSBAR
0e320a79 800
f38374d0 801 if ( GetToolBar() )
0e320a79 802 {
a885d89a
DW
803 int nToolbarWidth;
804 int nToolbarHeight;
805
806 GetToolBar()->GetSize( &nToolbarWidth
807 ,&nToolbarHeight
808 );
0e320a79 809
a885d89a 810 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
0e320a79 811 {
a885d89a 812 nToolbarHeight = vRect.yBottom;
0e320a79
DW
813 }
814 else
815 {
a885d89a 816 nToolbarWidth = vRect.xRight;
21802234 817 }
f38374d0 818
a885d89a
DW
819 //
820 // Use the 'real' PM position here
821 //
822 GetToolBar()->SetSize( 0
823 ,0
824 ,nToolbarWidth
825 ,nToolbarHeight
826 ,wxSIZE_NO_ADJUSTMENTS
827 );
21802234 828 }
a885d89a 829} // end of wxFrame::PositionToolBar
21802234
DW
830#endif // wxUSE_TOOLBAR
831
f38374d0
DW
832// ----------------------------------------------------------------------------
833// frame state (iconized/maximized/...)
834// ----------------------------------------------------------------------------
835
a885d89a 836//
21802234
DW
837// propagate our state change to all child frames: this allows us to emulate X
838// Windows behaviour where child frames float independently of the parent one
839// on the desktop, but are iconized/restored with it
a885d89a
DW
840//
841void wxFrame::IconizeChildFrames(
842 bool bIconize
843)
21802234 844{
a885d89a
DW
845 for (wxWindowList::Node* pNode = GetChildren().GetFirst();
846 pNode;
847 pNode = pNode->GetNext() )
21802234 848 {
a885d89a 849 wxWindow* pWin = pNode->GetData();
21802234 850
a885d89a 851 if (pWin->IsKindOf(CLASSINFO(wxFrame)) )
21802234 852 {
a885d89a 853 ((wxFrame *)pWin)->Iconize(bIconize);
0e320a79
DW
854 }
855 }
a885d89a 856} // end of wxFrame::IconizeChildFrames
0e320a79 857
21802234
DW
858// ===========================================================================
859// message processing
860// ===========================================================================
861
862// ---------------------------------------------------------------------------
863// preprocessing
864// ---------------------------------------------------------------------------
a885d89a
DW
865bool wxFrame::OS2TranslateMessage(
866 WXMSG* pMsg
867)
21802234 868{
a885d89a 869 if (wxWindow::OS2TranslateMessage(pMsg))
29435d81 870 return TRUE;
a885d89a 871 //
21802234 872 // try the menu bar accels
a885d89a
DW
873 //
874 wxMenuBar* pMenuBar = GetMenuBar();
875
876 if (!pMenuBar )
21802234
DW
877 return FALSE;
878
a885d89a
DW
879 const wxAcceleratorTable& rAcceleratorTable = pMenuBar->GetAccelTable();
880 return rAcceleratorTable.Translate(this, pMsg);
881} // end of wxFrame::OS2TranslateMessage
21802234
DW
882
883// ---------------------------------------------------------------------------
884// our private (non virtual) message handlers
885// ---------------------------------------------------------------------------
21802234
DW
886bool wxFrame::HandlePaint()
887{
a885d89a
DW
888 RECTL vRect;
889
890 if (::WinQueryUpdateRect(GetHwnd(), &vRect))
29435d81 891 {
a885d89a 892 if (m_bIconized)
29435d81 893 {
a885d89a
DW
894 //
895 // Icons in PM are the same as "pointers"
896 //
897 HPOINTER hIcon;
29435d81 898
a885d89a
DW
899 if (m_icon.Ok())
900 hIcon = (HPOINTER)::WinSendMsg(GetHwnd(), WM_QUERYICON, 0L, 0L);
901 else
902 hIcon = (HPOINTER)m_hDefaultIcon;
903
904 //
21802234
DW
905 // Hold a pointer to the dc so long as the OnPaint() message
906 // is being processed
a885d89a
DW
907 //
908 RECTL vRect2;
909 HPS hPs = ::WinBeginPaint(GetHwnd(), NULLHANDLE, &vRect2);
29435d81 910
a885d89a 911 //
29435d81 912 // Erase background before painting or we get white background
a885d89a
DW
913 //
914 OS2DefWindowProc(WM_ERASEBACKGROUND, (MPARAM)hPs, (MPARAM)&vRect2);
29435d81 915
a885d89a 916 if (hIcon)
29435d81 917 {
a885d89a
DW
918 HWND hWndClient;
919 RECTL vRect3;
21802234 920
a885d89a
DW
921 hWndClient = ::WinWindowFromID(GetHwnd(), FID_CLIENT);
922 ::WinQueryWindowRect(hWndClient, &vRect3);
29435d81 923
a885d89a
DW
924 static const int nIconWidth = 32;
925 static const int nIconHeight = 32;
926 int nIconX = (int)((vRect3.xRight - nIconWidth)/2);
927 int nIconY = (int)((vRect3.yBottom + nIconHeight)/2);
29435d81 928
a885d89a 929 ::WinDrawPointer(hPs, nIconX, nIconY, hIcon, DP_NORMAL);
29435d81 930 }
a885d89a 931 ::WinEndPaint(hPs);
29435d81
DW
932 return TRUE;
933 }
934 else
935 {
936 return wxWindow::HandlePaint();
937 }
938 }
939 else
940 {
941 // nothing to paint - processed
942 return TRUE;
943 }
29435d81 944 return FALSE;
a885d89a 945} // end of wxFrame::HandlePaint
21802234 946
a885d89a
DW
947bool wxFrame::HandleSize(
948 int nX
949, int nY
950, WXUINT nId
951)
21802234 952{
a885d89a 953 bool bProcessed = FALSE;
21802234 954
a885d89a 955 switch (nId)
21802234 956 {
a885d89a
DW
957 case kSizeNormal:
958 //
959 // Only do it it if we were iconized before, otherwise resizing the
21802234
DW
960 // parent frame has a curious side effect of bringing it under it's
961 // children
a885d89a 962 if (!m_bIconized )
21802234
DW
963 break;
964
a885d89a 965 //
21802234 966 // restore all child frames too
a885d89a 967 //
21802234
DW
968 IconizeChildFrames(FALSE);
969
a885d89a 970 //
21802234 971 // fall through
a885d89a 972 //
21802234 973
a885d89a
DW
974 case kSizeMax:
975 m_bIconized = FALSE;
21802234
DW
976 break;
977
a885d89a
DW
978 case kSizeMin:
979 //
980 // Iconize all child frames too
981 //
21802234 982 IconizeChildFrames(TRUE);
a885d89a 983 m_bIconized = TRUE;
21802234
DW
984 break;
985 }
f38374d0 986
a885d89a 987 if (!m_bIconized)
21802234 988 {
a885d89a 989 //
29435d81 990 // forward WM_SIZE to status bar control
a885d89a 991 //
f38374d0
DW
992#if wxUSE_NATIVE_STATUSBAR
993 if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)))
994 {
a885d89a
DW
995 wxSizeEvent vEvent( wxSize( nX
996 ,nY
997 )
998 ,m_frameStatusBar->GetId()
999 );
f38374d0 1000
a885d89a
DW
1001 vEvent.SetEventObject(m_frameStatusBar);
1002 m_frameStatusBar->OnSize(vEvent);
f38374d0
DW
1003 }
1004#endif // wxUSE_NATIVE_STATUSBAR
1005
21802234
DW
1006 PositionStatusBar();
1007 PositionToolBar();
a885d89a
DW
1008 wxSizeEvent vEvent( wxSize( nX
1009 ,nY
1010 )
1011 ,m_windowId
1012 );
21802234 1013
a885d89a
DW
1014 vEvent.SetEventObject(this);
1015 bProcessed = GetEventHandler()->ProcessEvent(vEvent);
21802234 1016 }
a885d89a
DW
1017 return bProcessed;
1018} // end of wxFrame::HandleSize
21802234 1019
a885d89a
DW
1020bool wxFrame::HandleCommand(
1021 WXWORD nId
1022, WXWORD nCmd
1023, WXHWND hControl
1024)
21802234 1025{
a885d89a 1026 if (hControl)
21802234 1027 {
a885d89a 1028 //
21802234 1029 // In case it's e.g. a toolbar.
a885d89a
DW
1030 //
1031 wxWindow* pWin = wxFindWinFromHandle(hControl);
1032
1033 if (pWin)
1034 return pWin->OS2Command( nCmd
1035 ,nId
1036 );
21802234
DW
1037 }
1038
a885d89a
DW
1039 //
1040 // Handle here commands from menus and accelerators
1041 //
1042 if (nCmd == 0 || nCmd == 1)
21802234 1043 {
a885d89a 1044 if (wxCurrentPopupMenu)
21802234 1045 {
a885d89a
DW
1046 wxMenu* pPopupMenu = wxCurrentPopupMenu;
1047
21802234
DW
1048 wxCurrentPopupMenu = NULL;
1049
a885d89a
DW
1050 return pPopupMenu->OS2Command( nCmd
1051 ,nId
1052 );
21802234
DW
1053 }
1054
a885d89a 1055 if (ProcessCommand(nId))
21802234
DW
1056 {
1057 return TRUE;
1058 }
1059 }
21802234 1060 return FALSE;
a885d89a 1061} // end of wxFrame::HandleCommand
21802234 1062
a885d89a
DW
1063bool wxFrame::HandleMenuSelect(
1064 WXWORD nItem
1065, WXWORD nFlags
1066, WXHMENU hMenu
1067)
21802234 1068{
a885d89a
DW
1069 int nMenuItem;
1070
1071 if (nFlags == 0xFFFF && hMenu == 0)
21802234 1072 {
a885d89a
DW
1073 //
1074 // Menu was removed from screen
1075 //
1076 nMenuItem = -1;
21802234 1077 }
a885d89a 1078 else if (!(nFlags & MIS_SUBMENU) && !(nFlags & MIS_SEPARATOR))
21802234 1079 {
a885d89a 1080 nMenuItem = nItem;
21802234 1081 }
21802234
DW
1082 else
1083 {
a885d89a
DW
1084 //
1085 // Don't give hints for separators (doesn't make sense) nor for the
21802234 1086 // items opening popup menus (they don't have them anyhow)
a885d89a 1087 //
21802234
DW
1088 return FALSE;
1089 }
a885d89a 1090 wxMenuEvent vEvent(wxEVT_MENU_HIGHLIGHT, nMenuItem);
21802234 1091
a885d89a
DW
1092 vEvent.SetEventObject(this);
1093 return GetEventHandler()->ProcessEvent(vEvent);
1094} // end of wxFrame::HandleMenuSelect
21802234
DW
1095
1096// ---------------------------------------------------------------------------
1097// the window proc for wxFrame
1098// ---------------------------------------------------------------------------
1099
a885d89a
DW
1100MRESULT wxFrame::OS2WindowProc(
1101 WXUINT uMessage
1102, WXWPARAM wParam
1103, WXLPARAM lParam
1104)
21802234 1105{
a885d89a
DW
1106 MRESULT mRc = 0L;
1107 bool bProcessed = FALSE;
21802234 1108
a885d89a 1109 switch (uMessage)
21802234
DW
1110 {
1111 case WM_CLOSE:
a885d89a
DW
1112 //
1113 // If we can't close, tell the system that we processed the
21802234 1114 // message - otherwise it would close us
a885d89a
DW
1115 //
1116 bProcessed = !Close();
21802234
DW
1117 break;
1118
1119 case WM_COMMAND:
1120 {
a885d89a
DW
1121 WORD wId;
1122 WORD wCmd;
1123 WXHWND hWnd;
1124
1125 UnpackCommand( (WXWPARAM)wParam
1126 ,(WXLPARAM)lParam
1127 ,&wId
1128 ,&hWnd
1129 ,&wCmd
1130 );
1131 bProcessed = HandleCommand( wId
1132 ,wCmd
1133 ,(WXHWND)hWnd
1134 );
21802234
DW
1135 }
1136 break;
1137
1138 case WM_MENUSELECT:
1139 {
a885d89a
DW
1140 WXWORD wItem;
1141 WXWORD wFlags;
1142 WXHMENU hMenu;
1143
1144 UnpackMenuSelect( wParam
1145 ,lParam
1146 ,&wItem
1147 ,&wFlags
1148 ,&hMenu
1149 );
1150 bProcessed = HandleMenuSelect( wItem
1151 ,wFlags
1152 ,hMenu
1153 );
21802234
DW
1154 }
1155 break;
1156
1157 case WM_PAINT:
a885d89a 1158 bProcessed = HandlePaint();
21802234
DW
1159 break;
1160
a885d89a 1161 case CM_QUERYDRAGIMAGE:
21802234 1162 {
a885d89a
DW
1163 HPOINTER hIcon;
1164
1165 if (m_icon.Ok())
1166 hIcon = (HPOINTER)::WinSendMsg(GetHwnd(), WM_QUERYICON, 0L, 0L);
1167 else
1168 hIcon = (HPOINTER)m_hDefaultIcon;
1169 mRc = (MRESULT)hIcon;
1170 bProcessed = mRc != 0;
21802234
DW
1171 }
1172 break;
1173
1174 case WM_SIZE:
a885d89a 1175 bProcessed = HandleSize(LOWORD(lParam), HIWORD(lParam), (WXUINT)wParam);
21802234
DW
1176 break;
1177 }
f38374d0 1178
a885d89a
DW
1179 if (!bProcessed )
1180 mRc = wxWindow::OS2WindowProc( uMessage
1181 ,wParam
1182 ,lParam
1183 );
f38374d0 1184 return (MRESULT)0;
a885d89a 1185} // wxFrame::OS2WindowProc
21802234 1186