]> git.saurik.com Git - wxWidgets.git/blob - src/msw/frame.cpp
Use wxConvAuto() in wxStyledTextCtrl::DoLoadFile().
[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 || wxUSE_MENUS_NATIVE
65 extern wxMenu *wxCurrentPopupMenu;
66 #endif // wxUSE_MENUS || 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 // generate an artificial resize event
237 void wxFrame::SendSizeEvent(int flags)
238 {
239 if ( !m_iconized )
240 {
241 RECT r = wxGetWindowRect(GetHwnd());
242
243 if ( flags & wxSEND_EVENT_POST )
244 {
245 ::PostMessage(GetHwnd(), WM_SIZE,
246 IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED,
247 MAKELPARAM(r.right - r.left, r.bottom - r.top));
248 }
249 else // send it
250 {
251 ::SendMessage(GetHwnd(), WM_SIZE,
252 IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED,
253 MAKELPARAM(r.right - r.left, r.bottom - r.top));
254 }
255 }
256 }
257
258 #if wxUSE_STATUSBAR
259 wxStatusBar *wxFrame::OnCreateStatusBar(int number,
260 long style,
261 wxWindowID id,
262 const wxString& name)
263 {
264 wxStatusBar *statusBar wxDUMMY_INITIALIZE(NULL);
265
266 #if wxUSE_NATIVE_STATUSBAR
267 if ( !UsesNativeStatusBar() )
268 {
269 statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style);
270 }
271 else
272 #endif
273 {
274 statusBar = new wxStatusBar(this, id, style, name);
275 }
276
277 statusBar->SetFieldsCount(number);
278
279 return statusBar;
280 }
281
282 void wxFrame::PositionStatusBar()
283 {
284 if ( !m_frameStatusBar || !m_frameStatusBar->IsShown() )
285 return;
286
287 int w, h;
288 GetClientSize(&w, &h);
289
290 int sw, sh;
291 m_frameStatusBar->GetSize(&sw, &sh);
292
293 int x = 0;
294 #if wxUSE_TOOLBAR
295 wxToolBar * const toolbar = GetToolBar();
296 if ( toolbar && !toolbar->HasFlag(wxTB_TOP) )
297 {
298 const wxSize sizeTB = toolbar->GetSize();
299
300 if ( toolbar->HasFlag(wxTB_LEFT | wxTB_RIGHT) )
301 {
302 if ( toolbar->HasFlag(wxTB_LEFT) )
303 x -= sizeTB.x;
304
305 w += sizeTB.x;
306 }
307 else // wxTB_BOTTOM
308 {
309 // we need to position the status bar below the toolbar
310 h += sizeTB.y;
311 }
312 }
313 //else: no adjustments necessary for the toolbar on top
314 #endif // wxUSE_TOOLBAR
315
316 // Since we wish the status bar to be directly under the client area,
317 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
318 m_frameStatusBar->SetSize(x, h, w, sh);
319 }
320
321 #endif // wxUSE_STATUSBAR
322
323 #if wxUSE_MENUS_NATIVE
324
325 void wxFrame::AttachMenuBar(wxMenuBar *menubar)
326 {
327 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
328
329 wxMenu *autoMenu = NULL;
330
331 if( menubar->GetMenuCount() == 1 )
332 {
333 autoMenu = wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(menubar->GetMenu(0));
334 SetRightMenu(wxID_ANY, menubar->GetMenuLabel(0), autoMenu);
335 }
336 else
337 {
338 autoMenu = new wxMenu;
339
340 for( size_t n = 0; n < menubar->GetMenuCount(); n++ )
341 {
342 wxMenu *item = menubar->GetMenu(n);
343 wxString label = menubar->GetMenuLabel(n);
344 wxMenu *new_item = wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(item);
345 autoMenu->Append(wxID_ANY, label, new_item);
346 }
347
348 SetRightMenu(wxID_ANY, _("Menu"), autoMenu);
349 }
350
351 #elif defined(WINCE_WITHOUT_COMMANDBAR)
352 if (!GetToolBar())
353 {
354 wxToolMenuBar* toolBar = new wxToolMenuBar(this, wxID_ANY,
355 wxDefaultPosition, wxDefaultSize,
356 wxBORDER_NONE | wxTB_HORIZONTAL,
357 wxToolBarNameStr, menubar);
358 SetToolBar(toolBar);
359 menubar->SetToolBar(toolBar);
360 }
361
362 // When the main window is created using CW_USEDEFAULT the height of the
363 // menubar is not taken into account, so we resize it afterwards if a
364 // menubar is present
365 HWND hwndMenuBar = SHFindMenuBar(GetHwnd());
366 if ( hwndMenuBar )
367 {
368 RECT mbRect;
369 ::GetWindowRect(hwndMenuBar, &mbRect);
370 const int menuHeight = mbRect.bottom - mbRect.top;
371
372 RECT rc;
373 ::GetWindowRect(GetHwnd(), &rc);
374 // adjust for menu / titlebar height
375 rc.bottom -= (2*menuHeight-1);
376
377 ::MoveWindow(GetHwnd(), rc.left, rc.top, rc.right, rc.bottom, FALSE);
378 }
379 #endif
380
381 wxFrameBase::AttachMenuBar(menubar);
382
383 if ( !menubar )
384 {
385 // actually remove the menu from the frame
386 m_hMenu = (WXHMENU)0;
387 InternalSetMenuBar();
388 }
389 else // set new non NULL menu bar
390 {
391 #if !defined(__WXWINCE__) || defined(WINCE_WITH_COMMANDBAR)
392 // Can set a menubar several times.
393 if ( menubar->GetHMenu() )
394 {
395 m_hMenu = menubar->GetHMenu();
396 }
397 else // no HMENU yet
398 {
399 m_hMenu = menubar->Create();
400
401 if ( !m_hMenu )
402 {
403 wxFAIL_MSG( wxT("failed to create menu bar") );
404 return;
405 }
406 }
407 #endif
408 InternalSetMenuBar();
409 }
410 }
411
412 void wxFrame::InternalSetMenuBar()
413 {
414 #if defined(__WXMICROWIN__) || defined(__WXWINCE__)
415 // Nothing
416 #else
417 if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) )
418 {
419 wxLogLastError(wxT("SetMenu"));
420 }
421 #endif
422 }
423
424 #endif // wxUSE_MENUS_NATIVE
425
426 #if wxUSE_MENUS
427 wxMenu* wxFrame::MSWFindMenuFromHMENU(WXHMENU hMenu)
428 {
429 return GetMenuBar() ? GetMenuBar()->MSWGetMenu(hMenu) : NULL;
430 }
431 #endif // wxUSE_MENUS
432
433 // Responds to colour changes, and passes event on to children.
434 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
435 {
436 // Don't override the colour explicitly set by the user, if any.
437 if ( !UseBgCol() )
438 {
439 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
440 Refresh();
441 }
442
443 #if wxUSE_STATUSBAR
444 if ( m_frameStatusBar )
445 {
446 wxSysColourChangedEvent event2;
447 event2.SetEventObject( m_frameStatusBar );
448 m_frameStatusBar->HandleWindowEvent(event2);
449 }
450 #endif // wxUSE_STATUSBAR
451
452 // Propagate the event to the non-top-level children
453 wxWindow::OnSysColourChanged(event);
454 }
455
456 // Pass true to show full screen, false to restore.
457 bool wxFrame::ShowFullScreen(bool show, long style)
458 {
459 // TODO-CE: add support for CE
460 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
461 if ( IsFullScreen() == show )
462 return false;
463
464 if (show)
465 {
466 // zap the toolbar, menubar, and statusbar if needed
467 //
468 // TODO: hide commandbar for WINCE_WITH_COMMANDBAR
469 #if wxUSE_TOOLBAR
470 wxToolBar *theToolBar = GetToolBar();
471
472 if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar)
473 {
474 if ( theToolBar->IsShown() )
475 {
476 theToolBar->SetSize(wxDefaultCoord,0);
477 theToolBar->Show(false);
478 }
479 else // prevent it from being restored later
480 {
481 style &= ~wxFULLSCREEN_NOTOOLBAR;
482 }
483 }
484 #endif // wxUSE_TOOLBAR
485
486 if (style & wxFULLSCREEN_NOMENUBAR)
487 SetMenu((HWND)GetHWND(), (HMENU) NULL);
488
489 #if wxUSE_STATUSBAR
490 wxStatusBar *theStatusBar = GetStatusBar();
491
492 // Save the number of fields in the statusbar
493 if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar)
494 {
495 if ( theStatusBar->IsShown() )
496 theStatusBar->Show(false);
497 else
498 style &= ~wxFULLSCREEN_NOSTATUSBAR;
499 }
500 #endif // wxUSE_STATUSBAR
501 }
502 else // restore to normal
503 {
504 // restore the toolbar, menubar, and statusbar if we had hid them
505 #if wxUSE_TOOLBAR
506 wxToolBar *theToolBar = GetToolBar();
507
508 if ((m_fsStyle & wxFULLSCREEN_NOTOOLBAR) && theToolBar)
509 {
510 theToolBar->Show(true);
511 }
512 #endif // wxUSE_TOOLBAR
513
514 #if wxUSE_MENUS
515 if (m_fsStyle & wxFULLSCREEN_NOMENUBAR)
516 {
517 const WXHMENU hmenu = MSWGetActiveMenu();
518 if ( hmenu )
519 ::SetMenu(GetHwnd(), (HMENU)hmenu);
520 }
521 #endif // wxUSE_MENUS
522
523 #if wxUSE_STATUSBAR
524 wxStatusBar *theStatusBar = GetStatusBar();
525
526 if ((m_fsStyle & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar)
527 {
528 theStatusBar->Show(true);
529 PositionStatusBar();
530 }
531 #endif // wxUSE_STATUSBAR
532 }
533 #endif // !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
534
535 return wxFrameBase::ShowFullScreen(show, style);
536 }
537
538 // ----------------------------------------------------------------------------
539 // tool/status bar stuff
540 // ----------------------------------------------------------------------------
541
542 #if wxUSE_TOOLBAR
543
544 wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
545 {
546 #if defined(WINCE_WITHOUT_COMMANDBAR)
547 // We may already have a toolbar from calling SetMenuBar.
548 if (GetToolBar())
549 return GetToolBar();
550 #endif
551 if ( wxFrameBase::CreateToolBar(style, id, name) )
552 {
553 PositionToolBar();
554 }
555
556 return m_frameToolBar;
557 }
558
559 void wxFrame::PositionToolBar()
560 {
561 // TODO: we want to do something different in WinCE, because the toolbar
562 // should be associated with the commandbar, instead of being
563 // independent window.
564 #if !defined(WINCE_WITHOUT_COMMANDBAR)
565 wxToolBar *toolbar = GetToolBar();
566 if ( toolbar && toolbar->IsShown() )
567 {
568 // don't call our (or even wxTopLevelWindow) version because we want
569 // the real (full) client area size, not excluding the tool/status bar
570 int width, height;
571 wxWindow::DoGetClientSize(&width, &height);
572
573 #if wxUSE_STATUSBAR
574 wxStatusBar *statbar = GetStatusBar();
575 if ( statbar && statbar->IsShown() )
576 {
577 height -= statbar->GetClientSize().y;
578 }
579 #endif // wxUSE_STATUSBAR
580
581 int tx, ty, tw, th;
582 toolbar->GetPosition( &tx, &ty );
583 toolbar->GetSize( &tw, &th );
584
585 int x, y;
586 if ( toolbar->HasFlag(wxTB_BOTTOM) )
587 {
588 x = 0;
589 y = height - th;
590 }
591 else if ( toolbar->HasFlag(wxTB_RIGHT) )
592 {
593 x = width - tw;
594 y = 0;
595 }
596 else // left or top
597 {
598 x = 0;
599 y = 0;
600 }
601
602 #if defined(WINCE_WITH_COMMANDBAR)
603 // We're using a commandbar - so we have to allow for it.
604 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
605 {
606 RECT rect;
607 ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect);
608 y = rect.bottom - rect.top;
609 }
610 #endif // WINCE_WITH_COMMANDBAR
611
612 if ( toolbar->HasFlag(wxTB_BOTTOM) )
613 {
614 if ( ty < 0 && ( -ty == th ) )
615 ty = height - th;
616 if ( tx < 0 && (-tx == tw ) )
617 tx = 0;
618 }
619 else if ( toolbar->HasFlag(wxTB_RIGHT) )
620 {
621 if( ty < 0 && ( -ty == th ) )
622 ty = 0;
623 if( tx < 0 && ( -tx == tw ) )
624 tx = width - tw;
625 }
626 else // left or top
627 {
628 if (ty < 0 && (-ty == th))
629 ty = 0;
630 if (tx < 0 && (-tx == tw))
631 tx = 0;
632 }
633
634 int desiredW,
635 desiredH;
636
637 if ( toolbar->IsVertical() )
638 {
639 desiredW = tw;
640 desiredH = height;
641 }
642 else
643 {
644 desiredW = width;
645 desiredH = th;
646 }
647
648 // use the 'real' MSW position here, don't offset relatively to the
649 // client area origin
650 toolbar->SetSize(x, y, desiredW, desiredH, wxSIZE_NO_ADJUSTMENTS);
651
652 }
653 #endif // !WINCE_WITH_COMMANDBAR
654 }
655
656 #endif // wxUSE_TOOLBAR
657
658 // ----------------------------------------------------------------------------
659 // frame state (iconized/maximized/...)
660 // ----------------------------------------------------------------------------
661
662 // propagate our state change to all child frames: this allows us to emulate X
663 // Windows behaviour where child frames float independently of the parent one
664 // on the desktop, but are iconized/restored with it
665 void wxFrame::IconizeChildFrames(bool bIconize)
666 {
667 m_iconized = bIconize;
668
669 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
670 node;
671 node = node->GetNext() )
672 {
673 wxWindow *win = node->GetData();
674
675 // iconizing the frames with this style under Win95 shell puts them at
676 // the bottom of the screen (as the MDI children) instead of making
677 // them appear in the taskbar because they are, by virtue of this
678 // style, not managed by the taskbar - instead leave Windows take care
679 // of them
680 if ( win->GetWindowStyle() & wxFRAME_TOOL_WINDOW )
681 continue;
682
683 // the child MDI frames are a special case and should not be touched by
684 // the parent frame - instead, they are managed by the user
685 wxFrame *frame = wxDynamicCast(win, wxFrame);
686 if ( frame
687 #if wxUSE_MDI_ARCHITECTURE
688 && !frame->IsMDIChild()
689 #endif // wxUSE_MDI_ARCHITECTURE
690 )
691 {
692 // we don't want to restore the child frames which had been
693 // iconized even before we were iconized, so save the child frame
694 // status when iconizing the parent frame and check it when
695 // restoring it
696 if ( bIconize )
697 {
698 frame->m_wasMinimized = frame->IsIconized();
699 }
700
701 // note that we shouldn't touch the hidden frames neither because
702 // iconizing/restoring them would show them as a side effect
703 if ( !frame->m_wasMinimized && frame->IsShown() )
704 frame->Iconize(bIconize);
705 }
706 }
707 }
708
709 WXHICON wxFrame::GetDefaultIcon() const
710 {
711 // we don't have any standard icons (any more)
712 return (WXHICON)0;
713 }
714
715 // ===========================================================================
716 // message processing
717 // ===========================================================================
718
719 // ---------------------------------------------------------------------------
720 // preprocessing
721 // ---------------------------------------------------------------------------
722
723 bool wxFrame::MSWDoTranslateMessage(wxFrame *frame, WXMSG *pMsg)
724 {
725 if ( wxWindow::MSWTranslateMessage(pMsg) )
726 return true;
727
728 #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
729 // try the menu bar accelerators
730 wxMenuBar *menuBar = GetMenuBar();
731 if ( menuBar && menuBar->GetAcceleratorTable()->Translate(frame, pMsg) )
732 return true;
733 #endif // wxUSE_MENUS && wxUSE_ACCEL
734
735 return false;
736 }
737
738 // ---------------------------------------------------------------------------
739 // our private (non virtual) message handlers
740 // ---------------------------------------------------------------------------
741
742 bool wxFrame::HandleSize(int WXUNUSED(x), int WXUNUSED(y), WXUINT id)
743 {
744 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
745 switch ( id )
746 {
747 case SIZE_RESTORED:
748 case SIZE_MAXIMIZED:
749 // only do it it if we were iconized before, otherwise resizing the
750 // parent frame has a curious side effect of bringing it under it's
751 // children
752 if ( !m_iconized )
753 break;
754
755 // restore all child frames too
756 IconizeChildFrames(false);
757
758 (void)SendIconizeEvent(false);
759 break;
760
761 case SIZE_MINIMIZED:
762 // iconize all child frames too
763 IconizeChildFrames(true);
764 break;
765 }
766 #else
767 wxUnusedVar(id);
768 #endif // !__WXWINCE__
769
770 if ( !m_iconized )
771 {
772 #if wxUSE_STATUSBAR
773 PositionStatusBar();
774 #endif // wxUSE_STATUSBAR
775
776 #if wxUSE_TOOLBAR
777 PositionToolBar();
778 #endif // wxUSE_TOOLBAR
779
780 #if defined(WINCE_WITH_COMMANDBAR)
781 // Position the menu command bar
782 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
783 {
784 RECT rect;
785 ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect);
786 wxSize clientSz = GetClientSize();
787
788 if ( !::MoveWindow((HWND) GetMenuBar()->GetCommandBar(), 0, 0, clientSz.x, rect.bottom - rect.top, true ) )
789 {
790 wxLogLastError(wxT("MoveWindow"));
791 }
792
793 }
794 #endif // WINCE_WITH_COMMANDBAR
795 }
796
797 // call the base class version to generate the appropriate events
798 return false;
799 }
800
801 bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
802 {
803 #if wxUSE_MENUS
804
805 #if defined(WINCE_WITHOUT_COMMANDBAR)
806 if (GetToolBar() && GetToolBar()->FindById(id))
807 return GetToolBar()->MSWCommand(cmd, id);
808 #endif
809
810 // we only need to handle the menu and accelerator commands from the items
811 // of our menu bar, base wxWindow class already handles the rest
812 if ( !control && (cmd == 0 /* menu */ || cmd == 1 /* accel */) )
813 {
814 #if wxUSE_MENUS_NATIVE
815 if ( !wxCurrentPopupMenu )
816 #endif // wxUSE_MENUS_NATIVE
817 {
818 wxMenuItem * const mitem = FindItemInMenuBar((signed short)id);
819 if ( mitem )
820 return ProcessCommand(mitem);
821 }
822 }
823 #endif // wxUSE_MENUS
824
825 return wxFrameBase::HandleCommand(id, cmd, control);;
826 }
827
828 // ---------------------------------------------------------------------------
829 // the window proc for wxFrame
830 // ---------------------------------------------------------------------------
831
832 WXLRESULT wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
833 {
834 WXLRESULT rc = 0;
835 bool processed = false;
836
837 switch ( message )
838 {
839 case WM_CLOSE:
840 // if we can't close, tell the system that we processed the
841 // message - otherwise it would close us
842 processed = !Close();
843 break;
844
845 case WM_SIZE:
846 processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam);
847 break;
848
849 case WM_COMMAND:
850 {
851 WORD id, cmd;
852 WXHWND hwnd;
853 UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam,
854 &id, &hwnd, &cmd);
855
856 HandleCommand(id, cmd, (WXHWND)hwnd);
857
858 // don't pass WM_COMMAND to the base class whether we processed
859 // it or not because we did generate an event for it (our
860 // HandleCommand() calls the base class version) and we must
861 // not do it again or the handlers which skip the event would
862 // be called twice
863 processed = true;
864 }
865 break;
866
867 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
868 case WM_QUERYDRAGICON:
869 {
870 const wxIcon& icon = GetIcon();
871 HICON hIcon = icon.IsOk() ? GetHiconOf(icon)
872 : (HICON)GetDefaultIcon();
873 rc = (WXLRESULT)hIcon;
874 processed = rc != 0;
875 }
876 break;
877 #endif // !__WXMICROWIN__
878 }
879
880 if ( !processed )
881 rc = wxFrameBase::MSWWindowProc(message, wParam, lParam);
882
883 return rc;
884 }
885
886 // ----------------------------------------------------------------------------
887 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
888 // from the client area, so the client area is what's really available for the
889 // frame contents
890 // ----------------------------------------------------------------------------
891
892 // get the origin of the client area in the client coordinates
893 wxPoint wxFrame::GetClientAreaOrigin() const
894 {
895 wxPoint pt = wxTopLevelWindow::GetClientAreaOrigin();
896
897 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) && \
898 (!defined(__WXWINCE__) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)))
899 wxToolBar * const toolbar = GetToolBar();
900 if ( toolbar && toolbar->IsShown() )
901 {
902 const wxSize sizeTB = toolbar->GetSize();
903
904 if ( toolbar->HasFlag(wxTB_TOP) )
905 {
906 pt.y += sizeTB.y;
907 }
908 else if ( toolbar->HasFlag(wxTB_LEFT) )
909 {
910 pt.x += sizeTB.x;
911 }
912 }
913 #endif // wxUSE_TOOLBAR
914
915 #if defined(WINCE_WITH_COMMANDBAR)
916 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
917 {
918 RECT rect;
919 ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect);
920 pt.y += (rect.bottom - rect.top);
921 }
922 #endif
923
924 return pt;
925 }