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