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