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
)
76 #elif defined(__WXX11__)
77 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowX11
)
78 #elif defined(__WXPM__)
79 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowOS2
)
82 BEGIN_EVENT_TABLE(wxWindow
, wxWindowNative
)
83 EVT_SIZE(wxWindow::OnSize
)
85 #if wxUSE_ACCEL || wxUSE_MENUS
86 EVT_KEY_DOWN(wxWindow::OnKeyDown
)
90 EVT_CHAR(wxWindow::OnChar
)
91 EVT_KEY_UP(wxWindow::OnKeyUp
)
94 EVT_PAINT(wxWindow::OnPaint
)
95 EVT_NC_PAINT(wxWindow::OnNcPaint
)
96 EVT_ERASE_BACKGROUND(wxWindow::OnErase
)
99 // ----------------------------------------------------------------------------
101 // ----------------------------------------------------------------------------
103 void wxWindow::Init()
106 m_scrollbarHorz
= (wxScrollBar
*)NULL
;
110 m_renderer
= wxTheme::Get()->GetRenderer();
113 bool wxWindow::Create(wxWindow
*parent
,
118 const wxString
& name
)
120 // we add wxCLIP_CHILDREN to get the same ("natural") behaviour under MSW
121 // as under the other platforms
122 if ( !wxWindowNative::Create(parent
, id
, pos
, size
,
123 style
| wxCLIP_CHILDREN
,
129 // if we should always have the scrollbar, do show it
130 if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
132 m_scrollbarVert
= new wxScrollBar(this, -1,
133 wxDefaultPosition
, wxDefaultSize
,
137 PositionScrollbars();
143 // ----------------------------------------------------------------------------
145 // ----------------------------------------------------------------------------
147 void wxWindow::SetBackground(const wxBitmap
& bitmap
,
152 m_alignBgBitmap
= alignment
;
153 m_stretchBgBitmap
= stretch
;
156 const wxBitmap
& wxWindow::GetBackgroundBitmap(int *alignment
,
157 wxStretch
*stretch
) const
159 if ( m_bitmapBg
.Ok() )
162 *alignment
= m_alignBgBitmap
;
164 *stretch
= m_stretchBgBitmap
;
170 // ----------------------------------------------------------------------------
172 // ----------------------------------------------------------------------------
174 // the event handler executed when the window background must be painted
175 void wxWindow::OnErase(wxEraseEvent
& event
)
184 DoDrawBackground(*event
.GetDC());
186 // if we have both scrollbars, we also have a square in the corner between
187 // them which we must paint
188 if ( m_scrollbarVert
&& m_scrollbarHorz
)
190 wxSize size
= GetSize();
191 wxRect rectClient
= GetClientRect(),
192 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
195 rectCorner
.x
= rectClient
.GetRight() + 1;
196 rectCorner
.y
= rectClient
.GetBottom() + 1;
197 rectCorner
.SetRight(size
.x
- rectBorder
.width
);
198 rectCorner
.SetBottom(size
.y
- rectBorder
.height
);
200 if ( GetUpdateRegion().Contains(rectCorner
) )
202 m_renderer
->DrawScrollCorner(*event
.GetDC(), rectCorner
);
207 // the event handlers executed when the window must be repainted
208 void wxWindow::OnNcPaint(wxPaintEvent
& event
)
212 // get the window rect
214 wxSize size
= GetSize();
218 rect
.height
= size
.y
;
220 // if the scrollbars are outside the border, we must adjust the rect to
222 if ( !m_renderer
->AreScrollbarsInsideBorder() )
224 wxScrollBar
*scrollbar
= GetScrollbar(wxVERTICAL
);
226 rect
.width
-= scrollbar
->GetSize().x
;
228 scrollbar
= GetScrollbar(wxHORIZONTAL
);
230 rect
.height
-= scrollbar
->GetSize().y
;
233 // get the DC and draw the border on it
235 DoDrawBorder(dc
, rect
);
239 void wxWindow::OnPaint(wxPaintEvent
& event
)
243 // it is a native control which paints itself
248 // get the DC to use and create renderer on it
250 wxControlRenderer
renderer(this, dc
, m_renderer
);
257 bool wxWindow::DoDrawBackground(wxDC
& dc
)
259 // FIXME: leaving this code in leads to partial bg redraws sometimes under
263 rect
= GetUpdateRegion().GetBox();
264 if ( !rect
.width
&& !rect
.height
)
267 wxSize size
= GetSize();
269 rect
.height
= size
.y
;
272 if ( GetBackgroundBitmap().Ok() )
274 // get the bitmap and the flags
277 wxBitmap bmp
= GetBackgroundBitmap(&alignment
, &stretch
);
278 wxControlRenderer::DrawBitmap(dc
, bmp
, rect
, alignment
, stretch
);
280 else // just fill it with bg colour if no bitmap
282 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this),
283 rect
, GetStateFlags());
289 void wxWindow::EraseBackground(wxDC
& dc
, const wxRect
& rect
)
291 // TODO: handle bg bitmaps here!
293 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this), rect
, GetStateFlags());
296 void wxWindow::DoDrawBorder(wxDC
& dc
, const wxRect
& rect
)
298 // draw outline unless the update region is enitrely inside it in which
299 // case we don't need to do it
300 #if 0 // doesn't seem to work, why?
301 if ( wxRegion(rect
).Contains(GetUpdateRegion().GetBox()) != wxInRegion
)
304 m_renderer
->DrawBorder(dc
, GetBorder(), rect
, GetStateFlags());
308 void wxWindow::DoDraw(wxControlRenderer
*renderer
)
312 void wxWindow::Refresh(bool eraseBackground
, const wxRect
*rectClient
)
315 wxPoint pt
= GetClientAreaOrigin();
317 wxSize size
= GetClientSize();
321 rectWin
= *rectClient
;
323 // don't refresh anything beyond the client area (scrollbars for
325 if ( rectWin
.GetRight() > size
.x
)
326 rectWin
.SetRight(size
.x
);
327 if ( rectWin
.GetBottom() > size
.y
)
328 rectWin
.SetBottom(size
.y
);
332 else // refresh the entire client area
336 rectWin
.width
= size
.x
;
337 rectWin
.height
= size
.y
;
341 #ifdef WXDEBUG_REFRESH
342 static bool s_refreshDebug
= FALSE
;
343 if ( s_refreshDebug
)
346 dc
.SetBrush(*wxCYAN_BRUSH
);
347 dc
.SetPen(*wxTRANSPARENT_PEN
);
348 dc
.DrawRectangle(rectWin
);
350 // under Unix we use "--sync" X option for this
351 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
356 #endif // WXDEBUG_REFRESH
358 wxWindowNative::Refresh(eraseBackground
, &rectWin
);
361 // ----------------------------------------------------------------------------
363 // ----------------------------------------------------------------------------
365 bool wxWindow::Enable(bool enable
)
367 if ( !wxWindowNative::Enable(enable
) )
370 // disabled window can't keep focus
371 if ( FindFocus() == this && GetParent() != NULL
)
373 GetParent()->SetFocus();
378 // a window with renderer is drawn by ourselves and it has to be
379 // refreshed to reflect its new status
386 bool wxWindow::IsFocused() const
388 wxWindow
*self
= wxConstCast(this, wxWindow
);
389 return self
->FindFocus() == self
;
392 bool wxWindow::IsPressed() const
397 bool wxWindow::IsDefault() const
402 bool wxWindow::IsCurrent() const
407 bool wxWindow::SetCurrent(bool doit
)
409 if ( doit
== m_isCurrent
)
414 if ( CanBeHighlighted() )
420 int wxWindow::GetStateFlags() const
424 flags
|= wxCONTROL_DISABLED
;
426 // the following states are only possible if our application is active - if
427 // it is not, even our default/focused controls shouldn't appear as such
428 if ( wxTheApp
->IsActive() )
431 flags
|= wxCONTROL_CURRENT
;
433 flags
|= wxCONTROL_FOCUSED
;
435 flags
|= wxCONTROL_PRESSED
;
437 flags
|= wxCONTROL_ISDEFAULT
;
443 // ----------------------------------------------------------------------------
445 // ----------------------------------------------------------------------------
447 void wxWindow::OnSize(wxSizeEvent
& event
)
449 if ( m_scrollbarVert
|| m_scrollbarHorz
)
451 PositionScrollbars();
457 wxSize
wxWindow::DoGetBestSize() const
459 return AdjustSize(DoGetBestClientSize());
462 wxSize
wxWindow::DoGetBestClientSize() const
464 return wxWindowNative::DoGetBestSize();
467 wxSize
wxWindow::AdjustSize(const wxSize
& size
) const
471 m_renderer
->AdjustSize(&sz
, this);
475 wxPoint
wxWindow::GetClientAreaOrigin() const
477 wxPoint pt
= wxWindowBase::GetClientAreaOrigin();
480 pt
+= m_renderer
->GetBorderDimensions(GetBorder()).GetPosition();
485 void wxWindow::DoGetClientSize(int *width
, int *height
) const
487 // if it is a native window, we assume it handles the scrollbars itself
488 // too - and if it doesn't, there is not much we can do
491 wxWindowNative::DoGetClientSize(width
, height
);
497 wxWindowNative::DoGetClientSize(&w
, &h
);
499 // we assume that the scrollbars are positioned correctly (by a previous
500 // call to PositionScrollbars()) here
504 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
506 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
510 // in any case, take account of the scrollbar
511 if ( m_scrollbarVert
)
512 w
-= m_scrollbarVert
->GetSize().x
;
514 // if we don't have scrollbar or if it is outside the border (and not
515 // blended into it), take account of the right border as well
516 if ( !m_scrollbarVert
|| inside
)
517 w
-= rectBorder
.width
;
519 // and always account for the left border
520 *width
= w
- rectBorder
.x
;
522 // we shouldn't return invalid width
529 if ( m_scrollbarHorz
)
530 h
-= m_scrollbarHorz
->GetSize().y
;
532 if ( !m_scrollbarHorz
|| inside
)
533 h
-= rectBorder
.height
;
535 *height
= h
- rectBorder
.y
;
537 // we shouldn't return invalid height
543 void wxWindow::DoSetClientSize(int width
, int height
)
545 // take into account the borders
546 wxRect rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
547 width
+= rectBorder
.x
;
548 height
+= rectBorder
.y
;
550 // and the scrollbars (as they may be offset into the border, use the
551 // scrollbar position, not size - this supposes that PositionScrollbars()
552 // had been called before)
553 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
554 wxSize size
= GetSize();
555 if ( m_scrollbarVert
)
556 width
+= size
.x
- m_scrollbarVert
->GetPosition().x
;
557 if ( !m_scrollbarVert
|| inside
)
558 width
+= rectBorder
.width
;
560 if ( m_scrollbarHorz
)
561 height
+= size
.y
- m_scrollbarHorz
->GetPosition().y
;
562 if ( !m_scrollbarHorz
|| inside
)
563 height
+= rectBorder
.height
;
565 wxWindowNative::DoSetClientSize(width
, height
);
568 wxHitTest
wxWindow::DoHitTest(wxCoord x
, wxCoord y
) const
570 wxHitTest ht
= wxWindowNative::DoHitTest(x
, y
);
571 if ( ht
== wxHT_WINDOW_INSIDE
)
573 if ( m_scrollbarVert
&& x
>= m_scrollbarVert
->GetPosition().x
)
575 // it can still be changed below because it may also be the corner
576 ht
= wxHT_WINDOW_VERT_SCROLLBAR
;
579 if ( m_scrollbarHorz
&& y
>= m_scrollbarHorz
->GetPosition().y
)
581 ht
= ht
== wxHT_WINDOW_VERT_SCROLLBAR
? wxHT_WINDOW_CORNER
582 : wxHT_WINDOW_HORZ_SCROLLBAR
;
589 // ----------------------------------------------------------------------------
590 // scrolling: we implement it entirely ourselves except for ScrollWindow()
591 // function which is supposed to be (efficiently) implemented by the native
593 // ----------------------------------------------------------------------------
595 void wxWindow::RefreshScrollbars()
597 if ( m_scrollbarHorz
)
598 m_scrollbarHorz
->Refresh();
600 if ( m_scrollbarVert
)
601 m_scrollbarVert
->Refresh();
604 void wxWindow::PositionScrollbars()
606 // do not use GetClientSize/Rect as it relies on the scrollbars being
607 // correctly positioned
609 wxSize size
= GetSize();
610 wxBorder border
= GetBorder();
611 wxRect rectBorder
= m_renderer
->GetBorderDimensions(border
);
612 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
614 int height
= m_scrollbarHorz
? m_scrollbarHorz
->GetSize().y
: 0;
615 int width
= m_scrollbarVert
? m_scrollbarVert
->GetSize().x
: 0;
618 if ( m_scrollbarVert
)
620 rectBar
.x
= size
.x
- width
;
622 rectBar
.x
-= rectBorder
.width
;
623 rectBar
.width
= width
;
626 rectBar
.y
+= rectBorder
.y
;
627 rectBar
.height
= size
.y
- height
;
629 rectBar
.height
-= rectBorder
.y
+ rectBorder
.height
;
631 m_scrollbarVert
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
634 if ( m_scrollbarHorz
)
636 rectBar
.y
= size
.y
- height
;
638 rectBar
.y
-= rectBorder
.height
;
639 rectBar
.height
= height
;
642 rectBar
.x
+= rectBorder
.x
;
643 rectBar
.width
= size
.x
- width
;
645 rectBar
.width
-= rectBorder
.x
+ rectBorder
.width
;
647 m_scrollbarHorz
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
653 void wxWindow::SetScrollbar(int orient
,
659 wxASSERT_MSG( pageSize
<= range
,
660 _T("page size can't be greater than range") );
662 bool hasClientSizeChanged
= FALSE
;
663 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
664 if ( range
&& (pageSize
< range
) )
669 scrollbar
= new wxScrollBar(this, -1,
670 wxDefaultPosition
, wxDefaultSize
,
671 orient
& wxVERTICAL
? wxSB_VERTICAL
673 if ( orient
& wxVERTICAL
)
674 m_scrollbarVert
= scrollbar
;
676 m_scrollbarHorz
= scrollbar
;
678 // the client area diminished as we created a scrollbar
679 hasClientSizeChanged
= TRUE
;
681 PositionScrollbars();
683 else if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
685 // we might have disabled it before
689 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
691 else // no range means no scrollbar
695 // wxALWAYS_SHOW_SB only applies to the vertical scrollbar
696 if ( (orient
& wxVERTICAL
) && (GetWindowStyle() & wxALWAYS_SHOW_SB
) )
698 // just disable the scrollbar
699 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
700 scrollbar
->Disable();
702 else // really remove the scrollbar
706 if ( orient
& wxVERTICAL
)
707 m_scrollbarVert
= NULL
;
709 m_scrollbarHorz
= NULL
;
711 // the client area increased as we removed a scrollbar
712 hasClientSizeChanged
= TRUE
;
714 // the size of the remaining scrollbar must be adjusted
715 if ( m_scrollbarHorz
|| m_scrollbarVert
)
717 PositionScrollbars();
723 // give the window a chance to relayout
724 if ( hasClientSizeChanged
)
726 wxSizeEvent
event(GetSize());
727 (void)GetEventHandler()->ProcessEvent(event
);
731 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
733 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
734 wxCHECK_RET( scrollbar
, _T("no scrollbar to set position for") );
736 scrollbar
->SetThumbPosition(pos
);
738 // VZ: I think we can safely ignore this as we always refresh it
739 // automatically whenever the value chanegs
746 int wxWindow::GetScrollPos(int orient
) const
748 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
749 return scrollbar
? scrollbar
->GetThumbPosition() : 0;
752 int wxWindow::GetScrollThumb(int orient
) const
754 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
755 return scrollbar
? scrollbar
->GetThumbSize() : 0;
758 int wxWindow::GetScrollRange(int orient
) const
760 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
761 return scrollbar
? scrollbar
->GetRange() : 0;
764 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
766 // before scrolling it, ensure that we don't have any unpainted areas
773 r
= ScrollNoRefresh(dx
, 0, rect
);
774 Refresh(TRUE
/* erase bkgnd */, &r
);
779 r
= ScrollNoRefresh(0, dy
, rect
);
780 Refresh(TRUE
/* erase bkgnd */, &r
);
784 wxRect
wxWindow::ScrollNoRefresh(int dx
, int dy
, const wxRect
*rectTotal
)
786 wxASSERT_MSG( !dx
|| !dy
, _T("can't be used for diag scrolling") );
788 // the rect to refresh (which we will calculate)
797 // calculate the part of the window which we can just redraw in the new
799 wxSize sizeTotal
= rectTotal
? rectTotal
->GetSize() : GetClientSize();
801 wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"),
802 sizeTotal
.x
, sizeTotal
.y
, dx
, dy
);
804 // the initial and end point of the region we move in client coords
805 wxPoint ptSource
, ptDest
;
808 ptSource
= rectTotal
->GetPosition();
809 ptDest
= rectTotal
->GetPosition();
812 // the size of this region
814 size
.x
= sizeTotal
.x
- abs(dx
);
815 size
.y
= sizeTotal
.y
- abs(dy
);
816 if ( size
.x
<= 0 || size
.y
<= 0 )
818 // just redraw everything as nothing of the displayed image will stay
819 wxLogTrace(_T("scroll"), _T("refreshing everything"));
821 rect
= rectTotal
? *rectTotal
: wxRect(0, 0, sizeTotal
.x
, sizeTotal
.y
);
823 else // move the part which doesn't change to the new location
825 // note that when we scroll the canvas in some direction we move the
826 // block which doesn't need to be refreshed in the opposite direction
830 // scroll to the right, move to the left
835 // scroll to the left, move to the right
841 // scroll down, move up
846 // scroll up, move down
851 // we need to hide the caret before moving or it will erase itself at
852 // the wrong (old) location
853 wxCaret
*caret
= GetCaret();
856 #endif // wxUSE_CARET
860 wxBitmap
bmp(size
.x
, size
.y
);
862 dcMem
.SelectObject(bmp
);
864 dcMem
.Blit(wxPoint(0, 0), size
, &dc
, ptSource
865 #if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT)
866 + GetClientAreaOrigin()
867 #endif // broken wxGTK wxDC::Blit
869 dc
.Blit(ptDest
, size
, &dcMem
, wxPoint(0, 0));
871 wxLogTrace(_T("scroll"),
872 _T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"),
873 ptSource
.x
, ptSource
.y
,
877 // and now repaint the uncovered area
879 // FIXME: We repaint the intersection of these rectangles twice - is
880 // it bad? I don't think so as it is rare to scroll the window
881 // diagonally anyhow and so adding extra logic to compute
882 // rectangle intersection is probably not worth the effort
891 // refresh the area along the right border
892 rect
.x
+= size
.x
+ dx
;
897 // refresh the area along the left border
901 rect
.height
= sizeTotal
.y
;
903 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
905 rect
.GetRight() + 1, rect
.GetBottom() + 1);
912 // refresh the area along the bottom border
913 rect
.y
+= size
.y
+ dy
;
918 // refresh the area along the top border
922 rect
.width
= sizeTotal
.x
;
924 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
926 rect
.GetRight() + 1, rect
.GetBottom() + 1);
932 #endif // wxUSE_CARET
938 // ----------------------------------------------------------------------------
939 // accelerators and menu hot keys
940 // ----------------------------------------------------------------------------
943 // the last window over which Alt was pressed (used by OnKeyUp)
944 wxWindow
*wxWindow::ms_winLastAltPress
= NULL
;
945 #endif // wxUSE_MENUS
947 #if wxUSE_ACCEL || wxUSE_MENUS
949 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
952 int key
= event
.GetKeyCode();
953 if ( !event
.ControlDown() && (key
== WXK_MENU
|| key
== WXK_F10
) )
955 ms_winLastAltPress
= this;
957 // it can't be an accel anyhow
961 ms_winLastAltPress
= NULL
;
962 #endif // wxUSE_MENUS
965 for ( wxWindow
*win
= this; win
; win
= win
->GetParent() )
967 int command
= win
->GetAcceleratorTable()->GetCommand(event
);
970 wxCommandEvent
eventCmd(wxEVT_COMMAND_MENU_SELECTED
, command
);
971 if ( win
->GetEventHandler()->ProcessEvent(eventCmd
) )
973 // skip "event.Skip()" below
978 if ( win
->IsTopLevel() )
980 // try the frame menu bar
982 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
985 wxMenuBar
*menubar
= frame
->GetMenuBar();
986 if ( menubar
&& menubar
->ProcessAccelEvent(event
) )
988 // skip "event.Skip()" below
992 #endif // wxUSE_MENUS
994 // don't propagate accels from the child frame to the parent one
998 #endif // wxUSE_ACCEL
1003 #endif // wxUSE_ACCEL
1007 wxMenuBar
*wxWindow::GetParentFrameMenuBar() const
1009 for ( const wxWindow
*win
= this; win
; win
= win
->GetParent() )
1011 if ( win
->IsTopLevel() )
1013 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1016 return frame
->GetMenuBar();
1019 // don't look further - we don't want to return the menubar of the
1028 void wxWindow::OnChar(wxKeyEvent
& event
)
1030 if ( event
.AltDown() && !event
.ControlDown() )
1032 int key
= event
.GetKeyCode();
1034 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1037 int item
= menubar
->FindNextItemForAccel(-1, key
);
1040 menubar
->PopupMenu((size_t)item
);
1042 // skip "event.Skip()" below
1051 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1053 int key
= event
.GetKeyCode();
1054 if ( !event
.HasModifiers() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1056 // only process Alt release specially if there were no other key
1057 // presses since Alt had been pressed and if both events happened in
1059 if ( ms_winLastAltPress
== this )
1061 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1062 if ( menubar
&& this != menubar
)
1064 menubar
->SelectMenu(0);
1073 // in any case reset it
1074 ms_winLastAltPress
= NULL
;
1077 #endif // wxUSE_MENUS