]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/msw/frame.cpp
Added no-remap system option so colourful toolbar buttons
[wxWidgets.git] / src / msw / frame.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: 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#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "frame.h"
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
28 #pragma hdrstop
29#endif
30
31#ifndef WX_PRECOMP
32 #include "wx/frame.h"
33 #include "wx/app.h"
34 #include "wx/menu.h"
35 #include "wx/utils.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/dcclient.h"
39 #include "wx/mdi.h"
40 #include "wx/panel.h"
41#endif // WX_PRECOMP
42
43#include "wx/msw/private.h"
44
45#ifdef __WXWINCE__
46#include <commctrl.h>
47#endif
48
49#if wxUSE_STATUSBAR
50 #include "wx/statusbr.h"
51 #include "wx/generic/statusbr.h"
52#endif // wxUSE_STATUSBAR
53
54#if wxUSE_TOOLBAR
55 #include "wx/toolbar.h"
56#endif // wxUSE_TOOLBAR
57
58#include "wx/menuitem.h"
59#include "wx/log.h"
60
61#ifdef __WXUNIVERSAL__
62 #include "wx/univ/theme.h"
63 #include "wx/univ/colschem.h"
64#endif // __WXUNIVERSAL__
65
66// ----------------------------------------------------------------------------
67// globals
68// ----------------------------------------------------------------------------
69
70#if wxUSE_MENUS_NATIVE
71 extern wxMenu *wxCurrentPopupMenu;
72#endif // 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#if wxUSE_EXTENDED_RTTI
83WX_DEFINE_FLAGS( wxFrameStyle )
84
85wxBEGIN_FLAGS( wxFrameStyle )
86 // new style border flags, we put them first to
87 // use them for streaming out
88 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
89 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
90 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
91 wxFLAGS_MEMBER(wxBORDER_RAISED)
92 wxFLAGS_MEMBER(wxBORDER_STATIC)
93 wxFLAGS_MEMBER(wxBORDER_NONE)
94
95 // old style border flags
96 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
97 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
98 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
99 wxFLAGS_MEMBER(wxRAISED_BORDER)
100 wxFLAGS_MEMBER(wxSTATIC_BORDER)
101 wxFLAGS_MEMBER(wxBORDER)
102
103 // standard window styles
104 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
105 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
106 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
107 wxFLAGS_MEMBER(wxWANTS_CHARS)
108 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
109 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
110 wxFLAGS_MEMBER(wxVSCROLL)
111 wxFLAGS_MEMBER(wxHSCROLL)
112
113 // frame styles
114 wxFLAGS_MEMBER(wxSTAY_ON_TOP)
115 wxFLAGS_MEMBER(wxCAPTION)
116 wxFLAGS_MEMBER(wxTHICK_FRAME)
117 wxFLAGS_MEMBER(wxSYSTEM_MENU)
118 wxFLAGS_MEMBER(wxRESIZE_BORDER)
119 wxFLAGS_MEMBER(wxRESIZE_BOX)
120 wxFLAGS_MEMBER(wxCLOSE_BOX)
121 wxFLAGS_MEMBER(wxMAXIMIZE_BOX)
122 wxFLAGS_MEMBER(wxMINIMIZE_BOX)
123
124 wxFLAGS_MEMBER(wxFRAME_TOOL_WINDOW)
125 wxFLAGS_MEMBER(wxFRAME_FLOAT_ON_PARENT)
126
127 wxFLAGS_MEMBER(wxFRAME_SHAPED)
128
129wxEND_FLAGS( wxFrameStyle )
130
131IMPLEMENT_DYNAMIC_CLASS_XTI(wxFrame, wxTopLevelWindow,"wx/frame.h")
132
133wxBEGIN_PROPERTIES_TABLE(wxFrame)
134 wxEVENT_PROPERTY( Menu , wxEVT_COMMAND_MENU_SELECTED , wxCommandEvent)
135
136 wxPROPERTY( Title,wxString, SetTitle, GetTitle, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
137 wxPROPERTY_FLAGS( WindowStyle , wxFrameStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
138 wxPROPERTY( MenuBar , wxMenuBar * , SetMenuBar , GetMenuBar , , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
139wxEND_PROPERTIES_TABLE()
140
141wxBEGIN_HANDLERS_TABLE(wxFrame)
142wxEND_HANDLERS_TABLE()
143
144wxCONSTRUCTOR_6( wxFrame , wxWindow* , Parent , wxWindowID , Id , wxString , Title , wxPoint , Position , wxSize , Size , long , WindowStyle)
145
146#else
147IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow)
148#endif
149
150// ============================================================================
151// implementation
152// ============================================================================
153
154// ----------------------------------------------------------------------------
155// static class members
156// ----------------------------------------------------------------------------
157
158#if wxUSE_STATUSBAR
159 #if wxUSE_NATIVE_STATUSBAR
160 bool wxFrame::m_useNativeStatusBar = TRUE;
161 #else
162 bool wxFrame::m_useNativeStatusBar = FALSE;
163 #endif
164#endif // wxUSE_NATIVE_STATUSBAR
165
166// ----------------------------------------------------------------------------
167// creation/destruction
168// ----------------------------------------------------------------------------
169
170void wxFrame::Init()
171{
172#if wxUSE_TOOLTIPS
173 m_hwndToolTip = 0;
174#endif
175
176 // Data to save/restore when calling ShowFullScreen
177 m_fsStatusBarFields = 0;
178 m_fsStatusBarHeight = 0;
179 m_fsToolBarHeight = 0;
180
181 m_wasMinimized = FALSE;
182}
183
184bool wxFrame::Create(wxWindow *parent,
185 wxWindowID id,
186 const wxString& title,
187 const wxPoint& pos,
188 const wxSize& size,
189 long style,
190 const wxString& name)
191{
192 if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
193 return FALSE;
194
195 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
196
197 wxModelessWindows.Append(this);
198
199 return TRUE;
200}
201
202wxFrame::~wxFrame()
203{
204 m_isBeingDeleted = TRUE;
205 DeleteAllBars();
206}
207
208// ----------------------------------------------------------------------------
209// wxFrame client size calculations
210// ----------------------------------------------------------------------------
211
212void wxFrame::DoSetClientSize(int width, int height)
213{
214 // leave enough space for the status bar if we have (and show) it
215#if wxUSE_STATUSBAR
216 wxStatusBar *statbar = GetStatusBar();
217 if ( statbar && statbar->IsShown() )
218 {
219 height += statbar->GetSize().y;
220 }
221#endif // wxUSE_STATUSBAR
222
223 // call GetClientAreaOrigin() to take the toolbar into account
224 wxPoint pt = GetClientAreaOrigin();
225 width += pt.x;
226 height += pt.y;
227
228 wxTopLevelWindow::DoSetClientSize(width, height);
229}
230
231// Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
232void wxFrame::DoGetClientSize(int *x, int *y) const
233{
234 wxTopLevelWindow::DoGetClientSize(x, y);
235
236 // account for the possible toolbar
237 wxPoint pt = GetClientAreaOrigin();
238 if ( x )
239 *x -= pt.x;
240
241 if ( y )
242 *y -= pt.y;
243
244#if wxUSE_STATUSBAR
245 // adjust client area height to take the status bar into account
246 if ( y )
247 {
248 wxStatusBar *statbar = GetStatusBar();
249 if ( statbar && statbar->IsShown() )
250 {
251 *y -= statbar->GetClientSize().y;
252 }
253 }
254#endif // wxUSE_STATUSBAR
255}
256
257// ----------------------------------------------------------------------------
258// wxFrame: various geometry-related functions
259// ----------------------------------------------------------------------------
260
261void wxFrame::Raise()
262{
263 ::SetForegroundWindow(GetHwnd());
264}
265
266// generate an artificial resize event
267void wxFrame::SendSizeEvent()
268{
269 if ( !m_iconized )
270 {
271 RECT r = wxGetWindowRect(GetHwnd());
272
273 (void)::PostMessage(GetHwnd(), WM_SIZE,
274 IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED,
275 MAKELPARAM(r.right - r.left, r.bottom - r.top));
276 }
277}
278
279#if wxUSE_STATUSBAR
280wxStatusBar *wxFrame::OnCreateStatusBar(int number,
281 long style,
282 wxWindowID id,
283 const wxString& name)
284{
285 wxStatusBar *statusBar = NULL;
286
287#if wxUSE_NATIVE_STATUSBAR
288 if ( !UsesNativeStatusBar() )
289 {
290 statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style);
291 }
292 else
293#endif
294 {
295 statusBar = new wxStatusBar(this, id, style, name);
296 }
297
298 statusBar->SetFieldsCount(number);
299
300 return statusBar;
301}
302
303void wxFrame::PositionStatusBar()
304{
305 if ( !m_frameStatusBar || !m_frameStatusBar->IsShown() )
306 return;
307
308 int w, h;
309 GetClientSize(&w, &h);
310 int sw, sh;
311 m_frameStatusBar->GetSize(&sw, &sh);
312
313 // Since we wish the status bar to be directly under the client area,
314 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
315 m_frameStatusBar->SetSize(0, h, w, sh);
316}
317#endif // wxUSE_STATUSBAR
318
319#if wxUSE_MENUS_NATIVE
320
321void wxFrame::AttachMenuBar(wxMenuBar *menubar)
322{
323#if defined(__WXWINCE__) && (_WIN32_WCE < 400 || wxUSE_POCKETPC_UI)
324 if (!GetToolBar())
325 {
326 wxToolBar* toolBar = new wxToolBar(this, -1,
327 wxDefaultPosition, wxDefaultSize,
328 wxBORDER_NONE | wxTB_HORIZONTAL,
329 wxToolBarNameStr, menubar);
330 SetToolBar(toolBar);
331 menubar->SetToolBar(toolBar);
332 }
333#endif
334
335 wxFrameBase::AttachMenuBar(menubar);
336
337 if ( !menubar )
338 {
339 // actually remove the menu from the frame
340 m_hMenu = (WXHMENU)0;
341 InternalSetMenuBar();
342 }
343 else // set new non NULL menu bar
344 {
345#if !defined(__WXWINCE__) || (_WIN32_WCE >= 400 && !wxUSE_POCKETPC_UI)
346 // Can set a menubar several times.
347 if ( menubar->GetHMenu() )
348 {
349 m_hMenu = menubar->GetHMenu();
350 }
351 else // no HMENU yet
352 {
353 m_hMenu = menubar->Create();
354
355 if ( !m_hMenu )
356 {
357 wxFAIL_MSG( _T("failed to create menu bar") );
358 return;
359 }
360 }
361#endif
362 InternalSetMenuBar();
363 }
364}
365
366void wxFrame::InternalSetMenuBar()
367{
368#if defined(__WXMICROWIN__) || defined(__WXWINCE__)
369 // Nothing
370#else
371 if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) )
372 {
373 wxLogLastError(wxT("SetMenu"));
374 }
375#endif
376}
377
378#endif // wxUSE_MENUS_NATIVE
379
380// Responds to colour changes, and passes event on to children.
381void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
382{
383 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
384 Refresh();
385
386#if wxUSE_STATUSBAR
387 if ( m_frameStatusBar )
388 {
389 wxSysColourChangedEvent event2;
390 event2.SetEventObject( m_frameStatusBar );
391 m_frameStatusBar->GetEventHandler()->ProcessEvent(event2);
392 }
393#endif // wxUSE_STATUSBAR
394
395 // Propagate the event to the non-top-level children
396 wxWindow::OnSysColourChanged(event);
397}
398
399// Pass TRUE to show full screen, FALSE to restore.
400bool wxFrame::ShowFullScreen(bool show, long style)
401{
402 if ( IsFullScreen() == show )
403 return FALSE;
404
405 if (show)
406 {
407#if wxUSE_TOOLBAR
408#if defined(__WXWINCE__) && (_WIN32_WCE < 400 || wxUSE_POCKETPC_UI)
409 // TODO: hide commandbar
410#else
411 wxToolBar *theToolBar = GetToolBar();
412 if (theToolBar)
413 theToolBar->GetSize(NULL, &m_fsToolBarHeight);
414
415 // zap the toolbar, menubar, and statusbar
416
417 if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar)
418 {
419 theToolBar->SetSize(-1,0);
420 theToolBar->Show(FALSE);
421 }
422#endif // __WXWINCE__
423#endif // wxUSE_TOOLBAR
424
425#if defined(__WXMICROWIN__)
426#elif defined(__WXWINCE__)
427 // TODO: make it work for WinCE
428#else
429 if (style & wxFULLSCREEN_NOMENUBAR)
430 SetMenu((HWND)GetHWND(), (HMENU) NULL);
431#endif
432
433#if wxUSE_STATUSBAR
434 wxStatusBar *theStatusBar = GetStatusBar();
435 if (theStatusBar)
436 theStatusBar->GetSize(NULL, &m_fsStatusBarHeight);
437
438 // Save the number of fields in the statusbar
439 if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar)
440 {
441 //m_fsStatusBarFields = theStatusBar->GetFieldsCount();
442 //SetStatusBar((wxStatusBar*) NULL);
443 //delete theStatusBar;
444 theStatusBar->Show(FALSE);
445 }
446 else
447 m_fsStatusBarFields = 0;
448#endif // wxUSE_STATUSBAR
449 }
450 else
451 {
452#if wxUSE_TOOLBAR
453#if defined(__WXWINCE__) && (_WIN32_WCE < 400 || wxUSE_POCKETPC_UI)
454 // TODO: show commandbar
455#else
456 wxToolBar *theToolBar = GetToolBar();
457
458 // restore the toolbar, menubar, and statusbar
459 if (theToolBar && (m_fsStyle & wxFULLSCREEN_NOTOOLBAR))
460 {
461 theToolBar->SetSize(-1, m_fsToolBarHeight);
462 theToolBar->Show(TRUE);
463 }
464#endif // __WXWINCE__
465#endif // wxUSE_TOOLBAR
466
467#if wxUSE_STATUSBAR
468 if ( m_fsStyle & wxFULLSCREEN_NOSTATUSBAR )
469 {
470 //CreateStatusBar(m_fsStatusBarFields);
471 if (GetStatusBar())
472 {
473 GetStatusBar()->Show(TRUE);
474 PositionStatusBar();
475 }
476 }
477#endif // wxUSE_STATUSBAR
478
479#if defined(__WXMICROWIN__)
480#elif defined(__WXWINCE__)
481 // TODO: make it work for WinCE
482#else
483 if ((m_fsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0))
484 SetMenu((HWND)GetHWND(), (HMENU)m_hMenu);
485#endif
486 }
487
488 return wxFrameBase::ShowFullScreen(show, style);
489}
490
491// ----------------------------------------------------------------------------
492// tool/status bar stuff
493// ----------------------------------------------------------------------------
494
495#if wxUSE_TOOLBAR
496
497wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
498{
499#if defined(__WXWINCE__) && (_WIN32_WCE < 400 || wxUSE_POCKETPC_UI)
500 // We may already have a toolbar from calling SetMenuBar.
501 if (GetToolBar())
502 return GetToolBar();
503#endif
504 if ( wxFrameBase::CreateToolBar(style, id, name) )
505 {
506 PositionToolBar();
507 }
508
509 return m_frameToolBar;
510}
511
512void wxFrame::PositionToolBar()
513{
514 wxToolBar *toolbar = GetToolBar();
515 if ( toolbar && toolbar->IsShown() )
516 {
517#if defined(__WXWINCE__) && (_WIN32_WCE < 400 || wxUSE_POCKETPC_UI)
518 // We want to do something different in WinCE, because
519 // the toolbar should be associated with the commandbar,
520 // and not an independent window.
521 // TODO
522#else
523 // don't call our (or even wxTopLevelWindow) version because we want
524 // the real (full) client area size, not excluding the tool/status bar
525 int width, height;
526 wxWindow::DoGetClientSize(&width, &height);
527
528#if wxUSE_STATUSBAR
529 wxStatusBar *statbar = GetStatusBar();
530 if ( statbar && statbar->IsShown() )
531 {
532 height -= statbar->GetClientSize().y;
533 }
534#endif // wxUSE_STATUSBAR
535
536 int tx, ty;
537 int tw, th;
538 toolbar->GetPosition(&tx, &ty);
539 toolbar->GetSize(&tw, &th);
540
541 // Adjust
542 if (ty < 0 && (-ty == th))
543 ty = 0;
544 if (tx < 0 && (-tx == tw))
545 tx = 0;
546
547 int desiredW = tw;
548 int desiredH = th;
549
550 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
551 {
552 desiredH = height;
553 }
554 else
555 {
556 desiredW = width;
557// if ( toolbar->GetWindowStyleFlag() & wxTB_FLAT )
558// desiredW -= 3;
559 }
560
561 // use the 'real' MSW position here, don't offset relativly to the
562 // client area origin
563
564 // Optimise such that we don't have to always resize the toolbar
565 // when the frame changes, otherwise we'll get a lot of flicker.
566 bool heightChanging = TRUE;
567 bool widthChanging = TRUE;
568
569 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
570 {
571 // It's OK if the current height is greater than what can be shown.
572 heightChanging = (desiredH > th) ;
573 widthChanging = (desiredW != tw) ;
574
575 // The next time around, we may not have to set the size
576 if (heightChanging)
577 desiredH = desiredH + 200;
578 }
579 else
580 {
581 // It's OK if the current width is greater than what can be shown.
582 widthChanging = (desiredW > tw) ;
583 heightChanging = (desiredH != th) ;
584
585 // The next time around, we may not have to set the size
586 if (widthChanging)
587 desiredW = desiredW + 200;
588 }
589
590 if (tx != 0 || ty != 0 || widthChanging || heightChanging)
591 toolbar->SetSize(0, 0, desiredW, desiredH, wxSIZE_NO_ADJUSTMENTS);
592
593#endif // __WXWINCE__
594 }
595}
596
597#endif // wxUSE_TOOLBAR
598
599// ----------------------------------------------------------------------------
600// frame state (iconized/maximized/...)
601// ----------------------------------------------------------------------------
602
603// propagate our state change to all child frames: this allows us to emulate X
604// Windows behaviour where child frames float independently of the parent one
605// on the desktop, but are iconized/restored with it
606void wxFrame::IconizeChildFrames(bool bIconize)
607{
608 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
609 node;
610 node = node->GetNext() )
611 {
612 wxWindow *win = node->GetData();
613
614 // iconizing the frames with this style under Win95 shell puts them at
615 // the bottom of the screen (as the MDI children) instead of making
616 // them appear in the taskbar because they are, by virtue of this
617 // style, not managed by the taskbar - instead leave Windows take care
618 // of them
619#ifdef __WIN95__
620 if ( win->GetWindowStyle() & wxFRAME_TOOL_WINDOW )
621 continue;
622#endif // Win95
623
624 // the child MDI frames are a special case and should not be touched by
625 // the parent frame - instead, they are managed by the user
626 wxFrame *frame = wxDynamicCast(win, wxFrame);
627 if ( frame
628#if wxUSE_MDI_ARCHITECTURE
629 && !wxDynamicCast(frame, wxMDIChildFrame)
630#endif // wxUSE_MDI_ARCHITECTURE
631 )
632 {
633 // we don't want to restore the child frames which had been
634 // iconized even before we were iconized, so save the child frame
635 // status when iconizing the parent frame and check it when
636 // restoring it
637 if ( bIconize )
638 {
639 frame->m_wasMinimized = frame->IsIconized();
640 }
641
642 // note that we shouldn't touch the hidden frames neither because
643 // iconizing/restoring them would show them as a side effect
644 if ( !frame->m_wasMinimized && frame->IsShown() )
645 frame->Iconize(bIconize);
646 }
647 }
648}
649
650WXHICON wxFrame::GetDefaultIcon() const
651{
652 // we don't have any standard icons (any more)
653 return (WXHICON)0;
654}
655
656// ===========================================================================
657// message processing
658// ===========================================================================
659
660// ---------------------------------------------------------------------------
661// preprocessing
662// ---------------------------------------------------------------------------
663
664bool wxFrame::MSWTranslateMessage(WXMSG* pMsg)
665{
666 if ( wxWindow::MSWTranslateMessage(pMsg) )
667 return TRUE;
668
669#if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
670 // try the menu bar accels
671 wxMenuBar *menuBar = GetMenuBar();
672 if ( !menuBar )
673 return FALSE;
674
675 const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable();
676 return acceleratorTable.Translate(this, pMsg);
677#else
678 return FALSE;
679#endif // wxUSE_MENUS && wxUSE_ACCEL
680}
681
682// ---------------------------------------------------------------------------
683// our private (non virtual) message handlers
684// ---------------------------------------------------------------------------
685
686bool wxFrame::HandlePaint()
687{
688 RECT rect;
689 if ( GetUpdateRect(GetHwnd(), &rect, FALSE) )
690 {
691#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
692 if ( m_iconized )
693 {
694 const wxIcon& icon = GetIcon();
695 HICON hIcon = icon.Ok() ? GetHiconOf(icon)
696 : (HICON)GetDefaultIcon();
697
698 // Hold a pointer to the dc so long as the OnPaint() message
699 // is being processed
700 PAINTSTRUCT ps;
701 HDC hdc = ::BeginPaint(GetHwnd(), &ps);
702
703 // Erase background before painting or we get white background
704 MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L);
705
706 if ( hIcon )
707 {
708 RECT rect;
709 ::GetClientRect(GetHwnd(), &rect);
710
711 // FIXME: why hardcoded?
712 static const int icon_width = 32;
713 static const int icon_height = 32;
714
715 int icon_x = (int)((rect.right - icon_width)/2);
716 int icon_y = (int)((rect.bottom - icon_height)/2);
717
718 ::DrawIcon(hdc, icon_x, icon_y, hIcon);
719 }
720
721 ::EndPaint(GetHwnd(), &ps);
722
723 return TRUE;
724 }
725 else
726 #endif
727 {
728 return wxWindow::HandlePaint();
729 }
730 }
731 else
732 {
733 // nothing to paint - processed
734 return TRUE;
735 }
736}
737
738bool wxFrame::HandleSize(int x, int y, WXUINT id)
739{
740 bool processed = FALSE;
741#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
742
743 switch ( id )
744 {
745 case SIZENORMAL:
746 // only do it it if we were iconized before, otherwise resizing the
747 // parent frame has a curious side effect of bringing it under it's
748 // children
749 if ( !m_iconized )
750 break;
751
752 // restore all child frames too
753 IconizeChildFrames(FALSE);
754
755 (void)SendIconizeEvent(FALSE);
756
757 // fall through
758
759 case SIZEFULLSCREEN:
760 m_iconized = FALSE;
761 break;
762
763 case SIZEICONIC:
764 // iconize all child frames too
765 IconizeChildFrames(TRUE);
766
767 (void)SendIconizeEvent();
768
769 m_iconized = TRUE;
770 break;
771 }
772#endif
773
774 if ( !m_iconized )
775 {
776#if wxUSE_STATUSBAR
777 PositionStatusBar();
778#endif // wxUSE_STATUSBAR
779
780#if wxUSE_TOOLBAR
781 PositionToolBar();
782#endif // wxUSE_TOOLBAR
783
784 processed = wxWindow::HandleSize(x, y, id);
785 }
786
787 return processed;
788}
789
790bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
791{
792 if ( control )
793 {
794 // In case it's e.g. a toolbar.
795 wxWindow *win = wxFindWinFromHandle(control);
796 if ( win )
797 return win->MSWCommand(cmd, id);
798 }
799
800 // handle here commands from menus and accelerators
801 if ( cmd == 0 || cmd == 1 )
802 {
803#if wxUSE_MENUS_NATIVE
804 if ( wxCurrentPopupMenu )
805 {
806 wxMenu *popupMenu = wxCurrentPopupMenu;
807 wxCurrentPopupMenu = NULL;
808
809 return popupMenu->MSWCommand(cmd, id);
810 }
811#endif // wxUSE_MENUS_NATIVE
812
813 if ( ProcessCommand(id) )
814 {
815 return TRUE;
816 }
817 }
818
819 return FALSE;
820}
821
822bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu)
823{
824 int item;
825 if ( flags == 0xFFFF && hMenu == 0 )
826 {
827 // menu was removed from screen
828 item = -1;
829 }
830#ifndef __WXMICROWIN__
831 else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) )
832 {
833 item = nItem;
834 }
835#endif
836 else
837 {
838 // don't give hints for separators (doesn't make sense) nor for the
839 // items opening popup menus (they don't have them anyhow) but do clear
840 // the status line - otherwise, we would be left with the help message
841 // for the previous item which doesn't apply any more
842 DoGiveHelp(wxEmptyString, FALSE);
843
844 return FALSE;
845 }
846
847 wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item);
848 event.SetEventObject(this);
849
850 return GetEventHandler()->ProcessEvent(event);
851}
852
853bool wxFrame::HandleMenuLoop(const wxEventType& evtType, WXWORD isPopup)
854{
855 // we don't have the menu id here, so we use the id to specify if the event
856 // was from a popup menu or a normal one
857 wxMenuEvent event(evtType, isPopup ? -1 : 0);
858 event.SetEventObject(this);
859
860 return GetEventHandler()->ProcessEvent(event);
861}
862
863// ---------------------------------------------------------------------------
864// the window proc for wxFrame
865// ---------------------------------------------------------------------------
866
867long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
868{
869 long rc = 0;
870 bool processed = FALSE;
871
872 switch ( message )
873 {
874 case WM_CLOSE:
875 // if we can't close, tell the system that we processed the
876 // message - otherwise it would close us
877 processed = !Close();
878 break;
879
880 case WM_SIZE:
881 processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam);
882 break;
883
884 case WM_COMMAND:
885 {
886 WORD id, cmd;
887 WXHWND hwnd;
888 UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam,
889 &id, &hwnd, &cmd);
890
891 processed = HandleCommand(id, cmd, (WXHWND)hwnd);
892 }
893 break;
894
895 case WM_PAINT:
896 processed = HandlePaint();
897 break;
898
899 case WM_INITMENUPOPUP:
900 processed = HandleInitMenuPopup((WXHMENU) wParam);
901 break;
902
903#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
904 case WM_MENUSELECT:
905 {
906 WXWORD item, flags;
907 WXHMENU hmenu;
908 UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu);
909
910 processed = HandleMenuSelect(item, flags, hmenu);
911 }
912 break;
913
914 case WM_EXITMENULOOP:
915 processed = HandleMenuLoop(wxEVT_MENU_CLOSE, wParam);
916 break;
917
918 case WM_QUERYDRAGICON:
919 {
920 const wxIcon& icon = GetIcon();
921 HICON hIcon = icon.Ok() ? GetHiconOf(icon)
922 : (HICON)GetDefaultIcon();
923 rc = (long)hIcon;
924 processed = rc != 0;
925 }
926 break;
927#endif // !__WXMICROWIN__
928 }
929
930 if ( !processed )
931 rc = wxFrameBase::MSWWindowProc(message, wParam, lParam);
932
933 return rc;
934}
935
936// handle WM_INITMENUPOPUP message
937bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu)
938{
939 wxMenu* menu = NULL;
940 if (GetMenuBar())
941 {
942 int nCount = GetMenuBar()->GetMenuCount();
943 for (int n = 0; n < nCount; n++)
944 {
945 if (GetMenuBar()->GetMenu(n)->GetHMenu() == hMenu)
946 {
947 menu = GetMenuBar()->GetMenu(n);
948 break;
949 }
950 }
951 }
952
953 wxMenuEvent event(wxEVT_MENU_OPEN, 0, menu);
954 event.SetEventObject(this);
955
956 return GetEventHandler()->ProcessEvent(event);
957}