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 #if defined(WXDEBUG_REFRESH) && defined(__WXMSW__) && !defined(__WXMICROWIN__)
58 #include "wx/msw/private.h"
61 // ============================================================================
63 // ============================================================================
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
69 // we can't use wxWindowNative here as it won't be expanded inside the macro
70 #if defined(__WXMSW__)
71 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowMSW
)
72 #elif defined(__WXGTK__)
73 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowGTK
)
74 #elif defined(__WXMGL__)
75 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowMGL
)
78 BEGIN_EVENT_TABLE(wxWindow
, wxWindowNative
)
79 EVT_SIZE(wxWindow::OnSize
)
81 #if wxUSE_ACCEL || wxUSE_MENUS
82 EVT_KEY_DOWN(wxWindow::OnKeyDown
)
86 EVT_CHAR(wxWindow::OnChar
)
87 EVT_KEY_UP(wxWindow::OnKeyUp
)
90 EVT_PAINT(wxWindow::OnPaint
)
91 EVT_NC_PAINT(wxWindow::OnNcPaint
)
92 EVT_ERASE_BACKGROUND(wxWindow::OnErase
)
95 // ----------------------------------------------------------------------------
97 // ----------------------------------------------------------------------------
102 m_scrollbarHorz
= (wxScrollBar
*)NULL
;
106 m_renderer
= wxTheme::Get()->GetRenderer();
109 bool wxWindow::Create(wxWindow
*parent
,
114 const wxString
& name
)
116 // we add wxCLIP_CHILDREN to get the same ("natural") behaviour under MSW
117 // as under the other platforms
118 if ( !wxWindowNative::Create(parent
, id
, pos
, size
,
119 style
| wxCLIP_CHILDREN
,
125 // if we should always have the scrollbar, do show it
126 if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
128 m_scrollbarVert
= new wxScrollBar(this, -1,
129 wxDefaultPosition
, wxDefaultSize
,
133 PositionScrollbars();
136 // the colours/fonts are default
144 // ----------------------------------------------------------------------------
146 // ----------------------------------------------------------------------------
148 void wxWindow::SetBackground(const wxBitmap
& bitmap
,
153 m_alignBgBitmap
= alignment
;
154 m_stretchBgBitmap
= stretch
;
157 const wxBitmap
& wxWindow::GetBackgroundBitmap(int *alignment
,
158 wxStretch
*stretch
) const
160 if ( m_bitmapBg
.Ok() )
163 *alignment
= m_alignBgBitmap
;
165 *stretch
= m_stretchBgBitmap
;
171 // ----------------------------------------------------------------------------
173 // ----------------------------------------------------------------------------
175 // the event handler executed when the window background must be painted
176 void wxWindow::OnErase(wxEraseEvent
& event
)
185 DoDrawBackground(*event
.GetDC());
187 // if we have both scrollbars, we also have a square in the corner between
188 // them which we must paint
189 if ( m_scrollbarVert
&& m_scrollbarHorz
)
191 wxSize size
= GetSize();
192 wxRect rectClient
= GetClientRect(),
193 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
196 rectCorner
.x
= rectClient
.GetRight() + 1;
197 rectCorner
.y
= rectClient
.GetBottom() + 1;
198 rectCorner
.SetRight(size
.x
- rectBorder
.width
);
199 rectCorner
.SetBottom(size
.y
- rectBorder
.height
);
201 if ( GetUpdateRegion().Contains(rectCorner
) )
203 m_renderer
->DrawScrollCorner(*event
.GetDC(), rectCorner
);
208 // the event handlers executed when the window must be repainted
209 void wxWindow::OnNcPaint(wxPaintEvent
& event
)
213 // get the window rect
215 wxSize size
= GetSize();
219 rect
.height
= size
.y
;
221 // if the scrollbars are outside the border, we must adjust the rect to
223 if ( !m_renderer
->AreScrollbarsInsideBorder() )
225 wxScrollBar
*scrollbar
= GetScrollbar(wxVERTICAL
);
227 rect
.width
-= scrollbar
->GetSize().x
;
229 scrollbar
= GetScrollbar(wxHORIZONTAL
);
231 rect
.height
-= scrollbar
->GetSize().y
;
234 // get the DC and draw the border on it
236 DoDrawBorder(dc
, rect
);
240 void wxWindow::OnPaint(wxPaintEvent
& event
)
244 // it is a native control which paints itself
249 // get the DC to use and create renderer on it
251 wxControlRenderer
renderer(this, dc
, m_renderer
);
258 bool wxWindow::DoDrawBackground(wxDC
& dc
)
260 // FIXME: leaving this code in leads to partial bg redraws sometimes under
264 rect
= GetUpdateRegion().GetBox();
265 if ( !rect
.width
&& !rect
.height
)
268 wxSize size
= GetSize();
270 rect
.height
= size
.y
;
273 if ( GetBackgroundBitmap().Ok() )
275 // get the bitmap and the flags
278 wxBitmap bmp
= GetBackgroundBitmap(&alignment
, &stretch
);
279 wxControlRenderer::DrawBitmap(dc
, bmp
, rect
, alignment
, stretch
);
281 else // just fill it with bg colour if no bitmap
283 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this),
284 rect
, GetStateFlags());
290 void wxWindow::EraseBackground(wxDC
& dc
, const wxRect
& rect
)
292 // TODO: handle bg bitmaps here!
294 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this), rect
, GetStateFlags());
297 void wxWindow::DoDrawBorder(wxDC
& dc
, const wxRect
& rect
)
299 // draw outline unless the update region is enitrely inside it in which
300 // case we don't need to do it
301 #if 0 // doesn't seem to work, why?
302 if ( wxRegion(rect
).Contains(GetUpdateRegion().GetBox()) != wxInRegion
)
305 m_renderer
->DrawBorder(dc
, GetBorder(), rect
, GetStateFlags());
309 void wxWindow::DoDraw(wxControlRenderer
*renderer
)
313 void wxWindow::Refresh(bool eraseBackground
, const wxRect
*rectClient
)
316 wxPoint pt
= GetClientAreaOrigin();
318 wxSize size
= GetClientSize();
322 rectWin
= *rectClient
;
324 // don't refresh anything beyond the client area (scrollbars for
326 if ( rectWin
.GetRight() > size
.x
)
327 rectWin
.SetRight(size
.x
);
328 if ( rectWin
.GetBottom() > size
.y
)
329 rectWin
.SetBottom(size
.y
);
333 else // refresh the entire client area
337 rectWin
.width
= size
.x
;
338 rectWin
.height
= size
.y
;
342 #ifdef WXDEBUG_REFRESH
343 static bool s_refreshDebug
= FALSE
;
344 if ( s_refreshDebug
)
347 dc
.SetBrush(*wxCYAN_BRUSH
);
348 dc
.SetPen(*wxTRANSPARENT_PEN
);
349 dc
.DrawRectangle(rectWin
);
351 // under Unix we use "--sync" X option for this
352 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
357 #endif // WXDEBUG_REFRESH
359 wxWindowNative::Refresh(eraseBackground
, &rectWin
);
362 // ----------------------------------------------------------------------------
364 // ----------------------------------------------------------------------------
366 bool wxWindow::Enable(bool enable
)
368 if ( !wxWindowNative::Enable(enable
) )
371 // disabled window can't keep focus
372 if ( FindFocus() == this )
374 GetParent()->SetFocus();
379 // a window with renderer is drawn by ourselves and it has to be
380 // refreshed to reflect its new status
387 bool wxWindow::IsFocused() const
389 wxWindow
*self
= wxConstCast(this, wxWindow
);
390 return self
->FindFocus() == self
;
393 bool wxWindow::IsPressed() const
398 bool wxWindow::IsDefault() const
403 bool wxWindow::IsCurrent() const
408 bool wxWindow::SetCurrent(bool doit
)
410 if ( doit
== m_isCurrent
)
415 if ( CanBeHighlighted() )
421 int wxWindow::GetStateFlags() const
425 flags
|= wxCONTROL_DISABLED
;
427 // the following states are only possible if our application is active - if
428 // it is not, even our default/focused controls shouldn't appear as such
429 if ( wxTheApp
->IsActive() )
432 flags
|= wxCONTROL_CURRENT
;
434 flags
|= wxCONTROL_FOCUSED
;
436 flags
|= wxCONTROL_PRESSED
;
438 flags
|= wxCONTROL_ISDEFAULT
;
444 // ----------------------------------------------------------------------------
446 // ----------------------------------------------------------------------------
448 void wxWindow::OnSize(wxSizeEvent
& event
)
450 if ( m_scrollbarVert
|| m_scrollbarHorz
)
452 PositionScrollbars();
458 wxSize
wxWindow::DoGetBestSize() const
460 return AdjustSize(DoGetBestClientSize());
463 wxSize
wxWindow::DoGetBestClientSize() const
465 return wxWindowNative::DoGetBestSize();
468 wxSize
wxWindow::AdjustSize(const wxSize
& size
) const
472 m_renderer
->AdjustSize(&sz
, this);
476 wxPoint
wxWindow::GetClientAreaOrigin() const
478 wxPoint pt
= wxWindowBase::GetClientAreaOrigin();
481 pt
+= m_renderer
->GetBorderDimensions(GetBorder()).GetPosition();
486 void wxWindow::DoGetClientSize(int *width
, int *height
) const
488 // if it is a native window, we assume it handles the scrollbars itself
489 // too - and if it doesn't, there is not much we can do
492 wxWindowNative::DoGetClientSize(width
, height
);
498 wxWindowNative::DoGetClientSize(&w
, &h
);
500 // we assume that the scrollbars are positioned correctly (by a previous
501 // call to PositionScrollbars()) here
505 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
507 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
511 // in any case, take account of the scrollbar
512 if ( m_scrollbarVert
)
513 w
-= m_scrollbarVert
->GetSize().x
;
515 // if we don't have scrollbar or if it is outside the border (and not
516 // blended into it), take account of the right border as well
517 if ( !m_scrollbarVert
|| inside
)
518 w
-= rectBorder
.width
;
520 // and always account for the left border
521 *width
= w
- rectBorder
.x
;
523 // we shouldn't return invalid width
530 if ( m_scrollbarHorz
)
531 h
-= m_scrollbarHorz
->GetSize().y
;
533 if ( !m_scrollbarHorz
|| inside
)
534 h
-= rectBorder
.height
;
536 *height
= h
- rectBorder
.y
;
538 // we shouldn't return invalid height
544 void wxWindow::DoSetClientSize(int width
, int height
)
546 // take into account the borders
547 wxRect rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
548 width
+= rectBorder
.x
;
549 height
+= rectBorder
.y
;
551 // and the scrollbars (as they may be offset into the border, use the
552 // scrollbar position, not size - this supposes that PositionScrollbars()
553 // had been called before)
554 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
555 wxSize size
= GetSize();
556 if ( m_scrollbarVert
)
557 width
+= size
.x
- m_scrollbarVert
->GetPosition().x
;
558 if ( !m_scrollbarVert
|| inside
)
559 width
+= rectBorder
.width
;
561 if ( m_scrollbarHorz
)
562 height
+= size
.y
- m_scrollbarHorz
->GetPosition().y
;
563 if ( !m_scrollbarHorz
|| inside
)
564 height
+= rectBorder
.height
;
566 wxWindowNative::DoSetClientSize(width
, height
);
569 wxHitTest
wxWindow::DoHitTest(wxCoord x
, wxCoord y
) const
571 wxHitTest ht
= wxWindowNative::DoHitTest(x
, y
);
572 if ( ht
== wxHT_WINDOW_INSIDE
)
574 if ( m_scrollbarVert
&& x
>= m_scrollbarVert
->GetPosition().x
)
576 // it can still be changed below because it may also be the corner
577 ht
= wxHT_WINDOW_VERT_SCROLLBAR
;
580 if ( m_scrollbarHorz
&& y
>= m_scrollbarHorz
->GetPosition().y
)
582 ht
= ht
== wxHT_WINDOW_VERT_SCROLLBAR
? wxHT_WINDOW_CORNER
583 : wxHT_WINDOW_HORZ_SCROLLBAR
;
590 // ----------------------------------------------------------------------------
591 // scrolling: we implement it entirely ourselves except for ScrollWindow()
592 // function which is supposed to be (efficiently) implemented by the native
594 // ----------------------------------------------------------------------------
596 void wxWindow::RefreshScrollbars()
598 if ( m_scrollbarHorz
)
599 m_scrollbarHorz
->Refresh();
601 if ( m_scrollbarVert
)
602 m_scrollbarVert
->Refresh();
605 void wxWindow::PositionScrollbars()
607 // do not use GetClientSize/Rect as it relies on the scrollbars being
608 // correctly positioned
610 wxSize size
= GetSize();
611 wxBorder border
= GetBorder();
612 wxRect rectBorder
= m_renderer
->GetBorderDimensions(border
);
613 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
615 int height
= m_scrollbarHorz
? m_scrollbarHorz
->GetSize().y
: 0;
616 int width
= m_scrollbarVert
? m_scrollbarVert
->GetSize().x
: 0;
619 if ( m_scrollbarVert
)
621 rectBar
.x
= size
.x
- width
;
623 rectBar
.x
-= rectBorder
.width
;
624 rectBar
.width
= width
;
627 rectBar
.y
+= rectBorder
.y
;
628 rectBar
.height
= size
.y
- height
;
630 rectBar
.height
-= rectBorder
.y
+ rectBorder
.height
;
632 m_scrollbarVert
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
635 if ( m_scrollbarHorz
)
637 rectBar
.y
= size
.y
- height
;
639 rectBar
.y
-= rectBorder
.height
;
640 rectBar
.height
= height
;
643 rectBar
.x
+= rectBorder
.x
;
644 rectBar
.width
= size
.x
- width
;
646 rectBar
.width
-= rectBorder
.x
+ rectBorder
.width
;
648 m_scrollbarHorz
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
654 void wxWindow::SetScrollbar(int orient
,
660 bool hasClientSizeChanged
= FALSE
;
661 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
667 scrollbar
= new wxScrollBar(this, -1,
668 wxDefaultPosition
, wxDefaultSize
,
669 orient
& wxVERTICAL
? wxSB_VERTICAL
671 if ( orient
& wxVERTICAL
)
672 m_scrollbarVert
= scrollbar
;
674 m_scrollbarHorz
= scrollbar
;
676 // the client area diminished as we created a scrollbar
677 hasClientSizeChanged
= TRUE
;
679 PositionScrollbars();
681 else if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
683 // we might have disabled it before
687 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
689 else // no range means no scrollbar
693 // wxALWAYS_SHOW_SB only applies to the vertical scrollbar
694 if ( (orient
& wxVERTICAL
) && (GetWindowStyle() & wxALWAYS_SHOW_SB
) )
696 // just disable the scrollbar
697 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
698 scrollbar
->Disable();
700 else // really remove the scrollbar
704 if ( orient
& wxVERTICAL
)
705 m_scrollbarVert
= NULL
;
707 m_scrollbarHorz
= NULL
;
709 // the client area increased as we removed a scrollbar
710 hasClientSizeChanged
= TRUE
;
712 // the size of the remaining scrollbar must be adjusted
713 if ( m_scrollbarHorz
|| m_scrollbarVert
)
715 PositionScrollbars();
721 // give the window a chance to relayout
722 if ( hasClientSizeChanged
)
724 wxSizeEvent
event(GetSize());
725 (void)GetEventHandler()->ProcessEvent(event
);
729 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
731 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
732 wxCHECK_RET( scrollbar
, _T("no scrollbar to set position for") );
734 scrollbar
->SetThumbPosition(pos
);
736 // VZ: I think we can safely ignore this as we always refresh it
737 // automatically whenever the value chanegs
744 int wxWindow::GetScrollPos(int orient
) const
746 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
747 return scrollbar
? scrollbar
->GetThumbPosition() : 0;
750 int wxWindow::GetScrollThumb(int orient
) const
752 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
753 return scrollbar
? scrollbar
->GetThumbSize() : 0;
756 int wxWindow::GetScrollRange(int orient
) const
758 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
759 return scrollbar
? scrollbar
->GetRange() : 0;
762 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
764 // before scrolling it, ensure that we don't have any unpainted areas
771 r
= ScrollNoRefresh(dx
, 0, rect
);
772 Refresh(TRUE
/* erase bkgnd */, &r
);
777 r
= ScrollNoRefresh(0, dy
, rect
);
778 Refresh(TRUE
/* erase bkgnd */, &r
);
782 wxRect
wxWindow::ScrollNoRefresh(int dx
, int dy
, const wxRect
*rectTotal
)
784 wxASSERT_MSG( !dx
|| !dy
, _T("can't be used for diag scrolling") );
786 // the rect to refresh (which we will calculate)
795 // calculate the part of the window which we can just redraw in the new
797 wxSize sizeTotal
= rectTotal
? rectTotal
->GetSize() : GetClientSize();
799 wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"),
800 sizeTotal
.x
, sizeTotal
.y
, dx
, dy
);
802 // the initial and end point of the region we move in client coords
803 wxPoint ptSource
, ptDest
;
806 ptSource
= rectTotal
->GetPosition();
807 ptDest
= rectTotal
->GetPosition();
810 // the size of this region
812 size
.x
= sizeTotal
.x
- abs(dx
);
813 size
.y
= sizeTotal
.y
- abs(dy
);
814 if ( size
.x
<= 0 || size
.y
<= 0 )
816 // just redraw everything as nothing of the displayed image will stay
817 wxLogTrace(_T("scroll"), _T("refreshing everything"));
819 rect
= rectTotal
? *rectTotal
: wxRect(0, 0, sizeTotal
.x
, sizeTotal
.y
);
821 else // move the part which doesn't change to the new location
823 // note that when we scroll the canvas in some direction we move the
824 // block which doesn't need to be refreshed in the opposite direction
828 // scroll to the right, move to the left
833 // scroll to the left, move to the right
839 // scroll down, move up
844 // scroll up, move down
849 // we need to hide the caret before moving or it will erase itself at
850 // the wrong (old) location
851 wxCaret
*caret
= GetCaret();
854 #endif // wxUSE_CARET
858 wxBitmap
bmp(size
.x
, size
.y
);
860 dcMem
.SelectObject(bmp
);
862 dcMem
.Blit(wxPoint(0, 0), size
, &dc
, ptSource
863 #if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT)
864 + GetClientAreaOrigin()
865 #endif // broken wxGTK wxDC::Blit
867 dc
.Blit(ptDest
, size
, &dcMem
, wxPoint(0, 0));
869 wxLogTrace(_T("scroll"),
870 _T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"),
871 ptSource
.x
, ptSource
.y
,
875 // and now repaint the uncovered area
877 // FIXME: We repaint the intersection of these rectangles twice - is
878 // it bad? I don't think so as it is rare to scroll the window
879 // diagonally anyhow and so adding extra logic to compute
880 // rectangle intersection is probably not worth the effort
889 // refresh the area along the right border
890 rect
.x
+= size
.x
+ dx
;
895 // refresh the area along the left border
899 rect
.height
= sizeTotal
.y
;
901 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
903 rect
.GetRight() + 1, rect
.GetBottom() + 1);
910 // refresh the area along the bottom border
911 rect
.y
+= size
.y
+ dy
;
916 // refresh the area along the top border
920 rect
.width
= sizeTotal
.x
;
922 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
924 rect
.GetRight() + 1, rect
.GetBottom() + 1);
930 #endif // wxUSE_CARET
936 // ----------------------------------------------------------------------------
938 // ----------------------------------------------------------------------------
940 bool wxWindow::SetBackgroundColour(const wxColour
& colour
)
942 if ( !wxWindowNative::SetBackgroundColour(colour
) )
950 bool wxWindow::SetForegroundColour(const wxColour
& colour
)
952 if ( !wxWindowNative::SetForegroundColour(colour
) )
960 bool wxWindow::SetFont(const wxFont
& font
)
962 if ( !wxWindowNative::SetFont(font
) )
970 // ----------------------------------------------------------------------------
972 // ----------------------------------------------------------------------------
974 struct WXDLLEXPORT wxWindowNext
978 } *wxWindow::ms_winCaptureNext
= NULL
;
980 void wxWindow::CaptureMouse()
982 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(0x%08x)"), this);
984 wxWindow
*winOld
= GetCapture();
988 wxWindowNext
*item
= new wxWindowNext
;
990 item
->next
= ms_winCaptureNext
;
991 ms_winCaptureNext
= item
;
993 //else: no mouse capture to save
995 wxWindowNative::CaptureMouse();
998 void wxWindow::ReleaseMouse()
1000 wxWindowNative::ReleaseMouse();
1002 if ( ms_winCaptureNext
)
1004 ms_winCaptureNext
->win
->CaptureMouse();
1006 wxWindowNext
*item
= ms_winCaptureNext
;
1007 ms_winCaptureNext
= item
->next
;
1010 //else: stack is empty, no previous capture
1012 wxLogTrace(_T("mousecapture"),
1013 _T("After ReleaseMouse() mouse is captured by 0x%08x"),
1017 // ----------------------------------------------------------------------------
1018 // accelerators and menu hot keys
1019 // ----------------------------------------------------------------------------
1022 // the last window over which Alt was pressed (used by OnKeyUp)
1023 wxWindow
*wxWindow::ms_winLastAltPress
= NULL
;
1024 #endif // wxUSE_MENUS
1026 #if wxUSE_ACCEL || wxUSE_MENUS
1028 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
1031 int key
= event
.GetKeyCode();
1032 if ( !event
.ControlDown() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1034 ms_winLastAltPress
= this;
1036 // it can't be an accel anyhow
1040 ms_winLastAltPress
= NULL
;
1041 #endif // wxUSE_MENUS
1044 for ( wxWindow
*win
= this; win
; win
= win
->GetParent() )
1046 int command
= win
->GetAcceleratorTable()->GetCommand(event
);
1047 if ( command
!= -1 )
1049 wxCommandEvent
eventCmd(wxEVT_COMMAND_MENU_SELECTED
, command
);
1050 if ( win
->GetEventHandler()->ProcessEvent(eventCmd
) )
1052 // skip "event.Skip()" below
1057 if ( win
->IsTopLevel() )
1059 // try the frame menu bar
1061 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1064 wxMenuBar
*menubar
= frame
->GetMenuBar();
1065 if ( menubar
&& menubar
->ProcessAccelEvent(event
) )
1067 // skip "event.Skip()" below
1071 #endif // wxUSE_MENUS
1073 // don't propagate accels from the child frame to the parent one
1077 #endif // wxUSE_ACCEL
1082 #endif // wxUSE_ACCEL
1086 wxMenuBar
*wxWindow::GetParentFrameMenuBar() const
1088 for ( const wxWindow
*win
= this; win
; win
= win
->GetParent() )
1090 if ( win
->IsTopLevel() )
1092 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1095 return frame
->GetMenuBar();
1098 // don't look further - we don't want to return the menubar of the
1107 void wxWindow::OnChar(wxKeyEvent
& event
)
1109 if ( event
.AltDown() && !event
.ControlDown() )
1111 int key
= event
.GetKeyCode();
1113 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1116 int item
= menubar
->FindNextItemForAccel(-1, key
);
1119 menubar
->PopupMenu((size_t)item
);
1121 // skip "event.Skip()" below
1130 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1132 int key
= event
.GetKeyCode();
1133 if ( !event
.HasModifiers() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1135 // only process Alt release specially if there were no other key
1136 // presses since Alt had been pressed and if both events happened in
1138 if ( ms_winLastAltPress
== this )
1140 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1141 if ( menubar
&& this != menubar
)
1143 menubar
->SelectMenu(0);
1152 // in any case reset it
1153 ms_winLastAltPress
= NULL
;
1156 #endif // wxUSE_MENUS