]> git.saurik.com Git - wxWidgets.git/blob - src/msw/frame.cpp
Implement CanSetZoomType correctly for the IE backend.
[wxWidgets.git] / src / msw / frame.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/frame.cpp
3 // Purpose: wxFrame
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #include "wx/frame.h"
28
29 #ifndef WX_PRECOMP
30 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
31 #include "wx/app.h"
32 #include "wx/menu.h"
33 #include "wx/utils.h"
34 #include "wx/dialog.h"
35 #include "wx/settings.h"
36 #include "wx/dcclient.h"
37 #include "wx/mdi.h"
38 #include "wx/panel.h"
39 #include "wx/log.h"
40 #include "wx/toolbar.h"
41 #include "wx/statusbr.h"
42 #include "wx/menuitem.h"
43 #endif // WX_PRECOMP
44
45 #include "wx/msw/private.h"
46
47 #if defined(__POCKETPC__) || defined(__SMARTPHONE__)
48 #include <ole2.h>
49 #include <aygshell.h>
50 #include "wx/msw/winundef.h"
51 #endif
52
53 #include "wx/generic/statusbr.h"
54
55 #ifdef __WXUNIVERSAL__
56 #include "wx/univ/theme.h"
57 #include "wx/univ/colschem.h"
58 #endif // __WXUNIVERSAL__
59
60 // ----------------------------------------------------------------------------
61 // globals
62 // ----------------------------------------------------------------------------
63
64 #if wxUSE_MENUS_NATIVE
65 extern wxMenu *wxCurrentPopupMenu;
66 #endif // wxUSE_MENUS_NATIVE
67
68 // ----------------------------------------------------------------------------
69 // event tables
70 // ----------------------------------------------------------------------------
71
72 BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
73 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
74 END_EVENT_TABLE()
75
76 // ============================================================================
77 // implementation
78 // ============================================================================
79
80 // ----------------------------------------------------------------------------
81 // static class members
82 // ----------------------------------------------------------------------------
83
84 #if wxUSE_STATUSBAR
85 #if wxUSE_NATIVE_STATUSBAR
86 bool wxFrame::m_useNativeStatusBar = true;
87 #else
88 bool wxFrame::m_useNativeStatusBar = false;
89 #endif
90 #endif // wxUSE_NATIVE_STATUSBAR
91
92 // ----------------------------------------------------------------------------
93 // creation/destruction
94 // ----------------------------------------------------------------------------
95
96 void wxFrame::Init()
97 {
98 #if wxUSE_MENUS
99 m_hMenu = NULL;
100 #endif // wxUSE_MENUS
101
102 #if wxUSE_TOOLTIPS
103 m_hwndToolTip = 0;
104 #endif
105
106 m_wasMinimized = false;
107 }
108
109 bool wxFrame::Create(wxWindow *parent,
110 wxWindowID id,
111 const wxString& title,
112 const wxPoint& pos,
113 const wxSize& size,
114 long style,
115 const wxString& name)
116 {
117 if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
118 return false;
119
120 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
121
122 #if defined(__SMARTPHONE__)
123 SetLeftMenu(wxID_EXIT, _("Done"));
124 #endif
125
126 #if wxUSE_ACCEL && defined(__POCKETPC__)
127 // The guidelines state that Ctrl+Q should quit the app.
128 // Let's define an accelerator table to send wxID_EXIT.
129 wxAcceleratorEntry entries[1];
130 entries[0].Set(wxACCEL_CTRL, 'Q', wxID_EXIT);
131 wxAcceleratorTable accel(1, entries);
132 SetAcceleratorTable(accel);
133 #endif // wxUSE_ACCEL && __POCKETPC__
134
135 return true;
136 }
137
138 wxFrame::~wxFrame()
139 {
140 SendDestroyEvent();
141
142 DeleteAllBars();
143 }
144
145 // ----------------------------------------------------------------------------
146 // wxFrame client size calculations
147 // ----------------------------------------------------------------------------
148
149 void wxFrame::DoSetClientSize(int width, int height)
150 {
151 // leave enough space for the status bar if we have (and show) it
152 #if wxUSE_STATUSBAR
153 wxStatusBar *statbar = GetStatusBar();
154 if ( statbar && statbar->IsShown() )
155 {
156 height += statbar->GetSize().y;
157 }
158 #endif // wxUSE_STATUSBAR
159
160 // call GetClientAreaOrigin() to take the toolbar into account
161 wxPoint pt = GetClientAreaOrigin();
162 width += pt.x;
163 height += pt.y;
164
165 #if wxUSE_TOOLBAR
166 wxToolBar * const toolbar = GetToolBar();
167 if ( toolbar )
168 {
169 if ( toolbar->HasFlag(wxTB_RIGHT | wxTB_BOTTOM) )
170 {
171 const wxSize sizeTB = toolbar->GetSize();
172 if ( toolbar->HasFlag(wxTB_RIGHT) )
173 width -= sizeTB.x;
174 else // wxTB_BOTTOM
175 height -= sizeTB.y;
176 }
177 //else: toolbar already taken into account by GetClientAreaOrigin()
178 }
179 #endif // wxUSE_TOOLBAR
180
181 wxTopLevelWindow::DoSetClientSize(width, height);
182 }
183
184 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
185 void wxFrame::DoGetClientSize(int *x, int *y) const
186 {
187 wxTopLevelWindow::DoGetClientSize(x, y);
188
189 // account for the possible toolbar
190 wxPoint pt = GetClientAreaOrigin();
191 if ( x )
192 *x -= pt.x;
193
194 if ( y )
195 *y -= pt.y;
196
197 #if wxUSE_TOOLBAR
198 wxToolBar * const toolbar = GetToolBar();
199 if ( toolbar )
200 {
201 if ( toolbar->HasFlag(wxTB_RIGHT | wxTB_BOTTOM) )
202 {
203 const wxSize sizeTB = toolbar->GetSize();
204 if ( toolbar->HasFlag(wxTB_RIGHT) )
205 {
206 if ( x )
207 *x -= sizeTB.x;
208 }
209 else // wxTB_BOTTOM
210 {
211 if ( y )
212 *y -= sizeTB.y;
213 }
214 }
215 //else: toolbar already taken into account by GetClientAreaOrigin()
216 }
217 #endif // wxUSE_TOOLBAR
218
219 #if wxUSE_STATUSBAR
220 // adjust client area height to take the status bar into account
221 if ( y )
222 {
223 wxStatusBar *statbar = GetStatusBar();
224 if ( statbar && statbar->IsShown() )
225 {
226 *y -= statbar->GetSize().y;
227 }
228 }
229 #endif // wxUSE_STATUSBAR
230 }
231
232 // ----------------------------------------------------------------------------
233 // wxFrame: various geometry-related functions
234 // ----------------------------------------------------------------------------
235
236 void wxFrame::Raise()
237 {
238 ::SetForegroundWindow(GetHwnd());
239 }
240
241 // generate an artificial resize event
242 void wxFrame::SendSizeEvent(int flags)
243 {
244 if ( !m_iconized )
245 {
246 RECT r = wxGetWindowRect(GetHwnd());
247
248 if ( flags & wxSEND_EVENT_POST )
249 {
250 ::PostMessage(GetHwnd(), WM_SIZE,
251 IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED,
252 MAKELPARAM(r.right - r.left, r.bottom - r.top));
253 }
254 else // send it
255 {
256 ::SendMessage(GetHwnd(), WM_SIZE,
257 IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED,
258 MAKELPARAM(r.right - r.left, r.bottom - r.top));
259 }
260 }
261 }
262
263 #if wxUSE_STATUSBAR
264 wxStatusBar *wxFrame::OnCreateStatusBar(int number,
265 long style,
266 wxWindowID id,
267 const wxString& name)
268 {
269 wxStatusBar *statusBar wxDUMMY_INITIALIZE(NULL);
270
271 #if wxUSE_NATIVE_STATUSBAR
272 if ( !UsesNativeStatusBar() )
273 {
274 statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style);
275 }
276 else
277 #endif
278 {
279 statusBar = new wxStatusBar(this, id, style, name);
280 }
281
282 statusBar->SetFieldsCount(number);
283
284 return statusBar;
285 }
286
287 void wxFrame::PositionStatusBar()
288 {
289 if ( !m_frameStatusBar || !m_frameStatusBar->IsShown() )
290 return;
291
292 int w, h;
293 GetClientSize(&w, &h);
294
295 int sw, sh;
296 m_frameStatusBar->GetSize(&sw, &sh);
297
298 int x = 0;
299 #if wxUSE_TOOLBAR
300 wxToolBar * const toolbar = GetToolBar();
301 if ( toolbar && !toolbar->HasFlag(wxTB_TOP) )
302 {
303 const wxSize sizeTB = toolbar->GetSize();
304
305 if ( toolbar->HasFlag(wxTB_LEFT | wxTB_RIGHT) )
306 {
307 if ( toolbar->HasFlag(wxTB_LEFT) )
308 x -= sizeTB.x;
309
310 w += sizeTB.x;
311 }
312 else // wxTB_BOTTOM
313 {
314 // we need to position the status bar below the toolbar
315 h += sizeTB.y;
316 }
317 }
318 //else: no adjustments necessary for the toolbar on top
319 #endif // wxUSE_TOOLBAR
320
321 // Since we wish the status bar to be directly under the client area,
322 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
323 m_frameStatusBar->SetSize(x, h, w, sh);
324 }
325
326 #endif // wxUSE_STATUSBAR
327
328 #if wxUSE_MENUS_NATIVE
329
330 void wxFrame::AttachMenuBar(wxMenuBar *menubar)
331 {
332 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
333
334 wxMenu *autoMenu = NULL;
335
336 if( menubar->GetMenuCount() == 1 )
337 {
338 autoMenu = wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(menubar->GetMenu(0));
339 SetRightMenu(wxID_ANY, menubar->GetMenuLabel(0), autoMenu);
340 }
341 else
342 {
343 autoMenu = new wxMenu;
344
345 for( size_t n = 0; n < menubar->GetMenuCount(); n++ )
346 {
347 wxMenu *item = menubar->GetMenu(n);
348 wxString label = menubar->GetMenuLabel(n);
349 wxMenu *new_item = wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(item);
350 autoMenu->Append(wxID_ANY, label, new_item);
351 }
352
353 SetRightMenu(wxID_ANY, _("Menu"), autoMenu);
354 }
355
356 #elif defined(WINCE_WITHOUT_COMMANDBAR)
357 if (!GetToolBar())
358 {
359 wxToolMenuBar* toolBar = new wxToolMenuBar(this, wxID_ANY,
360 wxDefaultPosition, wxDefaultSize,
361 wxBORDER_NONE | wxTB_HORIZONTAL,
362 wxToolBarNameStr, menubar);
363 SetToolBar(toolBar);
364 menubar->SetToolBar(toolBar);
365 }
366
367 // When the main window is created using CW_USEDEFAULT the height of the
368 // menubar is not taken into account, so we resize it afterwards if a
369 // menubar is present
370 HWND hwndMenuBar = SHFindMenuBar(GetHwnd());
371 if ( hwndMenuBar )
372 {
373 RECT mbRect;
374 ::GetWindowRect(hwndMenuBar, &mbRect);
375 const int menuHeight = mbRect.bottom - mbRect.top;
376
377 RECT rc;
378 ::GetWindowRect(GetHwnd(), &rc);
379 // adjust for menu / titlebar height
380 rc.bottom -= (2*menuHeight-1);
381
382 ::MoveWindow(Gethwnd(), rc.left, rc.top, rc.right, rc.bottom, FALSE);
383 }
384 #endif
385
386 wxFrameBase::AttachMenuBar(menubar);
387
388 if ( !menubar )
389 {
390 // actually remove the menu from the frame
391 m_hMenu = (WXHMENU)0;
392 InternalSetMenuBar();
393 }
394 else // set new non NULL menu bar
395 {
396 #if !defined(__WXWINCE__) || defined(WINCE_WITH_COMMANDBAR)
397 // Can set a menubar several times.
398 if ( menubar->GetHMenu() )
399 {
400 m_hMenu = menubar->GetHMenu();
401 }
402 else // no HMENU yet
403 {
404 m_hMenu = menubar->Create();
405
406 if ( !m_hMenu )
407 {
408 wxFAIL_MSG( wxT("failed to create menu bar") );
409 return;
410 }
411 }
412 #endif
413 InternalSetMenuBar();
414 }
415 }
416
417 void wxFrame::InternalSetMenuBar()
418 {
419 #if defined(__WXMICROWIN__) || defined(__WXWINCE__)
420 // Nothing
421 #else
422 if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) )
423 {
424 wxLogLastError(wxT("SetMenu"));
425 }
426 #endif
427 }
428
429 #endif // wxUSE_MENUS_NATIVE
430
431 // Responds to colour changes, and passes event on to children.
432 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
433 {
434 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
435 Refresh();
436
437 #if wxUSE_STATUSBAR
438 if ( m_frameStatusBar )
439 {
440 wxSysColourChangedEvent event2;
441 event2.SetEventObject( m_frameStatusBar );
442 m_frameStatusBar->HandleWindowEvent(event2);
443 }
444 #endif // wxUSE_STATUSBAR
445
446 // Propagate the event to the non-top-level children
447 wxWindow::OnSysColourChanged(event);
448 }
449
450 // Pass true to show full screen, false to restore.
451 bool wxFrame::ShowFullScreen(bool show, long style)
452 {
453 // TODO-CE: add support for CE
454 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
455 if ( IsFullScreen() == show )
456 return false;
457
458 if (show)
459 {
460 // zap the toolbar, menubar, and statusbar if needed
461 //
462 // TODO: hide commandbar for WINCE_WITH_COMMANDBAR
463 #if wxUSE_TOOLBAR
464 wxToolBar *theToolBar = GetToolBar();
465
466 if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar)
467 {
468 if ( theToolBar->IsShown() )
469 {
470 theToolBar->SetSize(wxDefaultCoord,0);
471 theToolBar->Show(false);
472 }
473 else // prevent it from being restored later
474 {
475 style &= ~wxFULLSCREEN_NOTOOLBAR;
476 }
477 }
478 #endif // wxUSE_TOOLBAR
479
480 if (style & wxFULLSCREEN_NOMENUBAR)
481 SetMenu((HWND)GetHWND(), (HMENU) NULL);
482
483 #if wxUSE_STATUSBAR
484 wxStatusBar *theStatusBar = GetStatusBar();
485
486 // Save the number of fields in the statusbar
487 if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar)
488 {
489 if ( theStatusBar->IsShown() )
490 theStatusBar->Show(false);
491 else
492 style &= ~wxFULLSCREEN_NOSTATUSBAR;
493 }
494 #endif // wxUSE_STATUSBAR
495 }
496 else // restore to normal
497 {
498 // restore the toolbar, menubar, and statusbar if we had hid them
499 #if wxUSE_TOOLBAR
500 wxToolBar *theToolBar = GetToolBar();
501
502 if ((m_fsStyle & wxFULLSCREEN_NOTOOLBAR) && theToolBar)
503 {
504 theToolBar->Show(true);
505 }
506 #endif // wxUSE_TOOLBAR
507
508 #if wxUSE_MENUS
509 if (m_fsStyle & wxFULLSCREEN_NOMENUBAR)
510 {
511 const WXHMENU hmenu = MSWGetActiveMenu();
512 if ( hmenu )
513 ::SetMenu(GetHwnd(), (HMENU)hmenu);
514 }
515 #endif // wxUSE_MENUS
516
517 #if wxUSE_STATUSBAR
518 wxStatusBar *theStatusBar = GetStatusBar();
519
520 if ((m_fsStyle & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar)
521 {
522 theStatusBar->Show(true);
523 PositionStatusBar();
524 }
525 #endif // wxUSE_STATUSBAR
526 }
527 #endif // !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
528
529 return wxFrameBase::ShowFullScreen(show, style);
530 }
531
532 // ----------------------------------------------------------------------------
533 // tool/status bar stuff
534 // ----------------------------------------------------------------------------
535
536 #if wxUSE_TOOLBAR
537
538 wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
539 {
540 #if defined(WINCE_WITHOUT_COMMANDBAR)
541 // We may already have a toolbar from calling SetMenuBar.
542 if (GetToolBar())
543 return GetToolBar();
544 #endif
545 if ( wxFrameBase::CreateToolBar(style, id, name) )
546 {
547 PositionToolBar();
548 }
549
550 return m_frameToolBar;
551 }
552
553 void wxFrame::PositionToolBar()
554 {
555 // TODO: we want to do something different in WinCE, because the toolbar
556 // should be associated with the commandbar, instead of being
557 // independent window.
558 #if !defined(WINCE_WITHOUT_COMMANDBAR)
559 wxToolBar *toolbar = GetToolBar();
560 if ( toolbar && toolbar->IsShown() )
561 {
562 // don't call our (or even wxTopLevelWindow) version because we want
563 // the real (full) client area size, not excluding the tool/status bar
564 int width, height;
565 wxWindow::DoGetClientSize(&width, &height);
566
567 #if wxUSE_STATUSBAR
568 wxStatusBar *statbar = GetStatusBar();
569 if ( statbar && statbar->IsShown() )
570 {
571 height -= statbar->GetClientSize().y;
572 }
573 #endif // wxUSE_STATUSBAR
574
575 int tx, ty, tw, th;
576 toolbar->GetPosition( &tx, &ty );
577 toolbar->GetSize( &tw, &th );
578
579 int x, y;
580 if ( toolbar->HasFlag(wxTB_BOTTOM) )
581 {
582 x = 0;
583 y = height - th;
584 }
585 else if ( toolbar->HasFlag(wxTB_RIGHT) )
586 {
587 x = width - tw;
588 y = 0;
589 }
590 else // left or top
591 {
592 x = 0;
593 y = 0;
594 }
595
596 #if defined(WINCE_WITH_COMMANDBAR)
597 // We're using a commandbar - so we have to allow for it.
598 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
599 {
600 RECT rect;
601 ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect);
602 y = rect.bottom - rect.top;
603 }
604 #endif // WINCE_WITH_COMMANDBAR
605
606 if ( toolbar->HasFlag(wxTB_BOTTOM) )
607 {
608 if ( ty < 0 && ( -ty == th ) )
609 ty = height - th;
610 if ( tx < 0 && (-tx == tw ) )
611 tx = 0;
612 }
613 else if ( toolbar->HasFlag(wxTB_RIGHT) )
614 {
615 if( ty < 0 && ( -ty == th ) )
616 ty = 0;
617 if( tx < 0 && ( -tx == tw ) )
618 tx = width - tw;
619 }
620 else // left or top
621 {
622 if (ty < 0 && (-ty == th))
623 ty = 0;
624 if (tx < 0 && (-tx == tw))
625 tx = 0;
626 }
627
628 int desiredW,
629 desiredH;
630
631 if ( toolbar->IsVertical() )
632 {
633 desiredW = tw;
634 desiredH = height;
635 }
636 else
637 {
638 desiredW = width;
639 desiredH = th;
640 }
641
642 // use the 'real' MSW position here, don't offset relatively to the
643 // client area origin
644 toolbar->SetSize(x, y, desiredW, desiredH, wxSIZE_NO_ADJUSTMENTS);
645
646 }
647 #endif // !WINCE_WITH_COMMANDBAR
648 }
649
650 #endif // wxUSE_TOOLBAR
651
652 // ----------------------------------------------------------------------------
653 // frame state (iconized/maximized/...)
654 // ----------------------------------------------------------------------------
655
656 // propagate our state change to all child frames: this allows us to emulate X
657 // Windows behaviour where child frames float independently of the parent one
658 // on the desktop, but are iconized/restored with it
659 void wxFrame::IconizeChildFrames(bool bIconize)
660 {
661 m_iconized = bIconize;
662
663 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
664 node;
665 node = node->GetNext() )
666 {
667 wxWindow *win = node->GetData();
668
669 // iconizing the frames with this style under Win95 shell puts them at
670 // the bottom of the screen (as the MDI children) instead of making
671 // them appear in the taskbar because they are, by virtue of this
672 // style, not managed by the taskbar - instead leave Windows take care
673 // of them
674 if ( win->GetWindowStyle() & wxFRAME_TOOL_WINDOW )
675 continue;
676
677 // the child MDI frames are a special case and should not be touched by
678 // the parent frame - instead, they are managed by the user
679 wxFrame *frame = wxDynamicCast(win, wxFrame);
680 if ( frame
681 #if wxUSE_MDI_ARCHITECTURE
682 && !frame->IsMDIChild()
683 #endif // wxUSE_MDI_ARCHITECTURE
684 )
685 {
686 // we don't want to restore the child frames which had been
687 // iconized even before we were iconized, so save the child frame
688 // status when iconizing the parent frame and check it when
689 // restoring it
690 if ( bIconize )
691 {
692 frame->m_wasMinimized = frame->IsIconized();
693 }
694
695 // note that we shouldn't touch the hidden frames neither because
696 // iconizing/restoring them would show them as a side effect
697 if ( !frame->m_wasMinimized && frame->IsShown() )
698 frame->Iconize(bIconize);
699 }
700 }
701 }
702
703 WXHICON wxFrame::GetDefaultIcon() const
704 {
705 // we don't have any standard icons (any more)
706 return (WXHICON)0;
707 }
708
709 // ===========================================================================
710 // message processing
711 // ===========================================================================
712
713 // ---------------------------------------------------------------------------
714 // preprocessing
715 // ---------------------------------------------------------------------------
716
717 bool wxFrame::MSWDoTranslateMessage(wxFrame *frame, WXMSG *pMsg)
718 {
719 if ( wxWindow::MSWTranslateMessage(pMsg) )
720 return true;
721
722 #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
723 // try the menu bar accelerators
724 wxMenuBar *menuBar = GetMenuBar();
725 if ( menuBar && menuBar->GetAcceleratorTable()->Translate(frame, pMsg) )
726 return true;
727 #endif // wxUSE_MENUS && wxUSE_ACCEL
728
729 return false;
730 }
731
732 // ---------------------------------------------------------------------------
733 // our private (non virtual) message handlers
734 // ---------------------------------------------------------------------------
735
736 bool wxFrame::HandleSize(int WXUNUSED(x), int WXUNUSED(y), WXUINT id)
737 {
738 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
739 switch ( id )
740 {
741 case SIZE_RESTORED:
742 case SIZE_MAXIMIZED:
743 // only do it it if we were iconized before, otherwise resizing the
744 // parent frame has a curious side effect of bringing it under it's
745 // children
746 if ( !m_iconized )
747 break;
748
749 // restore all child frames too
750 IconizeChildFrames(false);
751
752 (void)SendIconizeEvent(false);
753 break;
754
755 case SIZE_MINIMIZED:
756 // iconize all child frames too
757 IconizeChildFrames(true);
758 break;
759 }
760 #else
761 wxUnusedVar(id);
762 #endif // !__WXWINCE__
763
764 if ( !m_iconized )
765 {
766 #if wxUSE_STATUSBAR
767 PositionStatusBar();
768 #endif // wxUSE_STATUSBAR
769
770 #if wxUSE_TOOLBAR
771 PositionToolBar();
772 #endif // wxUSE_TOOLBAR
773
774 #if defined(WINCE_WITH_COMMANDBAR)
775 // Position the menu command bar
776 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
777 {
778 RECT rect;
779 ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect);
780 wxSize clientSz = GetClientSize();
781
782 if ( !::MoveWindow((HWND) GetMenuBar()->GetCommandBar(), 0, 0, clientSz.x, rect.bottom - rect.top, true ) )
783 {
784 wxLogLastError(wxT("MoveWindow"));
785 }
786
787 }
788 #endif // WINCE_WITH_COMMANDBAR
789 }
790
791 // call the base class version to generate the appropriate events
792 return false;
793 }
794
795 bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
796 {
797 #if wxUSE_MENUS
798
799 #if defined(WINCE_WITHOUT_COMMANDBAR)
800 if (GetToolBar() && GetToolBar()->FindById(id))
801 return GetToolBar()->MSWCommand(cmd, id);
802 #endif
803
804 // we only need to handle the menu and accelerator commands from the items
805 // of our menu bar, base wxWindow class already handles the rest
806 if ( !control && (cmd == 0 /* menu */ || cmd == 1 /* accel */) )
807 {
808 #if wxUSE_MENUS_NATIVE
809 if ( !wxCurrentPopupMenu )
810 #endif // wxUSE_MENUS_NATIVE
811 {
812 wxMenuItem * const mitem = FindItemInMenuBar((signed short)id);
813 if ( mitem )
814 return ProcessCommand(mitem);
815 }
816 }
817 #endif // wxUSE_MENUS
818
819 return wxFrameBase::HandleCommand(id, cmd, control);;
820 }
821
822 #if wxUSE_MENUS
823
824 bool
825 wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU WXUNUSED(hMenu))
826 {
827 // sign extend to int from unsigned short we get from Windows
828 int item = (signed short)nItem;
829
830 // WM_MENUSELECT is generated for both normal items and menus, including
831 // the top level menus of the menu bar, which can't be represented using
832 // any valid identifier in wxMenuEvent so use an otherwise unused value for
833 // them
834 if ( flags & (MF_POPUP | MF_SEPARATOR) )
835 item = wxID_NONE;
836
837 wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item);
838 event.SetEventObject(this);
839
840 if ( HandleWindowEvent(event) )
841 return true;
842
843 // by default, i.e. if the event wasn't handled above, clear the status bar
844 // text when an item which can't have any associated help string in wx API
845 // is selected
846 if ( item == wxID_NONE )
847 DoGiveHelp(wxEmptyString, true);
848
849 return false;
850 }
851
852 bool wxFrame::HandleMenuLoop(const wxEventType& evtType, WXWORD isPopup)
853 {
854 // we don't have the menu id here, so we use the id to specify if the event
855 // was from a popup menu or a normal one
856 wxMenuEvent event(evtType, isPopup ? -1 : 0);
857 event.SetEventObject(this);
858
859 return HandleWindowEvent(event);
860 }
861
862 bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu)
863 {
864 wxMenu* menu = NULL;
865 if (GetMenuBar())
866 {
867 menu = GetMenuBar()->MSWGetMenu(hMenu);
868 }
869
870 wxMenuEvent event(wxEVT_MENU_OPEN, 0, menu);
871 event.SetEventObject(this);
872
873 return HandleWindowEvent(event);
874 }
875
876 #endif // wxUSE_MENUS
877
878 // ---------------------------------------------------------------------------
879 // the window proc for wxFrame
880 // ---------------------------------------------------------------------------
881
882 WXLRESULT wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
883 {
884 WXLRESULT rc = 0;
885 bool processed = false;
886
887 switch ( message )
888 {
889 case WM_CLOSE:
890 // if we can't close, tell the system that we processed the
891 // message - otherwise it would close us
892 processed = !Close();
893 break;
894
895 case WM_SIZE:
896 processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam);
897 break;
898
899 case WM_COMMAND:
900 {
901 WORD id, cmd;
902 WXHWND hwnd;
903 UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam,
904 &id, &hwnd, &cmd);
905
906 HandleCommand(id, cmd, (WXHWND)hwnd);
907
908 // don't pass WM_COMMAND to the base class whether we processed
909 // it or not because we did generate an event for it (our
910 // HandleCommand() calls the base class version) and we must
911 // not do it again or the handlers which skip the event would
912 // be called twice
913 processed = true;
914 }
915 break;
916
917 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
918 #if wxUSE_MENUS
919 case WM_INITMENUPOPUP:
920 processed = HandleInitMenuPopup((WXHMENU) wParam);
921 break;
922
923 case WM_MENUSELECT:
924 {
925 WXWORD item, flags;
926 WXHMENU hmenu;
927 UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu);
928
929 processed = HandleMenuSelect(item, flags, hmenu);
930 }
931 break;
932
933 case WM_EXITMENULOOP:
934 processed = HandleMenuLoop(wxEVT_MENU_CLOSE, (WXWORD)wParam);
935 break;
936 #endif // wxUSE_MENUS
937
938 case WM_QUERYDRAGICON:
939 {
940 const wxIcon& icon = GetIcon();
941 HICON hIcon = icon.Ok() ? GetHiconOf(icon)
942 : (HICON)GetDefaultIcon();
943 rc = (WXLRESULT)hIcon;
944 processed = rc != 0;
945 }
946 break;
947 #endif // !__WXMICROWIN__
948 }
949
950 if ( !processed )
951 rc = wxFrameBase::MSWWindowProc(message, wParam, lParam);
952
953 return rc;
954 }
955
956 // ----------------------------------------------------------------------------
957 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
958 // from the client area, so the client area is what's really available for the
959 // frame contents
960 // ----------------------------------------------------------------------------
961
962 // get the origin of the client area in the client coordinates
963 wxPoint wxFrame::GetClientAreaOrigin() const
964 {
965 wxPoint pt = wxTopLevelWindow::GetClientAreaOrigin();
966
967 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) && \
968 (!defined(__WXWINCE__) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)))
969 wxToolBar * const toolbar = GetToolBar();
970 if ( toolbar && toolbar->IsShown() )
971 {
972 const wxSize sizeTB = toolbar->GetSize();
973
974 if ( toolbar->HasFlag(wxTB_TOP) )
975 {
976 pt.y += sizeTB.y;
977 }
978 else if ( toolbar->HasFlag(wxTB_LEFT) )
979 {
980 pt.x += sizeTB.x;
981 }
982 }
983 #endif // wxUSE_TOOLBAR
984
985 #if defined(WINCE_WITH_COMMANDBAR)
986 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
987 {
988 RECT rect;
989 ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect);
990 pt.y += (rect.bottom - rect.top);
991 }
992 #endif
993
994 return pt;
995 }