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
This commit is contained in:
Vadim Zeitlin 2008-12-08 16:30:09 +00:00
parent 0c9c5b4376
commit e36dcd10d0
2 changed files with 27 additions and 4 deletions

View File

@ -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();

View File

@ -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,10 +351,23 @@ 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)
{
// do this in advance to allow simply returning if we're not interested,
@ -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));