From e36dcd10d0528529a055c63111b3aa64538d4313 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 8 Dec 2008 16:30:09 +0000 Subject: [PATCH] add the possibility to cancel drag-resizing by pressing Esc git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57195 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/generic/headerctrlg.h | 4 ++++ src/generic/headerctrlg.cpp | 27 +++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/include/wx/generic/headerctrlg.h b/include/wx/generic/headerctrlg.h index f7f9e89254..42fe827ea8 100644 --- a/include/wx/generic/headerctrlg.h +++ b/include/wx/generic/headerctrlg.h @@ -65,6 +65,7 @@ private: // event handlers void OnPaint(wxPaintEvent& event); void OnMouse(wxMouseEvent& event); + void OnKeyDown(wxKeyEvent& event); void OnCaptureLost(wxMouseCaptureLostEvent& event); // return the horizontal start position of the given column in physical @@ -87,6 +88,9 @@ private: // column 1 but close enough to the divider separating it from column 0) int FindColumnAtPos(int x, bool& onSeparator) const; + // return true if a drag resizing operation is currently in progress + bool IsResizing() const; + // end any drag operation currently in progress (resizing or reordering) void EndDragging(); diff --git a/src/generic/headerctrlg.cpp b/src/generic/headerctrlg.cpp index c4e6d1eaa9..08765fde17 100644 --- a/src/generic/headerctrlg.cpp +++ b/src/generic/headerctrlg.cpp @@ -214,6 +214,11 @@ void wxHeaderCtrl::RefreshColsAfter(unsigned int idx) // wxHeaderCtrl dragging // ---------------------------------------------------------------------------- +bool wxHeaderCtrl::IsResizing() const +{ + return m_colBeingResized != COL_NONE; +} + void wxHeaderCtrl::UpdateResizingMarker(int xPhysical) { // unfortunately drawing the marker over the parent window doesn't work as @@ -244,8 +249,7 @@ void wxHeaderCtrl::EndDragging() void wxHeaderCtrl::EndResizing(int width) { - wxASSERT_MSG( m_colBeingResized != COL_NONE, - "shouldn't be called if we're not resizing" ); + wxASSERT_MSG( IsResizing(), "shouldn't be called if we're not resizing" ); EndDragging(); @@ -277,6 +281,8 @@ BEGIN_EVENT_TABLE(wxHeaderCtrl, wxHeaderCtrlBase) EVT_MOUSE_EVENTS(wxHeaderCtrl::OnMouse) EVT_MOUSE_CAPTURE_LOST(wxHeaderCtrl::OnCaptureLost) + + EVT_KEY_DOWN(wxHeaderCtrl::OnKeyDown) END_EVENT_TABLE() void wxHeaderCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) @@ -345,8 +351,21 @@ void wxHeaderCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) void wxHeaderCtrl::OnCaptureLost(wxMouseCaptureLostEvent& WXUNUSED(event)) { - if ( m_colBeingResized != COL_NONE ) + if ( IsResizing() ) + EndResizing(-1); +} + +void wxHeaderCtrl::OnKeyDown(wxKeyEvent& event) +{ + if ( IsResizing() && event.GetKeyCode() == WXK_ESCAPE ) + { + ReleaseMouse(); EndResizing(-1); + } + else + { + event.Skip(); + } } void wxHeaderCtrl::OnMouse(wxMouseEvent& mevent) @@ -362,7 +381,7 @@ void wxHeaderCtrl::OnMouse(wxMouseEvent& mevent) // first deal with the [continuation of any] dragging operations in // progress - if ( m_colBeingResized != COL_NONE ) + if ( IsResizing() ) { if ( mevent.LeftUp() ) EndResizing(xPhysical - GetColStart(m_colBeingResized)); -- 2.45.2