Loads of framework and dll fixes
[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
347 hClient = ::WinWindowFromID(GetHwnd(), FID_CLIENT);
348 ::WinShowWindow(GetHwnd(), (BOOL)bShowCmd);
349 ::WinShowWindow(hClient, (BOOL)bShowCmd);
350 } // end of wxFrame::DoShowWindow
351
352 bool wxFrame::Show(
353 bool bShow
354 )
355 {
356 SWP vSwp;
357
358 DoShowWindow((int)bShow);
359
360 if (bShow)
361 {
362 wxActivateEvent vEvent(wxEVT_ACTIVATE, TRUE, m_windowId);
363
364 ::WinQueryWindowPos(GetHwnd(), &vSwp);
365 m_bIconized = vSwp & SWP_MINIMIZE;
366 ::WinSetWindowPos( (HWND) GetHWND()
367 ,HWND_TOP
368 ,vSwp.x
369 ,vSwp.y
370 ,vSwp.cx
371 ,vSwp.cy
372 ,SWP_ZORDER | SWP_ACTIVATE | SWP_SHOW | SWP_MOVE
373 );
374 vEvent.SetEventObject(this);
375 GetEventHandler()->ProcessEvent(vEvent);
376 }
377 else
378 {
379 //
380 // Try to highlight the correct window (the parent)
381 //
382 if (GetParent())
383 {
384 HWND hWndParent = GetHwndOf(GetParent());
385
386 ::WinQueryWindowPos(hWndParent, &vSwp);
387 m_bIconized = vSwp & SWP_MINIMIZE;
388 if (hWndParent)
389 ::WinSetWindowPos( hWndParent
390 ,HWND_TOP
391 ,vSwp.x
392 ,vSwp.y
393 ,vSwp.cx
394 ,vSwp.cy
395 ,SWP_ZORDER | SWP_ACTIVATE | SWP_SHOW | SWP_MOVE
396 );
397 }
398 }
399 return TRUE;
400 } // end of wxFrame::Show
401
402 void wxFrame::Iconize(
403 bool bIconize
404 )
405 {
406 DoShowWindow(bIconize ? SWP_MINIMIZE : SWP_RESTORE);
407 } // end of wxFrame::Iconize
408
409 void wxFrame::Maximize(
410 bool bMaximize)
411 {
412 DoShowWindow(bMaximize ? SWP_MAXIMIZE : SWP_RESTORE);
413 } // end of wxFrame::Maximize
414
415 void wxFrame::Restore()
416 {
417 DoShowWindow(SWP_RESTORE);
418 } // end of wxFrame::Restore
419
420 bool wxFrame::IsIconized() const
421 {
422 SWP vSwp;
423 bool bIconic;
424
425 ::WinQueryWindowPos(GetHwnd(), &vSwp);
426
427 if (vSwp.fl & SWP_MINIMIZE)
428 ((wxFrame*)this)->m_bIconized = TRUE;
429 else
430 ((wxFrame*)this)->m_bIconized = FALSE;
431 return m_bIconized;
432 } // end of wxFrame::IsIconized
433
434 // Is it maximized?
435 bool wxFrame::IsMaximized() const
436 {
437 SWP vSwp;
438 bool bIconic;
439
440 ::WinQueryWindowPos(GetHwnd(), &vSwp);
441 return (vSwp.fl & SWP_MAXIMIZE);
442 } // end of wxFrame::IsMaximized
443
444 void wxFrame::SetIcon(
445 const wxIcon& rIcon
446 )
447 {
448 wxFrameBase::SetIcon(rIcon);
449
450 if ((m_icon.GetHICON()) != NULLHANDLE)
451 {
452 ::WinSendMsg( GetHwnd()
453 ,WM_SETICON
454 ,(MPARAM)((HPOINTER)m_icon.GetHICON())
455 ,NULL
456 );
457 ::WinSendMsg( GetHwnd()
458 ,WM_UPDATEFRAME
459 ,(MPARAM)FCF_ICON
460 ,(MPARAM)0
461 );
462 }
463 } // end of wxFrame::SetIcon
464
465 #if wxUSE_STATUSBAR
466 wxStatusBar* wxFrame::OnCreateStatusBar(
467 int nNumber
468 , long lulStyle
469 , wxWindowID vId
470 , const wxString& rName
471 )
472 {
473 wxStatusBar* pStatusBar = NULL;
474
475 pStatusBar = wxFrameBase::OnCreateStatusBar( nNumber
476 ,lulStyle
477 ,vId
478 ,rName
479 );
480 return pStatusBar;
481 } // end of wxFrame::OnCreateStatusBar
482
483 void wxFrame::PositionStatusBar()
484 {
485 //
486 // Native status bar positions itself
487 //
488 if (m_frameStatusBar)
489 {
490 int nWidth;
491 int nHeight;
492 int nStatbarWidth;
493 int nStatbarHeight;
494 HWND hWndClient;
495 RECTL vRect;
496
497 hWndClient = ::WinWindowFromID(GetHwnd(), FID_CLIENT);
498 ::WinQueryWindowRect(hWndClient, &vRect);
499 nWidth = vRect.xRight - vRect.xLeft;
500 nHeight = vRect.yTop - vRect.yBottom;
501
502 m_frameStatusBar->GetSize( &nStatbarWidth
503 ,&nStatbarHeight
504 );
505
506 //
507 // Since we wish the status bar to be directly under the client area,
508 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
509 //
510 m_frameStatusBar->SetSize( 0
511 ,nHeight
512 ,nWidth
513 ,nStatbarHeight
514 );
515 }
516 } // end of wxFrame::PositionStatusBar
517 #endif // wxUSE_STATUSBAR
518
519 void wxFrame::DetachMenuBar()
520 {
521 if (m_frameMenuBar)
522 {
523 m_frameMenuBar->Detach();
524 m_frameMenuBar = NULL;
525 }
526 } // end of wxFrame::DetachMenuBar
527
528 void wxFrame::SetMenuBar(
529 wxMenuBar* pMenuBar
530 )
531 {
532 if (!pMenuBar)
533 {
534 DetachMenuBar();
535 return;
536 }
537
538 m_frameMenuBar = NULL;
539
540 // Can set a menubar several times.
541 // TODO: how to prevent a memory leak if you have a currently-unattached
542 // menubar? wxWindows assumes that the frame will delete the menu (otherwise
543 // there are problems for MDI).
544 if (pMenuBar->GetHMenu())
545 {
546 m_hMenu = pMenuBar->GetHMenu();
547 }
548 else
549 {
550 pMenuBar->Detach();
551
552 m_hMenu = pMenuBar->Create();
553
554 if (!m_hMenu)
555 return;
556 }
557
558 InternalSetMenuBar();
559
560 m_frameMenuBar = pMenuBar;
561 pMenuBar->Attach(this);
562 } // end of wxFrame::SetMenuBar
563
564 void wxFrame::InternalSetMenuBar()
565 {
566 WinSendMsg((HWND)GetHwnd(), WM_UPDATEFRAME, (MPARAM)FCF_MENU, (MPARAM)0);
567 } // end of wxFrame::InternalSetMenuBar
568
569 //
570 // Responds to colour changes, and passes event on to children
571 //
572 void wxFrame::OnSysColourChanged(
573 wxSysColourChangedEvent& rEvent
574 )
575 {
576 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
577 Refresh();
578
579 if (m_frameStatusBar)
580 {
581 wxSysColourChangedEvent vEvent2;
582
583 vEvent2.SetEventObject(m_frameStatusBar);
584 m_frameStatusBar->GetEventHandler()->ProcessEvent(vEvent2);
585 }
586
587 //
588 // Propagate the event to the non-top-level children
589 //
590 wxWindow::OnSysColourChanged(rEvent);
591 } // end of wxFrame::OnSysColourChanged
592
593 // Pass TRUE to show full screen, FALSE to restore.
594 bool wxFrame::ShowFullScreen(
595 bool bShow
596 , long lStyle
597 )
598 {
599 /*
600 // TODO
601 if (show)
602 {
603 if (IsFullScreen())
604 return FALSE;
605
606 m_fsIsShowing = TRUE;
607 m_fsStyle = style;
608
609 wxToolBar *theToolBar = GetToolBar();
610 wxStatusBar *theStatusBar = GetStatusBar();
611
612 int dummyWidth;
613
614 if (theToolBar)
615 theToolBar->GetSize(&dummyWidth, &m_fsToolBarHeight);
616 if (theStatusBar)
617 theStatusBar->GetSize(&dummyWidth, &m_fsStatusBarHeight);
618
619 // zap the toolbar, menubar, and statusbar
620
621 if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar)
622 {
623 theToolBar->SetSize(-1,0);
624 theToolBar->Show(FALSE);
625 }
626
627 if (style & wxFULLSCREEN_NOMENUBAR)
628 SetMenu((HWND)GetHWND(), (HMENU) NULL);
629
630 // Save the number of fields in the statusbar
631 if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar)
632 {
633 m_fsStatusBarFields = theStatusBar->GetFieldsCount();
634 SetStatusBar((wxStatusBar*) NULL);
635 delete theStatusBar;
636 }
637 else
638 m_fsStatusBarFields = 0;
639
640 // zap the frame borders
641
642 // save the 'normal' window style
643 m_fsOldWindowStyle = GetWindowLong((HWND)GetHWND(), GWL_STYLE);
644
645 // save the old position, width & height, maximize state
646 m_fsOldSize = GetRect();
647 m_fsIsMaximized = IsMaximized();
648
649 // decide which window style flags to turn off
650 LONG newStyle = m_fsOldWindowStyle;
651 LONG offFlags = 0;
652
653 if (style & wxFULLSCREEN_NOBORDER)
654 offFlags |= WS_BORDER;
655 if (style & wxFULLSCREEN_NOCAPTION)
656 offFlags |= (WS_CAPTION | WS_SYSMENU);
657
658 newStyle &= (~offFlags);
659
660 // change our window style to be compatible with full-screen mode
661 SetWindowLong((HWND)GetHWND(), GWL_STYLE, newStyle);
662
663 // resize to the size of the desktop
664 int width, height;
665
666 RECT rect;
667 ::GetWindowRect(GetDesktopWindow(), &rect);
668 width = rect.right - rect.left;
669 height = rect.bottom - rect.top;
670
671 SetSize(width, height);
672
673 // now flush the window style cache and actually go full-screen
674 SetWindowPos((HWND)GetHWND(), HWND_TOP, 0, 0, width, height, SWP_FRAMECHANGED);
675
676 wxSizeEvent event(wxSize(width, height), GetId());
677 GetEventHandler()->ProcessEvent(event);
678
679 return TRUE;
680 }
681 else
682 {
683 if (!IsFullScreen())
684 return FALSE;
685
686 m_fsIsShowing = FALSE;
687
688 wxToolBar *theToolBar = GetToolBar();
689
690 // restore the toolbar, menubar, and statusbar
691 if (theToolBar && (m_fsStyle & wxFULLSCREEN_NOTOOLBAR))
692 {
693 theToolBar->SetSize(-1, m_fsToolBarHeight);
694 theToolBar->Show(TRUE);
695 }
696
697 if ((m_fsStyle & wxFULLSCREEN_NOSTATUSBAR) && (m_fsStatusBarFields > 0))
698 {
699 CreateStatusBar(m_fsStatusBarFields);
700 PositionStatusBar();
701 }
702
703 if ((m_fsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0))
704 SetMenu((HWND)GetHWND(), (HMENU)m_hMenu);
705
706 Maximize(m_fsIsMaximized);
707 SetWindowLong((HWND)GetHWND(),GWL_STYLE, m_fsOldWindowStyle);
708 SetWindowPos((HWND)GetHWND(),HWND_TOP,m_fsOldSize.x, m_fsOldSize.y,
709 m_fsOldSize.width, m_fsOldSize.height, SWP_FRAMECHANGED);
710
711 return TRUE;
712 }
713 */
714 return TRUE;
715 } // end of wxFrame::ShowFullScreen
716
717 //
718 // Frame window
719 //
720 bool wxFrame::OS2Create(
721 int nId
722 , wxWindow* pParent
723 , const wxChar* zWclass
724 , wxWindow* pWxWin
725 , const wxChar* zTitle
726 , int nX
727 , int nY
728 , int nWidth
729 , int nHeight
730 , long ulStyle
731 )
732 {
733 ULONG ulCreateFlags = 0L;
734 ULONG ulStyleFlags = 0L;
735 ULONG ulExtraFlags = 0L;
736 FRAMECDATA vFrameCtlData;
737 HWND hParent = NULLHANDLE;
738 HWND hClient = NULLHANDLE;
739 HWND hTitlebar = NULLHANDLE;
740 HWND hHScroll = NULLHANDLE;
741 HWND hVScroll = NULLHANDLE;
742 SWP vSwp;
743 SWP vSwpTitlebar;
744 SWP vSwpVScroll;
745 SWP vSwpHScroll;
746
747 m_hDefaultIcon = (WXHICON) (wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON : wxDEFAULT_FRAME_ICON);
748 memset(&vSwp, '\0', sizeof(SWP));
749 memset(&vSwpTitlebar, '\0', sizeof(SWP));
750 memset(&vSwpVScroll, '\0', sizeof(SWP));
751 memset(&vSwpHScroll, '\0', sizeof(SWP));
752 if (pParent)
753 hParent = GetWinHwnd(pParent);
754 else
755 hParent = HWND_DESKTOP;
756
757 if (ulStyle == wxDEFAULT_FRAME_STYLE)
758 ulCreateFlags = FCF_SIZEBORDER | FCF_TITLEBAR | FCF_SYSMENU |
759 FCF_MINMAX | FCF_VERTSCROLL | FCF_HORZSCROLL | FCF_TASKLIST;
760 else
761 {
762 if ((ulStyle & wxCAPTION) == wxCAPTION)
763 ulCreateFlags = FCF_TASKLIST;
764 else
765 ulCreateFlags = FCF_NOMOVEWITHOWNER;
766
767 if (ulStyle & wxMINIMIZE_BOX)
768 ulCreateFlags |= FCF_MINBUTTON;
769 if (ulStyle & wxMAXIMIZE_BOX)
770 ulCreateFlags |= FCF_MAXBUTTON;
771 if (ulStyle & wxTHICK_FRAME)
772 ulCreateFlags |= FCF_DLGBORDER;
773 if (ulStyle & wxSYSTEM_MENU)
774 ulCreateFlags |= FCF_SYSMENU;
775 if (ulStyle & wxCAPTION)
776 ulCreateFlags |= FCF_TASKLIST;
777 if (ulStyle & wxCLIP_CHILDREN)
778 {
779 // Invalid for frame windows under PM
780 }
781
782 if (ulStyle & wxTINY_CAPTION_VERT)
783 ulCreateFlags |= FCF_TASKLIST;
784 if (ulStyle & wxTINY_CAPTION_HORIZ)
785 ulCreateFlags |= FCF_TASKLIST;
786
787 if ((ulStyle & wxTHICK_FRAME) == 0)
788 ulCreateFlags |= FCF_BORDER;
789 if (ulStyle & wxFRAME_TOOL_WINDOW)
790 ulExtraFlags = kFrameToolWindow;
791
792 if (ulStyle & wxSTAY_ON_TOP)
793 ulCreateFlags |= FCF_SYSMODAL;
794 }
795 if ((ulStyle & wxMINIMIZE) || (ulStyle & wxICONIZE))
796 ulStyleFlags |= WS_MINIMIZED;
797 if (ulStyle & wxMAXIMIZE)
798 ulStyleFlags |= WS_MAXIMIZED;
799
800 //
801 // Clear the visible flag, we always call show
802 //
803 ulStyleFlags &= (unsigned long)~WS_VISIBLE;
804 m_bIconized = FALSE;
805
806 //
807 // Set the frame control block
808 //
809 vFrameCtlData.cb = sizeof(vFrameCtlData);
810 vFrameCtlData.flCreateFlags = ulCreateFlags;
811 vFrameCtlData.hmodResources = 0L;
812 vFrameCtlData.idResources = 0;
813
814 //
815 // Create the frame window
816 //
817 if (!wxWindow::OS2Create( hParent
818 ,WC_FRAME
819 ,zTitle
820 ,ulStyleFlags
821 ,(long)nX
822 ,(long)nY
823 ,(long)nWidth
824 ,(long)nHeight
825 ,NULLHANDLE
826 ,HWND_TOP
827 ,(long)nId
828 ,(void*)&vFrameCtlData
829 ,NULL
830 ))
831 {
832 return FALSE;
833 }
834
835 //
836 // Create the client window. We must call the API from here rather than
837 // the static base class create because we need a separate handle
838 //
839 if ((hClient = ::WinCreateWindow( GetHwnd() // Frame is parent
840 ,zWclass // Custom client class
841 ,NULL // Window title
842 ,0 // No styles
843 ,0, 0, 0, 0 // Window position
844 ,NULLHANDLE // Owner
845 ,HWND_TOP // Sibling
846 ,FID_CLIENT // standard client ID
847 ,NULL // Creation data
848 ,NULL // Window Pres Params
849 )) == 0L)
850 {
851 return FALSE;
852 }
853
854 //
855 // Now size everything. If adding a menu the client will need to be resized.
856 //
857 if (!::WinSetWindowPos( GetHwnd()
858 ,HWND_TOP
859 ,nX
860 ,nY
861 ,nWidth
862 ,nHeight
863 ,SWP_SIZE | SWP_MOVE | SWP_ACTIVATE
864 ))
865 return FALSE;
866
867 WinQueryWindowPos(GetHwnd(), &vSwp);
868
869 if (ulCreateFlags & FCF_TITLEBAR)
870 {
871 hTitlebar = WinWindowFromID(GetHwnd(), FID_TITLEBAR);
872 WinQueryWindowPos(hTitlebar, &vSwpTitlebar);
873 }
874 if (ulCreateFlags & FCF_HORZSCROLL)
875 {
876 hHScroll = WinWindowFromID(GetHwnd(), FID_HORZSCROLL);
877 WinQueryWindowPos(hHScroll, &vSwpHScroll);
878 }
879 if (ulCreateFlags & FCF_VERTSCROLL)
880 {
881 hVScroll = WinWindowFromID(GetHwnd(), FID_VERTSCROLL);
882 WinQueryWindowPos(hVScroll, &vSwpVScroll);
883 }
884 if (!::WinSetWindowPos( hClient
885 ,HWND_TOP
886 ,SV_CXSIZEBORDER
887 ,(SV_CYSIZEBORDER - 1) + vSwpHScroll.cy
888 ,vSwp.cx - ((SV_CXSIZEBORDER * 2) + vSwpVScroll.cx)
889 ,vSwp.cy - ((SV_CYSIZEBORDER * 2) + 1 + vSwpTitlebar.cy + vSwpHScroll.cy)
890 ,SWP_SIZE | SWP_MOVE
891 ))
892 return FALSE;
893 return TRUE;
894 } // end of wxFrame::OS2Create
895
896 //
897 // Default activation behaviour - set the focus for the first child
898 // subwindow found.
899 //
900 void wxFrame::OnActivate(
901 wxActivateEvent& rEvent
902 )
903 {
904 for (wxWindowList::Node* pNode = GetChildren().GetFirst();
905 pNode;
906 pNode = pNode->GetNext())
907 {
908 // FIXME all this is totally bogus - we need to do the same as wxPanel,
909 // but how to do it without duplicating the code?
910
911 // restore focus
912 wxWindow* pChild = pNode->GetData();
913
914 if (!pChild->IsTopLevel()
915 #if wxUSE_TOOLBAR
916 && !wxDynamicCast(pChild, wxToolBar)
917 #endif // wxUSE_TOOLBAR
918 #if wxUSE_STATUSBAR
919 && !wxDynamicCast(pChild, wxStatusBar)
920 #endif // wxUSE_STATUSBAR
921 )
922 {
923 pChild->SetFocus();
924 return;
925 }
926 }
927 } // end of wxFrame::OnActivate
928
929 // ----------------------------------------------------------------------------
930 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
931 // from the client area, so the client area is what's really available for the
932 // frame contents
933 // ----------------------------------------------------------------------------
934
935 // Checks if there is a toolbar, and returns the first free client position
936 wxPoint wxFrame::GetClientAreaOrigin() const
937 {
938 wxPoint vPoint(0, 0);
939
940 if (GetToolBar())
941 {
942 int nWidth;
943 int nHeight;
944
945 GetToolBar()->GetSize( &nWidth
946 ,&nHeight
947 );
948
949 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
950 {
951 vPoint.x += nWidth;
952 }
953 else
954 {
955 // PM is backwards from windows
956 vPoint.y += nHeight;
957 }
958 }
959 return vPoint;
960 } // end of wxFrame::GetClientAreaOrigin
961
962 // ----------------------------------------------------------------------------
963 // tool/status bar stuff
964 // ----------------------------------------------------------------------------
965
966 #if wxUSE_TOOLBAR
967
968 wxToolBar* wxFrame::CreateToolBar(
969 long lStyle
970 , wxWindowID vId
971 , const wxString& rName
972 )
973 {
974 if (wxFrameBase::CreateToolBar( lStyle
975 ,vId
976 ,rName
977 ))
978 {
979 PositionToolBar();
980 }
981 return m_frameToolBar;
982 } // end of wxFrame::CreateToolBar
983
984 void wxFrame::PositionToolBar()
985 {
986 HWND hWndClient;
987 RECTL vRect;
988
989 hWndClient = ::WinWindowFromID(GetHwnd(), FID_CLIENT);
990 ::WinQueryWindowRect(hWndClient, &vRect);
991
992 #if wxUSE_STATUSBAR
993 if (GetStatusBar())
994 {
995 int nStatusX;
996 int nStatusY;
997
998 GetStatusBar()->GetClientSize( &nStatusX
999 ,&nStatusY
1000 );
1001 // PM is backwards from windows
1002 vRect.yBottom += nStatusY;
1003 }
1004 #endif // wxUSE_STATUSBAR
1005
1006 if ( GetToolBar() )
1007 {
1008 int nToolbarWidth;
1009 int nToolbarHeight;
1010
1011 GetToolBar()->GetSize( &nToolbarWidth
1012 ,&nToolbarHeight
1013 );
1014
1015 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
1016 {
1017 nToolbarHeight = vRect.yBottom;
1018 }
1019 else
1020 {
1021 nToolbarWidth = vRect.xRight;
1022 }
1023
1024 //
1025 // Use the 'real' PM position here
1026 //
1027 GetToolBar()->SetSize( 0
1028 ,0
1029 ,nToolbarWidth
1030 ,nToolbarHeight
1031 ,wxSIZE_NO_ADJUSTMENTS
1032 );
1033 }
1034 } // end of wxFrame::PositionToolBar
1035 #endif // wxUSE_TOOLBAR
1036
1037 // ----------------------------------------------------------------------------
1038 // frame state (iconized/maximized/...)
1039 // ----------------------------------------------------------------------------
1040
1041 //
1042 // propagate our state change to all child frames: this allows us to emulate X
1043 // Windows behaviour where child frames float independently of the parent one
1044 // on the desktop, but are iconized/restored with it
1045 //
1046 void wxFrame::IconizeChildFrames(
1047 bool bIconize
1048 )
1049 {
1050 for (wxWindowList::Node* pNode = GetChildren().GetFirst();
1051 pNode;
1052 pNode = pNode->GetNext() )
1053 {
1054 wxWindow* pWin = pNode->GetData();
1055
1056 if (pWin->IsKindOf(CLASSINFO(wxFrame)) )
1057 {
1058 ((wxFrame *)pWin)->Iconize(bIconize);
1059 }
1060 }
1061 } // end of wxFrame::IconizeChildFrames
1062
1063 // ===========================================================================
1064 // message processing
1065 // ===========================================================================
1066
1067 // ---------------------------------------------------------------------------
1068 // preprocessing
1069 // ---------------------------------------------------------------------------
1070 bool wxFrame::OS2TranslateMessage(
1071 WXMSG* pMsg
1072 )
1073 {
1074 if (wxWindow::OS2TranslateMessage(pMsg))
1075 return TRUE;
1076 //
1077 // try the menu bar accels
1078 //
1079 wxMenuBar* pMenuBar = GetMenuBar();
1080
1081 if (!pMenuBar )
1082 return FALSE;
1083
1084 const wxAcceleratorTable& rAcceleratorTable = pMenuBar->GetAccelTable();
1085 return rAcceleratorTable.Translate(this, pMsg);
1086 } // end of wxFrame::OS2TranslateMessage
1087
1088 // ---------------------------------------------------------------------------
1089 // our private (non virtual) message handlers
1090 // ---------------------------------------------------------------------------
1091 bool wxFrame::HandlePaint()
1092 {
1093 RECTL vRect;
1094
1095 if (::WinQueryUpdateRect(GetHwnd(), &vRect))
1096 {
1097 if (m_bIconized)
1098 {
1099 //
1100 // Icons in PM are the same as "pointers"
1101 //
1102 HPOINTER hIcon;
1103
1104 if (m_icon.Ok())
1105 hIcon = (HPOINTER)::WinSendMsg(GetHwnd(), WM_QUERYICON, 0L, 0L);
1106 else
1107 hIcon = (HPOINTER)m_hDefaultIcon;
1108
1109 //
1110 // Hold a pointer to the dc so long as the OnPaint() message
1111 // is being processed
1112 //
1113 RECTL vRect2;
1114 HPS hPs = ::WinBeginPaint(GetHwnd(), NULLHANDLE, &vRect2);
1115
1116 //
1117 // Erase background before painting or we get white background
1118 //
1119 OS2DefWindowProc(WM_ERASEBACKGROUND, (MPARAM)hPs, (MPARAM)&vRect2);
1120
1121 if (hIcon)
1122 {
1123 HWND hWndClient;
1124 RECTL vRect3;
1125
1126 hWndClient = ::WinWindowFromID(GetHwnd(), FID_CLIENT);
1127 ::WinQueryWindowRect(hWndClient, &vRect3);
1128
1129 static const int nIconWidth = 32;
1130 static const int nIconHeight = 32;
1131 int nIconX = (int)((vRect3.xRight - nIconWidth)/2);
1132 int nIconY = (int)((vRect3.yBottom + nIconHeight)/2);
1133
1134 ::WinDrawPointer(hPs, nIconX, nIconY, hIcon, DP_NORMAL);
1135 }
1136 ::WinEndPaint(hPs);
1137 return TRUE;
1138 }
1139 else
1140 {
1141 return wxWindow::HandlePaint();
1142 }
1143 }
1144 else
1145 {
1146 // nothing to paint - processed
1147 return TRUE;
1148 }
1149 return FALSE;
1150 } // end of wxFrame::HandlePaint
1151
1152 bool wxFrame::HandleSize(
1153 int nX
1154 , int nY
1155 , WXUINT nId
1156 )
1157 {
1158 bool bProcessed = FALSE;
1159
1160 switch (nId)
1161 {
1162 case kSizeNormal:
1163 //
1164 // Only do it it if we were iconized before, otherwise resizing the
1165 // parent frame has a curious side effect of bringing it under it's
1166 // children
1167 if (!m_bIconized )
1168 break;
1169
1170 //
1171 // restore all child frames too
1172 //
1173 IconizeChildFrames(FALSE);
1174
1175 //
1176 // fall through
1177 //
1178
1179 case kSizeMax:
1180 m_bIconized = FALSE;
1181 break;
1182
1183 case kSizeMin:
1184 //
1185 // Iconize all child frames too
1186 //
1187 IconizeChildFrames(TRUE);
1188 m_bIconized = TRUE;
1189 break;
1190 }
1191
1192 if (!m_bIconized)
1193 {
1194 //
1195 // forward WM_SIZE to status bar control
1196 //
1197 #if wxUSE_NATIVE_STATUSBAR
1198 if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)))
1199 {
1200 wxSizeEvent vEvent( wxSize( nX
1201 ,nY
1202 )
1203 ,m_frameStatusBar->GetId()
1204 );
1205
1206 vEvent.SetEventObject(m_frameStatusBar);
1207 m_frameStatusBar->OnSize(vEvent);
1208 }
1209 #endif // wxUSE_NATIVE_STATUSBAR
1210
1211 PositionStatusBar();
1212 PositionToolBar();
1213 wxSizeEvent vEvent( wxSize( nX
1214 ,nY
1215 )
1216 ,m_windowId
1217 );
1218
1219 vEvent.SetEventObject(this);
1220 bProcessed = GetEventHandler()->ProcessEvent(vEvent);
1221 }
1222 return bProcessed;
1223 } // end of wxFrame::HandleSize
1224
1225 bool wxFrame::HandleCommand(
1226 WXWORD nId
1227 , WXWORD nCmd
1228 , WXHWND hControl
1229 )
1230 {
1231 if (hControl)
1232 {
1233 //
1234 // In case it's e.g. a toolbar.
1235 //
1236 wxWindow* pWin = wxFindWinFromHandle(hControl);
1237
1238 if (pWin)
1239 return pWin->OS2Command( nCmd
1240 ,nId
1241 );
1242 }
1243
1244 //
1245 // Handle here commands from menus and accelerators
1246 //
1247 if (nCmd == 0 || nCmd == 1)
1248 {
1249 if (wxCurrentPopupMenu)
1250 {
1251 wxMenu* pPopupMenu = wxCurrentPopupMenu;
1252
1253 wxCurrentPopupMenu = NULL;
1254
1255 return pPopupMenu->OS2Command( nCmd
1256 ,nId
1257 );
1258 }
1259
1260 if (ProcessCommand(nId))
1261 {
1262 return TRUE;
1263 }
1264 }
1265 return FALSE;
1266 } // end of wxFrame::HandleCommand
1267
1268 bool wxFrame::HandleMenuSelect(
1269 WXWORD nItem
1270 , WXWORD nFlags
1271 , WXHMENU hMenu
1272 )
1273 {
1274 int nMenuItem;
1275
1276 if (nFlags == 0xFFFF && hMenu == 0)
1277 {
1278 //
1279 // Menu was removed from screen
1280 //
1281 nMenuItem = -1;
1282 }
1283 else if (!(nFlags & MIS_SUBMENU) && !(nFlags & MIS_SEPARATOR))
1284 {
1285 nMenuItem = nItem;
1286 }
1287 else
1288 {
1289 //
1290 // Don't give hints for separators (doesn't make sense) nor for the
1291 // items opening popup menus (they don't have them anyhow)
1292 //
1293 return FALSE;
1294 }
1295 wxMenuEvent vEvent(wxEVT_MENU_HIGHLIGHT, nMenuItem);
1296
1297 vEvent.SetEventObject(this);
1298 return GetEventHandler()->ProcessEvent(vEvent);
1299 } // end of wxFrame::HandleMenuSelect
1300
1301 // ---------------------------------------------------------------------------
1302 // the window proc for wxFrame
1303 // ---------------------------------------------------------------------------
1304
1305 MRESULT wxFrame::OS2WindowProc(
1306 WXUINT uMessage
1307 , WXWPARAM wParam
1308 , WXLPARAM lParam
1309 )
1310 {
1311 MRESULT mRc = 0L;
1312 bool bProcessed = FALSE;
1313
1314 switch (uMessage)
1315 {
1316 case WM_CLOSE:
1317 //
1318 // If we can't close, tell the system that we processed the
1319 // message - otherwise it would close us
1320 //
1321 bProcessed = !Close();
1322 break;
1323
1324 case WM_COMMAND:
1325 {
1326 WORD wId;
1327 WORD wCmd;
1328 WXHWND hWnd;
1329
1330 UnpackCommand( (WXWPARAM)wParam
1331 ,(WXLPARAM)lParam
1332 ,&wId
1333 ,&hWnd
1334 ,&wCmd
1335 );
1336 bProcessed = HandleCommand( wId
1337 ,wCmd
1338 ,(WXHWND)hWnd
1339 );
1340 }
1341 break;
1342
1343 case WM_MENUSELECT:
1344 {
1345 WXWORD wItem;
1346 WXWORD wFlags;
1347 WXHMENU hMenu;
1348
1349 UnpackMenuSelect( wParam
1350 ,lParam
1351 ,&wItem
1352 ,&wFlags
1353 ,&hMenu
1354 );
1355 bProcessed = HandleMenuSelect( wItem
1356 ,wFlags
1357 ,hMenu
1358 );
1359 }
1360 break;
1361
1362 case WM_PAINT:
1363 bProcessed = HandlePaint();
1364 break;
1365
1366 case CM_QUERYDRAGIMAGE:
1367 {
1368 HPOINTER hIcon;
1369
1370 if (m_icon.Ok())
1371 hIcon = (HPOINTER)::WinSendMsg(GetHwnd(), WM_QUERYICON, 0L, 0L);
1372 else
1373 hIcon = (HPOINTER)m_hDefaultIcon;
1374 mRc = (MRESULT)hIcon;
1375 bProcessed = mRc != 0;
1376 }
1377 break;
1378
1379 case WM_SIZE:
1380 bProcessed = HandleSize(LOWORD(lParam), HIWORD(lParam), (WXUINT)wParam);
1381 break;
1382 }
1383
1384 if (!bProcessed )
1385 mRc = wxWindow::OS2WindowProc( uMessage
1386 ,wParam
1387 ,lParam
1388 );
1389 return (MRESULT)0;
1390 } // wxFrame::OS2WindowProc
1391