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