]> git.saurik.com Git - wxWidgets.git/blame - src/msw/frame.cpp
Don't use DDEExec registry key in wxMSW wxExecute() if it's empty.
[wxWidgets.git] / src / msw / frame.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
08b97268 2// Name: src/msw/frame.cpp
0d53fc34 3// Purpose: wxFrame
2bda0e17
KB
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
6c9a19aa 7// Copyright: (c) Julian Smart
65571936 8// Licence: wxWindows licence
2bda0e17
KB
9/////////////////////////////////////////////////////////////////////////////
10
7c0ea335
VZ
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
2bda0e17
KB
19// For compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
9f3362c4 23 #pragma hdrstop
2bda0e17
KB
24#endif
25
76b49cf4
WS
26#include "wx/frame.h"
27
2bda0e17 28#ifndef WX_PRECOMP
57bd4c60 29 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
9f3362c4 30 #include "wx/app.h"
1e6feb95 31 #include "wx/menu.h"
9f3362c4
VZ
32 #include "wx/utils.h"
33 #include "wx/dialog.h"
34 #include "wx/settings.h"
35 #include "wx/dcclient.h"
d3cc7c65 36 #include "wx/mdi.h"
f6bcfd97 37 #include "wx/panel.h"
e4db172a 38 #include "wx/log.h"
4e3e485b 39 #include "wx/toolbar.h"
3304646d 40 #include "wx/statusbr.h"
25466131 41 #include "wx/menuitem.h"
9f3362c4 42#endif // WX_PRECOMP
2bda0e17
KB
43
44#include "wx/msw/private.h"
7c0ea335 45
afafd942 46#if defined(__POCKETPC__) || defined(__SMARTPHONE__)
855ec944
VZ
47 #include <ole2.h>
48 #include <aygshell.h>
49 #include "wx/msw/winundef.h"
afafd942
JS
50#endif
51
8f62e633
RD
52#include "wx/generic/statusbr.h"
53
1e6feb95
VZ
54#ifdef __WXUNIVERSAL__
55 #include "wx/univ/theme.h"
56 #include "wx/univ/colschem.h"
57#endif // __WXUNIVERSAL__
58
7c0ea335
VZ
59// ----------------------------------------------------------------------------
60// globals
61// ----------------------------------------------------------------------------
2bda0e17 62
7f3f059a 63#if wxUSE_MENUS || wxUSE_MENUS_NATIVE
03baf031 64 extern wxMenu *wxCurrentPopupMenu;
7f3f059a 65#endif // wxUSE_MENUS || wxUSE_MENUS_NATIVE
2bda0e17 66
7c0ea335
VZ
67// ----------------------------------------------------------------------------
68// event tables
69// ----------------------------------------------------------------------------
70
0d53fc34 71BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
0d53fc34 72 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
2bda0e17
KB
73END_EVENT_TABLE()
74
7c0ea335
VZ
75// ============================================================================
76// implementation
77// ============================================================================
78
79// ----------------------------------------------------------------------------
80// static class members
81// ----------------------------------------------------------------------------
82
1e6feb95
VZ
83#if wxUSE_STATUSBAR
84 #if wxUSE_NATIVE_STATUSBAR
cbe874bd 85 bool wxFrame::m_useNativeStatusBar = true;
1e6feb95 86 #else
cbe874bd 87 bool wxFrame::m_useNativeStatusBar = false;
1e6feb95
VZ
88 #endif
89#endif // wxUSE_NATIVE_STATUSBAR
2bda0e17 90
7c0ea335
VZ
91// ----------------------------------------------------------------------------
92// creation/destruction
93// ----------------------------------------------------------------------------
2bda0e17 94
0d53fc34 95void wxFrame::Init()
2bda0e17 96{
cf8ff92f
VZ
97#if wxUSE_MENUS
98 m_hMenu = NULL;
99#endif // wxUSE_MENUS
100
9f3362c4
VZ
101#if wxUSE_TOOLTIPS
102 m_hwndToolTip = 0;
103#endif
a2327a9f 104
cbe874bd 105 m_wasMinimized = false;
7c0ea335 106}
9f3362c4 107
0d53fc34 108bool wxFrame::Create(wxWindow *parent,
7c0ea335
VZ
109 wxWindowID id,
110 const wxString& title,
111 const wxPoint& pos,
112 const wxSize& size,
113 long style,
114 const wxString& name)
115{
82c9f85c 116 if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
ef6d716b 117 return false;
d2aef312 118
98a02e87 119 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
b9691677 120
aaf803e9 121#if defined(__SMARTPHONE__)
ef6d716b
WS
122 SetLeftMenu(wxID_EXIT, _("Done"));
123#endif
124
855ec944 125#if wxUSE_ACCEL && defined(__POCKETPC__)
aaf803e9
JS
126 // The guidelines state that Ctrl+Q should quit the app.
127 // Let's define an accelerator table to send wxID_EXIT.
128 wxAcceleratorEntry entries[1];
129 entries[0].Set(wxACCEL_CTRL, 'Q', wxID_EXIT);
130 wxAcceleratorTable accel(1, entries);
131 SetAcceleratorTable(accel);
855ec944 132#endif // wxUSE_ACCEL && __POCKETPC__
aaf803e9 133
ef6d716b 134 return true;
2bda0e17
KB
135}
136
0d53fc34 137wxFrame::~wxFrame()
2bda0e17 138{
c6212a0c
VZ
139 SendDestroyEvent();
140
82c9f85c 141 DeleteAllBars();
2bda0e17
KB
142}
143
d4597e13
VZ
144// ----------------------------------------------------------------------------
145// wxFrame client size calculations
146// ----------------------------------------------------------------------------
2bda0e17 147
0d53fc34 148void wxFrame::DoSetClientSize(int width, int height)
2bda0e17 149{
82c9f85c 150 // leave enough space for the status bar if we have (and show) it
7c0ea335 151#if wxUSE_STATUSBAR
8d8bd249
VZ
152 wxStatusBar *statbar = GetStatusBar();
153 if ( statbar && statbar->IsShown() )
154 {
8d8bd249
VZ
155 height += statbar->GetSize().y;
156 }
7c0ea335 157#endif // wxUSE_STATUSBAR
2bda0e17 158
68d02db3
VZ
159 // call GetClientAreaOrigin() to take the toolbar into account
160 wxPoint pt = GetClientAreaOrigin();
161 width += pt.x;
162 height += pt.y;
3882e746 163
7a976304 164#if wxUSE_TOOLBAR
3882e746
VZ
165 wxToolBar * const toolbar = GetToolBar();
166 if ( toolbar )
7a976304 167 {
3882e746 168 if ( toolbar->HasFlag(wxTB_RIGHT | wxTB_BOTTOM) )
7a976304 169 {
3882e746
VZ
170 const wxSize sizeTB = toolbar->GetSize();
171 if ( toolbar->HasFlag(wxTB_RIGHT) )
172 width -= sizeTB.x;
173 else // wxTB_BOTTOM
174 height -= sizeTB.y;
7a976304 175 }
3882e746 176 //else: toolbar already taken into account by GetClientAreaOrigin()
7a976304 177 }
3882e746 178#endif // wxUSE_TOOLBAR
68d02db3 179
82c9f85c 180 wxTopLevelWindow::DoSetClientSize(width, height);
2bda0e17
KB
181}
182
d4597e13
VZ
183// Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
184void wxFrame::DoGetClientSize(int *x, int *y) const
185{
186 wxTopLevelWindow::DoGetClientSize(x, y);
187
68d02db3
VZ
188 // account for the possible toolbar
189 wxPoint pt = GetClientAreaOrigin();
190 if ( x )
191 *x -= pt.x;
192
193 if ( y )
194 *y -= pt.y;
3882e746 195
5b2acc3a 196#if wxUSE_TOOLBAR
3882e746
VZ
197 wxToolBar * const toolbar = GetToolBar();
198 if ( toolbar )
5b2acc3a 199 {
3882e746 200 if ( toolbar->HasFlag(wxTB_RIGHT | wxTB_BOTTOM) )
5b2acc3a 201 {
3882e746
VZ
202 const wxSize sizeTB = toolbar->GetSize();
203 if ( toolbar->HasFlag(wxTB_RIGHT) )
204 {
205 if ( x )
206 *x -= sizeTB.x;
207 }
208 else // wxTB_BOTTOM
209 {
210 if ( y )
211 *y -= sizeTB.y;
212 }
7a976304 213 }
3882e746 214 //else: toolbar already taken into account by GetClientAreaOrigin()
7a976304 215 }
3882e746
VZ
216#endif // wxUSE_TOOLBAR
217
d4597e13
VZ
218#if wxUSE_STATUSBAR
219 // adjust client area height to take the status bar into account
220 if ( y )
221 {
222 wxStatusBar *statbar = GetStatusBar();
223 if ( statbar && statbar->IsShown() )
224 {
c22bbd08 225 *y -= statbar->GetSize().y;
d4597e13
VZ
226 }
227 }
228#endif // wxUSE_STATUSBAR
229}
230
7c0ea335 231// ----------------------------------------------------------------------------
0d53fc34 232// wxFrame: various geometry-related functions
7c0ea335
VZ
233// ----------------------------------------------------------------------------
234
67bd5bad 235// generate an artificial resize event
ecdc1183 236void wxFrame::SendSizeEvent(int flags)
67bd5bad 237{
67bd5bad
GT
238 if ( !m_iconized )
239 {
82c9f85c
VZ
240 RECT r = wxGetWindowRect(GetHwnd());
241
ecdc1183
VZ
242 if ( flags & wxSEND_EVENT_POST )
243 {
244 ::PostMessage(GetHwnd(), WM_SIZE,
245 IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED,
246 MAKELPARAM(r.right - r.left, r.bottom - r.top));
247 }
248 else // send it
249 {
250 ::SendMessage(GetHwnd(), WM_SIZE,
251 IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED,
252 MAKELPARAM(r.right - r.left, r.bottom - r.top));
253 }
67bd5bad
GT
254 }
255}
256
d427503c 257#if wxUSE_STATUSBAR
0d53fc34 258wxStatusBar *wxFrame::OnCreateStatusBar(int number,
7c0ea335
VZ
259 long style,
260 wxWindowID id,
261 const wxString& name)
2bda0e17 262{
5cb598ae 263 wxStatusBar *statusBar wxDUMMY_INITIALIZE(NULL);
2bda0e17 264
47d67540 265#if wxUSE_NATIVE_STATUSBAR
1f0500b3 266 if ( !UsesNativeStatusBar() )
2bda0e17 267 {
1f0500b3 268 statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style);
2bda0e17
KB
269 }
270 else
271#endif
272 {
1f0500b3
VZ
273 statusBar = new wxStatusBar(this, id, style, name);
274 }
ed791986 275
1f0500b3 276 statusBar->SetFieldsCount(number);
2bda0e17 277
7c0ea335 278 return statusBar;
2bda0e17
KB
279}
280
0d53fc34 281void wxFrame::PositionStatusBar()
2bda0e17 282{
d4597e13 283 if ( !m_frameStatusBar || !m_frameStatusBar->IsShown() )
ed791986
VZ
284 return;
285
cbc66a27
VZ
286 int w, h;
287 GetClientSize(&w, &h);
3882e746 288
cbc66a27
VZ
289 int sw, sh;
290 m_frameStatusBar->GetSize(&sw, &sh);
291
8efbb8ad
VZ
292 int x = 0;
293#if wxUSE_TOOLBAR
294 wxToolBar * const toolbar = GetToolBar();
295 if ( toolbar && !toolbar->HasFlag(wxTB_TOP) )
296 {
297 const wxSize sizeTB = toolbar->GetSize();
298
299 if ( toolbar->HasFlag(wxTB_LEFT | wxTB_RIGHT) )
300 {
301 if ( toolbar->HasFlag(wxTB_LEFT) )
302 x -= sizeTB.x;
303
304 w += sizeTB.x;
305 }
306 else // wxTB_BOTTOM
307 {
308 // we need to position the status bar below the toolbar
309 h += sizeTB.y;
310 }
311 }
312 //else: no adjustments necessary for the toolbar on top
313#endif // wxUSE_TOOLBAR
314
cbc66a27
VZ
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.
8efbb8ad 317 m_frameStatusBar->SetSize(x, h, w, sh);
2bda0e17 318}
3882e746 319
d427503c 320#endif // wxUSE_STATUSBAR
2bda0e17 321
6522713c 322#if wxUSE_MENUS_NATIVE
ea9a4296 323
0d53fc34 324void wxFrame::AttachMenuBar(wxMenuBar *menubar)
2bda0e17 325{
3180bc0e 326#if defined(__SMARTPHONE__) && defined(__WXWINCE__)
fb8a56b7 327
ed679e74
WS
328 wxMenu *autoMenu = NULL;
329
330 if( menubar->GetMenuCount() == 1 )
331 {
332 autoMenu = wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(menubar->GetMenu(0));
52af3158 333 SetRightMenu(wxID_ANY, menubar->GetMenuLabel(0), autoMenu);
ed679e74
WS
334 }
335 else
fb8a56b7 336 {
ed679e74
WS
337 autoMenu = new wxMenu;
338
339 for( size_t n = 0; n < menubar->GetMenuCount(); n++ )
340 {
341 wxMenu *item = menubar->GetMenu(n);
52af3158 342 wxString label = menubar->GetMenuLabel(n);
ed679e74
WS
343 wxMenu *new_item = wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(item);
344 autoMenu->Append(wxID_ANY, label, new_item);
345 }
346
347 SetRightMenu(wxID_ANY, _("Menu"), autoMenu);
fb8a56b7
WS
348 }
349
fb8a56b7 350#elif defined(WINCE_WITHOUT_COMMANDBAR)
a96b4743
JS
351 if (!GetToolBar())
352 {
a9102b36 353 wxToolMenuBar* toolBar = new wxToolMenuBar(this, wxID_ANY,
a96b4743
JS
354 wxDefaultPosition, wxDefaultSize,
355 wxBORDER_NONE | wxTB_HORIZONTAL,
af5454a4 356 wxToolBarNameStr, menubar);
a96b4743
JS
357 SetToolBar(toolBar);
358 menubar->SetToolBar(toolBar);
359 }
fb8a56b7 360
c0a91b51
VZ
361 // When the main window is created using CW_USEDEFAULT the height of the
362 // menubar is not taken into account, so we resize it afterwards if a
363 // menubar is present
364 HWND hwndMenuBar = SHFindMenuBar(GetHwnd());
365 if ( hwndMenuBar )
fb8a56b7 366 {
c0a91b51
VZ
367 RECT mbRect;
368 ::GetWindowRect(hwndMenuBar, &mbRect);
369 const int menuHeight = mbRect.bottom - mbRect.top;
370
fb8a56b7 371 RECT rc;
c0a91b51 372 ::GetWindowRect(GetHwnd(), &rc);
fb8a56b7
WS
373 // adjust for menu / titlebar height
374 rc.bottom -= (2*menuHeight-1);
375
102db80f 376 ::MoveWindow(GetHwnd(), rc.left, rc.top, rc.right, rc.bottom, FALSE);
fb8a56b7 377 }
a96b4743
JS
378#endif
379
f008af16 380 wxFrameBase::AttachMenuBar(menubar);
6beb85c0 381
f6bcfd97 382 if ( !menubar )
c2dcfdef 383 {
f6bcfd97
BP
384 // actually remove the menu from the frame
385 m_hMenu = (WXHMENU)0;
386 InternalSetMenuBar();
065de612 387 }
f6bcfd97 388 else // set new non NULL menu bar
065de612 389 {
3d487566 390#if !defined(__WXWINCE__) || defined(WINCE_WITH_COMMANDBAR)
f6bcfd97 391 // Can set a menubar several times.
f6bcfd97
BP
392 if ( menubar->GetHMenu() )
393 {
394 m_hMenu = menubar->GetHMenu();
395 }
f008af16 396 else // no HMENU yet
f6bcfd97 397 {
f6bcfd97 398 m_hMenu = menubar->Create();
065de612 399
f6bcfd97 400 if ( !m_hMenu )
f008af16 401 {
9a83f860 402 wxFAIL_MSG( wxT("failed to create menu bar") );
f6bcfd97 403 return;
f008af16 404 }
f6bcfd97 405 }
39d2f9a7 406#endif
f6bcfd97 407 InternalSetMenuBar();
1e6feb95 408 }
2bda0e17
KB
409}
410
0d53fc34 411void wxFrame::InternalSetMenuBar()
2bda0e17 412{
a96b4743 413#if defined(__WXMICROWIN__) || defined(__WXWINCE__)
4676948b 414 // Nothing
4676948b 415#else
42e69d6b 416 if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) )
2bda0e17 417 {
f6bcfd97 418 wxLogLastError(wxT("SetMenu"));
2bda0e17 419 }
04ef50df 420#endif
2bda0e17
KB
421}
422
1e6feb95
VZ
423#endif // wxUSE_MENUS_NATIVE
424
95316a3f
VZ
425#if wxUSE_MENUS
426wxMenu* wxFrame::MSWFindMenuFromHMENU(WXHMENU hMenu)
427{
428 return GetMenuBar() ? GetMenuBar()->MSWGetMenu(hMenu) : NULL;
429}
430#endif // wxUSE_MENUS
431
2bda0e17 432// Responds to colour changes, and passes event on to children.
0d53fc34 433void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
2bda0e17 434{
3ceb10b1
VZ
435 // Don't override the colour explicitly set by the user, if any.
436 if ( !UseBgCol() )
437 {
438 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
439 Refresh();
440 }
2bda0e17 441
1e6feb95 442#if wxUSE_STATUSBAR
2bda0e17
KB
443 if ( m_frameStatusBar )
444 {
445 wxSysColourChangedEvent event2;
446 event2.SetEventObject( m_frameStatusBar );
937013e0 447 m_frameStatusBar->HandleWindowEvent(event2);
2bda0e17 448 }
1e6feb95 449#endif // wxUSE_STATUSBAR
2bda0e17
KB
450
451 // Propagate the event to the non-top-level children
452 wxWindow::OnSysColourChanged(event);
453}
454
cbe874bd 455// Pass true to show full screen, false to restore.
0d53fc34 456bool wxFrame::ShowFullScreen(bool show, long style)
a2327a9f 457{
b01a88e0
VZ
458 // TODO-CE: add support for CE
459#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
085ad686 460 if ( IsFullScreen() == show )
cbe874bd 461 return false;
c641b1d2 462
a2327a9f
JS
463 if (show)
464 {
b01a88e0
VZ
465 // zap the toolbar, menubar, and statusbar if needed
466 //
467 // TODO: hide commandbar for WINCE_WITH_COMMANDBAR
1e6feb95 468#if wxUSE_TOOLBAR
f6bcfd97 469 wxToolBar *theToolBar = GetToolBar();
a2327a9f
JS
470
471 if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar)
472 {
b01a88e0
VZ
473 if ( theToolBar->IsShown() )
474 {
475 theToolBar->SetSize(wxDefaultCoord,0);
476 theToolBar->Show(false);
477 }
478 else // prevent it from being restored later
479 {
480 style &= ~wxFULLSCREEN_NOTOOLBAR;
481 }
a2327a9f 482 }
1e6feb95 483#endif // wxUSE_TOOLBAR
a2327a9f
JS
484
485 if (style & wxFULLSCREEN_NOMENUBAR)
486 SetMenu((HWND)GetHWND(), (HMENU) NULL);
487
1e6feb95
VZ
488#if wxUSE_STATUSBAR
489 wxStatusBar *theStatusBar = GetStatusBar();
1e6feb95 490
a2327a9f
JS
491 // Save the number of fields in the statusbar
492 if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar)
493 {
b01a88e0
VZ
494 if ( theStatusBar->IsShown() )
495 theStatusBar->Show(false);
496 else
497 style &= ~wxFULLSCREEN_NOSTATUSBAR;
a2327a9f 498 }
1e6feb95 499#endif // wxUSE_STATUSBAR
a2327a9f 500 }
b01a88e0 501 else // restore to normal
a2327a9f 502 {
b01a88e0 503 // restore the toolbar, menubar, and statusbar if we had hid them
1e6feb95 504#if wxUSE_TOOLBAR
a2327a9f
JS
505 wxToolBar *theToolBar = GetToolBar();
506
b01a88e0 507 if ((m_fsStyle & wxFULLSCREEN_NOTOOLBAR) && theToolBar)
a2327a9f 508 {
cbe874bd 509 theToolBar->Show(true);
a2327a9f 510 }
1e6feb95 511#endif // wxUSE_TOOLBAR
a2327a9f 512
a8ff046b 513#if wxUSE_MENUS
bc88602a
JS
514 if (m_fsStyle & wxFULLSCREEN_NOMENUBAR)
515 {
51181d29
VZ
516 const WXHMENU hmenu = MSWGetActiveMenu();
517 if ( hmenu )
518 ::SetMenu(GetHwnd(), (HMENU)hmenu);
bc88602a 519 }
a8ff046b 520#endif // wxUSE_MENUS
b01a88e0 521
1e6feb95 522#if wxUSE_STATUSBAR
b01a88e0
VZ
523 wxStatusBar *theStatusBar = GetStatusBar();
524
525 if ((m_fsStyle & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar)
a2327a9f 526 {
b01a88e0
VZ
527 theStatusBar->Show(true);
528 PositionStatusBar();
a2327a9f 529 }
1e6feb95 530#endif // wxUSE_STATUSBAR
a2327a9f 531 }
b01a88e0 532#endif // !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
f6bcfd97 533
085ad686 534 return wxFrameBase::ShowFullScreen(show, style);
2bda0e17
KB
535}
536
7c0ea335
VZ
537// ----------------------------------------------------------------------------
538// tool/status bar stuff
539// ----------------------------------------------------------------------------
540
d427503c 541#if wxUSE_TOOLBAR
7c0ea335 542
0d53fc34 543wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
81d66cf3 544{
3d487566 545#if defined(WINCE_WITHOUT_COMMANDBAR)
39d2f9a7
JS
546 // We may already have a toolbar from calling SetMenuBar.
547 if (GetToolBar())
548 return GetToolBar();
549#endif
7c0ea335 550 if ( wxFrameBase::CreateToolBar(style, id, name) )
81d66cf3 551 {
81d66cf3 552 PositionToolBar();
81d66cf3 553 }
81d66cf3 554
7c0ea335 555 return m_frameToolBar;
81d66cf3
JS
556}
557
0d53fc34 558void wxFrame::PositionToolBar()
81d66cf3 559{
8898842f
VZ
560 // TODO: we want to do something different in WinCE, because the toolbar
561 // should be associated with the commandbar, instead of being
562 // independent window.
563#if !defined(WINCE_WITHOUT_COMMANDBAR)
d4597e13
VZ
564 wxToolBar *toolbar = GetToolBar();
565 if ( toolbar && toolbar->IsShown() )
566 {
567 // don't call our (or even wxTopLevelWindow) version because we want
568 // the real (full) client area size, not excluding the tool/status bar
569 int width, height;
570 wxWindow::DoGetClientSize(&width, &height);
81d66cf3 571
7c0ea335 572#if wxUSE_STATUSBAR
d4597e13
VZ
573 wxStatusBar *statbar = GetStatusBar();
574 if ( statbar && statbar->IsShown() )
575 {
576 height -= statbar->GetClientSize().y;
577 }
7c0ea335 578#endif // wxUSE_STATUSBAR
3882e746
VZ
579
580 int tx, ty, tw, th;
581 toolbar->GetPosition( &tx, &ty );
582 toolbar->GetSize( &tw, &th );
583
dd639a4f 584 int x, y;
3882e746
VZ
585 if ( toolbar->HasFlag(wxTB_BOTTOM) )
586 {
587 x = 0;
588 y = height - th;
589 }
590 else if ( toolbar->HasFlag(wxTB_RIGHT) )
591 {
592 x = width - tw;
593 y = 0;
594 }
595 else // left or top
596 {
597 x = 0;
598 y = 0;
599 }
600
3d487566 601#if defined(WINCE_WITH_COMMANDBAR)
fb8a56b7
WS
602 // We're using a commandbar - so we have to allow for it.
603 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
604 {
605 RECT rect;
606 ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect);
607 y = rect.bottom - rect.top;
608 }
3882e746
VZ
609#endif // WINCE_WITH_COMMANDBAR
610
611 if ( toolbar->HasFlag(wxTB_BOTTOM) )
612 {
613 if ( ty < 0 && ( -ty == th ) )
614 ty = height - th;
615 if ( tx < 0 && (-tx == tw ) )
616 tx = 0;
617 }
618 else if ( toolbar->HasFlag(wxTB_RIGHT) )
7a976304
VZ
619 {
620 if( ty < 0 && ( -ty == th ) )
621 ty = 0;
622 if( tx < 0 && ( -tx == tw ) )
623 tx = width - tw;
624 }
3882e746
VZ
625 else // left or top
626 {
627 if (ty < 0 && (-ty == th))
628 ty = 0;
629 if (tx < 0 && (-tx == tw))
630 tx = 0;
631 }
cbe874bd 632
563f85a9
VZ
633 int desiredW,
634 desiredH;
81d66cf3 635
7a976304 636 if ( toolbar->IsVertical() )
81d66cf3 637 {
563f85a9 638 desiredW = tw;
229de929 639 desiredH = height;
81d66cf3
JS
640 }
641 else
642 {
229de929 643 desiredW = width;
563f85a9 644 desiredH = th;
cbe874bd 645 }
7c0ea335 646
563f85a9 647 // use the 'real' MSW position here, don't offset relatively to the
d4597e13 648 // client area origin
563f85a9 649 toolbar->SetSize(x, y, desiredW, desiredH, wxSIZE_NO_ADJUSTMENTS);
cbe874bd 650
81d66cf3 651 }
8898842f 652#endif // !WINCE_WITH_COMMANDBAR
81d66cf3 653}
d4597e13 654
d427503c 655#endif // wxUSE_TOOLBAR
d2aef312 656
7c0ea335
VZ
657// ----------------------------------------------------------------------------
658// frame state (iconized/maximized/...)
659// ----------------------------------------------------------------------------
660
a23fd0e1
VZ
661// propagate our state change to all child frames: this allows us to emulate X
662// Windows behaviour where child frames float independently of the parent one
663// on the desktop, but are iconized/restored with it
0d53fc34 664void wxFrame::IconizeChildFrames(bool bIconize)
d2aef312 665{
4bc0f25e
VZ
666 m_iconized = bIconize;
667
222ed1d6 668 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
a23fd0e1
VZ
669 node;
670 node = node->GetNext() )
671 {
672 wxWindow *win = node->GetData();
673
3ca6a5f0
BP
674 // iconizing the frames with this style under Win95 shell puts them at
675 // the bottom of the screen (as the MDI children) instead of making
676 // them appear in the taskbar because they are, by virtue of this
677 // style, not managed by the taskbar - instead leave Windows take care
678 // of them
3ca6a5f0
BP
679 if ( win->GetWindowStyle() & wxFRAME_TOOL_WINDOW )
680 continue;
3ca6a5f0 681
3f7bc32b
VZ
682 // the child MDI frames are a special case and should not be touched by
683 // the parent frame - instead, they are managed by the user
2e9f62da 684 wxFrame *frame = wxDynamicCast(win, wxFrame);
1e6feb95
VZ
685 if ( frame
686#if wxUSE_MDI_ARCHITECTURE
4ab2824c 687 && !frame->IsMDIChild()
1e6feb95
VZ
688#endif // wxUSE_MDI_ARCHITECTURE
689 )
a23fd0e1 690 {
9327c3aa
VZ
691 // we don't want to restore the child frames which had been
692 // iconized even before we were iconized, so save the child frame
693 // status when iconizing the parent frame and check it when
694 // restoring it
695 if ( bIconize )
696 {
9c72ebec 697 frame->m_wasMinimized = frame->IsIconized();
9327c3aa
VZ
698 }
699
9c72ebec
VZ
700 // note that we shouldn't touch the hidden frames neither because
701 // iconizing/restoring them would show them as a side effect
702 if ( !frame->m_wasMinimized && frame->IsShown() )
9327c3aa 703 frame->Iconize(bIconize);
a23fd0e1 704 }
d2aef312 705 }
d2aef312
VZ
706}
707
0d53fc34 708WXHICON wxFrame::GetDefaultIcon() const
82c9f85c 709{
94826170
VZ
710 // we don't have any standard icons (any more)
711 return (WXHICON)0;
82c9f85c
VZ
712}
713
a23fd0e1 714// ===========================================================================
42e69d6b 715// message processing
a23fd0e1
VZ
716// ===========================================================================
717
42e69d6b
VZ
718// ---------------------------------------------------------------------------
719// preprocessing
720// ---------------------------------------------------------------------------
721
1ac76609 722bool wxFrame::MSWDoTranslateMessage(wxFrame *frame, WXMSG *pMsg)
42e69d6b
VZ
723{
724 if ( wxWindow::MSWTranslateMessage(pMsg) )
cbe874bd 725 return true;
42e69d6b 726
1e6feb95 727#if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
7802da36 728 // try the menu bar accelerators
42e69d6b 729 wxMenuBar *menuBar = GetMenuBar();
7802da36
VZ
730 if ( menuBar && menuBar->GetAcceleratorTable()->Translate(frame, pMsg) )
731 return true;
a1a1ca89 732#endif // wxUSE_MENUS && wxUSE_ACCEL
42e69d6b 733
cbe874bd 734 return false;
42e69d6b
VZ
735}
736
737// ---------------------------------------------------------------------------
738// our private (non virtual) message handlers
739// ---------------------------------------------------------------------------
740
4bc0f25e 741bool wxFrame::HandleSize(int WXUNUSED(x), int WXUNUSED(y), WXUINT id)
42e69d6b 742{
4676948b 743#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
42e69d6b
VZ
744 switch ( id )
745 {
4bc0f25e
VZ
746 case SIZE_RESTORED:
747 case SIZE_MAXIMIZED:
42e69d6b
VZ
748 // only do it it if we were iconized before, otherwise resizing the
749 // parent frame has a curious side effect of bringing it under it's
750 // children
751 if ( !m_iconized )
752 break;
753
754 // restore all child frames too
cbe874bd 755 IconizeChildFrames(false);
42e69d6b 756
cbe874bd 757 (void)SendIconizeEvent(false);
42e69d6b
VZ
758 break;
759
4bc0f25e 760 case SIZE_MINIMIZED:
42e69d6b 761 // iconize all child frames too
cbe874bd 762 IconizeChildFrames(true);
42e69d6b
VZ
763 break;
764 }
276c8cfb
WS
765#else
766 wxUnusedVar(id);
4bc0f25e 767#endif // !__WXWINCE__
42e69d6b
VZ
768
769 if ( !m_iconized )
770 {
1e6feb95 771#if wxUSE_STATUSBAR
42e69d6b 772 PositionStatusBar();
1e6feb95
VZ
773#endif // wxUSE_STATUSBAR
774
775#if wxUSE_TOOLBAR
42e69d6b 776 PositionToolBar();
1e6feb95 777#endif // wxUSE_TOOLBAR
42e69d6b 778
3d487566 779#if defined(WINCE_WITH_COMMANDBAR)
fb8a56b7
WS
780 // Position the menu command bar
781 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
782 {
783 RECT rect;
784 ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect);
785 wxSize clientSz = GetClientSize();
786
787 if ( !::MoveWindow((HWND) GetMenuBar()->GetCommandBar(), 0, 0, clientSz.x, rect.bottom - rect.top, true ) )
788 {
789 wxLogLastError(wxT("MoveWindow"));
790 }
791
792 }
4bc0f25e 793#endif // WINCE_WITH_COMMANDBAR
42e69d6b
VZ
794 }
795
4bc0f25e
VZ
796 // call the base class version to generate the appropriate events
797 return false;
42e69d6b
VZ
798}
799
1483e5db 800bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
42e69d6b 801{
1483e5db 802#if wxUSE_MENUS
f8114048
JS
803
804#if defined(WINCE_WITHOUT_COMMANDBAR)
805 if (GetToolBar() && GetToolBar()->FindById(id))
806 return GetToolBar()->MSWCommand(cmd, id);
807#endif
808
a6ac49b1
VZ
809 // we only need to handle the menu and accelerator commands from the items
810 // of our menu bar, base wxWindow class already handles the rest
811 if ( !control && (cmd == 0 /* menu */ || cmd == 1 /* accel */) )
42e69d6b 812 {
1e6feb95 813#if wxUSE_MENUS_NATIVE
a6ac49b1 814 if ( !wxCurrentPopupMenu )
1e6feb95 815#endif // wxUSE_MENUS_NATIVE
fb8a56b7 816 {
79f9ea05 817 wxMenuItem * const mitem = FindItemInMenuBar((signed short)id);
1483e5db
VZ
818 if ( mitem )
819 return ProcessCommand(mitem);
42e69d6b
VZ
820 }
821 }
1483e5db 822#endif // wxUSE_MENUS
42e69d6b 823
1483e5db 824 return wxFrameBase::HandleCommand(id, cmd, control);;
42e69d6b
VZ
825}
826
a23fd0e1 827// ---------------------------------------------------------------------------
0d53fc34 828// the window proc for wxFrame
a23fd0e1
VZ
829// ---------------------------------------------------------------------------
830
c140b7e7 831WXLRESULT wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
a23fd0e1 832{
c140b7e7 833 WXLRESULT rc = 0;
cbe874bd 834 bool processed = false;
a23fd0e1
VZ
835
836 switch ( message )
837 {
42e69d6b
VZ
838 case WM_CLOSE:
839 // if we can't close, tell the system that we processed the
840 // message - otherwise it would close us
841 processed = !Close();
842 break;
843
ccef86c7
VZ
844 case WM_SIZE:
845 processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam);
846 break;
847
42e69d6b
VZ
848 case WM_COMMAND:
849 {
850 WORD id, cmd;
851 WXHWND hwnd;
852 UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam,
853 &id, &hwnd, &cmd);
854
a6ac49b1
VZ
855 HandleCommand(id, cmd, (WXHWND)hwnd);
856
857 // don't pass WM_COMMAND to the base class whether we processed
858 // it or not because we did generate an event for it (our
859 // HandleCommand() calls the base class version) and we must
860 // not do it again or the handlers which skip the event would
861 // be called twice
862 processed = true;
42e69d6b
VZ
863 }
864 break;
865
a8ff046b 866#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
42e69d6b
VZ
867 case WM_QUERYDRAGICON:
868 {
f618020a 869 const wxIcon& icon = GetIcon();
a1b806b9 870 HICON hIcon = icon.IsOk() ? GetHiconOf(icon)
f618020a 871 : (HICON)GetDefaultIcon();
dca0f651 872 rc = (WXLRESULT)hIcon;
42e69d6b
VZ
873 processed = rc != 0;
874 }
875 break;
ccef86c7 876#endif // !__WXMICROWIN__
a23fd0e1
VZ
877 }
878
879 if ( !processed )
7e25f59e 880 rc = wxFrameBase::MSWWindowProc(message, wParam, lParam);
a23fd0e1
VZ
881
882 return rc;
883}
21802234 884
a9928e9d
JS
885// ----------------------------------------------------------------------------
886// wxFrame size management: we exclude the areas taken by menu/status/toolbars
887// from the client area, so the client area is what's really available for the
888// frame contents
889// ----------------------------------------------------------------------------
890
891// get the origin of the client area in the client coordinates
892wxPoint wxFrame::GetClientAreaOrigin() const
893{
894 wxPoint pt = wxTopLevelWindow::GetClientAreaOrigin();
895
896#if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) && \
897 (!defined(__WXWINCE__) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)))
3882e746 898 wxToolBar * const toolbar = GetToolBar();
a9928e9d
JS
899 if ( toolbar && toolbar->IsShown() )
900 {
3882e746 901 const wxSize sizeTB = toolbar->GetSize();
a9928e9d 902
3882e746 903 if ( toolbar->HasFlag(wxTB_TOP) )
a9928e9d 904 {
3882e746 905 pt.y += sizeTB.y;
a9928e9d 906 }
3882e746 907 else if ( toolbar->HasFlag(wxTB_LEFT) )
a9928e9d 908 {
3882e746 909 pt.x += sizeTB.x;
a9928e9d
JS
910 }
911 }
912#endif // wxUSE_TOOLBAR
913
3d487566 914#if defined(WINCE_WITH_COMMANDBAR)
fb8a56b7
WS
915 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
916 {
917 RECT rect;
918 ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect);
919 pt.y += (rect.bottom - rect.top);
920 }
a9928e9d
JS
921#endif
922
923 return pt;
924}