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