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