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