]> git.saurik.com Git - wxWidgets.git/blame - src/msw/frame.cpp
VZ: I removed (CASTWNDPROC) from ::CallWndProc - it doesn't compile here with it
[wxWidgets.git] / src / msw / frame.cpp
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: frame.cpp
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
12#ifdef __GNUG__
13#pragma implementation "frame.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24#include "wx/setup.h"
25#include "wx/frame.h"
26#include "wx/menu.h"
27#include "wx/app.h"
28#include "wx/utils.h"
29#include "wx/dialog.h"
30#include "wx/settings.h"
31#include "wx/dcclient.h"
32#endif
33
34#include "wx/msw/private.h"
35#include "wx/statusbr.h"
81d66cf3 36#include "wx/toolbar.h"
2bda0e17
KB
37#include "wx/menuitem.h"
38
39#ifdef LoadAccelerators
40#undef LoadAccelerators
41#endif
42
43#if USE_NATIVE_STATUSBAR
44#include <wx/msw/statbr95.h>
45#endif
46
47extern wxList wxModelessWindows;
48extern wxList wxPendingDelete;
49extern char wxFrameClassName[];
e1a6fc11 50extern wxMenu *wxCurrentPopupMenu;
2bda0e17
KB
51
52#if !USE_SHARED_LIBRARY
53BEGIN_EVENT_TABLE(wxFrame, wxWindow)
54 EVT_SIZE(wxFrame::OnSize)
55 EVT_ACTIVATE(wxFrame::OnActivate)
56 EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight)
57 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
58 EVT_IDLE(wxFrame::OnIdle)
59 EVT_CLOSE(wxFrame::OnCloseWindow)
60END_EVENT_TABLE()
61
62IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow)
63#endif
64
65#if USE_NATIVE_STATUSBAR
66bool wxFrame::m_useNativeStatusBar = TRUE;
67#else
68bool wxFrame::m_useNativeStatusBar = FALSE;
69#endif
70
71wxFrame::wxFrame(void)
72{
73e7daa0 73 m_frameToolBar = NULL ;
2bda0e17
KB
74 m_frameMenuBar = NULL;
75 m_frameStatusBar = NULL;
76
77 m_windowParent = NULL;
78 m_iconized = FALSE;
79}
80
81bool wxFrame::Create(wxWindow *parent,
debe6624 82 wxWindowID id,
2bda0e17
KB
83 const wxString& title,
84 const wxPoint& pos,
85 const wxSize& size,
debe6624 86 long style,
2bda0e17
KB
87 const wxString& name)
88{
89 if (!parent)
90 wxTopLevelWindows.Append(this);
91
92 SetName(name);
93// m_modalShowing = FALSE;
94 m_windowStyle = style;
95 m_frameMenuBar = NULL;
73e7daa0 96 m_frameToolBar = NULL ;
2bda0e17
KB
97 m_frameStatusBar = NULL;
98
99 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
100
101// m_icon = NULL;
102 if ( id > -1 )
103 m_windowId = id;
104 else
105 m_windowId = (int)NewControlId();
106
107 if (parent) parent->AddChild(this);
108
109 int x = pos.x;
110 int y = pos.y;
111 int width = size.x;
112 int height = size.y;
113
114 m_iconized = FALSE;
115 MSWCreate(m_windowId, (wxWindow *)parent, wxFrameClassName, this, (char *)(const char *)title,
116 x, y, width, height, style);
117
118 wxModelessWindows.Append(this);
119 return TRUE;
120}
121
122wxFrame::~wxFrame(void)
123{
124 m_isBeingDeleted = TRUE;
125 wxTopLevelWindows.DeleteObject(this);
126
127 if (m_frameStatusBar)
128 delete m_frameStatusBar;
129 if (m_frameMenuBar)
130 delete m_frameMenuBar;
131
132/* New behaviour March 1998: check if it's the last top-level window */
133// if (wxTheApp && (this == wxTheApp->GetTopWindow()))
134
135 if (wxTheApp && (wxTopLevelWindows.Number() == 0))
136 {
137 wxTheApp->SetTopWindow(NULL);
138
139 if (wxTheApp->GetExitOnFrameDelete())
140 {
141 PostQuitMessage(0);
142 }
143 }
144
145 wxModelessWindows.DeleteObject(this);
146
147 // For some reason, wxWindows can activate another task altogether
148 // when a frame is destroyed after a modal dialog has been invoked.
149 // Try to bring the parent to the top.
150 if (GetParent() && GetParent()->GetHWND())
151 ::BringWindowToTop((HWND) GetParent()->GetHWND());
152}
153
154WXHMENU wxFrame::GetWinMenu(void) const
155{
156 return m_hMenu;
157}
158
81d66cf3 159// Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
2bda0e17
KB
160void wxFrame::GetClientSize(int *x, int *y) const
161{
162 RECT rect;
163 GetClientRect((HWND) GetHWND(), &rect);
164
81d66cf3 165 if ( GetStatusBar() )
2bda0e17 166 {
81d66cf3
JS
167 int statusX, statusY;
168 GetStatusBar()->GetClientSize(&statusX, &statusY);
169 rect.bottom -= statusY;
2bda0e17 170 }
81d66cf3
JS
171
172 wxPoint pt(GetClientAreaOrigin());
173 rect.bottom -= pt.y;
174 rect.right -= pt.x;
175
2bda0e17
KB
176 *x = rect.right;
177 *y = rect.bottom;
178}
179
180// Set the client size (i.e. leave the calculation of borders etc.
181// to wxWindows)
debe6624 182void wxFrame::SetClientSize(int width, int height)
2bda0e17
KB
183{
184 HWND hWnd = (HWND) GetHWND();
185
186 RECT rect;
187 GetClientRect(hWnd, &rect);
188
189 RECT rect2;
190 GetWindowRect(hWnd, &rect2);
191
192 // Find the difference between the entire window (title bar and all)
193 // and the client area; add this to the new client size to move the
194 // window
195 int actual_width = rect2.right - rect2.left - rect.right + width;
196 int actual_height = rect2.bottom - rect2.top - rect.bottom + height;
197
81d66cf3 198 if ( GetStatusBar() )
2bda0e17 199 {
81d66cf3
JS
200 int statusX, statusY;
201 GetStatusBar()->GetClientSize(&statusX, &statusY);
202 actual_height += statusY;
2bda0e17
KB
203 }
204
81d66cf3
JS
205 wxPoint pt(GetClientAreaOrigin());
206 actual_width += pt.y;
207 actual_height += pt.x;
208
2bda0e17
KB
209 POINT point;
210 point.x = rect2.left;
211 point.y = rect2.top;
212
213 MoveWindow(hWnd, point.x, point.y, actual_width, actual_height, (BOOL)TRUE);
debe6624 214
2bda0e17
KB
215 wxSizeEvent event(wxSize(width, height), m_windowId);
216 event.SetEventObject( this );
217 GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
218}
219
220void wxFrame::GetSize(int *width, int *height) const
221{
222 RECT rect;
223 GetWindowRect((HWND) GetHWND(), &rect);
224 *width = rect.right - rect.left;
225 *height = rect.bottom - rect.top;
226}
227
228void wxFrame::GetPosition(int *x, int *y) const
229{
230 RECT rect;
231 GetWindowRect((HWND) GetHWND(), &rect);
232 POINT point;
233 point.x = rect.left;
234 point.y = rect.top;
235
236 *x = point.x;
237 *y = point.y;
238}
239
debe6624 240void wxFrame::SetSize(int x, int y, int width, int height, int sizeFlags)
2bda0e17
KB
241{
242 int currentX, currentY;
243 int x1 = x;
244 int y1 = y;
245 int w1 = width;
246 int h1 = height;
247
248 GetPosition(&currentX, &currentY);
249 if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
250 x1 = currentX;
251 if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
252 y1 = currentY;
253
254 int ww,hh ;
255 GetSize(&ww,&hh) ;
256 if (width == -1) w1 = ww ;
257 if (height==-1) h1 = hh ;
258
259 MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, (BOOL)TRUE);
260
2bda0e17
KB
261 wxSizeEvent event(wxSize(width, height), m_windowId);
262 event.SetEventObject( this );
263 GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
264}
265
debe6624 266bool wxFrame::Show(bool show)
2bda0e17
KB
267{
268 int cshow;
269 if (show)
270 cshow = SW_SHOW;
271 else
272 cshow = SW_HIDE;
273
274 if (!show)
275 {
276 // Try to highlight the correct window (the parent)
277 HWND hWndParent = 0;
278 if (GetParent())
279 {
280 hWndParent = (HWND) GetParent()->GetHWND();
281 if (hWndParent)
282 ::BringWindowToTop(hWndParent);
283 }
284 }
285
286 ShowWindow((HWND) GetHWND(), (BOOL)cshow);
287 if (show)
288 {
289 BringWindowToTop((HWND) GetHWND());
290
2bda0e17
KB
291 wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_windowId);
292 event.SetEventObject( this );
293 GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
294 }
295 return TRUE;
296}
297
debe6624 298void wxFrame::Iconize(bool iconize)
2bda0e17
KB
299{
300 if (!iconize)
301 Show(TRUE);
302
303 int cshow;
304 if (iconize)
305 cshow = SW_MINIMIZE;
306 else
307 cshow = SW_RESTORE;
308 ShowWindow((HWND) GetHWND(), (BOOL)cshow);
309 m_iconized = iconize;
310}
311
312// Equivalent to maximize/restore in Windows
debe6624 313void wxFrame::Maximize(bool maximize)
2bda0e17
KB
314{
315 Show(TRUE);
316 int cshow;
317 if (maximize)
318 cshow = SW_MAXIMIZE;
319 else
320 cshow = SW_RESTORE;
321 ShowWindow((HWND) GetHWND(), cshow);
322 m_iconized = FALSE;
323}
324
325bool wxFrame::IsIconized(void) const
326{
327 ((wxFrame *)this)->m_iconized = (::IsIconic((HWND) GetHWND()) != 0);
328 return m_iconized;
329}
330
331void wxFrame::SetTitle(const wxString& title)
332{
333 SetWindowText((HWND) GetHWND(), (const char *)title);
334}
335
336wxString wxFrame::GetTitle(void) const
337{
338 GetWindowText((HWND) GetHWND(), wxBuffer, 1000);
339 return wxString(wxBuffer);
340}
341
342void wxFrame::SetIcon(const wxIcon& icon)
343{
344 m_icon = icon;
345#if defined(__WIN95__)
346 if ( m_icon.Ok() )
347 SendMessage((HWND) GetHWND(), WM_SETICON,
348 (WPARAM)TRUE, (LPARAM)(HICON) m_icon.GetHICON());
349#endif
350}
351
57a7b7c1
JS
352void wxFrame::SetAcceleratorTable(const wxAcceleratorTable& accel)
353{
354 m_acceleratorTable = accel;
355}
356
81d66cf3
JS
357wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id,
358 const wxString& name)
2bda0e17
KB
359{
360 wxStatusBar *statusBar = NULL;
361
362#if USE_NATIVE_STATUSBAR
363 if (UsesNativeStatusBar())
364 {
81d66cf3 365 statusBar = new wxStatusBar95(this, id, style);
2bda0e17
KB
366 }
367 else
368#endif
369 {
81d66cf3
JS
370 statusBar = new wxStatusBar(this, id, wxPoint(0, 0), wxSize(100, 20),
371 style, name);
2bda0e17
KB
372
373 // Set the height according to the font and the border size
374 wxClientDC dc(statusBar);
375 dc.SetFont(* statusBar->GetFont());
376
377 long x, y;
378 dc.GetTextExtent("X", &x, &y);
379
380 int height = (int)( (y * 1.1) + 2* statusBar->GetBorderY());
381
382 statusBar->SetSize(-1, -1, 100, height);
383 }
384
385 statusBar->SetFieldsCount(number);
386 return statusBar;
387}
388
81d66cf3
JS
389wxStatusBar* wxFrame::CreateStatusBar(int number, long style, wxWindowID id,
390 const wxString& name)
2bda0e17
KB
391{
392 // VZ: calling CreateStatusBar twice is an error - why anyone would do it?
1311c7a9
VZ
393 wxCHECK_MSG( m_frameStatusBar == NULL, FALSE,
394 "recreating status bar in wxFrame" );
2bda0e17 395
81d66cf3
JS
396 m_frameStatusBar = OnCreateStatusBar(number, style, id,
397 name);
2bda0e17
KB
398 if ( m_frameStatusBar )
399 {
400 PositionStatusBar();
81d66cf3 401 return m_frameStatusBar;
2bda0e17
KB
402 }
403 else
81d66cf3 404 return NULL;
2bda0e17
KB
405}
406
debe6624 407void wxFrame::SetStatusText(const wxString& text, int number)
2bda0e17 408{
1311c7a9 409 wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set text for" );
2bda0e17
KB
410
411 m_frameStatusBar->SetStatusText(text, number);
412}
413
8b9518ee 414void wxFrame::SetStatusWidths(int n, const int widths_field[])
2bda0e17 415{
1311c7a9 416 wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set widths for" );
2bda0e17
KB
417
418 m_frameStatusBar->SetStatusWidths(n, widths_field);
419 PositionStatusBar();
420}
421
422void wxFrame::PositionStatusBar(void)
423{
424 // native status bar positions itself
425 if (m_frameStatusBar
426#if USE_NATIVE_STATUSBAR
427 && !m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95))
428#endif
429 )
430 {
431 int w, h;
432 GetClientSize(&w, &h);
433 int sw, sh;
434 m_frameStatusBar->GetSize(&sw, &sh);
81d66cf3
JS
435
436 // Since we wish the status bar to be directly under the client area,
437 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
2bda0e17
KB
438 m_frameStatusBar->SetSize(0, h, w, sh);
439 }
440}
441
442void wxFrame::SetMenuBar(wxMenuBar *menu_bar)
443{
444 if (!menu_bar)
445 {
446 m_frameMenuBar = NULL;
447 return;
448 }
449
450 if (menu_bar->m_menuBarFrame)
451 return;
452
453 int i;
454 HMENU menu = CreateMenu();
455
456 for (i = 0; i < menu_bar->m_menuCount; i ++)
457 {
458 HMENU popup = (HMENU)menu_bar->m_menus[i]->m_hMenu;
459 //
460 // After looking Bounds Checker result, it seems that all
461 // menus must be individually destroyed. So, don't reset m_hMenu,
462 // to allow ~wxMenu to do the job.
463 //
464 menu_bar->m_menus[i]->m_savehMenu = (WXHMENU) popup;
465 // Uncommenting for the moment... JACS
466 menu_bar->m_menus[i]->m_hMenu = 0;
467 AppendMenu(menu, MF_POPUP | MF_STRING, (UINT)popup, menu_bar->m_titles[i]);
468 }
469
470 menu_bar->m_hMenu = (WXHMENU)menu;
471 if (m_frameMenuBar)
472 delete m_frameMenuBar;
473
474 this->m_hMenu = (WXHMENU) menu;
475
476 DWORD err = 0;
477 if (!SetMenu((HWND) GetHWND(), menu))
478 {
479#ifdef __WIN32__
480 err = GetLastError();
481#endif
482 }
483
484 m_frameMenuBar = menu_bar;
485 menu_bar->m_menuBarFrame = this;
486}
487
57a7b7c1 488#if 0
2bda0e17
KB
489bool wxFrame::LoadAccelerators(const wxString& table)
490{
491 m_acceleratorTable = (WXHANDLE)
492#ifdef __WIN32__
493#ifdef UNICODE
494 ::LoadAcceleratorsW(wxGetInstance(), (const char *)table);
495#else
496 ::LoadAcceleratorsA(wxGetInstance(), (const char *)table);
497#endif
498#else
499 ::LoadAccelerators(wxGetInstance(), (const char *)table);
500#endif
501
502 // The above is necessary because LoadAccelerators is a macro
503 // which we have undefed earlier in the file to avoid confusion
504 // with wxFrame::LoadAccelerators. Ugh!
505
506 return (m_acceleratorTable != (WXHANDLE) NULL);
507}
57a7b7c1 508#endif
2bda0e17
KB
509
510void wxFrame::Fit(void)
511{
512 // Work out max. size
513 wxNode *node = GetChildren()->First();
514 int max_width = 0;
515 int max_height = 0;
516 while (node)
517 {
518 // Find a child that's a subwindow, but not a dialog box.
519 wxWindow *win = (wxWindow *)node->Data();
520
521 if (!win->IsKindOf(CLASSINFO(wxFrame)) &&
522 !win->IsKindOf(CLASSINFO(wxDialog)))
523 {
524 int width, height;
525 int x, y;
526 win->GetSize(&width, &height);
527 win->GetPosition(&x, &y);
528
529 if ((x + width) > max_width)
530 max_width = x + width;
531 if ((y + height) > max_height)
532 max_height = y + height;
533 }
534 node = node->Next();
535 }
536 SetClientSize(max_width, max_height);
537}
538
539// Responds to colour changes, and passes event on to children.
540void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
541{
542 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
543 Refresh();
544
545 if ( m_frameStatusBar )
546 {
547 wxSysColourChangedEvent event2;
548 event2.SetEventObject( m_frameStatusBar );
549 m_frameStatusBar->ProcessEvent(event2);
550 }
551
552 // Propagate the event to the non-top-level children
553 wxWindow::OnSysColourChanged(event);
554}
555
556/*
557 * Frame window
558 *
559 */
560
debe6624
JS
561void wxFrame::MSWCreate(int id, wxWindow *parent, const char *wclass, wxWindow *wx_win, const char *title,
562 int x, int y, int width, int height, long style)
2bda0e17
KB
563
564{
565 m_defaultIcon = (WXHICON) (wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON : wxDEFAULT_FRAME_ICON);
566
567 // If child windows aren't properly drawn initially, WS_CLIPCHILDREN
568 // could be the culprit. But without it, you can get a lot of flicker.
569
2bda0e17
KB
570 DWORD msflags = 0;
571 if ((style & wxCAPTION) == wxCAPTION)
1c089c47 572 msflags = WS_OVERLAPPED;
2bda0e17 573 else
1c089c47 574 msflags = WS_POPUP;
2bda0e17
KB
575
576 if (style & wxMINIMIZE_BOX)
577 msflags |= WS_MINIMIZEBOX;
578 if (style & wxMAXIMIZE_BOX)
579 msflags |= WS_MAXIMIZEBOX;
580 if (style & wxTHICK_FRAME)
581 msflags |= WS_THICKFRAME;
582 if (style & wxSYSTEM_MENU)
583 msflags |= WS_SYSMENU;
584 if ((style & wxMINIMIZE) || (style & wxICONIZE))
585 msflags |= WS_MINIMIZE;
586 if (style & wxMAXIMIZE)
587 msflags |= WS_MAXIMIZE;
588 if (style & wxCAPTION)
589 msflags |= WS_CAPTION;
1c089c47
JS
590 if (style & wxCLIP_CHILDREN)
591 msflags |= WS_CLIPCHILDREN;
2bda0e17
KB
592
593 // Keep this in wxFrame because it saves recoding this function
594 // in wxTinyFrame
595#if USE_ITSY_BITSY
596 if (style & wxTINY_CAPTION_VERT)
597 msflags |= IBS_VERTCAPTION;
598 if (style & wxTINY_CAPTION_HORIZ)
599 msflags |= IBS_HORZCAPTION;
600#else
601 if (style & wxTINY_CAPTION_VERT)
602 msflags |= WS_CAPTION;
603 if (style & wxTINY_CAPTION_HORIZ)
604 msflags |= WS_CAPTION;
605#endif
606 if ((style & wxTHICK_FRAME) == 0)
607 msflags |= WS_BORDER;
608
609 WXDWORD extendedStyle = MakeExtendedStyle(style);
610
611 if (style & wxSTAY_ON_TOP)
612 extendedStyle |= WS_EX_TOPMOST;
613
614 m_iconized = FALSE;
615 wxWindow::MSWCreate(id, parent, wclass, wx_win, title, x, y, width, height,
616 msflags, NULL, extendedStyle);
617 // Seems to be necessary if we use WS_POPUP
618 // style instead of WS_OVERLAPPED
619 if (width > -1 && height > -1)
620 ::PostMessage((HWND) GetHWND(), WM_SIZE, SIZE_RESTORED, MAKELPARAM(width, height));
621}
622
623bool wxFrame::MSWOnPaint(void)
624{
b2aef89b 625#if WXDEBUG > 1
2bda0e17
KB
626 wxDebugMsg("wxFrameWnd::OnPaint %d\n", handle);
627#endif
628 RECT rect;
629 if (GetUpdateRect((HWND) GetHWND(), &rect, FALSE))
630 {
631 if (m_iconized)
632 {
633 HICON the_icon;
634 if (m_icon.Ok())
635 the_icon = (HICON) m_icon.GetHICON();
636 if (the_icon == 0)
637 the_icon = (HICON) m_defaultIcon;
638
639 PAINTSTRUCT ps;
640 // Hold a pointer to the dc so long as the OnPaint() message
641 // is being processed
642 HDC cdc = BeginPaint((HWND) GetHWND(), &ps);
643
644 // Erase background before painting or we get white background
645 this->MSWDefWindowProc(WM_ICONERASEBKGND,(WORD)ps.hdc,0L);
646
647 if (the_icon)
648 {
649 RECT rect;
650 GetClientRect((HWND) GetHWND(), &rect);
651 int icon_width = 32;
652 int icon_height = 32;
653 int icon_x = (int)((rect.right - icon_width)/2);
654 int icon_y = (int)((rect.bottom - icon_height)/2);
655 DrawIcon(cdc, icon_x, icon_y, the_icon);
656 }
657
658 EndPaint((HWND) GetHWND(), &ps);
659 }
1c089c47 660 else
2bda0e17 661 {
debe6624
JS
662 wxPaintEvent event(m_windowId);
663 event.m_eventObject = this;
664 if (!GetEventHandler()->ProcessEvent(event))
665 Default();
2bda0e17
KB
666 }
667 return 0;
668 }
669 return 1;
670}
671
672WXHICON wxFrame::MSWOnQueryDragIcon(void)
673{
674 if (m_icon.Ok() && (m_icon.GetHICON() != 0))
675 return m_icon.GetHICON();
676 else
677 return m_defaultIcon;
678}
679
debe6624 680void wxFrame::MSWOnSize(int x, int y, WXUINT id)
2bda0e17 681{
b2aef89b 682#if WXDEBUG > 1
2bda0e17
KB
683 wxDebugMsg("wxFrameWnd::OnSize %d\n", m_hWnd);
684#endif
685 switch (id)
686 {
687 case SIZEFULLSCREEN:
688 case SIZENORMAL:
689 m_iconized = FALSE;
690 break;
691 case SIZEICONIC:
692 m_iconized = TRUE;
693 break;
694 }
695
696 if (!m_iconized)
697 {
698 // forward WM_SIZE to status bar control
699#if USE_NATIVE_STATUSBAR
700 if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)))
701 {
702 wxSizeEvent event(wxSize(x, y), m_frameStatusBar->GetId());
703 event.SetEventObject( m_frameStatusBar );
704
705 ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event);
706 }
707#endif
708
709 PositionStatusBar();
81d66cf3
JS
710 PositionToolBar();
711
2bda0e17
KB
712 wxSizeEvent event(wxSize(x, y), m_windowId);
713 event.SetEventObject( this );
debe6624
JS
714 if (!GetEventHandler()->ProcessEvent(event))
715 Default();
2bda0e17
KB
716 }
717}
718
719bool wxFrame::MSWOnClose(void)
720{
b2aef89b 721#if WXDEBUG > 1
2bda0e17
KB
722 wxDebugMsg("wxFrameWnd::OnClose %d\n", handle);
723#endif
724 return Close();
725}
726
debe6624 727bool wxFrame::MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control)
2bda0e17 728{
b2aef89b 729#if WXDEBUG > 1
2bda0e17
KB
730 wxDebugMsg("wxFrameWnd::OnCommand %d\n", handle);
731#endif
732 if (cmd == 0 || cmd == 1 ) // Can be either a menu command or an accelerator.
733 {
734 // In case it's e.g. a toolbar.
735 wxWindow *win = wxFindWinFromHandle(control);
736 if (win)
737 return win->MSWCommand(cmd, id);
738
e1a6fc11
JS
739 if (wxCurrentPopupMenu)
740 {
741 wxMenu *popupMenu = wxCurrentPopupMenu;
742 wxCurrentPopupMenu = NULL;
743 if (popupMenu->MSWCommand(cmd, id))
744 return TRUE;
745 }
746
2bda0e17
KB
747 if (GetMenuBar() && GetMenuBar()->FindItemForId(id))
748 {
749 ProcessCommand(id);
750 return TRUE;
751 }
752 else
753 return FALSE;
754 }
755 else
756 return FALSE;
757}
758
debe6624 759void wxFrame::MSWOnMenuHighlight(WXWORD nItem, WXWORD nFlags, WXHMENU hSysMenu)
2bda0e17 760{
2bda0e17
KB
761 if (nFlags == 0xFFFF && hSysMenu == 0)
762 {
763 wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, -1);
764 event.SetEventObject( this );
765 GetEventHandler()->ProcessEvent(event);
766 }
767 else if (nFlags != MF_SEPARATOR)
768 {
769 wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, nItem);
770 event.SetEventObject( this );
771 GetEventHandler()->ProcessEvent(event);
772 }
2bda0e17
KB
773}
774
775bool wxFrame::MSWProcessMessage(WXMSG* pMsg)
776{
57a7b7c1
JS
777 return FALSE;
778}
779
780bool wxFrame::MSWTranslateMessage(WXMSG* pMsg)
781{
782 if (m_acceleratorTable.Ok() &&
783 ::TranslateAccelerator((HWND) GetHWND(), (HACCEL) m_acceleratorTable.GetHACCEL(), (MSG *)pMsg))
2bda0e17
KB
784 return TRUE;
785
786 return FALSE;
787}
788
789// Default resizing behaviour - if only ONE subwindow,
790// resize to client rectangle size
791void wxFrame::OnSize(wxSizeEvent& event)
792{
cd70477b
VZ
793 // if we're using constraints - do use them
794 #if USE_CONSTRAINTS
795 if ( GetAutoLayout() ) {
796 Layout();
797 return;
798 }
799 #endif
800
801 // do we have _exactly_ one child?
2bda0e17 802 wxWindow *child = NULL;
cd70477b 803 for ( wxNode *node = GetChildren()->First(); node; node = node->Next() )
2bda0e17
KB
804 {
805 wxWindow *win = (wxWindow *)node->Data();
cd70477b
VZ
806 if ( !win->IsKindOf(CLASSINFO(wxFrame)) &&
807 !win->IsKindOf(CLASSINFO(wxDialog)) &&
73e7daa0
JS
808 (win != GetStatusBar()) &&
809 (win != GetToolBar()) )
2bda0e17 810 {
cd70477b
VZ
811 if ( child )
812 return; // it's our second subwindow - nothing to do
2bda0e17 813 child = win;
2bda0e17
KB
814 }
815 }
816
cd70477b
VZ
817 if ( child ) {
818 // we have exactly one child - set it's size to fill the whole frame
73e7daa0
JS
819 int clientW, clientH;
820 GetClientSize(&clientW, &clientH);
2bda0e17 821
73e7daa0
JS
822 int x = 0;
823 int y = 0;
824
73e7daa0 825 child->SetSize(x, y, clientW, clientH);
2bda0e17 826 }
2bda0e17
KB
827}
828
829// Default activation behaviour - set the focus for the first child
830// subwindow found.
831void wxFrame::OnActivate(wxActivateEvent& event)
832{
833 for(wxNode *node = GetChildren()->First(); node; node = node->Next())
834 {
835 // Find a child that's a subwindow, but not a dialog box.
836 wxWindow *child = (wxWindow *)node->Data();
837 if (!child->IsKindOf(CLASSINFO(wxFrame)) &&
838 !child->IsKindOf(CLASSINFO(wxDialog)))
839 {
b2aef89b 840#if WXDEBUG > 1
2bda0e17
KB
841 wxDebugMsg("wxFrame::OnActivate: about to set the child's focus.\n");
842#endif
843 child->SetFocus();
844 return;
845 }
846 }
847}
848
849// The default implementation for the close window event - calls
850// OnClose for backward compatibility.
851
852void wxFrame::OnCloseWindow(wxCloseEvent& event)
853{
854 // Compatibility
855 if ( GetEventHandler()->OnClose() || event.GetForce())
856 {
857 this->Destroy();
858 }
859}
860
47fa7969
JS
861bool wxFrame::OnClose(void)
862{
863 return TRUE;
864}
865
2bda0e17
KB
866// Destroy the window (delayed, if a managed window)
867bool wxFrame::Destroy(void)
868{
869 if (!wxPendingDelete.Member(this))
870 wxPendingDelete.Append(this);
871 return TRUE;
872}
873
874// Default menu selection behaviour - display a help string
875void wxFrame::OnMenuHighlight(wxMenuEvent& event)
876{
877 if (GetStatusBar())
878 {
879 if (event.GetMenuId() == -1)
880 SetStatusText("");
881 else
882 {
883 wxMenuBar *menuBar = GetMenuBar();
884 if (menuBar)
885 {
886 wxString helpString(menuBar->GetHelpString(event.GetMenuId()));
887 if (helpString != "")
888 SetStatusText(helpString);
889 }
890 }
891 }
892}
893
2bda0e17
KB
894wxMenuBar *wxFrame::GetMenuBar(void) const
895{
896 return m_frameMenuBar;
897}
898
debe6624 899void wxFrame::Centre(int direction)
2bda0e17
KB
900{
901 int display_width, display_height, width, height, x, y;
902 wxDisplaySize(&display_width, &display_height);
903
904 GetSize(&width, &height);
905 GetPosition(&x, &y);
906
907 if (direction & wxHORIZONTAL)
908 x = (int)((display_width - width)/2);
909 if (direction & wxVERTICAL)
910 y = (int)((display_height - height)/2);
911
912 SetSize(x, y, width, height);
913}
914
915// Call this to simulate a menu command
916void wxFrame::Command(int id)
917{
918 ProcessCommand(id);
919}
920
921void wxFrame::ProcessCommand(int id)
922{
923 wxCommandEvent commandEvent(wxEVENT_TYPE_MENU_COMMAND, id);
924 commandEvent.SetInt( id );
925 commandEvent.SetEventObject( this );
926
927 wxMenuBar *bar = GetMenuBar() ;
928 if (!bar)
929 return;
930
2bda0e17
KB
931 wxMenuItem *item = bar->FindItemForId(id) ;
932 if (item && item->IsCheckable())
933 {
2bda0e17
KB
934 bar->Check(id,!bar->Checked(id)) ;
935 }
debe6624 936 GetEventHandler()->ProcessEvent(commandEvent);
2bda0e17
KB
937}
938
81d66cf3
JS
939// Checks if there is a toolbar, and returns the first free client position
940wxPoint wxFrame::GetClientAreaOrigin() const
941{
942 wxPoint pt(0, 0);
943 if (GetToolBar())
944 {
945 int w, h;
946 GetToolBar()->GetSize(& w, & h);
947
948 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
949 {
950 pt.x += w;
951 }
952 else
953 {
954 pt.y += h;
955 }
956 }
957 return pt;
958}
959
960wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
961{
962 wxCHECK_MSG( m_frameToolBar == NULL, FALSE,
963 "recreating toolbar in wxFrame" );
964
965 wxToolBar* toolBar = OnCreateToolBar(style, id, name);
966 if (toolBar)
967 {
968 SetToolBar(toolBar);
969 PositionToolBar();
970 return toolBar;
971 }
972 else
973 {
974 return NULL;
975 }
976}
977
978wxToolBar* wxFrame::OnCreateToolBar(long style, wxWindowID id, const wxString& name)
979{
980 return new wxToolBar(this, id, wxDefaultPosition, wxDefaultSize, style, name);
981}
982
983void wxFrame::PositionToolBar(void)
984{
985 int cw, ch;
986
987 RECT rect;
988 ::GetClientRect((HWND) GetHWND(), &rect);
989
990 if ( GetStatusBar() )
991 {
992 int statusX, statusY;
993 GetStatusBar()->GetClientSize(&statusX, &statusY);
994 rect.bottom -= statusY;
995 }
996
997 if (GetToolBar())
998 {
999 int tw, th;
1000 GetToolBar()->GetSize(& tw, & th);
1001
1002 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
1003 {
1004 // Use the 'real' MSW position
1005 GetToolBar()->SetSize(0, 0, tw, rect.bottom, wxSIZE_NO_ADJUSTMENTS);
1006 }
1007 else
1008 {
1009 // Use the 'real' MSW position
1010 GetToolBar()->SetSize(0, 0, rect.right, th, wxSIZE_NO_ADJUSTMENTS);
1011 }
1012 }
1013}