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