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