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_MSG( m_frameStatusBar
== NULL
, FALSE
,
385 "recreating status bar in wxFrame" );
387 m_frameStatusBar
= OnCreateStatusBar(number
);
388 if ( m_frameStatusBar
)
397 void wxFrame::SetStatusText(const wxString
& text
, const int number
)
399 wxCHECK_RET( m_frameStatusBar
!= NULL
, "no statusbar to set text for" );
401 m_frameStatusBar
->SetStatusText(text
, number
);
404 void wxFrame::SetStatusWidths(const int n
, const int *widths_field
)
406 wxCHECK_RET( m_frameStatusBar
!= NULL
, "no statusbar to set widths for" );
408 m_frameStatusBar
->SetStatusWidths(n
, widths_field
);
412 void wxFrame::PositionStatusBar(void)
414 // native status bar positions itself
416 #if USE_NATIVE_STATUSBAR
417 && !m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
))
422 GetClientSize(&w
, &h
);
424 m_frameStatusBar
->GetSize(&sw
, &sh
);
425 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
429 void wxFrame::SetMenuBar(wxMenuBar
*menu_bar
)
433 m_frameMenuBar
= NULL
;
437 if (menu_bar
->m_menuBarFrame
)
441 HMENU menu
= CreateMenu();
443 for (i
= 0; i
< menu_bar
->m_menuCount
; i
++)
445 HMENU popup
= (HMENU
)menu_bar
->m_menus
[i
]->m_hMenu
;
447 // After looking Bounds Checker result, it seems that all
448 // menus must be individually destroyed. So, don't reset m_hMenu,
449 // to allow ~wxMenu to do the job.
451 menu_bar
->m_menus
[i
]->m_savehMenu
= (WXHMENU
) popup
;
452 // Uncommenting for the moment... JACS
453 menu_bar
->m_menus
[i
]->m_hMenu
= 0;
454 AppendMenu(menu
, MF_POPUP
| MF_STRING
, (UINT
)popup
, menu_bar
->m_titles
[i
]);
457 menu_bar
->m_hMenu
= (WXHMENU
)menu
;
459 delete m_frameMenuBar
;
461 this->m_hMenu
= (WXHMENU
) menu
;
464 if (!SetMenu((HWND
) GetHWND(), menu
))
467 err
= GetLastError();
471 m_frameMenuBar
= menu_bar
;
472 menu_bar
->m_menuBarFrame
= this;
475 bool wxFrame::LoadAccelerators(const wxString
& table
)
477 m_acceleratorTable
= (WXHANDLE
)
480 ::LoadAcceleratorsW(wxGetInstance(), (const char *)table
);
482 ::LoadAcceleratorsA(wxGetInstance(), (const char *)table
);
485 ::LoadAccelerators(wxGetInstance(), (const char *)table
);
488 // The above is necessary because LoadAccelerators is a macro
489 // which we have undefed earlier in the file to avoid confusion
490 // with wxFrame::LoadAccelerators. Ugh!
492 return (m_acceleratorTable
!= (WXHANDLE
) NULL
);
495 void wxFrame::Fit(void)
497 // Work out max. size
498 wxNode
*node
= GetChildren()->First();
503 // Find a child that's a subwindow, but not a dialog box.
504 wxWindow
*win
= (wxWindow
*)node
->Data();
506 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) &&
507 !win
->IsKindOf(CLASSINFO(wxDialog
)))
511 win
->GetSize(&width
, &height
);
512 win
->GetPosition(&x
, &y
);
514 if ((x
+ width
) > max_width
)
515 max_width
= x
+ width
;
516 if ((y
+ height
) > max_height
)
517 max_height
= y
+ height
;
521 SetClientSize(max_width
, max_height
);
524 // Responds to colour changes, and passes event on to children.
525 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
527 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
530 if ( m_frameStatusBar
)
532 wxSysColourChangedEvent event2
;
533 event2
.SetEventObject( m_frameStatusBar
);
534 m_frameStatusBar
->ProcessEvent(event2
);
537 // Propagate the event to the non-top-level children
538 wxWindow::OnSysColourChanged(event
);
546 void wxFrame::MSWCreate(const int id
, wxWindow
*parent
, const char *wclass
, wxWindow
*wx_win
, const char *title
,
547 const int x
, const int y
, const int width
, const int height
, const long style
)
550 m_defaultIcon
= (WXHICON
) (wxSTD_FRAME_ICON
? wxSTD_FRAME_ICON
: wxDEFAULT_FRAME_ICON
);
552 // If child windows aren't properly drawn initially, WS_CLIPCHILDREN
553 // could be the culprit. But without it, you can get a lot of flicker.
556 if ((style
& wxCAPTION
) == wxCAPTION
)
557 msflags
= WS_OVERLAPPED
;
561 if (style
& wxMINIMIZE_BOX
)
562 msflags
|= WS_MINIMIZEBOX
;
563 if (style
& wxMAXIMIZE_BOX
)
564 msflags
|= WS_MAXIMIZEBOX
;
565 if (style
& wxTHICK_FRAME
)
566 msflags
|= WS_THICKFRAME
;
567 if (style
& wxSYSTEM_MENU
)
568 msflags
|= WS_SYSMENU
;
569 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
570 msflags
|= WS_MINIMIZE
;
571 if (style
& wxMAXIMIZE
)
572 msflags
|= WS_MAXIMIZE
;
573 if (style
& wxCAPTION
)
574 msflags
|= WS_CAPTION
;
575 if (style
& wxCLIP_CHILDREN
)
576 msflags
|= WS_CLIPCHILDREN
;
578 // Keep this in wxFrame because it saves recoding this function
581 if (style
& wxTINY_CAPTION_VERT
)
582 msflags
|= IBS_VERTCAPTION
;
583 if (style
& wxTINY_CAPTION_HORIZ
)
584 msflags
|= IBS_HORZCAPTION
;
586 if (style
& wxTINY_CAPTION_VERT
)
587 msflags
|= WS_CAPTION
;
588 if (style
& wxTINY_CAPTION_HORIZ
)
589 msflags
|= WS_CAPTION
;
591 if ((style
& wxTHICK_FRAME
) == 0)
592 msflags
|= WS_BORDER
;
594 WXDWORD extendedStyle
= MakeExtendedStyle(style
);
596 if (style
& wxSTAY_ON_TOP
)
597 extendedStyle
|= WS_EX_TOPMOST
;
600 wxWindow::MSWCreate(id
, parent
, wclass
, wx_win
, title
, x
, y
, width
, height
,
601 msflags
, NULL
, extendedStyle
);
602 // Seems to be necessary if we use WS_POPUP
603 // style instead of WS_OVERLAPPED
604 if (width
> -1 && height
> -1)
605 ::PostMessage((HWND
) GetHWND(), WM_SIZE
, SIZE_RESTORED
, MAKELPARAM(width
, height
));
608 bool wxFrame::MSWOnPaint(void)
611 wxDebugMsg("wxFrameWnd::OnPaint %d\n", handle
);
614 if (GetUpdateRect((HWND
) GetHWND(), &rect
, FALSE
))
620 the_icon
= (HICON
) m_icon
.GetHICON();
622 the_icon
= (HICON
) m_defaultIcon
;
625 // Hold a pointer to the dc so long as the OnPaint() message
626 // is being processed
627 HDC cdc
= BeginPaint((HWND
) GetHWND(), &ps
);
629 // Erase background before painting or we get white background
630 this->MSWDefWindowProc(WM_ICONERASEBKGND
,(WORD
)ps
.hdc
,0L);
635 GetClientRect((HWND
) GetHWND(), &rect
);
637 int icon_height
= 32;
638 int icon_x
= (int)((rect
.right
- icon_width
)/2);
639 int icon_y
= (int)((rect
.bottom
- icon_height
)/2);
640 DrawIcon(cdc
, icon_x
, icon_y
, the_icon
);
643 EndPaint((HWND
) GetHWND(), &ps
);
647 GetEventHandler()->OldOnPaint();
654 WXHICON
wxFrame::MSWOnQueryDragIcon(void)
656 if (m_icon
.Ok() && (m_icon
.GetHICON() != 0))
657 return m_icon
.GetHICON();
659 return m_defaultIcon
;
662 void wxFrame::MSWOnSize(const int x
, const int y
, const WXUINT id
)
665 wxDebugMsg("wxFrameWnd::OnSize %d\n", m_hWnd
);
680 // forward WM_SIZE to status bar control
681 #if USE_NATIVE_STATUSBAR
682 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
684 wxSizeEvent
event(wxSize(x
, y
), m_frameStatusBar
->GetId());
685 event
.SetEventObject( m_frameStatusBar
);
687 ((wxStatusBar95
*)m_frameStatusBar
)->OnSize(event
);
692 #if WXWIN_COMPATIBILITY
693 GetEventHandler()->OldOnSize(x
, y
);
695 wxSizeEvent
event(wxSize(x
, y
), m_windowId
);
696 event
.SetEventObject( this );
697 GetEventHandler()->ProcessEvent(event
);
702 bool wxFrame::MSWOnClose(void)
705 wxDebugMsg("wxFrameWnd::OnClose %d\n", handle
);
710 bool wxFrame::MSWOnCommand(const WXWORD id
, const WXWORD cmd
, const WXHWND control
)
713 wxDebugMsg("wxFrameWnd::OnCommand %d\n", handle
);
715 if (cmd
== 0 || cmd
== 1 ) // Can be either a menu command or an accelerator.
717 // In case it's e.g. a toolbar.
718 wxWindow
*win
= wxFindWinFromHandle(control
);
720 return win
->MSWCommand(cmd
, id
);
722 if (GetMenuBar() && GetMenuBar()->FindItemForId(id
))
734 void wxFrame::MSWOnMenuHighlight(const WXWORD nItem
, const WXWORD nFlags
, const WXHMENU hSysMenu
)
736 #if WXWIN_COMPATIBILITY
737 if (nFlags
== 0xFFFF && hSysMenu
== 0)
738 GetEventHandler()->OldOnMenuSelect(-1);
739 else if (nFlags
!= MF_SEPARATOR
)
740 GetEventHandler()->OldOnMenuSelect(nItem
);
742 if (nFlags
== 0xFFFF && hSysMenu
== 0)
744 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, -1);
745 event
.SetEventObject( this );
746 GetEventHandler()->ProcessEvent(event
);
748 else if (nFlags
!= MF_SEPARATOR
)
750 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, nItem
);
751 event
.SetEventObject( this );
752 GetEventHandler()->ProcessEvent(event
);
757 bool wxFrame::MSWProcessMessage(WXMSG
* pMsg
)
759 if (m_acceleratorTable
!= 0 &&
760 ::TranslateAccelerator((HWND
) GetHWND(), (HANDLE
) m_acceleratorTable
, (MSG
*)pMsg
))
766 // Default resizing behaviour - if only ONE subwindow,
767 // resize to client rectangle size
768 void wxFrame::OnSize(wxSizeEvent
& event
)
770 // Search for a child which is a subwindow, not another frame.
771 wxWindow
*child
= NULL
;
772 // Count the number of _subwindow_ children
774 for(wxNode
*node
= GetChildren()->First(); node
; node
= node
->Next())
776 wxWindow
*win
= (wxWindow
*)node
->Data();
777 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
))
778 && (win
!= GetStatusBar()))
785 // If not one child, call the Layout function if compiled in
786 if (!child
|| (noChildren
> 1)
801 int client_x
, client_y
;
804 wxDebugMsg("wxFrame::OnSize: about to set the child's size.\n");
807 GetClientSize(&client_x
, &client_y
);
808 child
->SetSize(0, 0, client_x
, client_y
);
813 // Default activation behaviour - set the focus for the first child
815 void wxFrame::OnActivate(wxActivateEvent
& event
)
817 for(wxNode
*node
= GetChildren()->First(); node
; node
= node
->Next())
819 // Find a child that's a subwindow, but not a dialog box.
820 wxWindow
*child
= (wxWindow
*)node
->Data();
821 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) &&
822 !child
->IsKindOf(CLASSINFO(wxDialog
)))
825 wxDebugMsg("wxFrame::OnActivate: about to set the child's focus.\n");
833 // The default implementation for the close window event - calls
834 // OnClose for backward compatibility.
836 void wxFrame::OnCloseWindow(wxCloseEvent
& event
)
839 if ( GetEventHandler()->OnClose() || event
.GetForce())
845 // Destroy the window (delayed, if a managed window)
846 bool wxFrame::Destroy(void)
848 if (!wxPendingDelete
.Member(this))
849 wxPendingDelete
.Append(this);
853 // Default menu selection behaviour - display a help string
854 void wxFrame::OnMenuHighlight(wxMenuEvent
& event
)
858 if (event
.GetMenuId() == -1)
862 wxMenuBar
*menuBar
= GetMenuBar();
865 wxString
helpString(menuBar
->GetHelpString(event
.GetMenuId()));
866 if (helpString
!= "")
867 SetStatusText(helpString
);
873 #if WXWIN_COMPATIBILITY
874 void wxFrame::OldOnSize(int x
, int y
)
876 #if WXWIN_COMPATIBILITY == 1
877 wxSizeEvent
event(wxSize(x
, y
), m_windowId
);
878 event
.SetEventObject( this );
879 if (GetEventHandler()->ProcessEvent(event
))
882 // Search for a child which is a subwindow, not another frame.
883 wxWindow
*child
= NULL
;
884 // Count the number of _subwindow_ children
886 for(wxNode
*node
= GetChildren()->First(); node
; node
= node
->Next())
888 wxWindow
*win
= (wxWindow
*)node
->Data();
889 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)) && (win
!= GetStatusBar()))
896 // If not one child, call the Layout function if compiled in
897 if (!child
|| (noChildren
> 1)
912 int client_x
, client_y
;
915 wxDebugMsg("wxFrame::OnSize: about to set the child's size.\n");
918 GetClientSize(&client_x
, &client_y
);
919 child
->SetSize(0, 0, client_x
, client_y
);
923 // Default activation behaviour - set the focus for the first child
925 void wxFrame::OldOnActivate(bool flag
)
927 #if WXWIN_COMPATIBILITY == 1
928 wxActivateEvent
event(wxEVT_ACTIVATE
, flag
, m_windowId
);
929 event
.SetEventObject( this );
930 if (GetEventHandler()->ProcessEvent(event
))
933 for(wxNode
*node
= GetChildren()->First(); node
; node
= node
->Next())
935 // Find a child that's a subwindow, but not a dialog box.
936 wxWindow
*child
= (wxWindow
*)node
->Data();
937 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) &&
938 !child
->IsKindOf(CLASSINFO(wxDialog
)))
941 wxDebugMsg("wxFrame::OnActivate: about to set the child's focus.\n");
949 // Default menu selection behaviour - display a help string
950 void wxFrame::OldOnMenuSelect(int id
)
952 #if WXWIN_COMPATIBILITY == 1
953 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, id
);
954 event
.SetEventObject( this );
955 if (GetEventHandler()->ProcessEvent(event
))
964 wxMenuBar
*menuBar
= GetMenuBar();
967 wxString
helpString(menuBar
->GetHelpString(id
));
968 if (helpString
!= "")
969 SetStatusText(helpString
);
976 wxMenuBar
*wxFrame::GetMenuBar(void) const
978 return m_frameMenuBar
;
981 void wxFrame::Centre(const int direction
)
983 int display_width
, display_height
, width
, height
, x
, y
;
984 wxDisplaySize(&display_width
, &display_height
);
986 GetSize(&width
, &height
);
989 if (direction
& wxHORIZONTAL
)
990 x
= (int)((display_width
- width
)/2);
991 if (direction
& wxVERTICAL
)
992 y
= (int)((display_height
- height
)/2);
994 SetSize(x
, y
, width
, height
);
997 // Call this to simulate a menu command
998 void wxFrame::Command(int id
)
1003 void wxFrame::ProcessCommand(int id
)
1005 wxCommandEvent
commandEvent(wxEVENT_TYPE_MENU_COMMAND
, id
);
1006 commandEvent
.SetInt( id
);
1007 commandEvent
.SetEventObject( this );
1009 wxMenuBar
*bar
= GetMenuBar() ;
1013 // Motif does the job by itself!!
1015 wxMenuItem
*item
= bar
->FindItemForId(id
) ;
1016 if (item
&& item
->IsCheckable())
1018 //wxDebugMsg("Toggling id %d\n",id) ;
1019 bar
->Check(id
,!bar
->Checked(id
)) ;
1022 if (!ProcessEvent(commandEvent
))
1023 OldOnMenuCommand(id
);
1026 void wxFrame::OnIdle(wxIdleEvent
& event
)
1031 // Query app for menu item updates (called from OnIdle)
1032 void wxFrame::DoMenuUpdates(void)
1034 wxMenuBar
* bar
= GetMenuBar();
1039 for (i
= 0; i
< bar
->m_menuCount
; i
++)
1041 wxMenu
* menu
= bar
->m_menus
[i
];
1043 DoMenuUpdates(menu
);
1047 void wxFrame::DoMenuUpdates(wxMenu
* menu
)
1049 wxNode
* node
= menu
->m_menuItems
.First();
1052 wxMenuItem
* item
= (wxMenuItem
*) node
->Data();
1053 if ( !item
->IsSeparator() )
1055 wxWindowID id
= item
->GetId();
1056 wxUpdateUIEvent
event(id
);
1057 event
.SetEventObject( this );
1059 if (GetEventHandler()->ProcessEvent(event
))
1061 if (event
.GetSetText())
1062 menu
->SetLabel(id
, event
.GetText());
1063 if (event
.GetSetChecked())
1064 menu
->Check(id
, event
.GetChecked());
1065 if (event
.GetSetEnabled())
1066 menu
->Enable(id
, event
.GetEnabled());
1069 if (item
->GetSubMenu())
1070 DoMenuUpdates(item
->GetSubMenu());
1072 node
= node
->Next();