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