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