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