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