honour column min width when resizing in wxHeaderCtrl, no need to do it in wxDataViewCtrl

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57201 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2008-12-08 17:33:03 +00:00
parent f14ed73f1a
commit a45caa71bf
4 changed files with 96 additions and 24 deletions

View File

@@ -94,9 +94,19 @@ private:
// end any drag operation currently in progress (resizing or reordering) // end any drag operation currently in progress (resizing or reordering)
void EndDragging(); void EndDragging();
// and the resizing operation currently in progress and generate an event // start (if m_colBeingResized is -1) or continue resizing the column
// about it with its cancelled flag set if width is -1 //
void EndResizing(int width); // this generates wxEVT_COMMAND_HEADER_BEGIN_RESIZE/RESIZING events and can
// cancel the operation if the user handler decides so
void StartOrContinueResizing(unsigned int col, int xPhysical);
// end the resizing operation currently in progress and generate an event
// about it with its cancelled flag set if xPhysical is -1
void EndResizing(int xPhysical);
// constrain the given position to be larger than the start position of the
// given column plus its minimal width and return the effective width
int ConstrainByMinWidth(unsigned int col, int& xPhysical);
// update the current position of the resizing marker if xPhysical is a // update the current position of the resizing marker if xPhysical is a
// valid physical coordinate value or remove it entirely if it is -1 // valid physical coordinate value or remove it entirely if it is -1

View File

@@ -143,15 +143,6 @@ private:
event.Veto(); event.Veto();
} }
void OnResizing(wxHeaderCtrlEvent& event)
{
const wxHeaderColumnBase& col = GetColumn(event.GetColumn());
const int minWidth = col.GetMinWidth();
if ( event.GetWidth() < minWidth )
event.Veto();
}
void OnEndResize(wxHeaderCtrlEvent& event) void OnEndResize(wxHeaderCtrlEvent& event)
{ {
if ( !event.IsCancelled() ) if ( !event.IsCancelled() )
@@ -171,7 +162,6 @@ BEGIN_EVENT_TABLE(wxDataViewHeaderWindow, wxHeaderCtrl)
EVT_HEADER_RIGHT_CLICK(wxID_ANY, wxDataViewHeaderWindow::OnRClick) EVT_HEADER_RIGHT_CLICK(wxID_ANY, wxDataViewHeaderWindow::OnRClick)
EVT_HEADER_BEGIN_RESIZE(wxID_ANY, wxDataViewHeaderWindow::OnBeginResize) EVT_HEADER_BEGIN_RESIZE(wxID_ANY, wxDataViewHeaderWindow::OnBeginResize)
EVT_HEADER_RESIZING(wxID_ANY, wxDataViewHeaderWindow::OnResizing)
EVT_HEADER_END_RESIZE(wxID_ANY, wxDataViewHeaderWindow::OnEndResize) EVT_HEADER_END_RESIZE(wxID_ANY, wxDataViewHeaderWindow::OnEndResize)
END_EVENT_TABLE() END_EVENT_TABLE()

View File

@@ -247,7 +247,54 @@ void wxHeaderCtrl::EndDragging()
SetCursor(wxNullCursor); SetCursor(wxNullCursor);
} }
void wxHeaderCtrl::EndResizing(int width) int wxHeaderCtrl::ConstrainByMinWidth(unsigned int col, int& xPhysical)
{
const int xStart = GetColStart(col);
// notice that GetMinWidth() returns 0 if there is no minimal width so it
// still makes sense to use it even in this case
const int xMinEnd = xStart + GetColumn(col).GetMinWidth();
if ( xPhysical < xMinEnd )
xPhysical = xMinEnd;
return xPhysical - xStart;
}
void wxHeaderCtrl::StartOrContinueResizing(unsigned int col, int xPhysical)
{
wxHeaderCtrlEvent event(IsResizing() ? wxEVT_COMMAND_HEADER_RESIZING
: wxEVT_COMMAND_HEADER_BEGIN_RESIZE,
GetId());
event.SetEventObject(this);
event.SetColumn(col);
event.SetWidth(ConstrainByMinWidth(col, xPhysical));
if ( GetEventHandler()->ProcessEvent(event) && !event.IsAllowed() )
{
if ( IsResizing() )
{
ReleaseMouse();
EndResizing(-1);
}
//else: nothing to do -- we just don't start to resize
}
else // go ahead with resizing
{
if ( !IsResizing() )
{
m_colBeingResized = col;
SetCursor(wxCursor(wxCURSOR_SIZEWE));
CaptureMouse();
}
//else: we had already done the above when we started
UpdateResizingMarker(xPhysical);
}
}
void wxHeaderCtrl::EndResizing(int xPhysical)
{ {
wxASSERT_MSG( IsResizing(), "shouldn't be called if we're not resizing" ); wxASSERT_MSG( IsResizing(), "shouldn't be called if we're not resizing" );
@@ -255,16 +302,16 @@ void wxHeaderCtrl::EndResizing(int width)
// if dragging was cancelled we must have already lost the mouse capture so // if dragging was cancelled we must have already lost the mouse capture so
// don't try to release it // don't try to release it
if ( width != -1 ) if ( xPhysical != -1 )
ReleaseMouse(); ReleaseMouse();
wxHeaderCtrlEvent event(wxEVT_COMMAND_HEADER_END_RESIZE, GetId()); wxHeaderCtrlEvent event(wxEVT_COMMAND_HEADER_END_RESIZE, GetId());
event.SetEventObject(this); event.SetEventObject(this);
event.SetColumn(m_colBeingResized); event.SetColumn(m_colBeingResized);
if ( width == -1 ) if ( xPhysical == -1 )
event.SetCancelled(); event.SetCancelled();
else else
event.SetWidth(width); event.SetWidth(ConstrainByMinWidth(m_colBeingResized, xPhysical));
GetEventHandler()->ProcessEvent(event); GetEventHandler()->ProcessEvent(event);
@@ -384,9 +431,9 @@ void wxHeaderCtrl::OnMouse(wxMouseEvent& mevent)
if ( IsResizing() ) if ( IsResizing() )
{ {
if ( mevent.LeftUp() ) if ( mevent.LeftUp() )
EndResizing(xPhysical - GetColStart(m_colBeingResized)); EndResizing(xPhysical);
else // update the live separator position else // update the live separator position
UpdateResizingMarker(xPhysical); StartOrContinueResizing(m_colBeingResized, xPhysical);
return; return;
} }
@@ -427,10 +474,8 @@ void wxHeaderCtrl::OnMouse(wxMouseEvent& mevent)
if ( onSeparator ) if ( onSeparator )
{ {
// start resizing the column // start resizing the column
m_colBeingResized = col; wxASSERT_MSG( !IsResizing(), "reentering resize mode?" );
SetCursor(wxCursor(wxCURSOR_SIZEWE)); StartOrContinueResizing(col, xPhysical);
CaptureMouse();
UpdateResizingMarker(xPhysical);
} }
else // on column itself else // on column itself
{ {

View File

@@ -295,6 +295,7 @@ bool wxHeaderCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
wxEventType evtType = wxEVT_NULL; wxEventType evtType = wxEVT_NULL;
int idx = nmhdr->iItem; int idx = nmhdr->iItem;
int width = 0; int width = 0;
bool cancelled = false;
const UINT code = nmhdr->hdr.code; const UINT code = nmhdr->hdr.code;
switch ( code ) switch ( code )
{ {
@@ -343,10 +344,34 @@ bool wxHeaderCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
case HDN_ENDTRACKA: case HDN_ENDTRACKA:
case HDN_ENDTRACKW: case HDN_ENDTRACKW:
width = nmhdr->pitem->cxy;
if ( evtType == wxEVT_NULL ) if ( evtType == wxEVT_NULL )
{
evtType = wxEVT_COMMAND_HEADER_END_RESIZE; evtType = wxEVT_COMMAND_HEADER_END_RESIZE;
width = nmhdr->pitem->cxy; // don't generate events with invalid width
const int minWidth = GetColumn(idx).GetMinWidth();
if ( width < minWidth )
width = minWidth;
}
break;
case HDN_ITEMCHANGING:
if ( nmhdr->pitem && (nmhdr->pitem->mask & HDI_WIDTH) )
{
// prevent the column from being shrunk beneath its min width
if ( nmhdr->pitem->cxy < GetColumn(idx).GetMinWidth() )
{
*result = TRUE;
return true;
}
}
break;
case NM_RELEASEDCAPTURE:
cancelled = true;
break; break;
} }
@@ -358,6 +383,8 @@ bool wxHeaderCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
event.SetEventObject(this); event.SetEventObject(this);
event.SetColumn(idx); event.SetColumn(idx);
event.SetWidth(width); event.SetWidth(width);
if ( cancelled )
event.SetCancelled();
if ( GetEventHandler()->ProcessEvent(event) ) if ( GetEventHandler()->ProcessEvent(event) )
{ {