fixed column resizing when the ctrl is horz scrolled
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7578 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -178,19 +178,34 @@ protected:
|
|||||||
wxCursor *m_currentCursor;
|
wxCursor *m_currentCursor;
|
||||||
wxCursor *m_resizeCursor;
|
wxCursor *m_resizeCursor;
|
||||||
bool m_isDragging;
|
bool m_isDragging;
|
||||||
int m_column;
|
|
||||||
int m_minX;
|
// column being resized
|
||||||
int m_currentX;
|
int m_column;
|
||||||
|
|
||||||
|
// divider line position in logical (unscrolled) coords
|
||||||
|
int m_currentX;
|
||||||
|
|
||||||
|
// minimal position beyond which the divider line can't be dragged in
|
||||||
|
// logical coords
|
||||||
|
int m_minX;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
wxListHeaderWindow();
|
wxListHeaderWindow();
|
||||||
~wxListHeaderWindow();
|
virtual ~wxListHeaderWindow();
|
||||||
wxListHeaderWindow( wxWindow *win, wxWindowID id, wxListMainWindow *owner,
|
|
||||||
const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
|
wxListHeaderWindow( wxWindow *win,
|
||||||
long style = 0, const wxString &name = "wxlistctrlcolumntitles" );
|
wxWindowID id,
|
||||||
|
wxListMainWindow *owner,
|
||||||
|
const wxPoint &pos = wxDefaultPosition,
|
||||||
|
const wxSize &size = wxDefaultSize,
|
||||||
|
long style = 0,
|
||||||
|
const wxString &name = "wxlistctrlcolumntitles" );
|
||||||
|
|
||||||
void DoDrawRect( wxDC *dc, int x, int y, int w, int h );
|
void DoDrawRect( wxDC *dc, int x, int y, int w, int h );
|
||||||
void OnPaint( wxPaintEvent &event );
|
|
||||||
void DrawCurrent();
|
void DrawCurrent();
|
||||||
|
void AdjustDC(wxDC& dc);
|
||||||
|
|
||||||
|
void OnPaint( wxPaintEvent &event );
|
||||||
void OnMouse( wxMouseEvent &event );
|
void OnMouse( wxMouseEvent &event );
|
||||||
void OnSetFocus( wxFocusEvent &event );
|
void OnSetFocus( wxFocusEvent &event );
|
||||||
|
|
||||||
@@ -1168,64 +1183,72 @@ void wxListHeaderWindow::DoDrawRect( wxDC *dc, int x, int y, int w, int h )
|
|||||||
dc->DrawLine( x+w-1, y, x+w-1, y+1 );
|
dc->DrawLine( x+w-1, y, x+w-1, y+1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// shift the DC origin to match the position of the main window horz
|
||||||
|
// scrollbar: this allows us to always use logical coords
|
||||||
|
void wxListHeaderWindow::AdjustDC(wxDC& dc)
|
||||||
|
{
|
||||||
|
#if wxUSE_GENERIC_LIST_EXTENSIONS
|
||||||
|
if ( m_owner->GetMode() & wxLC_REPORT )
|
||||||
|
{
|
||||||
|
int xpix;
|
||||||
|
m_owner->GetScrollPixelsPerUnit( &xpix, NULL );
|
||||||
|
|
||||||
|
int x;
|
||||||
|
m_owner->GetViewStart( &x, NULL );
|
||||||
|
|
||||||
|
// account for the horz scrollbar offset
|
||||||
|
dc.SetDeviceOrigin( -x * xpix, 0 );
|
||||||
|
}
|
||||||
|
#endif // wxUSE_GENERIC_LIST_EXTENSIONS
|
||||||
|
}
|
||||||
|
|
||||||
void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
||||||
{
|
{
|
||||||
wxPaintDC dc( this );
|
wxPaintDC dc( this );
|
||||||
PrepareDC( dc );
|
PrepareDC( dc );
|
||||||
#if wxUSE_GENERIC_LIST_EXTENSIONS
|
AdjustDC( dc );
|
||||||
if ( m_owner->GetMode() & wxLC_REPORT )
|
|
||||||
{
|
|
||||||
int x , y ;
|
|
||||||
int xpix , ypix ;
|
|
||||||
|
|
||||||
m_owner->GetScrollPixelsPerUnit( &xpix , &ypix ) ;
|
|
||||||
m_owner->ViewStart( &x, &y ) ;
|
|
||||||
dc.SetDeviceOrigin( -x * xpix, 0 );
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
dc.BeginDrawing();
|
dc.BeginDrawing();
|
||||||
|
|
||||||
dc.SetFont( GetFont() );
|
dc.SetFont( GetFont() );
|
||||||
|
|
||||||
int w = 0;
|
// width and height of the entire header window
|
||||||
int h = 0;
|
int w, h;
|
||||||
int x = 0;
|
|
||||||
int y = 0;
|
|
||||||
GetClientSize( &w, &h );
|
GetClientSize( &w, &h );
|
||||||
|
|
||||||
dc.SetBackgroundMode(wxTRANSPARENT);
|
dc.SetBackgroundMode(wxTRANSPARENT);
|
||||||
dc.SetTextForeground( *wxBLACK );
|
|
||||||
|
|
||||||
// do *not* use the listctrl colour for headers - one day we will have a
|
// do *not* use the listctrl colour for headers - one day we will have a
|
||||||
// function to set it separately
|
// function to set it separately
|
||||||
|
dc.SetTextForeground( *wxBLACK );
|
||||||
|
|
||||||
x = 1;
|
int x = 1; // left of the header rect
|
||||||
y = 1;
|
const int y = 1; // top
|
||||||
int numColumns = m_owner->GetColumnCount();
|
int numColumns = m_owner->GetColumnCount();
|
||||||
wxListItem item;
|
wxListItem item;
|
||||||
for (int i = 0; i < numColumns; i++)
|
for (int i = 0; i < numColumns; i++)
|
||||||
{
|
{
|
||||||
m_owner->GetColumn( i, item );
|
m_owner->GetColumn( i, item );
|
||||||
int cw = item.m_width-2;
|
int wCol = item.m_width;
|
||||||
|
int cw = wCol - 2;
|
||||||
|
|
||||||
|
int xEnd = x + wCol;
|
||||||
#if wxUSE_GENERIC_LIST_EXTENSIONS
|
#if wxUSE_GENERIC_LIST_EXTENSIONS
|
||||||
if ((i+1 == numColumns) || ( dc.LogicalToDeviceX(x+item.m_width) > w-5))
|
xEnd = dc.LogicalToDeviceX(xEnd);
|
||||||
cw = dc.DeviceToLogicalX(w)-x-1;
|
|
||||||
#else
|
|
||||||
if ((i+1 == numColumns) || (x+item.m_width > w-5))
|
|
||||||
cw = w-x-1;
|
|
||||||
#endif
|
#endif
|
||||||
|
if ((i+1 == numColumns) || (xEnd > w-5))
|
||||||
|
cw = w-x-1;
|
||||||
|
|
||||||
dc.SetPen( *wxWHITE_PEN );
|
dc.SetPen( *wxWHITE_PEN );
|
||||||
|
|
||||||
DoDrawRect( &dc, x, y, cw, h-2 );
|
DoDrawRect( &dc, x, y, cw, h-2 );
|
||||||
dc.SetClippingRegion( x, y, cw-5, h-4 );
|
dc.SetClippingRegion( x, y, cw-5, h-4 );
|
||||||
dc.DrawText( item.m_text, x+4, y+3 );
|
dc.DrawText( item.m_text, x+4, y+3 );
|
||||||
dc.DestroyClippingRegion();
|
dc.DestroyClippingRegion();
|
||||||
x += item.m_width;
|
x += wCol;
|
||||||
#if wxUSE_GENERIC_LIST_EXTENSIONS
|
|
||||||
if (dc.LogicalToDeviceX(x) > w+5) break;
|
if (xEnd > w+5)
|
||||||
#else
|
break;
|
||||||
if (x > w+5) break;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
dc.EndDrawing();
|
dc.EndDrawing();
|
||||||
}
|
}
|
||||||
@@ -1234,20 +1257,20 @@ void wxListHeaderWindow::DrawCurrent()
|
|||||||
{
|
{
|
||||||
int x1 = m_currentX;
|
int x1 = m_currentX;
|
||||||
int y1 = 0;
|
int y1 = 0;
|
||||||
|
ClientToScreen( &x1, &y1 );
|
||||||
|
|
||||||
int x2 = m_currentX-1;
|
int x2 = m_currentX-1;
|
||||||
int y2 = 0;
|
int y2 = 0;
|
||||||
m_owner->GetClientSize( NULL, &y2 );
|
m_owner->GetClientSize( NULL, &y2 );
|
||||||
ClientToScreen( &x1, &y1 );
|
|
||||||
m_owner->ClientToScreen( &x2, &y2 );
|
m_owner->ClientToScreen( &x2, &y2 );
|
||||||
|
|
||||||
m_owner->CalcScrolledPosition( x1, 0, &x1, NULL );
|
|
||||||
x2 = x1 - 1;
|
|
||||||
|
|
||||||
wxScreenDC dc;
|
wxScreenDC dc;
|
||||||
dc.SetLogicalFunction( wxINVERT );
|
dc.SetLogicalFunction( wxINVERT );
|
||||||
dc.SetPen( wxPen( *wxBLACK, 2, wxSOLID ) );
|
dc.SetPen( wxPen( *wxBLACK, 2, wxSOLID ) );
|
||||||
dc.SetBrush( *wxTRANSPARENT_BRUSH );
|
dc.SetBrush( *wxTRANSPARENT_BRUSH );
|
||||||
|
|
||||||
|
AdjustDC(dc);
|
||||||
|
|
||||||
dc.DrawLine( x1, y1, x2, y2 );
|
dc.DrawLine( x1, y1, x2, y2 );
|
||||||
|
|
||||||
dc.SetLogicalFunction( wxCOPY );
|
dc.SetLogicalFunction( wxCOPY );
|
||||||
@@ -1258,10 +1281,14 @@ void wxListHeaderWindow::DrawCurrent()
|
|||||||
|
|
||||||
void wxListHeaderWindow::OnMouse( wxMouseEvent &event )
|
void wxListHeaderWindow::OnMouse( wxMouseEvent &event )
|
||||||
{
|
{
|
||||||
|
// we want to work with logical coords
|
||||||
|
#if wxUSE_GENERIC_LIST_EXTENSIONS
|
||||||
|
int x, y;
|
||||||
|
m_owner->CalcUnscrolledPosition(event.GetX(), event.GetY(), &x, &y);
|
||||||
|
#else // !wxUSE_GENERIC_LIST_EXTENSIONS
|
||||||
int x = event.GetX();
|
int x = event.GetX();
|
||||||
int y = event.GetY();
|
int y = event.GetY();
|
||||||
|
#endif // wxUSE_GENERIC_LIST_EXTENSIONS
|
||||||
m_owner->CalcUnscrolledPosition( x, 0, &x, NULL );
|
|
||||||
|
|
||||||
if (m_isDragging)
|
if (m_isDragging)
|
||||||
{
|
{
|
||||||
@@ -1289,20 +1316,30 @@ void wxListHeaderWindow::OnMouse( wxMouseEvent &event )
|
|||||||
|
|
||||||
m_minX = 0;
|
m_minX = 0;
|
||||||
bool hit_border = FALSE;
|
bool hit_border = FALSE;
|
||||||
|
|
||||||
|
// end of the current column
|
||||||
int xpos = 0;
|
int xpos = 0;
|
||||||
for (int j = 0; j < m_owner->GetColumnCount(); j++)
|
|
||||||
|
// find the column where this event occured
|
||||||
|
int countCol = m_owner->GetColumnCount();
|
||||||
|
for (int j = 0; j < countCol; j++)
|
||||||
{
|
{
|
||||||
xpos += m_owner->GetColumnWidth( j );
|
xpos += m_owner->GetColumnWidth( j );
|
||||||
m_column = j;
|
m_column = j;
|
||||||
if ((abs(x-xpos) < 3) && (y < 22) && (m_column < m_owner->GetColumnCount()-1))
|
|
||||||
|
if ((abs(x-xpos) < 3) && (y < 22) && (m_column < countCol - 1))
|
||||||
{
|
{
|
||||||
|
// near the column border
|
||||||
hit_border = TRUE;
|
hit_border = TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (x-xpos < 0)
|
|
||||||
|
if ( x < xpos )
|
||||||
{
|
{
|
||||||
|
// inside the column
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_minX = xpos;
|
m_minX = xpos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user