]> git.saurik.com Git - wxWidgets.git/blame - src/msw/frame.cpp
Enable variadic macros for VC9 and later.
[wxWidgets.git] / src / msw / frame.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
08b97268 2// Name: src/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
65571936 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
7c0ea335
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
2bda0e17
KB
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
9f3362c4 24 #pragma hdrstop
2bda0e17
KB
25#endif
26
76b49cf4
WS
27#include "wx/frame.h"
28
2bda0e17 29#ifndef WX_PRECOMP
57bd4c60 30 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
9f3362c4 31 #include "wx/app.h"
1e6feb95 32 #include "wx/menu.h"
9f3362c4
VZ
33 #include "wx/utils.h"
34 #include "wx/dialog.h"
35 #include "wx/settings.h"
36 #include "wx/dcclient.h"
d3cc7c65 37 #include "wx/mdi.h"
f6bcfd97 38 #include "wx/panel.h"
e4db172a 39 #include "wx/log.h"
4e3e485b 40 #include "wx/toolbar.h"
3304646d 41 #include "wx/statusbr.h"
25466131 42 #include "wx/menuitem.h"
9f3362c4 43#endif // WX_PRECOMP
2bda0e17
KB
44
45#include "wx/msw/private.h"
7c0ea335 46
afafd942 47#if defined(__POCKETPC__) || defined(__SMARTPHONE__)
855ec944
VZ
48 #include <ole2.h>
49 #include <aygshell.h>
50 #include "wx/msw/winundef.h"
afafd942
JS
51#endif
52
8f62e633
RD
53#include "wx/generic/statusbr.h"
54
1e6feb95
VZ
55#ifdef __WXUNIVERSAL__
56 #include "wx/univ/theme.h"
57 #include "wx/univ/colschem.h"
58#endif // __WXUNIVERSAL__
59
abb8764e
VZ
60// FIXME-VC6: Only VC6 doesn't have this in its standard headers so this
61// could be removed once support for it is dropped.
62#ifndef WM_UNINITMENUPOPUP
63 #define WM_UNINITMENUPOPUP 0x0125
64#endif
65
7c0ea335
VZ
66// ----------------------------------------------------------------------------
67// globals
68// ----------------------------------------------------------------------------
2bda0e17 69
7f3f059a 70#if wxUSE_MENUS || wxUSE_MENUS_NATIVE
03baf031 71 extern wxMenu *wxCurrentPopupMenu;
7f3f059a 72#endif // wxUSE_MENUS || 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
7c0ea335
VZ
82// ============================================================================
83// implementation
84// ============================================================================
85
86// ----------------------------------------------------------------------------
87// static class members
88// ----------------------------------------------------------------------------
89
1e6feb95
VZ
90#if wxUSE_STATUSBAR
91 #if wxUSE_NATIVE_STATUSBAR
cbe874bd 92 bool wxFrame::m_useNativeStatusBar = true;
1e6feb95 93 #else
cbe874bd 94 bool wxFrame::m_useNativeStatusBar = false;
1e6feb95
VZ
95 #endif
96#endif // wxUSE_NATIVE_STATUSBAR
2bda0e17 97
7c0ea335
VZ
98// ----------------------------------------------------------------------------
99// creation/destruction
100// ----------------------------------------------------------------------------
2bda0e17 101
0d53fc34 102void wxFrame::Init()
2bda0e17 103{
cf8ff92f
VZ
104#if wxUSE_MENUS
105 m_hMenu = NULL;
106#endif // wxUSE_MENUS
107
9f3362c4
VZ
108#if wxUSE_TOOLTIPS
109 m_hwndToolTip = 0;
110#endif
a2327a9f 111
cbe874bd 112 m_wasMinimized = false;
7c0ea335 113}
9f3362c4 114
0d53fc34 115bool wxFrame::Create(wxWindow *parent,
7c0ea335
VZ
116 wxWindowID id,
117 const wxString& title,
118 const wxPoint& pos,
119 const wxSize& size,
120 long style,
121 const wxString& name)
122{
82c9f85c 123 if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
ef6d716b 124 return false;
d2aef312 125
98a02e87 126 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
b9691677 127
aaf803e9 128#if defined(__SMARTPHONE__)
ef6d716b
WS
129 SetLeftMenu(wxID_EXIT, _("Done"));
130#endif
131
855ec944 132#if wxUSE_ACCEL && defined(__POCKETPC__)
aaf803e9
JS
133 // The guidelines state that Ctrl+Q should quit the app.
134 // Let's define an accelerator table to send wxID_EXIT.
135 wxAcceleratorEntry entries[1];
136 entries[0].Set(wxACCEL_CTRL, 'Q', wxID_EXIT);
137 wxAcceleratorTable accel(1, entries);
138 SetAcceleratorTable(accel);
855ec944 139#endif // wxUSE_ACCEL && __POCKETPC__
aaf803e9 140
ef6d716b 141 return true;
2bda0e17
KB
142}
143
0d53fc34 144wxFrame::~wxFrame()
2bda0e17 145{
c6212a0c
VZ
146 SendDestroyEvent();
147
82c9f85c 148 DeleteAllBars();
2bda0e17
KB
149}
150
d4597e13
VZ
151// ----------------------------------------------------------------------------
152// wxFrame client size calculations
153// ----------------------------------------------------------------------------
2bda0e17 154
0d53fc34 155void wxFrame::DoSetClientSize(int width, int height)
2bda0e17 156{
82c9f85c 157 // leave enough space for the status bar if we have (and show) it
7c0ea335 158#if wxUSE_STATUSBAR
8d8bd249
VZ
159 wxStatusBar *statbar = GetStatusBar();
160 if ( statbar && statbar->IsShown() )
161 {
8d8bd249
VZ
162 height += statbar->GetSize().y;
163 }
7c0ea335 164#endif // wxUSE_STATUSBAR
2bda0e17 165
68d02db3
VZ
166 // call GetClientAreaOrigin() to take the toolbar into account
167 wxPoint pt = GetClientAreaOrigin();
168 width += pt.x;
169 height += pt.y;
3882e746 170
7a976304 171#if wxUSE_TOOLBAR
3882e746
VZ
172 wxToolBar * const toolbar = GetToolBar();
173 if ( toolbar )
7a976304 174 {
3882e746 175 if ( toolbar->HasFlag(wxTB_RIGHT | wxTB_BOTTOM) )
7a976304 176 {
3882e746
VZ
177 const wxSize sizeTB = toolbar->GetSize();
178 if ( toolbar->HasFlag(wxTB_RIGHT) )
179 width -= sizeTB.x;
180 else // wxTB_BOTTOM
181 height -= sizeTB.y;
7a976304 182 }
3882e746 183 //else: toolbar already taken into account by GetClientAreaOrigin()
7a976304 184 }
3882e746 185#endif // wxUSE_TOOLBAR
68d02db3 186
82c9f85c 187 wxTopLevelWindow::DoSetClientSize(width, height);
2bda0e17
KB
188}
189
d4597e13
VZ
190// Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
191void wxFrame::DoGetClientSize(int *x, int *y) const
192{
193 wxTopLevelWindow::DoGetClientSize(x, y);
194
68d02db3
VZ
195 // account for the possible toolbar
196 wxPoint pt = GetClientAreaOrigin();
197 if ( x )
198 *x -= pt.x;
199
200 if ( y )
201 *y -= pt.y;
3882e746 202
5b2acc3a 203#if wxUSE_TOOLBAR
3882e746
VZ
204 wxToolBar * const toolbar = GetToolBar();
205 if ( toolbar )
5b2acc3a 206 {
3882e746 207 if ( toolbar->HasFlag(wxTB_RIGHT | wxTB_BOTTOM) )
5b2acc3a 208 {
3882e746
VZ
209 const wxSize sizeTB = toolbar->GetSize();
210 if ( toolbar->HasFlag(wxTB_RIGHT) )
211 {
212 if ( x )
213 *x -= sizeTB.x;
214 }
215 else // wxTB_BOTTOM
216 {
217 if ( y )
218 *y -= sizeTB.y;
219 }
7a976304 220 }
3882e746 221 //else: toolbar already taken into account by GetClientAreaOrigin()
7a976304 222 }
3882e746
VZ
223#endif // wxUSE_TOOLBAR
224
d4597e13
VZ
225#if wxUSE_STATUSBAR
226 // adjust client area height to take the status bar into account
227 if ( y )
228 {
229 wxStatusBar *statbar = GetStatusBar();
230 if ( statbar && statbar->IsShown() )
231 {
c22bbd08 232 *y -= statbar->GetSize().y;
d4597e13
VZ
233 }
234 }
235#endif // wxUSE_STATUSBAR
236}
237
7c0ea335 238// ----------------------------------------------------------------------------
0d53fc34 239// wxFrame: various geometry-related functions
7c0ea335
VZ
240// ----------------------------------------------------------------------------
241
67bd5bad 242// generate an artificial resize event
ecdc1183 243void wxFrame::SendSizeEvent(int flags)
67bd5bad 244{
67bd5bad
GT
245 if ( !m_iconized )
246 {
82c9f85c
VZ
247 RECT r = wxGetWindowRect(GetHwnd());
248
ecdc1183
VZ
249 if ( flags & wxSEND_EVENT_POST )
250 {
251 ::PostMessage(GetHwnd(), WM_SIZE,
252 IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED,
253 MAKELPARAM(r.right - r.left, r.bottom - r.top));
254 }
255 else // send it
256 {
257 ::SendMessage(GetHwnd(), WM_SIZE,
258 IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED,
259 MAKELPARAM(r.right - r.left, r.bottom - r.top));
260 }
67bd5bad
GT
261 }
262}
263
d427503c 264#if wxUSE_STATUSBAR
0d53fc34 265wxStatusBar *wxFrame::OnCreateStatusBar(int number,
7c0ea335
VZ
266 long style,
267 wxWindowID id,
268 const wxString& name)
2bda0e17 269{
5cb598ae 270 wxStatusBar *statusBar wxDUMMY_INITIALIZE(NULL);
2bda0e17 271
47d67540 272#if wxUSE_NATIVE_STATUSBAR
1f0500b3 273 if ( !UsesNativeStatusBar() )
2bda0e17 274 {
1f0500b3 275 statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style);
2bda0e17
KB
276 }
277 else
278#endif
279 {
1f0500b3
VZ
280 statusBar = new wxStatusBar(this, id, style, name);
281 }
ed791986 282
1f0500b3 283 statusBar->SetFieldsCount(number);
2bda0e17 284
7c0ea335 285 return statusBar;
2bda0e17
KB
286}
287
0d53fc34 288void wxFrame::PositionStatusBar()
2bda0e17 289{
d4597e13 290 if ( !m_frameStatusBar || !m_frameStatusBar->IsShown() )
ed791986
VZ
291 return;
292
cbc66a27
VZ
293 int w, h;
294 GetClientSize(&w, &h);
3882e746 295
cbc66a27
VZ
296 int sw, sh;
297 m_frameStatusBar->GetSize(&sw, &sh);
298
8efbb8ad
VZ
299 int x = 0;
300#if wxUSE_TOOLBAR
301 wxToolBar * const toolbar = GetToolBar();
302 if ( toolbar && !toolbar->HasFlag(wxTB_TOP) )
303 {
304 const wxSize sizeTB = toolbar->GetSize();
305
306 if ( toolbar->HasFlag(wxTB_LEFT | wxTB_RIGHT) )
307 {
308 if ( toolbar->HasFlag(wxTB_LEFT) )
309 x -= sizeTB.x;
310
311 w += sizeTB.x;
312 }
313 else // wxTB_BOTTOM
314 {
315 // we need to position the status bar below the toolbar
316 h += sizeTB.y;
317 }
318 }
319 //else: no adjustments necessary for the toolbar on top
320#endif // wxUSE_TOOLBAR
321
cbc66a27
VZ
322 // Since we wish the status bar to be directly under the client area,
323 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
8efbb8ad 324 m_frameStatusBar->SetSize(x, h, w, sh);
2bda0e17 325}
3882e746 326
d427503c 327#endif // wxUSE_STATUSBAR
2bda0e17 328
6522713c 329#if wxUSE_MENUS_NATIVE
ea9a4296 330
0d53fc34 331void wxFrame::AttachMenuBar(wxMenuBar *menubar)
2bda0e17 332{
3180bc0e 333#if defined(__SMARTPHONE__) && defined(__WXWINCE__)
fb8a56b7 334
ed679e74
WS
335 wxMenu *autoMenu = NULL;
336
337 if( menubar->GetMenuCount() == 1 )
338 {
339 autoMenu = wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(menubar->GetMenu(0));
52af3158 340 SetRightMenu(wxID_ANY, menubar->GetMenuLabel(0), autoMenu);
ed679e74
WS
341 }
342 else
fb8a56b7 343 {
ed679e74
WS
344 autoMenu = new wxMenu;
345
346 for( size_t n = 0; n < menubar->GetMenuCount(); n++ )
347 {
348 wxMenu *item = menubar->GetMenu(n);
52af3158 349 wxString label = menubar->GetMenuLabel(n);
ed679e74
WS
350 wxMenu *new_item = wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(item);
351 autoMenu->Append(wxID_ANY, label, new_item);
352 }
353
354 SetRightMenu(wxID_ANY, _("Menu"), autoMenu);
fb8a56b7
WS
355 }
356
fb8a56b7 357#elif defined(WINCE_WITHOUT_COMMANDBAR)
a96b4743
JS
358 if (!GetToolBar())
359 {
a9102b36 360 wxToolMenuBar* toolBar = new wxToolMenuBar(this, wxID_ANY,
a96b4743
JS
361 wxDefaultPosition, wxDefaultSize,
362 wxBORDER_NONE | wxTB_HORIZONTAL,
af5454a4 363 wxToolBarNameStr, menubar);
a96b4743
JS
364 SetToolBar(toolBar);
365 menubar->SetToolBar(toolBar);
366 }
fb8a56b7 367
c0a91b51
VZ
368 // When the main window is created using CW_USEDEFAULT the height of the
369 // menubar is not taken into account, so we resize it afterwards if a
370 // menubar is present
371 HWND hwndMenuBar = SHFindMenuBar(GetHwnd());
372 if ( hwndMenuBar )
fb8a56b7 373 {
c0a91b51
VZ
374 RECT mbRect;
375 ::GetWindowRect(hwndMenuBar, &mbRect);
376 const int menuHeight = mbRect.bottom - mbRect.top;
377
fb8a56b7 378 RECT rc;
c0a91b51 379 ::GetWindowRect(GetHwnd(), &rc);
fb8a56b7
WS
380 // adjust for menu / titlebar height
381 rc.bottom -= (2*menuHeight-1);
382
102db80f 383 ::MoveWindow(GetHwnd(), rc.left, rc.top, rc.right, rc.bottom, FALSE);
fb8a56b7 384 }
a96b4743
JS
385#endif
386
f008af16 387 wxFrameBase::AttachMenuBar(menubar);
6beb85c0 388
f6bcfd97 389 if ( !menubar )
c2dcfdef 390 {
f6bcfd97
BP
391 // actually remove the menu from the frame
392 m_hMenu = (WXHMENU)0;
393 InternalSetMenuBar();
065de612 394 }
f6bcfd97 395 else // set new non NULL menu bar
065de612 396 {
3d487566 397#if !defined(__WXWINCE__) || defined(WINCE_WITH_COMMANDBAR)
f6bcfd97 398 // Can set a menubar several times.
f6bcfd97
BP
399 if ( menubar->GetHMenu() )
400 {
401 m_hMenu = menubar->GetHMenu();
402 }
f008af16 403 else // no HMENU yet
f6bcfd97 404 {
f6bcfd97 405 m_hMenu = menubar->Create();
065de612 406
f6bcfd97 407 if ( !m_hMenu )
f008af16 408 {
9a83f860 409 wxFAIL_MSG( wxT("failed to create menu bar") );
f6bcfd97 410 return;
f008af16 411 }
f6bcfd97 412 }
39d2f9a7 413#endif
f6bcfd97 414 InternalSetMenuBar();
1e6feb95 415 }
2bda0e17
KB
416}
417
0d53fc34 418void wxFrame::InternalSetMenuBar()
2bda0e17 419{
a96b4743 420#if defined(__WXMICROWIN__) || defined(__WXWINCE__)
4676948b 421 // Nothing
4676948b 422#else
42e69d6b 423 if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) )
2bda0e17 424 {
f6bcfd97 425 wxLogLastError(wxT("SetMenu"));
2bda0e17 426 }
04ef50df 427#endif
2bda0e17
KB
428}
429
1e6feb95
VZ
430#endif // wxUSE_MENUS_NATIVE
431
2bda0e17 432// Responds to colour changes, and passes event on to children.
0d53fc34 433void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
2bda0e17 434{
98a02e87 435 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
2bda0e17
KB
436 Refresh();
437
1e6feb95 438#if wxUSE_STATUSBAR
2bda0e17
KB
439 if ( m_frameStatusBar )
440 {
441 wxSysColourChangedEvent event2;
442 event2.SetEventObject( m_frameStatusBar );
937013e0 443 m_frameStatusBar->HandleWindowEvent(event2);
2bda0e17 444 }
1e6feb95 445#endif // wxUSE_STATUSBAR
2bda0e17
KB
446
447 // Propagate the event to the non-top-level children
448 wxWindow::OnSysColourChanged(event);
449}
450
cbe874bd 451// Pass true to show full screen, false to restore.
0d53fc34 452bool wxFrame::ShowFullScreen(bool show, long style)
a2327a9f 453{
b01a88e0
VZ
454 // TODO-CE: add support for CE
455#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
085ad686 456 if ( IsFullScreen() == show )
cbe874bd 457 return false;
c641b1d2 458
a2327a9f
JS
459 if (show)
460 {
b01a88e0
VZ
461 // zap the toolbar, menubar, and statusbar if needed
462 //
463 // TODO: hide commandbar for WINCE_WITH_COMMANDBAR
1e6feb95 464#if wxUSE_TOOLBAR
f6bcfd97 465 wxToolBar *theToolBar = GetToolBar();
a2327a9f
JS
466
467 if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar)
468 {
b01a88e0
VZ
469 if ( theToolBar->IsShown() )
470 {
471 theToolBar->SetSize(wxDefaultCoord,0);
472 theToolBar->Show(false);
473 }
474 else // prevent it from being restored later
475 {
476 style &= ~wxFULLSCREEN_NOTOOLBAR;
477 }
a2327a9f 478 }
1e6feb95 479#endif // wxUSE_TOOLBAR
a2327a9f
JS
480
481 if (style & wxFULLSCREEN_NOMENUBAR)
482 SetMenu((HWND)GetHWND(), (HMENU) NULL);
483
1e6feb95
VZ
484#if wxUSE_STATUSBAR
485 wxStatusBar *theStatusBar = GetStatusBar();
1e6feb95 486
a2327a9f
JS
487 // Save the number of fields in the statusbar
488 if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar)
489 {
b01a88e0
VZ
490 if ( theStatusBar->IsShown() )
491 theStatusBar->Show(false);
492 else
493 style &= ~wxFULLSCREEN_NOSTATUSBAR;
a2327a9f 494 }
1e6feb95 495#endif // wxUSE_STATUSBAR
a2327a9f 496 }
b01a88e0 497 else // restore to normal
a2327a9f 498 {
b01a88e0 499 // restore the toolbar, menubar, and statusbar if we had hid them
1e6feb95 500#if wxUSE_TOOLBAR
a2327a9f
JS
501 wxToolBar *theToolBar = GetToolBar();
502
b01a88e0 503 if ((m_fsStyle & wxFULLSCREEN_NOTOOLBAR) && theToolBar)
a2327a9f 504 {
cbe874bd 505 theToolBar->Show(true);
a2327a9f 506 }
1e6feb95 507#endif // wxUSE_TOOLBAR
a2327a9f 508
a8ff046b 509#if wxUSE_MENUS
bc88602a
JS
510 if (m_fsStyle & wxFULLSCREEN_NOMENUBAR)
511 {
51181d29
VZ
512 const WXHMENU hmenu = MSWGetActiveMenu();
513 if ( hmenu )
514 ::SetMenu(GetHwnd(), (HMENU)hmenu);
bc88602a 515 }
a8ff046b 516#endif // wxUSE_MENUS
b01a88e0 517
1e6feb95 518#if wxUSE_STATUSBAR
b01a88e0
VZ
519 wxStatusBar *theStatusBar = GetStatusBar();
520
521 if ((m_fsStyle & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar)
a2327a9f 522 {
b01a88e0
VZ
523 theStatusBar->Show(true);
524 PositionStatusBar();
a2327a9f 525 }
1e6feb95 526#endif // wxUSE_STATUSBAR
a2327a9f 527 }
b01a88e0 528#endif // !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
f6bcfd97 529
085ad686 530 return wxFrameBase::ShowFullScreen(show, style);
2bda0e17
KB
531}
532
7c0ea335
VZ
533// ----------------------------------------------------------------------------
534// tool/status bar stuff
535// ----------------------------------------------------------------------------
536
d427503c 537#if wxUSE_TOOLBAR
7c0ea335 538
0d53fc34 539wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
81d66cf3 540{
3d487566 541#if defined(WINCE_WITHOUT_COMMANDBAR)
39d2f9a7
JS
542 // We may already have a toolbar from calling SetMenuBar.
543 if (GetToolBar())
544 return GetToolBar();
545#endif
7c0ea335 546 if ( wxFrameBase::CreateToolBar(style, id, name) )
81d66cf3 547 {
81d66cf3 548 PositionToolBar();
81d66cf3 549 }
81d66cf3 550
7c0ea335 551 return m_frameToolBar;
81d66cf3
JS
552}
553
0d53fc34 554void wxFrame::PositionToolBar()
81d66cf3 555{
8898842f
VZ
556 // TODO: we want to do something different in WinCE, because the toolbar
557 // should be associated with the commandbar, instead of being
558 // independent window.
559#if !defined(WINCE_WITHOUT_COMMANDBAR)
d4597e13
VZ
560 wxToolBar *toolbar = GetToolBar();
561 if ( toolbar && toolbar->IsShown() )
562 {
563 // don't call our (or even wxTopLevelWindow) version because we want
564 // the real (full) client area size, not excluding the tool/status bar
565 int width, height;
566 wxWindow::DoGetClientSize(&width, &height);
81d66cf3 567
7c0ea335 568#if wxUSE_STATUSBAR
d4597e13
VZ
569 wxStatusBar *statbar = GetStatusBar();
570 if ( statbar && statbar->IsShown() )
571 {
572 height -= statbar->GetClientSize().y;
573 }
7c0ea335 574#endif // wxUSE_STATUSBAR
3882e746
VZ
575
576 int tx, ty, tw, th;
577 toolbar->GetPosition( &tx, &ty );
578 toolbar->GetSize( &tw, &th );
579
dd639a4f 580 int x, y;
3882e746
VZ
581 if ( toolbar->HasFlag(wxTB_BOTTOM) )
582 {
583 x = 0;
584 y = height - th;
585 }
586 else if ( toolbar->HasFlag(wxTB_RIGHT) )
587 {
588 x = width - tw;
589 y = 0;
590 }
591 else // left or top
592 {
593 x = 0;
594 y = 0;
595 }
596
3d487566 597#if defined(WINCE_WITH_COMMANDBAR)
fb8a56b7
WS
598 // We're using a commandbar - so we have to allow for it.
599 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
600 {
601 RECT rect;
602 ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect);
603 y = rect.bottom - rect.top;
604 }
3882e746
VZ
605#endif // WINCE_WITH_COMMANDBAR
606
607 if ( toolbar->HasFlag(wxTB_BOTTOM) )
608 {
609 if ( ty < 0 && ( -ty == th ) )
610 ty = height - th;
611 if ( tx < 0 && (-tx == tw ) )
612 tx = 0;
613 }
614 else if ( toolbar->HasFlag(wxTB_RIGHT) )
7a976304
VZ
615 {
616 if( ty < 0 && ( -ty == th ) )
617 ty = 0;
618 if( tx < 0 && ( -tx == tw ) )
619 tx = width - tw;
620 }
3882e746
VZ
621 else // left or top
622 {
623 if (ty < 0 && (-ty == th))
624 ty = 0;
625 if (tx < 0 && (-tx == tw))
626 tx = 0;
627 }
cbe874bd 628
563f85a9
VZ
629 int desiredW,
630 desiredH;
81d66cf3 631
7a976304 632 if ( toolbar->IsVertical() )
81d66cf3 633 {
563f85a9 634 desiredW = tw;
229de929 635 desiredH = height;
81d66cf3
JS
636 }
637 else
638 {
229de929 639 desiredW = width;
563f85a9 640 desiredH = th;
cbe874bd 641 }
7c0ea335 642
563f85a9 643 // use the 'real' MSW position here, don't offset relatively to the
d4597e13 644 // client area origin
563f85a9 645 toolbar->SetSize(x, y, desiredW, desiredH, wxSIZE_NO_ADJUSTMENTS);
cbe874bd 646
81d66cf3 647 }
8898842f 648#endif // !WINCE_WITH_COMMANDBAR
81d66cf3 649}
d4597e13 650
d427503c 651#endif // wxUSE_TOOLBAR
d2aef312 652
7c0ea335
VZ
653// ----------------------------------------------------------------------------
654// frame state (iconized/maximized/...)
655// ----------------------------------------------------------------------------
656
a23fd0e1
VZ
657// propagate our state change to all child frames: this allows us to emulate X
658// Windows behaviour where child frames float independently of the parent one
659// on the desktop, but are iconized/restored with it
0d53fc34 660void wxFrame::IconizeChildFrames(bool bIconize)
d2aef312 661{
4bc0f25e
VZ
662 m_iconized = bIconize;
663
222ed1d6 664 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
a23fd0e1
VZ
665 node;
666 node = node->GetNext() )
667 {
668 wxWindow *win = node->GetData();
669
3ca6a5f0
BP
670 // iconizing the frames with this style under Win95 shell puts them at
671 // the bottom of the screen (as the MDI children) instead of making
672 // them appear in the taskbar because they are, by virtue of this
673 // style, not managed by the taskbar - instead leave Windows take care
674 // of them
3ca6a5f0
BP
675 if ( win->GetWindowStyle() & wxFRAME_TOOL_WINDOW )
676 continue;
3ca6a5f0 677
3f7bc32b
VZ
678 // the child MDI frames are a special case and should not be touched by
679 // the parent frame - instead, they are managed by the user
2e9f62da 680 wxFrame *frame = wxDynamicCast(win, wxFrame);
1e6feb95
VZ
681 if ( frame
682#if wxUSE_MDI_ARCHITECTURE
4ab2824c 683 && !frame->IsMDIChild()
1e6feb95
VZ
684#endif // wxUSE_MDI_ARCHITECTURE
685 )
a23fd0e1 686 {
9327c3aa
VZ
687 // we don't want to restore the child frames which had been
688 // iconized even before we were iconized, so save the child frame
689 // status when iconizing the parent frame and check it when
690 // restoring it
691 if ( bIconize )
692 {
9c72ebec 693 frame->m_wasMinimized = frame->IsIconized();
9327c3aa
VZ
694 }
695
9c72ebec
VZ
696 // note that we shouldn't touch the hidden frames neither because
697 // iconizing/restoring them would show them as a side effect
698 if ( !frame->m_wasMinimized && frame->IsShown() )
9327c3aa 699 frame->Iconize(bIconize);
a23fd0e1 700 }
d2aef312 701 }
d2aef312
VZ
702}
703
0d53fc34 704WXHICON wxFrame::GetDefaultIcon() const
82c9f85c 705{
94826170
VZ
706 // we don't have any standard icons (any more)
707 return (WXHICON)0;
82c9f85c
VZ
708}
709
a23fd0e1 710// ===========================================================================
42e69d6b 711// message processing
a23fd0e1
VZ
712// ===========================================================================
713
42e69d6b
VZ
714// ---------------------------------------------------------------------------
715// preprocessing
716// ---------------------------------------------------------------------------
717
1ac76609 718bool wxFrame::MSWDoTranslateMessage(wxFrame *frame, WXMSG *pMsg)
42e69d6b
VZ
719{
720 if ( wxWindow::MSWTranslateMessage(pMsg) )
cbe874bd 721 return true;
42e69d6b 722
1e6feb95 723#if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
7802da36 724 // try the menu bar accelerators
42e69d6b 725 wxMenuBar *menuBar = GetMenuBar();
7802da36
VZ
726 if ( menuBar && menuBar->GetAcceleratorTable()->Translate(frame, pMsg) )
727 return true;
a1a1ca89 728#endif // wxUSE_MENUS && wxUSE_ACCEL
42e69d6b 729
cbe874bd 730 return false;
42e69d6b
VZ
731}
732
733// ---------------------------------------------------------------------------
734// our private (non virtual) message handlers
735// ---------------------------------------------------------------------------
736
4bc0f25e 737bool wxFrame::HandleSize(int WXUNUSED(x), int WXUNUSED(y), WXUINT id)
42e69d6b 738{
4676948b 739#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
42e69d6b
VZ
740 switch ( id )
741 {
4bc0f25e
VZ
742 case SIZE_RESTORED:
743 case SIZE_MAXIMIZED:
42e69d6b
VZ
744 // only do it it if we were iconized before, otherwise resizing the
745 // parent frame has a curious side effect of bringing it under it's
746 // children
747 if ( !m_iconized )
748 break;
749
750 // restore all child frames too
cbe874bd 751 IconizeChildFrames(false);
42e69d6b 752
cbe874bd 753 (void)SendIconizeEvent(false);
42e69d6b
VZ
754 break;
755
4bc0f25e 756 case SIZE_MINIMIZED:
42e69d6b 757 // iconize all child frames too
cbe874bd 758 IconizeChildFrames(true);
42e69d6b
VZ
759 break;
760 }
276c8cfb
WS
761#else
762 wxUnusedVar(id);
4bc0f25e 763#endif // !__WXWINCE__
42e69d6b
VZ
764
765 if ( !m_iconized )
766 {
1e6feb95 767#if wxUSE_STATUSBAR
42e69d6b 768 PositionStatusBar();
1e6feb95
VZ
769#endif // wxUSE_STATUSBAR
770
771#if wxUSE_TOOLBAR
42e69d6b 772 PositionToolBar();
1e6feb95 773#endif // wxUSE_TOOLBAR
42e69d6b 774
3d487566 775#if defined(WINCE_WITH_COMMANDBAR)
fb8a56b7
WS
776 // Position the menu command bar
777 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
778 {
779 RECT rect;
780 ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect);
781 wxSize clientSz = GetClientSize();
782
783 if ( !::MoveWindow((HWND) GetMenuBar()->GetCommandBar(), 0, 0, clientSz.x, rect.bottom - rect.top, true ) )
784 {
785 wxLogLastError(wxT("MoveWindow"));
786 }
787
788 }
4bc0f25e 789#endif // WINCE_WITH_COMMANDBAR
42e69d6b
VZ
790 }
791
4bc0f25e
VZ
792 // call the base class version to generate the appropriate events
793 return false;
42e69d6b
VZ
794}
795
1483e5db 796bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
42e69d6b 797{
1483e5db 798#if wxUSE_MENUS
f8114048
JS
799
800#if defined(WINCE_WITHOUT_COMMANDBAR)
801 if (GetToolBar() && GetToolBar()->FindById(id))
802 return GetToolBar()->MSWCommand(cmd, id);
803#endif
804
a6ac49b1
VZ
805 // we only need to handle the menu and accelerator commands from the items
806 // of our menu bar, base wxWindow class already handles the rest
807 if ( !control && (cmd == 0 /* menu */ || cmd == 1 /* accel */) )
42e69d6b 808 {
1e6feb95 809#if wxUSE_MENUS_NATIVE
a6ac49b1 810 if ( !wxCurrentPopupMenu )
1e6feb95 811#endif // wxUSE_MENUS_NATIVE
fb8a56b7 812 {
79f9ea05 813 wxMenuItem * const mitem = FindItemInMenuBar((signed short)id);
1483e5db
VZ
814 if ( mitem )
815 return ProcessCommand(mitem);
42e69d6b
VZ
816 }
817 }
1483e5db 818#endif // wxUSE_MENUS
42e69d6b 819
1483e5db 820 return wxFrameBase::HandleCommand(id, cmd, control);;
42e69d6b
VZ
821}
822
a8ff046b
VZ
823#if wxUSE_MENUS
824
3e603cb7
VZ
825bool
826wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU WXUNUSED(hMenu))
a23fd0e1 827{
f6a86aff
VZ
828 // sign extend to int from unsigned short we get from Windows
829 int item = (signed short)nItem;
830
46743ff8
VZ
831 // WM_MENUSELECT is generated for both normal items and menus, including
832 // the top level menus of the menu bar, which can't be represented using
f6a86aff
VZ
833 // any valid identifier in wxMenuEvent so use an otherwise unused value for
834 // them
835 if ( flags & (MF_POPUP | MF_SEPARATOR) )
29c7962a 836 item = wxID_NONE;
a23fd0e1
VZ
837
838 wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item);
ccef86c7
VZ
839 event.SetEventObject(this);
840
46743ff8
VZ
841 if ( HandleWindowEvent(event) )
842 return true;
843
844 // by default, i.e. if the event wasn't handled above, clear the status bar
845 // text when an item which can't have any associated help string in wx API
846 // is selected
29c7962a 847 if ( item == wxID_NONE )
46743ff8
VZ
848 DoGiveHelp(wxEmptyString, true);
849
850 return false;
ccef86c7
VZ
851}
852
bde56d09
VZ
853bool
854wxFrame::DoSendMenuOpenCloseEvent(wxEventType evtType, wxMenu* menu, bool popup)
855{
856 wxMenuEvent event(evtType, popup ? wxID_ANY : 0, menu);
52545430 857 event.SetEventObject(menu);
bde56d09
VZ
858
859 return HandleWindowEvent(event);
860}
861
862bool wxFrame::HandleExitMenuLoop(WXWORD isPopup)
ccef86c7 863{
bde56d09
VZ
864 return DoSendMenuOpenCloseEvent(wxEVT_MENU_CLOSE,
865 isPopup ? wxCurrentPopupMenu : NULL,
866 isPopup != 0);
867}
a23fd0e1 868
bde56d09
VZ
869bool wxFrame::HandleMenuPopup(wxEventType evtType, WXHMENU hMenu)
870{
871 bool isPopup = false;
a8ff046b 872 wxMenu* menu = NULL;
bde56d09 873 if ( wxCurrentPopupMenu && wxCurrentPopupMenu->GetHMenu() == hMenu )
a8ff046b 874 {
bde56d09
VZ
875 menu = wxCurrentPopupMenu;
876 isPopup = true;
a8ff046b 877 }
bde56d09 878 else if ( GetMenuBar() )
7f3f059a 879 {
bde56d09 880 menu = GetMenuBar()->MSWGetMenu(hMenu);
7f3f059a 881 }
a8ff046b 882
a8ff046b 883
bde56d09 884 return DoSendMenuOpenCloseEvent(evtType, menu, isPopup);
a8ff046b
VZ
885}
886
887#endif // wxUSE_MENUS
888
a23fd0e1 889// ---------------------------------------------------------------------------
0d53fc34 890// the window proc for wxFrame
a23fd0e1
VZ
891// ---------------------------------------------------------------------------
892
c140b7e7 893WXLRESULT wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
a23fd0e1 894{
c140b7e7 895 WXLRESULT rc = 0;
cbe874bd 896 bool processed = false;
a23fd0e1
VZ
897
898 switch ( message )
899 {
42e69d6b
VZ
900 case WM_CLOSE:
901 // if we can't close, tell the system that we processed the
902 // message - otherwise it would close us
903 processed = !Close();
904 break;
905
ccef86c7
VZ
906 case WM_SIZE:
907 processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam);
908 break;
909
42e69d6b
VZ
910 case WM_COMMAND:
911 {
912 WORD id, cmd;
913 WXHWND hwnd;
914 UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam,
915 &id, &hwnd, &cmd);
916
a6ac49b1
VZ
917 HandleCommand(id, cmd, (WXHWND)hwnd);
918
919 // don't pass WM_COMMAND to the base class whether we processed
920 // it or not because we did generate an event for it (our
921 // HandleCommand() calls the base class version) and we must
922 // not do it again or the handlers which skip the event would
923 // be called twice
924 processed = true;
42e69d6b
VZ
925 }
926 break;
927
a8ff046b
VZ
928#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
929#if wxUSE_MENUS
92f1a59c 930 case WM_INITMENUPOPUP:
7f3f059a 931 processed = HandleMenuPopup(wxEVT_MENU_OPEN, (WXHMENU)wParam);
92f1a59c
JS
932 break;
933
a23fd0e1
VZ
934 case WM_MENUSELECT:
935 {
42e69d6b
VZ
936 WXWORD item, flags;
937 WXHMENU hmenu;
938 UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu);
939
940 processed = HandleMenuSelect(item, flags, hmenu);
a23fd0e1
VZ
941 }
942 break;
bc92cdf9 943
bde56d09
VZ
944 case WM_EXITMENULOOP:
945 // Under Windows 98 and 2000 and later we're going to get
946 // WM_UNINITMENUPOPUP which will be used to generate this event
947 // with more information (notably the menu that was closed) so we
948 // only need this one under old Windows systems where the newer
949 // event is never sent.
950 if ( wxGetWinVersion() < wxWinVersion_98 )
951 processed = HandleExitMenuLoop(wParam);
952 break;
953
7f3f059a
VZ
954 case WM_UNINITMENUPOPUP:
955 processed = HandleMenuPopup(wxEVT_MENU_CLOSE, (WXHMENU)wParam);
ccef86c7 956 break;
a8ff046b 957#endif // wxUSE_MENUS
ccef86c7 958
42e69d6b
VZ
959 case WM_QUERYDRAGICON:
960 {
f618020a 961 const wxIcon& icon = GetIcon();
a1b806b9 962 HICON hIcon = icon.IsOk() ? GetHiconOf(icon)
f618020a 963 : (HICON)GetDefaultIcon();
dca0f651 964 rc = (WXLRESULT)hIcon;
42e69d6b
VZ
965 processed = rc != 0;
966 }
967 break;
ccef86c7 968#endif // !__WXMICROWIN__
a23fd0e1
VZ
969 }
970
971 if ( !processed )
7e25f59e 972 rc = wxFrameBase::MSWWindowProc(message, wParam, lParam);
a23fd0e1
VZ
973
974 return rc;
975}
21802234 976
a9928e9d
JS
977// ----------------------------------------------------------------------------
978// wxFrame size management: we exclude the areas taken by menu/status/toolbars
979// from the client area, so the client area is what's really available for the
980// frame contents
981// ----------------------------------------------------------------------------
982
983// get the origin of the client area in the client coordinates
984wxPoint wxFrame::GetClientAreaOrigin() const
985{
986 wxPoint pt = wxTopLevelWindow::GetClientAreaOrigin();
987
988#if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) && \
989 (!defined(__WXWINCE__) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)))
3882e746 990 wxToolBar * const toolbar = GetToolBar();
a9928e9d
JS
991 if ( toolbar && toolbar->IsShown() )
992 {
3882e746 993 const wxSize sizeTB = toolbar->GetSize();
a9928e9d 994
3882e746 995 if ( toolbar->HasFlag(wxTB_TOP) )
a9928e9d 996 {
3882e746 997 pt.y += sizeTB.y;
a9928e9d 998 }
3882e746 999 else if ( toolbar->HasFlag(wxTB_LEFT) )
a9928e9d 1000 {
3882e746 1001 pt.x += sizeTB.x;
a9928e9d
JS
1002 }
1003 }
1004#endif // wxUSE_TOOLBAR
1005
3d487566 1006#if defined(WINCE_WITH_COMMANDBAR)
fb8a56b7
WS
1007 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
1008 {
1009 RECT rect;
1010 ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect);
1011 pt.y += (rect.bottom - rect.top);
1012 }
a9928e9d
JS
1013#endif
1014
1015 return pt;
1016}