]> git.saurik.com Git - wxWidgets.git/blame - src/msw/frame.cpp
fixed wxNotebook bg colour
[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$
8// Copyright: (c) Julian Smart and Markus Holzem
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
7c0ea335
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
2bda0e17 20#ifdef __GNUG__
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
VZ
44
45#if wxUSE_STATUSBAR
46 #include "wx/statusbr.h"
ed791986 47 #include "wx/generic/statusbr.h"
7c0ea335
VZ
48#endif // wxUSE_STATUSBAR
49
50#if wxUSE_TOOLBAR
51 #include "wx/toolbar.h"
52#endif // wxUSE_TOOLBAR
53
2bda0e17 54#include "wx/menuitem.h"
6776a0b2 55#include "wx/log.h"
2bda0e17 56
1e6feb95
VZ
57#ifdef __WXUNIVERSAL__
58 #include "wx/univ/theme.h"
59 #include "wx/univ/colschem.h"
60#endif // __WXUNIVERSAL__
61
7c0ea335
VZ
62// ----------------------------------------------------------------------------
63// globals
64// ----------------------------------------------------------------------------
2bda0e17 65
2ffa221c 66extern const wxChar *wxFrameClassName;
1e6feb95
VZ
67
68#if wxUSE_MENUS_NATIVE
e1a6fc11 69extern wxMenu *wxCurrentPopupMenu;
1e6feb95 70#endif // wxUSE_MENUS_NATIVE
2bda0e17 71
7c0ea335
VZ
72// ----------------------------------------------------------------------------
73// event tables
74// ----------------------------------------------------------------------------
75
0d53fc34
VS
76BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
77 EVT_ACTIVATE(wxFrame::OnActivate)
78 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
2bda0e17
KB
79END_EVENT_TABLE()
80
0d53fc34 81IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow)
2bda0e17 82
7c0ea335
VZ
83// ============================================================================
84// implementation
85// ============================================================================
86
87// ----------------------------------------------------------------------------
88// static class members
89// ----------------------------------------------------------------------------
90
1e6feb95
VZ
91#if wxUSE_STATUSBAR
92 #if wxUSE_NATIVE_STATUSBAR
0d53fc34 93 bool wxFrame::m_useNativeStatusBar = TRUE;
1e6feb95 94 #else
0d53fc34 95 bool wxFrame::m_useNativeStatusBar = FALSE;
1e6feb95
VZ
96 #endif
97#endif // wxUSE_NATIVE_STATUSBAR
2bda0e17 98
7c0ea335
VZ
99// ----------------------------------------------------------------------------
100// creation/destruction
101// ----------------------------------------------------------------------------
2bda0e17 102
0d53fc34 103void wxFrame::Init()
2bda0e17 104{
9f3362c4
VZ
105#if wxUSE_TOOLTIPS
106 m_hwndToolTip = 0;
107#endif
a2327a9f
JS
108
109 // Data to save/restore when calling ShowFullScreen
a2327a9f
JS
110 m_fsStatusBarFields = 0;
111 m_fsStatusBarHeight = 0;
112 m_fsToolBarHeight = 0;
f6bcfd97 113// m_fsMenu = 0;
f6bcfd97
BP
114
115 m_winLastFocused = (wxWindow *)NULL;
7c0ea335 116}
9f3362c4 117
0d53fc34 118bool wxFrame::Create(wxWindow *parent,
7c0ea335
VZ
119 wxWindowID id,
120 const wxString& title,
121 const wxPoint& pos,
122 const wxSize& size,
123 long style,
124 const wxString& name)
125{
82c9f85c
VZ
126 if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
127 return FALSE;
d2aef312 128
82c9f85c 129 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
2bda0e17 130
82c9f85c 131 wxModelessWindows.Append(this);
f6bcfd97 132
82c9f85c 133 return TRUE;
2bda0e17
KB
134}
135
0d53fc34 136wxFrame::~wxFrame()
2bda0e17 137{
82c9f85c 138 m_isBeingDeleted = TRUE;
2bda0e17 139
82c9f85c 140 DeleteAllBars();
2bda0e17
KB
141}
142
81d66cf3 143// Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
0d53fc34 144void wxFrame::DoGetClientSize(int *x, int *y) const
2bda0e17
KB
145{
146 RECT rect;
42e69d6b 147 ::GetClientRect(GetHwnd(), &rect);
2bda0e17 148
7c0ea335 149#if wxUSE_STATUSBAR
a2327a9f 150 if ( GetStatusBar() && GetStatusBar()->IsShown() )
2bda0e17 151 {
81d66cf3
JS
152 int statusX, statusY;
153 GetStatusBar()->GetClientSize(&statusX, &statusY);
154 rect.bottom -= statusY;
2bda0e17 155 }
7c0ea335 156#endif // wxUSE_STATUSBAR
81d66cf3
JS
157
158 wxPoint pt(GetClientAreaOrigin());
159 rect.bottom -= pt.y;
160 rect.right -= pt.x;
161
0655ad29
VZ
162 if ( x )
163 *x = rect.right;
164 if ( y )
165 *y = rect.bottom;
2bda0e17
KB
166}
167
0d53fc34 168void wxFrame::DoSetClientSize(int width, int height)
2bda0e17 169{
82c9f85c 170 // leave enough space for the status bar if we have (and show) it
7c0ea335 171#if wxUSE_STATUSBAR
8d8bd249
VZ
172 wxStatusBar *statbar = GetStatusBar();
173 if ( statbar && statbar->IsShown() )
174 {
8d8bd249
VZ
175 height += statbar->GetSize().y;
176 }
7c0ea335 177#endif // wxUSE_STATUSBAR
2bda0e17 178
82c9f85c 179 wxTopLevelWindow::DoSetClientSize(width, height);
2bda0e17
KB
180}
181
7c0ea335 182// ----------------------------------------------------------------------------
0d53fc34 183// wxFrame: various geometry-related functions
7c0ea335
VZ
184// ----------------------------------------------------------------------------
185
0d53fc34 186void wxFrame::Raise()
c48926e1
VZ
187{
188#ifdef __WIN16__
189 // no SetForegroundWindow() in Win16
190 wxFrameBase::Raise();
191#else // Win32
192 ::SetForegroundWindow(GetHwnd());
193#endif // Win16/32
194}
195
67bd5bad 196// generate an artificial resize event
0d53fc34 197void wxFrame::SendSizeEvent()
67bd5bad 198{
67bd5bad
GT
199 if ( !m_iconized )
200 {
82c9f85c
VZ
201 RECT r = wxGetWindowRect(GetHwnd());
202
67bd5bad
GT
203 (void)::PostMessage(GetHwnd(), WM_SIZE,
204 IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED,
205 MAKELPARAM(r.right - r.left, r.bottom - r.top));
206 }
207}
208
d427503c 209#if wxUSE_STATUSBAR
0d53fc34 210wxStatusBar *wxFrame::OnCreateStatusBar(int number,
7c0ea335
VZ
211 long style,
212 wxWindowID id,
213 const wxString& name)
2bda0e17
KB
214{
215 wxStatusBar *statusBar = NULL;
216
47d67540 217#if wxUSE_NATIVE_STATUSBAR
1f0500b3 218 if ( !UsesNativeStatusBar() )
2bda0e17 219 {
1f0500b3 220 statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style);
2bda0e17
KB
221 }
222 else
223#endif
224 {
1f0500b3
VZ
225 statusBar = new wxStatusBar(this, id, style, name);
226 }
ed791986 227
1f0500b3 228 statusBar->SetFieldsCount(number);
2bda0e17 229
7c0ea335 230 return statusBar;
2bda0e17
KB
231}
232
0d53fc34 233void wxFrame::PositionStatusBar()
2bda0e17 234{
ed791986
VZ
235 if ( !m_frameStatusBar )
236 return;
237
cbc66a27
VZ
238 int w, h;
239 GetClientSize(&w, &h);
240 int sw, sh;
241 m_frameStatusBar->GetSize(&sw, &sh);
242
243 // Since we wish the status bar to be directly under the client area,
244 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
245 m_frameStatusBar->SetSize(0, h, w, sh);
2bda0e17 246}
d427503c 247#endif // wxUSE_STATUSBAR
2bda0e17 248
6522713c 249#if wxUSE_MENUS_NATIVE
ea9a4296 250
0d53fc34 251void wxFrame::AttachMenuBar(wxMenuBar *menubar)
2bda0e17 252{
f008af16 253 wxFrameBase::AttachMenuBar(menubar);
6beb85c0 254
f6bcfd97 255 if ( !menubar )
c2dcfdef 256 {
f6bcfd97
BP
257 // actually remove the menu from the frame
258 m_hMenu = (WXHMENU)0;
259 InternalSetMenuBar();
065de612 260 }
f6bcfd97 261 else // set new non NULL menu bar
065de612 262 {
f6bcfd97 263 // Can set a menubar several times.
f6bcfd97
BP
264 if ( menubar->GetHMenu() )
265 {
266 m_hMenu = menubar->GetHMenu();
267 }
f008af16 268 else // no HMENU yet
f6bcfd97 269 {
f6bcfd97 270 m_hMenu = menubar->Create();
065de612 271
f6bcfd97 272 if ( !m_hMenu )
f008af16
VZ
273 {
274 wxFAIL_MSG( _T("failed to create menu bar") );
f6bcfd97 275 return;
f008af16 276 }
f6bcfd97 277 }
065de612 278
f6bcfd97 279 InternalSetMenuBar();
1e6feb95 280 }
2bda0e17
KB
281}
282
0d53fc34 283void wxFrame::InternalSetMenuBar()
2bda0e17 284{
04ef50df 285#ifndef __WXMICROWIN__
42e69d6b 286 if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) )
2bda0e17 287 {
f6bcfd97 288 wxLogLastError(wxT("SetMenu"));
2bda0e17 289 }
04ef50df 290#endif
2bda0e17
KB
291}
292
1e6feb95
VZ
293#endif // wxUSE_MENUS_NATIVE
294
2bda0e17 295// Responds to colour changes, and passes event on to children.
0d53fc34 296void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
2bda0e17
KB
297{
298 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
299 Refresh();
300
1e6feb95 301#if wxUSE_STATUSBAR
2bda0e17
KB
302 if ( m_frameStatusBar )
303 {
304 wxSysColourChangedEvent event2;
305 event2.SetEventObject( m_frameStatusBar );
02800301 306 m_frameStatusBar->GetEventHandler()->ProcessEvent(event2);
2bda0e17 307 }
1e6feb95 308#endif // wxUSE_STATUSBAR
2bda0e17
KB
309
310 // Propagate the event to the non-top-level children
311 wxWindow::OnSysColourChanged(event);
312}
313
a2327a9f 314// Pass TRUE to show full screen, FALSE to restore.
0d53fc34 315bool wxFrame::ShowFullScreen(bool show, long style)
a2327a9f 316{
c641b1d2
VS
317 if ( IsFullScreen() == show )
318 return FALSE;
319
a2327a9f
JS
320 if (show)
321 {
1e6feb95 322#if wxUSE_TOOLBAR
f6bcfd97 323 wxToolBar *theToolBar = GetToolBar();
a2327a9f 324 if (theToolBar)
1e6feb95 325 theToolBar->GetSize(NULL, &m_fsToolBarHeight);
a2327a9f
JS
326
327 // zap the toolbar, menubar, and statusbar
328
329 if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar)
330 {
331 theToolBar->SetSize(-1,0);
332 theToolBar->Show(FALSE);
333 }
1e6feb95 334#endif // wxUSE_TOOLBAR
a2327a9f 335
04ef50df 336#ifndef __WXMICROWIN__
a2327a9f
JS
337 if (style & wxFULLSCREEN_NOMENUBAR)
338 SetMenu((HWND)GetHWND(), (HMENU) NULL);
04ef50df 339#endif
a2327a9f 340
1e6feb95
VZ
341#if wxUSE_STATUSBAR
342 wxStatusBar *theStatusBar = GetStatusBar();
343 if (theStatusBar)
344 theStatusBar->GetSize(NULL, &m_fsStatusBarHeight);
345
a2327a9f
JS
346 // Save the number of fields in the statusbar
347 if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar)
348 {
579b10c2
JS
349 //m_fsStatusBarFields = theStatusBar->GetFieldsCount();
350 //SetStatusBar((wxStatusBar*) NULL);
351 //delete theStatusBar;
352 theStatusBar->Show(FALSE);
a2327a9f
JS
353 }
354 else
355 m_fsStatusBarFields = 0;
1e6feb95 356#endif // wxUSE_STATUSBAR
a2327a9f
JS
357 }
358 else
359 {
1e6feb95 360#if wxUSE_TOOLBAR
a2327a9f
JS
361 wxToolBar *theToolBar = GetToolBar();
362
363 // restore the toolbar, menubar, and statusbar
364 if (theToolBar && (m_fsStyle & wxFULLSCREEN_NOTOOLBAR))
365 {
366 theToolBar->SetSize(-1, m_fsToolBarHeight);
367 theToolBar->Show(TRUE);
368 }
1e6feb95 369#endif // wxUSE_TOOLBAR
a2327a9f 370
1e6feb95
VZ
371#if wxUSE_STATUSBAR
372 if ( m_fsStyle & wxFULLSCREEN_NOSTATUSBAR )
a2327a9f 373 {
579b10c2
JS
374 //CreateStatusBar(m_fsStatusBarFields);
375 if (GetStatusBar())
376 {
377 GetStatusBar()->Show(TRUE);
378 PositionStatusBar();
379 }
a2327a9f 380 }
1e6feb95 381#endif // wxUSE_STATUSBAR
a2327a9f 382
04ef50df 383#ifndef __WXMICROWIN__
a2327a9f
JS
384 if ((m_fsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0))
385 SetMenu((HWND)GetHWND(), (HMENU)m_hMenu);
04ef50df 386#endif
a2327a9f 387 }
c641b1d2
VS
388
389 return wxFrameBase::ShowFullScreen(show, style);
a2327a9f
JS
390}
391
2bda0e17
KB
392// Default activation behaviour - set the focus for the first child
393// subwindow found.
0d53fc34 394void wxFrame::OnActivate(wxActivateEvent& event)
2bda0e17 395{
f6bcfd97 396 if ( event.GetActive() )
00c4e897 397 {
f6bcfd97 398 // restore focus to the child which was last focused
0d53fc34 399 wxLogTrace(_T("focus"), _T("wxFrame %08x activated."), m_hWnd);
00c4e897 400
e9456d8d
VZ
401 wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent()
402 : NULL;
403 if ( !parent )
404 {
405 parent = this;
406 }
407
408 wxSetFocusToChild(parent, &m_winLastFocused);
00c4e897 409 }
e9456d8d 410 else // deactivating
2bda0e17 411 {
e9456d8d 412 // remember the last focused child if it is our child
f6bcfd97 413 m_winLastFocused = FindFocus();
e9456d8d
VZ
414
415 // so we NULL it out if it's a child from some other frame
416 wxWindow *win = m_winLastFocused;
417 while ( win )
319fefa9 418 {
e9456d8d
VZ
419 if ( win->IsTopLevel() )
420 {
421 if ( win != this )
422 {
423 m_winLastFocused = NULL;
424 }
425
f6bcfd97 426 break;
e9456d8d 427 }
f6bcfd97 428
e9456d8d 429 win = win->GetParent();
319fefa9 430 }
f6bcfd97
BP
431
432 wxLogTrace(_T("focus"),
0d53fc34 433 _T("wxFrame %08x deactivated, last focused: %08x."),
f6bcfd97
BP
434 m_hWnd,
435 m_winLastFocused ? GetHwndOf(m_winLastFocused)
436 : NULL);
437
438 event.Skip();
2bda0e17 439 }
2bda0e17
KB
440}
441
7c0ea335
VZ
442// ----------------------------------------------------------------------------
443// tool/status bar stuff
444// ----------------------------------------------------------------------------
445
d427503c 446#if wxUSE_TOOLBAR
7c0ea335 447
0d53fc34 448wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
81d66cf3 449{
7c0ea335 450 if ( wxFrameBase::CreateToolBar(style, id, name) )
81d66cf3 451 {
81d66cf3 452 PositionToolBar();
81d66cf3 453 }
81d66cf3 454
7c0ea335 455 return m_frameToolBar;
81d66cf3
JS
456}
457
0d53fc34 458void wxFrame::PositionToolBar()
81d66cf3 459{
81d66cf3 460 RECT rect;
42e69d6b 461 ::GetClientRect(GetHwnd(), &rect);
81d66cf3 462
7c0ea335 463#if wxUSE_STATUSBAR
81d66cf3
JS
464 if ( GetStatusBar() )
465 {
7c0ea335
VZ
466 int statusX, statusY;
467 GetStatusBar()->GetClientSize(&statusX, &statusY);
468 rect.bottom -= statusY;
81d66cf3 469 }
7c0ea335 470#endif // wxUSE_STATUSBAR
81d66cf3 471
a2327a9f 472 if ( GetToolBar() && GetToolBar()->IsShown() )
81d66cf3
JS
473 {
474 int tw, th;
7c0ea335 475 GetToolBar()->GetSize(&tw, &th);
81d66cf3 476
7c0ea335 477 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL )
81d66cf3 478 {
7c0ea335 479 th = rect.bottom;
81d66cf3
JS
480 }
481 else
482 {
7c0ea335 483 tw = rect.right;
81d66cf3 484 }
7c0ea335
VZ
485
486 // Use the 'real' MSW position here
487 GetToolBar()->SetSize(0, 0, tw, th, wxSIZE_NO_ADJUSTMENTS);
81d66cf3
JS
488 }
489}
d427503c 490#endif // wxUSE_TOOLBAR
d2aef312 491
7c0ea335
VZ
492// ----------------------------------------------------------------------------
493// frame state (iconized/maximized/...)
494// ----------------------------------------------------------------------------
495
a23fd0e1
VZ
496// propagate our state change to all child frames: this allows us to emulate X
497// Windows behaviour where child frames float independently of the parent one
498// on the desktop, but are iconized/restored with it
0d53fc34 499void wxFrame::IconizeChildFrames(bool bIconize)
d2aef312 500{
a23fd0e1
VZ
501 for ( wxWindowList::Node *node = GetChildren().GetFirst();
502 node;
503 node = node->GetNext() )
504 {
505 wxWindow *win = node->GetData();
506
3ca6a5f0
BP
507 // iconizing the frames with this style under Win95 shell puts them at
508 // the bottom of the screen (as the MDI children) instead of making
509 // them appear in the taskbar because they are, by virtue of this
510 // style, not managed by the taskbar - instead leave Windows take care
511 // of them
512#ifdef __WIN95__
513 if ( win->GetWindowStyle() & wxFRAME_TOOL_WINDOW )
514 continue;
515#endif // Win95
516
3f7bc32b
VZ
517 // the child MDI frames are a special case and should not be touched by
518 // the parent frame - instead, they are managed by the user
2e9f62da 519 wxFrame *frame = wxDynamicCast(win, wxFrame);
1e6feb95
VZ
520 if ( frame
521#if wxUSE_MDI_ARCHITECTURE
522 && !wxDynamicCast(frame, wxMDIChildFrame)
523#endif // wxUSE_MDI_ARCHITECTURE
524 )
a23fd0e1 525 {
3f7bc32b 526 frame->Iconize(bIconize);
a23fd0e1 527 }
d2aef312 528 }
d2aef312
VZ
529}
530
0d53fc34 531WXHICON wxFrame::GetDefaultIcon() const
82c9f85c
VZ
532{
533 return (WXHICON)(wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON
534 : wxDEFAULT_FRAME_ICON);
535}
536
a23fd0e1 537// ===========================================================================
42e69d6b 538// message processing
a23fd0e1
VZ
539// ===========================================================================
540
42e69d6b
VZ
541// ---------------------------------------------------------------------------
542// preprocessing
543// ---------------------------------------------------------------------------
544
0d53fc34 545bool wxFrame::MSWTranslateMessage(WXMSG* pMsg)
42e69d6b
VZ
546{
547 if ( wxWindow::MSWTranslateMessage(pMsg) )
548 return TRUE;
549
1e6feb95 550#if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
42e69d6b
VZ
551 // try the menu bar accels
552 wxMenuBar *menuBar = GetMenuBar();
553 if ( !menuBar )
554 return FALSE;
555
556 const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable();
c50f1fb9 557 return acceleratorTable.Translate(this, pMsg);
1e6feb95
VZ
558#else
559 return FALSE;
560#endif // wxUSE_MENUS && wxUSE_ACCEL
42e69d6b
VZ
561}
562
563// ---------------------------------------------------------------------------
564// our private (non virtual) message handlers
565// ---------------------------------------------------------------------------
566
0d53fc34 567bool wxFrame::HandlePaint()
42e69d6b
VZ
568{
569 RECT rect;
570 if ( GetUpdateRect(GetHwnd(), &rect, FALSE) )
571 {
04ef50df 572#ifndef __WXMICROWIN__
42e69d6b
VZ
573 if ( m_iconized )
574 {
c50f1fb9 575 HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon)
82c9f85c 576 : (HICON)GetDefaultIcon();
42e69d6b
VZ
577
578 // Hold a pointer to the dc so long as the OnPaint() message
579 // is being processed
580 PAINTSTRUCT ps;
581 HDC hdc = ::BeginPaint(GetHwnd(), &ps);
582
583 // Erase background before painting or we get white background
584 MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L);
585
586 if ( hIcon )
587 {
588 RECT rect;
589 ::GetClientRect(GetHwnd(), &rect);
590
591 // FIXME: why hardcoded?
592 static const int icon_width = 32;
593 static const int icon_height = 32;
594
595 int icon_x = (int)((rect.right - icon_width)/2);
596 int icon_y = (int)((rect.bottom - icon_height)/2);
597
598 ::DrawIcon(hdc, icon_x, icon_y, hIcon);
599 }
600
601 ::EndPaint(GetHwnd(), &ps);
602
603 return TRUE;
604 }
605 else
04ef50df 606 #endif
42e69d6b 607 {
5d1d2d46 608 return wxWindow::HandlePaint();
42e69d6b
VZ
609 }
610 }
611 else
612 {
613 // nothing to paint - processed
614 return TRUE;
615 }
616}
617
0d53fc34 618bool wxFrame::HandleSize(int x, int y, WXUINT id)
42e69d6b
VZ
619{
620 bool processed = FALSE;
04ef50df 621#ifndef __WXMICROWIN__
42e69d6b
VZ
622
623 switch ( id )
624 {
625 case SIZENORMAL:
626 // only do it it if we were iconized before, otherwise resizing the
627 // parent frame has a curious side effect of bringing it under it's
628 // children
629 if ( !m_iconized )
630 break;
631
632 // restore all child frames too
633 IconizeChildFrames(FALSE);
634
3dd9b88a
VZ
635 (void)SendIconizeEvent(FALSE);
636
42e69d6b
VZ
637 // fall through
638
639 case SIZEFULLSCREEN:
640 m_iconized = FALSE;
641 break;
642
643 case SIZEICONIC:
644 // iconize all child frames too
645 IconizeChildFrames(TRUE);
646
3dd9b88a
VZ
647 (void)SendIconizeEvent();
648
42e69d6b
VZ
649 m_iconized = TRUE;
650 break;
651 }
04ef50df 652#endif
42e69d6b
VZ
653
654 if ( !m_iconized )
655 {
1e6feb95 656#if wxUSE_STATUSBAR
42e69d6b 657 PositionStatusBar();
1e6feb95
VZ
658#endif // wxUSE_STATUSBAR
659
660#if wxUSE_TOOLBAR
42e69d6b 661 PositionToolBar();
1e6feb95 662#endif // wxUSE_TOOLBAR
42e69d6b
VZ
663
664 wxSizeEvent event(wxSize(x, y), m_windowId);
665 event.SetEventObject( this );
666 processed = GetEventHandler()->ProcessEvent(event);
667 }
668
669 return processed;
670}
671
0d53fc34 672bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
42e69d6b
VZ
673{
674 if ( control )
675 {
676 // In case it's e.g. a toolbar.
677 wxWindow *win = wxFindWinFromHandle(control);
678 if ( win )
679 return win->MSWCommand(cmd, id);
680 }
681
682 // handle here commands from menus and accelerators
683 if ( cmd == 0 || cmd == 1 )
684 {
1e6feb95 685#if wxUSE_MENUS_NATIVE
42e69d6b
VZ
686 if ( wxCurrentPopupMenu )
687 {
688 wxMenu *popupMenu = wxCurrentPopupMenu;
689 wxCurrentPopupMenu = NULL;
690
691 return popupMenu->MSWCommand(cmd, id);
692 }
1e6feb95 693#endif // wxUSE_MENUS_NATIVE
42e69d6b
VZ
694
695 if ( ProcessCommand(id) )
696 {
697 return TRUE;
698 }
699 }
700
701 return FALSE;
702}
703
0d53fc34 704bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu)
a23fd0e1
VZ
705{
706 int item;
c219cecc 707 if ( flags == 0xFFFF && hMenu == 0 )
a23fd0e1 708 {
c219cecc 709 // menu was removed from screen
a23fd0e1
VZ
710 item = -1;
711 }
04ef50df 712#ifndef __WXMICROWIN__
c219cecc 713 else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) )
a23fd0e1
VZ
714 {
715 item = nItem;
716 }
04ef50df 717#endif
a23fd0e1
VZ
718 else
719 {
1e6feb95 720#if wxUSE_STATUSBAR
c219cecc 721 // don't give hints for separators (doesn't make sense) nor for the
f6bcfd97
BP
722 // items opening popup menus (they don't have them anyhow) but do clear
723 // the status line - otherwise, we would be left with the help message
724 // for the previous item which doesn't apply any more
725 wxStatusBar *statbar = GetStatusBar();
726 if ( statbar )
727 {
728 statbar->SetStatusText(wxEmptyString);
729 }
1e6feb95 730#endif // wxUSE_STATUSBAR
f6bcfd97 731
a23fd0e1
VZ
732 return FALSE;
733 }
734
735 wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item);
736 event.SetEventObject( this );
737
738 return GetEventHandler()->ProcessEvent(event);
739}
740
741// ---------------------------------------------------------------------------
0d53fc34 742// the window proc for wxFrame
a23fd0e1
VZ
743// ---------------------------------------------------------------------------
744
0d53fc34 745long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
a23fd0e1
VZ
746{
747 long rc = 0;
748 bool processed = FALSE;
749
750 switch ( message )
751 {
42e69d6b
VZ
752 case WM_CLOSE:
753 // if we can't close, tell the system that we processed the
754 // message - otherwise it would close us
755 processed = !Close();
756 break;
757
758 case WM_COMMAND:
759 {
760 WORD id, cmd;
761 WXHWND hwnd;
762 UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam,
763 &id, &hwnd, &cmd);
764
765 processed = HandleCommand(id, cmd, (WXHWND)hwnd);
766 }
767 break;
768
04ef50df 769#ifndef __WXMICROWIN__
a23fd0e1
VZ
770 case WM_MENUSELECT:
771 {
42e69d6b
VZ
772 WXWORD item, flags;
773 WXHMENU hmenu;
774 UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu);
775
776 processed = HandleMenuSelect(item, flags, hmenu);
a23fd0e1
VZ
777 }
778 break;
04ef50df 779#endif
42e69d6b
VZ
780
781 case WM_PAINT:
782 processed = HandlePaint();
783 break;
784
04ef50df 785#ifndef __WXMICROWIN__
42e69d6b
VZ
786 case WM_QUERYDRAGICON:
787 {
c50f1fb9 788 HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon)
82c9f85c 789 : (HICON)GetDefaultIcon();
42e69d6b
VZ
790 rc = (long)hIcon;
791 processed = rc != 0;
792 }
793 break;
04ef50df 794#endif
42e69d6b
VZ
795
796 case WM_SIZE:
797 processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam);
798 break;
a23fd0e1
VZ
799 }
800
801 if ( !processed )
802 rc = wxWindow::MSWWindowProc(message, wParam, lParam);
803
804 return rc;
805}
21802234 806