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