Speedup for wxTreeCtrl::Insert()
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1094
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
void SortChildren(const wxTreeItemId& item,
wxTreeItemCmpFunc *cmpFunction = NULL);
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 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;
protected:
wxGenericTreeItem *m_anchor;
wxGenericTreeItem *m_current;
bool m_hasFocus;
int m_xScroll,m_yScroll;
unsigned int m_indent;
int m_lineHeight;
int m_xScroll,m_yScroll;
unsigned int m_indent;
int m_lineHeight;
void MyFrame::DoSetBold(bool bold)
{
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))
}
void MyFrame::OnDelete(wxCommandEvent& WXUNUSED(event))
m_imageListNormal = new wxImageList(16, 16, TRUE);
// should correspond to TreeCtrlIcon_xxx enum
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(icon1));
+ m_imageListNormal->Add(wxICON(icon2));
SetImageList(m_imageListNormal);
SetImageList(m_imageListNormal);
void MyTreeItemData::ShowInfo(wxTreeCtrl *tree)
{
void MyTreeItemData::ShowInfo(wxTreeCtrl *tree)
{
wxLogMessage("Item '%s': %sselected, %sexpanded, %sbold,\n"
"%u children (%u immediately under this item).",
m_desc.c_str(),
wxLogMessage("Item '%s': %sselected, %sexpanded, %sbold,\n"
"%u children (%u immediately under this item).",
m_desc.c_str(),
Bool2String(tree->IsBold(GetId())),
tree->GetChildrenCount(GetId()),
tree->GetChildrenCount(GetId(), FALSE));
Bool2String(tree->IsBold(GetId())),
tree->GetChildrenCount(GetId()),
tree->GetChildrenCount(GetId(), FALSE));
if (!item->HasText())
{
AssignRect( m_bound_hilight, m_bound_icon );
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;
m_bound_label.width = lw;
m_bound_label.height = lh;
AssignRect( m_bound_hilight, m_bound_label );
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;
case wxLC_LIST:
{
AssignRect( m_bound_label, m_bound_all );
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;
AssignRect( m_bound_hilight, m_bound_all );
AssignRect( m_bound_icon, 0, 0, 0, 0 );
break;
{
long lw,lh;
dc->GetTextExtent( "H", &lw, &lh );
{
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;
m_bound_all.width = window_width;
- AssignRect( m_bound_label, m_bound_all );
AssignRect( m_bound_hilight, 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 );
AssignRect( m_bound_icon, 0, 0, 0, 0 );
- m_bound_hilight.width = window_width-10;
- m_bound_label.width = window_width-10;
if (node)
{
wxListItemData *item = (wxListItemData*)node->Data();
if (node)
{
wxListItemData *item = (wxListItemData*)node->Data();
- item->SetPosition( x, m_bound_all.y );
+ item->SetPosition( x, m_bound_all.y+1 );
dc->SetBrush( wxWHITE_BRUSH );
dc->SetPen( wxTRANSPARENT_PEN );
}
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)
{
}
if (m_mode == wxLC_REPORT)
{
{
dc->SetPen( wxBLACK_PEN );
dc->SetBrush( wxTRANSPARENT_BRUSH );
{
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 );
DrawCurrent();
if (event.ButtonUp())
{
DrawCurrent();
if (event.ButtonUp())
{
-// wxScreenDC::EndDrawingOnTop();
ReleaseMouse();
m_isDraging = FALSE;
m_owner->SetColumnWidth( m_column, m_currentX-m_minX );
ReleaseMouse();
m_isDraging = FALSE;
m_owner->SetColumnWidth( m_column, m_currentX-m_minX );
{
m_isDraging = TRUE;
m_currentX = x;
{
m_isDraging = TRUE;
m_currentX = x;
-// wxScreenDC::StartDrawingOnTop( m_owner );
DrawCurrent();
CaptureMouse();
return;
DrawCurrent();
CaptureMouse();
return;
wxListLineData *line = (wxListLineData*)node->Data();
int dummy = 0;
line->GetSize( dummy, lineSpacing );
wxListLineData *line = (wxListLineData*)node->Data();
int dummy = 0;
line->GetSize( dummy, lineSpacing );
- lineSpacing = 6 + (int)dc.GetCharHeight();
+ lineSpacing = 4 + (int)dc.GetCharHeight();
if (m_mode & wxLC_REPORT)
{
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 );
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 );
node = m_lines.First();
while (node)
{
wxListLineData *line = (wxListLineData*)node->Data();
line->SetPosition( &dc, x, y, clientWidth );
for (int i = 0; i < GetColumnCount(); i++)
{
line->SetColumnPosition( i, col_x );
for (int i = 0; i < GetColumnCount(); i++)
{
line->SetColumnPosition( i, col_x );
else
line->InitItems( 1 );
line->SetItem( 0, 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 );
+ }
}
void wxListMainWindow::InsertColumn( long col, wxListItem &item )
}
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 );
{
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 );
+ }
m_columns.Append( column );
m_columns.Append( column );
void wxGenericTreeItem::GetSize( 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;
if ( y < m_y ) y = m_y;
int width = m_x + m_width;
if (width > x) x = width;
EVT_CHAR (wxTreeCtrl::OnChar)
EVT_SET_FOCUS (wxTreeCtrl::OnSetFocus)
EVT_KILL_FOCUS (wxTreeCtrl::OnKillFocus)
EVT_CHAR (wxTreeCtrl::OnChar)
EVT_SET_FOCUS (wxTreeCtrl::OnSetFocus)
EVT_KILL_FOCUS (wxTreeCtrl::OnKillFocus)
+ EVT_IDLE (wxTreeCtrl::OnIdle)
END_EVENT_TABLE()
// -----------------------------------------------------------------------------
END_EVENT_TABLE()
// -----------------------------------------------------------------------------
m_current =
m_anchor = (wxGenericTreeItem *) NULL;
m_hasFocus = FALSE;
m_current =
m_anchor = (wxGenericTreeItem *) NULL;
m_hasFocus = FALSE;
m_xScroll = 0;
m_yScroll = 0;
m_xScroll = 0;
m_yScroll = 0;
}
parent->Insert( item, previous );
}
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 );
wxFAIL_MSG("not implemented");
}
wxFAIL_MSG("not implemented");
}
-// -----------------------------------------------------------------------------
-// images are not currently supported, but we still provide stubs for these
-// functions
-// -----------------------------------------------------------------------------
wxImageList *wxTreeCtrl::GetImageList() const
{
return m_imageListNormal;
wxImageList *wxTreeCtrl::GetImageList() const
{
return m_imageListNormal;
// wxWindows callbacks
// -----------------------------------------------------------------------------
// wxWindows callbacks
// -----------------------------------------------------------------------------
-void wxTreeCtrl::OnPaint( const wxPaintEvent &WXUNUSED(event) )
+void wxTreeCtrl::OnPaint( wxPaintEvent &WXUNUSED(event) )
{
if ( !m_anchor )
return;
{
if ( !m_anchor )
return;
PaintLevel( m_anchor, dc, 0, y );
}
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 );
}
{
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 )
{
m_hasFocus = FALSE;
if ( m_current )
-void wxTreeCtrl::OnMouse( const wxMouseEvent &event )
+void wxTreeCtrl::OnMouse( wxMouseEvent &event )
{
if ( !(event.LeftDown() || event.LeftDClick()) )
return;
{
if ( !(event.LeftDown() || event.LeftDClick()) )
return;
+void wxTreeCtrl::OnIdle( wxIdleEvent &WXUNUSED(event) )
+{
+ if (!m_dirty) return;
+
+ m_dirty = FALSE;
+
+ CalculatePositions();
+
+ AdjustMyScrollbars();
+}
+
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void wxTreeCtrl::CalculateLevel( wxGenericTreeItem *item,
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void wxTreeCtrl::CalculateLevel( wxGenericTreeItem *item,
dh += 2 * viewport_class->ythickness;
}
dh += 2 * viewport_class->ythickness;
}
- if (GTK_WIDGET_VISIBLE(vscrollbar))
+ if (scroll_window->vscrollbar_visible)
{
dw += vscrollbar->allocation.width;
dw += scroll_class->scrollbar_spacing;
}
{
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;
{
dh += hscrollbar->allocation.height;
dw += scroll_class->scrollbar_spacing;
dh += 2 * viewport_class->ythickness;
}
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;
}
{
// 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;
{
// dh += hscrollbar->allocation.height;
dh += 15;
dh += 2 * viewport_class->ythickness;
}
dh += 2 * viewport_class->ythickness;
}
- if (GTK_WIDGET_VISIBLE(vscrollbar))
+ if (scroll_window->vscrollbar_visible)
{
dw += vscrollbar->allocation.width;
dw += scroll_class->scrollbar_spacing;
}
{
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;
{
dh += hscrollbar->allocation.height;
dw += scroll_class->scrollbar_spacing;
dh += 2 * viewport_class->ythickness;
}
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;
}
{
// 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;
{
// dh += hscrollbar->allocation.height;
dh += 15;