]> git.saurik.com Git - wxWidgets.git/blame - src/msw/frame.cpp
Added wxCheckLitBox (oh well)
[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
47d67540 43#if wxUSE_NATIVE_STATUSBAR
2bda0e17
KB
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
47d67540 65#if wxUSE_NATIVE_STATUSBAR
2bda0e17
KB
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;
d2aef312
VZ
115
116 // we pass NULL as parent to MSWCreate because frames with parents behave
117 // very strangely under Win95 shell
118 MSWCreate(m_windowId, NULL, wxFrameClassName, this, title,
119 x, y, width, height, style);
2bda0e17
KB
120
121 wxModelessWindows.Append(this);
122 return TRUE;
123}
124
125wxFrame::~wxFrame(void)
126{
127 m_isBeingDeleted = TRUE;
128 wxTopLevelWindows.DeleteObject(this);
129
130 if (m_frameStatusBar)
131 delete m_frameStatusBar;
132 if (m_frameMenuBar)
133 delete m_frameMenuBar;
134
135/* New behaviour March 1998: check if it's the last top-level window */
136// if (wxTheApp && (this == wxTheApp->GetTopWindow()))
137
138 if (wxTheApp && (wxTopLevelWindows.Number() == 0))
139 {
140 wxTheApp->SetTopWindow(NULL);
141
142 if (wxTheApp->GetExitOnFrameDelete())
143 {
144 PostQuitMessage(0);
145 }
146 }
147
148 wxModelessWindows.DeleteObject(this);
149
150 // For some reason, wxWindows can activate another task altogether
151 // when a frame is destroyed after a modal dialog has been invoked.
152 // Try to bring the parent to the top.
153 if (GetParent() && GetParent()->GetHWND())
154 ::BringWindowToTop((HWND) GetParent()->GetHWND());
155}
156
157WXHMENU wxFrame::GetWinMenu(void) const
158{
159 return m_hMenu;
160}
161
81d66cf3 162// Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
2bda0e17
KB
163void wxFrame::GetClientSize(int *x, int *y) const
164{
165 RECT rect;
166 GetClientRect((HWND) GetHWND(), &rect);
167
81d66cf3 168 if ( GetStatusBar() )
2bda0e17 169 {
81d66cf3
JS
170 int statusX, statusY;
171 GetStatusBar()->GetClientSize(&statusX, &statusY);
172 rect.bottom -= statusY;
2bda0e17 173 }
81d66cf3
JS
174
175 wxPoint pt(GetClientAreaOrigin());
176 rect.bottom -= pt.y;
177 rect.right -= pt.x;
178
2bda0e17
KB
179 *x = rect.right;
180 *y = rect.bottom;
181}
182
183// Set the client size (i.e. leave the calculation of borders etc.
184// to wxWindows)
debe6624 185void wxFrame::SetClientSize(int width, int height)
2bda0e17
KB
186{
187 HWND hWnd = (HWND) GetHWND();
188
189 RECT rect;
190 GetClientRect(hWnd, &rect);
191
192 RECT rect2;
193 GetWindowRect(hWnd, &rect2);
194
195 // Find the difference between the entire window (title bar and all)
196 // and the client area; add this to the new client size to move the
197 // window
198 int actual_width = rect2.right - rect2.left - rect.right + width;
199 int actual_height = rect2.bottom - rect2.top - rect.bottom + height;
200
81d66cf3 201 if ( GetStatusBar() )
2bda0e17 202 {
81d66cf3
JS
203 int statusX, statusY;
204 GetStatusBar()->GetClientSize(&statusX, &statusY);
205 actual_height += statusY;
2bda0e17
KB
206 }
207
81d66cf3
JS
208 wxPoint pt(GetClientAreaOrigin());
209 actual_width += pt.y;
210 actual_height += pt.x;
211
2bda0e17
KB
212 POINT point;
213 point.x = rect2.left;
214 point.y = rect2.top;
215
216 MoveWindow(hWnd, point.x, point.y, actual_width, actual_height, (BOOL)TRUE);
debe6624 217
2bda0e17
KB
218 wxSizeEvent event(wxSize(width, height), m_windowId);
219 event.SetEventObject( this );
220 GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
221}
222
223void wxFrame::GetSize(int *width, int *height) const
224{
225 RECT rect;
226 GetWindowRect((HWND) GetHWND(), &rect);
227 *width = rect.right - rect.left;
228 *height = rect.bottom - rect.top;
229}
230
231void wxFrame::GetPosition(int *x, int *y) const
232{
233 RECT rect;
234 GetWindowRect((HWND) GetHWND(), &rect);
235 POINT point;
236 point.x = rect.left;
237 point.y = rect.top;
238
239 *x = point.x;
240 *y = point.y;
241}
242
debe6624 243void wxFrame::SetSize(int x, int y, int width, int height, int sizeFlags)
2bda0e17
KB
244{
245 int currentX, currentY;
246 int x1 = x;
247 int y1 = y;
248 int w1 = width;
249 int h1 = height;
250
251 GetPosition(&currentX, &currentY);
252 if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
253 x1 = currentX;
254 if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
255 y1 = currentY;
256
257 int ww,hh ;
258 GetSize(&ww,&hh) ;
259 if (width == -1) w1 = ww ;
260 if (height==-1) h1 = hh ;
261
262 MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, (BOOL)TRUE);
263
2bda0e17
KB
264 wxSizeEvent event(wxSize(width, height), m_windowId);
265 event.SetEventObject( this );
266 GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
267}
268
debe6624 269bool wxFrame::Show(bool show)
2bda0e17
KB
270{
271 int cshow;
272 if (show)
273 cshow = SW_SHOW;
274 else
275 cshow = SW_HIDE;
276
277 if (!show)
278 {
279 // Try to highlight the correct window (the parent)
280 HWND hWndParent = 0;
281 if (GetParent())
282 {
283 hWndParent = (HWND) GetParent()->GetHWND();
284 if (hWndParent)
285 ::BringWindowToTop(hWndParent);
286 }
287 }
288
289 ShowWindow((HWND) GetHWND(), (BOOL)cshow);
290 if (show)
291 {
292 BringWindowToTop((HWND) GetHWND());
293
2bda0e17
KB
294 wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_windowId);
295 event.SetEventObject( this );
296 GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
297 }
298 return TRUE;
299}
300
debe6624 301void wxFrame::Iconize(bool iconize)
2bda0e17
KB
302{
303 if (!iconize)
304 Show(TRUE);
305
306 int cshow;
307 if (iconize)
308 cshow = SW_MINIMIZE;
309 else
310 cshow = SW_RESTORE;
311 ShowWindow((HWND) GetHWND(), (BOOL)cshow);
312 m_iconized = iconize;
313}
314
315// Equivalent to maximize/restore in Windows
debe6624 316void wxFrame::Maximize(bool maximize)
2bda0e17
KB
317{
318 Show(TRUE);
319 int cshow;
320 if (maximize)
321 cshow = SW_MAXIMIZE;
322 else
323 cshow = SW_RESTORE;
324 ShowWindow((HWND) GetHWND(), cshow);
325 m_iconized = FALSE;
326}
327
328bool wxFrame::IsIconized(void) const
329{
330 ((wxFrame *)this)->m_iconized = (::IsIconic((HWND) GetHWND()) != 0);
331 return m_iconized;
332}
333
334void wxFrame::SetTitle(const wxString& title)
335{
336 SetWindowText((HWND) GetHWND(), (const char *)title);
337}
338
339wxString wxFrame::GetTitle(void) const
340{
341 GetWindowText((HWND) GetHWND(), wxBuffer, 1000);
342 return wxString(wxBuffer);
343}
344
345void wxFrame::SetIcon(const wxIcon& icon)
346{
347 m_icon = icon;
348#if defined(__WIN95__)
349 if ( m_icon.Ok() )
350 SendMessage((HWND) GetHWND(), WM_SETICON,
351 (WPARAM)TRUE, (LPARAM)(HICON) m_icon.GetHICON());
352#endif
353}
354
81d66cf3
JS
355wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id,
356 const wxString& name)
2bda0e17
KB
357{
358 wxStatusBar *statusBar = NULL;
359
47d67540 360#if wxUSE_NATIVE_STATUSBAR
2bda0e17
KB
361 if (UsesNativeStatusBar())
362 {
81d66cf3 363 statusBar = new wxStatusBar95(this, id, style);
2bda0e17
KB
364 }
365 else
366#endif
367 {
81d66cf3
JS
368 statusBar = new wxStatusBar(this, id, wxPoint(0, 0), wxSize(100, 20),
369 style, name);
2bda0e17
KB
370
371 // Set the height according to the font and the border size
372 wxClientDC dc(statusBar);
c0ed460c 373 dc.SetFont(statusBar->GetFont());
2bda0e17
KB
374
375 long x, y;
376 dc.GetTextExtent("X", &x, &y);
377
378 int height = (int)( (y * 1.1) + 2* statusBar->GetBorderY());
379
380 statusBar->SetSize(-1, -1, 100, height);
381 }
382
383 statusBar->SetFieldsCount(number);
384 return statusBar;
385}
386
81d66cf3
JS
387wxStatusBar* wxFrame::CreateStatusBar(int number, long style, wxWindowID id,
388 const wxString& name)
2bda0e17
KB
389{
390 // VZ: calling CreateStatusBar twice is an error - why anyone would do it?
1311c7a9
VZ
391 wxCHECK_MSG( m_frameStatusBar == NULL, FALSE,
392 "recreating status bar in wxFrame" );
2bda0e17 393
81d66cf3
JS
394 m_frameStatusBar = OnCreateStatusBar(number, style, id,
395 name);
2bda0e17
KB
396 if ( m_frameStatusBar )
397 {
398 PositionStatusBar();
81d66cf3 399 return m_frameStatusBar;
2bda0e17
KB
400 }
401 else
81d66cf3 402 return NULL;
2bda0e17
KB
403}
404
debe6624 405void wxFrame::SetStatusText(const wxString& text, int number)
2bda0e17 406{
1311c7a9 407 wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set text for" );
2bda0e17
KB
408
409 m_frameStatusBar->SetStatusText(text, number);
410}
411
8b9518ee 412void wxFrame::SetStatusWidths(int n, const int widths_field[])
2bda0e17 413{
1311c7a9 414 wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set widths for" );
2bda0e17
KB
415
416 m_frameStatusBar->SetStatusWidths(n, widths_field);
417 PositionStatusBar();
418}
419
420void wxFrame::PositionStatusBar(void)
421{
422 // native status bar positions itself
423 if (m_frameStatusBar
47d67540 424#if wxUSE_NATIVE_STATUSBAR
2bda0e17
KB
425 && !m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95))
426#endif
427 )
428 {
429 int w, h;
430 GetClientSize(&w, &h);
431 int sw, sh;
432 m_frameStatusBar->GetSize(&sw, &sh);
81d66cf3
JS
433
434 // Since we wish the status bar to be directly under the client area,
435 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
2bda0e17
KB
436 m_frameStatusBar->SetSize(0, h, w, sh);
437 }
438}
439
440void wxFrame::SetMenuBar(wxMenuBar *menu_bar)
441{
442 if (!menu_bar)
443 {
444 m_frameMenuBar = NULL;
445 return;
446 }
447
448 if (menu_bar->m_menuBarFrame)
449 return;
450
451 int i;
452 HMENU menu = CreateMenu();
453
454 for (i = 0; i < menu_bar->m_menuCount; i ++)
455 {
456 HMENU popup = (HMENU)menu_bar->m_menus[i]->m_hMenu;
457 //
458 // After looking Bounds Checker result, it seems that all
459 // menus must be individually destroyed. So, don't reset m_hMenu,
460 // to allow ~wxMenu to do the job.
461 //
462 menu_bar->m_menus[i]->m_savehMenu = (WXHMENU) popup;
463 // Uncommenting for the moment... JACS
464 menu_bar->m_menus[i]->m_hMenu = 0;
465 AppendMenu(menu, MF_POPUP | MF_STRING, (UINT)popup, menu_bar->m_titles[i]);
466 }
467
468 menu_bar->m_hMenu = (WXHMENU)menu;
469 if (m_frameMenuBar)
470 delete m_frameMenuBar;
471
472 this->m_hMenu = (WXHMENU) menu;
473
474 DWORD err = 0;
475 if (!SetMenu((HWND) GetHWND(), menu))
476 {
477#ifdef __WIN32__
478 err = GetLastError();
479#endif
480 }
481
482 m_frameMenuBar = menu_bar;
483 menu_bar->m_menuBarFrame = this;
484}
485
57a7b7c1 486#if 0
2bda0e17
KB
487bool wxFrame::LoadAccelerators(const wxString& table)
488{
489 m_acceleratorTable = (WXHANDLE)
490#ifdef __WIN32__
491#ifdef UNICODE
492 ::LoadAcceleratorsW(wxGetInstance(), (const char *)table);
493#else
494 ::LoadAcceleratorsA(wxGetInstance(), (const char *)table);
495#endif
496#else
497 ::LoadAccelerators(wxGetInstance(), (const char *)table);
498#endif
499
500 // The above is necessary because LoadAccelerators is a macro
501 // which we have undefed earlier in the file to avoid confusion
502 // with wxFrame::LoadAccelerators. Ugh!
503
504 return (m_acceleratorTable != (WXHANDLE) NULL);
505}
57a7b7c1 506#endif
2bda0e17
KB
507
508void wxFrame::Fit(void)
509{
510 // Work out max. size
c0ed460c 511 wxNode *node = GetChildren().First();
2bda0e17
KB
512 int max_width = 0;
513 int max_height = 0;
514 while (node)
515 {
516 // Find a child that's a subwindow, but not a dialog box.
517 wxWindow *win = (wxWindow *)node->Data();
518
519 if (!win->IsKindOf(CLASSINFO(wxFrame)) &&
520 !win->IsKindOf(CLASSINFO(wxDialog)))
521 {
522 int width, height;
523 int x, y;
524 win->GetSize(&width, &height);
525 win->GetPosition(&x, &y);
526
527 if ((x + width) > max_width)
528 max_width = x + width;
529 if ((y + height) > max_height)
530 max_height = y + height;
531 }
532 node = node->Next();
533 }
534 SetClientSize(max_width, max_height);
535}
536
537// Responds to colour changes, and passes event on to children.
538void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
539{
540 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
541 Refresh();
542
543 if ( m_frameStatusBar )
544 {
545 wxSysColourChangedEvent event2;
546 event2.SetEventObject( m_frameStatusBar );
02800301 547 m_frameStatusBar->GetEventHandler()->ProcessEvent(event2);
2bda0e17
KB
548 }
549
550 // Propagate the event to the non-top-level children
551 wxWindow::OnSysColourChanged(event);
552}
553
554/*
555 * Frame window
556 *
557 */
558
debe6624
JS
559void wxFrame::MSWCreate(int id, wxWindow *parent, const char *wclass, wxWindow *wx_win, const char *title,
560 int x, int y, int width, int height, long style)
2bda0e17
KB
561
562{
563 m_defaultIcon = (WXHICON) (wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON : wxDEFAULT_FRAME_ICON);
564
565 // If child windows aren't properly drawn initially, WS_CLIPCHILDREN
566 // could be the culprit. But without it, you can get a lot of flicker.
567
2bda0e17
KB
568 DWORD msflags = 0;
569 if ((style & wxCAPTION) == wxCAPTION)
1c089c47 570 msflags = WS_OVERLAPPED;
2bda0e17 571 else
1c089c47 572 msflags = WS_POPUP;
2bda0e17
KB
573
574 if (style & wxMINIMIZE_BOX)
575 msflags |= WS_MINIMIZEBOX;
576 if (style & wxMAXIMIZE_BOX)
577 msflags |= WS_MAXIMIZEBOX;
578 if (style & wxTHICK_FRAME)
579 msflags |= WS_THICKFRAME;
580 if (style & wxSYSTEM_MENU)
581 msflags |= WS_SYSMENU;
582 if ((style & wxMINIMIZE) || (style & wxICONIZE))
583 msflags |= WS_MINIMIZE;
584 if (style & wxMAXIMIZE)
585 msflags |= WS_MAXIMIZE;
586 if (style & wxCAPTION)
587 msflags |= WS_CAPTION;
1c089c47
JS
588 if (style & wxCLIP_CHILDREN)
589 msflags |= WS_CLIPCHILDREN;
2bda0e17
KB
590
591 // Keep this in wxFrame because it saves recoding this function
592 // in wxTinyFrame
47d67540 593#if wxUSE_ITSY_BITSY
2bda0e17
KB
594 if (style & wxTINY_CAPTION_VERT)
595 msflags |= IBS_VERTCAPTION;
596 if (style & wxTINY_CAPTION_HORIZ)
597 msflags |= IBS_HORZCAPTION;
598#else
599 if (style & wxTINY_CAPTION_VERT)
600 msflags |= WS_CAPTION;
601 if (style & wxTINY_CAPTION_HORIZ)
602 msflags |= WS_CAPTION;
603#endif
604 if ((style & wxTHICK_FRAME) == 0)
605 msflags |= WS_BORDER;
606
607 WXDWORD extendedStyle = MakeExtendedStyle(style);
608
609 if (style & wxSTAY_ON_TOP)
610 extendedStyle |= WS_EX_TOPMOST;
611
612 m_iconized = FALSE;
613 wxWindow::MSWCreate(id, parent, wclass, wx_win, title, x, y, width, height,
614 msflags, NULL, extendedStyle);
615 // Seems to be necessary if we use WS_POPUP
616 // style instead of WS_OVERLAPPED
617 if (width > -1 && height > -1)
618 ::PostMessage((HWND) GetHWND(), WM_SIZE, SIZE_RESTORED, MAKELPARAM(width, height));
619}
620
621bool wxFrame::MSWOnPaint(void)
622{
2bda0e17
KB
623 RECT rect;
624 if (GetUpdateRect((HWND) GetHWND(), &rect, FALSE))
625 {
626 if (m_iconized)
627 {
628 HICON the_icon;
fd3f686c
VZ
629 if (m_icon.Ok())
630 the_icon = (HICON) m_icon.GetHICON();
631 else
2bda0e17
KB
632 the_icon = (HICON) m_defaultIcon;
633
634 PAINTSTRUCT ps;
635 // Hold a pointer to the dc so long as the OnPaint() message
636 // is being processed
637 HDC cdc = BeginPaint((HWND) GetHWND(), &ps);
638
639 // Erase background before painting or we get white background
640 this->MSWDefWindowProc(WM_ICONERASEBKGND,(WORD)ps.hdc,0L);
641
642 if (the_icon)
643 {
644 RECT rect;
645 GetClientRect((HWND) GetHWND(), &rect);
646 int icon_width = 32;
647 int icon_height = 32;
648 int icon_x = (int)((rect.right - icon_width)/2);
649 int icon_y = (int)((rect.bottom - icon_height)/2);
650 DrawIcon(cdc, icon_x, icon_y, the_icon);
651 }
652
653 EndPaint((HWND) GetHWND(), &ps);
654 }
1c089c47 655 else
2bda0e17 656 {
debe6624
JS
657 wxPaintEvent event(m_windowId);
658 event.m_eventObject = this;
659 if (!GetEventHandler()->ProcessEvent(event))
660 Default();
2bda0e17
KB
661 }
662 return 0;
663 }
664 return 1;
665}
666
667WXHICON wxFrame::MSWOnQueryDragIcon(void)
668{
669 if (m_icon.Ok() && (m_icon.GetHICON() != 0))
670 return m_icon.GetHICON();
671 else
672 return m_defaultIcon;
673}
674
debe6624 675void wxFrame::MSWOnSize(int x, int y, WXUINT id)
2bda0e17 676{
2bda0e17
KB
677 switch (id)
678 {
2bda0e17 679 case SIZENORMAL:
18453306
VZ
680 // only do it it if we were iconized before, otherwise resizing the
681 // parent frame has a curious side effect of bringing it under it's
682 // children
683 if ( !m_iconized )
684 break;
685
d2aef312
VZ
686 // restore all child frames too
687 IconizeChildFrames(FALSE);
688
689 // fall through
690
691 case SIZEFULLSCREEN:
2bda0e17 692 m_iconized = FALSE;
18453306 693 break;
d2aef312 694
2bda0e17 695 case SIZEICONIC:
d2aef312
VZ
696 // iconize all child frames too
697 IconizeChildFrames(TRUE);
698
2bda0e17 699 m_iconized = TRUE;
18453306 700 break;
2bda0e17
KB
701 }
702
703 if (!m_iconized)
704 {
705 // forward WM_SIZE to status bar control
47d67540 706#if wxUSE_NATIVE_STATUSBAR
2bda0e17
KB
707 if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)))
708 {
709 wxSizeEvent event(wxSize(x, y), m_frameStatusBar->GetId());
710 event.SetEventObject( m_frameStatusBar );
711
712 ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event);
713 }
714#endif
715
716 PositionStatusBar();
81d66cf3
JS
717 PositionToolBar();
718
2bda0e17
KB
719 wxSizeEvent event(wxSize(x, y), m_windowId);
720 event.SetEventObject( this );
debe6624
JS
721 if (!GetEventHandler()->ProcessEvent(event))
722 Default();
2bda0e17
KB
723 }
724}
725
726bool wxFrame::MSWOnClose(void)
727{
2bda0e17
KB
728 return Close();
729}
730
debe6624 731bool wxFrame::MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control)
2bda0e17 732{
2bda0e17
KB
733 if (cmd == 0 || cmd == 1 ) // Can be either a menu command or an accelerator.
734 {
735 // In case it's e.g. a toolbar.
736 wxWindow *win = wxFindWinFromHandle(control);
737 if (win)
738 return win->MSWCommand(cmd, id);
739
e1a6fc11
JS
740 if (wxCurrentPopupMenu)
741 {
742 wxMenu *popupMenu = wxCurrentPopupMenu;
743 wxCurrentPopupMenu = NULL;
744 if (popupMenu->MSWCommand(cmd, id))
745 return TRUE;
746 }
747
2bda0e17
KB
748 if (GetMenuBar() && GetMenuBar()->FindItemForId(id))
749 {
750 ProcessCommand(id);
751 return TRUE;
752 }
753 else
754 return FALSE;
755 }
756 else
757 return FALSE;
758}
759
debe6624 760void wxFrame::MSWOnMenuHighlight(WXWORD nItem, WXWORD nFlags, WXHMENU hSysMenu)
2bda0e17 761{
2bda0e17
KB
762 if (nFlags == 0xFFFF && hSysMenu == 0)
763 {
764 wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, -1);
765 event.SetEventObject( this );
766 GetEventHandler()->ProcessEvent(event);
767 }
768 else if (nFlags != MF_SEPARATOR)
769 {
770 wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, nItem);
771 event.SetEventObject( this );
772 GetEventHandler()->ProcessEvent(event);
773 }
2bda0e17
KB
774}
775
776bool wxFrame::MSWProcessMessage(WXMSG* pMsg)
777{
57a7b7c1
JS
778 return FALSE;
779}
780
781bool wxFrame::MSWTranslateMessage(WXMSG* pMsg)
782{
783 if (m_acceleratorTable.Ok() &&
784 ::TranslateAccelerator((HWND) GetHWND(), (HACCEL) m_acceleratorTable.GetHACCEL(), (MSG *)pMsg))
2bda0e17
KB
785 return TRUE;
786
787 return FALSE;
788}
789
790// Default resizing behaviour - if only ONE subwindow,
791// resize to client rectangle size
792void wxFrame::OnSize(wxSizeEvent& event)
793{
cd70477b 794 // if we're using constraints - do use them
47d67540 795 #if wxUSE_CONSTRAINTS
cd70477b
VZ
796 if ( GetAutoLayout() ) {
797 Layout();
798 return;
799 }
800 #endif
801
802 // do we have _exactly_ one child?
2bda0e17 803 wxWindow *child = NULL;
c0ed460c 804 for ( wxNode *node = GetChildren().First(); node; node = node->Next() )
2bda0e17
KB
805 {
806 wxWindow *win = (wxWindow *)node->Data();
cd70477b
VZ
807 if ( !win->IsKindOf(CLASSINFO(wxFrame)) &&
808 !win->IsKindOf(CLASSINFO(wxDialog)) &&
73e7daa0
JS
809 (win != GetStatusBar()) &&
810 (win != GetToolBar()) )
2bda0e17 811 {
cd70477b
VZ
812 if ( child )
813 return; // it's our second subwindow - nothing to do
2bda0e17 814 child = win;
2bda0e17
KB
815 }
816 }
817
cd70477b
VZ
818 if ( child ) {
819 // we have exactly one child - set it's size to fill the whole frame
73e7daa0
JS
820 int clientW, clientH;
821 GetClientSize(&clientW, &clientH);
2bda0e17 822
73e7daa0
JS
823 int x = 0;
824 int y = 0;
825
73e7daa0 826 child->SetSize(x, y, clientW, clientH);
2bda0e17 827 }
2bda0e17
KB
828}
829
830// Default activation behaviour - set the focus for the first child
831// subwindow found.
832void wxFrame::OnActivate(wxActivateEvent& event)
833{
c0ed460c 834 for(wxNode *node = GetChildren().First(); node; node = node->Next())
2bda0e17
KB
835 {
836 // Find a child that's a subwindow, but not a dialog box.
837 wxWindow *child = (wxWindow *)node->Data();
838 if (!child->IsKindOf(CLASSINFO(wxFrame)) &&
839 !child->IsKindOf(CLASSINFO(wxDialog)))
840 {
2bda0e17
KB
841 child->SetFocus();
842 return;
843 }
844 }
845}
846
847// The default implementation for the close window event - calls
848// OnClose for backward compatibility.
849
850void wxFrame::OnCloseWindow(wxCloseEvent& event)
851{
852 // Compatibility
853 if ( GetEventHandler()->OnClose() || event.GetForce())
854 {
855 this->Destroy();
856 }
387a3b02
JS
857 else
858 event.Veto(TRUE);
2bda0e17
KB
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{
f5419957 923 wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, id);
2bda0e17
KB
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
87d1e11f
JS
960void wxFrame::ScreenToClient(int *x, int *y) const
961{
962 wxWindow::ScreenToClient(x, y);
963
964 // We may be faking the client origin.
965 // So a window that's really at (0, 30) may appear
966 // (to wxWin apps) to be at (0, 0).
967 wxPoint pt(GetClientAreaOrigin());
968 *x -= pt.x;
969 *y -= pt.y;
970}
971
972void wxFrame::ClientToScreen(int *x, int *y) const
973{
974 // We may be faking the client origin.
975 // So a window that's really at (0, 30) may appear
976 // (to wxWin apps) to be at (0, 0).
977 wxPoint pt1(GetClientAreaOrigin());
978 *x += pt1.x;
979 *y += pt1.y;
980
981 wxWindow::ClientToScreen(x, y);
982}
983
81d66cf3
JS
984wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
985{
986 wxCHECK_MSG( m_frameToolBar == NULL, FALSE,
987 "recreating toolbar in wxFrame" );
988
989 wxToolBar* toolBar = OnCreateToolBar(style, id, name);
990 if (toolBar)
991 {
992 SetToolBar(toolBar);
993 PositionToolBar();
994 return toolBar;
995 }
996 else
997 {
998 return NULL;
999 }
1000}
1001
1002wxToolBar* wxFrame::OnCreateToolBar(long style, wxWindowID id, const wxString& name)
1003{
1004 return new wxToolBar(this, id, wxDefaultPosition, wxDefaultSize, style, name);
1005}
1006
1007void wxFrame::PositionToolBar(void)
1008{
81d66cf3
JS
1009 RECT rect;
1010 ::GetClientRect((HWND) GetHWND(), &rect);
1011
1012 if ( GetStatusBar() )
1013 {
1014 int statusX, statusY;
1015 GetStatusBar()->GetClientSize(&statusX, &statusY);
1016 rect.bottom -= statusY;
1017 }
1018
1019 if (GetToolBar())
1020 {
1021 int tw, th;
1022 GetToolBar()->GetSize(& tw, & th);
1023
1024 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
1025 {
1026 // Use the 'real' MSW position
1027 GetToolBar()->SetSize(0, 0, tw, rect.bottom, wxSIZE_NO_ADJUSTMENTS);
1028 }
1029 else
1030 {
1031 // Use the 'real' MSW position
1032 GetToolBar()->SetSize(0, 0, rect.right, th, wxSIZE_NO_ADJUSTMENTS);
1033 }
1034 }
1035}
d2aef312
VZ
1036
1037// propagate our state change to all child frames
1038void wxFrame::IconizeChildFrames(bool bIconize)
1039{
c0ed460c 1040 for ( wxNode *node = GetChildren().First(); node; node = node->Next() ) {
d2aef312
VZ
1041 wxWindow *win = (wxWindow *)node->Data();
1042 if ( win->IsKindOf(CLASSINFO(wxFrame)) ) {
1043 ((wxFrame *)win)->Iconize(bIconize);
1044 }
1045 }
1046}
1047