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