]> git.saurik.com Git - wxWidgets.git/blob - src/os2/frame.cpp
reverted my Set/getTitle change
[wxWidgets.git] / src / os2 / frame.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: frame.cpp
3 // Purpose: wxFrameOS2
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 #endif // WX_PRECOMP
34
35 #include "wx/os2/private.h"
36
37 #if wxUSE_STATUSBAR
38 #include "wx/statusbr.h"
39 #include "wx/generic/statusbr.h"
40 #endif // wxUSE_STATUSBAR
41
42 #if wxUSE_TOOLBAR
43 #include "wx/toolbar.h"
44 #endif // wxUSE_TOOLBAR
45
46 #include "wx/menuitem.h"
47 #include "wx/log.h"
48
49 // ----------------------------------------------------------------------------
50 // globals
51 // ----------------------------------------------------------------------------
52
53 extern wxWindowList wxModelessWindows;
54 extern wxList WXDLLEXPORT wxPendingDelete;
55 extern wxChar wxFrameClassName[];
56 extern wxMenu *wxCurrentPopupMenu;
57
58 extern void wxAssociateWinWithHandle( HWND hWnd
59 ,wxWindow* pWin
60 );
61
62 // ----------------------------------------------------------------------------
63 // event tables
64 // ----------------------------------------------------------------------------
65
66 BEGIN_EVENT_TABLE(wxFrameOS2, wxFrameBase)
67 EVT_ACTIVATE(wxFrameOS2::OnActivate)
68 EVT_SYS_COLOUR_CHANGED(wxFrameOS2::OnSysColourChanged)
69 END_EVENT_TABLE()
70
71 IMPLEMENT_DYNAMIC_CLASS(wxFrameOS2, wxWindow)
72
73 #ifndef __WXUNIVERSAL__
74 IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxFrameMSW)
75 #endif
76
77 // ============================================================================
78 // implementation
79 // ============================================================================
80
81 // ----------------------------------------------------------------------------
82 // static class members
83 // ----------------------------------------------------------------------------
84 #if wxUSE_STATUSBAR
85
86 #if wxUSE_NATIVE_STATUSBAR
87 bool wxFrameOS2::m_bUseNativeStatusBar = TRUE;
88 #else
89 bool wxFrameOS2::m_bUseNativeStatusBar = FALSE;
90 #endif
91
92 #endif //wxUSE_STATUSBAR
93
94 // ----------------------------------------------------------------------------
95 // creation/destruction
96 // ----------------------------------------------------------------------------
97
98 void wxFrameOS2::Init()
99 {
100 m_bIconized = FALSE;
101
102 #if wxUSE_TOOLTIPS
103 m_hWndToolTip = 0;
104 #endif
105 // Data to save/restore when calling ShowFullScreen
106 m_lFsStyle = 0L;
107 m_lFsOldWindowStyle = 0L;
108 m_nFsStatusBarFields = 0;
109 m_nFsStatusBarHeight = 0;
110 m_nFsToolBarHeight = 0;
111 m_bFsIsMaximized = FALSE;
112 m_bFsIsShowing = FALSE;
113 m_bIsShown = FALSE;
114 m_pWinLastFocused = (wxWindow *)NULL;
115
116 m_hFrame = NULL;
117 m_hTitleBar = NULL;
118 m_hHScroll = NULL;
119 m_hVScroll = NULL;
120
121 //
122 // Initialize SWP's
123 //
124 memset(&m_vSwp, 0, sizeof(SWP));
125 memset(&m_vSwpClient, 0, sizeof(SWP));
126 memset(&m_vSwpTitleBar, 0, sizeof(SWP));
127 memset(&m_vSwpMenuBar, 0, sizeof(SWP));
128 memset(&m_vSwpHScroll, 0, sizeof(SWP));
129 memset(&m_vSwpVScroll, 0, sizeof(SWP));
130 memset(&m_vSwpStatusBar, 0, sizeof(SWP));
131 memset(&m_vSwpToolBar, 0, sizeof(SWP));
132 } // end of wxFrameOS2::Init
133
134 bool wxFrameOS2::Create(
135 wxWindow* pParent
136 , wxWindowID vId
137 , const wxString& rsTitle
138 , const wxPoint& rPos
139 , const wxSize& rSize
140 , long lulStyle
141 , const wxString& rsName
142 )
143 {
144 int nX = rPos.x;
145 int nY = rPos.y;
146 int nWidth = rSize.x;
147 int nHeight = rSize.y;
148 bool bOk = FALSE;
149
150 SetName(rsName);
151 m_windowStyle = lulStyle;
152 m_frameMenuBar = NULL;
153 #if wxUSE_TOOLBAR
154 m_frameToolBar = NULL;
155 #endif //wxUSE_TOOLBAR
156
157 #if wxUSE_STATUSBAR
158 m_frameStatusBar = NULL;
159 #endif //wxUSE_STATUSBAR
160
161 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
162
163 if (vId > -1 )
164 m_windowId = vId;
165 else
166 m_windowId = (int)NewControlId();
167
168 if (pParent)
169 pParent->AddChild(this);
170
171 m_bIconized = FALSE;
172
173 if ((m_windowStyle & wxFRAME_FLOAT_ON_PARENT) == 0)
174 pParent = NULL;
175
176 bOk = OS2Create( m_windowId
177 ,pParent
178 ,wxFrameClassName
179 ,this
180 ,rsTitle
181 ,nX
182 ,nY
183 ,nWidth
184 ,nHeight
185 ,lulStyle
186 );
187 if (bOk)
188 {
189 if (!pParent)
190 wxTopLevelWindows.Append(this);
191 wxModelessWindows.Append(this);
192 }
193 return(bOk);
194 } // end of wxFrameOS2::Create
195
196 wxFrameOS2::~wxFrameOS2()
197 {
198 m_isBeingDeleted = TRUE;
199
200 wxTopLevelWindows.DeleteObject(this);
201
202 DeleteAllBars();
203
204 if (wxTheApp && (wxTopLevelWindows.Number() == 0))
205 {
206 wxTheApp->SetTopWindow(NULL);
207
208 if (wxTheApp->GetExitOnFrameDelete())
209 {
210 ::WinPostMsg(NULL, WM_QUIT, 0, 0);
211 }
212 }
213
214 wxModelessWindows.DeleteObject(this);
215
216 //
217 // For some reason, wxWindows can activate another task altogether
218 // when a frame is destroyed after a modal dialog has been invoked.
219 // Try to bring the parent to the top.
220 //
221 // MT:Only do this if this frame is currently the active window, else weird
222 // things start to happen.
223 //
224 if (wxGetActiveWindow() == this)
225 {
226 if (GetParent() && GetParent()->GetHWND())
227 {
228 ::WinSetWindowPos( (HWND) GetParent()->GetHWND()
229 ,HWND_TOP
230 ,0
231 ,0
232 ,0
233 ,0
234 ,SWP_ZORDER
235 );
236 }
237 }
238 } // end of wxFrameOS2::~wxFrame
239
240 //
241 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
242 //
243 void wxFrameOS2::DoGetClientSize(
244 int* pX
245 , int* pY
246 ) const
247 {
248 RECTL vRect;
249 ::WinQueryWindowRect(GetHwnd(), &vRect);
250
251 //
252 // No need to use statusbar code as in WIN32 as the FORMATFRAME
253 // window procedure ensures PM knows about the new frame client
254 // size internally. A ::WinQueryWindowRect is all that is needed!
255 //
256
257 if (pX)
258 *pX = vRect.xRight - vRect.xLeft;
259 if (pY)
260 *pY = vRect.yTop - vRect.yBottom;
261 } // end of wxFrameOS2::DoGetClientSize
262
263 //
264 // Set the client size (i.e. leave the calculation of borders etc.
265 // to wxWindows)
266 //
267 void wxFrameOS2::DoSetClientSize(
268 int nWidth
269 , int nHeight
270 )
271 {
272 HWND hWnd = GetHwnd();
273 RECTL vRect;
274 RECTL vRect2;
275
276 ::WinQueryWindowRect(GetHwnd(), &vRect);
277 ::WinQueryWindowRect(GetHwnd(), &vRect2);
278
279 //
280 // Find the difference between the entire window (title bar and all)
281 // and the client area; add this to the new client size to move the
282 // window. Remember OS/2's backwards y coord system!
283 //
284 int nActualWidth = vRect2.xRight - vRect2.xLeft - vRect.xRight + nWidth;
285 int nActualHeight = vRect2.yTop + vRect2.yTop - vRect.yTop + nHeight;
286
287 #if wxUSE_STATUSBAR
288 if ( GetStatusBar() )
289 {
290 int nStatusX;
291 int nStatusY;
292
293 GetStatusBar()->GetClientSize( &nStatusX
294 ,&nStatusY
295 );
296 nActualHeight += nStatusY;
297 }
298 #endif // wxUSE_STATUSBAR
299
300 wxPoint vPoint(GetClientAreaOrigin());
301 nActualWidth += vPoint.y;
302 nActualHeight += vPoint.x;
303
304 POINTL vPointl;
305
306 vPointl.x = vRect2.xLeft;
307 vPointl.y = vRect2.yTop;
308
309 ::WinSetWindowPos( hWnd
310 ,HWND_TOP
311 ,vPointl.x
312 ,vPointl.y
313 ,nActualWidth
314 ,nActualHeight
315 ,SWP_MOVE | SWP_SIZE | SWP_SHOW
316 );
317
318 wxSizeEvent vEvent( wxSize( nWidth
319 ,nHeight
320 )
321 ,m_windowId
322 );
323 vEvent.SetEventObject(this);
324 GetEventHandler()->ProcessEvent(vEvent);
325 } // end of wxFrameOS2::DoSetClientSize
326
327 void wxFrameOS2::DoGetSize(
328 int* pWidth
329 , int* pHeight
330 ) const
331 {
332 RECTL vRect;
333
334 ::WinQueryWindowRect(m_hFrame, &vRect);
335 *pWidth = vRect.xRight - vRect.xLeft;
336 *pHeight = vRect.yTop - vRect.yBottom;
337 } // end of wxFrameOS2::DoGetSize
338
339 void wxFrameOS2::DoGetPosition(
340 int* pX
341 , int* pY
342 ) const
343 {
344 RECTL vRect;
345 POINTL vPoint;
346
347 ::WinQueryWindowRect(m_hFrame, &vRect);
348
349 *pX = vRect.xRight - vRect.xLeft;
350 *pY = vRect.yTop - vRect.yBottom;
351 } // end of wxFrameOS2::DoGetPosition
352
353 // ----------------------------------------------------------------------------
354 // variations around ::ShowWindow()
355 // ----------------------------------------------------------------------------
356
357 void wxFrameOS2::DoShowWindow(
358 int bShowCmd
359 )
360 {
361 ::WinShowWindow(m_hFrame, (BOOL)bShowCmd);
362 m_bIconized = bShowCmd == SWP_MINIMIZE;
363 } // end of wxFrameOS2::DoShowWindow
364
365 bool wxFrameOS2::Show(
366 bool bShow
367 )
368 {
369 SWP vSwp;
370
371 DoShowWindow((int)bShow);
372
373 if (bShow)
374 {
375 wxActivateEvent vEvent(wxEVT_ACTIVATE, TRUE, m_windowId);
376
377 ::WinQueryWindowPos(m_hFrame, &vSwp);
378 m_bIconized = vSwp.fl & SWP_MINIMIZE;
379 ::WinSendMsg(m_hFrame, WM_UPDATEFRAME, (MPARAM)~0, 0);
380 ::WinEnableWindow(m_hFrame, TRUE);
381 vEvent.SetEventObject(this);
382 GetEventHandler()->ProcessEvent(vEvent);
383 }
384 else
385 {
386 //
387 // Try to highlight the correct window (the parent)
388 //
389 if (GetParent())
390 {
391 HWND hWndParent = GetHwndOf(GetParent());
392
393 ::WinQueryWindowPos(hWndParent, &vSwp);
394 m_bIconized = vSwp.fl & SWP_MINIMIZE;
395 if (hWndParent)
396 ::WinSetWindowPos( hWndParent
397 ,HWND_TOP
398 ,vSwp.x
399 ,vSwp.y
400 ,vSwp.cx
401 ,vSwp.cy
402 ,SWP_ZORDER | SWP_ACTIVATE | SWP_SHOW | SWP_MOVE
403 );
404 ::WinEnableWindow(hWndParent, TRUE);
405 }
406 }
407 return TRUE;
408 } // end of wxFrameOS2::Show
409
410 void wxFrameOS2::Iconize(
411 bool bIconize
412 )
413 {
414 DoShowWindow(bIconize ? SWP_MINIMIZE : SWP_RESTORE);
415 } // end of wxFrameOS2::Iconize
416
417 void wxFrameOS2::Maximize(
418 bool bMaximize)
419 {
420 DoShowWindow(bMaximize ? SWP_MAXIMIZE : SWP_RESTORE);
421 } // end of wxFrameOS2::Maximize
422
423 void wxFrameOS2::Restore()
424 {
425 DoShowWindow(SWP_RESTORE);
426 } // end of wxFrameOS2::Restore
427
428 bool wxFrameOS2::IsIconized() const
429 {
430 SWP vSwp;
431
432 ::WinQueryWindowPos(m_hFrame, &vSwp);
433
434 if (vSwp.fl & SWP_MINIMIZE)
435 ((wxFrame*)this)->m_bIconized = TRUE;
436 else
437 ((wxFrame*)this)->m_bIconized = FALSE;
438 return m_bIconized;
439 } // end of wxFrameOS2::IsIconized
440
441 // Is it maximized?
442 bool wxFrameOS2::IsMaximized() const
443 {
444 SWP vSwp;
445 bool bIconic;
446
447 ::WinQueryWindowPos(m_hFrame, &vSwp);
448 return (vSwp.fl & SWP_MAXIMIZE);
449 } // end of wxFrameOS2::IsMaximized
450
451 void wxFrameOS2::SetIcon(
452 const wxIcon& rIcon
453 )
454 {
455 wxFrameBase::SetIcon(rIcon);
456
457 if ((m_icon.GetHICON()) != NULLHANDLE)
458 {
459 ::WinSendMsg( m_hFrame
460 ,WM_SETICON
461 ,(MPARAM)((HPOINTER)m_icon.GetHICON())
462 ,NULL
463 );
464 ::WinSendMsg( m_hFrame
465 ,WM_UPDATEFRAME
466 ,(MPARAM)FCF_ICON
467 ,(MPARAM)0
468 );
469 }
470 } // end of wxFrameOS2::SetIcon
471
472 #if wxUSE_STATUSBAR
473 wxStatusBar* wxFrameOS2::OnCreateStatusBar(
474 int nNumber
475 , long lulStyle
476 , wxWindowID vId
477 , const wxString& rName
478 )
479 {
480 wxStatusBar* pStatusBar = NULL;
481 SWP vSwp;
482 ERRORID vError;
483 wxString sError;
484
485 pStatusBar = wxFrameBase::OnCreateStatusBar( nNumber
486 ,lulStyle
487 ,vId
488 ,rName
489 );
490
491 if( !pStatusBar )
492 return NULL;
493
494 ::WinSetParent( pStatusBar->GetHWND()
495 ,m_hFrame
496 ,FALSE
497 );
498 ::WinSetOwner( pStatusBar->GetHWND()
499 ,m_hFrame
500 );
501 //
502 // to show statusbar
503 //
504 if(::WinIsWindowShowing(m_hFrame))
505 ::WinSendMsg(m_hFrame, WM_UPDATEFRAME, (MPARAM)~0, 0);
506
507 return pStatusBar;
508 } // end of wxFrameOS2::OnCreateStatusBar
509
510 void wxFrameOS2::PositionStatusBar()
511 {
512 SWP vSwp;
513 ERRORID vError;
514 wxString sError;
515
516 //
517 // Native status bar positions itself
518 //
519 if (m_frameStatusBar)
520 {
521 int nWidth;
522 int nStatbarWidth;
523 int nStatbarHeight;
524 HWND hWndClient;
525 RECTL vRect;
526 RECTL vFRect;
527
528 ::WinQueryWindowRect(m_hFrame, &vRect);
529 ::WinMapWindowPoints(m_hFrame, HWND_DESKTOP, (PPOINTL)&vRect, 2);
530 vFRect = vRect;
531 ::WinCalcFrameRect(m_hFrame, &vRect, TRUE);
532 nWidth = vRect.xRight - vRect.xLeft;
533
534 m_frameStatusBar->GetSize( &nStatbarWidth
535 ,&nStatbarHeight
536 );
537
538 //
539 // Since we wish the status bar to be directly under the client area,
540 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
541 //
542 m_frameStatusBar->SetSize( vRect.xLeft - vFRect.xLeft
543 ,vRect.yBottom - vFRect.yBottom
544 ,nWidth
545 ,nStatbarHeight
546 );
547 if (!::WinQueryWindowPos(m_frameStatusBar->GetHWND(), &vSwp))
548 {
549 vError = ::WinGetLastError(vHabmain);
550 sError = wxPMErrorToStr(vError);
551 wxLogError("Error setting parent for StautsBar. Error: %s\n", sError);
552 return;
553 }
554 }
555 } // end of wxFrameOS2::PositionStatusBar
556 #endif // wxUSE_STATUSBAR
557
558 void wxFrameOS2::DetachMenuBar()
559 {
560 if (m_frameMenuBar)
561 {
562 m_frameMenuBar->Detach();
563 m_frameMenuBar = NULL;
564 }
565 } // end of wxFrameOS2::DetachMenuBar
566
567 void wxFrameOS2::SetMenuBar(
568 wxMenuBar* pMenuBar
569 )
570 {
571 ERRORID vError;
572 wxString sError;
573 HWND hTitlebar = NULLHANDLE;
574 HWND hHScroll = NULLHANDLE;
575 HWND hVScroll = NULLHANDLE;
576 HWND hMenuBar = NULLHANDLE;
577 SWP vSwp;
578 SWP vSwpTitlebar;
579 SWP vSwpVScroll;
580 SWP vSwpHScroll;
581 SWP vSwpMenu;
582
583 if (!pMenuBar)
584 {
585 DetachMenuBar();
586
587 //
588 // Actually remove the menu from the frame
589 //
590 m_hMenu = (WXHMENU)0;
591 InternalSetMenuBar();
592 }
593 else // set new non NULL menu bar
594 {
595 m_frameMenuBar = NULL;
596
597 //
598 // Can set a menubar several times.
599 // TODO: how to prevent a memory leak if you have a currently-unattached
600 // menubar? wxWindows assumes that the frame will delete the menu (otherwise
601 // there are problems for MDI).
602 //
603 if (pMenuBar->GetHMenu())
604 {
605 m_hMenu = pMenuBar->GetHMenu();
606 }
607 else
608 {
609 pMenuBar->Detach();
610 m_hMenu = pMenuBar->Create();
611 if (!m_hMenu)
612 return;
613 }
614 InternalSetMenuBar();
615 m_frameMenuBar = pMenuBar;
616 pMenuBar->Attach((wxFrame*)this);
617 }
618 } // end of wxFrameOS2::SetMenuBar
619
620 void wxFrameOS2::AttachMenuBar(
621 wxMenuBar* pMenubar
622 )
623 {
624 m_frameMenuBar = pMenubar;
625
626 if (!pMenubar)
627 {
628 //
629 // Actually remove the menu from the frame
630 //
631 m_hMenu = (WXHMENU)0;
632 InternalSetMenuBar();
633 }
634 else // Set new non NULL menu bar
635 {
636 //
637 // Can set a menubar several times.
638 //
639 if (pMenubar->GetHMenu())
640 {
641 m_hMenu = pMenubar->GetHMenu();
642 }
643 else
644 {
645 if (pMenubar->IsAttached())
646 pMenubar->Detach();
647
648 m_hMenu = pMenubar->Create();
649
650 if (!m_hMenu)
651 return;
652 }
653 InternalSetMenuBar();
654 }
655 } // end of wxFrameOS2::AttachMenuBar
656
657 void wxFrameOS2::InternalSetMenuBar()
658 {
659 ERRORID vError;
660 wxString sError;
661 //
662 // Set the parent and owner of the menubar to be the frame
663 //
664 if (!::WinSetParent(m_hMenu, m_hFrame, FALSE))
665 {
666 vError = ::WinGetLastError(vHabmain);
667 sError = wxPMErrorToStr(vError);
668 wxLogError("Error setting parent for submenu. Error: %s\n", sError);
669 }
670
671 if (!::WinSetOwner(m_hMenu, m_hFrame))
672 {
673 vError = ::WinGetLastError(vHabmain);
674 sError = wxPMErrorToStr(vError);
675 wxLogError("Error setting parent for submenu. Error: %s\n", sError);
676 }
677 ::WinSendMsg(m_hFrame, WM_UPDATEFRAME, (MPARAM)FCF_MENU, (MPARAM)0);
678 } // end of wxFrameOS2::InternalSetMenuBar
679
680 //
681 // Responds to colour changes, and passes event on to children
682 //
683 void wxFrameOS2::OnSysColourChanged(
684 wxSysColourChangedEvent& rEvent
685 )
686 {
687 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
688 Refresh();
689
690 #if wxUSE_STATUSBAR
691 if (m_frameStatusBar)
692 {
693 wxSysColourChangedEvent vEvent2;
694
695 vEvent2.SetEventObject(m_frameStatusBar);
696 m_frameStatusBar->GetEventHandler()->ProcessEvent(vEvent2);
697 }
698 #endif //wxUSE_STATUSBAR
699
700 //
701 // Propagate the event to the non-top-level children
702 //
703 wxWindow::OnSysColourChanged(rEvent);
704 } // end of wxFrameOS2::OnSysColourChanged
705
706 // Pass TRUE to show full screen, FALSE to restore.
707 bool wxFrameOS2::ShowFullScreen(
708 bool bShow
709 , long lStyle
710 )
711 {
712 if (bShow)
713 {
714 if (IsFullScreen())
715 return FALSE;
716
717 m_bFsIsShowing = TRUE;
718 m_lFsStyle = lStyle;
719
720 #if wxUSE_TOOLBAR
721 wxToolBar* pTheToolBar = GetToolBar();
722 #endif //wxUSE_TOOLBAR
723
724 #if wxUSE_STATUSBAR
725 wxStatusBar* pTheStatusBar = GetStatusBar();
726 #endif //wxUSE_STATUSBAR
727
728 int nDummyWidth;
729
730 #if wxUSE_TOOLBAR
731 if (pTheToolBar)
732 pTheToolBar->GetSize(&nDummyWidth, &m_nFsToolBarHeight);
733 #endif //wxUSE_TOOLBAR
734
735 #if wxUSE_STATUSBAR
736 if (pTheStatusBar)
737 pTheStatusBar->GetSize(&nDummyWidth, &m_nFsStatusBarHeight);
738 #endif //wxUSE_STATUSBAR
739
740 #if wxUSE_TOOLBAR
741 //
742 // Zap the toolbar, menubar, and statusbar
743 //
744 if ((lStyle & wxFULLSCREEN_NOTOOLBAR) && pTheToolBar)
745 {
746 pTheToolBar->SetSize(-1,0);
747 pTheToolBar->Show(FALSE);
748 }
749 #endif //wxUSE_TOOLBAR
750
751 if (lStyle & wxFULLSCREEN_NOMENUBAR)
752 {
753 ::WinSetParent(m_hMenu, m_hFrame, FALSE);
754 ::WinSetOwner(m_hMenu, m_hFrame);
755 ::WinSendMsg((HWND)m_hFrame, WM_UPDATEFRAME, (MPARAM)FCF_MENU, (MPARAM)0);
756 }
757
758 #if wxUSE_STATUSBAR
759 //
760 // Save the number of fields in the statusbar
761 //
762 if ((lStyle & wxFULLSCREEN_NOSTATUSBAR) && pTheStatusBar)
763 {
764 m_nFsStatusBarFields = pTheStatusBar->GetFieldsCount();
765 SetStatusBar((wxStatusBar*) NULL);
766 delete pTheStatusBar;
767 }
768 else
769 m_nFsStatusBarFields = 0;
770 #endif //wxUSE_STATUSBAR
771
772 //
773 // Zap the frame borders
774 //
775
776 //
777 // Save the 'normal' window style
778 //
779 m_lFsOldWindowStyle = ::WinQueryWindowULong(m_hFrame, QWL_STYLE);
780
781 //
782 // Save the old position, width & height, maximize state
783 //
784 m_vFsOldSize = GetRect();
785 m_bFsIsMaximized = IsMaximized();
786
787 //
788 // Decide which window style flags to turn off
789 //
790 LONG lNewStyle = m_lFsOldWindowStyle;
791 LONG lOffFlags = 0;
792
793 if (lStyle & wxFULLSCREEN_NOBORDER)
794 lOffFlags |= FCF_BORDER;
795 if (lStyle & wxFULLSCREEN_NOCAPTION)
796 lOffFlags |= (FCF_TASKLIST | FCF_SYSMENU);
797
798 lNewStyle &= (~lOffFlags);
799
800 //
801 // Change our window style to be compatible with full-screen mode
802 //
803 ::WinSetWindowULong((HWND)m_hFrame, QWL_STYLE, (ULONG)lNewStyle);
804
805 //
806 // Resize to the size of the desktop
807 int nWidth;
808 int nHeight;
809
810 RECTL vRect;
811
812 ::WinQueryWindowRect(HWND_DESKTOP, &vRect);
813 nWidth = vRect.xRight - vRect.xLeft;
814 //
815 // Rmember OS/2 is backwards!
816 //
817 nHeight = vRect.yTop - vRect.yBottom;
818
819 SetSize( nWidth
820 ,nHeight
821 );
822
823 //
824 // Now flush the window style cache and actually go full-screen
825 //
826 ::WinSetWindowPos( (HWND) GetParent()->GetHWND()
827 ,HWND_TOP
828 ,0
829 ,0
830 ,nWidth
831 ,nHeight
832 ,SWP_SIZE | SWP_SHOW
833 );
834
835 wxSizeEvent vEvent( wxSize( nWidth
836 ,nHeight
837 )
838 ,GetId()
839 );
840
841 GetEventHandler()->ProcessEvent(vEvent);
842 return TRUE;
843 }
844 else
845 {
846 if (!IsFullScreen())
847 return FALSE;
848
849 m_bFsIsShowing = FALSE;
850
851 #if wxUSE_TOOLBAR
852 wxToolBar* pTheToolBar = GetToolBar();
853
854 //
855 // Restore the toolbar, menubar, and statusbar
856 //
857 if (pTheToolBar && (m_lFsStyle & wxFULLSCREEN_NOTOOLBAR))
858 {
859 pTheToolBar->SetSize(-1, m_nFsToolBarHeight);
860 pTheToolBar->Show(TRUE);
861 }
862 #endif //wxUSE_TOOLBAR
863
864 #if wxUSE_STATUSBAR
865 if ((m_lFsStyle & wxFULLSCREEN_NOSTATUSBAR) && (m_nFsStatusBarFields > 0))
866 {
867 CreateStatusBar(m_nFsStatusBarFields);
868 // PositionStatusBar();
869 }
870 #endif //wxUSE_STATUSBAR
871
872 if ((m_lFsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0))
873 {
874 ::WinSetParent(m_hMenu, m_hFrame, FALSE);
875 ::WinSetOwner(m_hMenu, m_hFrame);
876 ::WinSendMsg(m_hFrame, WM_UPDATEFRAME, (MPARAM)FCF_MENU, (MPARAM)0);
877 }
878 Maximize(m_bFsIsMaximized);
879
880 ::WinSetWindowULong( m_hFrame
881 ,QWL_STYLE
882 ,(ULONG)m_lFsOldWindowStyle
883 );
884 ::WinSetWindowPos( (HWND) GetParent()->GetHWND()
885 ,HWND_TOP
886 ,m_vFsOldSize.x
887 ,m_vFsOldSize.y
888 ,m_vFsOldSize.width
889 ,m_vFsOldSize.height
890 ,SWP_SIZE | SWP_SHOW
891 );
892 return TRUE;
893 }
894 } // end of wxFrameOS2::ShowFullScreen
895
896 //
897 // Frame window
898 //
899 bool wxFrameOS2::OS2Create(
900 int nId
901 , wxWindow* pParent
902 , const wxChar* zWclass
903 , wxWindow* pWxWin
904 , const wxChar* zTitle
905 , int nX
906 , int nY
907 , int nWidth
908 , int nHeight
909 , long ulStyle
910 )
911 {
912 ULONG ulCreateFlags = 0L;
913 ULONG ulStyleFlags = 0L;
914 ULONG ulExtraFlags = 0L;
915 FRAMECDATA vFrameCtlData;
916 HWND hParent = NULLHANDLE;
917 HWND hTitlebar = NULLHANDLE;
918 HWND hHScroll = NULLHANDLE;
919 HWND hVScroll = NULLHANDLE;
920 HWND hFrame = NULLHANDLE;
921 HWND hClient = NULLHANDLE;
922 SWP vSwp[10];
923 RECTL vRect[10];
924 USHORT uCtlCount;
925 ERRORID vError;
926 wxString sError;
927
928 m_hDefaultIcon = (WXHICON) (wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON : wxDEFAULT_FRAME_ICON);
929
930 if (pParent)
931 hParent = GetWinHwnd(pParent);
932 else
933 hParent = HWND_DESKTOP;
934
935 if (ulStyle == wxDEFAULT_FRAME_STYLE)
936 ulCreateFlags = FCF_SIZEBORDER | FCF_TITLEBAR | FCF_SYSMENU |
937 FCF_MINMAX | FCF_TASKLIST;
938 else
939 {
940 if ((ulStyle & wxCAPTION) == wxCAPTION)
941 ulCreateFlags = FCF_TASKLIST;
942 else
943 ulCreateFlags = FCF_NOMOVEWITHOWNER;
944
945 if ((ulStyle & wxVSCROLL) == wxVSCROLL)
946 ulCreateFlags |= FCF_VERTSCROLL;
947 if ((ulStyle & wxHSCROLL) == wxHSCROLL)
948 ulCreateFlags |= FCF_HORZSCROLL;
949 if (ulStyle & wxMINIMIZE_BOX)
950 ulCreateFlags |= FCF_MINBUTTON;
951 if (ulStyle & wxMAXIMIZE_BOX)
952 ulCreateFlags |= FCF_MAXBUTTON;
953 if (ulStyle & wxTHICK_FRAME)
954 ulCreateFlags |= FCF_DLGBORDER;
955 if (ulStyle & wxSYSTEM_MENU)
956 ulCreateFlags |= FCF_SYSMENU;
957 if (ulStyle & wxCAPTION)
958 ulCreateFlags |= FCF_TASKLIST;
959 if (ulStyle & wxCLIP_CHILDREN)
960 {
961 // Invalid for frame windows under PM
962 }
963
964 if (ulStyle & wxTINY_CAPTION_VERT)
965 ulCreateFlags |= FCF_TASKLIST;
966 if (ulStyle & wxTINY_CAPTION_HORIZ)
967 ulCreateFlags |= FCF_TASKLIST;
968
969 if ((ulStyle & wxTHICK_FRAME) == 0)
970 ulCreateFlags |= FCF_BORDER;
971 if (ulStyle & wxFRAME_TOOL_WINDOW)
972 ulExtraFlags = kFrameToolWindow;
973
974 if (ulStyle & wxSTAY_ON_TOP)
975 ulCreateFlags |= FCF_SYSMODAL;
976 }
977 if ((ulStyle & wxMINIMIZE) || (ulStyle & wxICONIZE))
978 ulStyleFlags |= WS_MINIMIZED;
979 if (ulStyle & wxMAXIMIZE)
980 ulStyleFlags |= WS_MAXIMIZED;
981
982 //
983 // Clear the visible flag, we always call show
984 //
985 ulStyleFlags &= (unsigned long)~WS_VISIBLE;
986 m_bIconized = FALSE;
987
988 //
989 // Set the frame control block
990 //
991 vFrameCtlData.cb = sizeof(vFrameCtlData);
992 vFrameCtlData.flCreateFlags = ulCreateFlags;
993 vFrameCtlData.hmodResources = 0L;
994 vFrameCtlData.idResources = 0;
995
996 //
997 // Create the frame window: We break ranks with other ports now
998 // and instead of calling down into the base wxWindow class' OS2Create
999 // we do all our own stuff here. We will set the needed pieces
1000 // of wxWindow manually, here.
1001 //
1002
1003 hFrame = ::WinCreateStdWindow( hParent
1004 ,ulStyleFlags // frame-window style
1005 ,&ulCreateFlags // window style
1006 ,(PSZ)zWclass // class name
1007 ,(PSZ)zTitle // window title
1008 ,0L // default client style
1009 ,NULLHANDLE // resource in executable file
1010 ,0 // resource id
1011 ,&hClient // receives client window handle
1012 );
1013 if (!hFrame)
1014 {
1015 vError = ::WinGetLastError(vHabmain);
1016 sError = wxPMErrorToStr(vError);
1017 wxLogError("Error creating frame. Error: %s\n", sError);
1018 return FALSE;
1019 }
1020
1021 //
1022 // wxWindow class' m_hWnd set here and needed associations
1023 //
1024 m_hFrame = hFrame;
1025 m_hWnd = hClient;
1026 wxAssociateWinWithHandle(m_hWnd, this);
1027 wxAssociateWinWithHandle(m_hFrame, this);
1028
1029 m_backgroundColour.Set(wxString("GREY"));
1030
1031 LONG lColor = (LONG)m_backgroundColour.GetPixel();
1032
1033 if (!::WinSetPresParam( m_hWnd
1034 ,PP_BACKGROUNDCOLOR
1035 ,sizeof(LONG)
1036 ,(PVOID)&lColor
1037 ))
1038 {
1039 vError = ::WinGetLastError(vHabmain);
1040 sError = wxPMErrorToStr(vError);
1041 wxLogError("Error creating frame. Error: %s\n", sError);
1042 return FALSE;
1043 }
1044
1045 //
1046 // Now need to subclass window. Instead of calling the SubClassWin in wxWindow
1047 // we manually subclass here because we don't want to use the main wxWndProc
1048 // by default
1049 //
1050 m_fnOldWndProc = (WXFARPROC) ::WinSubclassWindow(m_hFrame, (PFNWP)wxFrameMainWndProc);
1051
1052 //
1053 // Now size everything. If adding a menu the client will need to be resized.
1054 //
1055
1056 if (!::WinSetWindowPos( m_hFrame
1057 ,HWND_TOP
1058 ,nX
1059 ,nY
1060 ,nWidth
1061 ,nHeight
1062 ,SWP_SIZE | SWP_MOVE | SWP_ACTIVATE | SWP_ZORDER
1063 ))
1064 {
1065 vError = ::WinGetLastError(vHabmain);
1066 sError = wxPMErrorToStr(vError);
1067 wxLogError("Error sizing frame. Error: %s\n", sError);
1068 return FALSE;
1069 }
1070 //
1071 // We may have to be smarter here when variable sized toolbars are added!
1072 //
1073 if (!::WinSetWindowPos( m_hWnd
1074 ,HWND_TOP
1075 ,nX // + 20
1076 ,nY // + 20
1077 ,nWidth // - 60
1078 ,nHeight // - 60
1079 ,SWP_SIZE | SWP_MOVE | SWP_ACTIVATE | SWP_ZORDER
1080 ))
1081 {
1082 vError = ::WinGetLastError(vHabmain);
1083 sError = wxPMErrorToStr(vError);
1084 wxLogError("Error sizing client. Error: %s\n", sError);
1085 return FALSE;
1086 }
1087 return TRUE;
1088 } // end of wxFrameOS2::OS2Create
1089
1090 //
1091 // Default activation behaviour - set the focus for the first child
1092 // subwindow found.
1093 //
1094 void wxFrameOS2::OnActivate(
1095 wxActivateEvent& rEvent
1096 )
1097 {
1098 if ( rEvent.GetActive() )
1099 {
1100 // restore focus to the child which was last focused
1101 wxLogTrace(_T("focus"), _T("wxFrame %08x activated."), m_hWnd);
1102
1103 wxWindow* pParent = m_pWinLastFocused ? m_pWinLastFocused->GetParent()
1104 : NULL;
1105 if (!pParent)
1106 {
1107 pParent = this;
1108 }
1109
1110 wxSetFocusToChild( pParent
1111 ,&m_pWinLastFocused
1112 );
1113 }
1114 else // deactivating
1115 {
1116 //
1117 // Remember the last focused child if it is our child
1118 //
1119 m_pWinLastFocused = FindFocus();
1120
1121 for (wxWindowList::Node* pNode = GetChildren().GetFirst();
1122 pNode;
1123 pNode = pNode->GetNext())
1124 {
1125 // FIXME all this is totally bogus - we need to do the same as wxPanel,
1126 // but how to do it without duplicating the code?
1127
1128 // restore focus
1129 wxWindow* pChild = pNode->GetData();
1130
1131 if (!pChild->IsTopLevel()
1132 #if wxUSE_TOOLBAR
1133 && !wxDynamicCast(pChild, wxToolBar)
1134 #endif // wxUSE_TOOLBAR
1135 #if wxUSE_STATUSBAR
1136 && !wxDynamicCast(pChild, wxStatusBar)
1137 #endif // wxUSE_STATUSBAR
1138 )
1139 {
1140 pChild->SetFocus();
1141 return;
1142 }
1143 }
1144 }
1145 } // end of wxFrameOS2::OnActivate
1146
1147 // ----------------------------------------------------------------------------
1148 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
1149 // from the client area, so the client area is what's really available for the
1150 // frame contents
1151 // ----------------------------------------------------------------------------
1152
1153 // Checks if there is a toolbar, and returns the first free client position
1154 wxPoint wxFrameOS2::GetClientAreaOrigin() const
1155 {
1156 wxPoint vPoint(0, 0);
1157
1158 #if wxUSE_TOOLBAR
1159 if (GetToolBar())
1160 {
1161 int nWidth;
1162 int nHeight;
1163
1164 GetToolBar()->GetSize( &nWidth
1165 ,&nHeight
1166 );
1167
1168 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
1169 {
1170 vPoint.x += nWidth;
1171 }
1172 else
1173 {
1174 // PM is backwards from windows
1175 vPoint.y += nHeight;
1176 }
1177 }
1178 #endif //wxUSE_TOOLBAR
1179 return vPoint;
1180 } // end of wxFrameOS2::GetClientAreaOrigin
1181
1182 // ----------------------------------------------------------------------------
1183 // tool/status bar stuff
1184 // ----------------------------------------------------------------------------
1185
1186 #if wxUSE_TOOLBAR
1187
1188 wxToolBar* wxFrameOS2::CreateToolBar(
1189 long lStyle
1190 , wxWindowID vId
1191 , const wxString& rName
1192 )
1193 {
1194 if (wxFrameBase::CreateToolBar( lStyle
1195 ,vId
1196 ,rName
1197 ))
1198 {
1199 PositionToolBar();
1200 }
1201 return m_frameToolBar;
1202 } // end of wxFrameOS2::CreateToolBar
1203
1204 void wxFrameOS2::PositionToolBar()
1205 {
1206 HWND hWndClient;
1207 RECTL vRect;
1208
1209 ::WinQueryWindowRect(GetHwnd(), &vRect);
1210
1211 #if wxUSE_STATUSBAR
1212 if (GetStatusBar())
1213 {
1214 int nStatusX;
1215 int nStatusY;
1216
1217 GetStatusBar()->GetClientSize( &nStatusX
1218 ,&nStatusY
1219 );
1220 // PM is backwards from windows
1221 vRect.yBottom += nStatusY;
1222 }
1223 #endif // wxUSE_STATUSBAR
1224
1225 if ( m_frameToolBar )
1226 {
1227 int nToolbarWidth;
1228 int nToolbarHeight;
1229
1230 m_frameToolBar->GetSize( &nToolbarWidth
1231 ,&nToolbarHeight
1232 );
1233
1234 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
1235 {
1236 nToolbarHeight = vRect.yBottom;
1237 }
1238 else
1239 {
1240 nToolbarWidth = vRect.xRight;
1241 }
1242
1243 //
1244 // Use the 'real' PM position here
1245 //
1246 GetToolBar()->SetSize( 0
1247 ,0
1248 ,nToolbarWidth
1249 ,nToolbarHeight
1250 ,wxSIZE_NO_ADJUSTMENTS
1251 );
1252 }
1253 } // end of wxFrameOS2::PositionToolBar
1254 #endif // wxUSE_TOOLBAR
1255
1256 // ----------------------------------------------------------------------------
1257 // frame state (iconized/maximized/...)
1258 // ----------------------------------------------------------------------------
1259
1260 //
1261 // propagate our state change to all child frames: this allows us to emulate X
1262 // Windows behaviour where child frames float independently of the parent one
1263 // on the desktop, but are iconized/restored with it
1264 //
1265 void wxFrameOS2::IconizeChildFrames(
1266 bool bIconize
1267 )
1268 {
1269 for (wxWindowList::Node* pNode = GetChildren().GetFirst();
1270 pNode;
1271 pNode = pNode->GetNext() )
1272 {
1273 wxWindow* pWin = pNode->GetData();
1274
1275 if (pWin->IsKindOf(CLASSINFO(wxFrame)) )
1276 {
1277 ((wxFrame *)pWin)->Iconize(bIconize);
1278 }
1279 }
1280 } // end of wxFrameOS2::IconizeChildFrames
1281
1282 // ===========================================================================
1283 // message processing
1284 // ===========================================================================
1285
1286 // ---------------------------------------------------------------------------
1287 // preprocessing
1288 // ---------------------------------------------------------------------------
1289 bool wxFrameOS2::OS2TranslateMessage(
1290 WXMSG* pMsg
1291 )
1292 {
1293 //
1294 // try the menu bar accels
1295 //
1296 wxMenuBar* pMenuBar = GetMenuBar();
1297
1298 if (!pMenuBar )
1299 return FALSE;
1300
1301 #if wxUSE_ACCEL
1302 const wxAcceleratorTable& rAcceleratorTable = pMenuBar->GetAccelTable();
1303 return rAcceleratorTable.Translate(GetHWND(), pMsg);
1304 #else
1305 return FALSE;
1306 #endif //wxUSE_ACCEL
1307 } // end of wxFrameOS2::OS2TranslateMessage
1308
1309 // ---------------------------------------------------------------------------
1310 // our private (non virtual) message handlers
1311 // ---------------------------------------------------------------------------
1312 bool wxFrameOS2::HandlePaint()
1313 {
1314 RECTL vRect;
1315
1316 if (::WinQueryUpdateRect(GetHWND(), &vRect))
1317 {
1318 if (m_bIconized)
1319 {
1320 //
1321 // Icons in PM are the same as "pointers"
1322 //
1323 HPOINTER hIcon;
1324
1325 if (m_icon.Ok())
1326 hIcon = (HPOINTER)::WinSendMsg(m_hFrame, WM_QUERYICON, 0L, 0L);
1327 else
1328 hIcon = (HPOINTER)m_hDefaultIcon;
1329
1330 //
1331 // Hold a pointer to the dc so long as the OnPaint() message
1332 // is being processed
1333 //
1334 RECTL vRect2;
1335 HPS hPs = ::WinBeginPaint(GetHwnd(), NULLHANDLE, &vRect2);
1336
1337 //
1338 // Erase background before painting or we get white background
1339 //
1340 OS2DefWindowProc(WM_ERASEBACKGROUND, (MPARAM)hPs, (MPARAM)&vRect2);
1341
1342 if (hIcon)
1343 {
1344 HWND hWndClient;
1345 RECTL vRect3;
1346
1347 ::WinQueryWindowRect(GetHwnd(), &vRect3);
1348
1349 static const int nIconWidth = 32;
1350 static const int nIconHeight = 32;
1351 int nIconX = (int)((vRect3.xRight - nIconWidth)/2);
1352 int nIconY = (int)((vRect3.yBottom + nIconHeight)/2);
1353
1354 ::WinDrawPointer(hPs, nIconX, nIconY, hIcon, DP_NORMAL);
1355 }
1356 ::WinEndPaint(hPs);
1357 return TRUE;
1358 }
1359 else
1360 {
1361 return(wxWindow::HandlePaint());
1362 }
1363 }
1364 else
1365 {
1366 // nothing to paint - processed
1367 return TRUE;
1368 }
1369 return FALSE;
1370 } // end of wxFrameOS2::HandlePaint
1371
1372 bool wxFrameOS2::HandleSize(
1373 int nX
1374 , int nY
1375 , WXUINT nId
1376 )
1377 {
1378 bool bProcessed = FALSE;
1379
1380 switch (nId)
1381 {
1382 case kSizeNormal:
1383 //
1384 // Only do it it if we were iconized before, otherwise resizing the
1385 // parent frame has a curious side effect of bringing it under it's
1386 // children
1387 if (!m_bIconized )
1388 break;
1389
1390 //
1391 // restore all child frames too
1392 //
1393 IconizeChildFrames(FALSE);
1394 (void)SendIconizeEvent(FALSE);
1395
1396 //
1397 // fall through
1398 //
1399
1400 case kSizeMax:
1401 m_bIconized = FALSE;
1402 break;
1403
1404 case kSizeMin:
1405 //
1406 // Iconize all child frames too
1407 //
1408 IconizeChildFrames(TRUE);
1409 (void)SendIconizeEvent();
1410 m_bIconized = TRUE;
1411 break;
1412 }
1413
1414 if (!m_bIconized)
1415 {
1416 //
1417 // forward WM_SIZE to status bar control
1418 //
1419 #if wxUSE_NATIVE_STATUSBAR
1420 if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)))
1421 {
1422 wxSizeEvent vEvent( wxSize( nX
1423 ,nY
1424 )
1425 ,m_frameStatusBar->GetId()
1426 );
1427
1428 vEvent.SetEventObject(m_frameStatusBar);
1429 m_frameStatusBar->OnSize(vEvent);
1430 }
1431 #endif // wxUSE_NATIVE_STATUSBAR
1432
1433 PositionStatusBar();
1434 #if wxUSE_TOOLBAR
1435 PositionToolBar();
1436 #endif // wxUSE_TOOLBAR
1437
1438 wxSizeEvent vEvent( wxSize( nX
1439 ,nY
1440 )
1441 ,m_windowId
1442 );
1443
1444 vEvent.SetEventObject(this);
1445 bProcessed = GetEventHandler()->ProcessEvent(vEvent);
1446 }
1447 return bProcessed;
1448 } // end of wxFrameOS2::HandleSize
1449
1450 bool wxFrameOS2::HandleCommand(
1451 WXWORD nId
1452 , WXWORD nCmd
1453 , WXHWND hControl
1454 )
1455 {
1456 if (hControl)
1457 {
1458 //
1459 // In case it's e.g. a toolbar.
1460 //
1461 wxWindow* pWin = wxFindWinFromHandle(hControl);
1462
1463 if (pWin)
1464 return pWin->OS2Command( nCmd
1465 ,nId
1466 );
1467 }
1468
1469 //
1470 // Handle here commands from menus and accelerators
1471 //
1472 if (nCmd == CMDSRC_MENU || nCmd == CMDSRC_ACCELERATOR)
1473 {
1474 if (wxCurrentPopupMenu)
1475 {
1476 wxMenu* pPopupMenu = wxCurrentPopupMenu;
1477
1478 wxCurrentPopupMenu = NULL;
1479
1480 return pPopupMenu->OS2Command( nCmd
1481 ,nId
1482 );
1483 }
1484
1485 if (ProcessCommand(nId))
1486 {
1487 return TRUE;
1488 }
1489 }
1490 return FALSE;
1491 } // end of wxFrameOS2::HandleCommand
1492
1493 bool wxFrameOS2::HandleMenuSelect(
1494 WXWORD nItem
1495 , WXWORD nFlags
1496 , WXHMENU hMenu
1497 )
1498 {
1499 if( !nFlags )
1500 {
1501 MENUITEM mItem;
1502 MRESULT rc;
1503
1504 rc = ::WinSendMsg(hMenu, MM_QUERYITEM, MPFROM2SHORT(nItem, TRUE), (MPARAM)&mItem);
1505
1506 if(rc && !(mItem.afStyle & (MIS_SUBMENU | MIS_SEPARATOR)))
1507 {
1508 wxMenuEvent vEvent(wxEVT_MENU_HIGHLIGHT, nItem);
1509
1510 vEvent.SetEventObject(this);
1511 GetEventHandler()->ProcessEvent(vEvent); // return value would be ignored by PM
1512 }
1513 }
1514 return TRUE;
1515 } // end of wxFrameOS2::HandleMenuSelect
1516
1517 // ---------------------------------------------------------------------------
1518 // Main Frame window proc
1519 // ---------------------------------------------------------------------------
1520 MRESULT EXPENTRY wxFrameMainWndProc(
1521 HWND hWnd
1522 , ULONG ulMsg
1523 , MPARAM wParam
1524 , MPARAM lParam
1525 )
1526 {
1527 MRESULT rc = (MRESULT)0;
1528 bool bProcessed = FALSE;
1529 wxFrame* pWnd = NULL;
1530
1531 pWnd = (wxFrame*) wxFindWinFromHandle((WXHWND) hWnd);
1532 switch (ulMsg)
1533 {
1534 case WM_QUERYFRAMECTLCOUNT:
1535 if(pWnd && pWnd->m_fnOldWndProc)
1536 {
1537 USHORT uItemCount = SHORT1FROMMR(pWnd->m_fnOldWndProc(hWnd, ulMsg, wParam, lParam));
1538
1539 rc = MRFROMSHORT(uItemCount);
1540 }
1541 break;
1542
1543 case WM_FORMATFRAME:
1544 /////////////////////////////////////////////////////////////////////////////////
1545 // Applications that subclass frame controls may find that the frame is already
1546 // subclassed the number of frame controls is variable.
1547 // The WM_FORMATFRAME and WM_QUERYFRAMECTLCOUNT messages must always be
1548 // subclassed by calling the previous window procedure and modifying its result.
1549 ////////////////////////////////////////////////////////////////////////////////
1550 {
1551 int nItemCount;
1552 int i;
1553 PSWP pSWP = NULL;
1554 SWP vSwpStb;
1555 RECTL vRectl;
1556 RECTL vRstb;
1557 int nHeight=0;
1558
1559 pSWP = (PSWP)PVOIDFROMMP(wParam);
1560 nItemCount = SHORT1FROMMR(pWnd->m_fnOldWndProc(hWnd, ulMsg, wParam, lParam));
1561 if(pWnd->m_frameStatusBar)
1562 {
1563 ::WinQueryWindowRect(pWnd->m_frameStatusBar->GetHWND(), &vRstb);
1564 pWnd->m_frameStatusBar->GetSize(NULL, &nHeight);
1565 ::WinQueryWindowRect(pWnd->m_hFrame, &vRectl);
1566 ::WinMapWindowPoints(pWnd->m_hFrame, HWND_DESKTOP, (PPOINTL)&vRectl, 2);
1567 vRstb = vRectl;
1568 ::WinCalcFrameRect(pWnd->m_hFrame, &vRectl, TRUE);
1569
1570 vSwpStb.x = vRectl.xLeft - vRstb.xLeft;
1571 vSwpStb.y = vRectl.yBottom - vRstb.yBottom;
1572 vSwpStb.cx = vRectl.xRight - vRectl.xLeft - 1; //?? -1 ??
1573 vSwpStb.cy = nHeight;
1574 vSwpStb.fl = SWP_SIZE |SWP_MOVE | SWP_SHOW;
1575 vSwpStb.hwnd = pWnd->m_frameStatusBar->GetHWND();
1576 vSwpStb.hwndInsertBehind = HWND_TOP;
1577 }
1578 ::WinQueryWindowRect(pWnd->m_hFrame, &vRectl);
1579 ::WinMapWindowPoints(pWnd->m_hFrame, HWND_DESKTOP, (PPOINTL)&vRectl, 2);
1580 ::WinCalcFrameRect(pWnd->m_hFrame, &vRectl, TRUE);
1581 ::WinMapWindowPoints(HWND_DESKTOP, pWnd->m_hFrame, (PPOINTL)&vRectl, 2);
1582 for(i = 0; i < nItemCount; i++)
1583 {
1584 if(pWnd->m_hWnd && pSWP[i].hwnd == pWnd->m_hWnd)
1585 {
1586 pSWP[i].x = vRectl.xLeft;
1587 pSWP[i].y = vRectl.yBottom + nHeight;
1588 pSWP[i].cx = vRectl.xRight - vRectl.xLeft;
1589 pSWP[i].cy = vRectl.yTop - vRectl.yBottom - nHeight;
1590 pSWP[i].fl = SWP_SIZE | SWP_MOVE | SWP_SHOW;
1591 pSWP[i].hwndInsertBehind = HWND_TOP;
1592 }
1593 }
1594 bProcessed = TRUE;
1595 rc = MRFROMSHORT(nItemCount);
1596 }
1597 break;
1598
1599 default:
1600 if(pWnd && pWnd->m_fnOldWndProc)
1601 rc = pWnd->m_fnOldWndProc(hWnd, ulMsg, wParam, lParam);
1602 else
1603 rc = ::WinDefWindowProc(hWnd, ulMsg, wParam, lParam);
1604 }
1605 return rc;
1606 } // end of wxFrameMainWndProc
1607
1608 MRESULT EXPENTRY wxFrameWndProc(
1609 HWND hWnd
1610 , ULONG ulMsg
1611 , MPARAM wParam
1612 , MPARAM lParam
1613 )
1614 {
1615 //
1616 // Trace all ulMsgs - useful for the debugging
1617 //
1618 HWND parentHwnd;
1619 wxFrame* pWnd = NULL;
1620
1621 parentHwnd = WinQueryWindow(hWnd,QW_PARENT);
1622 pWnd = (wxFrame*) wxFindWinFromHandle((WXHWND) hWnd);
1623
1624 //
1625 // When we get the first message for the HWND we just created, we associate
1626 // it with wxWindow stored in wxWndHook
1627 //
1628
1629 MRESULT rc = (MRESULT)0;
1630 bool bProcessed = FALSE;
1631
1632 //
1633 // Stop right here if we don't have a valid handle in our wxWindow object.
1634 //
1635 if (pWnd && !pWnd->GetHWND())
1636 {
1637 pWnd->SetHWND((WXHWND) hWnd);
1638 rc = pWnd->OS2DefWindowProc(ulMsg, wParam, lParam );
1639 pWnd->SetHWND(0);
1640 }
1641 else
1642 {
1643 if (pWnd)
1644 rc = pWnd->OS2WindowProc(ulMsg, wParam, lParam);
1645 else
1646 rc = ::WinDefWindowProc(hWnd, ulMsg, wParam, lParam);
1647 }
1648 return rc;
1649 } // end of wxFrameWndProc
1650
1651 MRESULT wxFrameOS2::OS2WindowProc(
1652 WXUINT uMessage
1653 , WXWPARAM wParam
1654 , WXLPARAM lParam
1655 )
1656 {
1657 MRESULT mRc = 0L;
1658 bool bProcessed = FALSE;
1659
1660 switch (uMessage)
1661 {
1662 case WM_CLOSE:
1663 //
1664 // If we can't close, tell the system that we processed the
1665 // message - otherwise it would close us
1666 //
1667 bProcessed = !Close();
1668 break;
1669
1670 case WM_PAINT:
1671 bProcessed = HandlePaint();
1672 mRc = (MRESULT)FALSE;
1673 break;
1674
1675 case WM_ERASEBACKGROUND:
1676 //
1677 // Returning TRUE to requests PM to paint the window background
1678 // in SYSCLR_WINDOW. We capture this here because the PS returned
1679 // in Frames is the PS for the whole frame, which we can't really
1680 // use at all. If you want to paint a different background, do it
1681 // in an OnPaint using a wxPaintDC.
1682 //
1683 mRc = (MRESULT)(TRUE);
1684 break;
1685
1686 case WM_COMMAND:
1687 {
1688 WORD wId;
1689 WORD wCmd;
1690 WXHWND hWnd;
1691
1692 UnpackCommand( (WXWPARAM)wParam
1693 ,(WXLPARAM)lParam
1694 ,&wId
1695 ,&hWnd
1696 ,&wCmd
1697 );
1698
1699 bProcessed = HandleCommand( wId
1700 ,wCmd
1701 ,(WXHWND)hWnd
1702 );
1703 }
1704 break;
1705
1706 case WM_MENUSELECT:
1707 {
1708 WXWORD wItem;
1709 WXWORD wFlags;
1710 WXHMENU hMenu;
1711
1712 UnpackMenuSelect( wParam
1713 ,lParam
1714 ,&wItem
1715 ,&wFlags
1716 ,&hMenu
1717 );
1718 bProcessed = HandleMenuSelect( wItem
1719 ,wFlags
1720 ,hMenu
1721 );
1722 mRc = (MRESULT)TRUE;
1723 }
1724 break;
1725
1726 case WM_SIZE:
1727 {
1728 SHORT nScxold = SHORT1FROMMP(wParam); // Old horizontal size.
1729 SHORT nScyold = SHORT2FROMMP(wParam); // Old vertical size.
1730 SHORT nScxnew = SHORT1FROMMP(lParam); // New horizontal size.
1731 SHORT nScynew = SHORT2FROMMP(lParam); // New vertical size.
1732
1733 lParam = MRFROM2SHORT( nScxnew - 20
1734 ,nScynew - 30
1735 );
1736 }
1737 bProcessed = HandleSize(LOWORD(lParam), HIWORD(lParam), (WXUINT)wParam);
1738 mRc = (MRESULT)FALSE;
1739 break;
1740
1741 case CM_QUERYDRAGIMAGE:
1742 {
1743 HPOINTER hIcon;
1744
1745 if (m_icon.Ok())
1746 hIcon = (HPOINTER)::WinSendMsg(GetHWND(), WM_QUERYICON, 0L, 0L);
1747 else
1748 hIcon = (HPOINTER)m_hDefaultIcon;
1749 mRc = (MRESULT)hIcon;
1750 bProcessed = mRc != 0;
1751 }
1752 break;
1753 }
1754
1755 if (!bProcessed )
1756 mRc = wxWindow::OS2WindowProc( uMessage
1757 ,wParam
1758 ,lParam
1759 );
1760 return (MRESULT)mRc;
1761 } // wxFrameOS2::OS2WindowProc
1762
1763 void wxFrameOS2::SetClient(WXHWND c_Hwnd)
1764 {
1765 // Duh...nothing to do under OS/2
1766 }
1767
1768 void wxFrameOS2::SetClient(
1769 wxWindow* pWindow
1770 )
1771 {
1772 wxWindow* pOldClient = this->GetClient();
1773 bool bClientHasFocus = pOldClient && (pOldClient == wxWindow::FindFocus());
1774
1775 if(pOldClient == pWindow) // nothing to do
1776 return;
1777 if(pWindow == NULL) // just need to remove old client
1778 {
1779 if(pOldClient == NULL) // nothing to do
1780 return;
1781
1782 if(bClientHasFocus )
1783 this->SetFocus();
1784
1785 pOldClient->Enable( FALSE );
1786 pOldClient->Show( FALSE );
1787 ::WinSetWindowUShort(pOldClient->GetHWND(), QWS_ID, (USHORT)pOldClient->GetId());
1788 // to avoid OS/2 bug need to update frame
1789 ::WinSendMsg((HWND)this->GetFrame(), WM_UPDATEFRAME, (MPARAM)~0, 0);
1790 return;
1791 }
1792
1793 //
1794 // Else need to change client
1795 //
1796 if(bClientHasFocus)
1797 this->SetFocus();
1798
1799 ::WinEnableWindowUpdate((HWND)GetHWND(), FALSE);
1800 if(pOldClient)
1801 {
1802 pOldClient->Enable(FALSE);
1803 pOldClient->Show(FALSE);
1804 ::WinSetWindowUShort(pOldClient->GetHWND(), QWS_ID, (USHORT)pOldClient->GetId());
1805 }
1806 pWindow->Reparent(this);
1807 ::WinSetWindowUShort(pWindow->GetHWND(), QWS_ID, FID_CLIENT);
1808 ::WinEnableWindowUpdate((HWND)GetHWND(), TRUE);
1809 pWindow->Enable();
1810 pWindow->Show(); // ensure client is showing
1811 if( this->IsShown() )
1812 {
1813 this->Show();
1814 ::WinSendMsg(m_hFrame, WM_UPDATEFRAME, (MPARAM)~0, 0);
1815 }
1816 }
1817
1818 wxWindow* wxFrameOS2::GetClient()
1819 {
1820 return wxFindWinFromHandle((WXHWND)::WinWindowFromID(m_hFrame, FID_CLIENT));
1821 }