]> git.saurik.com Git - wxWidgets.git/blame - src/msw/frame.cpp
In the object destructor, leave m_cocoaNSView intact for base class destructors
[wxWidgets.git] / src / msw / frame.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
7c0ea335 2// Name: msw/frame.cpp
0d53fc34 3// Purpose: wxFrame
2bda0e17
KB
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
6c9a19aa 8// Copyright: (c) Julian Smart
2bda0e17
KB
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
7c0ea335
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
2bda0e17 20#ifdef __GNUG__
7c0ea335 21 #pragma implementation "frame.h"
2bda0e17
KB
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
9f3362c4 28 #pragma hdrstop
2bda0e17
KB
29#endif
30
31#ifndef WX_PRECOMP
9f3362c4 32 #include "wx/frame.h"
9f3362c4 33 #include "wx/app.h"
1e6feb95 34 #include "wx/menu.h"
9f3362c4
VZ
35 #include "wx/utils.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/dcclient.h"
d3cc7c65 39 #include "wx/mdi.h"
f6bcfd97 40 #include "wx/panel.h"
9f3362c4 41#endif // WX_PRECOMP
2bda0e17
KB
42
43#include "wx/msw/private.h"
7c0ea335 44
4676948b
JS
45#ifdef __WXWINCE__
46#include <commctrl.h>
47#endif
48
7c0ea335
VZ
49#if wxUSE_STATUSBAR
50 #include "wx/statusbr.h"
ed791986 51 #include "wx/generic/statusbr.h"
7c0ea335
VZ
52#endif // wxUSE_STATUSBAR
53
54#if wxUSE_TOOLBAR
55 #include "wx/toolbar.h"
56#endif // wxUSE_TOOLBAR
57
2bda0e17 58#include "wx/menuitem.h"
6776a0b2 59#include "wx/log.h"
2bda0e17 60
1e6feb95
VZ
61#ifdef __WXUNIVERSAL__
62 #include "wx/univ/theme.h"
63 #include "wx/univ/colschem.h"
64#endif // __WXUNIVERSAL__
65
7c0ea335
VZ
66// ----------------------------------------------------------------------------
67// globals
68// ----------------------------------------------------------------------------
2bda0e17 69
1e6feb95 70#if wxUSE_MENUS_NATIVE
03baf031 71 extern wxMenu *wxCurrentPopupMenu;
1e6feb95 72#endif // wxUSE_MENUS_NATIVE
2bda0e17 73
7c0ea335
VZ
74// ----------------------------------------------------------------------------
75// event tables
76// ----------------------------------------------------------------------------
77
0d53fc34 78BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
0d53fc34 79 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
2bda0e17
KB
80END_EVENT_TABLE()
81
58b43418 82IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow)
2bda0e17 83
7c0ea335
VZ
84// ============================================================================
85// implementation
86// ============================================================================
87
88// ----------------------------------------------------------------------------
89// static class members
90// ----------------------------------------------------------------------------
91
1e6feb95
VZ
92#if wxUSE_STATUSBAR
93 #if wxUSE_NATIVE_STATUSBAR
0d53fc34 94 bool wxFrame::m_useNativeStatusBar = TRUE;
1e6feb95 95 #else
0d53fc34 96 bool wxFrame::m_useNativeStatusBar = FALSE;
1e6feb95
VZ
97 #endif
98#endif // wxUSE_NATIVE_STATUSBAR
2bda0e17 99
7c0ea335
VZ
100// ----------------------------------------------------------------------------
101// creation/destruction
102// ----------------------------------------------------------------------------
2bda0e17 103
0d53fc34 104void wxFrame::Init()
2bda0e17 105{
9f3362c4
VZ
106#if wxUSE_TOOLTIPS
107 m_hwndToolTip = 0;
108#endif
4676948b
JS
109#ifdef __WXWINCE__
110 m_commandBar = 0;
111#endif
a2327a9f
JS
112
113 // Data to save/restore when calling ShowFullScreen
a2327a9f
JS
114 m_fsStatusBarFields = 0;
115 m_fsStatusBarHeight = 0;
116 m_fsToolBarHeight = 0;
f6bcfd97 117
9327c3aa 118 m_wasMinimized = FALSE;
7c0ea335 119}
9f3362c4 120
0d53fc34 121bool wxFrame::Create(wxWindow *parent,
7c0ea335
VZ
122 wxWindowID id,
123 const wxString& title,
124 const wxPoint& pos,
125 const wxSize& size,
126 long style,
127 const wxString& name)
128{
82c9f85c
VZ
129 if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
130 return FALSE;
d2aef312 131
a756f210 132 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
2bda0e17 133
82c9f85c 134 wxModelessWindows.Append(this);
f6bcfd97 135
82c9f85c 136 return TRUE;
2bda0e17
KB
137}
138
0d53fc34 139wxFrame::~wxFrame()
2bda0e17 140{
82c9f85c 141 m_isBeingDeleted = TRUE;
82c9f85c 142 DeleteAllBars();
4676948b
JS
143#ifdef __WXWINCE__
144 if (m_commandBar)
145 {
146 ::DestroyWindow((HWND) m_commandBar);
147 m_commandBar = NULL;
148 }
149#endif
150
2bda0e17
KB
151}
152
d4597e13
VZ
153// ----------------------------------------------------------------------------
154// wxFrame client size calculations
155// ----------------------------------------------------------------------------
2bda0e17 156
0d53fc34 157void wxFrame::DoSetClientSize(int width, int height)
2bda0e17 158{
82c9f85c 159 // leave enough space for the status bar if we have (and show) it
7c0ea335 160#if wxUSE_STATUSBAR
8d8bd249
VZ
161 wxStatusBar *statbar = GetStatusBar();
162 if ( statbar && statbar->IsShown() )
163 {
8d8bd249
VZ
164 height += statbar->GetSize().y;
165 }
7c0ea335 166#endif // wxUSE_STATUSBAR
2bda0e17 167
68d02db3
VZ
168 // call GetClientAreaOrigin() to take the toolbar into account
169 wxPoint pt = GetClientAreaOrigin();
170 width += pt.x;
171 height += pt.y;
172
82c9f85c 173 wxTopLevelWindow::DoSetClientSize(width, height);
2bda0e17
KB
174}
175
d4597e13
VZ
176// Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
177void wxFrame::DoGetClientSize(int *x, int *y) const
178{
179 wxTopLevelWindow::DoGetClientSize(x, y);
180
68d02db3
VZ
181 // account for the possible toolbar
182 wxPoint pt = GetClientAreaOrigin();
183 if ( x )
184 *x -= pt.x;
185
186 if ( y )
187 *y -= pt.y;
188
d4597e13
VZ
189#if wxUSE_STATUSBAR
190 // adjust client area height to take the status bar into account
191 if ( y )
192 {
193 wxStatusBar *statbar = GetStatusBar();
194 if ( statbar && statbar->IsShown() )
195 {
196 *y -= statbar->GetClientSize().y;
197 }
198 }
199#endif // wxUSE_STATUSBAR
200}
201
7c0ea335 202// ----------------------------------------------------------------------------
0d53fc34 203// wxFrame: various geometry-related functions
7c0ea335
VZ
204// ----------------------------------------------------------------------------
205
0d53fc34 206void wxFrame::Raise()
c48926e1 207{
c48926e1 208 ::SetForegroundWindow(GetHwnd());
c48926e1
VZ
209}
210
67bd5bad 211// generate an artificial resize event
0d53fc34 212void wxFrame::SendSizeEvent()
67bd5bad 213{
67bd5bad
GT
214 if ( !m_iconized )
215 {
82c9f85c
VZ
216 RECT r = wxGetWindowRect(GetHwnd());
217
67bd5bad
GT
218 (void)::PostMessage(GetHwnd(), WM_SIZE,
219 IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED,
220 MAKELPARAM(r.right - r.left, r.bottom - r.top));
221 }
222}
223
d427503c 224#if wxUSE_STATUSBAR
0d53fc34 225wxStatusBar *wxFrame::OnCreateStatusBar(int number,
7c0ea335
VZ
226 long style,
227 wxWindowID id,
228 const wxString& name)
2bda0e17
KB
229{
230 wxStatusBar *statusBar = NULL;
231
47d67540 232#if wxUSE_NATIVE_STATUSBAR
1f0500b3 233 if ( !UsesNativeStatusBar() )
2bda0e17 234 {
1f0500b3 235 statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style);
2bda0e17
KB
236 }
237 else
238#endif
239 {
1f0500b3
VZ
240 statusBar = new wxStatusBar(this, id, style, name);
241 }
ed791986 242
1f0500b3 243 statusBar->SetFieldsCount(number);
2bda0e17 244
7c0ea335 245 return statusBar;
2bda0e17
KB
246}
247
0d53fc34 248void wxFrame::PositionStatusBar()
2bda0e17 249{
d4597e13 250 if ( !m_frameStatusBar || !m_frameStatusBar->IsShown() )
ed791986
VZ
251 return;
252
cbc66a27
VZ
253 int w, h;
254 GetClientSize(&w, &h);
255 int sw, sh;
256 m_frameStatusBar->GetSize(&sw, &sh);
257
258 // Since we wish the status bar to be directly under the client area,
259 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
260 m_frameStatusBar->SetSize(0, h, w, sh);
2bda0e17 261}
d427503c 262#endif // wxUSE_STATUSBAR
2bda0e17 263
6522713c 264#if wxUSE_MENUS_NATIVE
ea9a4296 265
0d53fc34 266void wxFrame::AttachMenuBar(wxMenuBar *menubar)
2bda0e17 267{
f008af16 268 wxFrameBase::AttachMenuBar(menubar);
6beb85c0 269
f6bcfd97 270 if ( !menubar )
c2dcfdef 271 {
f6bcfd97
BP
272 // actually remove the menu from the frame
273 m_hMenu = (WXHMENU)0;
274 InternalSetMenuBar();
065de612 275 }
f6bcfd97 276 else // set new non NULL menu bar
065de612 277 {
f6bcfd97 278 // Can set a menubar several times.
f6bcfd97
BP
279 if ( menubar->GetHMenu() )
280 {
281 m_hMenu = menubar->GetHMenu();
282 }
f008af16 283 else // no HMENU yet
f6bcfd97 284 {
f6bcfd97 285 m_hMenu = menubar->Create();
065de612 286
f6bcfd97 287 if ( !m_hMenu )
f008af16
VZ
288 {
289 wxFAIL_MSG( _T("failed to create menu bar") );
f6bcfd97 290 return;
f008af16 291 }
f6bcfd97 292 }
065de612 293
f6bcfd97 294 InternalSetMenuBar();
1e6feb95 295 }
2bda0e17
KB
296}
297
0d53fc34 298void wxFrame::InternalSetMenuBar()
2bda0e17 299{
4676948b
JS
300#ifdef __WXMICROWIN__
301 // Nothing
302#elif defined(__WXWINCE__)
303 if (!m_commandBar)
304 {
305 // TODO: what identifer shall we use?
306 // TODO: eventually have a wxCommandBar class
307 m_commandBar = (WXHWND) CommandBar_Create(wxGetInstance(), GetHwnd(), 999);
308 }
309 if (m_commandBar)
310 {
311 CommandBar_InsertMenubarEx((HWND) m_commandBar, wxGetInstance(),
312 (LPTSTR) (HMENU) m_hMenu, 0);
313 }
314#else
42e69d6b 315 if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) )
2bda0e17 316 {
f6bcfd97 317 wxLogLastError(wxT("SetMenu"));
2bda0e17 318 }
04ef50df 319#endif
2bda0e17
KB
320}
321
1e6feb95
VZ
322#endif // wxUSE_MENUS_NATIVE
323
2bda0e17 324// Responds to colour changes, and passes event on to children.
0d53fc34 325void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
2bda0e17 326{
a756f210 327 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
2bda0e17
KB
328 Refresh();
329
1e6feb95 330#if wxUSE_STATUSBAR
2bda0e17
KB
331 if ( m_frameStatusBar )
332 {
333 wxSysColourChangedEvent event2;
334 event2.SetEventObject( m_frameStatusBar );
02800301 335 m_frameStatusBar->GetEventHandler()->ProcessEvent(event2);
2bda0e17 336 }
1e6feb95 337#endif // wxUSE_STATUSBAR
2bda0e17
KB
338
339 // Propagate the event to the non-top-level children
340 wxWindow::OnSysColourChanged(event);
341}
342
a2327a9f 343// Pass TRUE to show full screen, FALSE to restore.
0d53fc34 344bool wxFrame::ShowFullScreen(bool show, long style)
a2327a9f 345{
085ad686 346 if ( IsFullScreen() == show )
c641b1d2
VS
347 return FALSE;
348
a2327a9f
JS
349 if (show)
350 {
1e6feb95 351#if wxUSE_TOOLBAR
f6bcfd97 352 wxToolBar *theToolBar = GetToolBar();
a2327a9f 353 if (theToolBar)
1e6feb95 354 theToolBar->GetSize(NULL, &m_fsToolBarHeight);
a2327a9f
JS
355
356 // zap the toolbar, menubar, and statusbar
357
358 if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar)
359 {
360 theToolBar->SetSize(-1,0);
361 theToolBar->Show(FALSE);
362 }
1e6feb95 363#endif // wxUSE_TOOLBAR
a2327a9f 364
4676948b
JS
365 // TODO: make it work for WinCE
366#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
a2327a9f
JS
367 if (style & wxFULLSCREEN_NOMENUBAR)
368 SetMenu((HWND)GetHWND(), (HMENU) NULL);
04ef50df 369#endif
a2327a9f 370
1e6feb95
VZ
371#if wxUSE_STATUSBAR
372 wxStatusBar *theStatusBar = GetStatusBar();
373 if (theStatusBar)
374 theStatusBar->GetSize(NULL, &m_fsStatusBarHeight);
375
a2327a9f
JS
376 // Save the number of fields in the statusbar
377 if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar)
378 {
579b10c2
JS
379 //m_fsStatusBarFields = theStatusBar->GetFieldsCount();
380 //SetStatusBar((wxStatusBar*) NULL);
381 //delete theStatusBar;
382 theStatusBar->Show(FALSE);
a2327a9f
JS
383 }
384 else
385 m_fsStatusBarFields = 0;
1e6feb95 386#endif // wxUSE_STATUSBAR
a2327a9f
JS
387 }
388 else
389 {
1e6feb95 390#if wxUSE_TOOLBAR
a2327a9f
JS
391 wxToolBar *theToolBar = GetToolBar();
392
393 // restore the toolbar, menubar, and statusbar
394 if (theToolBar && (m_fsStyle & wxFULLSCREEN_NOTOOLBAR))
395 {
396 theToolBar->SetSize(-1, m_fsToolBarHeight);
397 theToolBar->Show(TRUE);
398 }
1e6feb95 399#endif // wxUSE_TOOLBAR
a2327a9f 400
1e6feb95
VZ
401#if wxUSE_STATUSBAR
402 if ( m_fsStyle & wxFULLSCREEN_NOSTATUSBAR )
a2327a9f 403 {
579b10c2
JS
404 //CreateStatusBar(m_fsStatusBarFields);
405 if (GetStatusBar())
406 {
407 GetStatusBar()->Show(TRUE);
408 PositionStatusBar();
409 }
a2327a9f 410 }
1e6feb95 411#endif // wxUSE_STATUSBAR
a2327a9f 412
4676948b
JS
413 // TODO: make it work for WinCE
414#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
a2327a9f
JS
415 if ((m_fsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0))
416 SetMenu((HWND)GetHWND(), (HMENU)m_hMenu);
04ef50df 417#endif
a2327a9f 418 }
f6bcfd97 419
085ad686 420 return wxFrameBase::ShowFullScreen(show, style);
2bda0e17
KB
421}
422
7c0ea335
VZ
423// ----------------------------------------------------------------------------
424// tool/status bar stuff
425// ----------------------------------------------------------------------------
426
d427503c 427#if wxUSE_TOOLBAR
7c0ea335 428
0d53fc34 429wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
81d66cf3 430{
7c0ea335 431 if ( wxFrameBase::CreateToolBar(style, id, name) )
81d66cf3 432 {
81d66cf3 433 PositionToolBar();
81d66cf3 434 }
81d66cf3 435
7c0ea335 436 return m_frameToolBar;
81d66cf3
JS
437}
438
0d53fc34 439void wxFrame::PositionToolBar()
81d66cf3 440{
d4597e13
VZ
441 wxToolBar *toolbar = GetToolBar();
442 if ( toolbar && toolbar->IsShown() )
443 {
444 // don't call our (or even wxTopLevelWindow) version because we want
445 // the real (full) client area size, not excluding the tool/status bar
446 int width, height;
447 wxWindow::DoGetClientSize(&width, &height);
81d66cf3 448
7c0ea335 449#if wxUSE_STATUSBAR
d4597e13
VZ
450 wxStatusBar *statbar = GetStatusBar();
451 if ( statbar && statbar->IsShown() )
452 {
453 height -= statbar->GetClientSize().y;
454 }
7c0ea335 455#endif // wxUSE_STATUSBAR
81d66cf3 456
81d66cf3 457 int tw, th;
d4597e13 458 toolbar->GetSize(&tw, &th);
81d66cf3 459
d4597e13 460 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
81d66cf3 461 {
d4597e13 462 th = height;
81d66cf3
JS
463 }
464 else
465 {
d4597e13 466 tw = width;
98b96436
RR
467 if ( toolbar->GetWindowStyleFlag() & wxTB_FLAT )
468 th -= 3;
81d66cf3 469 }
7c0ea335 470
d4597e13
VZ
471 // use the 'real' MSW position here, don't offset relativly to the
472 // client area origin
473 toolbar->SetSize(0, 0, tw, th, wxSIZE_NO_ADJUSTMENTS);
81d66cf3
JS
474 }
475}
d4597e13 476
d427503c 477#endif // wxUSE_TOOLBAR
d2aef312 478
7c0ea335
VZ
479// ----------------------------------------------------------------------------
480// frame state (iconized/maximized/...)
481// ----------------------------------------------------------------------------
482
a23fd0e1
VZ
483// propagate our state change to all child frames: this allows us to emulate X
484// Windows behaviour where child frames float independently of the parent one
485// on the desktop, but are iconized/restored with it
0d53fc34 486void wxFrame::IconizeChildFrames(bool bIconize)
d2aef312 487{
222ed1d6 488 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
a23fd0e1
VZ
489 node;
490 node = node->GetNext() )
491 {
492 wxWindow *win = node->GetData();
493
3ca6a5f0
BP
494 // iconizing the frames with this style under Win95 shell puts them at
495 // the bottom of the screen (as the MDI children) instead of making
496 // them appear in the taskbar because they are, by virtue of this
497 // style, not managed by the taskbar - instead leave Windows take care
498 // of them
499#ifdef __WIN95__
500 if ( win->GetWindowStyle() & wxFRAME_TOOL_WINDOW )
501 continue;
502#endif // Win95
503
3f7bc32b
VZ
504 // the child MDI frames are a special case and should not be touched by
505 // the parent frame - instead, they are managed by the user
2e9f62da 506 wxFrame *frame = wxDynamicCast(win, wxFrame);
1e6feb95
VZ
507 if ( frame
508#if wxUSE_MDI_ARCHITECTURE
509 && !wxDynamicCast(frame, wxMDIChildFrame)
510#endif // wxUSE_MDI_ARCHITECTURE
511 )
a23fd0e1 512 {
9327c3aa
VZ
513 // we don't want to restore the child frames which had been
514 // iconized even before we were iconized, so save the child frame
515 // status when iconizing the parent frame and check it when
516 // restoring it
517 if ( bIconize )
518 {
d7d02962
VZ
519 // note that we shouldn't touch the hidden frames neither
520 // because iconizing/restoring them would show them as a side
521 // effect
522 frame->m_wasMinimized = frame->IsIconized() || !frame->IsShown();
9327c3aa
VZ
523 }
524
525 // this test works for both iconizing and restoring
526 if ( !frame->m_wasMinimized )
527 frame->Iconize(bIconize);
a23fd0e1 528 }
d2aef312 529 }
d2aef312
VZ
530}
531
0d53fc34 532WXHICON wxFrame::GetDefaultIcon() const
82c9f85c 533{
94826170
VZ
534 // we don't have any standard icons (any more)
535 return (WXHICON)0;
82c9f85c
VZ
536}
537
a23fd0e1 538// ===========================================================================
42e69d6b 539// message processing
a23fd0e1
VZ
540// ===========================================================================
541
42e69d6b
VZ
542// ---------------------------------------------------------------------------
543// preprocessing
544// ---------------------------------------------------------------------------
545
0d53fc34 546bool wxFrame::MSWTranslateMessage(WXMSG* pMsg)
42e69d6b
VZ
547{
548 if ( wxWindow::MSWTranslateMessage(pMsg) )
549 return TRUE;
550
1e6feb95 551#if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
42e69d6b
VZ
552 // try the menu bar accels
553 wxMenuBar *menuBar = GetMenuBar();
554 if ( !menuBar )
555 return FALSE;
556
557 const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable();
c50f1fb9 558 return acceleratorTable.Translate(this, pMsg);
1e6feb95
VZ
559#else
560 return FALSE;
561#endif // wxUSE_MENUS && wxUSE_ACCEL
42e69d6b
VZ
562}
563
564// ---------------------------------------------------------------------------
565// our private (non virtual) message handlers
566// ---------------------------------------------------------------------------
567
0d53fc34 568bool wxFrame::HandlePaint()
42e69d6b
VZ
569{
570 RECT rect;
571 if ( GetUpdateRect(GetHwnd(), &rect, FALSE) )
572 {
4676948b 573#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
42e69d6b
VZ
574 if ( m_iconized )
575 {
f618020a
MB
576 const wxIcon& icon = GetIcon();
577 HICON hIcon = icon.Ok() ? GetHiconOf(icon)
578 : (HICON)GetDefaultIcon();
42e69d6b
VZ
579
580 // Hold a pointer to the dc so long as the OnPaint() message
581 // is being processed
582 PAINTSTRUCT ps;
583 HDC hdc = ::BeginPaint(GetHwnd(), &ps);
584
585 // Erase background before painting or we get white background
586 MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L);
587
588 if ( hIcon )
589 {
590 RECT rect;
591 ::GetClientRect(GetHwnd(), &rect);
592
593 // FIXME: why hardcoded?
594 static const int icon_width = 32;
595 static const int icon_height = 32;
596
597 int icon_x = (int)((rect.right - icon_width)/2);
598 int icon_y = (int)((rect.bottom - icon_height)/2);
599
600 ::DrawIcon(hdc, icon_x, icon_y, hIcon);
601 }
602
603 ::EndPaint(GetHwnd(), &ps);
604
605 return TRUE;
606 }
607 else
04ef50df 608 #endif
42e69d6b 609 {
5d1d2d46 610 return wxWindow::HandlePaint();
42e69d6b
VZ
611 }
612 }
613 else
614 {
615 // nothing to paint - processed
616 return TRUE;
617 }
618}
619
0d53fc34 620bool wxFrame::HandleSize(int x, int y, WXUINT id)
42e69d6b
VZ
621{
622 bool processed = FALSE;
4676948b 623#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
42e69d6b
VZ
624
625 switch ( id )
626 {
627 case SIZENORMAL:
628 // only do it it if we were iconized before, otherwise resizing the
629 // parent frame has a curious side effect of bringing it under it's
630 // children
631 if ( !m_iconized )
632 break;
633
634 // restore all child frames too
635 IconizeChildFrames(FALSE);
636
3dd9b88a
VZ
637 (void)SendIconizeEvent(FALSE);
638
42e69d6b
VZ
639 // fall through
640
641 case SIZEFULLSCREEN:
642 m_iconized = FALSE;
643 break;
644
645 case SIZEICONIC:
646 // iconize all child frames too
647 IconizeChildFrames(TRUE);
648
3dd9b88a
VZ
649 (void)SendIconizeEvent();
650
42e69d6b
VZ
651 m_iconized = TRUE;
652 break;
653 }
04ef50df 654#endif
42e69d6b
VZ
655
656 if ( !m_iconized )
657 {
1e6feb95 658#if wxUSE_STATUSBAR
42e69d6b 659 PositionStatusBar();
1e6feb95
VZ
660#endif // wxUSE_STATUSBAR
661
662#if wxUSE_TOOLBAR
42e69d6b 663 PositionToolBar();
1e6feb95 664#endif // wxUSE_TOOLBAR
42e69d6b 665
4e4a5fed 666 processed = wxWindow::HandleSize(x, y, id);
42e69d6b
VZ
667 }
668
669 return processed;
670}
671
0d53fc34 672bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
42e69d6b
VZ
673{
674 if ( control )
675 {
676 // In case it's e.g. a toolbar.
677 wxWindow *win = wxFindWinFromHandle(control);
678 if ( win )
679 return win->MSWCommand(cmd, id);
680 }
681
682 // handle here commands from menus and accelerators
683 if ( cmd == 0 || cmd == 1 )
684 {
1e6feb95 685#if wxUSE_MENUS_NATIVE
42e69d6b
VZ
686 if ( wxCurrentPopupMenu )
687 {
688 wxMenu *popupMenu = wxCurrentPopupMenu;
689 wxCurrentPopupMenu = NULL;
690
691 return popupMenu->MSWCommand(cmd, id);
692 }
1e6feb95 693#endif // wxUSE_MENUS_NATIVE
42e69d6b
VZ
694
695 if ( ProcessCommand(id) )
696 {
697 return TRUE;
698 }
699 }
700
701 return FALSE;
702}
703
0d53fc34 704bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu)
a23fd0e1
VZ
705{
706 int item;
c219cecc 707 if ( flags == 0xFFFF && hMenu == 0 )
a23fd0e1 708 {
c219cecc 709 // menu was removed from screen
a23fd0e1
VZ
710 item = -1;
711 }
04ef50df 712#ifndef __WXMICROWIN__
c219cecc 713 else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) )
a23fd0e1
VZ
714 {
715 item = nItem;
716 }
04ef50df 717#endif
a23fd0e1
VZ
718 else
719 {
c219cecc 720 // don't give hints for separators (doesn't make sense) nor for the
f6bcfd97
BP
721 // items opening popup menus (they don't have them anyhow) but do clear
722 // the status line - otherwise, we would be left with the help message
723 // for the previous item which doesn't apply any more
1f361cdd 724 DoGiveHelp(wxEmptyString, FALSE);
f6bcfd97 725
a23fd0e1
VZ
726 return FALSE;
727 }
728
729 wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item);
ccef86c7
VZ
730 event.SetEventObject(this);
731
732 return GetEventHandler()->ProcessEvent(event);
733}
734
735bool wxFrame::HandleMenuLoop(const wxEventType& evtType, WXWORD isPopup)
736{
737 // we don't have the menu id here, so we use the id to specify if the event
738 // was from a popup menu or a normal one
739 wxMenuEvent event(evtType, isPopup ? -1 : 0);
740 event.SetEventObject(this);
a23fd0e1
VZ
741
742 return GetEventHandler()->ProcessEvent(event);
743}
744
745// ---------------------------------------------------------------------------
0d53fc34 746// the window proc for wxFrame
a23fd0e1
VZ
747// ---------------------------------------------------------------------------
748
0d53fc34 749long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
a23fd0e1
VZ
750{
751 long rc = 0;
752 bool processed = FALSE;
753
754 switch ( message )
755 {
42e69d6b
VZ
756 case WM_CLOSE:
757 // if we can't close, tell the system that we processed the
758 // message - otherwise it would close us
759 processed = !Close();
760 break;
761
ccef86c7
VZ
762 case WM_SIZE:
763 processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam);
764 break;
765
42e69d6b
VZ
766 case WM_COMMAND:
767 {
768 WORD id, cmd;
769 WXHWND hwnd;
770 UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam,
771 &id, &hwnd, &cmd);
772
773 processed = HandleCommand(id, cmd, (WXHWND)hwnd);
774 }
775 break;
776
ccef86c7
VZ
777 case WM_PAINT:
778 processed = HandlePaint();
779 break;
780
4676948b 781#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
a23fd0e1
VZ
782 case WM_MENUSELECT:
783 {
42e69d6b
VZ
784 WXWORD item, flags;
785 WXHMENU hmenu;
786 UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu);
787
788 processed = HandleMenuSelect(item, flags, hmenu);
a23fd0e1
VZ
789 }
790 break;
bc92cdf9
VZ
791
792 case WM_INITMENU:
793 processed = HandleInitMenu();
42e69d6b 794 break;
bc92cdf9 795
ccef86c7
VZ
796 case WM_EXITMENULOOP:
797 processed = HandleMenuLoop(wxEVT_MENU_CLOSE, wParam);
798 break;
ccef86c7 799
42e69d6b
VZ
800 case WM_QUERYDRAGICON:
801 {
f618020a
MB
802 const wxIcon& icon = GetIcon();
803 HICON hIcon = icon.Ok() ? GetHiconOf(icon)
804 : (HICON)GetDefaultIcon();
42e69d6b
VZ
805 rc = (long)hIcon;
806 processed = rc != 0;
807 }
808 break;
ccef86c7 809#endif // !__WXMICROWIN__
a23fd0e1
VZ
810 }
811
812 if ( !processed )
7e25f59e 813 rc = wxFrameBase::MSWWindowProc(message, wParam, lParam);
a23fd0e1
VZ
814
815 return rc;
816}
21802234 817
e39af974
JS
818// handle WM_INITMENU message
819bool wxFrame::HandleInitMenu()
820{
821 wxMenuEvent event(wxEVT_MENU_OPEN, 0);
822 event.SetEventObject(this);
823
824 return GetEventHandler()->ProcessEvent(event);
e39af974
JS
825}
826
827