column resizing is still broken :-((

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7579 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2000-06-16 15:34:21 +00:00
parent aa54dcf52c
commit 12675983a2

View File

@@ -209,6 +209,9 @@ public:
void OnMouse( wxMouseEvent &event ); void OnMouse( wxMouseEvent &event );
void OnSetFocus( wxFocusEvent &event ); void OnSetFocus( wxFocusEvent &event );
// needs refresh
bool m_dirty;
private: private:
DECLARE_DYNAMIC_CLASS(wxListHeaderWindow) DECLARE_DYNAMIC_CLASS(wxListHeaderWindow)
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
@@ -1152,6 +1155,8 @@ wxListHeaderWindow::wxListHeaderWindow( wxWindow *win, wxWindowID id, wxListMain
m_currentCursor = (wxCursor *) NULL; m_currentCursor = (wxCursor *) NULL;
m_resizeCursor = new wxCursor( wxCURSOR_SIZEWE ); m_resizeCursor = new wxCursor( wxCURSOR_SIZEWE );
m_isDragging = FALSE; m_isDragging = FALSE;
m_dirty = FALSE;
SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE ) ); SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE ) );
} }
@@ -1188,17 +1193,14 @@ void wxListHeaderWindow::DoDrawRect( wxDC *dc, int x, int y, int w, int h )
void wxListHeaderWindow::AdjustDC(wxDC& dc) void wxListHeaderWindow::AdjustDC(wxDC& dc)
{ {
#if wxUSE_GENERIC_LIST_EXTENSIONS #if wxUSE_GENERIC_LIST_EXTENSIONS
if ( m_owner->GetMode() & wxLC_REPORT ) int xpix;
{ m_owner->GetScrollPixelsPerUnit( &xpix, NULL );
int xpix;
m_owner->GetScrollPixelsPerUnit( &xpix, NULL );
int x; int x;
m_owner->GetViewStart( &x, NULL ); m_owner->GetViewStart( &x, NULL );
// account for the horz scrollbar offset // account for the horz scrollbar offset
dc.SetDeviceOrigin( -x * xpix, 0 ); dc.SetDeviceOrigin( -x * xpix, 0 );
}
#endif // wxUSE_GENERIC_LIST_EXTENSIONS #endif // wxUSE_GENERIC_LIST_EXTENSIONS
} }
@@ -1215,6 +1217,9 @@ void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
// width and height of the entire header window // width and height of the entire header window
int w, h; int w, h;
GetClientSize( &w, &h ); GetClientSize( &w, &h );
#if wxUSE_GENERIC_LIST_EXTENSIONS
m_owner->CalcUnscrolledPosition(w, 0, &w, NULL);
#endif // wxUSE_GENERIC_LIST_EXTENSIONS
dc.SetBackgroundMode(wxTRANSPARENT); dc.SetBackgroundMode(wxTRANSPARENT);
@@ -1230,13 +1235,12 @@ void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
{ {
m_owner->GetColumn( i, item ); m_owner->GetColumn( i, item );
int wCol = item.m_width; int wCol = item.m_width;
int cw = wCol - 2; int cw = wCol - 2; // the width of the rect to draw
int xEnd = x + wCol; int xEnd = x + wCol;
#if wxUSE_GENERIC_LIST_EXTENSIONS
xEnd = dc.LogicalToDeviceX(xEnd); // let the last column occupy all available space
#endif if ( i == numColumns - 1 )
if ((i+1 == numColumns) || (xEnd > w-5))
cw = w-x-1; cw = w-x-1;
dc.SetPen( *wxWHITE_PEN ); dc.SetPen( *wxWHITE_PEN );
@@ -1292,7 +1296,9 @@ void wxListHeaderWindow::OnMouse( wxMouseEvent &event )
if (m_isDragging) if (m_isDragging)
{ {
// erase the line
DrawCurrent(); DrawCurrent();
if (event.ButtonUp()) if (event.ButtonUp())
{ {
ReleaseMouse(); ReleaseMouse();
@@ -1301,85 +1307,86 @@ void wxListHeaderWindow::OnMouse( wxMouseEvent &event )
} }
else else
{ {
int size_x = 0; int w = 0;
int dummy; GetClientSize( &w, NULL );
GetClientSize( &size_x, & dummy ); if (x > m_minX + 7)
if (x > m_minX+7)
m_currentX = x; m_currentX = x;
else else
m_currentX = m_minX+7; m_currentX = m_minX + 7;
if (m_currentX > size_x-7) m_currentX = size_x-7;
if ( m_currentX > w - 7 )
m_currentX = w - 7;
// draw in the new location
DrawCurrent(); DrawCurrent();
} }
return;
} }
else // not dragging
m_minX = 0;
bool hit_border = FALSE;
// end of the current column
int xpos = 0;
// find the column where this event occured
int countCol = m_owner->GetColumnCount();
for (int j = 0; j < countCol; j++)
{ {
xpos += m_owner->GetColumnWidth( j ); m_minX = 0;
m_column = j; bool hit_border = FALSE;
if ((abs(x-xpos) < 3) && (y < 22) && (m_column < countCol - 1)) // end of the current column
int xpos = 0;
// find the column where this event occured
int countCol = m_owner->GetColumnCount();
for (int j = 0; j < countCol; j++)
{ {
// near the column border xpos += m_owner->GetColumnWidth( j );
hit_border = TRUE; m_column = j;
break;
if ( (abs(x-xpos) < 3) && (y < 22) )
{
// near the column border
hit_border = TRUE;
break;
}
if ( x < xpos )
{
// inside the column
break;
}
m_minX = xpos;
} }
if ( x < xpos ) if (event.LeftDown())
{ {
// inside the column if (hit_border)
break; {
m_isDragging = TRUE;
m_currentX = x;
DrawCurrent();
CaptureMouse();
}
else
{
wxWindow *parent = GetParent();
wxListEvent le( wxEVT_COMMAND_LIST_COL_CLICK, parent->GetId() );
le.SetEventObject( parent );
le.m_col = m_column;
parent->GetEventHandler()->ProcessEvent( le );
}
} }
else if (event.Moving())
m_minX = xpos;
}
if (event.LeftDown())
{
if (hit_border)
{ {
m_isDragging = TRUE; bool setCursor;
m_currentX = x; if (hit_border)
DrawCurrent(); {
CaptureMouse(); setCursor = m_currentCursor == wxSTANDARD_CURSOR;
return; m_currentCursor = m_resizeCursor;
} }
else else
{ {
wxListEvent le( wxEVT_COMMAND_LIST_COL_CLICK, GetParent()->GetId() ); setCursor = m_currentCursor != wxSTANDARD_CURSOR;
le.SetEventObject( GetParent() ); m_currentCursor = wxSTANDARD_CURSOR;
le.m_col = m_column; }
GetParent()->GetEventHandler()->ProcessEvent( le );
return;
}
}
if ( setCursor )
if (event.Moving()) SetCursor(*m_currentCursor);
{
bool setCursor;
if (hit_border)
{
setCursor = m_currentCursor == wxSTANDARD_CURSOR;
m_currentCursor = m_resizeCursor;
} }
else
{
setCursor = m_currentCursor != wxSTANDARD_CURSOR;
m_currentCursor = wxSTANDARD_CURSOR;
}
if ( setCursor )
SetCursor(*m_currentCursor);
} }
} }
@@ -2338,20 +2345,27 @@ void wxListMainWindow::SetColumn( int col, wxListItem &item )
wxListHeaderData *column = (wxListHeaderData*)node->Data(); wxListHeaderData *column = (wxListHeaderData*)node->Data();
column->SetItem( item ); column->SetItem( item );
} }
wxListCtrl *lc = (wxListCtrl*) GetParent();
if (lc->m_headerWin) lc->m_headerWin->Refresh(); wxListHeaderWindow *headerWin = ((wxListCtrl*) GetParent())->m_headerWin;
if ( headerWin )
headerWin->m_dirty = TRUE;
} }
void wxListMainWindow::SetColumnWidth( int col, int width ) void wxListMainWindow::SetColumnWidth( int col, int width )
{ {
if (!(m_mode & wxLC_REPORT)) return; wxCHECK_RET( m_mode & wxLC_REPORT,
_T("SetColumnWidth() can only be called in report mode.") );
m_dirty = TRUE; m_dirty = TRUE;
wxNode *node = (wxNode*) NULL; wxNode *node = (wxNode*) NULL;
if (width == wxLIST_AUTOSIZE_USEHEADER) width = 80; if (width == wxLIST_AUTOSIZE_USEHEADER)
if (width == wxLIST_AUTOSIZE) {
// TODO do use the header
width = 80;
}
else if (width == wxLIST_AUTOSIZE)
{ {
wxClientDC dc(this); wxClientDC dc(this);
dc.SetFont( GetFont() ); dc.SetFont( GetFont() );
@@ -2405,8 +2419,9 @@ void wxListMainWindow::SetColumnWidth( int col, int width )
node = node->Next(); node = node->Next();
} }
wxListCtrl *lc = (wxListCtrl*) GetParent(); wxListHeaderWindow *headerWin = ((wxListCtrl*) GetParent())->m_headerWin;
if (lc->m_headerWin) lc->m_headerWin->Refresh(); if ( headerWin )
headerWin->m_dirty = TRUE;
} }
void wxListMainWindow::GetColumn( int col, wxListItem &item ) void wxListMainWindow::GetColumn( int col, wxListItem &item )
@@ -3634,6 +3649,12 @@ void wxListCtrl::OnIdle( wxIdleEvent &WXUNUSED(event) )
m_mainWin->RealizeChanges(); m_mainWin->RealizeChanges();
m_mainWin->m_dirty = FALSE; m_mainWin->m_dirty = FALSE;
m_mainWin->Refresh(); m_mainWin->Refresh();
if ( m_headerWin && m_headerWin->m_dirty )
{
m_headerWin->m_dirty = FALSE;
m_headerWin->Refresh();
}
} }
bool wxListCtrl::SetBackgroundColour( const wxColour &colour ) bool wxListCtrl::SetBackgroundColour( const wxColour &colour )