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.
555 // DWORD msflags = WS_POPUP | WS_CLIPCHILDREN ;
558 if ((style
& wxCAPTION
) == wxCAPTION
)
559 msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
; // WS_POPUP | WS_CLIPCHILDREN ;
561 msflags
= WS_POPUP
| WS_CLIPCHILDREN
;
563 if (style
& wxMINIMIZE_BOX
)
564 msflags
|= WS_MINIMIZEBOX
;
565 if (style
& wxMAXIMIZE_BOX
)
566 msflags
|= WS_MAXIMIZEBOX
;
567 if (style
& wxTHICK_FRAME
)
568 msflags
|= WS_THICKFRAME
;
569 if (style
& wxSYSTEM_MENU
)
570 msflags
|= WS_SYSMENU
;
571 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
572 msflags
|= WS_MINIMIZE
;
573 if (style
& wxMAXIMIZE
)
574 msflags
|= WS_MAXIMIZE
;
575 if (style
& wxCAPTION
)
576 msflags
|= WS_CAPTION
;
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
);
648 // m_paintHDC = (WXHDC) cdc;
649 GetEventHandler()->OldOnPaint();
650 // m_paintHDC = NULL;
657 WXHICON
wxFrame::MSWOnQueryDragIcon(void)
659 if (m_icon
.Ok() && (m_icon
.GetHICON() != 0))
660 return m_icon
.GetHICON();
662 return m_defaultIcon
;
665 void wxFrame::MSWOnSize(const int x
, const int y
, const WXUINT id
)
668 wxDebugMsg("wxFrameWnd::OnSize %d\n", m_hWnd
);
683 // forward WM_SIZE to status bar control
684 #if USE_NATIVE_STATUSBAR
685 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
687 wxSizeEvent
event(wxSize(x
, y
), m_frameStatusBar
->GetId());
688 event
.SetEventObject( m_frameStatusBar
);
690 ((wxStatusBar95
*)m_frameStatusBar
)->OnSize(event
);
695 #if WXWIN_COMPATIBILITY
696 GetEventHandler()->OldOnSize(x
, y
);
698 wxSizeEvent
event(wxSize(x
, y
), m_windowId
);
699 event
.SetEventObject( this );
700 GetEventHandler()->ProcessEvent(event
);
705 bool wxFrame::MSWOnClose(void)
708 wxDebugMsg("wxFrameWnd::OnClose %d\n", handle
);
713 bool wxFrame::MSWOnCommand(const WXWORD id
, const WXWORD cmd
, const WXHWND control
)
716 wxDebugMsg("wxFrameWnd::OnCommand %d\n", handle
);
718 if (cmd
== 0 || cmd
== 1 ) // Can be either a menu command or an accelerator.
720 // In case it's e.g. a toolbar.
721 wxWindow
*win
= wxFindWinFromHandle(control
);
723 return win
->MSWCommand(cmd
, id
);
725 if (GetMenuBar() && GetMenuBar()->FindItemForId(id
))
737 void wxFrame::MSWOnMenuHighlight(const WXWORD nItem
, const WXWORD nFlags
, const WXHMENU hSysMenu
)
739 #if WXWIN_COMPATIBILITY
740 if (nFlags
== 0xFFFF && hSysMenu
== 0)
741 GetEventHandler()->OldOnMenuSelect(-1);
742 else if (nFlags
!= MF_SEPARATOR
)
743 GetEventHandler()->OldOnMenuSelect(nItem
);
745 if (nFlags
== 0xFFFF && hSysMenu
== 0)
747 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, -1);
748 event
.SetEventObject( this );
749 GetEventHandler()->ProcessEvent(event
);
751 else if (nFlags
!= MF_SEPARATOR
)
753 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, nItem
);
754 event
.SetEventObject( this );
755 GetEventHandler()->ProcessEvent(event
);
760 bool wxFrame::MSWProcessMessage(WXMSG
* pMsg
)
762 if (m_acceleratorTable
!= 0 &&
763 ::TranslateAccelerator((HWND
) GetHWND(), (HANDLE
) m_acceleratorTable
, (MSG
*)pMsg
))
769 // Default resizing behaviour - if only ONE subwindow,
770 // resize to client rectangle size
771 void wxFrame::OnSize(wxSizeEvent
& event
)
773 // Search for a child which is a subwindow, not another frame.
774 wxWindow
*child
= NULL
;
775 // Count the number of _subwindow_ children
777 for(wxNode
*node
= GetChildren()->First(); node
; node
= node
->Next())
779 wxWindow
*win
= (wxWindow
*)node
->Data();
780 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
))
781 && (win
!= GetStatusBar()))
788 // If not one child, call the Layout function if compiled in
789 if (!child
|| (noChildren
> 1)
804 int client_x
, client_y
;
807 wxDebugMsg("wxFrame::OnSize: about to set the child's size.\n");
810 GetClientSize(&client_x
, &client_y
);
811 child
->SetSize(0, 0, client_x
, client_y
);
816 // Default activation behaviour - set the focus for the first child
818 void wxFrame::OnActivate(wxActivateEvent
& event
)
820 for(wxNode
*node
= GetChildren()->First(); node
; node
= node
->Next())
822 // Find a child that's a subwindow, but not a dialog box.
823 wxWindow
*child
= (wxWindow
*)node
->Data();
824 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) &&
825 !child
->IsKindOf(CLASSINFO(wxDialog
)))
828 wxDebugMsg("wxFrame::OnActivate: about to set the child's focus.\n");
836 // The default implementation for the close window event - calls
837 // OnClose for backward compatibility.
839 void wxFrame::OnCloseWindow(wxCloseEvent
& event
)
842 if ( GetEventHandler()->OnClose() || event
.GetForce())
848 // Destroy the window (delayed, if a managed window)
849 bool wxFrame::Destroy(void)
851 if (!wxPendingDelete
.Member(this))
852 wxPendingDelete
.Append(this);
856 // Default menu selection behaviour - display a help string
857 void wxFrame::OnMenuHighlight(wxMenuEvent
& event
)
861 if (event
.GetMenuId() == -1)
865 wxMenuBar
*menuBar
= GetMenuBar();
868 wxString
helpString(menuBar
->GetHelpString(event
.GetMenuId()));
869 if (helpString
!= "")
870 SetStatusText(helpString
);
876 #if WXWIN_COMPATIBILITY
877 void wxFrame::OldOnSize(int x
, int y
)
879 #if WXWIN_COMPATIBILITY == 1
880 wxSizeEvent
event(wxSize(x
, y
), m_windowId
);
881 event
.SetEventObject( this );
882 if (GetEventHandler()->ProcessEvent(event
))
885 // Search for a child which is a subwindow, not another frame.
886 wxWindow
*child
= NULL
;
887 // Count the number of _subwindow_ children
889 for(wxNode
*node
= GetChildren()->First(); node
; node
= node
->Next())
891 wxWindow
*win
= (wxWindow
*)node
->Data();
892 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)) && (win
!= GetStatusBar()))
899 // If not one child, call the Layout function if compiled in
900 if (!child
|| (noChildren
> 1)
915 int client_x
, client_y
;
918 wxDebugMsg("wxFrame::OnSize: about to set the child's size.\n");
921 GetClientSize(&client_x
, &client_y
);
922 child
->SetSize(0, 0, client_x
, client_y
);
926 // Default activation behaviour - set the focus for the first child
928 void wxFrame::OldOnActivate(bool flag
)
930 #if WXWIN_COMPATIBILITY == 1
931 wxActivateEvent
event(wxEVT_ACTIVATE
, flag
, m_windowId
);
932 event
.SetEventObject( this );
933 if (GetEventHandler()->ProcessEvent(event
))
936 for(wxNode
*node
= GetChildren()->First(); node
; node
= node
->Next())
938 // Find a child that's a subwindow, but not a dialog box.
939 wxWindow
*child
= (wxWindow
*)node
->Data();
940 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) &&
941 !child
->IsKindOf(CLASSINFO(wxDialog
)))
944 wxDebugMsg("wxFrame::OnActivate: about to set the child's focus.\n");
952 // Default menu selection behaviour - display a help string
953 void wxFrame::OldOnMenuSelect(int id
)
955 #if WXWIN_COMPATIBILITY == 1
956 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, id
);
957 event
.SetEventObject( this );
958 if (GetEventHandler()->ProcessEvent(event
))
967 wxMenuBar
*menuBar
= GetMenuBar();
970 wxString
helpString(menuBar
->GetHelpString(id
));
971 if (helpString
!= "")
972 SetStatusText(helpString
);
979 wxMenuBar
*wxFrame::GetMenuBar(void) const
981 return m_frameMenuBar
;
984 void wxFrame::Centre(const int direction
)
986 int display_width
, display_height
, width
, height
, x
, y
;
987 wxDisplaySize(&display_width
, &display_height
);
989 GetSize(&width
, &height
);
992 if (direction
& wxHORIZONTAL
)
993 x
= (int)((display_width
- width
)/2);
994 if (direction
& wxVERTICAL
)
995 y
= (int)((display_height
- height
)/2);
997 SetSize(x
, y
, width
, height
);
1000 // Call this to simulate a menu command
1001 void wxFrame::Command(int id
)
1006 void wxFrame::ProcessCommand(int id
)
1008 wxCommandEvent
commandEvent(wxEVENT_TYPE_MENU_COMMAND
, id
);
1009 commandEvent
.SetInt( id
);
1010 commandEvent
.SetEventObject( this );
1012 wxMenuBar
*bar
= GetMenuBar() ;
1016 // Motif does the job by itself!!
1018 wxMenuItem
*item
= bar
->FindItemForId(id
) ;
1019 if (item
&& item
->IsCheckable())
1021 //wxDebugMsg("Toggling id %d\n",id) ;
1022 bar
->Check(id
,!bar
->Checked(id
)) ;
1025 if (!ProcessEvent(commandEvent
))
1026 OldOnMenuCommand(id
);
1029 void wxFrame::OnIdle(wxIdleEvent
& event
)
1034 // Query app for menu item updates (called from OnIdle)
1035 void wxFrame::DoMenuUpdates(void)
1037 wxMenuBar
* bar
= GetMenuBar();
1042 for (i
= 0; i
< bar
->m_menuCount
; i
++)
1044 wxMenu
* menu
= bar
->m_menus
[i
];
1046 DoMenuUpdates(menu
);
1050 void wxFrame::DoMenuUpdates(wxMenu
* menu
)
1052 wxNode
* node
= menu
->m_menuItems
.First();
1055 wxMenuItem
* item
= (wxMenuItem
*) node
->Data();
1056 if ( !item
->IsSeparator() )
1058 wxWindowID id
= item
->GetId();
1059 wxUpdateUIEvent
event(id
);
1060 event
.SetEventObject( this );
1062 if (GetEventHandler()->ProcessEvent(event
))
1064 if (event
.GetSetText())
1065 menu
->SetLabel(id
, event
.GetText());
1066 if (event
.GetSetChecked())
1067 menu
->Check(id
, event
.GetChecked());
1068 if (event
.GetSetEnabled())
1069 menu
->Enable(id
, event
.GetEnabled());
1072 if (item
->GetSubMenu())
1073 DoMenuUpdates(item
->GetSubMenu());
1075 node
= node
->Next();