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