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