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