Pixel corrections for wxListCtrl
Speedup for wxTreeCtrl::Insert() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1094 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -386,19 +386,18 @@ public:
|
||||
void SortChildren(const wxTreeItemId& item,
|
||||
wxTreeItemCmpFunc *cmpFunction = NULL);
|
||||
|
||||
// implementation
|
||||
// --------------
|
||||
// wxWindows callbacks
|
||||
void OnPaint( const wxPaintEvent &event );
|
||||
void OnSetFocus( const wxFocusEvent &event );
|
||||
void OnKillFocus( const wxFocusEvent &event );
|
||||
void OnPaint( wxPaintEvent &event );
|
||||
void OnSetFocus( wxFocusEvent &event );
|
||||
void OnKillFocus( wxFocusEvent &event );
|
||||
void OnChar( wxKeyEvent &event );
|
||||
void OnMouse( const wxMouseEvent &event );
|
||||
void OnMouse( wxMouseEvent &event );
|
||||
void OnIdle( wxIdleEvent &event );
|
||||
|
||||
protected:
|
||||
wxGenericTreeItem *m_anchor;
|
||||
wxGenericTreeItem *m_current;
|
||||
bool m_hasFocus;
|
||||
bool m_dirty;
|
||||
int m_xScroll,m_yScroll;
|
||||
unsigned int m_indent;
|
||||
int m_lineHeight;
|
||||
|
@@ -174,7 +174,7 @@ void MyFrame::OnDump(wxCommandEvent& WXUNUSED(event))
|
||||
|
||||
void MyFrame::DoSetBold(bool bold)
|
||||
{
|
||||
m_treeCtrl->SetItemBold(m_treeCtrl->GetSelection(), bold);
|
||||
// m_treeCtrl->SetItemBold(m_treeCtrl->GetSelection(), bold);
|
||||
}
|
||||
|
||||
void MyFrame::OnDelete(wxCommandEvent& WXUNUSED(event))
|
||||
@@ -204,8 +204,8 @@ MyTreeCtrl::MyTreeCtrl(wxWindow *parent, const wxWindowID id,
|
||||
m_imageListNormal = new wxImageList(16, 16, TRUE);
|
||||
|
||||
// should correspond to TreeCtrlIcon_xxx enum
|
||||
m_imageListNormal->Add(wxICON(icon2));
|
||||
m_imageListNormal->Add(wxICON(icon1));
|
||||
m_imageListNormal->Add(wxICON(icon2));
|
||||
|
||||
SetImageList(m_imageListNormal);
|
||||
|
||||
@@ -332,6 +332,7 @@ static inline const char *Bool2String(bool b)
|
||||
|
||||
void MyTreeItemData::ShowInfo(wxTreeCtrl *tree)
|
||||
{
|
||||
/*
|
||||
wxLogMessage("Item '%s': %sselected, %sexpanded, %sbold,\n"
|
||||
"%u children (%u immediately under this item).",
|
||||
m_desc.c_str(),
|
||||
@@ -340,4 +341,5 @@ void MyTreeItemData::ShowInfo(wxTreeCtrl *tree)
|
||||
Bool2String(tree->IsBold(GetId())),
|
||||
tree->GetChildrenCount(GetId()),
|
||||
tree->GetChildrenCount(GetId(), FALSE));
|
||||
*/
|
||||
}
|
||||
|
@@ -347,10 +347,10 @@ void wxListLineData::SetPosition( wxPaintDC *dc, int x, int y, int window_width
|
||||
if (!item->HasText())
|
||||
{
|
||||
AssignRect( m_bound_hilight, m_bound_icon );
|
||||
m_bound_hilight.x -= 3;
|
||||
m_bound_hilight.y -= 3;
|
||||
m_bound_hilight.width += 7;
|
||||
m_bound_hilight.height += 7;
|
||||
m_bound_hilight.x -= 5;
|
||||
m_bound_hilight.y -= 5;
|
||||
m_bound_hilight.width += 9;
|
||||
m_bound_hilight.height += 9;
|
||||
}
|
||||
}
|
||||
if (item->HasText())
|
||||
@@ -367,6 +367,10 @@ void wxListLineData::SetPosition( wxPaintDC *dc, int x, int y, int window_width
|
||||
m_bound_label.width = lw;
|
||||
m_bound_label.height = lh;
|
||||
AssignRect( m_bound_hilight, m_bound_label );
|
||||
m_bound_hilight.x -= 2;
|
||||
m_bound_hilight.y -= 2;
|
||||
m_bound_hilight.width += 4;
|
||||
m_bound_hilight.height += 4;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -374,6 +378,10 @@ void wxListLineData::SetPosition( wxPaintDC *dc, int x, int y, int window_width
|
||||
case wxLC_LIST:
|
||||
{
|
||||
AssignRect( m_bound_label, m_bound_all );
|
||||
m_bound_all.x -= 2;
|
||||
m_bound_all.y -= 2;
|
||||
m_bound_all.width += 4;
|
||||
m_bound_all.height += 4;
|
||||
AssignRect( m_bound_hilight, m_bound_all );
|
||||
AssignRect( m_bound_icon, 0, 0, 0, 0 );
|
||||
break;
|
||||
@@ -382,13 +390,13 @@ void wxListLineData::SetPosition( wxPaintDC *dc, int x, int y, int window_width
|
||||
{
|
||||
long lw,lh;
|
||||
dc->GetTextExtent( "H", &lw, &lh );
|
||||
m_bound_all.height = lh;
|
||||
m_bound_all.x = 0;
|
||||
m_bound_all.y -= 0;
|
||||
m_bound_all.height = lh+3;
|
||||
m_bound_all.width = window_width;
|
||||
AssignRect( m_bound_label, m_bound_all );
|
||||
AssignRect( m_bound_hilight, m_bound_all );
|
||||
AssignRect( m_bound_label, 0, 0, 0 ,0 );
|
||||
AssignRect( m_bound_icon, 0, 0, 0, 0 );
|
||||
m_bound_hilight.width = window_width-10;
|
||||
m_bound_label.width = window_width-10;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -401,7 +409,7 @@ void wxListLineData::SetColumnPosition( int index, int x )
|
||||
if (node)
|
||||
{
|
||||
wxListItemData *item = (wxListItemData*)node->Data();
|
||||
item->SetPosition( x, m_bound_all.y );
|
||||
item->SetPosition( x, m_bound_all.y+1 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -528,8 +536,8 @@ void wxListLineData::DoDraw( wxPaintDC *dc, bool hilight, bool paintBG )
|
||||
dc->SetBrush( wxWHITE_BRUSH );
|
||||
dc->SetPen( wxTRANSPARENT_PEN );
|
||||
}
|
||||
dc->DrawRectangle( m_bound_hilight.x-2, m_bound_hilight.y-2,
|
||||
m_bound_hilight.width+4, m_bound_hilight.height+4 );
|
||||
dc->DrawRectangle( m_bound_hilight.x, m_bound_hilight.y,
|
||||
m_bound_hilight.width, m_bound_hilight.height );
|
||||
}
|
||||
if (m_mode == wxLC_REPORT)
|
||||
{
|
||||
@@ -609,8 +617,8 @@ void wxListLineData::DrawRubberBand( wxPaintDC *dc, bool on )
|
||||
{
|
||||
dc->SetPen( wxBLACK_PEN );
|
||||
dc->SetBrush( wxTRANSPARENT_BRUSH );
|
||||
dc->DrawRectangle( m_bound_hilight.x-2, m_bound_hilight.y-2,
|
||||
m_bound_hilight.width+4, m_bound_hilight.height+4 );
|
||||
dc->DrawRectangle( m_bound_hilight.x, m_bound_hilight.y,
|
||||
m_bound_hilight.width, m_bound_hilight.height );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -769,7 +777,6 @@ void wxListHeaderWindow::OnMouse( wxMouseEvent &event )
|
||||
DrawCurrent();
|
||||
if (event.ButtonUp())
|
||||
{
|
||||
// wxScreenDC::EndDrawingOnTop();
|
||||
ReleaseMouse();
|
||||
m_isDraging = FALSE;
|
||||
m_owner->SetColumnWidth( m_column, m_currentX-m_minX );
|
||||
@@ -807,7 +814,6 @@ void wxListHeaderWindow::OnMouse( wxMouseEvent &event )
|
||||
{
|
||||
m_isDraging = TRUE;
|
||||
m_currentX = x;
|
||||
// wxScreenDC::StartDrawingOnTop( m_owner );
|
||||
DrawCurrent();
|
||||
CaptureMouse();
|
||||
return;
|
||||
@@ -1868,12 +1874,12 @@ void wxListMainWindow::CalculatePositions( void )
|
||||
wxListLineData *line = (wxListLineData*)node->Data();
|
||||
int dummy = 0;
|
||||
line->GetSize( dummy, lineSpacing );
|
||||
lineSpacing += 6;
|
||||
lineSpacing += 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
// just in case
|
||||
lineSpacing = 6 + (int)dc.GetCharHeight();
|
||||
lineSpacing = 4 + (int)dc.GetCharHeight();
|
||||
}
|
||||
|
||||
int clientWidth = 0;
|
||||
@@ -1881,17 +1887,18 @@ void wxListMainWindow::CalculatePositions( void )
|
||||
|
||||
if (m_mode & wxLC_REPORT)
|
||||
{
|
||||
int x = 5;
|
||||
int y = 6;
|
||||
int x = 4;
|
||||
int y = 3;
|
||||
int entireHeight = m_lines.Number() * lineSpacing + 10;
|
||||
SetScrollbars( m_xScroll, m_yScroll, 0, (entireHeight+10) / m_yScroll, 0, 0, TRUE );
|
||||
GetClientSize( &clientWidth, &clientHeight );
|
||||
|
||||
node = m_lines.First();
|
||||
while (node)
|
||||
{
|
||||
wxListLineData *line = (wxListLineData*)node->Data();
|
||||
line->SetPosition( &dc, x, y, clientWidth );
|
||||
int col_x = 3;
|
||||
int col_x = 2;
|
||||
for (int i = 0; i < GetColumnCount(); i++)
|
||||
{
|
||||
line->SetColumnPosition( i, col_x );
|
||||
@@ -2107,11 +2114,15 @@ void wxListMainWindow::InsertItem( wxListItem &item )
|
||||
else
|
||||
line->InitItems( 1 );
|
||||
line->SetItem( 0, item );
|
||||
wxNode *node = m_lines.Nth( item.m_itemId );
|
||||
if (node)
|
||||
m_lines.Insert( node, line );
|
||||
if ((item.m_itemId >= 0) && (item.m_itemId < (int)m_lines.GetCount()))
|
||||
{
|
||||
wxNode *node = m_lines.Nth( item.m_itemId );
|
||||
if (node) m_lines.Insert( node, line );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_lines.Append( line );
|
||||
}
|
||||
}
|
||||
|
||||
void wxListMainWindow::InsertColumn( long col, wxListItem &item )
|
||||
@@ -2121,11 +2132,16 @@ void wxListMainWindow::InsertColumn( long col, wxListItem &item )
|
||||
{
|
||||
if (item.m_width == wxLIST_AUTOSIZE_USEHEADER) item.m_width = GetTextLength( item.m_text );
|
||||
wxListHeaderData *column = new wxListHeaderData( item );
|
||||
wxNode *node = m_columns.Nth( col );
|
||||
if (node)
|
||||
m_columns.Insert( node, column );
|
||||
if ((col >= 0) && (col < (int)m_columns.GetCount()))
|
||||
{
|
||||
wxNode *node = m_columns.Nth( col );
|
||||
if (node)
|
||||
m_columns.Insert( node, column );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_columns.Append( column );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -231,7 +231,6 @@ void wxGenericTreeItem::SetCross( int x, int y )
|
||||
|
||||
void wxGenericTreeItem::GetSize( int &x, int &y )
|
||||
{
|
||||
// FIXME what does this all mean??
|
||||
if ( y < m_y ) y = m_y;
|
||||
int width = m_x + m_width;
|
||||
if (width > x) x = width;
|
||||
@@ -295,6 +294,7 @@ BEGIN_EVENT_TABLE(wxTreeCtrl,wxScrolledWindow)
|
||||
EVT_CHAR (wxTreeCtrl::OnChar)
|
||||
EVT_SET_FOCUS (wxTreeCtrl::OnSetFocus)
|
||||
EVT_KILL_FOCUS (wxTreeCtrl::OnKillFocus)
|
||||
EVT_IDLE (wxTreeCtrl::OnIdle)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -305,6 +305,7 @@ void wxTreeCtrl::Init()
|
||||
m_current =
|
||||
m_anchor = (wxGenericTreeItem *) NULL;
|
||||
m_hasFocus = FALSE;
|
||||
m_dirty = FALSE;
|
||||
|
||||
m_xScroll = 0;
|
||||
m_yScroll = 0;
|
||||
@@ -591,33 +592,8 @@ wxTreeItemId wxTreeCtrl::DoInsertItem(const wxTreeItemId& parentId,
|
||||
}
|
||||
|
||||
parent->Insert( item, previous );
|
||||
|
||||
CalculatePositions();
|
||||
|
||||
int cw, ch;
|
||||
GetClientSize( &cw, &ch );
|
||||
|
||||
PrepareDC( dc );
|
||||
|
||||
wxRectangle rect;
|
||||
rect.x = dc.LogicalToDeviceX( 0 );
|
||||
rect.y = 0;
|
||||
rect.width = 10000; // @@@ not very elegant...
|
||||
rect.height = ch;
|
||||
|
||||
if ( previous != 0 )
|
||||
{
|
||||
rect.y = dc.LogicalToDeviceY( parent->GetChildren().Item(previous)->GetY() );
|
||||
}
|
||||
else // it's the 1st child
|
||||
{
|
||||
rect.y = dc.LogicalToDeviceY( parent->GetY() );
|
||||
}
|
||||
|
||||
AdjustMyScrollbars();
|
||||
|
||||
if ( rect.height > 0 )
|
||||
Refresh( FALSE, &rect );
|
||||
|
||||
m_dirty = TRUE;
|
||||
|
||||
return item;
|
||||
}
|
||||
@@ -857,10 +833,6 @@ void wxTreeCtrl::SortChildren( const wxTreeItemId& WXUNUSED(item),
|
||||
wxFAIL_MSG("not implemented");
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// images are not currently supported, but we still provide stubs for these
|
||||
// functions
|
||||
// -----------------------------------------------------------------------------
|
||||
wxImageList *wxTreeCtrl::GetImageList() const
|
||||
{
|
||||
return m_imageListNormal;
|
||||
@@ -1027,7 +999,7 @@ void wxTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level, int &
|
||||
// wxWindows callbacks
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void wxTreeCtrl::OnPaint( const wxPaintEvent &WXUNUSED(event) )
|
||||
void wxTreeCtrl::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
||||
{
|
||||
if ( !m_anchor )
|
||||
return;
|
||||
@@ -1044,14 +1016,14 @@ void wxTreeCtrl::OnPaint( const wxPaintEvent &WXUNUSED(event) )
|
||||
PaintLevel( m_anchor, dc, 0, y );
|
||||
}
|
||||
|
||||
void wxTreeCtrl::OnSetFocus( const wxFocusEvent &WXUNUSED(event) )
|
||||
void wxTreeCtrl::OnSetFocus( wxFocusEvent &WXUNUSED(event) )
|
||||
{
|
||||
m_hasFocus = TRUE;
|
||||
if ( m_current )
|
||||
RefreshLine( m_current );
|
||||
}
|
||||
|
||||
void wxTreeCtrl::OnKillFocus( const wxFocusEvent &WXUNUSED(event) )
|
||||
void wxTreeCtrl::OnKillFocus( wxFocusEvent &WXUNUSED(event) )
|
||||
{
|
||||
m_hasFocus = FALSE;
|
||||
if ( m_current )
|
||||
@@ -1064,7 +1036,7 @@ void wxTreeCtrl::OnChar( wxKeyEvent &event )
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
void wxTreeCtrl::OnMouse( const wxMouseEvent &event )
|
||||
void wxTreeCtrl::OnMouse( wxMouseEvent &event )
|
||||
{
|
||||
if ( !(event.LeftDown() || event.LeftDClick()) )
|
||||
return;
|
||||
@@ -1099,6 +1071,17 @@ void wxTreeCtrl::OnMouse( const wxMouseEvent &event )
|
||||
}
|
||||
}
|
||||
|
||||
void wxTreeCtrl::OnIdle( wxIdleEvent &WXUNUSED(event) )
|
||||
{
|
||||
if (!m_dirty) return;
|
||||
|
||||
m_dirty = FALSE;
|
||||
|
||||
CalculatePositions();
|
||||
|
||||
AdjustMyScrollbars();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------
|
||||
void wxTreeCtrl::CalculateLevel( wxGenericTreeItem *item,
|
||||
|
@@ -1478,13 +1478,13 @@ void wxWindow::SetClientSize( int width, int height )
|
||||
dh += 2 * viewport_class->ythickness;
|
||||
}
|
||||
|
||||
if (GTK_WIDGET_VISIBLE(vscrollbar))
|
||||
if (scroll_window->vscrollbar_visible)
|
||||
{
|
||||
dw += vscrollbar->allocation.width;
|
||||
dw += scroll_class->scrollbar_spacing;
|
||||
}
|
||||
|
||||
if (GTK_WIDGET_VISIBLE(hscrollbar))
|
||||
if (scroll_window->hscrollbar_visible)
|
||||
{
|
||||
dh += hscrollbar->allocation.height;
|
||||
dw += scroll_class->scrollbar_spacing;
|
||||
@@ -1543,14 +1543,14 @@ void wxWindow::GetClientSize( int *width, int *height ) const
|
||||
dh += 2 * viewport_class->ythickness;
|
||||
}
|
||||
|
||||
if (GTK_WIDGET_VISIBLE(vscrollbar))
|
||||
if (scroll_window->vscrollbar_visible)
|
||||
{
|
||||
// dw += vscrollbar->allocation.width;
|
||||
dw += 15; // range.slider_width = 11 + 2*2pts edge
|
||||
dw += scroll_class->scrollbar_spacing;
|
||||
}
|
||||
|
||||
if (GTK_WIDGET_VISIBLE(hscrollbar))
|
||||
if (scroll_window->hscrollbar_visible)
|
||||
{
|
||||
// dh += hscrollbar->allocation.height;
|
||||
dh += 15;
|
||||
|
@@ -1478,13 +1478,13 @@ void wxWindow::SetClientSize( int width, int height )
|
||||
dh += 2 * viewport_class->ythickness;
|
||||
}
|
||||
|
||||
if (GTK_WIDGET_VISIBLE(vscrollbar))
|
||||
if (scroll_window->vscrollbar_visible)
|
||||
{
|
||||
dw += vscrollbar->allocation.width;
|
||||
dw += scroll_class->scrollbar_spacing;
|
||||
}
|
||||
|
||||
if (GTK_WIDGET_VISIBLE(hscrollbar))
|
||||
if (scroll_window->hscrollbar_visible)
|
||||
{
|
||||
dh += hscrollbar->allocation.height;
|
||||
dw += scroll_class->scrollbar_spacing;
|
||||
@@ -1543,14 +1543,14 @@ void wxWindow::GetClientSize( int *width, int *height ) const
|
||||
dh += 2 * viewport_class->ythickness;
|
||||
}
|
||||
|
||||
if (GTK_WIDGET_VISIBLE(vscrollbar))
|
||||
if (scroll_window->vscrollbar_visible)
|
||||
{
|
||||
// dw += vscrollbar->allocation.width;
|
||||
dw += 15; // range.slider_width = 11 + 2*2pts edge
|
||||
dw += scroll_class->scrollbar_spacing;
|
||||
}
|
||||
|
||||
if (GTK_WIDGET_VISIBLE(hscrollbar))
|
||||
if (scroll_window->hscrollbar_visible)
|
||||
{
|
||||
// dh += hscrollbar->allocation.height;
|
||||
dh += 15;
|
||||
|
Reference in New Issue
Block a user