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