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