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