]> git.saurik.com Git - wxWidgets.git/blob - src/msw/frame.cpp
Removed #pragmas in utils.cpp, corrected USE_(WX)DEBUG_CONTEXT,
[wxWidgets.git] / src / msw / frame.cpp
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
46 extern wxList wxModelessWindows;
47 extern wxList wxPendingDelete;
48 extern char wxFrameClassName[];
49
50 #if !USE_SHARED_LIBRARY
51 BEGIN_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)
58 END_EVENT_TABLE()
59
60 IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow)
61 #endif
62
63 #if USE_NATIVE_STATUSBAR
64 bool wxFrame::m_useNativeStatusBar = TRUE;
65 #else
66 bool wxFrame::m_useNativeStatusBar = FALSE;
67 #endif
68
69 wxFrame::wxFrame(void)
70 {
71 m_frameMenuBar = NULL;
72 m_frameStatusBar = NULL;
73
74 m_windowParent = NULL;
75 m_iconized = FALSE;
76 }
77
78 bool wxFrame::Create(wxWindow *parent,
79 wxWindowID id,
80 const wxString& title,
81 const wxPoint& pos,
82 const wxSize& size,
83 long style,
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
118 wxFrame::~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
150 WXHMENU 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
157 void 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)
174 void wxFrame::SetClientSize(int width, int height)
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);
202
203 wxSizeEvent event(wxSize(width, height), m_windowId);
204 event.SetEventObject( this );
205 GetEventHandler()->ProcessEvent(event);
206 }
207
208 void 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
216 void 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
228 void wxFrame::SetSize(int x, int y, int width, int height, int sizeFlags)
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
249 wxSizeEvent event(wxSize(width, height), m_windowId);
250 event.SetEventObject( this );
251 GetEventHandler()->ProcessEvent(event);
252 }
253
254 bool wxFrame::Show(bool show)
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
279 wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_windowId);
280 event.SetEventObject( this );
281 GetEventHandler()->ProcessEvent(event);
282 }
283 return TRUE;
284 }
285
286 void wxFrame::Iconize(bool iconize)
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
301 void wxFrame::Maximize(bool maximize)
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
313 bool wxFrame::IsIconized(void) const
314 {
315 ((wxFrame *)this)->m_iconized = (::IsIconic((HWND) GetHWND()) != 0);
316 return m_iconized;
317 }
318
319 void wxFrame::SetTitle(const wxString& title)
320 {
321 SetWindowText((HWND) GetHWND(), (const char *)title);
322 }
323
324 wxString wxFrame::GetTitle(void) const
325 {
326 GetWindowText((HWND) GetHWND(), wxBuffer, 1000);
327 return wxString(wxBuffer);
328 }
329
330 void 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
340 wxStatusBar *wxFrame::OnCreateStatusBar(int number)
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
370 bool wxFrame::CreateStatusBar(int number)
371 {
372 // VZ: calling CreateStatusBar twice is an error - why anyone would do it?
373 wxCHECK_MSG( m_frameStatusBar == NULL, FALSE,
374 "recreating status bar in wxFrame" );
375
376 m_frameStatusBar = OnCreateStatusBar(number);
377 if ( m_frameStatusBar )
378 {
379 PositionStatusBar();
380 return TRUE;
381 }
382 else
383 return FALSE;
384 }
385
386 void wxFrame::SetStatusText(const wxString& text, int number)
387 {
388 wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set text for" );
389
390 m_frameStatusBar->SetStatusText(text, number);
391 }
392
393 void wxFrame::SetStatusWidths(int n, const int widths_field[])
394 {
395 wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set widths for" );
396
397 m_frameStatusBar->SetStatusWidths(n, widths_field);
398 PositionStatusBar();
399 }
400
401 void 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
418 void 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
464 bool 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
484 void 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.
514 void 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
535 void 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)
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
544 DWORD msflags = 0;
545 if ((style & wxCAPTION) == wxCAPTION)
546 msflags = WS_OVERLAPPED;
547 else
548 msflags = WS_POPUP;
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;
564 if (style & wxCLIP_CHILDREN)
565 msflags |= WS_CLIPCHILDREN;
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
597 bool wxFrame::MSWOnPaint(void)
598 {
599 #if WXDEBUG > 1
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 }
634 else
635 {
636 wxPaintEvent event(m_windowId);
637 event.m_eventObject = this;
638 if (!GetEventHandler()->ProcessEvent(event))
639 Default();
640 }
641 return 0;
642 }
643 return 1;
644 }
645
646 WXHICON 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
654 void wxFrame::MSWOnSize(int x, int y, WXUINT id)
655 {
656 #if WXDEBUG > 1
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();
684 wxSizeEvent event(wxSize(x, y), m_windowId);
685 event.SetEventObject( this );
686 if (!GetEventHandler()->ProcessEvent(event))
687 Default();
688 }
689 }
690
691 bool wxFrame::MSWOnClose(void)
692 {
693 #if WXDEBUG > 1
694 wxDebugMsg("wxFrameWnd::OnClose %d\n", handle);
695 #endif
696 return Close();
697 }
698
699 bool wxFrame::MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control)
700 {
701 #if WXDEBUG > 1
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
723 void wxFrame::MSWOnMenuHighlight(WXWORD nItem, WXWORD nFlags, WXHMENU hSysMenu)
724 {
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 }
737 }
738
739 bool wxFrame::MSWProcessMessage(WXMSG* pMsg)
740 {
741 if (m_acceleratorTable != 0 &&
742 ::TranslateAccelerator((HWND) GetHWND(), (HANDLE) m_acceleratorTable, (MSG *)pMsg))
743 return TRUE;
744
745 return FALSE;
746 }
747
748 // Default resizing behaviour - if only ONE subwindow,
749 // resize to client rectangle size
750 void wxFrame::OnSize(wxSizeEvent& event)
751 {
752 // Search for a child which is a subwindow, not another frame.
753 wxWindow *child = NULL;
754 // Count the number of _subwindow_ children
755 int noChildren = 0;
756 for(wxNode *node = GetChildren()->First(); node; node = node->Next())
757 {
758 wxWindow *win = (wxWindow *)node->Data();
759 if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog))
760 && (win != GetStatusBar()))
761 {
762 child = win;
763 noChildren ++;
764 }
765 }
766
767 // If not one child, call the Layout function if compiled in
768 if (!child || (noChildren > 1)
769 #if USE_CONSTRAINTS
770 || GetAutoLayout()
771 #endif
772 )
773 {
774 #if USE_CONSTRAINTS
775 if (GetAutoLayout())
776 Layout();
777 #endif
778 return;
779 }
780
781 if (child)
782 {
783 int client_x, client_y;
784
785 #if WXDEBUG > 1
786 wxDebugMsg("wxFrame::OnSize: about to set the child's size.\n");
787 #endif
788
789 GetClientSize(&client_x, &client_y);
790 child->SetSize(0, 0, client_x, client_y);
791 }
792
793 }
794
795 // Default activation behaviour - set the focus for the first child
796 // subwindow found.
797 void wxFrame::OnActivate(wxActivateEvent& event)
798 {
799 for(wxNode *node = GetChildren()->First(); node; node = node->Next())
800 {
801 // Find a child that's a subwindow, but not a dialog box.
802 wxWindow *child = (wxWindow *)node->Data();
803 if (!child->IsKindOf(CLASSINFO(wxFrame)) &&
804 !child->IsKindOf(CLASSINFO(wxDialog)))
805 {
806 #if WXDEBUG > 1
807 wxDebugMsg("wxFrame::OnActivate: about to set the child's focus.\n");
808 #endif
809 child->SetFocus();
810 return;
811 }
812 }
813 }
814
815 // The default implementation for the close window event - calls
816 // OnClose for backward compatibility.
817
818 void wxFrame::OnCloseWindow(wxCloseEvent& event)
819 {
820 // Compatibility
821 if ( GetEventHandler()->OnClose() || event.GetForce())
822 {
823 this->Destroy();
824 }
825 }
826
827 // Destroy the window (delayed, if a managed window)
828 bool wxFrame::Destroy(void)
829 {
830 if (!wxPendingDelete.Member(this))
831 wxPendingDelete.Append(this);
832 return TRUE;
833 }
834
835 // Default menu selection behaviour - display a help string
836 void wxFrame::OnMenuHighlight(wxMenuEvent& event)
837 {
838 if (GetStatusBar())
839 {
840 if (event.GetMenuId() == -1)
841 SetStatusText("");
842 else
843 {
844 wxMenuBar *menuBar = GetMenuBar();
845 if (menuBar)
846 {
847 wxString helpString(menuBar->GetHelpString(event.GetMenuId()));
848 if (helpString != "")
849 SetStatusText(helpString);
850 }
851 }
852 }
853 }
854
855 wxMenuBar *wxFrame::GetMenuBar(void) const
856 {
857 return m_frameMenuBar;
858 }
859
860 void wxFrame::Centre(int direction)
861 {
862 int display_width, display_height, width, height, x, y;
863 wxDisplaySize(&display_width, &display_height);
864
865 GetSize(&width, &height);
866 GetPosition(&x, &y);
867
868 if (direction & wxHORIZONTAL)
869 x = (int)((display_width - width)/2);
870 if (direction & wxVERTICAL)
871 y = (int)((display_height - height)/2);
872
873 SetSize(x, y, width, height);
874 }
875
876 // Call this to simulate a menu command
877 void wxFrame::Command(int id)
878 {
879 ProcessCommand(id);
880 }
881
882 void wxFrame::ProcessCommand(int id)
883 {
884 wxCommandEvent commandEvent(wxEVENT_TYPE_MENU_COMMAND, id);
885 commandEvent.SetInt( id );
886 commandEvent.SetEventObject( this );
887
888 wxMenuBar *bar = GetMenuBar() ;
889 if (!bar)
890 return;
891
892 wxMenuItem *item = bar->FindItemForId(id) ;
893 if (item && item->IsCheckable())
894 {
895 bar->Check(id,!bar->Checked(id)) ;
896 }
897 GetEventHandler()->ProcessEvent(commandEvent);
898 }
899
900 void wxFrame::OnIdle(wxIdleEvent& event)
901 {
902 DoMenuUpdates();
903 }
904
905 // Query app for menu item updates (called from OnIdle)
906 void wxFrame::DoMenuUpdates(void)
907 {
908 wxMenuBar* bar = GetMenuBar();
909 if (!bar)
910 return;
911
912 int i;
913 for (i = 0; i < bar->m_menuCount; i++)
914 {
915 wxMenu* menu = bar->m_menus[i];
916
917 DoMenuUpdates(menu);
918 }
919 }
920
921 void wxFrame::DoMenuUpdates(wxMenu* menu)
922 {
923 wxNode* node = menu->m_menuItems.First();
924 while (node)
925 {
926 wxMenuItem* item = (wxMenuItem*) node->Data();
927 if ( !item->IsSeparator() )
928 {
929 wxWindowID id = item->GetId();
930 wxUpdateUIEvent event(id);
931 event.SetEventObject( this );
932
933 if (GetEventHandler()->ProcessEvent(event))
934 {
935 if (event.GetSetText())
936 menu->SetLabel(id, event.GetText());
937 if (event.GetSetChecked())
938 menu->Check(id, event.GetChecked());
939 if (event.GetSetEnabled())
940 menu->Enable(id, event.GetEnabled());
941 }
942
943 if (item->GetSubMenu())
944 DoMenuUpdates(item->GetSubMenu());
945 }
946 node = node->Next();
947 }
948 }