More wxFrame updates
[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(const wxIcon& icon)
442 {
443 wxFrameBase::SetIcon(icon);
444
445 // TODO:
446 /*
447 if ( m_icon.Ok() )
448 {
449 SendMessage(GetHwnd(), WM_SETICON,
450 (WPARAM)TRUE, (LPARAM)(HICON) m_icon.GetHICON());
451 }
452 */
453 }
454
455 #if wxUSE_STATUSBAR
456 wxStatusBar *wxFrame::OnCreateStatusBar(int number,
457 long style,
458 wxWindowID id,
459 const wxString& name)
460 {
461 wxStatusBar *statusBar = NULL;
462
463 statusBar = wxFrameBase::OnCreateStatusBar(number, style, id, name);
464
465 return statusBar;
466 }
467
468 void wxFrame::PositionStatusBar()
469 {
470 // TODO:
471 /*
472 // native status bar positions itself
473 if ( m_frameStatusBar )
474 {
475 int w, h;
476 GetClientSize(&w, &h);
477 int sw, sh;
478 m_frameStatusBar->GetSize(&sw, &sh);
479
480 // Since we wish the status bar to be directly under the client area,
481 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
482 m_frameStatusBar->SetSize(0, h, w, sh);
483 }
484 */
485 }
486 #endif // wxUSE_STATUSBAR
487
488 void wxFrame::DetachMenuBar()
489 {
490 if (m_frameMenuBar)
491 {
492 m_frameMenuBar->Detach();
493 m_frameMenuBar = NULL;
494 }
495 }
496
497 void wxFrame::SetMenuBar(wxMenuBar *menu_bar)
498 {
499 if (!menu_bar)
500 {
501 DetachMenuBar();
502 return;
503 }
504
505 wxCHECK_RET( !menu_bar->GetFrame(), wxT("this menubar is already attached") );
506
507 if (m_frameMenuBar)
508 delete m_frameMenuBar;
509
510 m_hMenu = menu_bar->Create();
511
512 if ( !m_hMenu )
513 return;
514
515 InternalSetMenuBar();
516
517 m_frameMenuBar = menu_bar;
518 menu_bar->Attach(this);
519 }
520
521 void wxFrame::InternalSetMenuBar()
522 {
523 // TODO:
524 /*
525 if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) )
526 {
527 wxLogLastError("SetMenu");
528 }
529 */
530 }
531
532 // Responds to colour changes, and passes event on to children.
533 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
534 {
535 // TODO:
536 /*
537 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
538 Refresh();
539
540 if ( m_frameStatusBar )
541 {
542 wxSysColourChangedEvent event2;
543 event2.SetEventObject( m_frameStatusBar );
544 m_frameStatusBar->GetEventHandler()->ProcessEvent(event2);
545 }
546
547 // Propagate the event to the non-top-level children
548 wxWindow::OnSysColourChanged(event);
549 */
550 }
551
552 /*
553 * Frame window
554 *
555 */
556
557 bool wxFrame::OS2Create(int id, wxWindow *parent, const wxChar *wclass, wxWindow *wx_win, const wxChar *title,
558 int x, int y, int width, int height, long style)
559
560 {
561 m_hDefaultIcon = (WXHICON) (wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON : wxDEFAULT_FRAME_ICON);
562
563 // If child windows aren't properly drawn initially, WS_CLIPCHILDREN
564 // could be the culprit. But without it, you can get a lot of flicker.
565
566 // TODO:
567 /*
568 DWORD msflags = 0;
569 if ((style & wxCAPTION) == wxCAPTION)
570 msflags = WS_OVERLAPPED;
571 else
572 msflags = WS_POPUP;
573
574 if (style & wxMINIMIZE_BOX)
575 msflags |= WS_MINIMIZEBOX;
576 if (style & wxMAXIMIZE_BOX)
577 msflags |= WS_MAXIMIZEBOX;
578 if (style & wxTHICK_FRAME)
579 msflags |= WS_THICKFRAME;
580 if (style & wxSYSTEM_MENU)
581 msflags |= WS_SYSMENU;
582 if ((style & wxMINIMIZE) || (style & wxICONIZE))
583 msflags |= WS_MINIMIZE;
584 if (style & wxMAXIMIZE)
585 msflags |= WS_MAXIMIZE;
586 if (style & wxCAPTION)
587 msflags |= WS_CAPTION;
588 if (style & wxCLIP_CHILDREN)
589 msflags |= WS_CLIPCHILDREN;
590
591 // Keep this in wxFrame because it saves recoding this function
592 // in wxTinyFrame
593 #if wxUSE_ITSY_BITSY
594 if (style & wxTINY_CAPTION_VERT)
595 msflags |= IBS_VERTCAPTION;
596 if (style & wxTINY_CAPTION_HORIZ)
597 msflags |= IBS_HORZCAPTION;
598 #else
599 if (style & wxTINY_CAPTION_VERT)
600 msflags |= WS_CAPTION;
601 if (style & wxTINY_CAPTION_HORIZ)
602 msflags |= WS_CAPTION;
603 #endif
604 if ((style & wxTHICK_FRAME) == 0)
605 msflags |= WS_BORDER;
606
607 WXDWORD extendedStyle = MakeExtendedStyle(style);
608
609 #if !defined(__WIN16__) && !defined(__SC__)
610 if (style & wxFRAME_TOOL_WINDOW)
611 extendedStyle |= WS_EX_TOOLWINDOW;
612 #endif
613
614 if (style & wxSTAY_ON_TOP)
615 extendedStyle |= WS_EX_TOPMOST;
616
617 m_iconized = FALSE;
618 if ( !wxWindow::MSWCreate(id, parent, wclass, wx_win, title, x, y, width, height,
619 msflags, NULL, extendedStyle) )
620 return FALSE;
621
622 // Seems to be necessary if we use WS_POPUP
623 // style instead of WS_OVERLAPPED
624 if (width > -1 && height > -1)
625 ::PostMessage(GetHwnd(), WM_SIZE, SIZE_RESTORED, MAKELPARAM(width, height));
626 */
627 return TRUE;
628 }
629
630 // Default activation behaviour - set the focus for the first child
631 // subwindow found.
632 void wxFrame::OnActivate(wxActivateEvent& event)
633 {
634 for ( wxWindowList::Node *node = GetChildren().GetFirst();
635 node;
636 node = node->GetNext() )
637 {
638 // FIXME all this is totally bogus - we need to do the same as wxPanel,
639 // but how to do it without duplicating the code?
640
641 // restore focus
642 wxWindow *child = node->GetData();
643
644 if ( !child->IsTopLevel()
645 #if wxUSE_TOOLBAR
646 && !wxDynamicCast(child, wxToolBar)
647 #endif // wxUSE_TOOLBAR
648 #if wxUSE_STATUSBAR
649 && !wxDynamicCast(child, wxStatusBar)
650 #endif // wxUSE_STATUSBAR
651 )
652 {
653 child->SetFocus();
654 return;
655 }
656 }
657 }
658
659 // ----------------------------------------------------------------------------
660 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
661 // from the client area, so the client area is what's really available for the
662 // frame contents
663 // ----------------------------------------------------------------------------
664
665 // Checks if there is a toolbar, and returns the first free client position
666 wxPoint wxFrame::GetClientAreaOrigin() const
667 {
668 wxPoint pt(0, 0);
669 if (GetToolBar())
670 {
671 int w, h;
672 GetToolBar()->GetSize(& w, & h);
673
674 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
675 {
676 pt.x += w;
677 }
678 else
679 {
680 pt.y += h;
681 }
682 }
683 return pt;
684 }
685
686 void wxFrame::DoScreenToClient(int *x, int *y) const
687 {
688 wxWindow::DoScreenToClient(x, y);
689
690 // We may be faking the client origin.
691 // So a window that's really at (0, 30) may appear
692 // (to wxWin apps) to be at (0, 0).
693 wxPoint pt(GetClientAreaOrigin());
694 *x -= pt.x;
695 *y -= pt.y;
696 }
697
698 void wxFrame::DoClientToScreen(int *x, int *y) const
699 {
700 // We may be faking the client origin.
701 // So a window that's really at (0, 30) may appear
702 // (to wxWin apps) to be at (0, 0).
703 wxPoint pt1(GetClientAreaOrigin());
704 *x += pt1.x;
705 *y += pt1.y;
706
707 wxWindow::DoClientToScreen(x, y);
708 }
709
710 // ----------------------------------------------------------------------------
711 // tool/status bar stuff
712 // ----------------------------------------------------------------------------
713
714 #if wxUSE_TOOLBAR
715
716 wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
717 {
718 if ( wxFrameBase::CreateToolBar(style, id, name) )
719 {
720 PositionToolBar();
721 }
722
723 return m_frameToolBar;
724 }
725
726 void wxFrame::PositionToolBar()
727 {
728 // TODO:
729 /*
730 RECT rect;
731 ::GetClientRect(GetHwnd(), &rect);
732
733 #if wxUSE_STATUSBAR
734 if ( GetStatusBar() )
735 {
736 int statusX, statusY;
737 GetStatusBar()->GetClientSize(&statusX, &statusY);
738 rect.bottom -= statusY;
739 }
740 #endif // wxUSE_STATUSBAR
741
742 if ( GetToolBar() )
743 {
744 int tw, th;
745 GetToolBar()->GetSize(&tw, &th);
746
747 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL )
748 {
749 th = rect.bottom;
750 }
751 else
752 {
753 tw = rect.right;
754 }
755
756 // Use the 'real' MSW position here
757 GetToolBar()->SetSize(0, 0, tw, th, wxSIZE_NO_ADJUSTMENTS);
758 }
759 */
760 }
761 #endif // wxUSE_TOOLBAR
762
763 // ----------------------------------------------------------------------------
764 // frame state (iconized/maximized/...)
765 // ----------------------------------------------------------------------------
766
767 // propagate our state change to all child frames: this allows us to emulate X
768 // Windows behaviour where child frames float independently of the parent one
769 // on the desktop, but are iconized/restored with it
770 void wxFrame::IconizeChildFrames(bool bIconize)
771 {
772 for ( wxWindowList::Node *node = GetChildren().GetFirst();
773 node;
774 node = node->GetNext() )
775 {
776 wxWindow *win = node->GetData();
777
778 if ( win->IsKindOf(CLASSINFO(wxFrame)) )
779 {
780 ((wxFrame *)win)->Iconize(bIconize);
781 }
782 }
783 }
784
785 // ===========================================================================
786 // message processing
787 // ===========================================================================
788
789 // ---------------------------------------------------------------------------
790 // preprocessing
791 // ---------------------------------------------------------------------------
792
793 bool wxFrame::OS2TranslateMessage(WXMSG* pMsg)
794 {
795 // TODO:
796 /*
797 if ( wxWindow::OS2TranslateMessage(pMsg) )
798 return TRUE;
799 */
800 // try the menu bar accels
801 wxMenuBar *menuBar = GetMenuBar();
802 if ( !menuBar )
803 return FALSE;
804
805 const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable();
806 return acceleratorTable.Translate(this, pMsg);
807 }
808
809 // ---------------------------------------------------------------------------
810 // our private (non virtual) message handlers
811 // ---------------------------------------------------------------------------
812
813 bool wxFrame::HandlePaint()
814 {
815 // TODO:
816 /*
817 RECT rect;
818 if ( GetUpdateRect(GetHwnd(), &rect, FALSE) )
819 {
820 if ( m_iconized )
821 {
822 HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon)
823 : (HICON)m_defaultIcon;
824
825 // Hold a pointer to the dc so long as the OnPaint() message
826 // is being processed
827 PAINTSTRUCT ps;
828 HDC hdc = ::BeginPaint(GetHwnd(), &ps);
829
830 // Erase background before painting or we get white background
831 MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L);
832
833 if ( hIcon )
834 {
835 RECT rect;
836 ::GetClientRect(GetHwnd(), &rect);
837
838 // FIXME: why hardcoded?
839 static const int icon_width = 32;
840 static const int icon_height = 32;
841
842 int icon_x = (int)((rect.right - icon_width)/2);
843 int icon_y = (int)((rect.bottom - icon_height)/2);
844
845 ::DrawIcon(hdc, icon_x, icon_y, hIcon);
846 }
847
848 ::EndPaint(GetHwnd(), &ps);
849
850 return TRUE;
851 }
852 else
853 {
854 return wxWindow::HandlePaint();
855 }
856 }
857 else
858 {
859 // nothing to paint - processed
860 return TRUE;
861 }
862 */
863 return FALSE;
864 }
865
866 bool wxFrame::HandleSize(int x, int y, WXUINT id)
867 {
868 bool processed = FALSE;
869
870 // TODO:
871 /*
872 switch ( id )
873 {
874 case SIZENORMAL:
875 // only do it it if we were iconized before, otherwise resizing the
876 // parent frame has a curious side effect of bringing it under it's
877 // children
878 if ( !m_iconized )
879 break;
880
881 // restore all child frames too
882 IconizeChildFrames(FALSE);
883
884 // fall through
885
886 case SIZEFULLSCREEN:
887 m_iconized = FALSE;
888 break;
889
890 case SIZEICONIC:
891 // iconize all child frames too
892 IconizeChildFrames(TRUE);
893
894 m_iconized = TRUE;
895 break;
896 }
897
898 if ( !m_iconized )
899 {
900 // forward WM_SIZE to status bar control
901 #if wxUSE_NATIVE_STATUSBAR
902 if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)))
903 {
904 wxSizeEvent event(wxSize(x, y), m_frameStatusBar->GetId());
905 event.SetEventObject( m_frameStatusBar );
906
907 ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event);
908 }
909 #endif // wxUSE_NATIVE_STATUSBAR
910
911 PositionStatusBar();
912 PositionToolBar();
913
914 wxSizeEvent event(wxSize(x, y), m_windowId);
915 event.SetEventObject( this );
916 processed = GetEventHandler()->ProcessEvent(event);
917 }
918 */
919 return processed;
920 }
921
922 bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
923 {
924 // TODO:
925 /*
926 if ( control )
927 {
928 // In case it's e.g. a toolbar.
929 wxWindow *win = wxFindWinFromHandle(control);
930 if ( win )
931 return win->MSWCommand(cmd, id);
932 }
933
934 // handle here commands from menus and accelerators
935 if ( cmd == 0 || cmd == 1 )
936 {
937 if ( wxCurrentPopupMenu )
938 {
939 wxMenu *popupMenu = wxCurrentPopupMenu;
940 wxCurrentPopupMenu = NULL;
941
942 return popupMenu->MSWCommand(cmd, id);
943 }
944
945 if ( ProcessCommand(id) )
946 {
947 return TRUE;
948 }
949 }
950 */
951 return FALSE;
952 }
953
954 bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu)
955 {
956 int item;
957 if ( flags == 0xFFFF && hMenu == 0 )
958 {
959 // menu was removed from screen
960 item = -1;
961 }
962 // TODO:
963 /*
964 else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) )
965 {
966 item = nItem;
967 }
968 else
969 {
970 // don't give hints for separators (doesn't make sense) nor for the
971 // items opening popup menus (they don't have them anyhow)
972 return FALSE;
973 }
974 */
975 wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item);
976 event.SetEventObject( this );
977
978 return GetEventHandler()->ProcessEvent(event);
979 }
980
981 // ---------------------------------------------------------------------------
982 // the window proc for wxFrame
983 // ---------------------------------------------------------------------------
984
985 MRESULT wxFrame::OS2WindowProc(HWND hwnd, WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
986 {
987 long rc = 0;
988 bool processed = FALSE;
989
990 // TODO:
991 /*
992 switch ( message )
993 {
994 case WM_CLOSE:
995 // if we can't close, tell the system that we processed the
996 // message - otherwise it would close us
997 processed = !Close();
998 break;
999
1000 case WM_COMMAND:
1001 {
1002 WORD id, cmd;
1003 WXHWND hwnd;
1004 UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam,
1005 &id, &hwnd, &cmd);
1006
1007 processed = HandleCommand(id, cmd, (WXHWND)hwnd);
1008 }
1009 break;
1010
1011 case WM_MENUSELECT:
1012 {
1013 WXWORD item, flags;
1014 WXHMENU hmenu;
1015 UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu);
1016
1017 processed = HandleMenuSelect(item, flags, hmenu);
1018 }
1019 break;
1020
1021 case WM_PAINT:
1022 processed = HandlePaint();
1023 break;
1024
1025 case WM_QUERYDRAGICON:
1026 {
1027 HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon)
1028 : (HICON)(m_defaultIcon);
1029 rc = (long)hIcon;
1030 processed = rc != 0;
1031 }
1032 break;
1033
1034 case WM_SIZE:
1035 processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam);
1036 break;
1037 }
1038
1039 if ( !processed )
1040 rc = wxWindow::MSWWindowProc(message, wParam, lParam);
1041
1042 return rc;
1043 */
1044 return (MRESULT)0;
1045 }
1046