]> git.saurik.com Git - wxWidgets.git/blame - src/msw/frame.cpp
extending calculation of visible region
[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
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
SC
133wxBEGIN_PROPERTIES_TABLE(wxFrame)
134 wxEVENT_PROPERTY( Menu , wxEVT_COMMAND_MENU_SELECTED , wxCommandEvent)
c5ca409b 135
3ff066a4
SC
136 wxPROPERTY( Title,wxString, SetTitle, GetTitle, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
137 wxPROPERTY_FLAGS( WindowStyle , wxFrameStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
138 wxPROPERTY( MenuBar , wxMenuBar * , SetMenuBar , GetMenuBar , , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
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 wxModelessWindows.Append(this);
f6bcfd97 198
82c9f85c 199 return TRUE;
2bda0e17
KB
200}
201
0d53fc34 202wxFrame::~wxFrame()
2bda0e17 203{
82c9f85c 204 m_isBeingDeleted = TRUE;
82c9f85c 205 DeleteAllBars();
2bda0e17
KB
206}
207
d4597e13
VZ
208// ----------------------------------------------------------------------------
209// wxFrame client size calculations
210// ----------------------------------------------------------------------------
2bda0e17 211
0d53fc34 212void wxFrame::DoSetClientSize(int width, int height)
2bda0e17 213{
82c9f85c 214 // leave enough space for the status bar if we have (and show) it
7c0ea335 215#if wxUSE_STATUSBAR
8d8bd249
VZ
216 wxStatusBar *statbar = GetStatusBar();
217 if ( statbar && statbar->IsShown() )
218 {
8d8bd249
VZ
219 height += statbar->GetSize().y;
220 }
7c0ea335 221#endif // wxUSE_STATUSBAR
2bda0e17 222
68d02db3
VZ
223 // call GetClientAreaOrigin() to take the toolbar into account
224 wxPoint pt = GetClientAreaOrigin();
225 width += pt.x;
226 height += pt.y;
227
82c9f85c 228 wxTopLevelWindow::DoSetClientSize(width, height);
2bda0e17
KB
229}
230
d4597e13
VZ
231// Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
232void wxFrame::DoGetClientSize(int *x, int *y) const
233{
234 wxTopLevelWindow::DoGetClientSize(x, y);
235
68d02db3
VZ
236 // account for the possible toolbar
237 wxPoint pt = GetClientAreaOrigin();
238 if ( x )
239 *x -= pt.x;
240
241 if ( y )
242 *y -= pt.y;
243
d4597e13
VZ
244#if wxUSE_STATUSBAR
245 // adjust client area height to take the status bar into account
246 if ( y )
247 {
248 wxStatusBar *statbar = GetStatusBar();
249 if ( statbar && statbar->IsShown() )
250 {
251 *y -= statbar->GetClientSize().y;
252 }
253 }
254#endif // wxUSE_STATUSBAR
255}
256
7c0ea335 257// ----------------------------------------------------------------------------
0d53fc34 258// wxFrame: various geometry-related functions
7c0ea335
VZ
259// ----------------------------------------------------------------------------
260
0d53fc34 261void wxFrame::Raise()
c48926e1 262{
c48926e1 263 ::SetForegroundWindow(GetHwnd());
c48926e1
VZ
264}
265
67bd5bad 266// generate an artificial resize event
0d53fc34 267void wxFrame::SendSizeEvent()
67bd5bad 268{
67bd5bad
GT
269 if ( !m_iconized )
270 {
82c9f85c
VZ
271 RECT r = wxGetWindowRect(GetHwnd());
272
67bd5bad
GT
273 (void)::PostMessage(GetHwnd(), WM_SIZE,
274 IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED,
275 MAKELPARAM(r.right - r.left, r.bottom - r.top));
276 }
277}
278
d427503c 279#if wxUSE_STATUSBAR
0d53fc34 280wxStatusBar *wxFrame::OnCreateStatusBar(int number,
7c0ea335
VZ
281 long style,
282 wxWindowID id,
283 const wxString& name)
2bda0e17
KB
284{
285 wxStatusBar *statusBar = NULL;
286
47d67540 287#if wxUSE_NATIVE_STATUSBAR
1f0500b3 288 if ( !UsesNativeStatusBar() )
2bda0e17 289 {
1f0500b3 290 statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style);
2bda0e17
KB
291 }
292 else
293#endif
294 {
1f0500b3
VZ
295 statusBar = new wxStatusBar(this, id, style, name);
296 }
ed791986 297
1f0500b3 298 statusBar->SetFieldsCount(number);
2bda0e17 299
7c0ea335 300 return statusBar;
2bda0e17
KB
301}
302
0d53fc34 303void wxFrame::PositionStatusBar()
2bda0e17 304{
d4597e13 305 if ( !m_frameStatusBar || !m_frameStatusBar->IsShown() )
ed791986
VZ
306 return;
307
cbc66a27
VZ
308 int w, h;
309 GetClientSize(&w, &h);
310 int sw, sh;
311 m_frameStatusBar->GetSize(&sw, &sh);
312
313 // Since we wish the status bar to be directly under the client area,
314 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
315 m_frameStatusBar->SetSize(0, h, w, sh);
2bda0e17 316}
d427503c 317#endif // wxUSE_STATUSBAR
2bda0e17 318
6522713c 319#if wxUSE_MENUS_NATIVE
ea9a4296 320
0d53fc34 321void wxFrame::AttachMenuBar(wxMenuBar *menubar)
2bda0e17 322{
a96b4743
JS
323#if defined(__WXWINCE__) && (_WIN32_WCE < 400 || wxUSE_POCKETPC_UI)
324 if (!GetToolBar())
325 {
326 wxToolBar* toolBar = new wxToolBar(this, -1,
327 wxDefaultPosition, wxDefaultSize,
328 wxBORDER_NONE | wxTB_HORIZONTAL,
af5454a4 329 wxToolBarNameStr, menubar);
a96b4743
JS
330 SetToolBar(toolBar);
331 menubar->SetToolBar(toolBar);
332 }
333#endif
334
f008af16 335 wxFrameBase::AttachMenuBar(menubar);
6beb85c0 336
f6bcfd97 337 if ( !menubar )
c2dcfdef 338 {
f6bcfd97
BP
339 // actually remove the menu from the frame
340 m_hMenu = (WXHMENU)0;
341 InternalSetMenuBar();
065de612 342 }
f6bcfd97 343 else // set new non NULL menu bar
065de612 344 {
a96b4743 345#if !defined(__WXWINCE__) || (_WIN32_WCE >= 400 && !wxUSE_POCKETPC_UI)
f6bcfd97 346 // Can set a menubar several times.
f6bcfd97
BP
347 if ( menubar->GetHMenu() )
348 {
349 m_hMenu = menubar->GetHMenu();
350 }
f008af16 351 else // no HMENU yet
f6bcfd97 352 {
f6bcfd97 353 m_hMenu = menubar->Create();
065de612 354
f6bcfd97 355 if ( !m_hMenu )
f008af16
VZ
356 {
357 wxFAIL_MSG( _T("failed to create menu bar") );
f6bcfd97 358 return;
f008af16 359 }
f6bcfd97 360 }
39d2f9a7 361#endif
f6bcfd97 362 InternalSetMenuBar();
1e6feb95 363 }
2bda0e17
KB
364}
365
0d53fc34 366void wxFrame::InternalSetMenuBar()
2bda0e17 367{
a96b4743 368#if defined(__WXMICROWIN__) || defined(__WXWINCE__)
4676948b 369 // Nothing
4676948b 370#else
42e69d6b 371 if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) )
2bda0e17 372 {
f6bcfd97 373 wxLogLastError(wxT("SetMenu"));
2bda0e17 374 }
04ef50df 375#endif
2bda0e17
KB
376}
377
1e6feb95
VZ
378#endif // wxUSE_MENUS_NATIVE
379
2bda0e17 380// Responds to colour changes, and passes event on to children.
0d53fc34 381void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
2bda0e17 382{
a756f210 383 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
2bda0e17
KB
384 Refresh();
385
1e6feb95 386#if wxUSE_STATUSBAR
2bda0e17
KB
387 if ( m_frameStatusBar )
388 {
389 wxSysColourChangedEvent event2;
390 event2.SetEventObject( m_frameStatusBar );
02800301 391 m_frameStatusBar->GetEventHandler()->ProcessEvent(event2);
2bda0e17 392 }
1e6feb95 393#endif // wxUSE_STATUSBAR
2bda0e17
KB
394
395 // Propagate the event to the non-top-level children
396 wxWindow::OnSysColourChanged(event);
397}
398
a2327a9f 399// Pass TRUE to show full screen, FALSE to restore.
0d53fc34 400bool wxFrame::ShowFullScreen(bool show, long style)
a2327a9f 401{
085ad686 402 if ( IsFullScreen() == show )
c641b1d2
VS
403 return FALSE;
404
a2327a9f
JS
405 if (show)
406 {
1e6feb95 407#if wxUSE_TOOLBAR
a96b4743 408#if defined(__WXWINCE__) && (_WIN32_WCE < 400 || wxUSE_POCKETPC_UI)
09785dd3
JS
409 // TODO: hide commandbar
410#else
f6bcfd97 411 wxToolBar *theToolBar = GetToolBar();
a2327a9f 412 if (theToolBar)
1e6feb95 413 theToolBar->GetSize(NULL, &m_fsToolBarHeight);
a2327a9f
JS
414
415 // zap the toolbar, menubar, and statusbar
416
417 if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar)
418 {
419 theToolBar->SetSize(-1,0);
420 theToolBar->Show(FALSE);
421 }
09785dd3 422#endif // __WXWINCE__
1e6feb95 423#endif // wxUSE_TOOLBAR
a2327a9f 424
a96b4743
JS
425#if defined(__WXMICROWIN__)
426#elif defined(__WXWINCE__)
4676948b 427 // TODO: make it work for WinCE
a96b4743 428#else
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
a96b4743 453#if defined(__WXWINCE__) && (_WIN32_WCE < 400 || wxUSE_POCKETPC_UI)
09785dd3
JS
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
a96b4743
JS
479#if defined(__WXMICROWIN__)
480#elif defined(__WXWINCE__)
4676948b 481 // TODO: make it work for WinCE
a96b4743 482#else
a2327a9f
JS
483 if ((m_fsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0))
484 SetMenu((HWND)GetHWND(), (HMENU)m_hMenu);
04ef50df 485#endif
a2327a9f 486 }
f6bcfd97 487
085ad686 488 return wxFrameBase::ShowFullScreen(show, style);
2bda0e17
KB
489}
490
7c0ea335
VZ
491// ----------------------------------------------------------------------------
492// tool/status bar stuff
493// ----------------------------------------------------------------------------
494
d427503c 495#if wxUSE_TOOLBAR
7c0ea335 496
0d53fc34 497wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
81d66cf3 498{
a96b4743 499#if defined(__WXWINCE__) && (_WIN32_WCE < 400 || wxUSE_POCKETPC_UI)
39d2f9a7
JS
500 // We may already have a toolbar from calling SetMenuBar.
501 if (GetToolBar())
502 return GetToolBar();
503#endif
7c0ea335 504 if ( wxFrameBase::CreateToolBar(style, id, name) )
81d66cf3 505 {
81d66cf3 506 PositionToolBar();
81d66cf3 507 }
81d66cf3 508
7c0ea335 509 return m_frameToolBar;
81d66cf3
JS
510}
511
0d53fc34 512void wxFrame::PositionToolBar()
81d66cf3 513{
d4597e13
VZ
514 wxToolBar *toolbar = GetToolBar();
515 if ( toolbar && toolbar->IsShown() )
516 {
a96b4743 517#if defined(__WXWINCE__) && (_WIN32_WCE < 400 || wxUSE_POCKETPC_UI)
09785dd3
JS
518 // We want to do something different in WinCE, because
519 // the toolbar should be associated with the commandbar,
520 // and not an independent window.
521 // TODO
522#else
d4597e13
VZ
523 // don't call our (or even wxTopLevelWindow) version because we want
524 // the real (full) client area size, not excluding the tool/status bar
525 int width, height;
526 wxWindow::DoGetClientSize(&width, &height);
81d66cf3 527
7c0ea335 528#if wxUSE_STATUSBAR
d4597e13
VZ
529 wxStatusBar *statbar = GetStatusBar();
530 if ( statbar && statbar->IsShown() )
531 {
532 height -= statbar->GetClientSize().y;
533 }
7c0ea335 534#endif // wxUSE_STATUSBAR
81d66cf3 535
229de929 536 int tx, ty;
81d66cf3 537 int tw, th;
229de929 538 toolbar->GetPosition(&tx, &ty);
d4597e13 539 toolbar->GetSize(&tw, &th);
229de929
JS
540
541 // Adjust
542 if (ty < 0 && (-ty == th))
543 ty = 0;
544 if (tx < 0 && (-tx == tw))
545 tx = 0;
546
547 int desiredW = tw;
548 int desiredH = th;
81d66cf3 549
d4597e13 550 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
81d66cf3 551 {
229de929 552 desiredH = height;
81d66cf3
JS
553 }
554 else
555 {
229de929
JS
556 desiredW = width;
557// if ( toolbar->GetWindowStyleFlag() & wxTB_FLAT )
558// desiredW -= 3;
559 }
7c0ea335 560
d4597e13
VZ
561 // use the 'real' MSW position here, don't offset relativly to the
562 // client area origin
229de929
JS
563
564 // Optimise such that we don't have to always resize the toolbar
565 // when the frame changes, otherwise we'll get a lot of flicker.
566 bool heightChanging = TRUE;
567 bool widthChanging = TRUE;
568
569 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
570 {
571 // It's OK if the current height is greater than what can be shown.
572 heightChanging = (desiredH > th) ;
573 widthChanging = (desiredW != tw) ;
574
575 // The next time around, we may not have to set the size
576 if (heightChanging)
577 desiredH = desiredH + 200;
578 }
579 else
580 {
581 // It's OK if the current width is greater than what can be shown.
582 widthChanging = (desiredW > tw) ;
583 heightChanging = (desiredH != th) ;
584
585 // The next time around, we may not have to set the size
586 if (widthChanging)
587 desiredW = desiredW + 200;
588 }
589
590 if (tx != 0 || ty != 0 || widthChanging || heightChanging)
591 toolbar->SetSize(0, 0, desiredW, desiredH, wxSIZE_NO_ADJUSTMENTS);
592
09785dd3 593#endif // __WXWINCE__
81d66cf3
JS
594 }
595}
d4597e13 596
d427503c 597#endif // wxUSE_TOOLBAR
d2aef312 598
7c0ea335
VZ
599// ----------------------------------------------------------------------------
600// frame state (iconized/maximized/...)
601// ----------------------------------------------------------------------------
602
a23fd0e1
VZ
603// propagate our state change to all child frames: this allows us to emulate X
604// Windows behaviour where child frames float independently of the parent one
605// on the desktop, but are iconized/restored with it
0d53fc34 606void wxFrame::IconizeChildFrames(bool bIconize)
d2aef312 607{
222ed1d6 608 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
a23fd0e1
VZ
609 node;
610 node = node->GetNext() )
611 {
612 wxWindow *win = node->GetData();
613
3ca6a5f0
BP
614 // iconizing the frames with this style under Win95 shell puts them at
615 // the bottom of the screen (as the MDI children) instead of making
616 // them appear in the taskbar because they are, by virtue of this
617 // style, not managed by the taskbar - instead leave Windows take care
618 // of them
619#ifdef __WIN95__
620 if ( win->GetWindowStyle() & wxFRAME_TOOL_WINDOW )
621 continue;
622#endif // Win95
623
3f7bc32b
VZ
624 // the child MDI frames are a special case and should not be touched by
625 // the parent frame - instead, they are managed by the user
2e9f62da 626 wxFrame *frame = wxDynamicCast(win, wxFrame);
1e6feb95
VZ
627 if ( frame
628#if wxUSE_MDI_ARCHITECTURE
629 && !wxDynamicCast(frame, wxMDIChildFrame)
630#endif // wxUSE_MDI_ARCHITECTURE
631 )
a23fd0e1 632 {
9327c3aa
VZ
633 // we don't want to restore the child frames which had been
634 // iconized even before we were iconized, so save the child frame
635 // status when iconizing the parent frame and check it when
636 // restoring it
637 if ( bIconize )
638 {
9c72ebec 639 frame->m_wasMinimized = frame->IsIconized();
9327c3aa
VZ
640 }
641
9c72ebec
VZ
642 // note that we shouldn't touch the hidden frames neither because
643 // iconizing/restoring them would show them as a side effect
644 if ( !frame->m_wasMinimized && frame->IsShown() )
9327c3aa 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
c140b7e7 867WXLRESULT wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
a23fd0e1 868{
c140b7e7 869 WXLRESULT rc = 0;
a23fd0e1
VZ
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}