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