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