Frame and Window coding
[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/setup.h"
17 #include "wx/frame.h"
18 #include "wx/menu.h"
19 #include "wx/app.h"
20 #include "wx/utils.h"
21 #include "wx/dialog.h"
22 #include "wx/settings.h"
23 #include "wx/dcclient.h"
24 #endif // WX_PRECOMP
25
26 #include "wx/os2/private.h"
27
28 #if wxUSE_STATUSBAR
29 #include "wx/statusbr.h"
30 #include "wx/generic/statusbr.h"
31 #endif // wxUSE_STATUSBAR
32
33 #if wxUSE_TOOLBAR
34 #include "wx/toolbar.h"
35 #endif // wxUSE_TOOLBAR
36
37 #include "wx/menuitem.h"
38 #include "wx/log.h"
39
40 // ----------------------------------------------------------------------------
41 // globals
42 // ----------------------------------------------------------------------------
43
44 extern wxWindowList wxModelessWindows;
45 extern wxList WXDLLEXPORT wxPendingDelete;
46 extern wxChar wxFrameClassName[];
47 extern wxMenu *wxCurrentPopupMenu;
48
49 // ----------------------------------------------------------------------------
50 // event tables
51 // ----------------------------------------------------------------------------
52
53 BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
54 EVT_ACTIVATE(wxFrame::OnActivate)
55 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
56 END_EVENT_TABLE()
57
58 IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow)
59
60 // ============================================================================
61 // implementation
62 // ============================================================================
63
64 // ----------------------------------------------------------------------------
65 // static class members
66 // ----------------------------------------------------------------------------
67
68 #if wxUSE_NATIVE_STATUSBAR
69 bool wxFrame::m_bUseNativeStatusBar = TRUE;
70 #else
71 bool wxFrame::m_bUseNativeStatusBar = FALSE;
72 #endif
73
74 // ----------------------------------------------------------------------------
75 // creation/destruction
76 // ----------------------------------------------------------------------------
77
78 void wxFrame::Init()
79 {
80 m_bIconized = FALSE;
81
82 #if wxUSE_TOOLTIPS
83 m_hWndToolTip = 0;
84 #endif
85 // Data to save/restore when calling ShowFullScreen
86 m_lFsStyle = 0L;
87 m_lFsOldWindowStyle = 0L;
88 m_nFsStatusBarFields = 0;
89 m_nFsStatusBarHeight = 0;
90 m_nFsToolBarHeight = 0;
91 m_bFsIsMaximized = FALSE;
92 m_bFsIsShowing = FALSE;
93 } // end of wxFrame::Init
94
95 bool wxFrame::Create(
96 wxWindow* pParent
97 , wxWindowID vId
98 , const wxString& rsTitle
99 , const wxPoint& rPos
100 , const wxSize& rSize
101 , long lulStyle
102 , const wxString& rsName
103 )
104 {
105 int nX = rPos.x;
106 int nY = rPos.y;
107 int nWidth = rSize.x;
108 int nHeight = rSize.y;
109
110 SetName(rsName);
111 m_windowStyle = lulStyle;
112 m_frameMenuBar = NULL;
113 m_frameToolBar = NULL;
114 m_frameStatusBar = NULL;
115
116 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
117
118 if (vId > -1 )
119 m_windowId = vId;
120 else
121 m_windowId = (int)NewControlId();
122
123 if (pParent)
124 pParent->AddChild(this);
125
126 m_bIconized = FALSE;
127
128 //
129 // We pass NULL as parent to MSWCreate because frames with parents behave
130 // very strangely under Win95 shell.
131 // Alteration by JACS: keep normal Windows behaviour (float on top of parent)
132 // with this ulStyle.
133 //
134 if ((m_windowStyle & wxFRAME_FLOAT_ON_PARENT) == 0)
135 pParent = NULL;
136
137 if (!pParent)
138 wxTopLevelWindows.Append(this);
139
140 OS2Create( m_windowId
141 ,pParent
142 ,wxFrameClassName
143 ,this
144 ,rsTitle
145 ,nX
146 ,nY
147 ,nWidth
148 ,nHeight
149 ,lulStyle
150 );
151
152 wxModelessWindows.Append(this);
153 return TRUE;
154 } // end of wxFrame::Create
155
156 wxFrame::~wxFrame()
157 {
158 m_isBeingDeleted = TRUE;
159 wxTopLevelWindows.DeleteObject(this);
160
161 DeleteAllBars();
162
163 if (wxTheApp && (wxTopLevelWindows.Number() == 0))
164 {
165 wxTheApp->SetTopWindow(NULL);
166
167 if (wxTheApp->GetExitOnFrameDelete())
168 {
169 ::WinPostMsg(GetHwnd(), WM_QUIT, 0, 0);
170 }
171 }
172 wxModelessWindows.DeleteObject(this);
173
174 //
175 // For some reason, wxWindows can activate another task altogether
176 // when a frame is destroyed after a modal dialog has been invoked.
177 // Try to bring the parent to the top.
178 //
179 // MT:Only do this if this frame is currently the active window, else weird
180 // things start to happen.
181 //
182 if (wxGetActiveWindow() == this)
183 {
184 if (GetParent() && GetParent()->GetHWND())
185 {
186 ::WinSetWindowPos( (HWND) GetParent()->GetHWND()
187 ,HWND_TOP
188 ,0
189 ,0
190 ,0
191 ,0
192 ,SWP_ZORDER
193 );
194 }
195 }
196 } // end of wxFrame::~wxFrame
197
198 //
199 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
200 //
201 void wxFrame::DoGetClientSize(
202 int* pX
203 , int* pY
204 ) const
205 {
206 //
207 // OS/2 PM's coordinates go from bottom-left not
208 // top-left thus the += instead of the -=
209 //
210 RECTL vRect;
211 HWND hWndClient;
212
213 //
214 // PM has no GetClientRect that inherantly knows about the client window
215 // We have to explicitly go fetch it!
216 //
217 hWndClient = ::WinWindowFromID(GetHwnd(), FID_CLIENT);
218 ::WinQueryWindowRect(hWndClient, &vRect);
219
220 #if wxUSE_STATUSBAR
221 if ( GetStatusBar() )
222 {
223 int nStatusX;
224 int nStatusY;
225
226 GetStatusBar()->GetClientSize( &nStatusX
227 ,&nStatusY
228 );
229 vRect.yBottom += nStatusY;
230 }
231 #endif // wxUSE_STATUSBAR
232
233 wxPoint vPoint(GetClientAreaOrigin());
234
235 vRect.yBottom += vPoint.y;
236 vRect.xRight -= vPoint.x;
237
238 if (pX)
239 *pX = vRect.xRight;
240 if (pY)
241 *pY = vRect.yBottom;
242 } // end of wxFrame::DoGetClientSize
243
244 //
245 // Set the client size (i.e. leave the calculation of borders etc.
246 // to wxWindows)
247 //
248 void wxFrame::DoSetClientSize(
249 int nWidth
250 , int nHeight
251 )
252 {
253 HWND hWnd = GetHwnd();
254 HWND hWndClient;
255 RECTL vRect;
256 RECT vRect2;
257
258 hWndClient = ::WinWindowFromID(GetHwnd(), FID_CLIENT);
259 ::WinQueryWindowRect(hWndClient, &vRect);
260
261 ::WinQueryWindowRect(hWnd, &vRect2);
262
263 //
264 // Find the difference between the entire window (title bar and all)
265 // and the client area; add this to the new client size to move the
266 // window. Remember OS/2's backwards y coord system!
267 //
268 int nActualWidth = vRect2.xRight - vRect2.xLeft - vRect.xRight + nWidth;
269 int nActualHeight = vRect2.yTop + vRect2.yTop - vRect.yTop + nHeight;
270
271 #if wxUSE_STATUSBAR
272 if ( GetStatusBar() )
273 {
274 int nStatusX;
275 int nStatusY;
276
277 GetStatusBar()->GetClientSize( &nStatusX
278 ,&nStatusY
279 );
280 nActualHeight += nStatusY;
281 }
282 #endif // wxUSE_STATUSBAR
283
284 wxPoint vPoint(GetClientAreaOrigin());
285 nActualWidth += vPoint.y;
286 nActualHeight += vPoint.x;
287
288 POINTL vPointl;
289
290 vPointl.x = vRect2.xLeft;
291 vPoint.y = vRect2.yTop;
292
293 ::WinSetWindowPos( hWnd
294 ,HWND_TOP
295 ,vPointl.x
296 ,vPointl.y
297 ,nActualWidth
298 ,nActualHeight
299 ,SWP_MOVE | SWP_SIZE | SWP_SHOW
300 );
301
302 wxSizeEvent vEvent( wxSize( nWidth
303 ,nHeight
304 )
305 ,m_windowId
306 );
307 vEvent.SetEventObject(this);
308 GetEventHandler()->ProcessEvent(vEvent);
309 } // end of wxFrame::DoSetClientSize
310
311 void wxFrame::DoGetSize(
312 int* pWidth
313 , int* pHeight
314 ) const
315 {
316 RECTL vRect;
317
318 ::WinQueryWindowRect(GetHwnd(), &vRect);
319 *pWidth = vRect.xRight - vRect.xLeft;
320 *pHeight = vRect.yTop - vRect.yBottom;
321 } // end of wxFrame::DoGetSize
322
323 void wxFrame::DoGetPosition(
324 int* pX
325 , int* pY
326 ) const
327 {
328 RECTL vRect;
329 POINTL vPoint;
330
331 ::WinQueryWindowRect(GetHwnd(), &vRect);
332 vPoint.x = vRect.xLeft;
333
334 //
335 // OS/2 is backwards [WIN32 it is vRect.yTop]
336 //
337 vPoint.y = vRect.yBottom;
338
339 *pX = vPoint.x;
340 *pY = vPoint.y;
341 } // end of wxFrame::DoGetPosition
342
343 // ----------------------------------------------------------------------------
344 // variations around ::ShowWindow()
345 // ----------------------------------------------------------------------------
346
347 void wxFrame::DoShowWindow(
348 int nShowCmd
349 )
350 {
351 ::WinShowWindow(GetHwnd(), nShowCmd);
352 m_bIconized = nShowCmd == SWP_MINIMIZE;
353 } // end of wxFrame::DoShowWindow
354
355 bool wxFrame::Show(
356 bool bShow
357 )
358 {
359 DoShowWindow(bShow ? SWP_SHOW : SWP_HIDE);
360
361 if (bShow)
362 {
363 wxActivateEvent vEvent(wxEVT_ACTIVATE, TRUE, m_windowId);
364
365 ::WinSetWindowPos( (HWND) GetHWND()
366 ,HWND_TOP
367 ,0
368 ,0
369 ,0
370 ,0
371 ,SWP_ZORDER
372 );
373 vEvent.SetEventObject(this);
374 GetEventHandler()->ProcessEvent(vEvent);
375 }
376 else
377 {
378 //
379 // Try to highlight the correct window (the parent)
380 //
381 if (GetParent())
382 {
383 HWND hWndParent = GetHwndOf(GetParent());
384
385 if (hWndParent)
386 ::WinSetWindowPos( hWndParent
387 ,HWND_TOP
388 ,0
389 ,0
390 ,0
391 ,0
392 ,SWP_ZORDER
393 );
394 }
395 }
396 return TRUE;
397 } // end of wxFrame::Show
398
399 void wxFrame::Iconize(
400 bool bIconize
401 )
402 {
403 DoShowWindow(bIconize ? SWP_MINIMIZE : SWP_RESTORE);
404 } // end of wxFrame::Iconize
405
406 void wxFrame::Maximize(
407 bool bMaximize)
408 {
409 DoShowWindow(bMaximize ? SWP_MAXIMIZE : SWP_RESTORE);
410 } // end of wxFrame::Maximize
411
412 void wxFrame::Restore()
413 {
414 DoShowWindow(SWP_RESTORE);
415 } // end of wxFrame::Restore
416
417 bool wxFrame::IsIconized() const
418 {
419 SWP vSwp;
420 bool bIconic;
421
422 ::WinQueryWindowPos(GetHwnd(), &vSwp);
423
424 if (vSwp.fl & SWP_MINIMIZE)
425 ((wxFrame*)this)->m_bIconized = TRUE;
426 else
427 ((wxFrame*)this)->m_bIconized = FALSE;
428 return m_bIconized;
429 } // end of wxFrame::IsIconized
430
431 // Is it maximized?
432 bool wxFrame::IsMaximized() const
433 {
434 SWP vSwp;
435 bool bIconic;
436
437 ::WinQueryWindowPos(GetHwnd(), &vSwp);
438 return (vSwp.fl & SWP_MAXIMIZE);
439 } // end of wxFrame::IsMaximized
440
441 void wxFrame::SetIcon(
442 const wxIcon& rIcon
443 )
444 {
445 wxFrameBase::SetIcon(rIcon);
446
447 if (m_icon.Ok())
448 {
449 WinSendMsg( GetHwnd()
450 ,WM_SETICON
451 ,(MPARAM)((HICON)m_icon.GetHICON())
452 ,NULL
453 );
454 }
455 } // end of wxFrame::SetIcon
456
457 #if wxUSE_STATUSBAR
458 wxStatusBar* wxFrame::OnCreateStatusBar(
459 int nNumber
460 , long lulStyle
461 , wxWindowID vId
462 , const wxString& rName
463 )
464 {
465 wxStatusBar* pStatusBar = NULL;
466
467 pStatusBar = wxFrameBase::OnCreateStatusBar( nNumber
468 ,lulStyle
469 ,vId
470 ,rName
471 );
472 return pStatusBar;
473 } // end of wxFrame::OnCreateStatusBar
474
475 void wxFrame::PositionStatusBar()
476 {
477 //
478 // Native status bar positions itself
479 //
480 if (m_frameStatusBar)
481 {
482 int nWidth;
483 int nHeight;
484 int nStatbarWidth;
485 int nStatbarHeight;
486 HWND hWndClient;
487 RECTL vRect;
488
489 hWndClient = ::WinWindowFromID(GetHwnd(), FID_CLIENT);
490 ::WinQueryWindowRect(hWndClient, &vRect);
491 nWidth = vRect.xRight - vRect.xLeft;
492 nHeight = vRect.yTop - vRect.yBottom;
493
494 m_frameStatusBar->GetSize( &nStatbarWidth
495 ,&nStatbarHeight
496 );
497
498 //
499 // Since we wish the status bar to be directly under the client area,
500 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
501 //
502 m_frameStatusBar->SetSize( 0
503 ,nHeight
504 ,nWidth
505 ,nStatbarHeight
506 );
507 }
508 } // end of wxFrame::PositionStatusBar
509 #endif // wxUSE_STATUSBAR
510
511 void wxFrame::DetachMenuBar()
512 {
513 if (m_frameMenuBar)
514 {
515 m_frameMenuBar->Detach();
516 m_frameMenuBar = NULL;
517 }
518 } // end of wxFrame::DetachMenuBar
519
520 void wxFrame::SetMenuBar(
521 wxMenuBar* pMenuBar
522 )
523 {
524 if (!pMenuBar)
525 {
526 DetachMenuBar();
527 return;
528 }
529
530 wxCHECK_RET(!pMenuBar->GetFrame(), wxT("this menubar is already attached"));
531
532 if (m_frameMenuBar)
533 delete m_frameMenuBar;
534
535 m_hMenu = pMenuBar->Create();
536 m_ulMenubarId = pMenuBar->GetMenubarId();
537 if (m_ulMenubarId != FID_MENU)
538 {
539 ::WinSetWindowUShort( m_hMenu
540 ,QWS_ID
541 ,(unsigned short)m_ulMenubarId
542 );
543 }
544
545 if (!m_hMenu)
546 return;
547
548 InternalSetMenuBar();
549
550 m_frameMenuBar = pMenuBar;
551 pMenuBar->Attach(this);
552 } // end of wxFrame::SetMenuBar
553
554 void wxFrame::InternalSetMenuBar()
555 {
556
557 ::WinPostMsg( GetHwnd()
558 ,WM_UPDATEFRAME
559 ,(MPARAM)FCF_MENU
560 ,NULL
561 );
562 } // end of wxFrame::InternalSetMenuBar
563
564 //
565 // Responds to colour changes, and passes event on to children
566 //
567 void wxFrame::OnSysColourChanged(
568 wxSysColourChangedEvent& rEvent
569 )
570 {
571 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
572 Refresh();
573
574 if (m_frameStatusBar)
575 {
576 wxSysColourChangedEvent vEvent2;
577
578 vEvent2.SetEventObject(m_frameStatusBar);
579 m_frameStatusBar->GetEventHandler()->ProcessEvent(vEvent2);
580 }
581
582 //
583 // Propagate the event to the non-top-level children
584 //
585 wxWindow::OnSysColourChanged(rEvent);
586 } // end of wxFrame::OnSysColourChanged
587
588 //
589 // Frame window
590 //
591 bool wxFrame::OS2Create(
592 int nId
593 , wxWindow* pParent
594 , const wxChar* zWclass
595 , wxWindow* pWxWin
596 , const wxChar* zTitle
597 , int nX
598 , int nY
599 , int nWidth
600 , int nHeight
601 , long ulStyle
602 )
603 {
604 ULONG ulPmFlags = 0;
605 ULONG ulExtraFlags = 0;
606 ULONG ulTempFlags = FCF_TITLEBAR |
607 FCF_SYSMENU |
608 FCF_MINBUTTON |
609 FCF_MAXBUTTON |
610 FCF_SIZEBORDER |
611 FCF_ICON |
612 FCF_MENU |
613 FCF_ACCELTABLE |
614 FCF_SHELLPOSITION |
615 FCF_TASKLIST;
616
617 m_hDefaultIcon = (WXHICON) (wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON : wxDEFAULT_FRAME_ICON);
618
619 if ((ulStyle & wxCAPTION) == wxCAPTION)
620 ulPmFlags = FCF_TASKLIST;
621 else
622 ulPmFlags = FCF_NOMOVEWITHOWNER;
623
624 if (ulStyle & wxMINIMIZE_BOX)
625 ulPmFlags |= FCF_MINBUTTON;
626 if (ulStyle & wxMAXIMIZE_BOX)
627 ulPmFlags |= FCF_MAXBUTTON;
628 if (ulStyle & wxTHICK_FRAME)
629 ulPmFlags |= FCF_DLGBORDER;
630 if (ulStyle & wxSYSTEM_MENU)
631 ulPmFlags |= FCF_SYSMENU;
632 if ((ulStyle & wxMINIMIZE) || (ulStyle & wxICONIZE))
633 ulPmFlags |= WS_MINIMIZED;
634 if (ulStyle & wxMAXIMIZE)
635 ulPmFlags |= WS_MAXIMIZED;
636 if (ulStyle & wxCAPTION)
637 ulPmFlags |= FCF_TASKLIST;
638 if (ulStyle & wxCLIP_CHILDREN)
639 {
640 // Invalid for frame windows under PM
641 }
642
643 //
644 // Keep this in wxFrame because it saves recoding this function
645 // in wxTinyFrame
646 //
647 #if wxUSE_ITSY_BITSY
648 if (ulStyle & wxTINY_CAPTION_VERT)
649 ulExtraFlags |= kVertCaption;
650 if (ulStyle & wxTINY_CAPTION_HORIZ)
651 ulExtraFlags |= kHorzCaption;
652 #else
653 if (ulStyle & wxTINY_CAPTION_VERT)
654 ulPmFlags |= FCF_TASKLIST;
655 if (ulStyle & wxTINY_CAPTION_HORIZ)
656 ulPmFlags |= FCF_TASKLIST;
657 #endif
658 if ((ulStyle & wxTHICK_FRAME) == 0)
659 ulPmFlags |= FCF_BORDER;
660 if (ulStyle & wxFRAME_TOOL_WINDOW)
661 ulExtraFlags = kFrameToolWindow;
662
663 if (ulStyle & wxSTAY_ON_TOP)
664 ulPmFlags |= FCF_SYSMODAL;
665
666 if (ulPmFlags & ulTempFlags)
667 ulPmFlags = FCF_STANDARD;
668 //
669 // Clear the visible flag, we always call show
670 //
671 ulPmFlags &= (unsigned long)~WS_VISIBLE;
672 m_bIconized = FALSE;
673 if ( !wxWindow::OS2Create( nId
674 ,pParent
675 ,zWclass
676 ,pWxWin
677 ,zTitle
678 ,nX
679 ,nY
680 ,nWidth
681 ,nHeight
682 ,ulPmFlags
683 ,NULL
684 ,ulExtraFlags))
685 {
686 return FALSE;
687 }
688 return TRUE;
689 } // end of wxFrame::OS2Create
690
691 //
692 // Default activation behaviour - set the focus for the first child
693 // subwindow found.
694 //
695 void wxFrame::OnActivate(
696 wxActivateEvent& rEvent
697 )
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 } // end of wxFrame::OnActivate
723
724 // ----------------------------------------------------------------------------
725 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
726 // from the client area, so the client area is what's really available for the
727 // frame contents
728 // ----------------------------------------------------------------------------
729
730 // Checks if there is a toolbar, and returns the first free client position
731 wxPoint wxFrame::GetClientAreaOrigin() const
732 {
733 wxPoint vPoint(0, 0);
734
735 if (GetToolBar())
736 {
737 int nWidth;
738 int nHeight;
739
740 GetToolBar()->GetSize( &nWidth
741 ,&nHeight
742 );
743
744 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
745 {
746 vPoint.x += nWidth;
747 }
748 else
749 {
750 // PM is backwards from windows
751 vPoint.y += nHeight;
752 }
753 }
754 return vPoint;
755 } // end of wxFrame::GetClientAreaOrigin
756
757 // ----------------------------------------------------------------------------
758 // tool/status bar stuff
759 // ----------------------------------------------------------------------------
760
761 #if wxUSE_TOOLBAR
762
763 wxToolBar* wxFrame::CreateToolBar(
764 long lStyle
765 , wxWindowID vId
766 , const wxString& rName
767 )
768 {
769 if (wxFrameBase::CreateToolBar( lStyle
770 ,vId
771 ,rName
772 ))
773 {
774 PositionToolBar();
775 }
776 return m_frameToolBar;
777 } // end of wxFrame::CreateToolBar
778
779 void wxFrame::PositionToolBar()
780 {
781 HWND hWndClient;
782 RECTL vRect;
783
784 hWndClient = ::WinWindowFromID(GetHwnd(), FID_CLIENT);
785 ::WinQueryWindowRect(hWndClient, &vRect);
786
787 #if wxUSE_STATUSBAR
788 if (GetStatusBar())
789 {
790 int nStatusX;
791 int nStatusY;
792
793 GetStatusBar()->GetClientSize( &nStatusX
794 ,&nStatusY
795 );
796 // PM is backwards from windows
797 vRect.yBottom += nStatusY;
798 }
799 #endif // wxUSE_STATUSBAR
800
801 if ( GetToolBar() )
802 {
803 int nToolbarWidth;
804 int nToolbarHeight;
805
806 GetToolBar()->GetSize( &nToolbarWidth
807 ,&nToolbarHeight
808 );
809
810 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
811 {
812 nToolbarHeight = vRect.yBottom;
813 }
814 else
815 {
816 nToolbarWidth = vRect.xRight;
817 }
818
819 //
820 // Use the 'real' PM position here
821 //
822 GetToolBar()->SetSize( 0
823 ,0
824 ,nToolbarWidth
825 ,nToolbarHeight
826 ,wxSIZE_NO_ADJUSTMENTS
827 );
828 }
829 } // end of wxFrame::PositionToolBar
830 #endif // wxUSE_TOOLBAR
831
832 // ----------------------------------------------------------------------------
833 // frame state (iconized/maximized/...)
834 // ----------------------------------------------------------------------------
835
836 //
837 // propagate our state change to all child frames: this allows us to emulate X
838 // Windows behaviour where child frames float independently of the parent one
839 // on the desktop, but are iconized/restored with it
840 //
841 void wxFrame::IconizeChildFrames(
842 bool bIconize
843 )
844 {
845 for (wxWindowList::Node* pNode = GetChildren().GetFirst();
846 pNode;
847 pNode = pNode->GetNext() )
848 {
849 wxWindow* pWin = pNode->GetData();
850
851 if (pWin->IsKindOf(CLASSINFO(wxFrame)) )
852 {
853 ((wxFrame *)pWin)->Iconize(bIconize);
854 }
855 }
856 } // end of wxFrame::IconizeChildFrames
857
858 // ===========================================================================
859 // message processing
860 // ===========================================================================
861
862 // ---------------------------------------------------------------------------
863 // preprocessing
864 // ---------------------------------------------------------------------------
865 bool wxFrame::OS2TranslateMessage(
866 WXMSG* pMsg
867 )
868 {
869 if (wxWindow::OS2TranslateMessage(pMsg))
870 return TRUE;
871 //
872 // try the menu bar accels
873 //
874 wxMenuBar* pMenuBar = GetMenuBar();
875
876 if (!pMenuBar )
877 return FALSE;
878
879 const wxAcceleratorTable& rAcceleratorTable = pMenuBar->GetAccelTable();
880 return rAcceleratorTable.Translate(this, pMsg);
881 } // end of wxFrame::OS2TranslateMessage
882
883 // ---------------------------------------------------------------------------
884 // our private (non virtual) message handlers
885 // ---------------------------------------------------------------------------
886 bool wxFrame::HandlePaint()
887 {
888 RECTL vRect;
889
890 if (::WinQueryUpdateRect(GetHwnd(), &vRect))
891 {
892 if (m_bIconized)
893 {
894 //
895 // Icons in PM are the same as "pointers"
896 //
897 HPOINTER hIcon;
898
899 if (m_icon.Ok())
900 hIcon = (HPOINTER)::WinSendMsg(GetHwnd(), WM_QUERYICON, 0L, 0L);
901 else
902 hIcon = (HPOINTER)m_hDefaultIcon;
903
904 //
905 // Hold a pointer to the dc so long as the OnPaint() message
906 // is being processed
907 //
908 RECTL vRect2;
909 HPS hPs = ::WinBeginPaint(GetHwnd(), NULLHANDLE, &vRect2);
910
911 //
912 // Erase background before painting or we get white background
913 //
914 OS2DefWindowProc(WM_ERASEBACKGROUND, (MPARAM)hPs, (MPARAM)&vRect2);
915
916 if (hIcon)
917 {
918 HWND hWndClient;
919 RECTL vRect3;
920
921 hWndClient = ::WinWindowFromID(GetHwnd(), FID_CLIENT);
922 ::WinQueryWindowRect(hWndClient, &vRect3);
923
924 static const int nIconWidth = 32;
925 static const int nIconHeight = 32;
926 int nIconX = (int)((vRect3.xRight - nIconWidth)/2);
927 int nIconY = (int)((vRect3.yBottom + nIconHeight)/2);
928
929 ::WinDrawPointer(hPs, nIconX, nIconY, hIcon, DP_NORMAL);
930 }
931 ::WinEndPaint(hPs);
932 return TRUE;
933 }
934 else
935 {
936 return wxWindow::HandlePaint();
937 }
938 }
939 else
940 {
941 // nothing to paint - processed
942 return TRUE;
943 }
944 return FALSE;
945 } // end of wxFrame::HandlePaint
946
947 bool wxFrame::HandleSize(
948 int nX
949 , int nY
950 , WXUINT nId
951 )
952 {
953 bool bProcessed = FALSE;
954
955 switch (nId)
956 {
957 case kSizeNormal:
958 //
959 // Only do it it if we were iconized before, otherwise resizing the
960 // parent frame has a curious side effect of bringing it under it's
961 // children
962 if (!m_bIconized )
963 break;
964
965 //
966 // restore all child frames too
967 //
968 IconizeChildFrames(FALSE);
969
970 //
971 // fall through
972 //
973
974 case kSizeMax:
975 m_bIconized = FALSE;
976 break;
977
978 case kSizeMin:
979 //
980 // Iconize all child frames too
981 //
982 IconizeChildFrames(TRUE);
983 m_bIconized = TRUE;
984 break;
985 }
986
987 if (!m_bIconized)
988 {
989 //
990 // forward WM_SIZE to status bar control
991 //
992 #if wxUSE_NATIVE_STATUSBAR
993 if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)))
994 {
995 wxSizeEvent vEvent( wxSize( nX
996 ,nY
997 )
998 ,m_frameStatusBar->GetId()
999 );
1000
1001 vEvent.SetEventObject(m_frameStatusBar);
1002 m_frameStatusBar->OnSize(vEvent);
1003 }
1004 #endif // wxUSE_NATIVE_STATUSBAR
1005
1006 PositionStatusBar();
1007 PositionToolBar();
1008 wxSizeEvent vEvent( wxSize( nX
1009 ,nY
1010 )
1011 ,m_windowId
1012 );
1013
1014 vEvent.SetEventObject(this);
1015 bProcessed = GetEventHandler()->ProcessEvent(vEvent);
1016 }
1017 return bProcessed;
1018 } // end of wxFrame::HandleSize
1019
1020 bool wxFrame::HandleCommand(
1021 WXWORD nId
1022 , WXWORD nCmd
1023 , WXHWND hControl
1024 )
1025 {
1026 if (hControl)
1027 {
1028 //
1029 // In case it's e.g. a toolbar.
1030 //
1031 wxWindow* pWin = wxFindWinFromHandle(hControl);
1032
1033 if (pWin)
1034 return pWin->OS2Command( nCmd
1035 ,nId
1036 );
1037 }
1038
1039 //
1040 // Handle here commands from menus and accelerators
1041 //
1042 if (nCmd == 0 || nCmd == 1)
1043 {
1044 if (wxCurrentPopupMenu)
1045 {
1046 wxMenu* pPopupMenu = wxCurrentPopupMenu;
1047
1048 wxCurrentPopupMenu = NULL;
1049
1050 return pPopupMenu->OS2Command( nCmd
1051 ,nId
1052 );
1053 }
1054
1055 if (ProcessCommand(nId))
1056 {
1057 return TRUE;
1058 }
1059 }
1060 return FALSE;
1061 } // end of wxFrame::HandleCommand
1062
1063 bool wxFrame::HandleMenuSelect(
1064 WXWORD nItem
1065 , WXWORD nFlags
1066 , WXHMENU hMenu
1067 )
1068 {
1069 int nMenuItem;
1070
1071 if (nFlags == 0xFFFF && hMenu == 0)
1072 {
1073 //
1074 // Menu was removed from screen
1075 //
1076 nMenuItem = -1;
1077 }
1078 else if (!(nFlags & MIS_SUBMENU) && !(nFlags & MIS_SEPARATOR))
1079 {
1080 nMenuItem = nItem;
1081 }
1082 else
1083 {
1084 //
1085 // Don't give hints for separators (doesn't make sense) nor for the
1086 // items opening popup menus (they don't have them anyhow)
1087 //
1088 return FALSE;
1089 }
1090 wxMenuEvent vEvent(wxEVT_MENU_HIGHLIGHT, nMenuItem);
1091
1092 vEvent.SetEventObject(this);
1093 return GetEventHandler()->ProcessEvent(vEvent);
1094 } // end of wxFrame::HandleMenuSelect
1095
1096 // ---------------------------------------------------------------------------
1097 // the window proc for wxFrame
1098 // ---------------------------------------------------------------------------
1099
1100 MRESULT wxFrame::OS2WindowProc(
1101 WXUINT uMessage
1102 , WXWPARAM wParam
1103 , WXLPARAM lParam
1104 )
1105 {
1106 MRESULT mRc = 0L;
1107 bool bProcessed = FALSE;
1108
1109 switch (uMessage)
1110 {
1111 case WM_CLOSE:
1112 //
1113 // If we can't close, tell the system that we processed the
1114 // message - otherwise it would close us
1115 //
1116 bProcessed = !Close();
1117 break;
1118
1119 case WM_COMMAND:
1120 {
1121 WORD wId;
1122 WORD wCmd;
1123 WXHWND hWnd;
1124
1125 UnpackCommand( (WXWPARAM)wParam
1126 ,(WXLPARAM)lParam
1127 ,&wId
1128 ,&hWnd
1129 ,&wCmd
1130 );
1131 bProcessed = HandleCommand( wId
1132 ,wCmd
1133 ,(WXHWND)hWnd
1134 );
1135 }
1136 break;
1137
1138 case WM_MENUSELECT:
1139 {
1140 WXWORD wItem;
1141 WXWORD wFlags;
1142 WXHMENU hMenu;
1143
1144 UnpackMenuSelect( wParam
1145 ,lParam
1146 ,&wItem
1147 ,&wFlags
1148 ,&hMenu
1149 );
1150 bProcessed = HandleMenuSelect( wItem
1151 ,wFlags
1152 ,hMenu
1153 );
1154 }
1155 break;
1156
1157 case WM_PAINT:
1158 bProcessed = HandlePaint();
1159 break;
1160
1161 case CM_QUERYDRAGIMAGE:
1162 {
1163 HPOINTER hIcon;
1164
1165 if (m_icon.Ok())
1166 hIcon = (HPOINTER)::WinSendMsg(GetHwnd(), WM_QUERYICON, 0L, 0L);
1167 else
1168 hIcon = (HPOINTER)m_hDefaultIcon;
1169 mRc = (MRESULT)hIcon;
1170 bProcessed = mRc != 0;
1171 }
1172 break;
1173
1174 case WM_SIZE:
1175 bProcessed = HandleSize(LOWORD(lParam), HIWORD(lParam), (WXUINT)wParam);
1176 break;
1177 }
1178
1179 if (!bProcessed )
1180 mRc = wxWindow::OS2WindowProc( uMessage
1181 ,wParam
1182 ,lParam
1183 );
1184 return (MRESULT)0;
1185 } // wxFrame::OS2WindowProc
1186