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