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