]> git.saurik.com Git - wxWidgets.git/blame - src/msw/frame.cpp
let wxFRAME_EX_CONTEXTHELP override wxM{IN|AX}IMIZE_BOX as the latter are included...
[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
9f3362c4 30 #include "wx/app.h"
1e6feb95 31 #include "wx/menu.h"
9f3362c4
VZ
32 #include "wx/utils.h"
33 #include "wx/dialog.h"
34 #include "wx/settings.h"
35 #include "wx/dcclient.h"
d3cc7c65 36 #include "wx/mdi.h"
f6bcfd97 37 #include "wx/panel.h"
e4db172a 38 #include "wx/log.h"
4e3e485b 39 #include "wx/toolbar.h"
3304646d 40 #include "wx/statusbr.h"
9f3362c4 41#endif // WX_PRECOMP
2bda0e17
KB
42
43#include "wx/msw/private.h"
7c0ea335 44
2bd6022f
WS
45// include <commctrl.h> "properly"
46#include "wx/msw/wrapcctl.h"
4676948b 47
afafd942 48#if defined(__POCKETPC__) || defined(__SMARTPHONE__)
855ec944
VZ
49 #include <ole2.h>
50 #include <aygshell.h>
51 #include "wx/msw/winundef.h"
afafd942
JS
52#endif
53
3304646d 54#include "wx/generic/statusbr.h"
7c0ea335 55
2bda0e17
KB
56#include "wx/menuitem.h"
57
1e6feb95
VZ
58#ifdef __WXUNIVERSAL__
59 #include "wx/univ/theme.h"
60 #include "wx/univ/colschem.h"
61#endif // __WXUNIVERSAL__
62
7c0ea335
VZ
63// ----------------------------------------------------------------------------
64// globals
65// ----------------------------------------------------------------------------
2bda0e17 66
1e6feb95 67#if wxUSE_MENUS_NATIVE
03baf031 68 extern wxMenu *wxCurrentPopupMenu;
1e6feb95 69#endif // wxUSE_MENUS_NATIVE
2bda0e17 70
7c0ea335
VZ
71// ----------------------------------------------------------------------------
72// event tables
73// ----------------------------------------------------------------------------
74
0d53fc34 75BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
0d53fc34 76 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
2bda0e17
KB
77END_EVENT_TABLE()
78
51596bcb 79#if wxUSE_EXTENDED_RTTI
bc9fb572
JS
80WX_DEFINE_FLAGS( wxFrameStyle )
81
3ff066a4 82wxBEGIN_FLAGS( wxFrameStyle )
bc9fb572
JS
83 // new style border flags, we put them first to
84 // use them for streaming out
3ff066a4
SC
85 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
86 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
87 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
88 wxFLAGS_MEMBER(wxBORDER_RAISED)
89 wxFLAGS_MEMBER(wxBORDER_STATIC)
90 wxFLAGS_MEMBER(wxBORDER_NONE)
cbe874bd 91
bc9fb572 92 // old style border flags
3ff066a4
SC
93 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
94 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
95 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
96 wxFLAGS_MEMBER(wxRAISED_BORDER)
97 wxFLAGS_MEMBER(wxSTATIC_BORDER)
cb0afb26 98 wxFLAGS_MEMBER(wxBORDER)
bc9fb572
JS
99
100 // standard window styles
3ff066a4
SC
101 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
102 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
103 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
104 wxFLAGS_MEMBER(wxWANTS_CHARS)
cb0afb26 105 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
3ff066a4
SC
106 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
107 wxFLAGS_MEMBER(wxVSCROLL)
108 wxFLAGS_MEMBER(wxHSCROLL)
bc9fb572
JS
109
110 // frame styles
3ff066a4
SC
111 wxFLAGS_MEMBER(wxSTAY_ON_TOP)
112 wxFLAGS_MEMBER(wxCAPTION)
1c067fe3 113#if WXWIN_COMPATIBILITY_2_6
3ff066a4 114 wxFLAGS_MEMBER(wxTHICK_FRAME)
1c067fe3 115#endif // WXWIN_COMPATIBILITY_2_6
3ff066a4
SC
116 wxFLAGS_MEMBER(wxSYSTEM_MENU)
117 wxFLAGS_MEMBER(wxRESIZE_BORDER)
1c067fe3 118#if WXWIN_COMPATIBILITY_2_6
3ff066a4 119 wxFLAGS_MEMBER(wxRESIZE_BOX)
1c067fe3 120#endif // WXWIN_COMPATIBILITY_2_6
3ff066a4
SC
121 wxFLAGS_MEMBER(wxCLOSE_BOX)
122 wxFLAGS_MEMBER(wxMAXIMIZE_BOX)
123 wxFLAGS_MEMBER(wxMINIMIZE_BOX)
bc9fb572 124
3ff066a4
SC
125 wxFLAGS_MEMBER(wxFRAME_TOOL_WINDOW)
126 wxFLAGS_MEMBER(wxFRAME_FLOAT_ON_PARENT)
bc9fb572 127
3ff066a4 128 wxFLAGS_MEMBER(wxFRAME_SHAPED)
bc9fb572 129
3ff066a4 130wxEND_FLAGS( wxFrameStyle )
bc9fb572 131
51596bcb
SC
132IMPLEMENT_DYNAMIC_CLASS_XTI(wxFrame, wxTopLevelWindow,"wx/frame.h")
133
3ff066a4 134wxBEGIN_PROPERTIES_TABLE(wxFrame)
fb8a56b7 135 wxEVENT_PROPERTY( Menu , wxEVT_COMMAND_MENU_SELECTED , wxCommandEvent)
c5ca409b 136
3ff066a4 137 wxPROPERTY( Title,wxString, SetTitle, GetTitle, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
af498247
VZ
138 wxPROPERTY_FLAGS( WindowStyle , wxFrameStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
139 wxPROPERTY( MenuBar , wxMenuBar * , SetMenuBar , GetMenuBar , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
3ff066a4 140wxEND_PROPERTIES_TABLE()
51596bcb 141
3ff066a4
SC
142wxBEGIN_HANDLERS_TABLE(wxFrame)
143wxEND_HANDLERS_TABLE()
51596bcb 144
cbe874bd 145wxCONSTRUCTOR_6( wxFrame , wxWindow* , Parent , wxWindowID , Id , wxString , Title , wxPoint , Position , wxSize , Size , long , WindowStyle)
51596bcb
SC
146
147#else
58b43418 148IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow)
51596bcb 149#endif
2bda0e17 150
7c0ea335
VZ
151// ============================================================================
152// implementation
153// ============================================================================
154
155// ----------------------------------------------------------------------------
156// static class members
157// ----------------------------------------------------------------------------
158
1e6feb95
VZ
159#if wxUSE_STATUSBAR
160 #if wxUSE_NATIVE_STATUSBAR
cbe874bd 161 bool wxFrame::m_useNativeStatusBar = true;
1e6feb95 162 #else
cbe874bd 163 bool wxFrame::m_useNativeStatusBar = false;
1e6feb95
VZ
164 #endif
165#endif // wxUSE_NATIVE_STATUSBAR
2bda0e17 166
7c0ea335
VZ
167// ----------------------------------------------------------------------------
168// creation/destruction
169// ----------------------------------------------------------------------------
2bda0e17 170
0d53fc34 171void wxFrame::Init()
2bda0e17 172{
cf8ff92f
VZ
173#if wxUSE_MENUS
174 m_hMenu = NULL;
175#endif // wxUSE_MENUS
176
9f3362c4
VZ
177#if wxUSE_TOOLTIPS
178 m_hwndToolTip = 0;
179#endif
a2327a9f 180
cbe874bd 181 m_wasMinimized = false;
7c0ea335 182}
9f3362c4 183
0d53fc34 184bool wxFrame::Create(wxWindow *parent,
7c0ea335
VZ
185 wxWindowID id,
186 const wxString& title,
187 const wxPoint& pos,
188 const wxSize& size,
189 long style,
190 const wxString& name)
191{
82c9f85c 192 if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
ef6d716b 193 return false;
d2aef312 194
98a02e87 195 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
b9691677 196
aaf803e9 197#if defined(__SMARTPHONE__)
ef6d716b
WS
198 SetLeftMenu(wxID_EXIT, _("Done"));
199#endif
200
855ec944 201#if wxUSE_ACCEL && defined(__POCKETPC__)
aaf803e9
JS
202 // The guidelines state that Ctrl+Q should quit the app.
203 // Let's define an accelerator table to send wxID_EXIT.
204 wxAcceleratorEntry entries[1];
205 entries[0].Set(wxACCEL_CTRL, 'Q', wxID_EXIT);
206 wxAcceleratorTable accel(1, entries);
207 SetAcceleratorTable(accel);
855ec944 208#endif // wxUSE_ACCEL && __POCKETPC__
aaf803e9 209
ef6d716b 210 return true;
2bda0e17
KB
211}
212
0d53fc34 213wxFrame::~wxFrame()
2bda0e17 214{
cbe874bd 215 m_isBeingDeleted = true;
82c9f85c 216 DeleteAllBars();
2bda0e17
KB
217}
218
d4597e13
VZ
219// ----------------------------------------------------------------------------
220// wxFrame client size calculations
221// ----------------------------------------------------------------------------
2bda0e17 222
0d53fc34 223void wxFrame::DoSetClientSize(int width, int height)
2bda0e17 224{
82c9f85c 225 // leave enough space for the status bar if we have (and show) it
7c0ea335 226#if wxUSE_STATUSBAR
8d8bd249
VZ
227 wxStatusBar *statbar = GetStatusBar();
228 if ( statbar && statbar->IsShown() )
229 {
8d8bd249
VZ
230 height += statbar->GetSize().y;
231 }
7c0ea335 232#endif // wxUSE_STATUSBAR
2bda0e17 233
68d02db3
VZ
234 // call GetClientAreaOrigin() to take the toolbar into account
235 wxPoint pt = GetClientAreaOrigin();
236 width += pt.x;
237 height += pt.y;
238
82c9f85c 239 wxTopLevelWindow::DoSetClientSize(width, height);
2bda0e17
KB
240}
241
d4597e13
VZ
242// Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
243void wxFrame::DoGetClientSize(int *x, int *y) const
244{
245 wxTopLevelWindow::DoGetClientSize(x, y);
246
68d02db3
VZ
247 // account for the possible toolbar
248 wxPoint pt = GetClientAreaOrigin();
249 if ( x )
250 *x -= pt.x;
251
252 if ( y )
253 *y -= pt.y;
254
d4597e13
VZ
255#if wxUSE_STATUSBAR
256 // adjust client area height to take the status bar into account
257 if ( y )
258 {
259 wxStatusBar *statbar = GetStatusBar();
260 if ( statbar && statbar->IsShown() )
261 {
262 *y -= statbar->GetClientSize().y;
263 }
264 }
265#endif // wxUSE_STATUSBAR
266}
267
7c0ea335 268// ----------------------------------------------------------------------------
0d53fc34 269// wxFrame: various geometry-related functions
7c0ea335
VZ
270// ----------------------------------------------------------------------------
271
0d53fc34 272void wxFrame::Raise()
c48926e1 273{
c48926e1 274 ::SetForegroundWindow(GetHwnd());
c48926e1
VZ
275}
276
67bd5bad 277// generate an artificial resize event
0d53fc34 278void wxFrame::SendSizeEvent()
67bd5bad 279{
67bd5bad
GT
280 if ( !m_iconized )
281 {
82c9f85c
VZ
282 RECT r = wxGetWindowRect(GetHwnd());
283
67bd5bad
GT
284 (void)::PostMessage(GetHwnd(), WM_SIZE,
285 IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED,
286 MAKELPARAM(r.right - r.left, r.bottom - r.top));
287 }
288}
289
d427503c 290#if wxUSE_STATUSBAR
0d53fc34 291wxStatusBar *wxFrame::OnCreateStatusBar(int number,
7c0ea335
VZ
292 long style,
293 wxWindowID id,
294 const wxString& name)
2bda0e17 295{
5cb598ae 296 wxStatusBar *statusBar wxDUMMY_INITIALIZE(NULL);
2bda0e17 297
47d67540 298#if wxUSE_NATIVE_STATUSBAR
1f0500b3 299 if ( !UsesNativeStatusBar() )
2bda0e17 300 {
1f0500b3 301 statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style);
2bda0e17
KB
302 }
303 else
304#endif
305 {
1f0500b3
VZ
306 statusBar = new wxStatusBar(this, id, style, name);
307 }
ed791986 308
1f0500b3 309 statusBar->SetFieldsCount(number);
2bda0e17 310
7c0ea335 311 return statusBar;
2bda0e17
KB
312}
313
0d53fc34 314void wxFrame::PositionStatusBar()
2bda0e17 315{
d4597e13 316 if ( !m_frameStatusBar || !m_frameStatusBar->IsShown() )
ed791986
VZ
317 return;
318
cbc66a27
VZ
319 int w, h;
320 GetClientSize(&w, &h);
321 int sw, sh;
322 m_frameStatusBar->GetSize(&sw, &sh);
323
324 // Since we wish the status bar to be directly under the client area,
325 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
326 m_frameStatusBar->SetSize(0, h, w, sh);
2bda0e17 327}
d427503c 328#endif // wxUSE_STATUSBAR
2bda0e17 329
6522713c 330#if wxUSE_MENUS_NATIVE
ea9a4296 331
0d53fc34 332void wxFrame::AttachMenuBar(wxMenuBar *menubar)
2bda0e17 333{
3180bc0e 334#if defined(__SMARTPHONE__) && defined(__WXWINCE__)
fb8a56b7 335
ed679e74
WS
336 wxMenu *autoMenu = NULL;
337
338 if( menubar->GetMenuCount() == 1 )
339 {
340 autoMenu = wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(menubar->GetMenu(0));
341 SetRightMenu(wxID_ANY, menubar->GetLabelTop(0), autoMenu);
342 }
343 else
fb8a56b7 344 {
ed679e74
WS
345 autoMenu = new wxMenu;
346
347 for( size_t n = 0; n < menubar->GetMenuCount(); n++ )
348 {
349 wxMenu *item = menubar->GetMenu(n);
350 wxString label = menubar->GetLabelTop(n);
351 wxMenu *new_item = wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(item);
352 autoMenu->Append(wxID_ANY, label, new_item);
353 }
354
355 SetRightMenu(wxID_ANY, _("Menu"), autoMenu);
fb8a56b7
WS
356 }
357
fb8a56b7 358#elif defined(WINCE_WITHOUT_COMMANDBAR)
a96b4743
JS
359 if (!GetToolBar())
360 {
a9102b36 361 wxToolMenuBar* toolBar = new wxToolMenuBar(this, wxID_ANY,
a96b4743
JS
362 wxDefaultPosition, wxDefaultSize,
363 wxBORDER_NONE | wxTB_HORIZONTAL,
af5454a4 364 wxToolBarNameStr, menubar);
a96b4743
JS
365 SetToolBar(toolBar);
366 menubar->SetToolBar(toolBar);
367 }
fb8a56b7
WS
368 // Now adjust size for menu bar
369 int menuHeight = 26;
370
371 //When the main window is created using CW_USEDEFAULT the height of the
372 // is created is not taken into account). So we resize the window after
373 // if a menubar is present
374 {
375 RECT rc;
376 ::GetWindowRect((HWND) GetHWND(), &rc);
377 // adjust for menu / titlebar height
378 rc.bottom -= (2*menuHeight-1);
379
cbe874bd 380 ::MoveWindow((HWND) GetHWND(), rc.left, rc.top, rc.right, rc.bottom, FALSE);
fb8a56b7 381 }
a96b4743
JS
382#endif
383
f008af16 384 wxFrameBase::AttachMenuBar(menubar);
6beb85c0 385
f6bcfd97 386 if ( !menubar )
c2dcfdef 387 {
f6bcfd97
BP
388 // actually remove the menu from the frame
389 m_hMenu = (WXHMENU)0;
390 InternalSetMenuBar();
065de612 391 }
f6bcfd97 392 else // set new non NULL menu bar
065de612 393 {
3d487566 394#if !defined(__WXWINCE__) || defined(WINCE_WITH_COMMANDBAR)
f6bcfd97 395 // Can set a menubar several times.
f6bcfd97
BP
396 if ( menubar->GetHMenu() )
397 {
398 m_hMenu = menubar->GetHMenu();
399 }
f008af16 400 else // no HMENU yet
f6bcfd97 401 {
f6bcfd97 402 m_hMenu = menubar->Create();
065de612 403
f6bcfd97 404 if ( !m_hMenu )
f008af16
VZ
405 {
406 wxFAIL_MSG( _T("failed to create menu bar") );
f6bcfd97 407 return;
f008af16 408 }
f6bcfd97 409 }
39d2f9a7 410#endif
f6bcfd97 411 InternalSetMenuBar();
1e6feb95 412 }
2bda0e17
KB
413}
414
0d53fc34 415void wxFrame::InternalSetMenuBar()
2bda0e17 416{
a96b4743 417#if defined(__WXMICROWIN__) || defined(__WXWINCE__)
4676948b 418 // Nothing
4676948b 419#else
42e69d6b 420 if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) )
2bda0e17 421 {
f6bcfd97 422 wxLogLastError(wxT("SetMenu"));
2bda0e17 423 }
04ef50df 424#endif
2bda0e17
KB
425}
426
1e6feb95
VZ
427#endif // wxUSE_MENUS_NATIVE
428
2bda0e17 429// Responds to colour changes, and passes event on to children.
0d53fc34 430void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
2bda0e17 431{
98a02e87 432 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
2bda0e17
KB
433 Refresh();
434
1e6feb95 435#if wxUSE_STATUSBAR
2bda0e17
KB
436 if ( m_frameStatusBar )
437 {
438 wxSysColourChangedEvent event2;
439 event2.SetEventObject( m_frameStatusBar );
02800301 440 m_frameStatusBar->GetEventHandler()->ProcessEvent(event2);
2bda0e17 441 }
1e6feb95 442#endif // wxUSE_STATUSBAR
2bda0e17
KB
443
444 // Propagate the event to the non-top-level children
445 wxWindow::OnSysColourChanged(event);
446}
447
cbe874bd 448// Pass true to show full screen, false to restore.
0d53fc34 449bool wxFrame::ShowFullScreen(bool show, long style)
a2327a9f 450{
b01a88e0
VZ
451 // TODO-CE: add support for CE
452#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
085ad686 453 if ( IsFullScreen() == show )
cbe874bd 454 return false;
c641b1d2 455
a2327a9f
JS
456 if (show)
457 {
b01a88e0
VZ
458 // zap the toolbar, menubar, and statusbar if needed
459 //
460 // TODO: hide commandbar for WINCE_WITH_COMMANDBAR
1e6feb95 461#if wxUSE_TOOLBAR
f6bcfd97 462 wxToolBar *theToolBar = GetToolBar();
a2327a9f
JS
463
464 if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar)
465 {
b01a88e0
VZ
466 if ( theToolBar->IsShown() )
467 {
468 theToolBar->SetSize(wxDefaultCoord,0);
469 theToolBar->Show(false);
470 }
471 else // prevent it from being restored later
472 {
473 style &= ~wxFULLSCREEN_NOTOOLBAR;
474 }
a2327a9f 475 }
1e6feb95 476#endif // wxUSE_TOOLBAR
a2327a9f
JS
477
478 if (style & wxFULLSCREEN_NOMENUBAR)
479 SetMenu((HWND)GetHWND(), (HMENU) NULL);
480
1e6feb95
VZ
481#if wxUSE_STATUSBAR
482 wxStatusBar *theStatusBar = GetStatusBar();
1e6feb95 483
a2327a9f
JS
484 // Save the number of fields in the statusbar
485 if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar)
486 {
b01a88e0
VZ
487 if ( theStatusBar->IsShown() )
488 theStatusBar->Show(false);
489 else
490 style &= ~wxFULLSCREEN_NOSTATUSBAR;
a2327a9f 491 }
1e6feb95 492#endif // wxUSE_STATUSBAR
a2327a9f 493 }
b01a88e0 494 else // restore to normal
a2327a9f 495 {
b01a88e0 496 // restore the toolbar, menubar, and statusbar if we had hid them
1e6feb95 497#if wxUSE_TOOLBAR
a2327a9f
JS
498 wxToolBar *theToolBar = GetToolBar();
499
b01a88e0 500 if ((m_fsStyle & wxFULLSCREEN_NOTOOLBAR) && theToolBar)
a2327a9f 501 {
cbe874bd 502 theToolBar->Show(true);
a2327a9f 503 }
1e6feb95 504#endif // wxUSE_TOOLBAR
a2327a9f 505
bc88602a
JS
506 if (m_fsStyle & wxFULLSCREEN_NOMENUBAR)
507 {
508 WXHMENU menu = m_hMenu;
509
510#if wxUSE_MDI_ARCHITECTURE
511 wxMDIParentFrame *frame = wxDynamicCast(this, wxMDIParentFrame);
512 if (frame)
513 {
514 wxMDIChildFrame *child = frame->GetActiveChild();
515 if (child)
516 {
517 menu = child->GetWinMenu();
518 }
519 }
520#endif // wxUSE_MDI_ARCHITECTURE
521
522 if (menu)
523 {
524 ::SetMenu(GetHwnd(), (HMENU)menu);
525 }
526 }
b01a88e0 527
1e6feb95 528#if wxUSE_STATUSBAR
b01a88e0
VZ
529 wxStatusBar *theStatusBar = GetStatusBar();
530
531 if ((m_fsStyle & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar)
a2327a9f 532 {
b01a88e0
VZ
533 theStatusBar->Show(true);
534 PositionStatusBar();
a2327a9f 535 }
1e6feb95 536#endif // wxUSE_STATUSBAR
a2327a9f 537 }
b01a88e0 538#endif // !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
f6bcfd97 539
085ad686 540 return wxFrameBase::ShowFullScreen(show, style);
2bda0e17
KB
541}
542
7c0ea335
VZ
543// ----------------------------------------------------------------------------
544// tool/status bar stuff
545// ----------------------------------------------------------------------------
546
d427503c 547#if wxUSE_TOOLBAR
7c0ea335 548
0d53fc34 549wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
81d66cf3 550{
3d487566 551#if defined(WINCE_WITHOUT_COMMANDBAR)
39d2f9a7
JS
552 // We may already have a toolbar from calling SetMenuBar.
553 if (GetToolBar())
554 return GetToolBar();
555#endif
7c0ea335 556 if ( wxFrameBase::CreateToolBar(style, id, name) )
81d66cf3 557 {
81d66cf3 558 PositionToolBar();
81d66cf3 559 }
81d66cf3 560
7c0ea335 561 return m_frameToolBar;
81d66cf3
JS
562}
563
0d53fc34 564void wxFrame::PositionToolBar()
81d66cf3 565{
d4597e13
VZ
566 wxToolBar *toolbar = GetToolBar();
567 if ( toolbar && toolbar->IsShown() )
568 {
3d487566 569#if defined(WINCE_WITHOUT_COMMANDBAR)
09785dd3
JS
570 // We want to do something different in WinCE, because
571 // the toolbar should be associated with the commandbar,
572 // and not an independent window.
573 // TODO
574#else
d4597e13
VZ
575 // don't call our (or even wxTopLevelWindow) version because we want
576 // the real (full) client area size, not excluding the tool/status bar
577 int width, height;
578 wxWindow::DoGetClientSize(&width, &height);
81d66cf3 579
7c0ea335 580#if wxUSE_STATUSBAR
d4597e13
VZ
581 wxStatusBar *statbar = GetStatusBar();
582 if ( statbar && statbar->IsShown() )
583 {
584 height -= statbar->GetClientSize().y;
585 }
7c0ea335 586#endif // wxUSE_STATUSBAR
81d66cf3 587
fb8a56b7
WS
588 int x = 0;
589 int y = 0;
3d487566 590#if defined(WINCE_WITH_COMMANDBAR)
fb8a56b7
WS
591 // We're using a commandbar - so we have to allow for it.
592 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
593 {
594 RECT rect;
595 ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect);
596 y = rect.bottom - rect.top;
597 }
45f27284
JS
598#endif
599
229de929 600 int tx, ty;
81d66cf3 601 int tw, th;
229de929 602 toolbar->GetPosition(&tx, &ty);
d4597e13 603 toolbar->GetSize(&tw, &th);
cbe874bd 604
229de929
JS
605 // Adjust
606 if (ty < 0 && (-ty == th))
607 ty = 0;
608 if (tx < 0 && (-tx == tw))
cbe874bd
WS
609 tx = 0;
610
229de929
JS
611 int desiredW = tw;
612 int desiredH = th;
81d66cf3 613
d4597e13 614 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
81d66cf3 615 {
229de929 616 desiredH = height;
81d66cf3
JS
617 }
618 else
619 {
229de929
JS
620 desiredW = width;
621// if ( toolbar->GetWindowStyleFlag() & wxTB_FLAT )
622// desiredW -= 3;
cbe874bd 623 }
7c0ea335 624
d4597e13
VZ
625 // use the 'real' MSW position here, don't offset relativly to the
626 // client area origin
229de929
JS
627
628 // Optimise such that we don't have to always resize the toolbar
cbe874bd 629 // when the frame changes, otherwise we'll get a lot of flicker.
5cb598ae
WS
630 bool heightChanging wxDUMMY_INITIALIZE(true);
631 bool widthChanging wxDUMMY_INITIALIZE(true);
cbe874bd 632
229de929
JS
633 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
634 {
635 // It's OK if the current height is greater than what can be shown.
636 heightChanging = (desiredH > th) ;
637 widthChanging = (desiredW != tw) ;
cbe874bd
WS
638
639 // The next time around, we may not have to set the size
229de929
JS
640 if (heightChanging)
641 desiredH = desiredH + 200;
642 }
643 else
644 {
645 // It's OK if the current width is greater than what can be shown.
646 widthChanging = (desiredW > tw) ;
647 heightChanging = (desiredH != th) ;
648
cbe874bd 649 // The next time around, we may not have to set the size
229de929
JS
650 if (widthChanging)
651 desiredW = desiredW + 200;
652 }
cbe874bd 653
229de929 654 if (tx != 0 || ty != 0 || widthChanging || heightChanging)
45f27284 655 toolbar->SetSize(x, y, desiredW, desiredH, wxSIZE_NO_ADJUSTMENTS);
cbe874bd 656
09785dd3 657#endif // __WXWINCE__
81d66cf3
JS
658 }
659}
d4597e13 660
d427503c 661#endif // wxUSE_TOOLBAR
d2aef312 662
7c0ea335
VZ
663// ----------------------------------------------------------------------------
664// frame state (iconized/maximized/...)
665// ----------------------------------------------------------------------------
666
a23fd0e1
VZ
667// propagate our state change to all child frames: this allows us to emulate X
668// Windows behaviour where child frames float independently of the parent one
669// on the desktop, but are iconized/restored with it
0d53fc34 670void wxFrame::IconizeChildFrames(bool bIconize)
d2aef312 671{
4bc0f25e
VZ
672 m_iconized = bIconize;
673
222ed1d6 674 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
a23fd0e1
VZ
675 node;
676 node = node->GetNext() )
677 {
678 wxWindow *win = node->GetData();
679
3ca6a5f0
BP
680 // iconizing the frames with this style under Win95 shell puts them at
681 // the bottom of the screen (as the MDI children) instead of making
682 // them appear in the taskbar because they are, by virtue of this
683 // style, not managed by the taskbar - instead leave Windows take care
684 // of them
3ca6a5f0
BP
685 if ( win->GetWindowStyle() & wxFRAME_TOOL_WINDOW )
686 continue;
3ca6a5f0 687
3f7bc32b
VZ
688 // the child MDI frames are a special case and should not be touched by
689 // the parent frame - instead, they are managed by the user
2e9f62da 690 wxFrame *frame = wxDynamicCast(win, wxFrame);
1e6feb95
VZ
691 if ( frame
692#if wxUSE_MDI_ARCHITECTURE
4ab2824c 693 && !frame->IsMDIChild()
1e6feb95
VZ
694#endif // wxUSE_MDI_ARCHITECTURE
695 )
a23fd0e1 696 {
9327c3aa
VZ
697 // we don't want to restore the child frames which had been
698 // iconized even before we were iconized, so save the child frame
699 // status when iconizing the parent frame and check it when
700 // restoring it
701 if ( bIconize )
702 {
9c72ebec 703 frame->m_wasMinimized = frame->IsIconized();
9327c3aa
VZ
704 }
705
9c72ebec
VZ
706 // note that we shouldn't touch the hidden frames neither because
707 // iconizing/restoring them would show them as a side effect
708 if ( !frame->m_wasMinimized && frame->IsShown() )
9327c3aa 709 frame->Iconize(bIconize);
a23fd0e1 710 }
d2aef312 711 }
d2aef312
VZ
712}
713
0d53fc34 714WXHICON wxFrame::GetDefaultIcon() const
82c9f85c 715{
94826170
VZ
716 // we don't have any standard icons (any more)
717 return (WXHICON)0;
82c9f85c
VZ
718}
719
a23fd0e1 720// ===========================================================================
42e69d6b 721// message processing
a23fd0e1
VZ
722// ===========================================================================
723
42e69d6b
VZ
724// ---------------------------------------------------------------------------
725// preprocessing
726// ---------------------------------------------------------------------------
727
1ac76609 728bool wxFrame::MSWDoTranslateMessage(wxFrame *frame, WXMSG *pMsg)
42e69d6b
VZ
729{
730 if ( wxWindow::MSWTranslateMessage(pMsg) )
cbe874bd 731 return true;
42e69d6b 732
1e6feb95 733#if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
42e69d6b
VZ
734 // try the menu bar accels
735 wxMenuBar *menuBar = GetMenuBar();
a1a1ca89
VZ
736 if ( menuBar )
737 {
738 const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable();
1ac76609 739 return acceleratorTable.Translate(frame, pMsg);
a1a1ca89
VZ
740 }
741#endif // wxUSE_MENUS && wxUSE_ACCEL
42e69d6b 742
cbe874bd 743 return false;
42e69d6b
VZ
744}
745
746// ---------------------------------------------------------------------------
747// our private (non virtual) message handlers
748// ---------------------------------------------------------------------------
749
0d53fc34 750bool wxFrame::HandlePaint()
42e69d6b
VZ
751{
752 RECT rect;
cbe874bd 753 if ( ::GetUpdateRect(GetHwnd(), &rect, FALSE) )
42e69d6b 754 {
4676948b 755#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
42e69d6b
VZ
756 if ( m_iconized )
757 {
f618020a
MB
758 const wxIcon& icon = GetIcon();
759 HICON hIcon = icon.Ok() ? GetHiconOf(icon)
760 : (HICON)GetDefaultIcon();
42e69d6b
VZ
761
762 // Hold a pointer to the dc so long as the OnPaint() message
763 // is being processed
764 PAINTSTRUCT ps;
765 HDC hdc = ::BeginPaint(GetHwnd(), &ps);
766
767 // Erase background before painting or we get white background
768 MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L);
769
770 if ( hIcon )
771 {
772 RECT rect;
773 ::GetClientRect(GetHwnd(), &rect);
774
775 // FIXME: why hardcoded?
776 static const int icon_width = 32;
777 static const int icon_height = 32;
778
779 int icon_x = (int)((rect.right - icon_width)/2);
780 int icon_y = (int)((rect.bottom - icon_height)/2);
781
782 ::DrawIcon(hdc, icon_x, icon_y, hIcon);
783 }
784
785 ::EndPaint(GetHwnd(), &ps);
786
cbe874bd 787 return true;
42e69d6b
VZ
788 }
789 else
04ef50df 790 #endif
42e69d6b 791 {
5d1d2d46 792 return wxWindow::HandlePaint();
42e69d6b
VZ
793 }
794 }
795 else
796 {
797 // nothing to paint - processed
cbe874bd 798 return true;
42e69d6b
VZ
799 }
800}
801
4bc0f25e 802bool wxFrame::HandleSize(int WXUNUSED(x), int WXUNUSED(y), WXUINT id)
42e69d6b 803{
4676948b 804#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
42e69d6b
VZ
805 switch ( id )
806 {
4bc0f25e
VZ
807 case SIZE_RESTORED:
808 case SIZE_MAXIMIZED:
42e69d6b
VZ
809 // only do it it if we were iconized before, otherwise resizing the
810 // parent frame has a curious side effect of bringing it under it's
811 // children
812 if ( !m_iconized )
813 break;
814
815 // restore all child frames too
cbe874bd 816 IconizeChildFrames(false);
42e69d6b 817
cbe874bd 818 (void)SendIconizeEvent(false);
42e69d6b
VZ
819 break;
820
4bc0f25e 821 case SIZE_MINIMIZED:
42e69d6b 822 // iconize all child frames too
cbe874bd 823 IconizeChildFrames(true);
42e69d6b
VZ
824 break;
825 }
276c8cfb
WS
826#else
827 wxUnusedVar(id);
4bc0f25e 828#endif // !__WXWINCE__
42e69d6b
VZ
829
830 if ( !m_iconized )
831 {
1e6feb95 832#if wxUSE_STATUSBAR
42e69d6b 833 PositionStatusBar();
1e6feb95
VZ
834#endif // wxUSE_STATUSBAR
835
836#if wxUSE_TOOLBAR
42e69d6b 837 PositionToolBar();
1e6feb95 838#endif // wxUSE_TOOLBAR
42e69d6b 839
3d487566 840#if defined(WINCE_WITH_COMMANDBAR)
fb8a56b7
WS
841 // Position the menu command bar
842 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
843 {
844 RECT rect;
845 ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect);
846 wxSize clientSz = GetClientSize();
847
848 if ( !::MoveWindow((HWND) GetMenuBar()->GetCommandBar(), 0, 0, clientSz.x, rect.bottom - rect.top, true ) )
849 {
850 wxLogLastError(wxT("MoveWindow"));
851 }
852
853 }
4bc0f25e 854#endif // WINCE_WITH_COMMANDBAR
42e69d6b
VZ
855 }
856
4bc0f25e
VZ
857 // call the base class version to generate the appropriate events
858 return false;
42e69d6b
VZ
859}
860
0d53fc34 861bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
42e69d6b
VZ
862{
863 if ( control )
864 {
865 // In case it's e.g. a toolbar.
866 wxWindow *win = wxFindWinFromHandle(control);
867 if ( win )
868 return win->MSWCommand(cmd, id);
869 }
870
871 // handle here commands from menus and accelerators
872 if ( cmd == 0 || cmd == 1 )
873 {
1e6feb95 874#if wxUSE_MENUS_NATIVE
42e69d6b
VZ
875 if ( wxCurrentPopupMenu )
876 {
877 wxMenu *popupMenu = wxCurrentPopupMenu;
878 wxCurrentPopupMenu = NULL;
879
880 return popupMenu->MSWCommand(cmd, id);
881 }
1e6feb95 882#endif // wxUSE_MENUS_NATIVE
42e69d6b 883
3180bc0e 884#if defined(__SMARTPHONE__) && defined(__WXWINCE__)
fb8a56b7
WS
885 // handle here commands from Smartphone menu bar
886 if ( wxTopLevelWindow::HandleCommand(id, cmd, control ) )
887 {
888 return true;
889 }
3180bc0e 890#endif // __SMARTPHONE__ && __WXWINCE__
fb8a56b7 891
42e69d6b
VZ
892 if ( ProcessCommand(id) )
893 {
cbe874bd 894 return true;
42e69d6b
VZ
895 }
896 }
897
cbe874bd 898 return false;
42e69d6b
VZ
899}
900
0d53fc34 901bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu)
a23fd0e1
VZ
902{
903 int item;
c219cecc 904 if ( flags == 0xFFFF && hMenu == 0 )
a23fd0e1 905 {
c219cecc 906 // menu was removed from screen
a23fd0e1
VZ
907 item = -1;
908 }
04ef50df 909#ifndef __WXMICROWIN__
c219cecc 910 else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) )
a23fd0e1
VZ
911 {
912 item = nItem;
913 }
04ef50df 914#endif
a23fd0e1
VZ
915 else
916 {
c219cecc 917 // don't give hints for separators (doesn't make sense) nor for the
f6bcfd97
BP
918 // items opening popup menus (they don't have them anyhow) but do clear
919 // the status line - otherwise, we would be left with the help message
920 // for the previous item which doesn't apply any more
cbe874bd 921 DoGiveHelp(wxEmptyString, false);
f6bcfd97 922
cbe874bd 923 return false;
a23fd0e1
VZ
924 }
925
926 wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item);
ccef86c7
VZ
927 event.SetEventObject(this);
928
929 return GetEventHandler()->ProcessEvent(event);
930}
931
932bool wxFrame::HandleMenuLoop(const wxEventType& evtType, WXWORD isPopup)
933{
934 // we don't have the menu id here, so we use the id to specify if the event
935 // was from a popup menu or a normal one
936 wxMenuEvent event(evtType, isPopup ? -1 : 0);
937 event.SetEventObject(this);
a23fd0e1
VZ
938
939 return GetEventHandler()->ProcessEvent(event);
940}
941
942// ---------------------------------------------------------------------------
0d53fc34 943// the window proc for wxFrame
a23fd0e1
VZ
944// ---------------------------------------------------------------------------
945
c140b7e7 946WXLRESULT wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
a23fd0e1 947{
c140b7e7 948 WXLRESULT rc = 0;
cbe874bd 949 bool processed = false;
a23fd0e1
VZ
950
951 switch ( message )
952 {
42e69d6b
VZ
953 case WM_CLOSE:
954 // if we can't close, tell the system that we processed the
955 // message - otherwise it would close us
956 processed = !Close();
957 break;
958
ccef86c7
VZ
959 case WM_SIZE:
960 processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam);
961 break;
962
42e69d6b
VZ
963 case WM_COMMAND:
964 {
965 WORD id, cmd;
966 WXHWND hwnd;
967 UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam,
968 &id, &hwnd, &cmd);
969
970 processed = HandleCommand(id, cmd, (WXHWND)hwnd);
971 }
972 break;
973
ccef86c7
VZ
974 case WM_PAINT:
975 processed = HandlePaint();
976 break;
977
92f1a59c
JS
978 case WM_INITMENUPOPUP:
979 processed = HandleInitMenuPopup((WXHMENU) wParam);
980 break;
981
4676948b 982#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
a23fd0e1
VZ
983 case WM_MENUSELECT:
984 {
42e69d6b
VZ
985 WXWORD item, flags;
986 WXHMENU hmenu;
987 UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu);
988
989 processed = HandleMenuSelect(item, flags, hmenu);
a23fd0e1
VZ
990 }
991 break;
bc92cdf9 992
ccef86c7 993 case WM_EXITMENULOOP:
373a5fb3 994 processed = HandleMenuLoop(wxEVT_MENU_CLOSE, (WXWORD)wParam);
ccef86c7 995 break;
ccef86c7 996
42e69d6b
VZ
997 case WM_QUERYDRAGICON:
998 {
f618020a
MB
999 const wxIcon& icon = GetIcon();
1000 HICON hIcon = icon.Ok() ? GetHiconOf(icon)
1001 : (HICON)GetDefaultIcon();
42e69d6b
VZ
1002 rc = (long)hIcon;
1003 processed = rc != 0;
1004 }
1005 break;
ccef86c7 1006#endif // !__WXMICROWIN__
a23fd0e1
VZ
1007 }
1008
1009 if ( !processed )
7e25f59e 1010 rc = wxFrameBase::MSWWindowProc(message, wParam, lParam);
a23fd0e1
VZ
1011
1012 return rc;
1013}
21802234 1014
92f1a59c
JS
1015// handle WM_INITMENUPOPUP message
1016bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu)
e39af974 1017{
92f1a59c
JS
1018 wxMenu* menu = NULL;
1019 if (GetMenuBar())
1020 {
1021 int nCount = GetMenuBar()->GetMenuCount();
1022 for (int n = 0; n < nCount; n++)
1023 {
1024 if (GetMenuBar()->GetMenu(n)->GetHMenu() == hMenu)
1025 {
1026 menu = GetMenuBar()->GetMenu(n);
1027 break;
1028 }
1029 }
1030 }
cbe874bd 1031
92f1a59c 1032 wxMenuEvent event(wxEVT_MENU_OPEN, 0, menu);
e39af974
JS
1033 event.SetEventObject(this);
1034
1035 return GetEventHandler()->ProcessEvent(event);
e39af974 1036}
a9928e9d
JS
1037
1038// ----------------------------------------------------------------------------
1039// wxFrame size management: we exclude the areas taken by menu/status/toolbars
1040// from the client area, so the client area is what's really available for the
1041// frame contents
1042// ----------------------------------------------------------------------------
1043
1044// get the origin of the client area in the client coordinates
1045wxPoint wxFrame::GetClientAreaOrigin() const
1046{
1047 wxPoint pt = wxTopLevelWindow::GetClientAreaOrigin();
1048
1049#if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) && \
1050 (!defined(__WXWINCE__) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)))
1051 wxToolBar *toolbar = GetToolBar();
1052 if ( toolbar && toolbar->IsShown() )
1053 {
1054 int w, h;
1055 toolbar->GetSize(&w, &h);
1056
1057 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
1058 {
1059 pt.x += w;
1060 }
1061 else
1062 {
1063 pt.y += h;
1064 }
1065 }
1066#endif // wxUSE_TOOLBAR
1067
3d487566 1068#if defined(WINCE_WITH_COMMANDBAR)
fb8a56b7
WS
1069 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
1070 {
1071 RECT rect;
1072 ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect);
1073 pt.y += (rect.bottom - rect.top);
1074 }
a9928e9d
JS
1075#endif
1076
1077 return pt;
1078}