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