1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "frame.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
29 #include "wx/dialog.h"
30 #include "wx/settings.h"
31 #include "wx/dcclient.h"
34 #include "wx/msw/private.h"
35 #include "wx/statusbr.h"
36 #include "wx/menuitem.h"
38 #ifdef LoadAccelerators
39 #undef LoadAccelerators
42 #if USE_NATIVE_STATUSBAR
43 #include <wx/msw/statbr95.h>
46 extern wxList wxModelessWindows
;
47 extern wxList wxPendingDelete
;
48 extern char wxFrameClassName
[];
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
)
60 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxWindow
)
63 #if USE_NATIVE_STATUSBAR
64 bool wxFrame::m_useNativeStatusBar
= TRUE
;
66 bool wxFrame::m_useNativeStatusBar
= FALSE
;
69 wxFrame::wxFrame(void)
71 m_frameMenuBar
= NULL
;
72 m_frameStatusBar
= NULL
;
74 m_windowParent
= NULL
;
78 bool wxFrame::Create(wxWindow
*parent
,
80 const wxString
& title
,
87 wxTopLevelWindows
.Append(this);
90 // m_modalShowing = FALSE;
91 m_windowStyle
= style
;
92 m_frameMenuBar
= NULL
;
93 m_frameStatusBar
= NULL
;
95 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
101 m_windowId
= (int)NewControlId();
103 if (parent
) parent
->AddChild(this);
111 MSWCreate(m_windowId
, (wxWindow
*)parent
, wxFrameClassName
, this, (char *)(const char *)title
,
112 x
, y
, width
, height
, style
);
114 wxModelessWindows
.Append(this);
118 wxFrame::~wxFrame(void)
120 m_isBeingDeleted
= TRUE
;
121 wxTopLevelWindows
.DeleteObject(this);
123 if (m_frameStatusBar
)
124 delete m_frameStatusBar
;
126 delete m_frameMenuBar
;
128 /* New behaviour March 1998: check if it's the last top-level window */
129 // if (wxTheApp && (this == wxTheApp->GetTopWindow()))
131 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
133 wxTheApp
->SetTopWindow(NULL
);
135 if (wxTheApp
->GetExitOnFrameDelete())
141 wxModelessWindows
.DeleteObject(this);
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());
150 WXHMENU
wxFrame::GetWinMenu(void) const
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
160 GetClientRect((HWND
) GetHWND(), &rect
);
162 if ( m_frameStatusBar
)
164 int statusX
, statusY
;
165 m_frameStatusBar
->GetClientSize(&statusX
, &statusY
);
166 rect
.bottom
-= statusY
;
172 // Set the client size (i.e. leave the calculation of borders etc.
174 void wxFrame::SetClientSize(const int width
, const int height
)
176 HWND hWnd
= (HWND
) GetHWND();
179 GetClientRect(hWnd
, &rect
);
182 GetWindowRect(hWnd
, &rect2
);
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
187 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
188 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
190 if ( m_frameStatusBar
)
192 int statusX
, statusY
;
193 m_frameStatusBar
->GetClientSize(&statusX
, &statusY
);
194 actual_height
+= statusY
;
198 point
.x
= rect2
.left
;
201 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
202 #if WXWIN_COMPATIBILITY
203 GetEventHandler()->OldOnSize(width
, height
);
205 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
206 event
.SetEventObject( this );
207 GetEventHandler()->ProcessEvent(event
);
211 void wxFrame::GetSize(int *width
, int *height
) const
214 GetWindowRect((HWND
) GetHWND(), &rect
);
215 *width
= rect
.right
- rect
.left
;
216 *height
= rect
.bottom
- rect
.top
;
219 void wxFrame::GetPosition(int *x
, int *y
) const
222 GetWindowRect((HWND
) GetHWND(), &rect
);
231 void wxFrame::SetSize(const int x
, const int y
, const int width
, const int height
, const int sizeFlags
)
233 int currentX
, currentY
;
239 GetPosition(¤tX
, ¤tY
);
240 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
242 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
247 if (width
== -1) w1
= ww
;
248 if (height
==-1) h1
= hh
;
250 MoveWindow((HWND
) GetHWND(), x1
, y1
, w1
, h1
, (BOOL
)TRUE
);
252 #if WXWIN_COMPATIBILITY
253 GetEventHandler()->OldOnSize(width
, height
);
255 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
256 event
.SetEventObject( this );
257 GetEventHandler()->ProcessEvent(event
);
261 bool wxFrame::Show(const bool show
)
271 // Try to highlight the correct window (the parent)
275 hWndParent
= (HWND
) GetParent()->GetHWND();
277 ::BringWindowToTop(hWndParent
);
281 ShowWindow((HWND
) GetHWND(), (BOOL
)cshow
);
284 BringWindowToTop((HWND
) GetHWND());
286 #if WXWIN_COMPATIBILITY
289 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
290 event
.SetEventObject( this );
291 GetEventHandler()->ProcessEvent(event
);
297 void wxFrame::Iconize(const bool iconize
)
307 ShowWindow((HWND
) GetHWND(), (BOOL
)cshow
);
308 m_iconized
= iconize
;
311 // Equivalent to maximize/restore in Windows
312 void wxFrame::Maximize(const bool maximize
)
320 ShowWindow((HWND
) GetHWND(), cshow
);
324 bool wxFrame::IsIconized(void) const
326 ((wxFrame
*)this)->m_iconized
= (::IsIconic((HWND
) GetHWND()) != 0);
330 void wxFrame::SetTitle(const wxString
& title
)
332 SetWindowText((HWND
) GetHWND(), (const char *)title
);
335 wxString
wxFrame::GetTitle(void) const
337 GetWindowText((HWND
) GetHWND(), wxBuffer
, 1000);
338 return wxString(wxBuffer
);
341 void wxFrame::SetIcon(const wxIcon
& icon
)
344 #if defined(__WIN95__)
346 SendMessage((HWND
) GetHWND(), WM_SETICON
,
347 (WPARAM
)TRUE
, (LPARAM
)(HICON
) m_icon
.GetHICON());
351 wxStatusBar
*wxFrame::OnCreateStatusBar(const int number
)
353 wxStatusBar
*statusBar
= NULL
;
355 #if USE_NATIVE_STATUSBAR
356 if (UsesNativeStatusBar())
358 statusBar
= new wxStatusBar95(this);
363 statusBar
= new wxStatusBar(this, -1, wxPoint(0, 0), wxSize(100, 20));
365 // Set the height according to the font and the border size
366 wxClientDC
dc(statusBar
);
367 dc
.SetFont(* statusBar
->GetFont());
370 dc
.GetTextExtent("X", &x
, &y
);
372 int height
= (int)( (y
* 1.1) + 2* statusBar
->GetBorderY());
374 statusBar
->SetSize(-1, -1, 100, height
);
377 statusBar
->SetFieldsCount(number
);
381 bool wxFrame::CreateStatusBar(const int number
)
383 // VZ: calling CreateStatusBar twice is an error - why anyone would do it?
384 wxCHECK_RET( m_frameStatusBar
== NULL
, FALSE
);
386 m_frameStatusBar
= OnCreateStatusBar(number
);
387 if ( m_frameStatusBar
)
396 void wxFrame::SetStatusText(const wxString
& text
, const int number
)
398 wxCHECK( m_frameStatusBar
!= NULL
);
400 m_frameStatusBar
->SetStatusText(text
, number
);
403 void wxFrame::SetStatusWidths(const int n
, const int *widths_field
)
405 wxCHECK( m_frameStatusBar
!= NULL
);
407 m_frameStatusBar
->SetStatusWidths(n
, widths_field
);
411 void wxFrame::PositionStatusBar(void)
413 // native status bar positions itself
415 #if USE_NATIVE_STATUSBAR
416 && !m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
))
421 GetClientSize(&w
, &h
);
423 m_frameStatusBar
->GetSize(&sw
, &sh
);
424 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
428 void wxFrame::SetMenuBar(wxMenuBar
*menu_bar
)
432 m_frameMenuBar
= NULL
;
436 if (menu_bar
->m_menuBarFrame
)
440 HMENU menu
= CreateMenu();
442 for (i
= 0; i
< menu_bar
->m_menuCount
; i
++)
444 HMENU popup
= (HMENU
)menu_bar
->m_menus
[i
]->m_hMenu
;
446 // After looking Bounds Checker result, it seems that all
447 // menus must be individually destroyed. So, don't reset m_hMenu,
448 // to allow ~wxMenu to do the job.
450 menu_bar
->m_menus
[i
]->m_savehMenu
= (WXHMENU
) popup
;
451 // Uncommenting for the moment... JACS
452 menu_bar
->m_menus
[i
]->m_hMenu
= 0;
453 AppendMenu(menu
, MF_POPUP
| MF_STRING
, (UINT
)popup
, menu_bar
->m_titles
[i
]);
456 menu_bar
->m_hMenu
= (WXHMENU
)menu
;
458 delete m_frameMenuBar
;
460 this->m_hMenu
= (WXHMENU
) menu
;
463 if (!SetMenu((HWND
) GetHWND(), menu
))
466 err
= GetLastError();
470 m_frameMenuBar
= menu_bar
;
471 menu_bar
->m_menuBarFrame
= this;
474 bool wxFrame::LoadAccelerators(const wxString
& table
)
476 m_acceleratorTable
= (WXHANDLE
)
479 ::LoadAcceleratorsW(wxGetInstance(), (const char *)table
);
481 ::LoadAcceleratorsA(wxGetInstance(), (const char *)table
);
484 ::LoadAccelerators(wxGetInstance(), (const char *)table
);
487 // The above is necessary because LoadAccelerators is a macro
488 // which we have undefed earlier in the file to avoid confusion
489 // with wxFrame::LoadAccelerators. Ugh!
491 return (m_acceleratorTable
!= (WXHANDLE
) NULL
);
494 void wxFrame::Fit(void)
496 // Work out max. size
497 wxNode
*node
= GetChildren()->First();
502 // Find a child that's a subwindow, but not a dialog box.
503 wxWindow
*win
= (wxWindow
*)node
->Data();
505 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) &&
506 !win
->IsKindOf(CLASSINFO(wxDialog
)))
510 win
->GetSize(&width
, &height
);
511 win
->GetPosition(&x
, &y
);
513 if ((x
+ width
) > max_width
)
514 max_width
= x
+ width
;
515 if ((y
+ height
) > max_height
)
516 max_height
= y
+ height
;
520 SetClientSize(max_width
, max_height
);
523 // Responds to colour changes, and passes event on to children.
524 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
526 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
529 if ( m_frameStatusBar
)
531 wxSysColourChangedEvent event2
;
532 event2
.SetEventObject( m_frameStatusBar
);
533 m_frameStatusBar
->ProcessEvent(event2
);
536 // Propagate the event to the non-top-level children
537 wxWindow::OnSysColourChanged(event
);
545 void wxFrame::MSWCreate(const int id
, wxWindow
*parent
, const char *wclass
, wxWindow
*wx_win
, const char *title
,
546 const int x
, const int y
, const int width
, const int height
, const long style
)
549 m_defaultIcon
= (WXHICON
) (wxSTD_FRAME_ICON
? wxSTD_FRAME_ICON
: wxDEFAULT_FRAME_ICON
);
551 // If child windows aren't properly drawn initially, WS_CLIPCHILDREN
552 // could be the culprit. But without it, you can get a lot of flicker.
554 // DWORD msflags = WS_POPUP | WS_CLIPCHILDREN ;
557 if ((style
& wxCAPTION
) == wxCAPTION
)
558 msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
; // WS_POPUP | WS_CLIPCHILDREN ;
560 msflags
= WS_POPUP
| WS_CLIPCHILDREN
;
562 if (style
& wxMINIMIZE_BOX
)
563 msflags
|= WS_MINIMIZEBOX
;
564 if (style
& wxMAXIMIZE_BOX
)
565 msflags
|= WS_MAXIMIZEBOX
;
566 if (style
& wxTHICK_FRAME
)
567 msflags
|= WS_THICKFRAME
;
568 if (style
& wxSYSTEM_MENU
)
569 msflags
|= WS_SYSMENU
;
570 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
571 msflags
|= WS_MINIMIZE
;
572 if (style
& wxMAXIMIZE
)
573 msflags
|= WS_MAXIMIZE
;
574 if (style
& wxCAPTION
)
575 msflags
|= WS_CAPTION
;
577 // Keep this in wxFrame because it saves recoding this function
580 if (style
& wxTINY_CAPTION_VERT
)
581 msflags
|= IBS_VERTCAPTION
;
582 if (style
& wxTINY_CAPTION_HORIZ
)
583 msflags
|= IBS_HORZCAPTION
;
585 if (style
& wxTINY_CAPTION_VERT
)
586 msflags
|= WS_CAPTION
;
587 if (style
& wxTINY_CAPTION_HORIZ
)
588 msflags
|= WS_CAPTION
;
590 if ((style
& wxTHICK_FRAME
) == 0)
591 msflags
|= WS_BORDER
;
593 WXDWORD extendedStyle
= MakeExtendedStyle(style
);
595 if (style
& wxSTAY_ON_TOP
)
596 extendedStyle
|= WS_EX_TOPMOST
;
599 wxWindow::MSWCreate(id
, parent
, wclass
, wx_win
, title
, x
, y
, width
, height
,
600 msflags
, NULL
, extendedStyle
);
601 // Seems to be necessary if we use WS_POPUP
602 // style instead of WS_OVERLAPPED
603 if (width
> -1 && height
> -1)
604 ::PostMessage((HWND
) GetHWND(), WM_SIZE
, SIZE_RESTORED
, MAKELPARAM(width
, height
));
607 bool wxFrame::MSWOnPaint(void)
610 wxDebugMsg("wxFrameWnd::OnPaint %d\n", handle
);
613 if (GetUpdateRect((HWND
) GetHWND(), &rect
, FALSE
))
619 the_icon
= (HICON
) m_icon
.GetHICON();
621 the_icon
= (HICON
) m_defaultIcon
;
624 // Hold a pointer to the dc so long as the OnPaint() message
625 // is being processed
626 HDC cdc
= BeginPaint((HWND
) GetHWND(), &ps
);
628 // Erase background before painting or we get white background
629 this->MSWDefWindowProc(WM_ICONERASEBKGND
,(WORD
)ps
.hdc
,0L);
634 GetClientRect((HWND
) GetHWND(), &rect
);
636 int icon_height
= 32;
637 int icon_x
= (int)((rect
.right
- icon_width
)/2);
638 int icon_y
= (int)((rect
.bottom
- icon_height
)/2);
639 DrawIcon(cdc
, icon_x
, icon_y
, the_icon
);
642 EndPaint((HWND
) GetHWND(), &ps
);
647 // m_paintHDC = (WXHDC) cdc;
648 GetEventHandler()->OldOnPaint();
649 // m_paintHDC = NULL;
656 WXHICON
wxFrame::MSWOnQueryDragIcon(void)
658 if (m_icon
.Ok() && (m_icon
.GetHICON() != 0))
659 return m_icon
.GetHICON();
661 return m_defaultIcon
;
664 void wxFrame::MSWOnSize(const int x
, const int y
, const WXUINT id
)
667 wxDebugMsg("wxFrameWnd::OnSize %d\n", m_hWnd
);
682 // forward WM_SIZE to status bar control
683 #if USE_NATIVE_STATUSBAR
684 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
686 wxSizeEvent
event(wxSize(x
, y
), m_frameStatusBar
->GetId());
687 event
.SetEventObject( m_frameStatusBar
);
689 ((wxStatusBar95
*)m_frameStatusBar
)->OnSize(event
);
694 #if WXWIN_COMPATIBILITY
695 GetEventHandler()->OldOnSize(x
, y
);
697 wxSizeEvent
event(wxSize(x
, y
), m_windowId
);
698 event
.SetEventObject( this );
699 GetEventHandler()->ProcessEvent(event
);
704 bool wxFrame::MSWOnClose(void)
707 wxDebugMsg("wxFrameWnd::OnClose %d\n", handle
);
712 bool wxFrame::MSWOnCommand(const WXWORD id
, const WXWORD cmd
, const WXHWND control
)
715 wxDebugMsg("wxFrameWnd::OnCommand %d\n", handle
);
717 if (cmd
== 0 || cmd
== 1 ) // Can be either a menu command or an accelerator.
719 // In case it's e.g. a toolbar.
720 wxWindow
*win
= wxFindWinFromHandle(control
);
722 return win
->MSWCommand(cmd
, id
);
724 if (GetMenuBar() && GetMenuBar()->FindItemForId(id
))
736 void wxFrame::MSWOnMenuHighlight(const WXWORD nItem
, const WXWORD nFlags
, const WXHMENU hSysMenu
)
738 #if WXWIN_COMPATIBILITY
739 if (nFlags
== 0xFFFF && hSysMenu
== 0)
740 GetEventHandler()->OldOnMenuSelect(-1);
741 else if (nFlags
!= MF_SEPARATOR
)
742 GetEventHandler()->OldOnMenuSelect(nItem
);
744 if (nFlags
== 0xFFFF && hSysMenu
== 0)
746 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, -1);
747 event
.SetEventObject( this );
748 GetEventHandler()->ProcessEvent(event
);
750 else if (nFlags
!= MF_SEPARATOR
)
752 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, nItem
);
753 event
.SetEventObject( this );
754 GetEventHandler()->ProcessEvent(event
);
759 bool wxFrame::MSWProcessMessage(WXMSG
* pMsg
)
761 if (m_acceleratorTable
!= 0 &&
762 ::TranslateAccelerator((HWND
) GetHWND(), (HANDLE
) m_acceleratorTable
, (MSG
*)pMsg
))
768 // Default resizing behaviour - if only ONE subwindow,
769 // resize to client rectangle size
770 void wxFrame::OnSize(wxSizeEvent
& event
)
772 // Search for a child which is a subwindow, not another frame.
773 wxWindow
*child
= NULL
;
774 // Count the number of _subwindow_ children
776 for(wxNode
*node
= GetChildren()->First(); node
; node
= node
->Next())
778 wxWindow
*win
= (wxWindow
*)node
->Data();
779 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
))
780 && (win
!= GetStatusBar()))
787 // If not one child, call the Layout function if compiled in
788 if (!child
|| (noChildren
> 1)
803 int client_x
, client_y
;
806 wxDebugMsg("wxFrame::OnSize: about to set the child's size.\n");
809 GetClientSize(&client_x
, &client_y
);
810 child
->SetSize(0, 0, client_x
, client_y
);
815 // Default activation behaviour - set the focus for the first child
817 void wxFrame::OnActivate(wxActivateEvent
& event
)
819 for(wxNode
*node
= GetChildren()->First(); node
; node
= node
->Next())
821 // Find a child that's a subwindow, but not a dialog box.
822 wxWindow
*child
= (wxWindow
*)node
->Data();
823 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) &&
824 !child
->IsKindOf(CLASSINFO(wxDialog
)))
827 wxDebugMsg("wxFrame::OnActivate: about to set the child's focus.\n");
835 // The default implementation for the close window event - calls
836 // OnClose for backward compatibility.
838 void wxFrame::OnCloseWindow(wxCloseEvent
& event
)
841 if ( GetEventHandler()->OnClose() || event
.GetForce())
847 // Destroy the window (delayed, if a managed window)
848 bool wxFrame::Destroy(void)
850 if (!wxPendingDelete
.Member(this))
851 wxPendingDelete
.Append(this);
855 // Default menu selection behaviour - display a help string
856 void wxFrame::OnMenuHighlight(wxMenuEvent
& event
)
860 if (event
.GetMenuId() == -1)
864 wxMenuBar
*menuBar
= GetMenuBar();
867 wxString
helpString(menuBar
->GetHelpString(event
.GetMenuId()));
868 if (helpString
!= "")
869 SetStatusText(helpString
);
875 #if WXWIN_COMPATIBILITY
876 void wxFrame::OldOnSize(int x
, int y
)
878 #if WXWIN_COMPATIBILITY == 1
879 wxSizeEvent
event(wxSize(x
, y
), m_windowId
);
880 event
.SetEventObject( this );
881 if (GetEventHandler()->ProcessEvent(event
))
884 // Search for a child which is a subwindow, not another frame.
885 wxWindow
*child
= NULL
;
886 // Count the number of _subwindow_ children
888 for(wxNode
*node
= GetChildren()->First(); node
; node
= node
->Next())
890 wxWindow
*win
= (wxWindow
*)node
->Data();
891 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)) && (win
!= GetStatusBar()))
898 // If not one child, call the Layout function if compiled in
899 if (!child
|| (noChildren
> 1)
914 int client_x
, client_y
;
917 wxDebugMsg("wxFrame::OnSize: about to set the child's size.\n");
920 GetClientSize(&client_x
, &client_y
);
921 child
->SetSize(0, 0, client_x
, client_y
);
925 // Default activation behaviour - set the focus for the first child
927 void wxFrame::OldOnActivate(bool flag
)
929 #if WXWIN_COMPATIBILITY == 1
930 wxActivateEvent
event(wxEVT_ACTIVATE
, flag
, m_windowId
);
931 event
.SetEventObject( this );
932 if (GetEventHandler()->ProcessEvent(event
))
935 for(wxNode
*node
= GetChildren()->First(); node
; node
= node
->Next())
937 // Find a child that's a subwindow, but not a dialog box.
938 wxWindow
*child
= (wxWindow
*)node
->Data();
939 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) &&
940 !child
->IsKindOf(CLASSINFO(wxDialog
)))
943 wxDebugMsg("wxFrame::OnActivate: about to set the child's focus.\n");
951 // Default menu selection behaviour - display a help string
952 void wxFrame::OldOnMenuSelect(int id
)
954 #if WXWIN_COMPATIBILITY == 1
955 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, id
);
956 event
.SetEventObject( this );
957 if (GetEventHandler()->ProcessEvent(event
))
966 wxMenuBar
*menuBar
= GetMenuBar();
969 wxString
helpString(menuBar
->GetHelpString(id
));
970 if (helpString
!= "")
971 SetStatusText(helpString
);
978 wxMenuBar
*wxFrame::GetMenuBar(void) const
980 return m_frameMenuBar
;
983 void wxFrame::Centre(const int direction
)
985 int display_width
, display_height
, width
, height
, x
, y
;
986 wxDisplaySize(&display_width
, &display_height
);
988 GetSize(&width
, &height
);
991 if (direction
& wxHORIZONTAL
)
992 x
= (int)((display_width
- width
)/2);
993 if (direction
& wxVERTICAL
)
994 y
= (int)((display_height
- height
)/2);
996 SetSize(x
, y
, width
, height
);
999 // Call this to simulate a menu command
1000 void wxFrame::Command(int id
)
1005 void wxFrame::ProcessCommand(int id
)
1007 wxCommandEvent
commandEvent(wxEVENT_TYPE_MENU_COMMAND
, id
);
1008 commandEvent
.SetInt( id
);
1009 commandEvent
.SetEventObject( this );
1011 wxMenuBar
*bar
= GetMenuBar() ;
1015 // Motif does the job by itself!!
1017 wxMenuItem
*item
= bar
->FindItemForId(id
) ;
1018 if (item
&& item
->IsCheckable())
1020 //wxDebugMsg("Toggling id %d\n",id) ;
1021 bar
->Check(id
,!bar
->Checked(id
)) ;
1024 if (!ProcessEvent(commandEvent
))
1025 OldOnMenuCommand(id
);
1028 void wxFrame::OnIdle(wxIdleEvent
& event
)
1033 // Query app for menu item updates (called from OnIdle)
1034 void wxFrame::DoMenuUpdates(void)
1036 wxMenuBar
* bar
= GetMenuBar();
1041 for (i
= 0; i
< bar
->m_menuCount
; i
++)
1043 wxMenu
* menu
= bar
->m_menus
[i
];
1045 DoMenuUpdates(menu
);
1049 void wxFrame::DoMenuUpdates(wxMenu
* menu
)
1051 wxNode
* node
= menu
->m_menuItems
.First();
1054 wxMenuItem
* item
= (wxMenuItem
*) node
->Data();
1055 if ( !item
->IsSeparator() )
1057 wxWindowID id
= item
->GetId();
1058 wxUpdateUIEvent
event(id
);
1059 event
.SetEventObject( this );
1061 if (GetEventHandler()->ProcessEvent(event
))
1063 if (event
.GetSetText())
1064 menu
->SetLabel(id
, event
.GetText());
1065 if (event
.GetSetChecked())
1066 menu
->Check(id
, event
.GetChecked());
1067 if (event
.GetSetEnabled())
1068 menu
->Enable(id
, event
.GetEnabled());
1071 if (item
->GetSubMenu())
1072 DoMenuUpdates(item
->GetSubMenu());
1074 node
= node
->Next();