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(__WXPM__)
77 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowOS2
)
80 BEGIN_EVENT_TABLE(wxWindow
, wxWindowNative
)
81 EVT_SIZE(wxWindow::OnSize
)
83 #if wxUSE_ACCEL || wxUSE_MENUS
84 EVT_KEY_DOWN(wxWindow::OnKeyDown
)
88 EVT_CHAR(wxWindow::OnChar
)
89 EVT_KEY_UP(wxWindow::OnKeyUp
)
92 EVT_PAINT(wxWindow::OnPaint
)
93 EVT_NC_PAINT(wxWindow::OnNcPaint
)
94 EVT_ERASE_BACKGROUND(wxWindow::OnErase
)
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
101 void wxWindow::Init()
104 m_scrollbarHorz
= (wxScrollBar
*)NULL
;
108 m_renderer
= wxTheme::Get()->GetRenderer();
111 bool wxWindow::Create(wxWindow
*parent
,
116 const wxString
& name
)
118 // we add wxCLIP_CHILDREN to get the same ("natural") behaviour under MSW
119 // as under the other platforms
120 if ( !wxWindowNative::Create(parent
, id
, pos
, size
,
121 style
| wxCLIP_CHILDREN
,
127 // if we should always have the scrollbar, do show it
128 if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
130 m_scrollbarVert
= new wxScrollBar(this, -1,
131 wxDefaultPosition
, wxDefaultSize
,
135 PositionScrollbars();
141 // ----------------------------------------------------------------------------
143 // ----------------------------------------------------------------------------
145 void wxWindow::SetBackground(const wxBitmap
& bitmap
,
150 m_alignBgBitmap
= alignment
;
151 m_stretchBgBitmap
= stretch
;
154 const wxBitmap
& wxWindow::GetBackgroundBitmap(int *alignment
,
155 wxStretch
*stretch
) const
157 if ( m_bitmapBg
.Ok() )
160 *alignment
= m_alignBgBitmap
;
162 *stretch
= m_stretchBgBitmap
;
168 // ----------------------------------------------------------------------------
170 // ----------------------------------------------------------------------------
172 // the event handler executed when the window background must be painted
173 void wxWindow::OnErase(wxEraseEvent
& event
)
182 DoDrawBackground(*event
.GetDC());
184 // if we have both scrollbars, we also have a square in the corner between
185 // them which we must paint
186 if ( m_scrollbarVert
&& m_scrollbarHorz
)
188 wxSize size
= GetSize();
189 wxRect rectClient
= GetClientRect(),
190 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
193 rectCorner
.x
= rectClient
.GetRight() + 1;
194 rectCorner
.y
= rectClient
.GetBottom() + 1;
195 rectCorner
.SetRight(size
.x
- rectBorder
.width
);
196 rectCorner
.SetBottom(size
.y
- rectBorder
.height
);
198 if ( GetUpdateRegion().Contains(rectCorner
) )
200 m_renderer
->DrawScrollCorner(*event
.GetDC(), rectCorner
);
205 // the event handlers executed when the window must be repainted
206 void wxWindow::OnNcPaint(wxPaintEvent
& event
)
210 // get the window rect
212 wxSize size
= GetSize();
216 rect
.height
= size
.y
;
218 // if the scrollbars are outside the border, we must adjust the rect to
220 if ( !m_renderer
->AreScrollbarsInsideBorder() )
222 wxScrollBar
*scrollbar
= GetScrollbar(wxVERTICAL
);
224 rect
.width
-= scrollbar
->GetSize().x
;
226 scrollbar
= GetScrollbar(wxHORIZONTAL
);
228 rect
.height
-= scrollbar
->GetSize().y
;
231 // get the DC and draw the border on it
233 DoDrawBorder(dc
, rect
);
237 void wxWindow::OnPaint(wxPaintEvent
& event
)
241 // it is a native control which paints itself
246 // get the DC to use and create renderer on it
248 wxControlRenderer
renderer(this, dc
, m_renderer
);
255 bool wxWindow::DoDrawBackground(wxDC
& dc
)
257 // FIXME: leaving this code in leads to partial bg redraws sometimes under
261 rect
= GetUpdateRegion().GetBox();
262 if ( !rect
.width
&& !rect
.height
)
265 wxSize size
= GetSize();
267 rect
.height
= size
.y
;
270 if ( GetBackgroundBitmap().Ok() )
272 // get the bitmap and the flags
275 wxBitmap bmp
= GetBackgroundBitmap(&alignment
, &stretch
);
276 wxControlRenderer::DrawBitmap(dc
, bmp
, rect
, alignment
, stretch
);
278 else // just fill it with bg colour if no bitmap
280 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this),
281 rect
, GetStateFlags());
287 void wxWindow::EraseBackground(wxDC
& dc
, const wxRect
& rect
)
289 // TODO: handle bg bitmaps here!
291 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this), rect
, GetStateFlags());
294 void wxWindow::DoDrawBorder(wxDC
& dc
, const wxRect
& rect
)
296 // draw outline unless the update region is enitrely inside it in which
297 // case we don't need to do it
298 #if 0 // doesn't seem to work, why?
299 if ( wxRegion(rect
).Contains(GetUpdateRegion().GetBox()) != wxInRegion
)
302 m_renderer
->DrawBorder(dc
, GetBorder(), rect
, GetStateFlags());
306 void wxWindow::DoDraw(wxControlRenderer
*renderer
)
310 void wxWindow::Refresh(bool eraseBackground
, const wxRect
*rectClient
)
313 wxPoint pt
= GetClientAreaOrigin();
315 wxSize size
= GetClientSize();
319 rectWin
= *rectClient
;
321 // don't refresh anything beyond the client area (scrollbars for
323 if ( rectWin
.GetRight() > size
.x
)
324 rectWin
.SetRight(size
.x
);
325 if ( rectWin
.GetBottom() > size
.y
)
326 rectWin
.SetBottom(size
.y
);
330 else // refresh the entire client area
334 rectWin
.width
= size
.x
;
335 rectWin
.height
= size
.y
;
339 #ifdef WXDEBUG_REFRESH
340 static bool s_refreshDebug
= FALSE
;
341 if ( s_refreshDebug
)
344 dc
.SetBrush(*wxCYAN_BRUSH
);
345 dc
.SetPen(*wxTRANSPARENT_PEN
);
346 dc
.DrawRectangle(rectWin
);
348 // under Unix we use "--sync" X option for this
349 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
354 #endif // WXDEBUG_REFRESH
356 wxWindowNative::Refresh(eraseBackground
, &rectWin
);
359 // ----------------------------------------------------------------------------
361 // ----------------------------------------------------------------------------
363 bool wxWindow::Enable(bool enable
)
365 if ( !wxWindowNative::Enable(enable
) )
368 // disabled window can't keep focus
369 if ( FindFocus() == this && GetParent() != NULL
)
371 GetParent()->SetFocus();
376 // a window with renderer is drawn by ourselves and it has to be
377 // refreshed to reflect its new status
384 bool wxWindow::IsFocused() const
386 wxWindow
*self
= wxConstCast(this, wxWindow
);
387 return self
->FindFocus() == self
;
390 bool wxWindow::IsPressed() const
395 bool wxWindow::IsDefault() const
400 bool wxWindow::IsCurrent() const
405 bool wxWindow::SetCurrent(bool doit
)
407 if ( doit
== m_isCurrent
)
412 if ( CanBeHighlighted() )
418 int wxWindow::GetStateFlags() const
422 flags
|= wxCONTROL_DISABLED
;
424 // the following states are only possible if our application is active - if
425 // it is not, even our default/focused controls shouldn't appear as such
426 if ( wxTheApp
->IsActive() )
429 flags
|= wxCONTROL_CURRENT
;
431 flags
|= wxCONTROL_FOCUSED
;
433 flags
|= wxCONTROL_PRESSED
;
435 flags
|= wxCONTROL_ISDEFAULT
;
441 // ----------------------------------------------------------------------------
443 // ----------------------------------------------------------------------------
445 void wxWindow::OnSize(wxSizeEvent
& event
)
447 if ( m_scrollbarVert
|| m_scrollbarHorz
)
449 PositionScrollbars();
455 wxSize
wxWindow::DoGetBestSize() const
457 return AdjustSize(DoGetBestClientSize());
460 wxSize
wxWindow::DoGetBestClientSize() const
462 return wxWindowNative::DoGetBestSize();
465 wxSize
wxWindow::AdjustSize(const wxSize
& size
) const
469 m_renderer
->AdjustSize(&sz
, this);
473 wxPoint
wxWindow::GetClientAreaOrigin() const
475 wxPoint pt
= wxWindowBase::GetClientAreaOrigin();
478 pt
+= m_renderer
->GetBorderDimensions(GetBorder()).GetPosition();
483 void wxWindow::DoGetClientSize(int *width
, int *height
) const
485 // if it is a native window, we assume it handles the scrollbars itself
486 // too - and if it doesn't, there is not much we can do
489 wxWindowNative::DoGetClientSize(width
, height
);
495 wxWindowNative::DoGetClientSize(&w
, &h
);
497 // we assume that the scrollbars are positioned correctly (by a previous
498 // call to PositionScrollbars()) here
502 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
504 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
508 // in any case, take account of the scrollbar
509 if ( m_scrollbarVert
)
510 w
-= m_scrollbarVert
->GetSize().x
;
512 // if we don't have scrollbar or if it is outside the border (and not
513 // blended into it), take account of the right border as well
514 if ( !m_scrollbarVert
|| inside
)
515 w
-= rectBorder
.width
;
517 // and always account for the left border
518 *width
= w
- rectBorder
.x
;
520 // we shouldn't return invalid width
527 if ( m_scrollbarHorz
)
528 h
-= m_scrollbarHorz
->GetSize().y
;
530 if ( !m_scrollbarHorz
|| inside
)
531 h
-= rectBorder
.height
;
533 *height
= h
- rectBorder
.y
;
535 // we shouldn't return invalid height
541 void wxWindow::DoSetClientSize(int width
, int height
)
543 // take into account the borders
544 wxRect rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
545 width
+= rectBorder
.x
;
546 height
+= rectBorder
.y
;
548 // and the scrollbars (as they may be offset into the border, use the
549 // scrollbar position, not size - this supposes that PositionScrollbars()
550 // had been called before)
551 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
552 wxSize size
= GetSize();
553 if ( m_scrollbarVert
)
554 width
+= size
.x
- m_scrollbarVert
->GetPosition().x
;
555 if ( !m_scrollbarVert
|| inside
)
556 width
+= rectBorder
.width
;
558 if ( m_scrollbarHorz
)
559 height
+= size
.y
- m_scrollbarHorz
->GetPosition().y
;
560 if ( !m_scrollbarHorz
|| inside
)
561 height
+= rectBorder
.height
;
563 wxWindowNative::DoSetClientSize(width
, height
);
566 wxHitTest
wxWindow::DoHitTest(wxCoord x
, wxCoord y
) const
568 wxHitTest ht
= wxWindowNative::DoHitTest(x
, y
);
569 if ( ht
== wxHT_WINDOW_INSIDE
)
571 if ( m_scrollbarVert
&& x
>= m_scrollbarVert
->GetPosition().x
)
573 // it can still be changed below because it may also be the corner
574 ht
= wxHT_WINDOW_VERT_SCROLLBAR
;
577 if ( m_scrollbarHorz
&& y
>= m_scrollbarHorz
->GetPosition().y
)
579 ht
= ht
== wxHT_WINDOW_VERT_SCROLLBAR
? wxHT_WINDOW_CORNER
580 : wxHT_WINDOW_HORZ_SCROLLBAR
;
587 // ----------------------------------------------------------------------------
588 // scrolling: we implement it entirely ourselves except for ScrollWindow()
589 // function which is supposed to be (efficiently) implemented by the native
591 // ----------------------------------------------------------------------------
593 void wxWindow::RefreshScrollbars()
595 if ( m_scrollbarHorz
)
596 m_scrollbarHorz
->Refresh();
598 if ( m_scrollbarVert
)
599 m_scrollbarVert
->Refresh();
602 void wxWindow::PositionScrollbars()
604 // do not use GetClientSize/Rect as it relies on the scrollbars being
605 // correctly positioned
607 wxSize size
= GetSize();
608 wxBorder border
= GetBorder();
609 wxRect rectBorder
= m_renderer
->GetBorderDimensions(border
);
610 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
612 int height
= m_scrollbarHorz
? m_scrollbarHorz
->GetSize().y
: 0;
613 int width
= m_scrollbarVert
? m_scrollbarVert
->GetSize().x
: 0;
616 if ( m_scrollbarVert
)
618 rectBar
.x
= size
.x
- width
;
620 rectBar
.x
-= rectBorder
.width
;
621 rectBar
.width
= width
;
624 rectBar
.y
+= rectBorder
.y
;
625 rectBar
.height
= size
.y
- height
;
627 rectBar
.height
-= rectBorder
.y
+ rectBorder
.height
;
629 m_scrollbarVert
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
632 if ( m_scrollbarHorz
)
634 rectBar
.y
= size
.y
- height
;
636 rectBar
.y
-= rectBorder
.height
;
637 rectBar
.height
= height
;
640 rectBar
.x
+= rectBorder
.x
;
641 rectBar
.width
= size
.x
- width
;
643 rectBar
.width
-= rectBorder
.x
+ rectBorder
.width
;
645 m_scrollbarHorz
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
651 void wxWindow::SetScrollbar(int orient
,
657 wxASSERT_MSG( pageSize
<= range
,
658 _T("page size can't be greater than range") );
660 bool hasClientSizeChanged
= FALSE
;
661 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
662 if ( range
&& (pageSize
< range
) )
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 // ----------------------------------------------------------------------------
937 // accelerators and menu hot keys
938 // ----------------------------------------------------------------------------
941 // the last window over which Alt was pressed (used by OnKeyUp)
942 wxWindow
*wxWindow::ms_winLastAltPress
= NULL
;
943 #endif // wxUSE_MENUS
945 #if wxUSE_ACCEL || wxUSE_MENUS
947 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
950 int key
= event
.GetKeyCode();
951 if ( !event
.ControlDown() && (key
== WXK_MENU
|| key
== WXK_F10
) )
953 ms_winLastAltPress
= this;
955 // it can't be an accel anyhow
959 ms_winLastAltPress
= NULL
;
960 #endif // wxUSE_MENUS
963 for ( wxWindow
*win
= this; win
; win
= win
->GetParent() )
965 int command
= win
->GetAcceleratorTable()->GetCommand(event
);
968 wxCommandEvent
eventCmd(wxEVT_COMMAND_MENU_SELECTED
, command
);
969 if ( win
->GetEventHandler()->ProcessEvent(eventCmd
) )
971 // skip "event.Skip()" below
976 if ( win
->IsTopLevel() )
978 // try the frame menu bar
980 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
983 wxMenuBar
*menubar
= frame
->GetMenuBar();
984 if ( menubar
&& menubar
->ProcessAccelEvent(event
) )
986 // skip "event.Skip()" below
990 #endif // wxUSE_MENUS
992 // don't propagate accels from the child frame to the parent one
996 #endif // wxUSE_ACCEL
1001 #endif // wxUSE_ACCEL
1005 wxMenuBar
*wxWindow::GetParentFrameMenuBar() const
1007 for ( const wxWindow
*win
= this; win
; win
= win
->GetParent() )
1009 if ( win
->IsTopLevel() )
1011 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1014 return frame
->GetMenuBar();
1017 // don't look further - we don't want to return the menubar of the
1026 void wxWindow::OnChar(wxKeyEvent
& event
)
1028 if ( event
.AltDown() && !event
.ControlDown() )
1030 int key
= event
.GetKeyCode();
1032 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1035 int item
= menubar
->FindNextItemForAccel(-1, key
);
1038 menubar
->PopupMenu((size_t)item
);
1040 // skip "event.Skip()" below
1049 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1051 int key
= event
.GetKeyCode();
1052 if ( !event
.HasModifiers() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1054 // only process Alt release specially if there were no other key
1055 // presses since Alt had been pressed and if both events happened in
1057 if ( ms_winLastAltPress
== this )
1059 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1060 if ( menubar
&& this != menubar
)
1062 menubar
->SelectMenu(0);
1071 // in any case reset it
1072 ms_winLastAltPress
= NULL
;
1075 #endif // wxUSE_MENUS