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