]> git.saurik.com Git - wxWidgets.git/blame - src/msw/frame.cpp
fixed bug reported in patch 427696 (incorrect toolbar style)
[wxWidgets.git] / src / msw / frame.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
7c0ea335 2// Name: msw/frame.cpp
2bda0e17
KB
3// Purpose: wxFrame
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
VZ
32 #include "wx/setup.h"
33 #include "wx/frame.h"
34 #include "wx/menu.h"
35 #include "wx/app.h"
36 #include "wx/utils.h"
37 #include "wx/dialog.h"
38 #include "wx/settings.h"
39 #include "wx/dcclient.h"
d3cc7c65 40 #include "wx/mdi.h"
f6bcfd97 41 #include "wx/panel.h"
9f3362c4 42#endif // WX_PRECOMP
2bda0e17
KB
43
44#include "wx/msw/private.h"
7c0ea335
VZ
45
46#if wxUSE_STATUSBAR
47 #include "wx/statusbr.h"
ed791986 48 #include "wx/generic/statusbr.h"
7c0ea335
VZ
49#endif // wxUSE_STATUSBAR
50
51#if wxUSE_TOOLBAR
52 #include "wx/toolbar.h"
53#endif // wxUSE_TOOLBAR
54
2bda0e17 55#include "wx/menuitem.h"
6776a0b2 56#include "wx/log.h"
2bda0e17 57
7c0ea335
VZ
58// ----------------------------------------------------------------------------
59// globals
60// ----------------------------------------------------------------------------
2bda0e17 61
a23fd0e1 62extern wxWindowList wxModelessWindows;
cde9f08e 63extern wxList WXDLLEXPORT wxPendingDelete;
2ffa221c 64extern const wxChar *wxFrameClassName;
e1a6fc11 65extern wxMenu *wxCurrentPopupMenu;
2bda0e17 66
7c0ea335
VZ
67// ----------------------------------------------------------------------------
68// event tables
69// ----------------------------------------------------------------------------
70
7c0ea335
VZ
71BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
72 EVT_ACTIVATE(wxFrame::OnActivate)
73 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
2bda0e17
KB
74END_EVENT_TABLE()
75
76IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow)
2bda0e17 77
7c0ea335
VZ
78// ============================================================================
79// implementation
80// ============================================================================
81
82// ----------------------------------------------------------------------------
83// static class members
84// ----------------------------------------------------------------------------
85
47d67540 86#if wxUSE_NATIVE_STATUSBAR
9f3362c4 87 bool wxFrame::m_useNativeStatusBar = TRUE;
2bda0e17 88#else
9f3362c4 89 bool wxFrame::m_useNativeStatusBar = FALSE;
2bda0e17
KB
90#endif
91
7c0ea335
VZ
92// ----------------------------------------------------------------------------
93// creation/destruction
94// ----------------------------------------------------------------------------
2bda0e17 95
7c0ea335 96void wxFrame::Init()
2bda0e17 97{
bf505d28
VZ
98 m_iconized =
99 m_maximizeOnShow = FALSE;
7c0ea335 100
9f3362c4
VZ
101#if wxUSE_TOOLTIPS
102 m_hwndToolTip = 0;
103#endif
a2327a9f
JS
104
105 // Data to save/restore when calling ShowFullScreen
106 m_fsStyle = 0;
107 m_fsOldWindowStyle = 0;
108 m_fsStatusBarFields = 0;
109 m_fsStatusBarHeight = 0;
110 m_fsToolBarHeight = 0;
f6bcfd97 111// m_fsMenu = 0;
a2327a9f
JS
112 m_fsIsMaximized = FALSE;
113 m_fsIsShowing = FALSE;
f6bcfd97
BP
114
115 m_winLastFocused = (wxWindow *)NULL;
116
117 // unlike (almost?) all other windows, frames are created hidden
118 m_isShown = FALSE;
7c0ea335 119}
9f3362c4 120
7c0ea335
VZ
121bool wxFrame::Create(wxWindow *parent,
122 wxWindowID id,
123 const wxString& title,
124 const wxPoint& pos,
125 const wxSize& size,
126 long style,
127 const wxString& name)
128{
2bda0e17 129 SetName(name);
2bda0e17
KB
130 m_windowStyle = style;
131 m_frameMenuBar = NULL;
7c0ea335 132 m_frameToolBar = NULL;
2bda0e17
KB
133 m_frameStatusBar = NULL;
134
135 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
136
2bda0e17
KB
137 if ( id > -1 )
138 m_windowId = id;
139 else
140 m_windowId = (int)NewControlId();
141
142 if (parent) parent->AddChild(this);
143
144 int x = pos.x;
145 int y = pos.y;
146 int width = size.x;
147 int height = size.y;
148
149 m_iconized = FALSE;
d2aef312 150
f6bcfd97 151 wxTopLevelWindows.Append(this);
319fefa9 152
aeab10d0 153 MSWCreate(m_windowId, parent, wxFrameClassName, this, title,
d2aef312 154 x, y, width, height, style);
2bda0e17
KB
155
156 wxModelessWindows.Append(this);
f6bcfd97 157
2bda0e17
KB
158 return TRUE;
159}
160
bfc6fde4 161wxFrame::~wxFrame()
2bda0e17
KB
162{
163 m_isBeingDeleted = TRUE;
164 wxTopLevelWindows.DeleteObject(this);
165
f6bcfd97
BP
166 // the ~wxToolBar() code relies on the previous line to be executed before
167 // this one, i.e. the frame should remove itself from wxTopLevelWindows
168 // before destorying its toolbar
7c0ea335 169 DeleteAllBars();
2bda0e17
KB
170
171 if (wxTheApp && (wxTopLevelWindows.Number() == 0))
172 {
173 wxTheApp->SetTopWindow(NULL);
174
175 if (wxTheApp->GetExitOnFrameDelete())
176 {
177 PostQuitMessage(0);
178 }
179 }
180
181 wxModelessWindows.DeleteObject(this);
182
183 // For some reason, wxWindows can activate another task altogether
184 // when a frame is destroyed after a modal dialog has been invoked.
185 // Try to bring the parent to the top.
36e2955a
UM
186 // MT:Only do this if this frame is currently the active window, else weird
187 // things start to happen
188 if ( wxGetActiveWindow() == this )
2bda0e17
KB
189 if (GetParent() && GetParent()->GetHWND())
190 ::BringWindowToTop((HWND) GetParent()->GetHWND());
191}
192
81d66cf3 193// Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
cc2b7472 194void wxFrame::DoGetClientSize(int *x, int *y) const
2bda0e17
KB
195{
196 RECT rect;
42e69d6b 197 ::GetClientRect(GetHwnd(), &rect);
2bda0e17 198
7c0ea335 199#if wxUSE_STATUSBAR
a2327a9f 200 if ( GetStatusBar() && GetStatusBar()->IsShown() )
2bda0e17 201 {
81d66cf3
JS
202 int statusX, statusY;
203 GetStatusBar()->GetClientSize(&statusX, &statusY);
204 rect.bottom -= statusY;
2bda0e17 205 }
7c0ea335 206#endif // wxUSE_STATUSBAR
81d66cf3
JS
207
208 wxPoint pt(GetClientAreaOrigin());
209 rect.bottom -= pt.y;
210 rect.right -= pt.x;
211
0655ad29
VZ
212 if ( x )
213 *x = rect.right;
214 if ( y )
215 *y = rect.bottom;
2bda0e17
KB
216}
217
218// Set the client size (i.e. leave the calculation of borders etc.
219// to wxWindows)
bfc6fde4 220void wxFrame::DoSetClientSize(int width, int height)
2bda0e17 221{
42e69d6b 222 HWND hWnd = GetHwnd();
2bda0e17
KB
223
224 RECT rect;
2de8030d 225 ::GetClientRect(hWnd, &rect);
2bda0e17
KB
226
227 RECT rect2;
228 GetWindowRect(hWnd, &rect2);
229
230 // Find the difference between the entire window (title bar and all)
231 // and the client area; add this to the new client size to move the
232 // window
233 int actual_width = rect2.right - rect2.left - rect.right + width;
234 int actual_height = rect2.bottom - rect2.top - rect.bottom + height;
235
7c0ea335 236#if wxUSE_STATUSBAR
a2327a9f 237 if ( GetStatusBar() && GetStatusBar()->IsShown())
2bda0e17 238 {
81d66cf3
JS
239 int statusX, statusY;
240 GetStatusBar()->GetClientSize(&statusX, &statusY);
241 actual_height += statusY;
2bda0e17 242 }
7c0ea335 243#endif // wxUSE_STATUSBAR
2bda0e17 244
81d66cf3
JS
245 wxPoint pt(GetClientAreaOrigin());
246 actual_width += pt.y;
247 actual_height += pt.x;
248
2bda0e17
KB
249 POINT point;
250 point.x = rect2.left;
251 point.y = rect2.top;
252
253 MoveWindow(hWnd, point.x, point.y, actual_width, actual_height, (BOOL)TRUE);
debe6624 254
2bda0e17
KB
255 wxSizeEvent event(wxSize(width, height), m_windowId);
256 event.SetEventObject( this );
257 GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
258}
259
cc2b7472 260void wxFrame::DoGetSize(int *width, int *height) const
2bda0e17
KB
261{
262 RECT rect;
42e69d6b 263 GetWindowRect(GetHwnd(), &rect);
2bda0e17
KB
264 *width = rect.right - rect.left;
265 *height = rect.bottom - rect.top;
266}
267
cc2b7472 268void wxFrame::DoGetPosition(int *x, int *y) const
2bda0e17
KB
269{
270 RECT rect;
42e69d6b 271 GetWindowRect(GetHwnd(), &rect);
2bda0e17
KB
272 POINT point;
273 point.x = rect.left;
274 point.y = rect.top;
275
276 *x = point.x;
277 *y = point.y;
278}
279
7c0ea335
VZ
280// ----------------------------------------------------------------------------
281// variations around ::ShowWindow()
282// ----------------------------------------------------------------------------
283
284void wxFrame::DoShowWindow(int nShowCmd)
285{
286 ::ShowWindow(GetHwnd(), nShowCmd);
287
288 m_iconized = nShowCmd == SW_MINIMIZE;
289}
290
debe6624 291bool wxFrame::Show(bool show)
2bda0e17 292{
f6bcfd97
BP
293 // don't use wxWindow version as we want to call DoShowWindow()
294 if ( !wxWindowBase::Show(show) )
295 return FALSE;
296
bf505d28
VZ
297 int nShowCmd;
298 if ( show )
299 {
300 if ( m_maximizeOnShow )
301 {
302 // show and maximize
303 nShowCmd = SW_MAXIMIZE;
304
305 m_maximizeOnShow = FALSE;
306 }
307 else // just show
308 {
309 nShowCmd = SW_SHOW;
310 }
311 }
312 else // hide
313 {
314 nShowCmd = SW_HIDE;
315 }
316
317 DoShowWindow(nShowCmd);
2bda0e17 318
7c0ea335 319 if ( show )
2bda0e17 320 {
7c0ea335 321 ::BringWindowToTop(GetHwnd());
2bda0e17 322
7c0ea335
VZ
323 wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_windowId);
324 event.SetEventObject( this );
325 GetEventHandler()->ProcessEvent(event);
326 }
bf505d28 327 else // hide
7c0ea335
VZ
328 {
329 // Try to highlight the correct window (the parent)
330 if ( GetParent() )
331 {
332 HWND hWndParent = GetHwndOf(GetParent());
333 if (hWndParent)
334 ::BringWindowToTop(hWndParent);
335 }
336 }
2bda0e17 337
7c0ea335 338 return TRUE;
2bda0e17
KB
339}
340
debe6624 341void wxFrame::Iconize(bool iconize)
2bda0e17 342{
7c0ea335 343 DoShowWindow(iconize ? SW_MINIMIZE : SW_RESTORE);
2bda0e17
KB
344}
345
debe6624 346void wxFrame::Maximize(bool maximize)
2bda0e17 347{
bf505d28
VZ
348 if ( IsShown() )
349 {
350 // just maximize it directly
351 DoShowWindow(maximize ? SW_MAXIMIZE : SW_RESTORE);
352 }
353 else // hidden
354 {
355 // we can't maximize the hidden frame because it shows it as well, so
356 // just remember that we should do it later in this case
357 m_maximizeOnShow = TRUE;
358 }
7c0ea335
VZ
359}
360
361void wxFrame::Restore()
362{
363 DoShowWindow(SW_RESTORE);
2bda0e17
KB
364}
365
bfc6fde4 366bool wxFrame::IsIconized() const
2bda0e17 367{
42e69d6b 368 ((wxFrame *)this)->m_iconized = (::IsIconic(GetHwnd()) != 0);
2bda0e17
KB
369 return m_iconized;
370}
371
6f63ec3f 372// Is it maximized?
bfc6fde4 373bool wxFrame::IsMaximized() const
6f63ec3f 374{
7c0ea335 375 return (::IsZoomed(GetHwnd()) != 0);
2bda0e17
KB
376}
377
378void wxFrame::SetIcon(const wxIcon& icon)
379{
7c0ea335
VZ
380 wxFrameBase::SetIcon(icon);
381
2bda0e17 382#if defined(__WIN95__)
7c0ea335
VZ
383 if ( m_icon.Ok() )
384 {
385 SendMessage(GetHwnd(), WM_SETICON,
386 (WPARAM)TRUE, (LPARAM)(HICON) m_icon.GetHICON());
387 }
388#endif // __WIN95__
2bda0e17
KB
389}
390
67bd5bad
GT
391// generate an artificial resize event
392void wxFrame::SendSizeEvent()
393{
394 RECT r;
395#ifdef __WIN16__
396 ::GetWindowRect(GetHwnd(), &r);
397#else
398 if ( !::GetWindowRect(GetHwnd(), &r) )
399 {
400 wxLogLastError(_T("GetWindowRect"));
401 }
402#endif
403
404 if ( !m_iconized )
405 {
406 (void)::PostMessage(GetHwnd(), WM_SIZE,
407 IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED,
408 MAKELPARAM(r.right - r.left, r.bottom - r.top));
409 }
410}
411
d427503c 412#if wxUSE_STATUSBAR
7c0ea335
VZ
413wxStatusBar *wxFrame::OnCreateStatusBar(int number,
414 long style,
415 wxWindowID id,
416 const wxString& name)
2bda0e17
KB
417{
418 wxStatusBar *statusBar = NULL;
419
47d67540 420#if wxUSE_NATIVE_STATUSBAR
1f0500b3 421 if ( !UsesNativeStatusBar() )
2bda0e17 422 {
1f0500b3 423 statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style);
2bda0e17
KB
424 }
425 else
426#endif
427 {
1f0500b3
VZ
428 statusBar = new wxStatusBar(this, id, style, name);
429 }
ed791986 430
1f0500b3
VZ
431 // Set the height according to the font and the border size
432 wxClientDC dc(statusBar);
433 dc.SetFont(statusBar->GetFont());
ed791986 434
1f0500b3
VZ
435 wxCoord y;
436 dc.GetTextExtent(_T("X"), NULL, &y );
ed791986 437
1f0500b3 438 int height = (int)( (11*y)/10 + 2*statusBar->GetBorderY());
ed791986 439
1f0500b3 440 statusBar->SetSize(-1, -1, -1, height);
ed791986 441
1f0500b3 442 statusBar->SetFieldsCount(number);
2bda0e17 443
7c0ea335 444 return statusBar;
2bda0e17
KB
445}
446
bfc6fde4 447void wxFrame::PositionStatusBar()
2bda0e17 448{
ed791986
VZ
449 if ( !m_frameStatusBar )
450 return;
451
cbc66a27
VZ
452 int w, h;
453 GetClientSize(&w, &h);
454 int sw, sh;
455 m_frameStatusBar->GetSize(&sw, &sh);
456
457 // Since we wish the status bar to be directly under the client area,
458 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
459 m_frameStatusBar->SetSize(0, h, w, sh);
2bda0e17 460}
d427503c 461#endif // wxUSE_STATUSBAR
2bda0e17 462
ea9a4296
UM
463void wxFrame::DetachMenuBar()
464{
f6bcfd97 465 if ( m_frameMenuBar )
ea9a4296
UM
466 {
467 m_frameMenuBar->Detach();
468 m_frameMenuBar = NULL;
469 }
470}
471
f6bcfd97 472void wxFrame::SetMenuBar(wxMenuBar *menubar)
2bda0e17 473{
f6bcfd97 474 if ( !menubar )
c2dcfdef 475 {
ea9a4296 476 DetachMenuBar();
2bda0e17 477
f6bcfd97
BP
478 // actually remove the menu from the frame
479 m_hMenu = (WXHMENU)0;
480 InternalSetMenuBar();
065de612 481 }
f6bcfd97 482 else // set new non NULL menu bar
065de612 483 {
f6bcfd97 484 m_frameMenuBar = NULL;
065de612 485
f6bcfd97
BP
486 // Can set a menubar several times.
487 // TODO: how to prevent a memory leak if you have a currently-unattached
488 // menubar? wxWindows assumes that the frame will delete the menu (otherwise
489 // there are problems for MDI).
490 if ( menubar->GetHMenu() )
491 {
492 m_hMenu = menubar->GetHMenu();
493 }
494 else
495 {
496 menubar->Detach();
065de612 497
f6bcfd97 498 m_hMenu = menubar->Create();
065de612 499
f6bcfd97
BP
500 if ( !m_hMenu )
501 return;
502 }
065de612 503
f6bcfd97 504 InternalSetMenuBar();
065de612 505
f6bcfd97
BP
506 m_frameMenuBar = menubar;
507 menubar->Attach(this);
065de612 508 }
2bda0e17
KB
509}
510
42e69d6b 511void wxFrame::InternalSetMenuBar()
2bda0e17 512{
42e69d6b 513 if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) )
2bda0e17 514 {
f6bcfd97 515 wxLogLastError(wxT("SetMenu"));
2bda0e17 516 }
2bda0e17
KB
517}
518
519// Responds to colour changes, and passes event on to children.
520void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
521{
522 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
523 Refresh();
524
525 if ( m_frameStatusBar )
526 {
527 wxSysColourChangedEvent event2;
528 event2.SetEventObject( m_frameStatusBar );
02800301 529 m_frameStatusBar->GetEventHandler()->ProcessEvent(event2);
2bda0e17
KB
530 }
531
532 // Propagate the event to the non-top-level children
533 wxWindow::OnSysColourChanged(event);
534}
535
a2327a9f
JS
536// Pass TRUE to show full screen, FALSE to restore.
537bool wxFrame::ShowFullScreen(bool show, long style)
538{
539 if (show)
540 {
541 if (IsFullScreen())
542 return FALSE;
543
544 m_fsIsShowing = TRUE;
545 m_fsStyle = style;
546
f6bcfd97
BP
547 wxToolBar *theToolBar = GetToolBar();
548 wxStatusBar *theStatusBar = GetStatusBar();
a2327a9f
JS
549
550 int dummyWidth;
551
552 if (theToolBar)
553 theToolBar->GetSize(&dummyWidth, &m_fsToolBarHeight);
554 if (theStatusBar)
555 theStatusBar->GetSize(&dummyWidth, &m_fsStatusBarHeight);
556
557 // zap the toolbar, menubar, and statusbar
558
559 if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar)
560 {
561 theToolBar->SetSize(-1,0);
562 theToolBar->Show(FALSE);
563 }
564
565 if (style & wxFULLSCREEN_NOMENUBAR)
566 SetMenu((HWND)GetHWND(), (HMENU) NULL);
567
568 // Save the number of fields in the statusbar
569 if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar)
570 {
579b10c2
JS
571 //m_fsStatusBarFields = theStatusBar->GetFieldsCount();
572 //SetStatusBar((wxStatusBar*) NULL);
573 //delete theStatusBar;
574 theStatusBar->Show(FALSE);
a2327a9f
JS
575 }
576 else
577 m_fsStatusBarFields = 0;
578
579 // zap the frame borders
580
581 // save the 'normal' window style
582 m_fsOldWindowStyle = GetWindowLong((HWND)GetHWND(), GWL_STYLE);
583
f6bcfd97 584 // save the old position, width & height, maximize state
a2327a9f 585 m_fsOldSize = GetRect();
f6bcfd97 586 m_fsIsMaximized = IsMaximized();
a2327a9f 587
f6bcfd97 588 // decide which window style flags to turn off
a2327a9f
JS
589 LONG newStyle = m_fsOldWindowStyle;
590 LONG offFlags = 0;
591
592 if (style & wxFULLSCREEN_NOBORDER)
593 offFlags |= WS_BORDER;
594 if (style & wxFULLSCREEN_NOCAPTION)
595 offFlags |= (WS_CAPTION | WS_SYSMENU);
596
597 newStyle &= (~offFlags);
598
599 // change our window style to be compatible with full-screen mode
600 SetWindowLong((HWND)GetHWND(), GWL_STYLE, newStyle);
601
602 // resize to the size of the desktop
603 int width, height;
604
605 RECT rect;
606 ::GetWindowRect(GetDesktopWindow(), &rect);
607 width = rect.right - rect.left;
608 height = rect.bottom - rect.top;
609
610 SetSize(width, height);
611
612 // now flush the window style cache and actually go full-screen
613 SetWindowPos((HWND)GetHWND(), HWND_TOP, 0, 0, width, height, SWP_FRAMECHANGED);
614
615 wxSizeEvent event(wxSize(width, height), GetId());
616 GetEventHandler()->ProcessEvent(event);
617
618 return TRUE;
619 }
620 else
621 {
622 if (!IsFullScreen())
623 return FALSE;
624
625 m_fsIsShowing = FALSE;
626
627 wxToolBar *theToolBar = GetToolBar();
628
629 // restore the toolbar, menubar, and statusbar
630 if (theToolBar && (m_fsStyle & wxFULLSCREEN_NOTOOLBAR))
631 {
632 theToolBar->SetSize(-1, m_fsToolBarHeight);
633 theToolBar->Show(TRUE);
634 }
635
579b10c2 636 if ((m_fsStyle & wxFULLSCREEN_NOSTATUSBAR)) // && (m_fsStatusBarFields > 0))
a2327a9f 637 {
579b10c2
JS
638 //CreateStatusBar(m_fsStatusBarFields);
639 if (GetStatusBar())
640 {
641 GetStatusBar()->Show(TRUE);
642 PositionStatusBar();
643 }
a2327a9f
JS
644 }
645
646 if ((m_fsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0))
647 SetMenu((HWND)GetHWND(), (HMENU)m_hMenu);
648
649 Maximize(m_fsIsMaximized);
650 SetWindowLong((HWND)GetHWND(),GWL_STYLE, m_fsOldWindowStyle);
651 SetWindowPos((HWND)GetHWND(),HWND_TOP,m_fsOldSize.x, m_fsOldSize.y,
652 m_fsOldSize.width, m_fsOldSize.height, SWP_FRAMECHANGED);
653
654 return TRUE;
655 }
656}
657
2bda0e17
KB
658/*
659 * Frame window
660 *
661 */
662
837e5743 663bool wxFrame::MSWCreate(int id, wxWindow *parent, const wxChar *wclass, wxWindow *wx_win, const wxChar *title,
debe6624 664 int x, int y, int width, int height, long style)
2bda0e17
KB
665
666{
667 m_defaultIcon = (WXHICON) (wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON : wxDEFAULT_FRAME_ICON);
668
669 // If child windows aren't properly drawn initially, WS_CLIPCHILDREN
670 // could be the culprit. But without it, you can get a lot of flicker.
671
2bda0e17 672 DWORD msflags = 0;
3ca6a5f0
BP
673 if ( style & wxCAPTION )
674 {
675 if ( style & wxFRAME_TOOL_WINDOW )
676 msflags |= WS_POPUPWINDOW;
677 else
678 msflags |= WS_OVERLAPPED;
679 }
2bda0e17 680 else
3ca6a5f0
BP
681 {
682 msflags |= WS_POPUP;
683 }
2bda0e17
KB
684
685 if (style & wxMINIMIZE_BOX)
686 msflags |= WS_MINIMIZEBOX;
687 if (style & wxMAXIMIZE_BOX)
688 msflags |= WS_MAXIMIZEBOX;
689 if (style & wxTHICK_FRAME)
690 msflags |= WS_THICKFRAME;
691 if (style & wxSYSTEM_MENU)
692 msflags |= WS_SYSMENU;
f6bcfd97 693 if ( style & wxMINIMIZE )
2bda0e17
KB
694 msflags |= WS_MINIMIZE;
695 if (style & wxMAXIMIZE)
696 msflags |= WS_MAXIMIZE;
697 if (style & wxCAPTION)
698 msflags |= WS_CAPTION;
1c089c47
JS
699 if (style & wxCLIP_CHILDREN)
700 msflags |= WS_CLIPCHILDREN;
2bda0e17
KB
701
702 // Keep this in wxFrame because it saves recoding this function
703 // in wxTinyFrame
8355a72f 704#if wxUSE_ITSY_BITSY && !defined(__WIN32__)
2bda0e17
KB
705 if (style & wxTINY_CAPTION_VERT)
706 msflags |= IBS_VERTCAPTION;
707 if (style & wxTINY_CAPTION_HORIZ)
708 msflags |= IBS_HORZCAPTION;
709#else
710 if (style & wxTINY_CAPTION_VERT)
711 msflags |= WS_CAPTION;
712 if (style & wxTINY_CAPTION_HORIZ)
713 msflags |= WS_CAPTION;
714#endif
715 if ((style & wxTHICK_FRAME) == 0)
716 msflags |= WS_BORDER;
717
718 WXDWORD extendedStyle = MakeExtendedStyle(style);
719
b0a6bb75 720 // make all frames appear in the win9x shell taskbar unless
b3daa5a3 721 // wxFRAME_TOOL_WINDOW or wxFRAME_NO_TASKBAR is given - without giving them
b0a6bb75 722 // WS_EX_APPWINDOW style, the child (i.e. owned) frames wouldn't appear in it
2432b92d 723#if !defined(__WIN16__) && !defined(__SC__)
4b9fc37a
GT
724 if ( (style & wxFRAME_TOOL_WINDOW) ||
725 (style & wxFRAME_NO_TASKBAR) )
b0a6bb75 726 extendedStyle |= WS_EX_TOOLWINDOW;
b3daa5a3 727 else if ( !(style & wxFRAME_NO_TASKBAR) )
b0a6bb75 728 extendedStyle |= WS_EX_APPWINDOW;
1e6d9499 729#endif
cd2df130 730
2bda0e17
KB
731 if (style & wxSTAY_ON_TOP)
732 extendedStyle |= WS_EX_TOPMOST;
733
4204da65 734#ifndef __WIN16__
b96340e6
JS
735 if (m_exStyle & wxFRAME_EX_CONTEXTHELP)
736 extendedStyle |= WS_EX_CONTEXTHELP;
4204da65 737#endif
b96340e6 738
2bda0e17 739 m_iconized = FALSE;
a23fd0e1
VZ
740 if ( !wxWindow::MSWCreate(id, parent, wclass, wx_win, title, x, y, width, height,
741 msflags, NULL, extendedStyle) )
742 return FALSE;
743
2bda0e17
KB
744 // Seems to be necessary if we use WS_POPUP
745 // style instead of WS_OVERLAPPED
746 if (width > -1 && height > -1)
42e69d6b 747 ::PostMessage(GetHwnd(), WM_SIZE, SIZE_RESTORED, MAKELPARAM(width, height));
a23fd0e1
VZ
748
749 return TRUE;
2bda0e17
KB
750}
751
2bda0e17
KB
752// Default activation behaviour - set the focus for the first child
753// subwindow found.
754void wxFrame::OnActivate(wxActivateEvent& event)
755{
f6bcfd97 756 if ( event.GetActive() )
00c4e897 757 {
f6bcfd97
BP
758 // restore focus to the child which was last focused
759 wxLogTrace(_T("focus"), _T("wxFrame %08x activated."), m_hWnd);
00c4e897 760
e9456d8d
VZ
761 wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent()
762 : NULL;
763 if ( !parent )
764 {
765 parent = this;
766 }
767
768 wxSetFocusToChild(parent, &m_winLastFocused);
00c4e897 769 }
e9456d8d 770 else // deactivating
2bda0e17 771 {
e9456d8d 772 // remember the last focused child if it is our child
f6bcfd97 773 m_winLastFocused = FindFocus();
e9456d8d
VZ
774
775 // so we NULL it out if it's a child from some other frame
776 wxWindow *win = m_winLastFocused;
777 while ( win )
319fefa9 778 {
e9456d8d
VZ
779 if ( win->IsTopLevel() )
780 {
781 if ( win != this )
782 {
783 m_winLastFocused = NULL;
784 }
785
f6bcfd97 786 break;
e9456d8d 787 }
f6bcfd97 788
e9456d8d 789 win = win->GetParent();
319fefa9 790 }
f6bcfd97
BP
791
792 wxLogTrace(_T("focus"),
793 _T("wxFrame %08x deactivated, last focused: %08x."),
794 m_hWnd,
795 m_winLastFocused ? GetHwndOf(m_winLastFocused)
796 : NULL);
797
798 event.Skip();
2bda0e17 799 }
2bda0e17
KB
800}
801
de243b05
VS
802void wxFrame::RemoveChild( wxWindowBase *child )
803{
804 if ( child == m_winLastFocused )
805 m_winLastFocused = NULL;
806 wxFrameBase::RemoveChild(child);
807}
808
7c0ea335
VZ
809// ----------------------------------------------------------------------------
810// tool/status bar stuff
811// ----------------------------------------------------------------------------
812
d427503c 813#if wxUSE_TOOLBAR
7c0ea335 814
81d66cf3
JS
815wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
816{
7c0ea335 817 if ( wxFrameBase::CreateToolBar(style, id, name) )
81d66cf3 818 {
81d66cf3 819 PositionToolBar();
81d66cf3 820 }
81d66cf3 821
7c0ea335 822 return m_frameToolBar;
81d66cf3
JS
823}
824
bfc6fde4 825void wxFrame::PositionToolBar()
81d66cf3 826{
81d66cf3 827 RECT rect;
42e69d6b 828 ::GetClientRect(GetHwnd(), &rect);
81d66cf3 829
7c0ea335 830#if wxUSE_STATUSBAR
81d66cf3
JS
831 if ( GetStatusBar() )
832 {
7c0ea335
VZ
833 int statusX, statusY;
834 GetStatusBar()->GetClientSize(&statusX, &statusY);
835 rect.bottom -= statusY;
81d66cf3 836 }
7c0ea335 837#endif // wxUSE_STATUSBAR
81d66cf3 838
a2327a9f 839 if ( GetToolBar() && GetToolBar()->IsShown() )
81d66cf3
JS
840 {
841 int tw, th;
7c0ea335 842 GetToolBar()->GetSize(&tw, &th);
81d66cf3 843
7c0ea335 844 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL )
81d66cf3 845 {
7c0ea335 846 th = rect.bottom;
81d66cf3
JS
847 }
848 else
849 {
7c0ea335 850 tw = rect.right;
81d66cf3 851 }
7c0ea335
VZ
852
853 // Use the 'real' MSW position here
854 GetToolBar()->SetSize(0, 0, tw, th, wxSIZE_NO_ADJUSTMENTS);
81d66cf3
JS
855 }
856}
d427503c 857#endif // wxUSE_TOOLBAR
d2aef312 858
7c0ea335
VZ
859// ----------------------------------------------------------------------------
860// frame state (iconized/maximized/...)
861// ----------------------------------------------------------------------------
862
a23fd0e1
VZ
863// propagate our state change to all child frames: this allows us to emulate X
864// Windows behaviour where child frames float independently of the parent one
865// on the desktop, but are iconized/restored with it
d2aef312
VZ
866void wxFrame::IconizeChildFrames(bool bIconize)
867{
a23fd0e1
VZ
868 for ( wxWindowList::Node *node = GetChildren().GetFirst();
869 node;
870 node = node->GetNext() )
871 {
872 wxWindow *win = node->GetData();
873
3ca6a5f0
BP
874 // iconizing the frames with this style under Win95 shell puts them at
875 // the bottom of the screen (as the MDI children) instead of making
876 // them appear in the taskbar because they are, by virtue of this
877 // style, not managed by the taskbar - instead leave Windows take care
878 // of them
879#ifdef __WIN95__
880 if ( win->GetWindowStyle() & wxFRAME_TOOL_WINDOW )
881 continue;
882#endif // Win95
883
3f7bc32b
VZ
884 // the child MDI frames are a special case and should not be touched by
885 // the parent frame - instead, they are managed by the user
886 wxFrame *frame = wxDynamicCast(win, wxFrame);
91dd52fe 887 if ( frame && !frame->IsMDIChild() )
a23fd0e1 888 {
3f7bc32b 889 frame->Iconize(bIconize);
a23fd0e1 890 }
d2aef312 891 }
d2aef312
VZ
892}
893
a23fd0e1 894// ===========================================================================
42e69d6b 895// message processing
a23fd0e1
VZ
896// ===========================================================================
897
42e69d6b
VZ
898// ---------------------------------------------------------------------------
899// preprocessing
900// ---------------------------------------------------------------------------
901
902bool wxFrame::MSWTranslateMessage(WXMSG* pMsg)
903{
904 if ( wxWindow::MSWTranslateMessage(pMsg) )
905 return TRUE;
906
907 // try the menu bar accels
908 wxMenuBar *menuBar = GetMenuBar();
909 if ( !menuBar )
910 return FALSE;
911
912 const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable();
c50f1fb9 913 return acceleratorTable.Translate(this, pMsg);
42e69d6b
VZ
914}
915
916// ---------------------------------------------------------------------------
917// our private (non virtual) message handlers
918// ---------------------------------------------------------------------------
919
920bool wxFrame::HandlePaint()
921{
922 RECT rect;
923 if ( GetUpdateRect(GetHwnd(), &rect, FALSE) )
924 {
925 if ( m_iconized )
926 {
c50f1fb9 927 HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon)
42e69d6b
VZ
928 : (HICON)m_defaultIcon;
929
930 // Hold a pointer to the dc so long as the OnPaint() message
931 // is being processed
932 PAINTSTRUCT ps;
933 HDC hdc = ::BeginPaint(GetHwnd(), &ps);
934
935 // Erase background before painting or we get white background
936 MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L);
937
938 if ( hIcon )
939 {
940 RECT rect;
941 ::GetClientRect(GetHwnd(), &rect);
942
943 // FIXME: why hardcoded?
944 static const int icon_width = 32;
945 static const int icon_height = 32;
946
947 int icon_x = (int)((rect.right - icon_width)/2);
948 int icon_y = (int)((rect.bottom - icon_height)/2);
949
950 ::DrawIcon(hdc, icon_x, icon_y, hIcon);
951 }
952
953 ::EndPaint(GetHwnd(), &ps);
954
955 return TRUE;
956 }
957 else
958 {
5d1d2d46 959 return wxWindow::HandlePaint();
42e69d6b
VZ
960 }
961 }
962 else
963 {
964 // nothing to paint - processed
965 return TRUE;
966 }
967}
968
969bool wxFrame::HandleSize(int x, int y, WXUINT id)
970{
971 bool processed = FALSE;
972
973 switch ( id )
974 {
975 case SIZENORMAL:
976 // only do it it if we were iconized before, otherwise resizing the
977 // parent frame has a curious side effect of bringing it under it's
978 // children
979 if ( !m_iconized )
980 break;
981
982 // restore all child frames too
983 IconizeChildFrames(FALSE);
984
985 // fall through
986
987 case SIZEFULLSCREEN:
988 m_iconized = FALSE;
989 break;
990
991 case SIZEICONIC:
992 // iconize all child frames too
993 IconizeChildFrames(TRUE);
994
995 m_iconized = TRUE;
996 break;
997 }
998
999 if ( !m_iconized )
1000 {
42e69d6b
VZ
1001 PositionStatusBar();
1002 PositionToolBar();
1003
1004 wxSizeEvent event(wxSize(x, y), m_windowId);
1005 event.SetEventObject( this );
1006 processed = GetEventHandler()->ProcessEvent(event);
1007 }
1008
1009 return processed;
1010}
1011
1012bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
1013{
1014 if ( control )
1015 {
1016 // In case it's e.g. a toolbar.
1017 wxWindow *win = wxFindWinFromHandle(control);
1018 if ( win )
1019 return win->MSWCommand(cmd, id);
1020 }
1021
1022 // handle here commands from menus and accelerators
1023 if ( cmd == 0 || cmd == 1 )
1024 {
1025 if ( wxCurrentPopupMenu )
1026 {
1027 wxMenu *popupMenu = wxCurrentPopupMenu;
1028 wxCurrentPopupMenu = NULL;
1029
1030 return popupMenu->MSWCommand(cmd, id);
1031 }
1032
1033 if ( ProcessCommand(id) )
1034 {
1035 return TRUE;
1036 }
1037 }
1038
1039 return FALSE;
1040}
1041
c219cecc 1042bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu)
a23fd0e1
VZ
1043{
1044 int item;
c219cecc 1045 if ( flags == 0xFFFF && hMenu == 0 )
a23fd0e1 1046 {
c219cecc 1047 // menu was removed from screen
a23fd0e1
VZ
1048 item = -1;
1049 }
c219cecc 1050 else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) )
a23fd0e1
VZ
1051 {
1052 item = nItem;
1053 }
1054 else
1055 {
c219cecc 1056 // don't give hints for separators (doesn't make sense) nor for the
f6bcfd97
BP
1057 // items opening popup menus (they don't have them anyhow) but do clear
1058 // the status line - otherwise, we would be left with the help message
1059 // for the previous item which doesn't apply any more
1060 wxStatusBar *statbar = GetStatusBar();
1061 if ( statbar )
1062 {
1063 statbar->SetStatusText(wxEmptyString);
1064 }
1065
a23fd0e1
VZ
1066 return FALSE;
1067 }
1068
1069 wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item);
1070 event.SetEventObject( this );
1071
1072 return GetEventHandler()->ProcessEvent(event);
1073}
1074
1075// ---------------------------------------------------------------------------
1076// the window proc for wxFrame
1077// ---------------------------------------------------------------------------
1078
1079long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
1080{
1081 long rc = 0;
1082 bool processed = FALSE;
1083
1084 switch ( message )
1085 {
42e69d6b
VZ
1086 case WM_CLOSE:
1087 // if we can't close, tell the system that we processed the
1088 // message - otherwise it would close us
1089 processed = !Close();
1090 break;
1091
1092 case WM_COMMAND:
1093 {
1094 WORD id, cmd;
1095 WXHWND hwnd;
1096 UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam,
1097 &id, &hwnd, &cmd);
1098
1099 processed = HandleCommand(id, cmd, (WXHWND)hwnd);
1100 }
1101 break;
1102
a23fd0e1
VZ
1103 case WM_MENUSELECT:
1104 {
42e69d6b
VZ
1105 WXWORD item, flags;
1106 WXHMENU hmenu;
1107 UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu);
1108
1109 processed = HandleMenuSelect(item, flags, hmenu);
a23fd0e1
VZ
1110 }
1111 break;
42e69d6b
VZ
1112
1113 case WM_PAINT:
1114 processed = HandlePaint();
1115 break;
1116
1117 case WM_QUERYDRAGICON:
1118 {
c50f1fb9 1119 HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon)
42e69d6b
VZ
1120 : (HICON)(m_defaultIcon);
1121 rc = (long)hIcon;
1122 processed = rc != 0;
1123 }
1124 break;
1125
1126 case WM_SIZE:
1127 processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam);
1128 break;
a23fd0e1
VZ
1129 }
1130
1131 if ( !processed )
1132 rc = wxWindow::MSWWindowProc(message, wParam, lParam);
1133
1134 return rc;
1135}
21802234 1136