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