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