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