1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: univ/window.cpp
3 // Purpose: implementation of extra wxWindow methods for wxUniv port
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2000 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
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"
41 #include "wx/univ/colschem.h"
42 #include "wx/univ/renderer.h"
43 #include "wx/univ/theme.h"
49 // turn Refresh() debugging on/off
50 #define WXDEBUG_REFRESH
53 #undef WXDEBUG_REFRESH
56 // ============================================================================
58 // ============================================================================
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
64 // we can't use wxWindowNative here as it won't be expanded inside the macro
65 #if defined(__WXMSW__)
66 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowMSW
)
67 #elif defined(__WXGTK__)
68 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowGTK
)
69 #elif defined(__WXMGL__)
70 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowMGL
)
73 BEGIN_EVENT_TABLE(wxWindow
, wxWindowNative
)
74 EVT_SIZE(wxWindow::OnSize
)
76 #if wxUSE_ACCEL || wxUSE_MENUS
77 EVT_KEY_DOWN(wxWindow::OnKeyDown
)
81 EVT_CHAR(wxWindow::OnChar
)
82 EVT_KEY_UP(wxWindow::OnKeyUp
)
85 EVT_PAINT(wxWindow::OnPaint
)
86 EVT_NC_PAINT(wxWindow::OnNcPaint
)
87 EVT_ERASE_BACKGROUND(wxWindow::OnErase
)
90 // ----------------------------------------------------------------------------
92 // ----------------------------------------------------------------------------
97 m_scrollbarHorz
= (wxScrollBar
*)NULL
;
101 m_renderer
= wxTheme::Get()->GetRenderer();
104 bool wxWindow::Create(wxWindow
*parent
,
109 const wxString
& name
)
111 // we add wxCLIP_CHILDREN and wxNO_FULL_REPAINT_ON_RESIZE because without
112 // these styles we can't get rid of flicker on wxMSW
113 if ( !wxWindowNative::Create(parent
, id
, pos
, size
,
116 wxNO_FULL_REPAINT_ON_RESIZE
, name
) )
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
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
485 wxWindowNative::DoGetClientSize(&w
, &h
);
487 // we assume that the scrollbars are positioned correctly (by a previous
488 // call to PositionScrollbars()) here
492 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
494 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
498 // in any case, take account of the scrollbar
499 if ( m_scrollbarVert
)
500 w
-= m_scrollbarVert
->GetSize().x
;
502 // if we don't have scrollbar or if it is outside the border (and not
503 // blended into it), take account of the right border as well
504 if ( !m_scrollbarVert
|| inside
)
505 w
-= rectBorder
.width
;
507 // and always account for the left border
508 *width
= w
- rectBorder
.x
;
510 // we shouldn't return invalid width
517 if ( m_scrollbarHorz
)
518 h
-= m_scrollbarHorz
->GetSize().y
;
520 if ( !m_scrollbarHorz
|| inside
)
521 h
-= rectBorder
.height
;
523 *height
= h
- rectBorder
.y
;
525 // we shouldn't return invalid height
531 void wxWindow::DoSetClientSize(int width
, int height
)
533 // take into account the borders
534 wxRect rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
535 width
+= rectBorder
.x
;
536 height
+= rectBorder
.y
;
538 // and the scrollbars (as they may be offset into the border, use the
539 // scrollbar position, not size - this supposes that PositionScrollbars()
540 // had been called before)
541 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
542 wxSize size
= GetSize();
543 if ( m_scrollbarVert
)
544 width
+= size
.x
- m_scrollbarVert
->GetPosition().x
;
545 if ( !m_scrollbarVert
|| inside
)
546 width
+= rectBorder
.width
;
548 if ( m_scrollbarHorz
)
549 height
+= size
.y
- m_scrollbarHorz
->GetPosition().y
;
550 if ( !m_scrollbarHorz
|| inside
)
551 height
+= rectBorder
.height
;
553 wxWindowNative::DoSetClientSize(width
, height
);
556 wxHitTest
wxWindow::DoHitTest(wxCoord x
, wxCoord y
) const
558 wxHitTest ht
= wxWindowNative::DoHitTest(x
, y
);
559 if ( ht
== wxHT_WINDOW_INSIDE
)
561 if ( m_scrollbarVert
&& x
>= m_scrollbarVert
->GetPosition().x
)
563 // it can still be changed below because it may also be the corner
564 ht
= wxHT_WINDOW_VERT_SCROLLBAR
;
567 if ( m_scrollbarHorz
&& y
>= m_scrollbarHorz
->GetPosition().y
)
569 ht
= ht
== wxHT_WINDOW_VERT_SCROLLBAR
? wxHT_WINDOW_CORNER
570 : wxHT_WINDOW_HORZ_SCROLLBAR
;
577 // ----------------------------------------------------------------------------
578 // scrolling: we implement it entirely ourselves except for ScrollWindow()
579 // function which is supposed to be (efficiently) implemented by the native
581 // ----------------------------------------------------------------------------
583 void wxWindow::RefreshScrollbars()
585 if ( m_scrollbarHorz
)
586 m_scrollbarHorz
->Refresh();
588 if ( m_scrollbarVert
)
589 m_scrollbarVert
->Refresh();
592 void wxWindow::PositionScrollbars()
594 // do not use GetClientSize/Rect as it relies on the scrollbars being
595 // correctly positioned
597 wxSize size
= GetSize();
598 wxBorder border
= GetBorder();
599 wxRect rectBorder
= m_renderer
->GetBorderDimensions(border
);
600 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
602 int height
= m_scrollbarHorz
? m_scrollbarHorz
->GetSize().y
: 0;
603 int width
= m_scrollbarVert
? m_scrollbarVert
->GetSize().x
: 0;
606 if ( m_scrollbarVert
)
608 rectBar
.x
= size
.x
- width
;
610 rectBar
.x
-= rectBorder
.width
;
611 rectBar
.width
= width
;
614 rectBar
.y
+= rectBorder
.y
;
615 rectBar
.height
= size
.y
- height
;
617 rectBar
.height
-= rectBorder
.y
+ rectBorder
.height
;
619 m_scrollbarVert
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
622 if ( m_scrollbarHorz
)
624 rectBar
.y
= size
.y
- height
;
626 rectBar
.y
-= rectBorder
.height
;
627 rectBar
.height
= height
;
630 rectBar
.x
+= rectBorder
.x
;
631 rectBar
.width
= size
.x
- width
;
633 rectBar
.width
-= rectBorder
.x
+ rectBorder
.width
;
635 m_scrollbarHorz
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
641 void wxWindow::SetScrollbar(int orient
,
647 bool hasClientSizeChanged
= FALSE
;
648 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
654 scrollbar
= new wxScrollBar(this, -1,
655 wxDefaultPosition
, wxDefaultSize
,
656 orient
& wxVERTICAL
? wxSB_VERTICAL
658 if ( orient
& wxVERTICAL
)
659 m_scrollbarVert
= scrollbar
;
661 m_scrollbarHorz
= scrollbar
;
663 // the client area diminished as we created a scrollbar
664 hasClientSizeChanged
= TRUE
;
666 PositionScrollbars();
668 else if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
670 // we might have disabled it before
674 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
676 else // no range means no scrollbar
680 // wxALWAYS_SHOW_SB only applies to the vertical scrollbar
681 if ( (orient
& wxVERTICAL
) && (GetWindowStyle() & wxALWAYS_SHOW_SB
) )
683 // just disable the scrollbar
684 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
685 scrollbar
->Disable();
687 else // really remove the scrollbar
691 if ( orient
& wxVERTICAL
)
692 m_scrollbarVert
= NULL
;
694 m_scrollbarHorz
= NULL
;
696 // the client area increased as we removed a scrollbar
697 hasClientSizeChanged
= TRUE
;
699 // the size of the remaining scrollbar must be adjusted
700 if ( m_scrollbarHorz
|| m_scrollbarVert
)
702 PositionScrollbars();
708 // give the window a chance to relayout
709 if ( hasClientSizeChanged
)
711 wxSizeEvent
event(GetSize());
712 (void)GetEventHandler()->ProcessEvent(event
);
716 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
718 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
719 wxCHECK_RET( scrollbar
, _T("no scrollbar to set position for") );
721 scrollbar
->SetThumbPosition(pos
);
726 int wxWindow::GetScrollPos(int orient
) const
728 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
729 return scrollbar
? scrollbar
->GetThumbPosition() : 0;
732 int wxWindow::GetScrollThumb(int orient
) const
734 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
735 return scrollbar
? scrollbar
->GetThumbSize() : 0;
738 int wxWindow::GetScrollRange(int orient
) const
740 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
741 return scrollbar
? scrollbar
->GetRange() : 0;
744 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
746 // before scrolling it, ensure that we don't have any unpainted areas
753 r
= ScrollNoRefresh(dx
, 0, rect
);
754 Refresh(TRUE
/* erase bkgnd */, &r
);
759 r
= ScrollNoRefresh(0, dy
, rect
);
760 Refresh(TRUE
/* erase bkgnd */, &r
);
764 wxRect
wxWindow::ScrollNoRefresh(int dx
, int dy
, const wxRect
*rectTotal
)
766 wxASSERT_MSG( !dx
|| !dy
, _T("can't be used for diag scrolling") );
768 // the rect to refresh (which we will calculate)
777 // calculate the part of the window which we can just redraw in the new
779 wxSize sizeTotal
= rectTotal
? rectTotal
->GetSize() : GetClientSize();
781 wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"),
782 sizeTotal
.x
, sizeTotal
.y
, dx
, dy
);
784 // the initial and end point of the region we move in client coords
785 wxPoint ptSource
, ptDest
;
788 ptSource
= rectTotal
->GetPosition();
789 ptDest
= rectTotal
->GetPosition();
792 // the size of this region
794 size
.x
= sizeTotal
.x
- abs(dx
);
795 size
.y
= sizeTotal
.y
- abs(dy
);
796 if ( size
.x
<= 0 || size
.y
<= 0 )
798 // just redraw everything as nothing of the displayed image will stay
799 wxLogTrace(_T("scroll"), _T("refreshing everything"));
801 rect
= rectTotal
? *rectTotal
: wxRect(0, 0, sizeTotal
.x
, sizeTotal
.y
);
803 else // move the part which doesn't change to the new location
805 // note that when we scroll the canvas in some direction we move the
806 // block which doesn't need to be refreshed in the opposite direction
810 // scroll to the right, move to the left
815 // scroll to the left, move to the right
821 // scroll down, move up
826 // scroll up, move down
831 // we need to hide the caret before moving or it will erase itself at
832 // the wrong (old) location
833 wxCaret
*caret
= GetCaret();
836 #endif // wxUSE_CARET
840 wxBitmap
bmp(size
.x
, size
.y
);
842 dcMem
.SelectObject(bmp
);
844 dcMem
.Blit(wxPoint(0, 0), size
, &dc
, ptSource
845 #if defined(__WXGTK__) && !defined(__WX_DC_BLIT_FIXED__)
846 + GetClientAreaOrigin()
847 #endif // broken wxGTK wxDC::Blit
849 dc
.Blit(ptDest
, size
, &dcMem
, wxPoint(0, 0));
851 wxLogTrace(_T("scroll"),
852 _T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"),
853 ptSource
.x
, ptSource
.y
,
857 // and now repaint the uncovered area
859 // FIXME: We repaint the intersection of these rectangles twice - is
860 // it bad? I don't think so as it is rare to scroll the window
861 // diagonally anyhow and so adding extra logic to compute
862 // rectangle intersection is probably not worth the effort
871 // refresh the area along the right border
872 rect
.x
+= size
.x
+ dx
;
877 // refresh the area along the left border
881 rect
.height
= sizeTotal
.y
;
883 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
885 rect
.GetRight() + 1, rect
.GetBottom() + 1);
892 // refresh the area along the bottom border
893 rect
.y
+= size
.y
+ dy
;
898 // refresh the area along the top border
902 rect
.width
= sizeTotal
.x
;
904 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
906 rect
.GetRight() + 1, rect
.GetBottom() + 1);
912 #endif // wxUSE_CARET
918 // ----------------------------------------------------------------------------
920 // ----------------------------------------------------------------------------
922 bool wxWindow::SetBackgroundColour(const wxColour
& colour
)
924 if ( !wxWindowNative::SetBackgroundColour(colour
) )
932 bool wxWindow::SetForegroundColour(const wxColour
& colour
)
934 if ( !wxWindowNative::SetForegroundColour(colour
) )
942 bool wxWindow::SetFont(const wxFont
& font
)
944 if ( !wxWindowNative::SetFont(font
) )
952 // ----------------------------------------------------------------------------
954 // ----------------------------------------------------------------------------
956 struct WXDLLEXPORT wxWindowNext
960 } *wxWindow::ms_winCaptureNext
= NULL
;
962 void wxWindow::CaptureMouse()
964 wxWindow
*winOld
= GetCapture();
968 wxWindowNext
*item
= new wxWindowNext
;
970 item
->next
= ms_winCaptureNext
;
971 ms_winCaptureNext
= item
;
973 //else: no mouse capture to save
975 wxWindowNative::CaptureMouse();
978 void wxWindow::ReleaseMouse()
980 wxWindowNative::ReleaseMouse();
982 if ( ms_winCaptureNext
)
984 ms_winCaptureNext
->win
->CaptureMouse();
986 wxWindowNext
*item
= ms_winCaptureNext
;
987 ms_winCaptureNext
= item
->next
;
990 //else: stack is empty, no previous capture
993 // ----------------------------------------------------------------------------
994 // accelerators and menu hot keys
995 // ----------------------------------------------------------------------------
998 // the last window over which Alt was pressed (used by OnKeyUp)
999 wxWindow
*wxWindow::ms_winLastAltPress
= NULL
;
1000 #endif // wxUSE_MENUS
1002 #if wxUSE_ACCEL || wxUSE_MENUS
1004 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
1007 int key
= event
.GetKeyCode();
1008 if ( !event
.ControlDown() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1010 ms_winLastAltPress
= this;
1012 // it can't be an accel anyhow
1016 ms_winLastAltPress
= NULL
;
1017 #endif // wxUSE_MENUS
1020 for ( wxWindow
*win
= this; win
; win
= win
->GetParent() )
1022 int command
= win
->GetAcceleratorTable()->GetCommand(event
);
1023 if ( command
!= -1 )
1025 wxCommandEvent
eventCmd(wxEVT_COMMAND_MENU_SELECTED
, command
);
1026 if ( win
->GetEventHandler()->ProcessEvent(eventCmd
) )
1028 // skip "event.Skip()" below
1033 if ( win
->IsTopLevel() )
1035 // try the frame menu bar
1037 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1040 wxMenuBar
*menubar
= frame
->GetMenuBar();
1041 if ( menubar
&& menubar
->ProcessAccelEvent(event
) )
1043 // skip "event.Skip()" below
1047 #endif // wxUSE_MENUS
1049 // don't propagate accels from the child frame to the parent one
1053 #endif // wxUSE_ACCEL
1058 #endif // wxUSE_ACCEL
1062 wxMenuBar
*wxWindow::GetParentFrameMenuBar() const
1064 for ( const wxWindow
*win
= this; win
; win
= win
->GetParent() )
1066 if ( win
->IsTopLevel() )
1068 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1071 return frame
->GetMenuBar();
1074 // don't look further - we don't want to return the menubar of the
1083 void wxWindow::OnChar(wxKeyEvent
& event
)
1085 if ( event
.AltDown() && !event
.ControlDown() )
1087 int key
= event
.GetKeyCode();
1089 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1092 int item
= menubar
->FindNextItemForAccel(-1, key
);
1095 menubar
->PopupMenu((size_t)item
);
1097 // skip "event.Skip()" below
1106 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1108 int key
= event
.GetKeyCode();
1109 if ( !event
.HasModifiers() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1111 // only process Alt release specially if there were no other key
1112 // presses since Alt had been pressed and if both events happened in
1114 if ( ms_winLastAltPress
== this )
1116 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1117 if ( menubar
&& this != menubar
)
1119 menubar
->SelectMenu(0);
1128 // in any case reset it
1129 ms_winLastAltPress
= NULL
;
1132 #endif // wxUSE_MENUS