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