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