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