]> git.saurik.com Git - wxWidgets.git/blame - src/os2/frame.cpp
cleanup image after application
[wxWidgets.git] / src / os2 / frame.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: frame.cpp
0d53fc34 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
65571936 9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
21802234
DW
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifndef WX_PRECOMP
51c1d535
DW
16 #include "wx/defs.h"
17 #include "wx/object.h"
18 #include "wx/dynarray.h"
19 #include "wx/list.h"
20 #include "wx/hash.h"
21 #include "wx/string.h"
22 #include "wx/intl.h"
23 #include "wx/log.h"
24 #include "wx/event.h"
21802234
DW
25 #include "wx/setup.h"
26 #include "wx/frame.h"
27 #include "wx/menu.h"
28 #include "wx/app.h"
29 #include "wx/utils.h"
30 #include "wx/dialog.h"
31 #include "wx/settings.h"
32 #include "wx/dcclient.h"
2aa60728 33 #include "wx/mdi.h"
21802234
DW
34#endif // WX_PRECOMP
35
36#include "wx/os2/private.h"
f38374d0
DW
37
38#if wxUSE_STATUSBAR
39 #include "wx/statusbr.h"
ea51d98d 40 #include "wx/generic/statusbr.h"
f38374d0
DW
41#endif // wxUSE_STATUSBAR
42
43#if wxUSE_TOOLBAR
44 #include "wx/toolbar.h"
45#endif // wxUSE_TOOLBAR
46
0e320a79 47#include "wx/menuitem.h"
21802234 48#include "wx/log.h"
0e320a79 49
f38374d0
DW
50// ----------------------------------------------------------------------------
51// globals
52// ----------------------------------------------------------------------------
53
21802234
DW
54extern wxWindowList wxModelessWindows;
55extern wxList WXDLLEXPORT wxPendingDelete;
19193a2c
KB
56
57#if wxUSE_MENUS_NATIVE
21802234 58extern wxMenu *wxCurrentPopupMenu;
19193a2c 59#endif
0e320a79 60
19193a2c
KB
61extern void wxAssociateWinWithHandle( HWND hWnd
62 ,wxWindowOS2* pWin
b7084589 63 );
51c1d535 64
f38374d0
DW
65// ----------------------------------------------------------------------------
66// event tables
67// ----------------------------------------------------------------------------
68
0d53fc34 69BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
0d53fc34 70 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
0e320a79
DW
71END_EVENT_TABLE()
72
8d7ddd02 73IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow)
0e320a79 74
f38374d0
DW
75// ============================================================================
76// implementation
77// ============================================================================
0e320a79 78
f38374d0
DW
79// ----------------------------------------------------------------------------
80// static class members
81// ----------------------------------------------------------------------------
7e99520b 82#if wxUSE_STATUSBAR
0e320a79 83
f38374d0 84#if wxUSE_NATIVE_STATUSBAR
0d53fc34 85 bool wxFrame::m_bUseNativeStatusBar = TRUE;
f38374d0 86#else
0d53fc34 87 bool wxFrame::m_bUseNativeStatusBar = FALSE;
f38374d0 88#endif
0e320a79 89
7e99520b
DW
90#endif //wxUSE_STATUSBAR
91
f38374d0
DW
92// ----------------------------------------------------------------------------
93// creation/destruction
94// ----------------------------------------------------------------------------
95
0d53fc34 96void wxFrame::Init()
0e320a79 97{
ea51d98d
DW
98 m_nFsStatusBarFields = 0;
99 m_nFsStatusBarHeight = 0;
100 m_nFsToolBarHeight = 0;
5d44b24e 101 m_hWndToolTip = 0L;
0cf6acbf 102 m_bWasMinimized = FALSE;
5d44b24e
DW
103
104
105 m_frameMenuBar = NULL;
106 m_frameToolBar = NULL;
107 m_frameStatusBar = NULL;
40bd6154 108
5d44b24e
DW
109 m_hTitleBar = NULLHANDLE;
110 m_hHScroll = NULLHANDLE;
111 m_hVScroll = NULLHANDLE;
51c1d535 112
40bd6154
DW
113 //
114 // Initialize SWP's
115 //
40bd6154
DW
116 memset(&m_vSwpTitleBar, 0, sizeof(SWP));
117 memset(&m_vSwpMenuBar, 0, sizeof(SWP));
118 memset(&m_vSwpHScroll, 0, sizeof(SWP));
119 memset(&m_vSwpVScroll, 0, sizeof(SWP));
120 memset(&m_vSwpStatusBar, 0, sizeof(SWP));
121 memset(&m_vSwpToolBar, 0, sizeof(SWP));
5d44b24e
DW
122 m_bIconized = FALSE;
123
0d53fc34 124} // end of wxFrame::Init
ea51d98d 125
0d53fc34 126bool wxFrame::Create(
ea51d98d
DW
127 wxWindow* pParent
128, wxWindowID vId
129, const wxString& rsTitle
130, const wxPoint& rPos
131, const wxSize& rSize
5d44b24e 132, long lStyle
ea51d98d
DW
133, const wxString& rsName
134)
f38374d0 135{
5d44b24e
DW
136 if (!wxTopLevelWindow::Create( pParent
137 ,vId
138 ,rsTitle
139 ,rPos
140 ,rSize
141 ,lStyle
142 ,rsName
143 ))
144 return FALSE;
5d44b24e
DW
145 wxModelessWindows.Append(this);
146 return TRUE;
0d53fc34 147} // end of wxFrame::Create
0e320a79 148
0d53fc34 149wxFrame::~wxFrame()
0e320a79 150{
ea51d98d 151 m_isBeingDeleted = TRUE;
ea51d98d 152 DeleteAllBars();
0d53fc34 153} // end of wxFrame::~wxFrame
0e320a79 154
ea51d98d 155//
0e320a79 156// Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
ea51d98d 157//
0d53fc34 158void wxFrame::DoGetClientSize(
80d83cbc
DW
159 int* pX
160, int* pY
161) const
0e320a79 162{
5d44b24e
DW
163 wxTopLevelWindow::DoGetClientSize( pX
164 ,pY
165 );
5fb9d2be
DW
166 //
167 // No need to use statusbar code as in WIN32 as the FORMATFRAME
168 // window procedure ensures PM knows about the new frame client
5d44b24e
DW
169 // size internally. A ::WinQueryWindowRect (that is called in
170 // wxWindow's GetClient size from above) is all that is needed!
5fb9d2be 171 //
0d53fc34 172} // end of wxFrame::DoGetClientSize
0e320a79 173
a885d89a 174//
0e320a79 175// Set the client size (i.e. leave the calculation of borders etc.
77ffb593 176// to wxWidgets)
80d83cbc 177//
0d53fc34 178void wxFrame::DoSetClientSize(
80d83cbc
DW
179 int nWidth
180, int nHeight
181)
0e320a79 182{
80d83cbc 183 //
5d44b24e
DW
184 // Statusbars are not part of the OS/2 Client but parent frame
185 // so no statusbar consideration
80d83cbc 186 //
5d44b24e
DW
187 wxTopLevelWindow::DoSetClientSize( nWidth
188 ,nHeight
189 );
0d53fc34 190} // end of wxFrame::DoSetClientSize
80d83cbc 191
f38374d0 192// ----------------------------------------------------------------------------
5d44b24e 193// wxFrame: various geometry-related functions
f38374d0
DW
194// ----------------------------------------------------------------------------
195
5d44b24e 196void wxFrame::Raise()
0e320a79 197{
5d44b24e
DW
198 wxFrameBase::Raise();
199 ::WinSetWindowPos( (HWND) GetParent()->GetHWND()
200 ,HWND_TOP
201 ,0
202 ,0
203 ,0
204 ,0
205 ,SWP_ZORDER
206 );
207}
21802234 208
21802234 209#if wxUSE_STATUSBAR
0d53fc34 210wxStatusBar* wxFrame::OnCreateStatusBar(
0fe536e3 211 int nNumber
a885d89a 212, long lulStyle
0fe536e3
DW
213, wxWindowID vId
214, const wxString& rName
215)
0e320a79 216{
0fe536e3 217 wxStatusBar* pStatusBar = NULL;
f6bcfd97 218 wxString sError;
0e320a79 219
0fe536e3 220 pStatusBar = wxFrameBase::OnCreateStatusBar( nNumber
a885d89a 221 ,lulStyle
0fe536e3
DW
222 ,vId
223 ,rName
5b3ed311
DW
224 );
225
226 if( !pStatusBar )
f6bcfd97 227 return NULL;
f6bcfd97 228
54ffa107
DW
229 wxClientDC vDC(pStatusBar);
230 int nY;
231
232 //
233 // Set the height according to the font and the border size
234 //
235 vDC.SetFont(pStatusBar->GetFont()); // Screws up the menues for some reason
236 vDC.GetTextExtent( "X"
237 ,NULL
238 ,&nY
239 );
240
241 int nHeight = ((11 * nY) / 10 + 2 * pStatusBar->GetBorderY());
242
243 pStatusBar->SetSize( -1
244 ,-1
245 ,-1
246 ,nHeight
247 );
248
51c1d535
DW
249 ::WinSetParent( pStatusBar->GetHWND()
250 ,m_hFrame
251 ,FALSE
252 );
253 ::WinSetOwner( pStatusBar->GetHWND()
254 ,m_hFrame
255 );
7e99520b 256 //
5b3ed311 257 // to show statusbar
f6bcfd97 258 //
51c1d535
DW
259 if(::WinIsWindowShowing(m_hFrame))
260 ::WinSendMsg(m_hFrame, WM_UPDATEFRAME, (MPARAM)~0, 0);
7e99520b 261
0fe536e3 262 return pStatusBar;
0d53fc34 263} // end of wxFrame::OnCreateStatusBar
0e320a79 264
0d53fc34 265void wxFrame::PositionStatusBar()
0e320a79 266{
f6bcfd97
BP
267 SWP vSwp;
268 ERRORID vError;
269 wxString sError;
270
0fe536e3
DW
271 //
272 // Native status bar positions itself
273 //
274 if (m_frameStatusBar)
f38374d0 275 {
a885d89a 276 int nWidth;
987da0d4 277 int nY;
a885d89a 278 int nStatbarWidth;
0fe536e3 279 int nStatbarHeight;
0fe536e3 280 RECTL vRect;
51c1d535 281 RECTL vFRect;
0fe536e3 282
51c1d535 283 ::WinQueryWindowRect(m_hFrame, &vRect);
987da0d4 284 nY = vRect.yTop;
51c1d535
DW
285 ::WinMapWindowPoints(m_hFrame, HWND_DESKTOP, (PPOINTL)&vRect, 2);
286 vFRect = vRect;
287 ::WinCalcFrameRect(m_hFrame, &vRect, TRUE);
0fe536e3 288 nWidth = vRect.xRight - vRect.xLeft;
987da0d4 289 nY = nY - (vRect.yBottom - vFRect.yBottom);
a885d89a 290
0fe536e3
DW
291 m_frameStatusBar->GetSize( &nStatbarWidth
292 ,&nStatbarHeight
293 );
f38374d0 294
987da0d4 295 nY= nY - nStatbarHeight;
0fe536e3 296 //
f38374d0
DW
297 // Since we wish the status bar to be directly under the client area,
298 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
0fe536e3 299 //
51c1d535 300 m_frameStatusBar->SetSize( vRect.xLeft - vFRect.xLeft
987da0d4 301 ,nY
0fe536e3
DW
302 ,nWidth
303 ,nStatbarHeight
304 );
f6bcfd97
BP
305 if (!::WinQueryWindowPos(m_frameStatusBar->GetHWND(), &vSwp))
306 {
307 vError = ::WinGetLastError(vHabmain);
308 sError = wxPMErrorToStr(vError);
283ed244 309 wxLogError("Error setting parent for StautsBar. Error: %s\n", sError.c_str());
f6bcfd97
BP
310 return;
311 }
f38374d0 312 }
0d53fc34 313} // end of wxFrame::PositionStatusBar
21802234 314#endif // wxUSE_STATUSBAR
0e320a79 315
d697657f
DW
316#if wxUSE_TOOLBAR
317wxToolBar* wxFrame::OnCreateToolBar(
318 long lStyle
319, wxWindowID vId
320, const wxString& rsName
321)
322{
323 wxToolBar* pToolBar = wxFrameBase::OnCreateToolBar( lStyle
324 ,vId
325 ,rsName
326 );
327
328 ::WinSetParent( pToolBar->GetHWND()
329 ,m_hFrame
330 ,FALSE
331 );
332 ::WinSetOwner( pToolBar->GetHWND()
333 ,m_hFrame
334 );
335 return pToolBar;
336} // end of WinGuiBase_CFrame::OnCreateToolBar
337#endif
338
19193a2c 339#if wxUSE_MENUS_NATIVE
0d53fc34 340void wxFrame::DetachMenuBar()
0e320a79 341{
21802234 342 if (m_frameMenuBar)
0e320a79 343 {
29435d81 344 m_frameMenuBar->Detach();
0e320a79 345 m_frameMenuBar = NULL;
21802234 346 }
0d53fc34 347} // end of wxFrame::DetachMenuBar
21802234 348
0d53fc34 349void wxFrame::SetMenuBar(
a885d89a 350 wxMenuBar* pMenuBar
0fe536e3 351)
21802234 352{
c3cea748
DW
353 wxString sError;
354
0fe536e3 355 if (!pMenuBar)
21802234
DW
356 {
357 DetachMenuBar();
29a99be3 358
64e0c5c6
DW
359 //
360 // Actually remove the menu from the frame
361 //
362 m_hMenu = (WXHMENU)0;
363 InternalSetMenuBar();
29a99be3 364 }
64e0c5c6 365 else // set new non NULL menu bar
c3cea748 366 {
64e0c5c6 367 m_frameMenuBar = NULL;
c3cea748 368
64e0c5c6
DW
369 //
370 // Can set a menubar several times.
371 // TODO: how to prevent a memory leak if you have a currently-unattached
77ffb593 372 // menubar? wxWidgets assumes that the frame will delete the menu (otherwise
64e0c5c6
DW
373 // there are problems for MDI).
374 //
375 if (pMenuBar->GetHMenu())
376 {
377 m_hMenu = pMenuBar->GetHMenu();
378 }
379 else
380 {
381 pMenuBar->Detach();
382 m_hMenu = pMenuBar->Create();
383 if (!m_hMenu)
384 return;
385 }
386 InternalSetMenuBar();
387 m_frameMenuBar = pMenuBar;
0367c1c0 388 pMenuBar->Attach((wxFrame*)this);
c3cea748 389 }
0d53fc34 390} // end of wxFrame::SetMenuBar
0e320a79 391
0d53fc34 392void wxFrame::AttachMenuBar(
893758d5
DW
393 wxMenuBar* pMenubar
394)
395{
19193a2c
KB
396 wxFrameBase::AttachMenuBar(pMenubar);
397
893758d5
DW
398 m_frameMenuBar = pMenubar;
399
400 if (!pMenubar)
401 {
402 //
403 // Actually remove the menu from the frame
404 //
405 m_hMenu = (WXHMENU)0;
406 InternalSetMenuBar();
407 }
408 else // Set new non NULL menu bar
409 {
410 //
411 // Can set a menubar several times.
412 //
413 if (pMenubar->GetHMenu())
414 {
415 m_hMenu = pMenubar->GetHMenu();
416 }
417 else
418 {
419 if (pMenubar->IsAttached())
420 pMenubar->Detach();
421
422 m_hMenu = pMenubar->Create();
423
424 if (!m_hMenu)
425 return;
426 }
427 InternalSetMenuBar();
428 }
0d53fc34 429} // end of wxFrame::AttachMenuBar
893758d5 430
0d53fc34 431void wxFrame::InternalSetMenuBar()
0e320a79 432{
64e0c5c6
DW
433 ERRORID vError;
434 wxString sError;
435 //
436 // Set the parent and owner of the menubar to be the frame
437 //
51c1d535 438 if (!::WinSetParent(m_hMenu, m_hFrame, FALSE))
64e0c5c6
DW
439 {
440 vError = ::WinGetLastError(vHabmain);
441 sError = wxPMErrorToStr(vError);
283ed244 442 wxLogError("Error setting parent for submenu. Error: %s\n", sError.c_str());
64e0c5c6
DW
443 }
444
51c1d535 445 if (!::WinSetOwner(m_hMenu, m_hFrame))
64e0c5c6
DW
446 {
447 vError = ::WinGetLastError(vHabmain);
448 sError = wxPMErrorToStr(vError);
283ed244 449 wxLogError("Error setting parent for submenu. Error: %s\n", sError.c_str());
64e0c5c6 450 }
b7084589 451 ::WinSendMsg(m_hFrame, WM_UPDATEFRAME, (MPARAM)FCF_MENU, (MPARAM)0);
0d53fc34 452} // end of wxFrame::InternalSetMenuBar
19193a2c 453#endif // wxUSE_MENUS_NATIVE
0e320a79 454
a885d89a
DW
455//
456// Responds to colour changes, and passes event on to children
457//
0d53fc34 458void wxFrame::OnSysColourChanged(
a885d89a
DW
459 wxSysColourChangedEvent& rEvent
460)
0e320a79 461{
a756f210 462 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
0e320a79
DW
463 Refresh();
464
7e99520b 465#if wxUSE_STATUSBAR
a885d89a 466 if (m_frameStatusBar)
0e320a79 467 {
a885d89a
DW
468 wxSysColourChangedEvent vEvent2;
469
470 vEvent2.SetEventObject(m_frameStatusBar);
471 m_frameStatusBar->GetEventHandler()->ProcessEvent(vEvent2);
0e320a79 472 }
7e99520b 473#endif //wxUSE_STATUSBAR
0e320a79 474
a885d89a 475 //
0e320a79 476 // Propagate the event to the non-top-level children
a885d89a
DW
477 //
478 wxWindow::OnSysColourChanged(rEvent);
0d53fc34 479} // end of wxFrame::OnSysColourChanged
21802234 480
542875a8 481// Pass TRUE to show full screen, FALSE to restore.
0d53fc34 482bool wxFrame::ShowFullScreen(
542875a8
DW
483 bool bShow
484, long lStyle
485)
486{
64e0c5c6 487 if (bShow)
542875a8
DW
488 {
489 if (IsFullScreen())
490 return FALSE;
491
64e0c5c6
DW
492 m_bFsIsShowing = TRUE;
493 m_lFsStyle = lStyle;
542875a8 494
7e99520b 495#if wxUSE_TOOLBAR
19193a2c 496 wxToolBar* pTheToolBar = GetToolBar();
7e99520b
DW
497#endif //wxUSE_TOOLBAR
498
499#if wxUSE_STATUSBAR
19193a2c 500 wxStatusBar* pTheStatusBar = GetStatusBar();
7e99520b 501#endif //wxUSE_STATUSBAR
542875a8 502
64e0c5c6 503 int nDummyWidth;
542875a8 504
7e99520b 505#if wxUSE_TOOLBAR
64e0c5c6
DW
506 if (pTheToolBar)
507 pTheToolBar->GetSize(&nDummyWidth, &m_nFsToolBarHeight);
7e99520b
DW
508#endif //wxUSE_TOOLBAR
509
510#if wxUSE_STATUSBAR
64e0c5c6
DW
511 if (pTheStatusBar)
512 pTheStatusBar->GetSize(&nDummyWidth, &m_nFsStatusBarHeight);
7e99520b 513#endif //wxUSE_STATUSBAR
542875a8 514
7e99520b 515#if wxUSE_TOOLBAR
64e0c5c6
DW
516 //
517 // Zap the toolbar, menubar, and statusbar
518 //
519 if ((lStyle & wxFULLSCREEN_NOTOOLBAR) && pTheToolBar)
542875a8 520 {
64e0c5c6
DW
521 pTheToolBar->SetSize(-1,0);
522 pTheToolBar->Show(FALSE);
542875a8 523 }
7e99520b 524#endif //wxUSE_TOOLBAR
542875a8 525
64e0c5c6
DW
526 if (lStyle & wxFULLSCREEN_NOMENUBAR)
527 {
b7084589
DW
528 ::WinSetParent(m_hMenu, m_hFrame, FALSE);
529 ::WinSetOwner(m_hMenu, m_hFrame);
530 ::WinSendMsg((HWND)m_hFrame, WM_UPDATEFRAME, (MPARAM)FCF_MENU, (MPARAM)0);
64e0c5c6 531 }
542875a8 532
7e99520b 533#if wxUSE_STATUSBAR
64e0c5c6 534 //
542875a8 535 // Save the number of fields in the statusbar
64e0c5c6
DW
536 //
537 if ((lStyle & wxFULLSCREEN_NOSTATUSBAR) && pTheStatusBar)
542875a8 538 {
64e0c5c6 539 m_nFsStatusBarFields = pTheStatusBar->GetFieldsCount();
542875a8 540 SetStatusBar((wxStatusBar*) NULL);
64e0c5c6 541 delete pTheStatusBar;
542875a8
DW
542 }
543 else
64e0c5c6 544 m_nFsStatusBarFields = 0;
7e99520b 545#endif //wxUSE_STATUSBAR
542875a8 546
64e0c5c6
DW
547 //
548 // Zap the frame borders
549 //
542875a8 550
64e0c5c6
DW
551 //
552 // Save the 'normal' window style
553 //
b7084589 554 m_lFsOldWindowStyle = ::WinQueryWindowULong(m_hFrame, QWL_STYLE);
542875a8 555
64e0c5c6 556 //
b7084589 557 // Save the old position, width & height, maximize state
64e0c5c6
DW
558 //
559 m_vFsOldSize = GetRect();
560 m_bFsIsMaximized = IsMaximized();
542875a8 561
64e0c5c6 562 //
b7084589 563 // Decide which window style flags to turn off
64e0c5c6
DW
564 //
565 LONG lNewStyle = m_lFsOldWindowStyle;
566 LONG lOffFlags = 0;
542875a8 567
64e0c5c6
DW
568 if (lStyle & wxFULLSCREEN_NOBORDER)
569 lOffFlags |= FCF_BORDER;
570 if (lStyle & wxFULLSCREEN_NOCAPTION)
571 lOffFlags |= (FCF_TASKLIST | FCF_SYSMENU);
542875a8 572
64e0c5c6 573 lNewStyle &= (~lOffFlags);
542875a8 574
64e0c5c6
DW
575 //
576 // Change our window style to be compatible with full-screen mode
577 //
b7084589 578 ::WinSetWindowULong((HWND)m_hFrame, QWL_STYLE, (ULONG)lNewStyle);
542875a8 579
64e0c5c6
DW
580 //
581 // Resize to the size of the desktop
582 int nWidth;
583 int nHeight;
542875a8 584
64e0c5c6 585 RECTL vRect;
542875a8 586
64e0c5c6
DW
587 ::WinQueryWindowRect(HWND_DESKTOP, &vRect);
588 nWidth = vRect.xRight - vRect.xLeft;
589 //
590 // Rmember OS/2 is backwards!
591 //
592 nHeight = vRect.yTop - vRect.yBottom;
542875a8 593
64e0c5c6
DW
594 SetSize( nWidth
595 ,nHeight
596 );
542875a8 597
64e0c5c6
DW
598 //
599 // Now flush the window style cache and actually go full-screen
600 //
601 ::WinSetWindowPos( (HWND) GetParent()->GetHWND()
602 ,HWND_TOP
603 ,0
604 ,0
605 ,nWidth
606 ,nHeight
607 ,SWP_SIZE | SWP_SHOW
608 );
609
610 wxSizeEvent vEvent( wxSize( nWidth
611 ,nHeight
612 )
613 ,GetId()
614 );
542875a8 615
64e0c5c6 616 GetEventHandler()->ProcessEvent(vEvent);
542875a8
DW
617 return TRUE;
618 }
619 else
620 {
621 if (!IsFullScreen())
622 return FALSE;
623
64e0c5c6 624 m_bFsIsShowing = FALSE;
542875a8 625
7e99520b 626#if wxUSE_TOOLBAR
64e0c5c6 627 wxToolBar* pTheToolBar = GetToolBar();
542875a8 628
64e0c5c6
DW
629 //
630 // Restore the toolbar, menubar, and statusbar
631 //
632 if (pTheToolBar && (m_lFsStyle & wxFULLSCREEN_NOTOOLBAR))
542875a8 633 {
64e0c5c6
DW
634 pTheToolBar->SetSize(-1, m_nFsToolBarHeight);
635 pTheToolBar->Show(TRUE);
542875a8 636 }
7e99520b 637#endif //wxUSE_TOOLBAR
542875a8 638
7e99520b 639#if wxUSE_STATUSBAR
64e0c5c6 640 if ((m_lFsStyle & wxFULLSCREEN_NOSTATUSBAR) && (m_nFsStatusBarFields > 0))
542875a8 641 {
64e0c5c6 642 CreateStatusBar(m_nFsStatusBarFields);
5b3ed311 643// PositionStatusBar();
542875a8 644 }
7e99520b 645#endif //wxUSE_STATUSBAR
542875a8 646
64e0c5c6
DW
647 if ((m_lFsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0))
648 {
b7084589
DW
649 ::WinSetParent(m_hMenu, m_hFrame, FALSE);
650 ::WinSetOwner(m_hMenu, m_hFrame);
651 ::WinSendMsg(m_hFrame, WM_UPDATEFRAME, (MPARAM)FCF_MENU, (MPARAM)0);
64e0c5c6
DW
652 }
653 Maximize(m_bFsIsMaximized);
654
b7084589 655 ::WinSetWindowULong( m_hFrame
64e0c5c6
DW
656 ,QWL_STYLE
657 ,(ULONG)m_lFsOldWindowStyle
658 );
659 ::WinSetWindowPos( (HWND) GetParent()->GetHWND()
660 ,HWND_TOP
661 ,m_vFsOldSize.x
662 ,m_vFsOldSize.y
663 ,m_vFsOldSize.width
664 ,m_vFsOldSize.height
665 ,SWP_SIZE | SWP_SHOW
666 );
542875a8 667 }
47df2b8c 668 return wxFrameBase::ShowFullScreen(bShow, lStyle);
0d53fc34 669} // end of wxFrame::ShowFullScreen
542875a8 670
a885d89a
DW
671//
672// Frame window
673//
f38374d0
DW
674// ----------------------------------------------------------------------------
675// wxFrame size management: we exclude the areas taken by menu/status/toolbars
676// from the client area, so the client area is what's really available for the
677// frame contents
678// ----------------------------------------------------------------------------
0e320a79
DW
679
680// Checks if there is a toolbar, and returns the first free client position
0d53fc34 681wxPoint wxFrame::GetClientAreaOrigin() const
0e320a79 682{
2590f154 683 wxPoint vPoint = wxTopLevelWindow::GetClientAreaOrigin();
a885d89a 684
2590f154
DW
685 //
686 // In OS/2 the toolbar and statusbar are frame extensions so there is no
687 // adjustment. The client is supposedly resized for a toolbar in OS/2
688 // as it is for the status bar.
689 //
a885d89a 690 return vPoint;
0d53fc34 691} // end of wxFrame::GetClientAreaOrigin
0e320a79 692
f38374d0
DW
693// ----------------------------------------------------------------------------
694// tool/status bar stuff
695// ----------------------------------------------------------------------------
696
21802234 697#if wxUSE_TOOLBAR
f38374d0 698
0d53fc34 699wxToolBar* wxFrame::CreateToolBar(
a885d89a
DW
700 long lStyle
701, wxWindowID vId
702, const wxString& rName
703)
0e320a79 704{
a885d89a
DW
705 if (wxFrameBase::CreateToolBar( lStyle
706 ,vId
707 ,rName
708 ))
0e320a79 709 {
0e320a79 710 PositionToolBar();
0e320a79 711 }
f38374d0 712 return m_frameToolBar;
0d53fc34 713} // end of wxFrame::CreateToolBar
0e320a79 714
0d53fc34 715void wxFrame::PositionToolBar()
0e320a79 716{
d697657f
DW
717 wxToolBar* pToolBar = GetToolBar();
718 wxCoord vWidth;
719 wxCoord vHeight;
720 wxCoord vTWidth;
721 wxCoord vTHeight;
722
723 if (!pToolBar)
724 return;
725
a885d89a 726 RECTL vRect;
d697657f 727 RECTL vFRect;
d697657f 728 wxPoint vPos;
a885d89a 729
d697657f
DW
730 ::WinQueryWindowRect(m_hFrame, &vRect);
731 vPos.y = (wxCoord)vRect.yTop;
732 ::WinMapWindowPoints(m_hFrame, HWND_DESKTOP, (PPOINTL)&vRect, 2);
733 vFRect = vRect;
734 ::WinCalcFrameRect(m_hFrame, &vRect, TRUE);
0e320a79 735
d697657f
DW
736 vPos.y = (wxCoord)(vFRect.yTop - vRect.yTop);
737 pToolBar->GetSize( &vTWidth
738 ,&vTHeight
739 );
a885d89a 740
d697657f
DW
741 if (pToolBar->GetWindowStyleFlag() & wxTB_HORIZONTAL)
742 {
743 vWidth = (wxCoord)(vRect.xRight - vRect.xLeft);
744 pToolBar->SetSize( vRect.xLeft - vFRect.xLeft
745 ,vPos.y
746 ,vWidth
747 ,vTHeight
748 );
0e320a79 749 }
d697657f 750 else
0e320a79 751 {
d697657f
DW
752 wxCoord vSwidth = 0;
753 wxCoord vSheight = 0;
0e320a79 754
d697657f
DW
755 if (m_frameStatusBar)
756 m_frameStatusBar->GetSize( &vSwidth
757 ,&vSheight
758 );
759 vHeight = (wxCoord)(vRect.yTop - vRect.yBottom);
760 pToolBar->SetSize( vRect.xLeft - vFRect.xLeft
761 ,vPos.y
762 ,vTWidth
763 ,vHeight - vSheight
764 );
21802234 765 }
d697657f
DW
766 if( ::WinIsWindowShowing(m_hFrame) )
767 ::WinSendMsg(m_hFrame, WM_UPDATEFRAME, (MPARAM)~0, 0);
0d53fc34 768} // end of wxFrame::PositionToolBar
21802234
DW
769#endif // wxUSE_TOOLBAR
770
f38374d0
DW
771// ----------------------------------------------------------------------------
772// frame state (iconized/maximized/...)
773// ----------------------------------------------------------------------------
774
a885d89a 775//
21802234
DW
776// propagate our state change to all child frames: this allows us to emulate X
777// Windows behaviour where child frames float independently of the parent one
778// on the desktop, but are iconized/restored with it
a885d89a 779//
0d53fc34 780void wxFrame::IconizeChildFrames(
a885d89a
DW
781 bool bIconize
782)
21802234 783{
072ce457
SN
784 // FIXME: Generic MDI does not use Frames for the Childs, so this does _not_
785 // work. Possibly, the right thing is simply to eliminate this
786 // functions and all the calls to it from within this file.
787#if 0
a885d89a
DW
788 for (wxWindowList::Node* pNode = GetChildren().GetFirst();
789 pNode;
790 pNode = pNode->GetNext() )
21802234 791 {
a885d89a 792 wxWindow* pWin = pNode->GetData();
0cf6acbf 793 wxFrame* pFrame = wxDynamicCast(pWin, wxFrame);
21802234 794
0cf6acbf
DW
795 if ( pFrame
796#if wxUSE_MDI_ARCHITECTURE
797 && !wxDynamicCast(pFrame, wxMDIChildFrame)
798#endif // wxUSE_MDI_ARCHITECTURE
799 )
21802234 800 {
0cf6acbf
DW
801 //
802 // We don't want to restore the child frames which had been
803 // iconized even before we were iconized, so save the child frame
804 // status when iconizing the parent frame and check it when
805 // restoring it.
806 //
807 if (bIconize)
808 {
809 pFrame->m_bWasMinimized = pFrame->IsIconized();
810 }
811
812 //
813 // This test works for both iconizing and restoring
814 //
815 if (!pFrame->m_bWasMinimized)
816 pFrame->Iconize(bIconize);
0e320a79
DW
817 }
818 }
072ce457 819#endif
0d53fc34 820} // end of wxFrame::IconizeChildFrames
0e320a79 821
5d44b24e
DW
822WXHICON wxFrame::GetDefaultIcon() const
823{
824 return (WXHICON)(wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON
825 : wxDEFAULT_FRAME_ICON);
826}
21802234
DW
827// ===========================================================================
828// message processing
829// ===========================================================================
830
831// ---------------------------------------------------------------------------
832// preprocessing
833// ---------------------------------------------------------------------------
0d53fc34 834bool wxFrame::OS2TranslateMessage(
a885d89a
DW
835 WXMSG* pMsg
836)
21802234 837{
a885d89a 838 //
21802234 839 // try the menu bar accels
a885d89a
DW
840 //
841 wxMenuBar* pMenuBar = GetMenuBar();
842
19193a2c 843 if (!pMenuBar)
21802234
DW
844 return FALSE;
845
19193a2c 846#if wxUSE_ACCEL && wxUSE_MENUS_NATIVE
a885d89a 847 const wxAcceleratorTable& rAcceleratorTable = pMenuBar->GetAccelTable();
e604d44b 848 return rAcceleratorTable.Translate(GetHWND(), pMsg);
7e99520b
DW
849#else
850 return FALSE;
851#endif //wxUSE_ACCEL
0d53fc34 852} // end of wxFrame::OS2TranslateMessage
21802234
DW
853
854// ---------------------------------------------------------------------------
855// our private (non virtual) message handlers
856// ---------------------------------------------------------------------------
0d53fc34 857bool wxFrame::HandlePaint()
21802234 858{
a885d89a
DW
859 RECTL vRect;
860
e604d44b 861 if (::WinQueryUpdateRect(GetHWND(), &vRect))
29435d81 862 {
a885d89a 863 if (m_bIconized)
29435d81 864 {
a885d89a
DW
865 //
866 // Icons in PM are the same as "pointers"
867 //
3437f881 868 const wxIcon& vIcon = GetIcon();
a885d89a 869 HPOINTER hIcon;
29435d81 870
3437f881 871 if (vIcon.Ok())
b7084589 872 hIcon = (HPOINTER)::WinSendMsg(m_hFrame, WM_QUERYICON, 0L, 0L);
a885d89a
DW
873 else
874 hIcon = (HPOINTER)m_hDefaultIcon;
875
876 //
21802234
DW
877 // Hold a pointer to the dc so long as the OnPaint() message
878 // is being processed
a885d89a
DW
879 //
880 RECTL vRect2;
64e0c5c6 881 HPS hPs = ::WinBeginPaint(GetHwnd(), NULLHANDLE, &vRect2);
29435d81 882
a885d89a 883 //
29435d81 884 // Erase background before painting or we get white background
a885d89a
DW
885 //
886 OS2DefWindowProc(WM_ERASEBACKGROUND, (MPARAM)hPs, (MPARAM)&vRect2);
29435d81 887
a885d89a 888 if (hIcon)
29435d81 889 {
a885d89a 890 RECTL vRect3;
21802234 891
40bd6154 892 ::WinQueryWindowRect(GetHwnd(), &vRect3);
29435d81 893
a885d89a
DW
894 static const int nIconWidth = 32;
895 static const int nIconHeight = 32;
896 int nIconX = (int)((vRect3.xRight - nIconWidth)/2);
897 int nIconY = (int)((vRect3.yBottom + nIconHeight)/2);
29435d81 898
a885d89a 899 ::WinDrawPointer(hPs, nIconX, nIconY, hIcon, DP_NORMAL);
29435d81 900 }
a885d89a 901 ::WinEndPaint(hPs);
29435d81
DW
902 return TRUE;
903 }
904 else
905 {
8330166c
DW
906 if (!wxWindow::HandlePaint())
907 {
908 HPS hPS;
909 RECTL vRect;
910
911 hPS = ::WinBeginPaint( GetHwnd()
912 ,NULLHANDLE
913 ,&vRect
914 );
915 if(hPS)
916 {
917 ::GpiCreateLogColorTable( hPS
918 ,0L
919 ,LCOLF_CONSECRGB
920 ,0L
921 ,(LONG)wxTheColourDatabase->m_nSize
922 ,(PLONG)wxTheColourDatabase->m_palTable
923 );
924 ::GpiCreateLogColorTable( hPS
925 ,0L
926 ,LCOLF_RGB
927 ,0L
928 ,0L
929 ,NULL
930 );
931
932 ::WinFillRect( hPS
933 ,&vRect
934 ,GetBackgroundColour().GetPixel()
935 );
936 ::WinEndPaint(hPS);
937 }
938 }
939 return TRUE;
29435d81
DW
940 }
941 }
942 else
943 {
944 // nothing to paint - processed
945 return TRUE;
946 }
29435d81 947 return FALSE;
0d53fc34 948} // end of wxFrame::HandlePaint
21802234 949
0d53fc34 950bool wxFrame::HandleSize(
a885d89a
DW
951 int nX
952, int nY
953, WXUINT nId
954)
21802234 955{
a885d89a 956 bool bProcessed = FALSE;
21802234 957
a885d89a 958 switch (nId)
21802234 959 {
a885d89a
DW
960 case kSizeNormal:
961 //
962 // Only do it it if we were iconized before, otherwise resizing the
21802234
DW
963 // parent frame has a curious side effect of bringing it under it's
964 // children
a885d89a 965 if (!m_bIconized )
21802234
DW
966 break;
967
a885d89a 968 //
21802234 969 // restore all child frames too
a885d89a 970 //
21802234 971 IconizeChildFrames(FALSE);
3febf684 972 (void)SendIconizeEvent(FALSE);
21802234 973
a885d89a 974 //
21802234 975 // fall through
a885d89a 976 //
21802234 977
a885d89a
DW
978 case kSizeMax:
979 m_bIconized = FALSE;
21802234
DW
980 break;
981
a885d89a
DW
982 case kSizeMin:
983 //
984 // Iconize all child frames too
985 //
21802234 986 IconizeChildFrames(TRUE);
3febf684 987 (void)SendIconizeEvent();
a885d89a 988 m_bIconized = TRUE;
21802234
DW
989 break;
990 }
f38374d0 991
a885d89a 992 if (!m_bIconized)
21802234 993 {
a885d89a 994 //
29435d81 995 // forward WM_SIZE to status bar control
a885d89a 996 //
f38374d0
DW
997#if wxUSE_NATIVE_STATUSBAR
998 if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)))
999 {
a885d89a
DW
1000 wxSizeEvent vEvent( wxSize( nX
1001 ,nY
1002 )
1003 ,m_frameStatusBar->GetId()
1004 );
f38374d0 1005
a885d89a
DW
1006 vEvent.SetEventObject(m_frameStatusBar);
1007 m_frameStatusBar->OnSize(vEvent);
f38374d0
DW
1008 }
1009#endif // wxUSE_NATIVE_STATUSBAR
1010
51c1d535 1011 PositionStatusBar();
7e99520b 1012#if wxUSE_TOOLBAR
21802234 1013 PositionToolBar();
7e99520b
DW
1014#endif // wxUSE_TOOLBAR
1015
598d8cac
DW
1016 bProcessed = wxWindow::HandleSize( nX
1017 ,nY
1018 ,nId
1019 );
21802234 1020 }
a885d89a 1021 return bProcessed;
0d53fc34 1022} // end of wxFrame::HandleSize
21802234 1023
0d53fc34 1024bool wxFrame::HandleCommand(
a885d89a
DW
1025 WXWORD nId
1026, WXWORD nCmd
1027, WXHWND hControl
1028)
21802234 1029{
a885d89a 1030 if (hControl)
21802234 1031 {
a885d89a 1032 //
21802234 1033 // In case it's e.g. a toolbar.
a885d89a
DW
1034 //
1035 wxWindow* pWin = wxFindWinFromHandle(hControl);
1036
1037 if (pWin)
1038 return pWin->OS2Command( nCmd
1039 ,nId
1040 );
21802234
DW
1041 }
1042
a885d89a
DW
1043 //
1044 // Handle here commands from menus and accelerators
1045 //
5b3ed311 1046 if (nCmd == CMDSRC_MENU || nCmd == CMDSRC_ACCELERATOR)
21802234 1047 {
19193a2c 1048#if wxUSE_MENUS_NATIVE
a885d89a 1049 if (wxCurrentPopupMenu)
21802234 1050 {
a885d89a
DW
1051 wxMenu* pPopupMenu = wxCurrentPopupMenu;
1052
21802234
DW
1053 wxCurrentPopupMenu = NULL;
1054
a885d89a
DW
1055 return pPopupMenu->OS2Command( nCmd
1056 ,nId
1057 );
19193a2c 1058 return TRUE;
21802234 1059 }
19193a2c 1060#endif
21802234 1061
a885d89a 1062 if (ProcessCommand(nId))
21802234
DW
1063 {
1064 return TRUE;
1065 }
1066 }
21802234 1067 return FALSE;
0d53fc34 1068} // end of wxFrame::HandleCommand
21802234 1069
0d53fc34 1070bool wxFrame::HandleMenuSelect(
a885d89a
DW
1071 WXWORD nItem
1072, WXWORD nFlags
1073, WXHMENU hMenu
1074)
21802234 1075{
e604d44b
DW
1076 if( !nFlags )
1077 {
1078 MENUITEM mItem;
1079 MRESULT rc;
1080
51c1d535 1081 rc = ::WinSendMsg(hMenu, MM_QUERYITEM, MPFROM2SHORT(nItem, TRUE), (MPARAM)&mItem);
e604d44b
DW
1082
1083 if(rc && !(mItem.afStyle & (MIS_SUBMENU | MIS_SEPARATOR)))
1084 {
1085 wxMenuEvent vEvent(wxEVT_MENU_HIGHLIGHT, nItem);
1086
1087 vEvent.SetEventObject(this);
1088 GetEventHandler()->ProcessEvent(vEvent); // return value would be ignored by PM
1089 }
16ff355b
DW
1090 else
1091 {
1092 DoGiveHelp(wxEmptyString, FALSE);
1093 return FALSE;
1094 }
e604d44b
DW
1095 }
1096 return TRUE;
0d53fc34 1097} // end of wxFrame::HandleMenuSelect
21802234
DW
1098
1099// ---------------------------------------------------------------------------
51c1d535 1100// Main Frame window proc
21802234 1101// ---------------------------------------------------------------------------
51c1d535
DW
1102MRESULT EXPENTRY wxFrameMainWndProc(
1103 HWND hWnd
1104, ULONG ulMsg
1105, MPARAM wParam
1106, MPARAM lParam
1107)
1108{
1109 MRESULT rc = (MRESULT)0;
1110 bool bProcessed = FALSE;
1111 wxFrame* pWnd = NULL;
1112
1113 pWnd = (wxFrame*) wxFindWinFromHandle((WXHWND) hWnd);
1114 switch (ulMsg)
1115 {
1116 case WM_QUERYFRAMECTLCOUNT:
1117 if(pWnd && pWnd->m_fnOldWndProc)
1118 {
1119 USHORT uItemCount = SHORT1FROMMR(pWnd->m_fnOldWndProc(hWnd, ulMsg, wParam, lParam));
1120
1121 rc = MRFROMSHORT(uItemCount);
1122 }
1123 break;
1124
1125 case WM_FORMATFRAME:
1126/////////////////////////////////////////////////////////////////////////////////
1127// Applications that subclass frame controls may find that the frame is already
1128// subclassed the number of frame controls is variable.
1129// The WM_FORMATFRAME and WM_QUERYFRAMECTLCOUNT messages must always be
1130// subclassed by calling the previous window procedure and modifying its result.
1131////////////////////////////////////////////////////////////////////////////////
1132 {
1133 int nItemCount;
1134 int i;
1135 PSWP pSWP = NULL;
51c1d535
DW
1136 RECTL vRectl;
1137 RECTL vRstb;
d697657f
DW
1138 RECTL vRtlb;
1139 int nHeight = 0;
1140 int nHeight2 = 0;
1141 int nWidth = 0;
51c1d535
DW
1142
1143 pSWP = (PSWP)PVOIDFROMMP(wParam);
1144 nItemCount = SHORT1FROMMR(pWnd->m_fnOldWndProc(hWnd, ulMsg, wParam, lParam));
1145 if(pWnd->m_frameStatusBar)
1146 {
1147 ::WinQueryWindowRect(pWnd->m_frameStatusBar->GetHWND(), &vRstb);
1148 pWnd->m_frameStatusBar->GetSize(NULL, &nHeight);
d697657f
DW
1149 }
1150 if(pWnd->m_frameToolBar)
1151 {
1152 ::WinQueryWindowRect(pWnd->m_frameToolBar->GetHWND(), &vRtlb);
1153 pWnd->m_frameToolBar->GetSize(&nWidth, &nHeight2);
51c1d535
DW
1154 }
1155 ::WinQueryWindowRect(pWnd->m_hFrame, &vRectl);
1156 ::WinMapWindowPoints(pWnd->m_hFrame, HWND_DESKTOP, (PPOINTL)&vRectl, 2);
1157 ::WinCalcFrameRect(pWnd->m_hFrame, &vRectl, TRUE);
1158 ::WinMapWindowPoints(HWND_DESKTOP, pWnd->m_hFrame, (PPOINTL)&vRectl, 2);
1159 for(i = 0; i < nItemCount; i++)
1160 {
1161 if(pWnd->m_hWnd && pSWP[i].hwnd == pWnd->m_hWnd)
1162 {
d697657f
DW
1163 if (pWnd->m_frameToolBar && pWnd->m_frameToolBar->GetWindowStyleFlag() & wxTB_HORIZONTAL)
1164 {
1165 pSWP[i].x = vRectl.xLeft;
1166 pSWP[i].y = vRectl.yBottom + nHeight;
1167 pSWP[i].cx = vRectl.xRight - vRectl.xLeft;
1168 pSWP[i].cy = vRectl.yTop - vRectl.yBottom - (nHeight + nHeight2);
1169 }
1170 else
1171 {
97d74dd2 1172 pSWP[i].x = vRectl.xLeft + nWidth;
d697657f
DW
1173 pSWP[i].y = vRectl.yBottom + nHeight;
1174 pSWP[i].cx = vRectl.xRight - (vRectl.xLeft + nWidth);
1175 pSWP[i].cy = vRectl.yTop - vRectl.yBottom - nHeight;
1176 }
51c1d535
DW
1177 pSWP[i].fl = SWP_SIZE | SWP_MOVE | SWP_SHOW;
1178 pSWP[i].hwndInsertBehind = HWND_TOP;
1179 }
1180 }
1181 bProcessed = TRUE;
1182 rc = MRFROMSHORT(nItemCount);
1183 }
1184 break;
1185
1186 default:
1187 if(pWnd && pWnd->m_fnOldWndProc)
1188 rc = pWnd->m_fnOldWndProc(hWnd, ulMsg, wParam, lParam);
1189 else
1190 rc = ::WinDefWindowProc(hWnd, ulMsg, wParam, lParam);
1191 }
1192 return rc;
1193} // end of wxFrameMainWndProc
1194
1195MRESULT EXPENTRY wxFrameWndProc(
1196 HWND hWnd
1197, ULONG ulMsg
1198, MPARAM wParam
1199, MPARAM lParam
1200)
1201{
1202 //
1203 // Trace all ulMsgs - useful for the debugging
1204 //
1205 HWND parentHwnd;
1206 wxFrame* pWnd = NULL;
1207
1208 parentHwnd = WinQueryWindow(hWnd,QW_PARENT);
1209 pWnd = (wxFrame*) wxFindWinFromHandle((WXHWND) hWnd);
1210
1211 //
1212 // When we get the first message for the HWND we just created, we associate
1213 // it with wxWindow stored in wxWndHook
1214 //
51c1d535
DW
1215
1216 MRESULT rc = (MRESULT)0;
51c1d535
DW
1217
1218 //
1219 // Stop right here if we don't have a valid handle in our wxWindow object.
1220 //
1221 if (pWnd && !pWnd->GetHWND())
1222 {
1223 pWnd->SetHWND((WXHWND) hWnd);
1224 rc = pWnd->OS2DefWindowProc(ulMsg, wParam, lParam );
1225 pWnd->SetHWND(0);
1226 }
1227 else
1228 {
d08f23a7
DW
1229 if (pWnd)
1230 rc = pWnd->OS2WindowProc(ulMsg, wParam, lParam);
1231 else
1232 rc = ::WinDefWindowProc(hWnd, ulMsg, wParam, lParam);
51c1d535
DW
1233 }
1234 return rc;
1235} // end of wxFrameWndProc
21802234 1236
0d53fc34 1237MRESULT wxFrame::OS2WindowProc(
a885d89a
DW
1238 WXUINT uMessage
1239, WXWPARAM wParam
1240, WXLPARAM lParam
1241)
21802234 1242{
a885d89a
DW
1243 MRESULT mRc = 0L;
1244 bool bProcessed = FALSE;
21802234 1245
a885d89a 1246 switch (uMessage)
21802234
DW
1247 {
1248 case WM_CLOSE:
a885d89a
DW
1249 //
1250 // If we can't close, tell the system that we processed the
21802234 1251 // message - otherwise it would close us
a885d89a
DW
1252 //
1253 bProcessed = !Close();
21802234
DW
1254 break;
1255
d08f23a7 1256 case WM_PAINT:
8d854fa9
DW
1257 bProcessed = HandlePaint();
1258 mRc = (MRESULT)FALSE;
1259 break;
d08f23a7 1260
8d854fa9
DW
1261 case WM_ERASEBACKGROUND:
1262 //
1263 // Returning TRUE to requests PM to paint the window background
1264 // in SYSCLR_WINDOW. We capture this here because the PS returned
1265 // in Frames is the PS for the whole frame, which we can't really
1266 // use at all. If you want to paint a different background, do it
1267 // in an OnPaint using a wxPaintDC.
1268 //
1269 mRc = (MRESULT)(TRUE);
d08f23a7
DW
1270 break;
1271
8d854fa9 1272 case WM_COMMAND:
21802234 1273 {
a885d89a
DW
1274 WORD wId;
1275 WORD wCmd;
1276 WXHWND hWnd;
1277
1278 UnpackCommand( (WXWPARAM)wParam
d08f23a7
DW
1279 ,(WXLPARAM)lParam
1280 ,&wId
1281 ,&hWnd
1282 ,&wCmd
1283 );
5b3ed311 1284
a885d89a
DW
1285 bProcessed = HandleCommand( wId
1286 ,wCmd
1287 ,(WXHWND)hWnd
1288 );
21802234
DW
1289 }
1290 break;
1291
1292 case WM_MENUSELECT:
1293 {
a885d89a
DW
1294 WXWORD wItem;
1295 WXWORD wFlags;
1296 WXHMENU hMenu;
1297
1298 UnpackMenuSelect( wParam
1299 ,lParam
1300 ,&wItem
1301 ,&wFlags
1302 ,&hMenu
1303 );
1304 bProcessed = HandleMenuSelect( wItem
1305 ,wFlags
1306 ,hMenu
1307 );
e604d44b 1308 mRc = (MRESULT)TRUE;
21802234
DW
1309 }
1310 break;
1311
d08f23a7
DW
1312 case WM_SIZE:
1313 {
d08f23a7
DW
1314 SHORT nScxnew = SHORT1FROMMP(lParam); // New horizontal size.
1315 SHORT nScynew = SHORT2FROMMP(lParam); // New vertical size.
1316
1317 lParam = MRFROM2SHORT( nScxnew - 20
1318 ,nScynew - 30
1319 );
1320 }
1321 bProcessed = HandleSize(LOWORD(lParam), HIWORD(lParam), (WXUINT)wParam);
1322 mRc = (MRESULT)FALSE;
21802234
DW
1323 break;
1324
a885d89a 1325 case CM_QUERYDRAGIMAGE:
21802234 1326 {
3437f881 1327 const wxIcon& vIcon = GetIcon();
a885d89a
DW
1328 HPOINTER hIcon;
1329
3437f881 1330 if (vIcon.Ok())
e604d44b 1331 hIcon = (HPOINTER)::WinSendMsg(GetHWND(), WM_QUERYICON, 0L, 0L);
a885d89a
DW
1332 else
1333 hIcon = (HPOINTER)m_hDefaultIcon;
1334 mRc = (MRESULT)hIcon;
1335 bProcessed = mRc != 0;
21802234
DW
1336 }
1337 break;
21802234 1338 }
f38374d0 1339
a885d89a
DW
1340 if (!bProcessed )
1341 mRc = wxWindow::OS2WindowProc( uMessage
1342 ,wParam
1343 ,lParam
1344 );
e604d44b 1345 return (MRESULT)mRc;
0d53fc34 1346} // wxFrame::OS2WindowProc
21802234 1347
0d53fc34 1348void wxFrame::SetClient(WXHWND c_Hwnd)
5b3ed311 1349{
51c1d535 1350 // Duh...nothing to do under OS/2
5b3ed311
DW
1351}
1352
0d53fc34 1353void wxFrame::SetClient(
51c1d535
DW
1354 wxWindow* pWindow
1355)
5b3ed311 1356{
51c1d535
DW
1357 wxWindow* pOldClient = this->GetClient();
1358 bool bClientHasFocus = pOldClient && (pOldClient == wxWindow::FindFocus());
5b3ed311 1359
51c1d535 1360 if(pOldClient == pWindow) // nothing to do
5b3ed311 1361 return;
51c1d535
DW
1362 if(pWindow == NULL) // just need to remove old client
1363 {
1364 if(pOldClient == NULL) // nothing to do
1365 return;
5b3ed311 1366
51c1d535 1367 if(bClientHasFocus )
5b3ed311
DW
1368 this->SetFocus();
1369
51c1d535
DW
1370 pOldClient->Enable( FALSE );
1371 pOldClient->Show( FALSE );
1372 ::WinSetWindowUShort(pOldClient->GetHWND(), QWS_ID, (USHORT)pOldClient->GetId());
5b3ed311 1373 // to avoid OS/2 bug need to update frame
b7084589 1374 ::WinSendMsg((HWND)this->GetFrame(), WM_UPDATEFRAME, (MPARAM)~0, 0);
5b3ed311 1375 return;
51c1d535 1376 }
5b3ed311 1377
51c1d535
DW
1378 //
1379 // Else need to change client
1380 //
1381 if(bClientHasFocus)
5b3ed311
DW
1382 this->SetFocus();
1383
51c1d535
DW
1384 ::WinEnableWindowUpdate((HWND)GetHWND(), FALSE);
1385 if(pOldClient)
1386 {
1387 pOldClient->Enable(FALSE);
1388 pOldClient->Show(FALSE);
1389 ::WinSetWindowUShort(pOldClient->GetHWND(), QWS_ID, (USHORT)pOldClient->GetId());
1390 }
1391 pWindow->Reparent(this);
1392 ::WinSetWindowUShort(pWindow->GetHWND(), QWS_ID, FID_CLIENT);
1393 ::WinEnableWindowUpdate((HWND)GetHWND(), TRUE);
1394 pWindow->Enable();
1395 pWindow->Show(); // ensure client is showing
1396 if( this->IsShown() )
1397 {
1398 this->Show();
b7084589 1399 ::WinSendMsg(m_hFrame, WM_UPDATEFRAME, (MPARAM)~0, 0);
51c1d535 1400 }
5b3ed311
DW
1401}
1402
0d53fc34 1403wxWindow* wxFrame::GetClient()
5b3ed311 1404{
b7084589 1405 return wxFindWinFromHandle((WXHWND)::WinWindowFromID(m_hFrame, FID_CLIENT));
5b3ed311 1406}
cfcebdb1
DW
1407
1408void wxFrame::SendSizeEvent()
1409{
1410 if (!m_bIconized)
1411 {
1412 RECTL vRect = wxGetWindowRect(GetHwnd());
1413
1414 ::WinPostMsg( GetHwnd()
1415 ,WM_SIZE
1416 ,MPFROM2SHORT( vRect.xRight - vRect.xLeft
1417 ,vRect.xRight - vRect.xLeft
1418 )
1419 ,MPFROM2SHORT( vRect.yTop - vRect.yBottom
1420 ,vRect.yTop - vRect.yBottom
1421 )
1422 );
1423 }
1424}
1425