1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: univ/window.cpp
3 // Purpose: implementation of extra wxWindow methods for wxUniv port
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
21 #pragma implementation "univwindow.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/window.h"
34 #include "wx/dcclient.h"
35 #include "wx/dcmemory.h"
37 #include "wx/scrolbar.h"
42 #include "wx/univ/colschem.h"
43 #include "wx/univ/renderer.h"
44 #include "wx/univ/theme.h"
50 // turn Refresh() debugging on/off
51 #define WXDEBUG_REFRESH
54 #undef WXDEBUG_REFRESH
57 // ============================================================================
59 // ============================================================================
61 // ----------------------------------------------------------------------------
63 // ----------------------------------------------------------------------------
65 // we can't use wxWindowNative here as it won't be expanded inside the macro
66 #if defined(__WXMSW__)
67 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowMSW
)
68 #elif defined(__WXGTK__)
69 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowGTK
)
70 #elif defined(__WXMGL__)
71 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowMGL
)
74 BEGIN_EVENT_TABLE(wxWindow
, wxWindowNative
)
75 EVT_SIZE(wxWindow::OnSize
)
77 #if wxUSE_ACCEL || wxUSE_MENUS
78 EVT_KEY_DOWN(wxWindow::OnKeyDown
)
82 EVT_CHAR(wxWindow::OnChar
)
83 EVT_KEY_UP(wxWindow::OnKeyUp
)
86 EVT_PAINT(wxWindow::OnPaint
)
87 EVT_NC_PAINT(wxWindow::OnNcPaint
)
88 EVT_ERASE_BACKGROUND(wxWindow::OnErase
)
91 // ----------------------------------------------------------------------------
93 // ----------------------------------------------------------------------------
98 m_scrollbarHorz
= (wxScrollBar
*)NULL
;
102 m_renderer
= wxTheme::Get()->GetRenderer();
105 bool wxWindow::Create(wxWindow
*parent
,
110 const wxString
& name
)
112 // we add wxCLIP_CHILDREN to get the same ("natural") behaviour under MSW
113 // as under the other platforms
114 if ( !wxWindowNative::Create(parent
, id
, pos
, size
,
115 style
| wxCLIP_CHILDREN
,
121 // if we should always have the scrollbar, do show it
122 if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
124 m_scrollbarVert
= new wxScrollBar(this, -1,
125 wxDefaultPosition
, wxDefaultSize
,
129 PositionScrollbars();
132 // the colours/fonts are default
140 // ----------------------------------------------------------------------------
142 // ----------------------------------------------------------------------------
144 void wxWindow::SetBackground(const wxBitmap
& bitmap
,
149 m_alignBgBitmap
= alignment
;
150 m_stretchBgBitmap
= stretch
;
153 const wxBitmap
& wxWindow::GetBackgroundBitmap(int *alignment
,
154 wxStretch
*stretch
) const
156 if ( m_bitmapBg
.Ok() )
159 *alignment
= m_alignBgBitmap
;
161 *stretch
= m_stretchBgBitmap
;
167 // ----------------------------------------------------------------------------
169 // ----------------------------------------------------------------------------
171 // the event handler executed when the window background must be painted
172 void wxWindow::OnErase(wxEraseEvent
& event
)
181 DoDrawBackground(*event
.GetDC());
183 // if we have both scrollbars, we also have a square in the corner between
184 // them which we must paint
185 if ( m_scrollbarVert
&& m_scrollbarHorz
)
187 wxSize size
= GetSize();
188 wxRect rectClient
= GetClientRect(),
189 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
192 rectCorner
.x
= rectClient
.GetRight() + 1;
193 rectCorner
.y
= rectClient
.GetBottom() + 1;
194 rectCorner
.SetRight(size
.x
- rectBorder
.width
);
195 rectCorner
.SetBottom(size
.y
- rectBorder
.height
);
197 if ( GetUpdateRegion().Contains(rectCorner
) )
199 m_renderer
->DrawScrollCorner(*event
.GetDC(), rectCorner
);
204 // the event handlers executed when the window must be repainted
205 void wxWindow::OnNcPaint(wxPaintEvent
& event
)
209 // get the window rect
211 wxSize size
= GetSize();
215 rect
.height
= size
.y
;
217 // if the scrollbars are outside the border, we must adjust the rect to
219 if ( !m_renderer
->AreScrollbarsInsideBorder() )
221 wxScrollBar
*scrollbar
= GetScrollbar(wxVERTICAL
);
223 rect
.width
-= scrollbar
->GetSize().x
;
225 scrollbar
= GetScrollbar(wxHORIZONTAL
);
227 rect
.height
-= scrollbar
->GetSize().y
;
230 // get the DC and draw the border on it
232 DoDrawBorder(dc
, rect
);
236 void wxWindow::OnPaint(wxPaintEvent
& event
)
240 // it is a native control which paints itself
245 // get the DC to use and create renderer on it
247 wxControlRenderer
renderer(this, dc
, m_renderer
);
254 bool wxWindow::DoDrawBackground(wxDC
& dc
)
256 // FIXME: leaving this code in leads to partial bg redraws sometimes under
260 rect
= GetUpdateRegion().GetBox();
261 if ( !rect
.width
&& !rect
.height
)
264 wxSize size
= GetSize();
266 rect
.height
= size
.y
;
269 if ( GetBackgroundBitmap().Ok() )
271 // get the bitmap and the flags
274 wxBitmap bmp
= GetBackgroundBitmap(&alignment
, &stretch
);
275 wxControlRenderer::DrawBitmap(dc
, bmp
, rect
, alignment
, stretch
);
277 else // just fill it with bg colour if no bitmap
279 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this),
280 rect
, GetStateFlags());
286 void wxWindow::EraseBackground(wxDC
& dc
, const wxRect
& rect
)
288 // TODO: handle bg bitmaps here!
290 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this), rect
, GetStateFlags());
293 void wxWindow::DoDrawBorder(wxDC
& dc
, const wxRect
& rect
)
295 // draw outline unless the update region is enitrely inside it in which
296 // case we don't need to do it
297 #if 0 // doesn't seem to work, why?
298 if ( wxRegion(rect
).Contains(GetUpdateRegion().GetBox()) != wxInRegion
)
301 m_renderer
->DrawBorder(dc
, GetBorder(), rect
, GetStateFlags());
305 void wxWindow::DoDraw(wxControlRenderer
*renderer
)
309 void wxWindow::Refresh(bool eraseBackground
, const wxRect
*rectClient
)
312 wxPoint pt
= GetClientAreaOrigin();
314 wxSize size
= GetClientSize();
318 rectWin
= *rectClient
;
320 // don't refresh anything beyond the client area (scrollbars for
322 if ( rectWin
.GetRight() > size
.x
)
323 rectWin
.SetRight(size
.x
);
324 if ( rectWin
.GetBottom() > size
.y
)
325 rectWin
.SetBottom(size
.y
);
329 else // refresh the entire client area
333 rectWin
.width
= size
.x
;
334 rectWin
.height
= size
.y
;
338 #ifdef WXDEBUG_REFRESH
339 static bool s_refreshDebug
= FALSE
;
340 if ( s_refreshDebug
)
343 dc
.SetBrush(*wxCYAN_BRUSH
);
344 dc
.SetPen(*wxTRANSPARENT_PEN
);
345 dc
.DrawRectangle(rectWin
);
347 // under Unix we use "--sync" X option for this
348 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
353 #endif // WXDEBUG_REFRESH
355 wxWindowNative::Refresh(eraseBackground
, &rectWin
);
358 // ----------------------------------------------------------------------------
360 // ----------------------------------------------------------------------------
362 bool wxWindow::Enable(bool enable
)
364 if ( !wxWindowNative::Enable(enable
) )
367 // disabled window can't keep focus
368 if ( FindFocus() == this )
370 GetParent()->SetFocus();
375 // a window with renderer is drawn by ourselves and it has to be
376 // refreshed to reflect its new status
383 bool wxWindow::IsFocused() const
385 wxWindow
*self
= wxConstCast(this, wxWindow
);
386 return self
->FindFocus() == self
;
389 bool wxWindow::IsPressed() const
394 bool wxWindow::IsDefault() const
399 bool wxWindow::IsCurrent() const
404 bool wxWindow::SetCurrent(bool doit
)
406 if ( doit
== m_isCurrent
)
411 if ( CanBeHighlighted() )
417 int wxWindow::GetStateFlags() const
421 flags
|= wxCONTROL_DISABLED
;
423 // the following states are only possible if our application is active - if
424 // it is not, even our default/focused controls shouldn't appear as such
425 if ( wxTheApp
->IsActive() )
428 flags
|= wxCONTROL_CURRENT
;
430 flags
|= wxCONTROL_FOCUSED
;
432 flags
|= wxCONTROL_PRESSED
;
434 flags
|= wxCONTROL_ISDEFAULT
;
440 // ----------------------------------------------------------------------------
442 // ----------------------------------------------------------------------------
444 void wxWindow::OnSize(wxSizeEvent
& event
)
446 if ( m_scrollbarVert
|| m_scrollbarHorz
)
448 PositionScrollbars();
454 wxSize
wxWindow::DoGetBestSize() const
456 return AdjustSize(DoGetBestClientSize());
459 wxSize
wxWindow::DoGetBestClientSize() const
461 return wxWindowNative::DoGetBestSize();
464 wxSize
wxWindow::AdjustSize(const wxSize
& size
) const
468 m_renderer
->AdjustSize(&sz
, this);
472 wxPoint
wxWindow::GetClientAreaOrigin() const
474 wxPoint pt
= wxWindowBase::GetClientAreaOrigin();
477 pt
+= m_renderer
->GetBorderDimensions(GetBorder()).GetPosition();
482 void wxWindow::DoGetClientSize(int *width
, int *height
) const
484 // if it is a native window, we assume it handles the scrollbars itself
485 // too - and if it doesn't, there is not much we can do
488 wxWindowNative::DoGetClientSize(width
, height
);
494 wxWindowNative::DoGetClientSize(&w
, &h
);
496 // we assume that the scrollbars are positioned correctly (by a previous
497 // call to PositionScrollbars()) here
501 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
503 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
507 // in any case, take account of the scrollbar
508 if ( m_scrollbarVert
)
509 w
-= m_scrollbarVert
->GetSize().x
;
511 // if we don't have scrollbar or if it is outside the border (and not
512 // blended into it), take account of the right border as well
513 if ( !m_scrollbarVert
|| inside
)
514 w
-= rectBorder
.width
;
516 // and always account for the left border
517 *width
= w
- rectBorder
.x
;
519 // we shouldn't return invalid width
526 if ( m_scrollbarHorz
)
527 h
-= m_scrollbarHorz
->GetSize().y
;
529 if ( !m_scrollbarHorz
|| inside
)
530 h
-= rectBorder
.height
;
532 *height
= h
- rectBorder
.y
;
534 // we shouldn't return invalid height
540 void wxWindow::DoSetClientSize(int width
, int height
)
542 // take into account the borders
543 wxRect rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
544 width
+= rectBorder
.x
;
545 height
+= rectBorder
.y
;
547 // and the scrollbars (as they may be offset into the border, use the
548 // scrollbar position, not size - this supposes that PositionScrollbars()
549 // had been called before)
550 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
551 wxSize size
= GetSize();
552 if ( m_scrollbarVert
)
553 width
+= size
.x
- m_scrollbarVert
->GetPosition().x
;
554 if ( !m_scrollbarVert
|| inside
)
555 width
+= rectBorder
.width
;
557 if ( m_scrollbarHorz
)
558 height
+= size
.y
- m_scrollbarHorz
->GetPosition().y
;
559 if ( !m_scrollbarHorz
|| inside
)
560 height
+= rectBorder
.height
;
562 wxWindowNative::DoSetClientSize(width
, height
);
565 wxHitTest
wxWindow::DoHitTest(wxCoord x
, wxCoord y
) const
567 wxHitTest ht
= wxWindowNative::DoHitTest(x
, y
);
568 if ( ht
== wxHT_WINDOW_INSIDE
)
570 if ( m_scrollbarVert
&& x
>= m_scrollbarVert
->GetPosition().x
)
572 // it can still be changed below because it may also be the corner
573 ht
= wxHT_WINDOW_VERT_SCROLLBAR
;
576 if ( m_scrollbarHorz
&& y
>= m_scrollbarHorz
->GetPosition().y
)
578 ht
= ht
== wxHT_WINDOW_VERT_SCROLLBAR
? wxHT_WINDOW_CORNER
579 : wxHT_WINDOW_HORZ_SCROLLBAR
;
586 // ----------------------------------------------------------------------------
587 // scrolling: we implement it entirely ourselves except for ScrollWindow()
588 // function which is supposed to be (efficiently) implemented by the native
590 // ----------------------------------------------------------------------------
592 void wxWindow::RefreshScrollbars()
594 if ( m_scrollbarHorz
)
595 m_scrollbarHorz
->Refresh();
597 if ( m_scrollbarVert
)
598 m_scrollbarVert
->Refresh();
601 void wxWindow::PositionScrollbars()
603 // do not use GetClientSize/Rect as it relies on the scrollbars being
604 // correctly positioned
606 wxSize size
= GetSize();
607 wxBorder border
= GetBorder();
608 wxRect rectBorder
= m_renderer
->GetBorderDimensions(border
);
609 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
611 int height
= m_scrollbarHorz
? m_scrollbarHorz
->GetSize().y
: 0;
612 int width
= m_scrollbarVert
? m_scrollbarVert
->GetSize().x
: 0;
615 if ( m_scrollbarVert
)
617 rectBar
.x
= size
.x
- width
;
619 rectBar
.x
-= rectBorder
.width
;
620 rectBar
.width
= width
;
623 rectBar
.y
+= rectBorder
.y
;
624 rectBar
.height
= size
.y
- height
;
626 rectBar
.height
-= rectBorder
.y
+ rectBorder
.height
;
628 m_scrollbarVert
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
631 if ( m_scrollbarHorz
)
633 rectBar
.y
= size
.y
- height
;
635 rectBar
.y
-= rectBorder
.height
;
636 rectBar
.height
= height
;
639 rectBar
.x
+= rectBorder
.x
;
640 rectBar
.width
= size
.x
- width
;
642 rectBar
.width
-= rectBorder
.x
+ rectBorder
.width
;
644 m_scrollbarHorz
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
650 void wxWindow::SetScrollbar(int orient
,
656 bool hasClientSizeChanged
= FALSE
;
657 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
663 scrollbar
= new wxScrollBar(this, -1,
664 wxDefaultPosition
, wxDefaultSize
,
665 orient
& wxVERTICAL
? wxSB_VERTICAL
667 if ( orient
& wxVERTICAL
)
668 m_scrollbarVert
= scrollbar
;
670 m_scrollbarHorz
= scrollbar
;
672 // the client area diminished as we created a scrollbar
673 hasClientSizeChanged
= TRUE
;
675 PositionScrollbars();
677 else if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
679 // we might have disabled it before
683 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
685 else // no range means no scrollbar
689 // wxALWAYS_SHOW_SB only applies to the vertical scrollbar
690 if ( (orient
& wxVERTICAL
) && (GetWindowStyle() & wxALWAYS_SHOW_SB
) )
692 // just disable the scrollbar
693 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
694 scrollbar
->Disable();
696 else // really remove the scrollbar
700 if ( orient
& wxVERTICAL
)
701 m_scrollbarVert
= NULL
;
703 m_scrollbarHorz
= NULL
;
705 // the client area increased as we removed a scrollbar
706 hasClientSizeChanged
= TRUE
;
708 // the size of the remaining scrollbar must be adjusted
709 if ( m_scrollbarHorz
|| m_scrollbarVert
)
711 PositionScrollbars();
717 // give the window a chance to relayout
718 if ( hasClientSizeChanged
)
720 wxSizeEvent
event(GetSize());
721 (void)GetEventHandler()->ProcessEvent(event
);
725 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
727 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
728 wxCHECK_RET( scrollbar
, _T("no scrollbar to set position for") );
730 scrollbar
->SetThumbPosition(pos
);
732 // VZ: I think we can safely ignore this as we always refresh it
733 // automatically whenever the value chanegs
740 int wxWindow::GetScrollPos(int orient
) const
742 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
743 return scrollbar
? scrollbar
->GetThumbPosition() : 0;
746 int wxWindow::GetScrollThumb(int orient
) const
748 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
749 return scrollbar
? scrollbar
->GetThumbSize() : 0;
752 int wxWindow::GetScrollRange(int orient
) const
754 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
755 return scrollbar
? scrollbar
->GetRange() : 0;
758 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
760 // before scrolling it, ensure that we don't have any unpainted areas
767 r
= ScrollNoRefresh(dx
, 0, rect
);
768 Refresh(TRUE
/* erase bkgnd */, &r
);
773 r
= ScrollNoRefresh(0, dy
, rect
);
774 Refresh(TRUE
/* erase bkgnd */, &r
);
778 wxRect
wxWindow::ScrollNoRefresh(int dx
, int dy
, const wxRect
*rectTotal
)
780 wxASSERT_MSG( !dx
|| !dy
, _T("can't be used for diag scrolling") );
782 // the rect to refresh (which we will calculate)
791 // calculate the part of the window which we can just redraw in the new
793 wxSize sizeTotal
= rectTotal
? rectTotal
->GetSize() : GetClientSize();
795 wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"),
796 sizeTotal
.x
, sizeTotal
.y
, dx
, dy
);
798 // the initial and end point of the region we move in client coords
799 wxPoint ptSource
, ptDest
;
802 ptSource
= rectTotal
->GetPosition();
803 ptDest
= rectTotal
->GetPosition();
806 // the size of this region
808 size
.x
= sizeTotal
.x
- abs(dx
);
809 size
.y
= sizeTotal
.y
- abs(dy
);
810 if ( size
.x
<= 0 || size
.y
<= 0 )
812 // just redraw everything as nothing of the displayed image will stay
813 wxLogTrace(_T("scroll"), _T("refreshing everything"));
815 rect
= rectTotal
? *rectTotal
: wxRect(0, 0, sizeTotal
.x
, sizeTotal
.y
);
817 else // move the part which doesn't change to the new location
819 // note that when we scroll the canvas in some direction we move the
820 // block which doesn't need to be refreshed in the opposite direction
824 // scroll to the right, move to the left
829 // scroll to the left, move to the right
835 // scroll down, move up
840 // scroll up, move down
845 // we need to hide the caret before moving or it will erase itself at
846 // the wrong (old) location
847 wxCaret
*caret
= GetCaret();
850 #endif // wxUSE_CARET
854 wxBitmap
bmp(size
.x
, size
.y
);
856 dcMem
.SelectObject(bmp
);
858 dcMem
.Blit(wxPoint(0, 0), size
, &dc
, ptSource
859 #if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT)
860 + GetClientAreaOrigin()
861 #endif // broken wxGTK wxDC::Blit
863 dc
.Blit(ptDest
, size
, &dcMem
, wxPoint(0, 0));
865 wxLogTrace(_T("scroll"),
866 _T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"),
867 ptSource
.x
, ptSource
.y
,
871 // and now repaint the uncovered area
873 // FIXME: We repaint the intersection of these rectangles twice - is
874 // it bad? I don't think so as it is rare to scroll the window
875 // diagonally anyhow and so adding extra logic to compute
876 // rectangle intersection is probably not worth the effort
885 // refresh the area along the right border
886 rect
.x
+= size
.x
+ dx
;
891 // refresh the area along the left border
895 rect
.height
= sizeTotal
.y
;
897 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
899 rect
.GetRight() + 1, rect
.GetBottom() + 1);
906 // refresh the area along the bottom border
907 rect
.y
+= size
.y
+ dy
;
912 // refresh the area along the top border
916 rect
.width
= sizeTotal
.x
;
918 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
920 rect
.GetRight() + 1, rect
.GetBottom() + 1);
926 #endif // wxUSE_CARET
932 // ----------------------------------------------------------------------------
934 // ----------------------------------------------------------------------------
936 bool wxWindow::SetBackgroundColour(const wxColour
& colour
)
938 if ( !wxWindowNative::SetBackgroundColour(colour
) )
946 bool wxWindow::SetForegroundColour(const wxColour
& colour
)
948 if ( !wxWindowNative::SetForegroundColour(colour
) )
956 bool wxWindow::SetFont(const wxFont
& font
)
958 if ( !wxWindowNative::SetFont(font
) )
966 // ----------------------------------------------------------------------------
968 // ----------------------------------------------------------------------------
970 struct WXDLLEXPORT wxWindowNext
974 } *wxWindow::ms_winCaptureNext
= NULL
;
976 void wxWindow::CaptureMouse()
978 wxWindow
*winOld
= GetCapture();
982 wxWindowNext
*item
= new wxWindowNext
;
984 item
->next
= ms_winCaptureNext
;
985 ms_winCaptureNext
= item
;
987 //else: no mouse capture to save
989 wxWindowNative::CaptureMouse();
992 void wxWindow::ReleaseMouse()
994 wxWindowNative::ReleaseMouse();
996 if ( ms_winCaptureNext
)
998 ms_winCaptureNext
->win
->CaptureMouse();
1000 wxWindowNext
*item
= ms_winCaptureNext
;
1001 ms_winCaptureNext
= item
->next
;
1004 //else: stack is empty, no previous capture
1007 // ----------------------------------------------------------------------------
1008 // accelerators and menu hot keys
1009 // ----------------------------------------------------------------------------
1012 // the last window over which Alt was pressed (used by OnKeyUp)
1013 wxWindow
*wxWindow::ms_winLastAltPress
= NULL
;
1014 #endif // wxUSE_MENUS
1016 #if wxUSE_ACCEL || wxUSE_MENUS
1018 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
1021 int key
= event
.GetKeyCode();
1022 if ( !event
.ControlDown() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1024 ms_winLastAltPress
= this;
1026 // it can't be an accel anyhow
1030 ms_winLastAltPress
= NULL
;
1031 #endif // wxUSE_MENUS
1034 for ( wxWindow
*win
= this; win
; win
= win
->GetParent() )
1036 int command
= win
->GetAcceleratorTable()->GetCommand(event
);
1037 if ( command
!= -1 )
1039 wxCommandEvent
eventCmd(wxEVT_COMMAND_MENU_SELECTED
, command
);
1040 if ( win
->GetEventHandler()->ProcessEvent(eventCmd
) )
1042 // skip "event.Skip()" below
1047 if ( win
->IsTopLevel() )
1049 // try the frame menu bar
1051 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1054 wxMenuBar
*menubar
= frame
->GetMenuBar();
1055 if ( menubar
&& menubar
->ProcessAccelEvent(event
) )
1057 // skip "event.Skip()" below
1061 #endif // wxUSE_MENUS
1063 // don't propagate accels from the child frame to the parent one
1067 #endif // wxUSE_ACCEL
1072 #endif // wxUSE_ACCEL
1076 wxMenuBar
*wxWindow::GetParentFrameMenuBar() const
1078 for ( const wxWindow
*win
= this; win
; win
= win
->GetParent() )
1080 if ( win
->IsTopLevel() )
1082 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1085 return frame
->GetMenuBar();
1088 // don't look further - we don't want to return the menubar of the
1097 void wxWindow::OnChar(wxKeyEvent
& event
)
1099 if ( event
.AltDown() && !event
.ControlDown() )
1101 int key
= event
.GetKeyCode();
1103 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1106 int item
= menubar
->FindNextItemForAccel(-1, key
);
1109 menubar
->PopupMenu((size_t)item
);
1111 // skip "event.Skip()" below
1120 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1122 int key
= event
.GetKeyCode();
1123 if ( !event
.HasModifiers() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1125 // only process Alt release specially if there were no other key
1126 // presses since Alt had been pressed and if both events happened in
1128 if ( ms_winLastAltPress
== this )
1130 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1131 if ( menubar
&& this != menubar
)
1133 menubar
->SelectMenu(0);
1142 // in any case reset it
1143 ms_winLastAltPress
= NULL
;
1146 #endif // wxUSE_MENUS