]> git.saurik.com Git - wxWidgets.git/blob - src/os2/frame.cpp
Readded #if wxUSE_UNICODE to ~wxApp.
[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/setup.h"
17 #include "wx/frame.h"
18 #include "wx/menu.h"
19 #include "wx/app.h"
20 #include "wx/utils.h"
21 #include "wx/dialog.h"
22 #include "wx/settings.h"
23 #include "wx/dcclient.h"
24 #endif // WX_PRECOMP
25
26 #include "wx/os2/private.h"
27
28 #if wxUSE_STATUSBAR
29 #include "wx/statusbr.h"
30 #include "wx/generic/statusbr.h"
31 #endif // wxUSE_STATUSBAR
32
33 #if wxUSE_TOOLBAR
34 #include "wx/toolbar.h"
35 #endif // wxUSE_TOOLBAR
36
37 #include "wx/menuitem.h"
38 #include "wx/log.h"
39
40 // ----------------------------------------------------------------------------
41 // globals
42 // ----------------------------------------------------------------------------
43
44 extern wxWindowList wxModelessWindows;
45 extern wxList WXDLLEXPORT wxPendingDelete;
46 extern wxChar wxFrameClassName[];
47 extern wxMenu *wxCurrentPopupMenu;
48
49 // ----------------------------------------------------------------------------
50 // event tables
51 // ----------------------------------------------------------------------------
52
53 BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
54 EVT_ACTIVATE(wxFrame::OnActivate)
55 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
56 END_EVENT_TABLE()
57
58 IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow)
59
60 // ============================================================================
61 // implementation
62 // ============================================================================
63
64 // ----------------------------------------------------------------------------
65 // static class members
66 // ----------------------------------------------------------------------------
67
68 #if wxUSE_NATIVE_STATUSBAR
69 bool wxFrame::m_bUseNativeStatusBar = TRUE;
70 #else
71 bool wxFrame::m_bUseNativeStatusBar = FALSE;
72 #endif
73
74 // ----------------------------------------------------------------------------
75 // creation/destruction
76 // ----------------------------------------------------------------------------
77
78 void wxFrame::Init()
79 {
80 m_bIconized = FALSE;
81
82 #if wxUSE_TOOLTIPS
83 m_hWndToolTip = 0;
84 #endif
85 // Data to save/restore when calling ShowFullScreen
86 m_lFsStyle = 0L;
87 m_lFsOldWindowStyle = 0L;
88 m_nFsStatusBarFields = 0;
89 m_nFsStatusBarHeight = 0;
90 m_nFsToolBarHeight = 0;
91 m_bFsIsMaximized = FALSE;
92 m_bFsIsShowing = FALSE;
93 } // end of wxFrame::Init
94
95 bool wxFrame::Create(
96 wxWindow* pParent
97 , wxWindowID vId
98 , const wxString& rsTitle
99 , const wxPoint& rPos
100 , const wxSize& rSize
101 , long lulStyle
102 , const wxString& rsName
103 )
104 {
105 int nX = rPos.x;
106 int nY = rPos.y;
107 int nWidth = rSize.x;
108 int nHeight = rSize.y;
109
110 SetName(rsName);
111 m_windowStyle = lulStyle;
112 m_frameMenuBar = NULL;
113 m_frameToolBar = NULL;
114 m_frameStatusBar = NULL;
115
116 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
117
118 if (vId > -1 )
119 m_windowId = vId;
120 else
121 m_windowId = (int)NewControlId();
122
123 if (pParent)
124 pParent->AddChild(this);
125
126 m_bIconized = FALSE;
127
128 if ((m_windowStyle & wxFRAME_FLOAT_ON_PARENT) == 0)
129 pParent = NULL;
130
131 if (!pParent)
132 wxTopLevelWindows.Append(this);
133
134 OS2Create( m_windowId
135 ,pParent
136 ,wxFrameClassName
137 ,this
138 ,rsTitle
139 ,nX
140 ,nY
141 ,nWidth
142 ,nHeight
143 ,lulStyle
144 );
145
146 wxModelessWindows.Append(this);
147 return TRUE;
148 } // end of wxFrame::Create
149
150 wxFrame::~wxFrame()
151 {
152 m_isBeingDeleted = TRUE;
153 wxTopLevelWindows.DeleteObject(this);
154
155 DeleteAllBars();
156
157 if (wxTheApp && (wxTopLevelWindows.Number() == 0))
158 {
159 wxTheApp->SetTopWindow(NULL);
160
161 if (wxTheApp->GetExitOnFrameDelete())
162 {
163 ::WinPostMsg(GetHwnd(), WM_QUIT, 0, 0);
164 }
165 }
166 wxModelessWindows.DeleteObject(this);
167
168 //
169 // For some reason, wxWindows can activate another task altogether
170 // when a frame is destroyed after a modal dialog has been invoked.
171 // Try to bring the parent to the top.
172 //
173 // MT:Only do this if this frame is currently the active window, else weird
174 // things start to happen.
175 //
176 if (wxGetActiveWindow() == this)
177 {
178 if (GetParent() && GetParent()->GetHWND())
179 {
180 ::WinSetWindowPos( (HWND) GetParent()->GetHWND()
181 ,HWND_TOP
182 ,0
183 ,0
184 ,0
185 ,0
186 ,SWP_ZORDER
187 );
188 }
189 }
190 } // end of wxFrame::~wxFrame
191
192 //
193 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
194 //
195 void wxFrame::DoGetClientSize(
196 int* pX
197 , int* pY
198 ) const
199 {
200 //
201 // OS/2 PM's coordinates go from bottom-left not
202 // top-left thus the += instead of the -=
203 //
204 RECTL vRect;
205 HWND hWndClient;
206
207 //
208 // PM has no GetClientRect that inherantly knows about the client window
209 // We have to explicitly go fetch it!
210 //
211 hWndClient = ::WinWindowFromID(GetHwnd(), FID_CLIENT);
212 ::WinQueryWindowRect(hWndClient, &vRect);
213
214 #if wxUSE_STATUSBAR
215 if ( GetStatusBar() )
216 {
217 int nStatusX;
218 int nStatusY;
219
220 GetStatusBar()->GetClientSize( &nStatusX
221 ,&nStatusY
222 );
223 vRect.yBottom += nStatusY;
224 }
225 #endif // wxUSE_STATUSBAR
226
227 wxPoint vPoint(GetClientAreaOrigin());
228
229 vRect.yBottom += vPoint.y;
230 vRect.xRight -= vPoint.x;
231
232 if (pX)
233 *pX = vRect.xRight;
234 if (pY)
235 *pY = vRect.yBottom;
236 } // end of wxFrame::DoGetClientSize
237
238 //
239 // Set the client size (i.e. leave the calculation of borders etc.
240 // to wxWindows)
241 //
242 void wxFrame::DoSetClientSize(
243 int nWidth
244 , int nHeight
245 )
246 {
247 HWND hWnd = GetHwnd();
248 HWND hWndClient;
249 RECTL vRect;
250 RECTL vRect2;
251
252 hWndClient = ::WinWindowFromID(GetHwnd(), FID_CLIENT);
253 ::WinQueryWindowRect(hWndClient, &vRect);
254
255 ::WinQueryWindowRect(hWnd, &vRect2);
256
257 //
258 // Find the difference between the entire window (title bar and all)
259 // and the client area; add this to the new client size to move the
260 // window. Remember OS/2's backwards y coord system!
261 //
262 int nActualWidth = vRect2.xRight - vRect2.xLeft - vRect.xRight + nWidth;
263 int nActualHeight = vRect2.yTop + vRect2.yTop - vRect.yTop + nHeight;
264
265 #if wxUSE_STATUSBAR
266 if ( GetStatusBar() )
267 {
268 int nStatusX;
269 int nStatusY;
270
271 GetStatusBar()->GetClientSize( &nStatusX
272 ,&nStatusY
273 );
274 nActualHeight += nStatusY;
275 }
276 #endif // wxUSE_STATUSBAR
277
278 wxPoint vPoint(GetClientAreaOrigin());
279 nActualWidth += vPoint.y;
280 nActualHeight += vPoint.x;
281
282 POINTL vPointl;
283
284 vPointl.x = vRect2.xLeft;
285 vPoint.y = vRect2.yTop;
286
287 ::WinSetWindowPos( hWnd
288 ,HWND_TOP
289 ,vPointl.x
290 ,vPointl.y
291 ,nActualWidth
292 ,nActualHeight
293 ,SWP_MOVE | SWP_SIZE | SWP_SHOW
294 );
295
296 wxSizeEvent vEvent( wxSize( nWidth
297 ,nHeight
298 )
299 ,m_windowId
300 );
301 vEvent.SetEventObject(this);
302 GetEventHandler()->ProcessEvent(vEvent);
303 } // end of wxFrame::DoSetClientSize
304
305 void wxFrame::DoGetSize(
306 int* pWidth
307 , int* pHeight
308 ) const
309 {
310 RECTL vRect;
311
312 ::WinQueryWindowRect(GetHwnd(), &vRect);
313 *pWidth = vRect.xRight - vRect.xLeft;
314 *pHeight = vRect.yTop - vRect.yBottom;
315 } // end of wxFrame::DoGetSize
316
317 void wxFrame::DoGetPosition(
318 int* pX
319 , int* pY
320 ) const
321 {
322 RECTL vRect;
323 POINTL vPoint;
324
325 ::WinQueryWindowRect(GetHwnd(), &vRect);
326 vPoint.x = vRect.xLeft;
327
328 //
329 // OS/2 is backwards [WIN32 it is vRect.yTop]
330 //
331 vPoint.y = vRect.yBottom;
332
333 *pX = vPoint.x;
334 *pY = vPoint.y;
335 } // end of wxFrame::DoGetPosition
336
337 // ----------------------------------------------------------------------------
338 // variations around ::ShowWindow()
339 // ----------------------------------------------------------------------------
340
341 void wxFrame::DoShowWindow(
342 int bShowCmd
343 )
344 {
345 HWND hClient;
346 HWND hTitlebar = NULLHANDLE;
347 HWND hHScroll = NULLHANDLE;
348 HWND hVScroll = NULLHANDLE;
349 HWND hMenuBar = NULLHANDLE;
350 SWP vSwp;
351 SWP vSwpTitlebar;
352 SWP vSwpVScroll;
353 SWP vSwpHScroll;
354 SWP vSwpMenu;
355
356 //
357 // Send anything to initialize the frame
358 //
359 WinQueryWindowPos(GetHwnd(), &vSwp);
360 hClient = WinWindowFromID(GetHwnd(), FID_CLIENT);
361 hTitlebar = WinWindowFromID(GetHwnd(), FID_TITLEBAR);
362 WinQueryWindowPos(hTitlebar, &vSwpTitlebar);
363 hHScroll = WinWindowFromID(GetHwnd(), FID_HORZSCROLL);
364 WinQueryWindowPos(hHScroll, &vSwpHScroll);
365 hVScroll = WinWindowFromID(GetHwnd(), FID_VERTSCROLL);
366 WinQueryWindowPos(hVScroll, &vSwpVScroll);
367 hMenuBar = WinWindowFromID(GetHwnd(), FID_MENU);
368 WinQueryWindowPos(hMenuBar, &vSwpMenu);
369 WinSetWindowPos( hClient
370 ,HWND_TOP
371 ,SV_CXSIZEBORDER
372 ,(SV_CYSIZEBORDER - 1) + vSwpHScroll.cy
373 ,vSwp.cx - ((SV_CXSIZEBORDER * 2) + vSwpVScroll.cx)
374 ,vSwp.cy - ((SV_CYSIZEBORDER * 2) + 1 + vSwpTitlebar.cy + vSwpMenu.cy + vSwpHScroll.cy)
375 ,SWP_SIZE | SWP_MOVE
376 );
377 ::WinShowWindow(GetHwnd(), (BOOL)bShowCmd);
378 ::WinShowWindow(hClient, (BOOL)bShowCmd);
379 } // end of wxFrame::DoShowWindow
380
381 bool wxFrame::Show(
382 bool bShow
383 )
384 {
385 SWP vSwp;
386
387 DoShowWindow((int)bShow);
388
389 if (bShow)
390 {
391 wxActivateEvent vEvent(wxEVT_ACTIVATE, TRUE, m_windowId);
392
393 ::WinQueryWindowPos(GetHwnd(), &vSwp);
394 m_bIconized = vSwp.fl & SWP_MINIMIZE;
395 ::WinEnableWindow(GetHwnd(), TRUE);
396 vEvent.SetEventObject(this);
397 GetEventHandler()->ProcessEvent(vEvent);
398 }
399 else
400 {
401 //
402 // Try to highlight the correct window (the parent)
403 //
404 if (GetParent())
405 {
406 HWND hWndParent = GetHwndOf(GetParent());
407
408 ::WinQueryWindowPos(hWndParent, &vSwp);
409 m_bIconized = vSwp.fl & SWP_MINIMIZE;
410 if (hWndParent)
411 ::WinSetWindowPos( hWndParent
412 ,HWND_TOP
413 ,vSwp.x
414 ,vSwp.y
415 ,vSwp.cx
416 ,vSwp.cy
417 ,SWP_ZORDER | SWP_ACTIVATE | SWP_SHOW | SWP_MOVE
418 );
419 ::WinEnableWindow(hWndParent, TRUE);
420 }
421 }
422 return TRUE;
423 } // end of wxFrame::Show
424
425 void wxFrame::Iconize(
426 bool bIconize
427 )
428 {
429 DoShowWindow(bIconize ? SWP_MINIMIZE : SWP_RESTORE);
430 } // end of wxFrame::Iconize
431
432 void wxFrame::Maximize(
433 bool bMaximize)
434 {
435 DoShowWindow(bMaximize ? SWP_MAXIMIZE : SWP_RESTORE);
436 } // end of wxFrame::Maximize
437
438 void wxFrame::Restore()
439 {
440 DoShowWindow(SWP_RESTORE);
441 } // end of wxFrame::Restore
442
443 bool wxFrame::IsIconized() const
444 {
445 SWP vSwp;
446 bool bIconic;
447
448 ::WinQueryWindowPos(GetHwnd(), &vSwp);
449
450 if (vSwp.fl & SWP_MINIMIZE)
451 ((wxFrame*)this)->m_bIconized = TRUE;
452 else
453 ((wxFrame*)this)->m_bIconized = FALSE;
454 return m_bIconized;
455 } // end of wxFrame::IsIconized
456
457 // Is it maximized?
458 bool wxFrame::IsMaximized() const
459 {
460 SWP vSwp;
461 bool bIconic;
462
463 ::WinQueryWindowPos(GetHwnd(), &vSwp);
464 return (vSwp.fl & SWP_MAXIMIZE);
465 } // end of wxFrame::IsMaximized
466
467 void wxFrame::SetIcon(
468 const wxIcon& rIcon
469 )
470 {
471 wxFrameBase::SetIcon(rIcon);
472
473 if ((m_icon.GetHICON()) != NULLHANDLE)
474 {
475 ::WinSendMsg( GetHwnd()
476 ,WM_SETICON
477 ,(MPARAM)((HPOINTER)m_icon.GetHICON())
478 ,NULL
479 );
480 ::WinSendMsg( GetHwnd()
481 ,WM_UPDATEFRAME
482 ,(MPARAM)FCF_ICON
483 ,(MPARAM)0
484 );
485 }
486 } // end of wxFrame::SetIcon
487
488 #if wxUSE_STATUSBAR
489 wxStatusBar* wxFrame::OnCreateStatusBar(
490 int nNumber
491 , long lulStyle
492 , wxWindowID vId
493 , const wxString& rName
494 )
495 {
496 wxStatusBar* pStatusBar = NULL;
497
498 pStatusBar = wxFrameBase::OnCreateStatusBar( nNumber
499 ,lulStyle
500 ,vId
501 ,rName
502 );
503 return pStatusBar;
504 } // end of wxFrame::OnCreateStatusBar
505
506 void wxFrame::PositionStatusBar()
507 {
508 //
509 // Native status bar positions itself
510 //
511 if (m_frameStatusBar)
512 {
513 int nWidth;
514 int nHeight;
515 int nStatbarWidth;
516 int nStatbarHeight;
517 HWND hWndClient;
518 RECTL vRect;
519
520 hWndClient = ::WinWindowFromID(GetHwnd(), FID_CLIENT);
521 ::WinQueryWindowRect(hWndClient, &vRect);
522 nWidth = vRect.xRight - vRect.xLeft;
523 nHeight = vRect.yTop - vRect.yBottom;
524
525 m_frameStatusBar->GetSize( &nStatbarWidth
526 ,&nStatbarHeight
527 );
528
529 //
530 // Since we wish the status bar to be directly under the client area,
531 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
532 //
533 m_frameStatusBar->SetSize( 0
534 ,nHeight
535 ,nWidth
536 ,nStatbarHeight
537 );
538 }
539 } // end of wxFrame::PositionStatusBar
540 #endif // wxUSE_STATUSBAR
541
542 void wxFrame::DetachMenuBar()
543 {
544 if (m_frameMenuBar)
545 {
546 m_frameMenuBar->Detach();
547 m_frameMenuBar = NULL;
548 }
549 } // end of wxFrame::DetachMenuBar
550
551 void wxFrame::SetMenuBar(
552 wxMenuBar* pMenuBar
553 )
554 {
555 if (!pMenuBar)
556 {
557 DetachMenuBar();
558 return;
559 }
560
561 m_frameMenuBar = NULL;
562
563 // Can set a menubar several times.
564 // TODO: how to prevent a memory leak if you have a currently-unattached
565 // menubar? wxWindows assumes that the frame will delete the menu (otherwise
566 // there are problems for MDI).
567 if (pMenuBar->GetHMenu())
568 {
569 m_hMenu = pMenuBar->GetHMenu();
570 }
571 else
572 {
573 pMenuBar->Detach();
574
575 m_hMenu = pMenuBar->Create();
576
577 if (!m_hMenu)
578 return;
579 }
580
581 InternalSetMenuBar();
582
583 m_frameMenuBar = pMenuBar;
584 pMenuBar->Attach(this);
585 } // end of wxFrame::SetMenuBar
586
587 void wxFrame::InternalSetMenuBar()
588 {
589 WinSendMsg((HWND)GetHwnd(), WM_UPDATEFRAME, (MPARAM)FCF_MENU, (MPARAM)0);
590 } // end of wxFrame::InternalSetMenuBar
591
592 //
593 // Responds to colour changes, and passes event on to children
594 //
595 void wxFrame::OnSysColourChanged(
596 wxSysColourChangedEvent& rEvent
597 )
598 {
599 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
600 Refresh();
601
602 if (m_frameStatusBar)
603 {
604 wxSysColourChangedEvent vEvent2;
605
606 vEvent2.SetEventObject(m_frameStatusBar);
607 m_frameStatusBar->GetEventHandler()->ProcessEvent(vEvent2);
608 }
609
610 //
611 // Propagate the event to the non-top-level children
612 //
613 wxWindow::OnSysColourChanged(rEvent);
614 } // end of wxFrame::OnSysColourChanged
615
616 // Pass TRUE to show full screen, FALSE to restore.
617 bool wxFrame::ShowFullScreen(
618 bool bShow
619 , long lStyle
620 )
621 {
622 /*
623 // TODO
624 if (show)
625 {
626 if (IsFullScreen())
627 return FALSE;
628
629 m_fsIsShowing = TRUE;
630 m_fsStyle = style;
631
632 wxToolBar *theToolBar = GetToolBar();
633 wxStatusBar *theStatusBar = GetStatusBar();
634
635 int dummyWidth;
636
637 if (theToolBar)
638 theToolBar->GetSize(&dummyWidth, &m_fsToolBarHeight);
639 if (theStatusBar)
640 theStatusBar->GetSize(&dummyWidth, &m_fsStatusBarHeight);
641
642 // zap the toolbar, menubar, and statusbar
643
644 if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar)
645 {
646 theToolBar->SetSize(-1,0);
647 theToolBar->Show(FALSE);
648 }
649
650 if (style & wxFULLSCREEN_NOMENUBAR)
651 SetMenu((HWND)GetHWND(), (HMENU) NULL);
652
653 // Save the number of fields in the statusbar
654 if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar)
655 {
656 m_fsStatusBarFields = theStatusBar->GetFieldsCount();
657 SetStatusBar((wxStatusBar*) NULL);
658 delete theStatusBar;
659 }
660 else
661 m_fsStatusBarFields = 0;
662
663 // zap the frame borders
664
665 // save the 'normal' window style
666 m_fsOldWindowStyle = GetWindowLong((HWND)GetHWND(), GWL_STYLE);
667
668 // save the old position, width & height, maximize state
669 m_fsOldSize = GetRect();
670 m_fsIsMaximized = IsMaximized();
671
672 // decide which window style flags to turn off
673 LONG newStyle = m_fsOldWindowStyle;
674 LONG offFlags = 0;
675
676 if (style & wxFULLSCREEN_NOBORDER)
677 offFlags |= WS_BORDER;
678 if (style & wxFULLSCREEN_NOCAPTION)
679 offFlags |= (WS_CAPTION | WS_SYSMENU);
680
681 newStyle &= (~offFlags);
682
683 // change our window style to be compatible with full-screen mode
684 SetWindowLong((HWND)GetHWND(), GWL_STYLE, newStyle);
685
686 // resize to the size of the desktop
687 int width, height;
688
689 RECT rect;
690 ::GetWindowRect(GetDesktopWindow(), &rect);
691 width = rect.right - rect.left;
692 height = rect.bottom - rect.top;
693
694 SetSize(width, height);
695
696 // now flush the window style cache and actually go full-screen
697 SetWindowPos((HWND)GetHWND(), HWND_TOP, 0, 0, width, height, SWP_FRAMECHANGED);
698
699 wxSizeEvent event(wxSize(width, height), GetId());
700 GetEventHandler()->ProcessEvent(event);
701
702 return TRUE;
703 }
704 else
705 {
706 if (!IsFullScreen())
707 return FALSE;
708
709 m_fsIsShowing = FALSE;
710
711 wxToolBar *theToolBar = GetToolBar();
712
713 // restore the toolbar, menubar, and statusbar
714 if (theToolBar && (m_fsStyle & wxFULLSCREEN_NOTOOLBAR))
715 {
716 theToolBar->SetSize(-1, m_fsToolBarHeight);
717 theToolBar->Show(TRUE);
718 }
719
720 if ((m_fsStyle & wxFULLSCREEN_NOSTATUSBAR) && (m_fsStatusBarFields > 0))
721 {
722 CreateStatusBar(m_fsStatusBarFields);
723 PositionStatusBar();
724 }
725
726 if ((m_fsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0))
727 SetMenu((HWND)GetHWND(), (HMENU)m_hMenu);
728
729 Maximize(m_fsIsMaximized);
730 SetWindowLong((HWND)GetHWND(),GWL_STYLE, m_fsOldWindowStyle);
731 SetWindowPos((HWND)GetHWND(),HWND_TOP,m_fsOldSize.x, m_fsOldSize.y,
732 m_fsOldSize.width, m_fsOldSize.height, SWP_FRAMECHANGED);
733
734 return TRUE;
735 }
736 */
737 return TRUE;
738 } // end of wxFrame::ShowFullScreen
739
740 //
741 // Frame window
742 //
743 bool wxFrame::OS2Create(
744 int nId
745 , wxWindow* pParent
746 , const wxChar* zWclass
747 , wxWindow* pWxWin
748 , const wxChar* zTitle
749 , int nX
750 , int nY
751 , int nWidth
752 , int nHeight
753 , long ulStyle
754 )
755 {
756 ULONG ulCreateFlags = 0L;
757 ULONG ulStyleFlags = 0L;
758 ULONG ulExtraFlags = 0L;
759 FRAMECDATA vFrameCtlData;
760 HWND hParent = NULLHANDLE;
761 HWND hClient = NULLHANDLE;
762 HWND hTitlebar = NULLHANDLE;
763 HWND hHScroll = NULLHANDLE;
764 HWND hVScroll = NULLHANDLE;
765 HWND hMenuBar = NULLHANDLE;
766 HWND hMenu1 = NULLHANDLE;
767 HWND hMenu2 = NULLHANDLE;
768 HWND hFrame = NULLHANDLE;
769 SWP vSwp;
770 SWP vSwpTitlebar;
771 SWP vSwpVScroll;
772 SWP vSwpHScroll;
773 SWP vSwpMenu;
774 RGB2 vRgb;
775
776 m_hDefaultIcon = (WXHICON) (wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON : wxDEFAULT_FRAME_ICON);
777 memset(&vSwp, '\0', sizeof(SWP));
778 memset(&vSwpTitlebar, '\0', sizeof(SWP));
779 memset(&vSwpVScroll, '\0', sizeof(SWP));
780 memset(&vSwpHScroll, '\0', sizeof(SWP));
781
782 if (pParent)
783 hParent = GetWinHwnd(pParent);
784 else
785 hParent = HWND_DESKTOP;
786
787 if (ulStyle == wxDEFAULT_FRAME_STYLE)
788 ulCreateFlags = FCF_SIZEBORDER | FCF_TITLEBAR | FCF_SYSMENU |
789 FCF_MINMAX | FCF_VERTSCROLL | FCF_HORZSCROLL | FCF_TASKLIST;
790 else
791 {
792 if ((ulStyle & wxCAPTION) == wxCAPTION)
793 ulCreateFlags = FCF_TASKLIST;
794 else
795 ulCreateFlags = FCF_NOMOVEWITHOWNER;
796
797 if (ulStyle & wxMINIMIZE_BOX)
798 ulCreateFlags |= FCF_MINBUTTON;
799 if (ulStyle & wxMAXIMIZE_BOX)
800 ulCreateFlags |= FCF_MAXBUTTON;
801 if (ulStyle & wxTHICK_FRAME)
802 ulCreateFlags |= FCF_DLGBORDER;
803 if (ulStyle & wxSYSTEM_MENU)
804 ulCreateFlags |= FCF_SYSMENU;
805 if (ulStyle & wxCAPTION)
806 ulCreateFlags |= FCF_TASKLIST;
807 if (ulStyle & wxCLIP_CHILDREN)
808 {
809 // Invalid for frame windows under PM
810 }
811
812 if (ulStyle & wxTINY_CAPTION_VERT)
813 ulCreateFlags |= FCF_TASKLIST;
814 if (ulStyle & wxTINY_CAPTION_HORIZ)
815 ulCreateFlags |= FCF_TASKLIST;
816
817 if ((ulStyle & wxTHICK_FRAME) == 0)
818 ulCreateFlags |= FCF_BORDER;
819 if (ulStyle & wxFRAME_TOOL_WINDOW)
820 ulExtraFlags = kFrameToolWindow;
821
822 if (ulStyle & wxSTAY_ON_TOP)
823 ulCreateFlags |= FCF_SYSMODAL;
824 }
825 if ((ulStyle & wxMINIMIZE) || (ulStyle & wxICONIZE))
826 ulStyleFlags |= WS_MINIMIZED;
827 if (ulStyle & wxMAXIMIZE)
828 ulStyleFlags |= WS_MAXIMIZED;
829
830 //
831 // Clear the visible flag, we always call show
832 //
833 ulStyleFlags &= (unsigned long)~WS_VISIBLE;
834 m_bIconized = FALSE;
835
836 //
837 // Set the frame control block
838 //
839 vFrameCtlData.cb = sizeof(vFrameCtlData);
840 vFrameCtlData.flCreateFlags = ulCreateFlags;
841 vFrameCtlData.hmodResources = 0L;
842 vFrameCtlData.idResources = 0;
843
844 //
845 // Create the frame window
846 //
847 if (!wxWindow::OS2Create( hParent
848 ,WC_FRAME
849 ,zTitle
850 ,ulStyleFlags
851 ,(long)nX
852 ,(long)nY
853 ,(long)nWidth
854 ,(long)nHeight
855 ,NULLHANDLE
856 ,HWND_TOP
857 ,(long)nId
858 ,(void*)&vFrameCtlData
859 ,NULL
860 ))
861 {
862 return FALSE;
863 }
864
865 //
866 // Create the client window. We must call the API from here rather than
867 // the static base class create because we need a separate handle
868 //
869 if ((hClient = ::WinCreateWindow( hFrame // Frame is parent
870 ,wxFrameClassName
871 ,NULL // Window title
872 ,0 // No styles
873 ,0, 0, 0, 0 // Window position
874 ,NULLHANDLE // Owner
875 ,HWND_TOP // Sibling
876 ,FID_CLIENT // standard client ID
877 ,NULL // Creation data
878 ,NULL // Window Pres Params
879 )) == 0L)
880 {
881 return FALSE;
882 }
883 //
884 // Send anything to initialize the frame
885 //
886 ::WinSendMsg( hFrame
887 ,WM_UPDATEFRAME
888 ,(MPARAM)FCF_TASKLIST
889 ,(MPARAM)0
890 );
891
892 //
893 // Now size everything. If adding a menu the client will need to be resized.
894 //
895 if (!::WinSetWindowPos( hFrame
896 ,HWND_TOP
897 ,nX
898 ,nY
899 ,nWidth
900 ,nHeight
901 ,SWP_SIZE | SWP_MOVE | SWP_ACTIVATE
902 ))
903 return FALSE;
904
905 WinQueryWindowPos(hFrame, &vSwp);
906
907 //
908 // Set the client window's background, otherwise it is transparent!
909 //
910 wxColour vColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW);
911
912 vRgb.bRed = (BYTE)vColour.Red();
913 vRgb.bGreen = (BYTE)vColour.Green();
914 vRgb.bBlue = (BYTE)vColour.Blue();
915 WinSetPresParam( hClient
916 ,PP_BACKGROUNDCOLOR
917 ,(ULONG)sizeof(RGB2)
918 ,(PVOID)&vRgb
919 );
920 if (ulCreateFlags & FCF_TITLEBAR)
921 {
922 hTitlebar = WinWindowFromID(hFrame, FID_TITLEBAR);
923 WinQueryWindowPos(hTitlebar, &vSwpTitlebar);
924 }
925 if (ulCreateFlags & FCF_HORZSCROLL)
926 {
927 hHScroll = WinWindowFromID(hFrame, FID_HORZSCROLL);
928 WinQueryWindowPos(hHScroll, &vSwpHScroll);
929 }
930 if (ulCreateFlags & FCF_VERTSCROLL)
931 {
932 hVScroll = WinWindowFromID(hFrame, FID_VERTSCROLL);
933 WinQueryWindowPos(hVScroll, &vSwpVScroll);
934 }
935 if (!::WinSetWindowPos( hClient
936 ,HWND_TOP
937 ,SV_CXSIZEBORDER
938 ,(SV_CYSIZEBORDER - 1) + vSwpHScroll.cy
939 ,vSwp.cx - ((SV_CXSIZEBORDER * 2) + vSwpVScroll.cx)
940 ,vSwp.cy - ((SV_CYSIZEBORDER * 2) + 1 + vSwpTitlebar.cy + vSwpHScroll.cy)
941 ,SWP_SIZE | SWP_MOVE
942 ))
943 return FALSE;
944 WinQueryWindowPos(hClient, &vSwp);
945 ::WinShowWindow(hClient, TRUE);
946 return TRUE;
947 } // end of wxFrame::OS2Create
948
949 //
950 // Default activation behaviour - set the focus for the first child
951 // subwindow found.
952 //
953 void wxFrame::OnActivate(
954 wxActivateEvent& rEvent
955 )
956 {
957 for (wxWindowList::Node* pNode = GetChildren().GetFirst();
958 pNode;
959 pNode = pNode->GetNext())
960 {
961 // FIXME all this is totally bogus - we need to do the same as wxPanel,
962 // but how to do it without duplicating the code?
963
964 // restore focus
965 wxWindow* pChild = pNode->GetData();
966
967 if (!pChild->IsTopLevel()
968 #if wxUSE_TOOLBAR
969 && !wxDynamicCast(pChild, wxToolBar)
970 #endif // wxUSE_TOOLBAR
971 #if wxUSE_STATUSBAR
972 && !wxDynamicCast(pChild, wxStatusBar)
973 #endif // wxUSE_STATUSBAR
974 )
975 {
976 pChild->SetFocus();
977 return;
978 }
979 }
980 } // end of wxFrame::OnActivate
981
982 // ----------------------------------------------------------------------------
983 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
984 // from the client area, so the client area is what's really available for the
985 // frame contents
986 // ----------------------------------------------------------------------------
987
988 // Checks if there is a toolbar, and returns the first free client position
989 wxPoint wxFrame::GetClientAreaOrigin() const
990 {
991 wxPoint vPoint(0, 0);
992
993 if (GetToolBar())
994 {
995 int nWidth;
996 int nHeight;
997
998 GetToolBar()->GetSize( &nWidth
999 ,&nHeight
1000 );
1001
1002 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
1003 {
1004 vPoint.x += nWidth;
1005 }
1006 else
1007 {
1008 // PM is backwards from windows
1009 vPoint.y += nHeight;
1010 }
1011 }
1012 return vPoint;
1013 } // end of wxFrame::GetClientAreaOrigin
1014
1015 // ----------------------------------------------------------------------------
1016 // tool/status bar stuff
1017 // ----------------------------------------------------------------------------
1018
1019 #if wxUSE_TOOLBAR
1020
1021 wxToolBar* wxFrame::CreateToolBar(
1022 long lStyle
1023 , wxWindowID vId
1024 , const wxString& rName
1025 )
1026 {
1027 if (wxFrameBase::CreateToolBar( lStyle
1028 ,vId
1029 ,rName
1030 ))
1031 {
1032 PositionToolBar();
1033 }
1034 return m_frameToolBar;
1035 } // end of wxFrame::CreateToolBar
1036
1037 void wxFrame::PositionToolBar()
1038 {
1039 HWND hWndClient;
1040 RECTL vRect;
1041
1042 hWndClient = ::WinWindowFromID(GetHwnd(), FID_CLIENT);
1043 ::WinQueryWindowRect(hWndClient, &vRect);
1044
1045 #if wxUSE_STATUSBAR
1046 if (GetStatusBar())
1047 {
1048 int nStatusX;
1049 int nStatusY;
1050
1051 GetStatusBar()->GetClientSize( &nStatusX
1052 ,&nStatusY
1053 );
1054 // PM is backwards from windows
1055 vRect.yBottom += nStatusY;
1056 }
1057 #endif // wxUSE_STATUSBAR
1058
1059 if ( GetToolBar() )
1060 {
1061 int nToolbarWidth;
1062 int nToolbarHeight;
1063
1064 GetToolBar()->GetSize( &nToolbarWidth
1065 ,&nToolbarHeight
1066 );
1067
1068 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
1069 {
1070 nToolbarHeight = vRect.yBottom;
1071 }
1072 else
1073 {
1074 nToolbarWidth = vRect.xRight;
1075 }
1076
1077 //
1078 // Use the 'real' PM position here
1079 //
1080 GetToolBar()->SetSize( 0
1081 ,0
1082 ,nToolbarWidth
1083 ,nToolbarHeight
1084 ,wxSIZE_NO_ADJUSTMENTS
1085 );
1086 }
1087 } // end of wxFrame::PositionToolBar
1088 #endif // wxUSE_TOOLBAR
1089
1090 // ----------------------------------------------------------------------------
1091 // frame state (iconized/maximized/...)
1092 // ----------------------------------------------------------------------------
1093
1094 //
1095 // propagate our state change to all child frames: this allows us to emulate X
1096 // Windows behaviour where child frames float independently of the parent one
1097 // on the desktop, but are iconized/restored with it
1098 //
1099 void wxFrame::IconizeChildFrames(
1100 bool bIconize
1101 )
1102 {
1103 for (wxWindowList::Node* pNode = GetChildren().GetFirst();
1104 pNode;
1105 pNode = pNode->GetNext() )
1106 {
1107 wxWindow* pWin = pNode->GetData();
1108
1109 if (pWin->IsKindOf(CLASSINFO(wxFrame)) )
1110 {
1111 ((wxFrame *)pWin)->Iconize(bIconize);
1112 }
1113 }
1114 } // end of wxFrame::IconizeChildFrames
1115
1116 // ===========================================================================
1117 // message processing
1118 // ===========================================================================
1119
1120 // ---------------------------------------------------------------------------
1121 // preprocessing
1122 // ---------------------------------------------------------------------------
1123 bool wxFrame::OS2TranslateMessage(
1124 WXMSG* pMsg
1125 )
1126 {
1127 if (wxWindow::OS2TranslateMessage(pMsg))
1128 return TRUE;
1129 //
1130 // try the menu bar accels
1131 //
1132 wxMenuBar* pMenuBar = GetMenuBar();
1133
1134 if (!pMenuBar )
1135 return FALSE;
1136
1137 const wxAcceleratorTable& rAcceleratorTable = pMenuBar->GetAccelTable();
1138 return rAcceleratorTable.Translate(this, pMsg);
1139 } // end of wxFrame::OS2TranslateMessage
1140
1141 // ---------------------------------------------------------------------------
1142 // our private (non virtual) message handlers
1143 // ---------------------------------------------------------------------------
1144 bool wxFrame::HandlePaint()
1145 {
1146 RECTL vRect;
1147
1148 if (::WinQueryUpdateRect(GetHwnd(), &vRect))
1149 {
1150 if (m_bIconized)
1151 {
1152 //
1153 // Icons in PM are the same as "pointers"
1154 //
1155 HPOINTER hIcon;
1156
1157 if (m_icon.Ok())
1158 hIcon = (HPOINTER)::WinSendMsg(GetHwnd(), WM_QUERYICON, 0L, 0L);
1159 else
1160 hIcon = (HPOINTER)m_hDefaultIcon;
1161
1162 //
1163 // Hold a pointer to the dc so long as the OnPaint() message
1164 // is being processed
1165 //
1166 RECTL vRect2;
1167 HPS hPs = ::WinBeginPaint(GetHwnd(), NULLHANDLE, &vRect2);
1168
1169 //
1170 // Erase background before painting or we get white background
1171 //
1172 OS2DefWindowProc(WM_ERASEBACKGROUND, (MPARAM)hPs, (MPARAM)&vRect2);
1173
1174 if (hIcon)
1175 {
1176 HWND hWndClient;
1177 RECTL vRect3;
1178
1179 hWndClient = ::WinWindowFromID(GetHwnd(), FID_CLIENT);
1180 ::WinQueryWindowRect(hWndClient, &vRect3);
1181
1182 static const int nIconWidth = 32;
1183 static const int nIconHeight = 32;
1184 int nIconX = (int)((vRect3.xRight - nIconWidth)/2);
1185 int nIconY = (int)((vRect3.yBottom + nIconHeight)/2);
1186
1187 ::WinDrawPointer(hPs, nIconX, nIconY, hIcon, DP_NORMAL);
1188 }
1189 ::WinEndPaint(hPs);
1190 return TRUE;
1191 }
1192 else
1193 {
1194 return wxWindow::HandlePaint();
1195 }
1196 }
1197 else
1198 {
1199 // nothing to paint - processed
1200 return TRUE;
1201 }
1202 return FALSE;
1203 } // end of wxFrame::HandlePaint
1204
1205 bool wxFrame::HandleSize(
1206 int nX
1207 , int nY
1208 , WXUINT nId
1209 )
1210 {
1211 bool bProcessed = FALSE;
1212
1213 switch (nId)
1214 {
1215 case kSizeNormal:
1216 //
1217 // Only do it it if we were iconized before, otherwise resizing the
1218 // parent frame has a curious side effect of bringing it under it's
1219 // children
1220 if (!m_bIconized )
1221 break;
1222
1223 //
1224 // restore all child frames too
1225 //
1226 IconizeChildFrames(FALSE);
1227
1228 //
1229 // fall through
1230 //
1231
1232 case kSizeMax:
1233 m_bIconized = FALSE;
1234 break;
1235
1236 case kSizeMin:
1237 //
1238 // Iconize all child frames too
1239 //
1240 IconizeChildFrames(TRUE);
1241 m_bIconized = TRUE;
1242 break;
1243 }
1244
1245 if (!m_bIconized)
1246 {
1247 //
1248 // forward WM_SIZE to status bar control
1249 //
1250 #if wxUSE_NATIVE_STATUSBAR
1251 if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)))
1252 {
1253 wxSizeEvent vEvent( wxSize( nX
1254 ,nY
1255 )
1256 ,m_frameStatusBar->GetId()
1257 );
1258
1259 vEvent.SetEventObject(m_frameStatusBar);
1260 m_frameStatusBar->OnSize(vEvent);
1261 }
1262 #endif // wxUSE_NATIVE_STATUSBAR
1263
1264 PositionStatusBar();
1265 PositionToolBar();
1266 wxSizeEvent vEvent( wxSize( nX
1267 ,nY
1268 )
1269 ,m_windowId
1270 );
1271
1272 vEvent.SetEventObject(this);
1273 bProcessed = GetEventHandler()->ProcessEvent(vEvent);
1274 }
1275 return bProcessed;
1276 } // end of wxFrame::HandleSize
1277
1278 bool wxFrame::HandleCommand(
1279 WXWORD nId
1280 , WXWORD nCmd
1281 , WXHWND hControl
1282 )
1283 {
1284 if (hControl)
1285 {
1286 //
1287 // In case it's e.g. a toolbar.
1288 //
1289 wxWindow* pWin = wxFindWinFromHandle(hControl);
1290
1291 if (pWin)
1292 return pWin->OS2Command( nCmd
1293 ,nId
1294 );
1295 }
1296
1297 //
1298 // Handle here commands from menus and accelerators
1299 //
1300 if (nCmd == 0 || nCmd == 1)
1301 {
1302 if (wxCurrentPopupMenu)
1303 {
1304 wxMenu* pPopupMenu = wxCurrentPopupMenu;
1305
1306 wxCurrentPopupMenu = NULL;
1307
1308 return pPopupMenu->OS2Command( nCmd
1309 ,nId
1310 );
1311 }
1312
1313 if (ProcessCommand(nId))
1314 {
1315 return TRUE;
1316 }
1317 }
1318 return FALSE;
1319 } // end of wxFrame::HandleCommand
1320
1321 bool wxFrame::HandleMenuSelect(
1322 WXWORD nItem
1323 , WXWORD nFlags
1324 , WXHMENU hMenu
1325 )
1326 {
1327 int nMenuItem;
1328
1329 if (nFlags == 0xFFFF && hMenu == 0)
1330 {
1331 //
1332 // Menu was removed from screen
1333 //
1334 nMenuItem = -1;
1335 }
1336 else if (!(nFlags & MIS_SUBMENU) && !(nFlags & MIS_SEPARATOR))
1337 {
1338 nMenuItem = nItem;
1339 }
1340 else
1341 {
1342 //
1343 // Don't give hints for separators (doesn't make sense) nor for the
1344 // items opening popup menus (they don't have them anyhow)
1345 //
1346 return FALSE;
1347 }
1348 wxMenuEvent vEvent(wxEVT_MENU_HIGHLIGHT, nMenuItem);
1349
1350 vEvent.SetEventObject(this);
1351 return GetEventHandler()->ProcessEvent(vEvent);
1352 } // end of wxFrame::HandleMenuSelect
1353
1354 // ---------------------------------------------------------------------------
1355 // the window proc for wxFrame
1356 // ---------------------------------------------------------------------------
1357
1358 MRESULT wxFrame::OS2WindowProc(
1359 WXUINT uMessage
1360 , WXWPARAM wParam
1361 , WXLPARAM lParam
1362 )
1363 {
1364 MRESULT mRc = 0L;
1365 bool bProcessed = FALSE;
1366
1367 switch (uMessage)
1368 {
1369 case WM_CLOSE:
1370 //
1371 // If we can't close, tell the system that we processed the
1372 // message - otherwise it would close us
1373 //
1374 bProcessed = !Close();
1375 break;
1376
1377 case WM_COMMAND:
1378 {
1379 WORD wId;
1380 WORD wCmd;
1381 WXHWND hWnd;
1382
1383 UnpackCommand( (WXWPARAM)wParam
1384 ,(WXLPARAM)lParam
1385 ,&wId
1386 ,&hWnd
1387 ,&wCmd
1388 );
1389 bProcessed = HandleCommand( wId
1390 ,wCmd
1391 ,(WXHWND)hWnd
1392 );
1393 }
1394 break;
1395
1396 case WM_MENUSELECT:
1397 {
1398 WXWORD wItem;
1399 WXWORD wFlags;
1400 WXHMENU hMenu;
1401
1402 UnpackMenuSelect( wParam
1403 ,lParam
1404 ,&wItem
1405 ,&wFlags
1406 ,&hMenu
1407 );
1408 bProcessed = HandleMenuSelect( wItem
1409 ,wFlags
1410 ,hMenu
1411 );
1412 }
1413 break;
1414
1415 case WM_PAINT:
1416 bProcessed = HandlePaint();
1417 break;
1418
1419 case CM_QUERYDRAGIMAGE:
1420 {
1421 HPOINTER hIcon;
1422
1423 if (m_icon.Ok())
1424 hIcon = (HPOINTER)::WinSendMsg(GetHwnd(), WM_QUERYICON, 0L, 0L);
1425 else
1426 hIcon = (HPOINTER)m_hDefaultIcon;
1427 mRc = (MRESULT)hIcon;
1428 bProcessed = mRc != 0;
1429 }
1430 break;
1431
1432 case WM_SIZE:
1433 bProcessed = HandleSize(LOWORD(lParam), HIWORD(lParam), (WXUINT)wParam);
1434 break;
1435 }
1436
1437 if (!bProcessed )
1438 mRc = wxWindow::OS2WindowProc( uMessage
1439 ,wParam
1440 ,lParam
1441 );
1442 return (MRESULT)0;
1443 } // wxFrame::OS2WindowProc
1444