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