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();
138 // the colours/fonts are default
146 // ----------------------------------------------------------------------------
148 // ----------------------------------------------------------------------------
150 void wxWindow::SetBackground(const wxBitmap
& bitmap
,
155 m_alignBgBitmap
= alignment
;
156 m_stretchBgBitmap
= stretch
;
159 const wxBitmap
& wxWindow::GetBackgroundBitmap(int *alignment
,
160 wxStretch
*stretch
) const
162 if ( m_bitmapBg
.Ok() )
165 *alignment
= m_alignBgBitmap
;
167 *stretch
= m_stretchBgBitmap
;
173 // ----------------------------------------------------------------------------
175 // ----------------------------------------------------------------------------
177 // the event handler executed when the window background must be painted
178 void wxWindow::OnErase(wxEraseEvent
& event
)
187 DoDrawBackground(*event
.GetDC());
189 // if we have both scrollbars, we also have a square in the corner between
190 // them which we must paint
191 if ( m_scrollbarVert
&& m_scrollbarHorz
)
193 wxSize size
= GetSize();
194 wxRect rectClient
= GetClientRect(),
195 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
198 rectCorner
.x
= rectClient
.GetRight() + 1;
199 rectCorner
.y
= rectClient
.GetBottom() + 1;
200 rectCorner
.SetRight(size
.x
- rectBorder
.width
);
201 rectCorner
.SetBottom(size
.y
- rectBorder
.height
);
203 if ( GetUpdateRegion().Contains(rectCorner
) )
205 m_renderer
->DrawScrollCorner(*event
.GetDC(), rectCorner
);
210 // the event handlers executed when the window must be repainted
211 void wxWindow::OnNcPaint(wxPaintEvent
& event
)
215 // get the window rect
217 wxSize size
= GetSize();
221 rect
.height
= size
.y
;
223 // if the scrollbars are outside the border, we must adjust the rect to
225 if ( !m_renderer
->AreScrollbarsInsideBorder() )
227 wxScrollBar
*scrollbar
= GetScrollbar(wxVERTICAL
);
229 rect
.width
-= scrollbar
->GetSize().x
;
231 scrollbar
= GetScrollbar(wxHORIZONTAL
);
233 rect
.height
-= scrollbar
->GetSize().y
;
236 // get the DC and draw the border on it
238 DoDrawBorder(dc
, rect
);
242 void wxWindow::OnPaint(wxPaintEvent
& event
)
246 // it is a native control which paints itself
251 // get the DC to use and create renderer on it
253 wxControlRenderer
renderer(this, dc
, m_renderer
);
260 bool wxWindow::DoDrawBackground(wxDC
& dc
)
262 // FIXME: leaving this code in leads to partial bg redraws sometimes under
266 rect
= GetUpdateRegion().GetBox();
267 if ( !rect
.width
&& !rect
.height
)
270 wxSize size
= GetSize();
272 rect
.height
= size
.y
;
275 if ( GetBackgroundBitmap().Ok() )
277 // get the bitmap and the flags
280 wxBitmap bmp
= GetBackgroundBitmap(&alignment
, &stretch
);
281 wxControlRenderer::DrawBitmap(dc
, bmp
, rect
, alignment
, stretch
);
283 else // just fill it with bg colour if no bitmap
285 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this),
286 rect
, GetStateFlags());
292 void wxWindow::EraseBackground(wxDC
& dc
, const wxRect
& rect
)
294 // TODO: handle bg bitmaps here!
296 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this), rect
, GetStateFlags());
299 void wxWindow::DoDrawBorder(wxDC
& dc
, const wxRect
& rect
)
301 // draw outline unless the update region is enitrely inside it in which
302 // case we don't need to do it
303 #if 0 // doesn't seem to work, why?
304 if ( wxRegion(rect
).Contains(GetUpdateRegion().GetBox()) != wxInRegion
)
307 m_renderer
->DrawBorder(dc
, GetBorder(), rect
, GetStateFlags());
311 void wxWindow::DoDraw(wxControlRenderer
*renderer
)
315 void wxWindow::Refresh(bool eraseBackground
, const wxRect
*rectClient
)
318 wxPoint pt
= GetClientAreaOrigin();
320 wxSize size
= GetClientSize();
324 rectWin
= *rectClient
;
326 // don't refresh anything beyond the client area (scrollbars for
328 if ( rectWin
.GetRight() > size
.x
)
329 rectWin
.SetRight(size
.x
);
330 if ( rectWin
.GetBottom() > size
.y
)
331 rectWin
.SetBottom(size
.y
);
335 else // refresh the entire client area
339 rectWin
.width
= size
.x
;
340 rectWin
.height
= size
.y
;
344 #ifdef WXDEBUG_REFRESH
345 static bool s_refreshDebug
= FALSE
;
346 if ( s_refreshDebug
)
349 dc
.SetBrush(*wxCYAN_BRUSH
);
350 dc
.SetPen(*wxTRANSPARENT_PEN
);
351 dc
.DrawRectangle(rectWin
);
353 // under Unix we use "--sync" X option for this
354 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
359 #endif // WXDEBUG_REFRESH
361 wxWindowNative::Refresh(eraseBackground
, &rectWin
);
364 // ----------------------------------------------------------------------------
366 // ----------------------------------------------------------------------------
368 bool wxWindow::Enable(bool enable
)
370 if ( !wxWindowNative::Enable(enable
) )
373 // disabled window can't keep focus
374 if ( FindFocus() == this )
376 GetParent()->SetFocus();
381 // a window with renderer is drawn by ourselves and it has to be
382 // refreshed to reflect its new status
389 bool wxWindow::IsFocused() const
391 wxWindow
*self
= wxConstCast(this, wxWindow
);
392 return self
->FindFocus() == self
;
395 bool wxWindow::IsPressed() const
400 bool wxWindow::IsDefault() const
405 bool wxWindow::IsCurrent() const
410 bool wxWindow::SetCurrent(bool doit
)
412 if ( doit
== m_isCurrent
)
417 if ( CanBeHighlighted() )
423 int wxWindow::GetStateFlags() const
427 flags
|= wxCONTROL_DISABLED
;
429 // the following states are only possible if our application is active - if
430 // it is not, even our default/focused controls shouldn't appear as such
431 if ( wxTheApp
->IsActive() )
434 flags
|= wxCONTROL_CURRENT
;
436 flags
|= wxCONTROL_FOCUSED
;
438 flags
|= wxCONTROL_PRESSED
;
440 flags
|= wxCONTROL_ISDEFAULT
;
446 // ----------------------------------------------------------------------------
448 // ----------------------------------------------------------------------------
450 void wxWindow::OnSize(wxSizeEvent
& event
)
452 if ( m_scrollbarVert
|| m_scrollbarHorz
)
454 PositionScrollbars();
460 wxSize
wxWindow::DoGetBestSize() const
462 return AdjustSize(DoGetBestClientSize());
465 wxSize
wxWindow::DoGetBestClientSize() const
467 return wxWindowNative::DoGetBestSize();
470 wxSize
wxWindow::AdjustSize(const wxSize
& size
) const
474 m_renderer
->AdjustSize(&sz
, this);
478 wxPoint
wxWindow::GetClientAreaOrigin() const
480 wxPoint pt
= wxWindowBase::GetClientAreaOrigin();
483 pt
+= m_renderer
->GetBorderDimensions(GetBorder()).GetPosition();
488 void wxWindow::DoGetClientSize(int *width
, int *height
) const
490 // if it is a native window, we assume it handles the scrollbars itself
491 // too - and if it doesn't, there is not much we can do
494 wxWindowNative::DoGetClientSize(width
, height
);
500 wxWindowNative::DoGetClientSize(&w
, &h
);
502 // we assume that the scrollbars are positioned correctly (by a previous
503 // call to PositionScrollbars()) here
507 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
509 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
513 // in any case, take account of the scrollbar
514 if ( m_scrollbarVert
)
515 w
-= m_scrollbarVert
->GetSize().x
;
517 // if we don't have scrollbar or if it is outside the border (and not
518 // blended into it), take account of the right border as well
519 if ( !m_scrollbarVert
|| inside
)
520 w
-= rectBorder
.width
;
522 // and always account for the left border
523 *width
= w
- rectBorder
.x
;
525 // we shouldn't return invalid width
532 if ( m_scrollbarHorz
)
533 h
-= m_scrollbarHorz
->GetSize().y
;
535 if ( !m_scrollbarHorz
|| inside
)
536 h
-= rectBorder
.height
;
538 *height
= h
- rectBorder
.y
;
540 // we shouldn't return invalid height
546 void wxWindow::DoSetClientSize(int width
, int height
)
548 // take into account the borders
549 wxRect rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
550 width
+= rectBorder
.x
;
551 height
+= rectBorder
.y
;
553 // and the scrollbars (as they may be offset into the border, use the
554 // scrollbar position, not size - this supposes that PositionScrollbars()
555 // had been called before)
556 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
557 wxSize size
= GetSize();
558 if ( m_scrollbarVert
)
559 width
+= size
.x
- m_scrollbarVert
->GetPosition().x
;
560 if ( !m_scrollbarVert
|| inside
)
561 width
+= rectBorder
.width
;
563 if ( m_scrollbarHorz
)
564 height
+= size
.y
- m_scrollbarHorz
->GetPosition().y
;
565 if ( !m_scrollbarHorz
|| inside
)
566 height
+= rectBorder
.height
;
568 wxWindowNative::DoSetClientSize(width
, height
);
571 wxHitTest
wxWindow::DoHitTest(wxCoord x
, wxCoord y
) const
573 wxHitTest ht
= wxWindowNative::DoHitTest(x
, y
);
574 if ( ht
== wxHT_WINDOW_INSIDE
)
576 if ( m_scrollbarVert
&& x
>= m_scrollbarVert
->GetPosition().x
)
578 // it can still be changed below because it may also be the corner
579 ht
= wxHT_WINDOW_VERT_SCROLLBAR
;
582 if ( m_scrollbarHorz
&& y
>= m_scrollbarHorz
->GetPosition().y
)
584 ht
= ht
== wxHT_WINDOW_VERT_SCROLLBAR
? wxHT_WINDOW_CORNER
585 : wxHT_WINDOW_HORZ_SCROLLBAR
;
592 // ----------------------------------------------------------------------------
593 // scrolling: we implement it entirely ourselves except for ScrollWindow()
594 // function which is supposed to be (efficiently) implemented by the native
596 // ----------------------------------------------------------------------------
598 void wxWindow::RefreshScrollbars()
600 if ( m_scrollbarHorz
)
601 m_scrollbarHorz
->Refresh();
603 if ( m_scrollbarVert
)
604 m_scrollbarVert
->Refresh();
607 void wxWindow::PositionScrollbars()
609 // do not use GetClientSize/Rect as it relies on the scrollbars being
610 // correctly positioned
612 wxSize size
= GetSize();
613 wxBorder border
= GetBorder();
614 wxRect rectBorder
= m_renderer
->GetBorderDimensions(border
);
615 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
617 int height
= m_scrollbarHorz
? m_scrollbarHorz
->GetSize().y
: 0;
618 int width
= m_scrollbarVert
? m_scrollbarVert
->GetSize().x
: 0;
621 if ( m_scrollbarVert
)
623 rectBar
.x
= size
.x
- width
;
625 rectBar
.x
-= rectBorder
.width
;
626 rectBar
.width
= width
;
629 rectBar
.y
+= rectBorder
.y
;
630 rectBar
.height
= size
.y
- height
;
632 rectBar
.height
-= rectBorder
.y
+ rectBorder
.height
;
634 m_scrollbarVert
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
637 if ( m_scrollbarHorz
)
639 rectBar
.y
= size
.y
- height
;
641 rectBar
.y
-= rectBorder
.height
;
642 rectBar
.height
= height
;
645 rectBar
.x
+= rectBorder
.x
;
646 rectBar
.width
= size
.x
- width
;
648 rectBar
.width
-= rectBorder
.x
+ rectBorder
.width
;
650 m_scrollbarHorz
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
656 void wxWindow::SetScrollbar(int orient
,
662 bool hasClientSizeChanged
= FALSE
;
663 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
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 // ----------------------------------------------------------------------------
940 // ----------------------------------------------------------------------------
942 bool wxWindow::SetBackgroundColour(const wxColour
& colour
)
944 if ( !wxWindowNative::SetBackgroundColour(colour
) )
952 bool wxWindow::SetForegroundColour(const wxColour
& colour
)
954 if ( !wxWindowNative::SetForegroundColour(colour
) )
962 bool wxWindow::SetFont(const wxFont
& font
)
964 if ( !wxWindowNative::SetFont(font
) )
972 // ----------------------------------------------------------------------------
974 // ----------------------------------------------------------------------------
976 struct WXDLLEXPORT wxWindowNext
980 } *wxWindow::ms_winCaptureNext
= NULL
;
982 void wxWindow::CaptureMouse()
984 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(0x%08x)"), this);
986 wxWindow
*winOld
= GetCapture();
990 wxWindowNext
*item
= new wxWindowNext
;
992 item
->next
= ms_winCaptureNext
;
993 ms_winCaptureNext
= item
;
995 //else: no mouse capture to save
997 wxWindowNative::CaptureMouse();
1000 void wxWindow::ReleaseMouse()
1002 wxWindowNative::ReleaseMouse();
1004 if ( ms_winCaptureNext
)
1006 ms_winCaptureNext
->win
->CaptureMouse();
1008 wxWindowNext
*item
= ms_winCaptureNext
;
1009 ms_winCaptureNext
= item
->next
;
1012 //else: stack is empty, no previous capture
1014 wxLogTrace(_T("mousecapture"),
1015 _T("After ReleaseMouse() mouse is captured by 0x%08x"),
1019 // ----------------------------------------------------------------------------
1020 // accelerators and menu hot keys
1021 // ----------------------------------------------------------------------------
1024 // the last window over which Alt was pressed (used by OnKeyUp)
1025 wxWindow
*wxWindow::ms_winLastAltPress
= NULL
;
1026 #endif // wxUSE_MENUS
1028 #if wxUSE_ACCEL || wxUSE_MENUS
1030 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
1033 int key
= event
.GetKeyCode();
1034 if ( !event
.ControlDown() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1036 ms_winLastAltPress
= this;
1038 // it can't be an accel anyhow
1042 ms_winLastAltPress
= NULL
;
1043 #endif // wxUSE_MENUS
1046 for ( wxWindow
*win
= this; win
; win
= win
->GetParent() )
1048 int command
= win
->GetAcceleratorTable()->GetCommand(event
);
1049 if ( command
!= -1 )
1051 wxCommandEvent
eventCmd(wxEVT_COMMAND_MENU_SELECTED
, command
);
1052 if ( win
->GetEventHandler()->ProcessEvent(eventCmd
) )
1054 // skip "event.Skip()" below
1059 if ( win
->IsTopLevel() )
1061 // try the frame menu bar
1063 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1066 wxMenuBar
*menubar
= frame
->GetMenuBar();
1067 if ( menubar
&& menubar
->ProcessAccelEvent(event
) )
1069 // skip "event.Skip()" below
1073 #endif // wxUSE_MENUS
1075 // don't propagate accels from the child frame to the parent one
1079 #endif // wxUSE_ACCEL
1084 #endif // wxUSE_ACCEL
1088 wxMenuBar
*wxWindow::GetParentFrameMenuBar() const
1090 for ( const wxWindow
*win
= this; win
; win
= win
->GetParent() )
1092 if ( win
->IsTopLevel() )
1094 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1097 return frame
->GetMenuBar();
1100 // don't look further - we don't want to return the menubar of the
1109 void wxWindow::OnChar(wxKeyEvent
& event
)
1111 if ( event
.AltDown() && !event
.ControlDown() )
1113 int key
= event
.GetKeyCode();
1115 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1118 int item
= menubar
->FindNextItemForAccel(-1, key
);
1121 menubar
->PopupMenu((size_t)item
);
1123 // skip "event.Skip()" below
1132 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1134 int key
= event
.GetKeyCode();
1135 if ( !event
.HasModifiers() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1137 // only process Alt release specially if there were no other key
1138 // presses since Alt had been pressed and if both events happened in
1140 if ( ms_winLastAltPress
== this )
1142 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1143 if ( menubar
&& this != menubar
)
1145 menubar
->SelectMenu(0);
1154 // in any case reset it
1155 ms_winLastAltPress
= NULL
;
1158 #endif // wxUSE_MENUS