]> git.saurik.com Git - wxWidgets.git/blob - src/os2/frame.cpp
wxImage::Rotate corrections added; docview improvements (menus updated properly)
[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_useNativeStatusBar = TRUE;
70 #else
71 bool wxFrame::m_useNativeStatusBar = 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_hHwndToolTip = 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 lStyle
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 = lStyle;
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 //
129 // We pass NULL as parent to MSWCreate because frames with parents behave
130 // very strangely under Win95 shell.
131 // Alteration by JACS: keep normal Windows behaviour (float on top of parent)
132 // with this style.
133 //
134 if ((m_windowStyle & wxFRAME_FLOAT_ON_PARENT) == 0)
135 pParent = NULL;
136
137 if (!pParent)
138 wxTopLevelWindows.Append(this);
139
140 OS2Create( m_windowId
141 ,pParent
142 ,wxFrameClassName
143 ,this
144 ,rsTitle
145 ,nX
146 ,nY
147 ,nWidth
148 ,nHeight
149 ,lStyle
150 );
151
152 wxModelessWindows.Append(this);
153 return TRUE;
154 } // end of wxFrame::Create
155
156 wxFrame::~wxFrame()
157 {
158 m_isBeingDeleted = TRUE;
159 wxTopLevelWindows.DeleteObject(this);
160
161 DeleteAllBars();
162
163 if (wxTheApp && (wxTopLevelWindows.Number() == 0))
164 {
165 wxTheApp->SetTopWindow(NULL);
166
167 if (wxTheApp->GetExitOnFrameDelete())
168 {
169 ::WinPostMsg(GetHwnd(), WM_QUIT, 0, 0);
170 }
171 }
172 wxModelessWindows.DeleteObject(this);
173
174 //
175 // For some reason, wxWindows can activate another task altogether
176 // when a frame is destroyed after a modal dialog has been invoked.
177 // Try to bring the parent to the top.
178 //
179 // MT:Only do this if this frame is currently the active window, else weird
180 // things start to happen.
181 //
182 if (wxGetActiveWindow() == this)
183 {
184 if (GetParent() && GetParent()->GetHWND())
185 {
186 ::WinSetWindowPos( (HWND) GetParent()->GetHWND()
187 ,HWND_TOP
188 ,0
189 ,0
190 ,0
191 ,0
192 ,SWP_ZORDER
193 );
194 }
195 }
196 } // end of wxFrame::~wxFrame
197
198 //
199 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
200 //
201 void wxFrame::DoGetClientSize(
202 int* pX
203 , int* pY
204 ) const
205 {
206 //
207 // OS/2 PM's coordinates go from bottom-left not
208 // top-left thus the += instead of the -=
209 //
210 RECTL vRect;
211 HWND hWndClient;
212
213 //
214 // PM has no GetClientRect that inherantly knows about the client window
215 // We have to explicitly go fetch it!
216 //
217 hWndClient = ::WinWindowFromId(GetHwnd(), FID_CLIENT);
218 ::WinQueryWindowRect(hWndClient, &vRect);
219
220 #if wxUSE_STATUSBAR
221 if ( GetStatusBar() )
222 {
223 int nStatusX
224 int nStatusY;
225
226 GetStatusBar()->GetClientSize( &nStatusX
227 ,&nStatusY
228 );
229 vRect.yBottom += nStatusY;
230 }
231 #endif // wxUSE_STATUSBAR
232
233 wxPoint vPoint(GetClientAreaOrigin());
234
235 vRect.bottom += pt.y;
236 vRect.right -= pt.x;
237
238 if (pX)
239 *pX = vRect.xRight;
240 if (pY)
241 *pY = vRect.yBottom;
242 } // end of wxFrame::DoGetClientSize
243
244 //
245 // Set the client size (i.e. leave the calculation of borders etc.
246 // to wxWindows)
247 //
248 void wxFrame::DoSetClientSize(
249 int nWidth
250 , int nHeight
251 )
252 {
253 HWND hWnd = GetHwnd();
254 HWND hWndClient;
255 RECTL vRect;
256 RECT vRect2;
257
258 hWndClient = ::WinWindowFromId(GetHwnd(), FID_CLIENT);
259 ::WinQueryWindowRect(hWndClient, &vRect);
260
261 ::WinQueryWindowRect(hWnd, &vRect2);
262
263 //
264 // Find the difference between the entire window (title bar and all)
265 // and the client area; add this to the new client size to move the
266 // window. Remember OS/2's backwards y coord system!
267 //
268 int nActualWidth = vRect2.xRight - vRect2.xLeft - vRect.xRight + nWidth;
269 int nActualHeight = vRect2.yTop + vRect2.yTop - vRect.yTop + nHeight;
270
271 #if wxUSE_STATUSBAR
272 if ( GetStatusBar() )
273 {
274 int nStatusX;
275 int nStatusY;
276
277 GetStatusBar()->GetClientSize( &nStatusX
278 ,&nStatusY
279 );
280 nActualHeight += nStatusY;
281 }
282 #endif // wxUSE_STATUSBAR
283
284 wxPoint vPoint(GetClientAreaOrigin());
285 nActualWidth += vPoint.y;
286 nActualHeight += vPoint.x;
287
288 POINTL vPointl;
289
290 vPointl.x = vRect2.xLeft;
291 vPoint.y = vRect2.yTop;
292
293 ::WinSetWindowPos( hWnd
294 ,HWND_TOP
295 ,vPointl.x
296 ,vPointl.y
297 ,nActualWidth
298 ,nActualHeight
299 ,SWP_MOVE | SWP_SIZE | SWP_SHOW
300 );
301
302 wxSizeEvent vEvent( wxSize( nWidth
303 ,nHeight
304 )
305 ,m_windowId
306 );
307 vEvent.SetEventObject(this);
308 GetEventHandler()->ProcessEvent(vEvent);
309 } // end of wxFrame::DoSetClientSize
310
311 void wxFrame::DoGetSize(
312 int* pWidth
313 , int* pHeight
314 ) const
315 {
316 RECTL vRect;
317
318 ::WinQueryWindowRect(GetHwnd(), &vRect);
319 *pWidth = vRect.xRight - vRect.xLeft;
320 *pHeight = vRect.yTop - vRect.yBottom;
321 } // end of wxFrame::DoGetSize
322
323 void wxFrame::DoGetPosition(
324 int* pX
325 , int* pY
326 ) const
327 {
328 RECTL vRect;
329 POINT vPoint;
330
331 ::WinQueryWindowRect(GetHwnd(), &vRect);
332 vPoint.x = vRect.xLeft;
333
334 //
335 // OS/2 is backwards [WIN32 it is vRect.yTop]
336 //
337 vPoint.y = vRect.yBottom;
338
339 *pX = vPoint.x;
340 *pY = vPoint.y;
341 } // end of wxFrame::DoGetPosition
342
343 // ----------------------------------------------------------------------------
344 // variations around ::ShowWindow()
345 // ----------------------------------------------------------------------------
346
347 void wxFrame::DoShowWindow(
348 int nShowCmd
349 )
350 {
351 ::WinShowWindow(GetHwnd(), nShowCmd);
352 m_bIconized = nShowCmd == SWP_MINIMIZE;
353 } // end of wxFrame::DoShowWindow
354
355 bool wxFrame::Show(
356 bool bShow
357 )
358 {
359 DoShowWindow(show ? SWP_SHOW : SW_HIDE);
360
361 if (bShow)
362 {
363 wxActivateEvent vEvent(wxEVT_ACTIVATE, TRUE, m_windowId);
364
365 ::WinSetWindowPos( (HWND) GetHWND()
366 ,HWND_TOP
367 ,0
368 ,0
369 ,0
370 ,0
371 ,SWP_ZORDER
372 );
373 vEvent.SetEventObject(this);
374 GetEventHandler()->ProcessEvent(vEvent);
375 }
376 else
377 {
378 //
379 // Try to highlight the correct window (the parent)
380 //
381 if (GetParent())
382 {
383 HWND hWndParent = GetHwndOf(GetParent());
384
385 if (hWndParent)
386 ::WinSetWindowPos( hWndParent
387 ,HWND_TOP
388 ,0
389 ,0
390 ,0
391 ,0
392 ,SWP_ZORDER
393 );
394 }
395 }
396 return TRUE;
397 } // end of wxFrame::Show
398
399 void wxFrame::Iconize(
400 bool bIconize
401 )
402 {
403 DoShowWindow(bIconize ? SWP_MINIMIZE : SWP_RESTORE);
404 } // end of wxFrame::Iconize
405
406 void wxFrame::Maximize(
407 bool bMaximize)
408 {
409 DoShowWindow(bMaximize ? SWP_MAXIMIZE : SWP_RESTORE);
410 } // end of wxFrame::Maximize
411
412 void wxFrame::Restore()
413 {
414 DoShowWindow(SWP_RESTORE);
415 } // end of wxFrame::Restore
416
417 bool wxFrame::IsIconized() const
418 {
419 SWP vSwp;
420 bool bIconic;
421
422 ::WinQueryWindowPos(GetHwnd(), &vSwp)
423
424 if (vSwp.fl & SWP_MINIMIZE)
425 ((wxFrame*)this)->m_bIconized = TRUE;
426 else
427 ((wxFrame*)this)->m_bIconized = FALSE;
428 return m_bIconized;
429 } // end of wxFrame::IsIconized
430
431 // Is it maximized?
432 bool wxFrame::IsMaximized() const
433 {
434 SWP vSwp;
435 bool bIconic;
436
437 ::WinQueryWindowPos(GetHwnd(), &vSwp)
438 return (vSwp.fl & SWP_MAXIMIZE);
439 } // end of wxFrame::IsMaximized
440
441 void wxFrame::SetIcon(
442 const wxIcon& rIcon
443 )
444 {
445 wxFrameBase::SetIcon(rIcon);
446
447 if (m_icon.Ok())
448 {
449 WinSendMessage( GetHwnd()
450 ,WM_SETICON
451 ,(HICON) m_icon.GetHICON()
452 ,NULL
453 )
454 }
455 } // end of wxFrame::SetIcon
456
457 #if wxUSE_STATUSBAR
458 wxStatusBar* wxFrame::OnCreateStatusBar(
459 int nNumber
460 , long lStyle
461 , wxWindowID vId
462 , const wxString& rName
463 )
464 {
465 wxStatusBar* pStatusBar = NULL;
466
467 pStatusBar = wxFrameBase::OnCreateStatusBar( nNumber
468 ,lStyle
469 ,vId
470 ,rName
471 );
472 return pStatusBar;
473 } // end of wxFrame::OnCreateStatusBar
474
475 void wxFrame::PositionStatusBar()
476 {
477 //
478 // Native status bar positions itself
479 //
480 if (m_frameStatusBar)
481 {
482 int nWidth
483 int nHeight;
484 int nStatbarWidth
485 int nStatbarHeight;
486 HWND hWndClient;
487 RECTL vRect;
488
489 hWndClient = ::WinWindowFromId(GetHwnd(), FID_CLIENT);
490 ::WinQueryWindowRect(hWndClient, &vRect);
491 nWidth = vRect.xRight - vRect.xLeft;
492 nHeight = vRect.xTop - vRect.xBottom;
493
494 m_frameStatusBar->GetSize( &nStatbarWidth
495 ,&nStatbarHeight
496 );
497
498 //
499 // Since we wish the status bar to be directly under the client area,
500 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
501 //
502 m_frameStatusBar->SetSize( 0
503 ,nHeight
504 ,nWidth
505 ,nStatbarHeight
506 );
507 }
508 } // end of wxFrame::PositionStatusBar
509 #endif // wxUSE_STATUSBAR
510
511 void wxFrame::DetachMenuBar()
512 {
513 if (m_frameMenuBar)
514 {
515 m_frameMenuBar->Detach();
516 m_frameMenuBar = NULL;
517 }
518 } // end of wxFrame::DetachMenuBar
519
520 void wxFrame::SetMenuBar(
521 wxMenuBar* pMenuBbar
522 )
523 {
524 if (!pMenuBar)
525 {
526 DetachMenuBar();
527 return;
528 }
529
530 wxCHECK_RET(!pMenuBar->GetFrame(), wxT("this menubar is already attached"));
531
532 if (m_frameMenuBar)
533 delete m_frameMenuBar;
534
535 m_hMenu = pMenuBbar->Create();
536 m_ulMenubarId = pMenubar->GetMenubarId();
537 if (m_ulMenubarId != FID_MENU)
538 {
539 ::WinSetWIndowUShort( m_hMenu
540 ,QWS_ID
541 ,(unsigned short(m_ulMenubarId)
542 );
543 }
544
545 if (!m_hMenu)
546 return;
547
548 InternalSetMenuBar();
549
550 m_frameMenuBar = menu_bar;
551 menu_bar->Attach(this);
552 } // end of wxFrame::SetMenuBar
553
554 void wxFrame::InternalSetMenuBar()
555 {
556
557 ::WinPostMsg( GetHwnd()
558 ,WM_UPDATEFRAME
559 ,FCF_MENU
560 ,NULL
561 );
562 } // end of wxFrame::InternalSetMenuBar
563
564 // Responds to colour changes, and passes event on to children.
565 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
566 {
567 // TODO:
568 /*
569 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
570 Refresh();
571
572 if ( m_frameStatusBar )
573 {
574 wxSysColourChangedEvent event2;
575 event2.SetEventObject( m_frameStatusBar );
576 m_frameStatusBar->GetEventHandler()->ProcessEvent(event2);
577 }
578
579 // Propagate the event to the non-top-level children
580 wxWindow::OnSysColourChanged(event);
581 */
582 }
583
584 /*
585 * Frame window
586 *
587 */
588
589 bool wxFrame::OS2Create(int id, wxWindow *parent, const wxChar *wclass, wxWindow *wx_win, const wxChar *title,
590 int x, int y, int width, int height, long style)
591
592 {
593 m_hDefaultIcon = (WXHICON) (wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON : wxDEFAULT_FRAME_ICON);
594
595 // If child windows aren't properly drawn initially, WS_CLIPCHILDREN
596 // could be the culprit. But without it, you can get a lot of flicker.
597
598 // TODO:
599 /*
600 DWORD msflags = 0;
601 if ((style & wxCAPTION) == wxCAPTION)
602 msflags = WS_OVERLAPPED;
603 else
604 msflags = WS_POPUP;
605
606 if (style & wxMINIMIZE_BOX)
607 msflags |= WS_MINIMIZEBOX;
608 if (style & wxMAXIMIZE_BOX)
609 msflags |= WS_MAXIMIZEBOX;
610 if (style & wxTHICK_FRAME)
611 msflags |= WS_THICKFRAME;
612 if (style & wxSYSTEM_MENU)
613 msflags |= WS_SYSMENU;
614 if ((style & wxMINIMIZE) || (style & wxICONIZE))
615 msflags |= WS_MINIMIZE;
616 if (style & wxMAXIMIZE)
617 msflags |= WS_MAXIMIZE;
618 if (style & wxCAPTION)
619 msflags |= WS_CAPTION;
620 if (style & wxCLIP_CHILDREN)
621 msflags |= WS_CLIPCHILDREN;
622
623 // Keep this in wxFrame because it saves recoding this function
624 // in wxTinyFrame
625 #if wxUSE_ITSY_BITSY
626 if (style & wxTINY_CAPTION_VERT)
627 msflags |= IBS_VERTCAPTION;
628 if (style & wxTINY_CAPTION_HORIZ)
629 msflags |= IBS_HORZCAPTION;
630 #else
631 if (style & wxTINY_CAPTION_VERT)
632 msflags |= WS_CAPTION;
633 if (style & wxTINY_CAPTION_HORIZ)
634 msflags |= WS_CAPTION;
635 #endif
636 if ((style & wxTHICK_FRAME) == 0)
637 msflags |= WS_BORDER;
638
639 WXDWORD extendedStyle = MakeExtendedStyle(style);
640
641 #if !defined(__WIN16__) && !defined(__SC__)
642 if (style & wxFRAME_TOOL_WINDOW)
643 extendedStyle |= WS_EX_TOOLWINDOW;
644 #endif
645
646 if (style & wxSTAY_ON_TOP)
647 extendedStyle |= WS_EX_TOPMOST;
648
649 m_iconized = FALSE;
650 if ( !wxWindow::MSWCreate(id, parent, wclass, wx_win, title, x, y, width, height,
651 msflags, NULL, extendedStyle) )
652 return FALSE;
653
654 // Seems to be necessary if we use WS_POPUP
655 // style instead of WS_OVERLAPPED
656 if (width > -1 && height > -1)
657 ::PostMessage(GetHwnd(), WM_SIZE, SIZE_RESTORED, MAKELPARAM(width, height));
658 */
659 return TRUE;
660 }
661
662 // Default activation behaviour - set the focus for the first child
663 // subwindow found.
664 void wxFrame::OnActivate(wxActivateEvent& event)
665 {
666 for ( wxWindowList::Node *node = GetChildren().GetFirst();
667 node;
668 node = node->GetNext() )
669 {
670 // FIXME all this is totally bogus - we need to do the same as wxPanel,
671 // but how to do it without duplicating the code?
672
673 // restore focus
674 wxWindow *child = node->GetData();
675
676 if ( !child->IsTopLevel()
677 #if wxUSE_TOOLBAR
678 && !wxDynamicCast(child, wxToolBar)
679 #endif // wxUSE_TOOLBAR
680 #if wxUSE_STATUSBAR
681 && !wxDynamicCast(child, wxStatusBar)
682 #endif // wxUSE_STATUSBAR
683 )
684 {
685 child->SetFocus();
686 return;
687 }
688 }
689 }
690
691 // ----------------------------------------------------------------------------
692 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
693 // from the client area, so the client area is what's really available for the
694 // frame contents
695 // ----------------------------------------------------------------------------
696
697 // Checks if there is a toolbar, and returns the first free client position
698 wxPoint wxFrame::GetClientAreaOrigin() const
699 {
700 wxPoint pt(0, 0);
701 if (GetToolBar())
702 {
703 int w, h;
704 GetToolBar()->GetSize(& w, & h);
705
706 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
707 {
708 pt.x += w;
709 }
710 else
711 {
712 pt.y += h;
713 }
714 }
715 return pt;
716 }
717
718 void wxFrame::DoScreenToClient(int *x, int *y) const
719 {
720 wxWindow::DoScreenToClient(x, y);
721
722 // We may be faking the client origin.
723 // So a window that's really at (0, 30) may appear
724 // (to wxWin apps) to be at (0, 0).
725 wxPoint pt(GetClientAreaOrigin());
726 *x -= pt.x;
727 *y -= pt.y;
728 }
729
730 void wxFrame::DoClientToScreen(int *x, int *y) const
731 {
732 // We may be faking the client origin.
733 // So a window that's really at (0, 30) may appear
734 // (to wxWin apps) to be at (0, 0).
735 wxPoint pt1(GetClientAreaOrigin());
736 *x += pt1.x;
737 *y += pt1.y;
738
739 wxWindow::DoClientToScreen(x, y);
740 }
741
742 // ----------------------------------------------------------------------------
743 // tool/status bar stuff
744 // ----------------------------------------------------------------------------
745
746 #if wxUSE_TOOLBAR
747
748 wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
749 {
750 if ( wxFrameBase::CreateToolBar(style, id, name) )
751 {
752 PositionToolBar();
753 }
754
755 return m_frameToolBar;
756 }
757
758 void wxFrame::PositionToolBar()
759 {
760 // TODO:
761 /*
762 RECT rect;
763 ::GetClientRect(GetHwnd(), &rect);
764
765 #if wxUSE_STATUSBAR
766 if ( GetStatusBar() )
767 {
768 int statusX, statusY;
769 GetStatusBar()->GetClientSize(&statusX, &statusY);
770 rect.bottom -= statusY;
771 }
772 #endif // wxUSE_STATUSBAR
773
774 if ( GetToolBar() )
775 {
776 int tw, th;
777 GetToolBar()->GetSize(&tw, &th);
778
779 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL )
780 {
781 th = rect.bottom;
782 }
783 else
784 {
785 tw = rect.right;
786 }
787
788 // Use the 'real' MSW position here
789 GetToolBar()->SetSize(0, 0, tw, th, wxSIZE_NO_ADJUSTMENTS);
790 }
791 */
792 }
793 #endif // wxUSE_TOOLBAR
794
795 // ----------------------------------------------------------------------------
796 // frame state (iconized/maximized/...)
797 // ----------------------------------------------------------------------------
798
799 // propagate our state change to all child frames: this allows us to emulate X
800 // Windows behaviour where child frames float independently of the parent one
801 // on the desktop, but are iconized/restored with it
802 void wxFrame::IconizeChildFrames(bool bIconize)
803 {
804 for ( wxWindowList::Node *node = GetChildren().GetFirst();
805 node;
806 node = node->GetNext() )
807 {
808 wxWindow *win = node->GetData();
809
810 if ( win->IsKindOf(CLASSINFO(wxFrame)) )
811 {
812 ((wxFrame *)win)->Iconize(bIconize);
813 }
814 }
815 }
816
817 // ===========================================================================
818 // message processing
819 // ===========================================================================
820
821 // ---------------------------------------------------------------------------
822 // preprocessing
823 // ---------------------------------------------------------------------------
824
825 bool wxFrame::OS2TranslateMessage(WXMSG* pMsg)
826 {
827 // TODO:
828 /*
829 if ( wxWindow::OS2TranslateMessage(pMsg) )
830 return TRUE;
831 */
832 // try the menu bar accels
833 wxMenuBar *menuBar = GetMenuBar();
834 if ( !menuBar )
835 return FALSE;
836
837 const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable();
838 return acceleratorTable.Translate(this, pMsg);
839 }
840
841 // ---------------------------------------------------------------------------
842 // our private (non virtual) message handlers
843 // ---------------------------------------------------------------------------
844
845 bool wxFrame::HandlePaint()
846 {
847 // TODO:
848 /*
849 RECT rect;
850 if ( GetUpdateRect(GetHwnd(), &rect, FALSE) )
851 {
852 if ( m_iconized )
853 {
854 HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon)
855 : (HICON)m_defaultIcon;
856
857 // Hold a pointer to the dc so long as the OnPaint() message
858 // is being processed
859 PAINTSTRUCT ps;
860 HDC hdc = ::BeginPaint(GetHwnd(), &ps);
861
862 // Erase background before painting or we get white background
863 MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L);
864
865 if ( hIcon )
866 {
867 RECT rect;
868 ::GetClientRect(GetHwnd(), &rect);
869
870 // FIXME: why hardcoded?
871 static const int icon_width = 32;
872 static const int icon_height = 32;
873
874 int icon_x = (int)((rect.right - icon_width)/2);
875 int icon_y = (int)((rect.bottom - icon_height)/2);
876
877 ::DrawIcon(hdc, icon_x, icon_y, hIcon);
878 }
879
880 ::EndPaint(GetHwnd(), &ps);
881
882 return TRUE;
883 }
884 else
885 {
886 return wxWindow::HandlePaint();
887 }
888 }
889 else
890 {
891 // nothing to paint - processed
892 return TRUE;
893 }
894 */
895 return FALSE;
896 }
897
898 bool wxFrame::HandleSize(int x, int y, WXUINT id)
899 {
900 bool processed = FALSE;
901
902 // TODO:
903 /*
904 switch ( id )
905 {
906 case SIZENORMAL:
907 // only do it it if we were iconized before, otherwise resizing the
908 // parent frame has a curious side effect of bringing it under it's
909 // children
910 if ( !m_iconized )
911 break;
912
913 // restore all child frames too
914 IconizeChildFrames(FALSE);
915
916 // fall through
917
918 case SIZEFULLSCREEN:
919 m_iconized = FALSE;
920 break;
921
922 case SIZEICONIC:
923 // iconize all child frames too
924 IconizeChildFrames(TRUE);
925
926 m_iconized = TRUE;
927 break;
928 }
929
930 if ( !m_iconized )
931 {
932 // forward WM_SIZE to status bar control
933 #if wxUSE_NATIVE_STATUSBAR
934 if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)))
935 {
936 wxSizeEvent event(wxSize(x, y), m_frameStatusBar->GetId());
937 event.SetEventObject( m_frameStatusBar );
938
939 ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event);
940 }
941 #endif // wxUSE_NATIVE_STATUSBAR
942
943 PositionStatusBar();
944 PositionToolBar();
945
946 wxSizeEvent event(wxSize(x, y), m_windowId);
947 event.SetEventObject( this );
948 processed = GetEventHandler()->ProcessEvent(event);
949 }
950 */
951 return processed;
952 }
953
954 bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
955 {
956 // TODO:
957 /*
958 if ( control )
959 {
960 // In case it's e.g. a toolbar.
961 wxWindow *win = wxFindWinFromHandle(control);
962 if ( win )
963 return win->MSWCommand(cmd, id);
964 }
965
966 // handle here commands from menus and accelerators
967 if ( cmd == 0 || cmd == 1 )
968 {
969 if ( wxCurrentPopupMenu )
970 {
971 wxMenu *popupMenu = wxCurrentPopupMenu;
972 wxCurrentPopupMenu = NULL;
973
974 return popupMenu->MSWCommand(cmd, id);
975 }
976
977 if ( ProcessCommand(id) )
978 {
979 return TRUE;
980 }
981 }
982 */
983 return FALSE;
984 }
985
986 bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu)
987 {
988 int item;
989 if ( flags == 0xFFFF && hMenu == 0 )
990 {
991 // menu was removed from screen
992 item = -1;
993 }
994 // TODO:
995 /*
996 else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) )
997 {
998 item = nItem;
999 }
1000 else
1001 {
1002 // don't give hints for separators (doesn't make sense) nor for the
1003 // items opening popup menus (they don't have them anyhow)
1004 return FALSE;
1005 }
1006 */
1007 wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item);
1008 event.SetEventObject( this );
1009
1010 return GetEventHandler()->ProcessEvent(event);
1011 }
1012
1013 // ---------------------------------------------------------------------------
1014 // the window proc for wxFrame
1015 // ---------------------------------------------------------------------------
1016
1017 MRESULT wxFrame::OS2WindowProc(HWND hwnd, WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
1018 {
1019 long rc = 0;
1020 bool processed = FALSE;
1021
1022 // TODO:
1023 /*
1024 switch ( message )
1025 {
1026 case WM_CLOSE:
1027 // if we can't close, tell the system that we processed the
1028 // message - otherwise it would close us
1029 processed = !Close();
1030 break;
1031
1032 case WM_COMMAND:
1033 {
1034 WORD id, cmd;
1035 WXHWND hwnd;
1036 UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam,
1037 &id, &hwnd, &cmd);
1038
1039 processed = HandleCommand(id, cmd, (WXHWND)hwnd);
1040 }
1041 break;
1042
1043 case WM_MENUSELECT:
1044 {
1045 WXWORD item, flags;
1046 WXHMENU hmenu;
1047 UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu);
1048
1049 processed = HandleMenuSelect(item, flags, hmenu);
1050 }
1051 break;
1052
1053 case WM_PAINT:
1054 processed = HandlePaint();
1055 break;
1056
1057 case WM_QUERYDRAGICON:
1058 {
1059 HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon)
1060 : (HICON)(m_defaultIcon);
1061 rc = (long)hIcon;
1062 processed = rc != 0;
1063 }
1064 break;
1065
1066 case WM_SIZE:
1067 processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam);
1068 break;
1069 }
1070
1071 if ( !processed )
1072 rc = wxWindow::MSWWindowProc(message, wParam, lParam);
1073
1074 return rc;
1075 */
1076 return (MRESULT)0;
1077 }
1078