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