... we have it ourselves ...
else
line->GetFoo();
+
+ => done
+
+ 5. attributes support: we need OnGetItemAttr() as well!
*/
// ============================================================================
void GetItem( wxListItem &info ) const;
- wxListItemAttr *GetAttributes() const { return m_attr; }
+ void SetAttr(wxListItemAttr *attr) { m_attr = attr; }
+ wxListItemAttr *GetAttr() const { return m_attr; }
public:
// the item image or -1
wxListMainWindow *m_owner;
public:
- wxListLineData( wxListMainWindow *owner, size_t line );
+ wxListLineData(wxListMainWindow *owner);
~wxListLineData() { delete m_gi; }
// remember the position this line appears at
void SetPosition( int x, int y, int window_width, int spacing );
- long IsHit( int x, int y );
+ // wxListCtrl API
+
+ void SetImage( int image ) { SetImage(0, image); }
+ int GetImage() const { return GetImage(0); }
+ bool HasImage() const { return GetImage() != -1; }
+ bool HasText() const { return !GetText(0).empty(); }
void SetItem( int index, const wxListItem &info );
void GetItem( int index, wxListItem &info );
wxString GetText(int index) const;
void SetText( int index, const wxString s );
- void SetImage( int index, int image );
- int GetImage( int index ) const;
-
- // get the bound rect of this line
- wxRect GetRect() const;
-
- // get the bound rect of the label
- wxRect GetLabelRect() const;
-
- // get the bound rect of the items icon (only may be called if we do have
- // an icon!)
- wxRect GetIconRect() const;
-
- // get the rect to be highlighted when the item has focus
- wxRect GetHighlightRect() const;
-
- // get the size of the total line rect
- wxSize GetSize() const { return GetRect().GetSize(); }
+ wxListItemAttr *GetAttr() const;
+ void SetAttr(wxListItemAttr *attr);
// return true if the highlighting really changed
bool Highlight( bool on );
void ReverseHighlight();
- // draw the line on the given DC
- void Draw( wxDC *dc, int y = 0, int height = 0, bool highlighted = FALSE );
-
bool IsHighlighted() const
{
wxASSERT_MSG( !IsVirtual(), _T("unexpected call to IsHighlighted") );
return m_highlighted;
}
- // only for wxListMainWindow::CacheLineData()
- void SetLineIndex(size_t line) { m_lineIndex = line; }
+ // draw the line on the given DC in icon/list mode
+ void Draw( wxDC *dc );
+
+ // the same in report mode
+ void DrawInReportMode( wxDC *dc,
+ const wxRect& rect,
+ const wxRect& rectHL,
+ bool highlighted );
private:
// set the line to contain num items (only can be > 1 in report mode)
const wxFont& font,
bool highlight);
- // the index of this line (only used in report mode)
- size_t m_lineIndex;
+ // these are only used by GetImage/SetImage above, we don't support images
+ // with subitems at the public API level yet
+ void SetImage( int index, int image );
+ int GetImage( int index ) const;
};
-
WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData, wxListLineDataArray);
#include "wx/arrimpl.cpp"
WX_DEFINE_OBJARRAY(wxListLineDataArray);
// return true if this is a virtual list control
bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL); }
+ // return true if the control is in report mode
+ bool InReportView() const { return HasFlag(wxLC_REPORT); }
+
// return true if we are in single selection mode, false if multi sel
bool IsSingleSel() const { return HasFlag(wxLC_SINGLE_SEL); }
void ReverseHighlight( size_t line )
{ HighlightLine(line, !IsHighlighted(line)); RefreshLine(line); }
+ // return true if the line is highlighted
+ bool IsHighlighted(size_t line) const;
+
// refresh one or several lines at once
void RefreshLine( size_t line );
void RefreshLines( size_t lineFrom, size_t lineTo );
- // return true if the line is highlighted
- bool IsHighlighted(size_t line) const;
+ // refresh all lines below the given one: the difference with
+ // RefreshLines() is that the index here might not be a valid one (happens
+ // when the last line is deleted)
+ void RefreshAfter( size_t lineFrom );
+
+ // the methods which are forwarded to wxListLineData itself in list/icon
+ // modes but are here because the lines don't store their positions in the
+ // report mode
+
+ // get the bound rect for the entire line
+ wxRect GetLineRect(size_t line) const;
+
+ // get the bound rect of the label
+ wxRect GetLineLabelRect(size_t line) const;
+
+ // get the bound rect of the items icon (only may be called if we do have
+ // an icon!)
+ wxRect GetLineIconRect(size_t line) const;
+
+ // get the rect to be highlighted when the item has focus
+ wxRect GetLineHighlightRect(size_t line) const;
+
+ // get the size of the total line rect
+ wxSize GetLineSize(size_t line) const
+ { return GetLineRect(line).GetSize(); }
+
+ // return the hit code for the corresponding position (in this line)
+ long HitTestLine(size_t line, int x, int y) const;
void EditLabel( long item );
void OnRenameTimer();
void OnPaint( wxPaintEvent &event );
void DrawImage( int index, wxDC *dc, int x, int y );
- void GetImageSize( int index, int &width, int &height );
- int GetTextLength( const wxString &s );
+ void GetImageSize( int index, int &width, int &height ) const;
+ int GetTextLength( const wxString &s ) const;
void SetImageList( wxImageList *imageList, int which );
void SetItemSpacing( int spacing, bool isSmall = FALSE );
// returns the sum of the heights of all columns
int GetHeaderWidth() const;
- int GetCountPerPage() { return m_linesPerPage; }
+ int GetCountPerPage() const;
void SetItem( wxListItem &item );
void GetItem( wxListItem &item );
{
// this item itself was in m_itemsSel, remove it from there
m_itemsSel.RemoveAt(i);
+
+ count--;
}
// and adjust the index of all which follow it
return m_owner->IsVirtual();
}
-wxListLineData::wxListLineData( wxListMainWindow *owner, size_t line )
+wxListLineData::wxListLineData( wxListMainWindow *owner )
{
m_owner = owner;
m_items.DeleteContents( TRUE );
- SetLineIndex(line);
-
if ( InReportView() )
{
m_gi = NULL;
InitItems( GetMode() == wxLC_REPORT ? m_owner->GetColumnCount() : 1 );
}
-wxRect wxListLineData::GetRect() const
-{
- if ( !InReportView() )
- return m_gi->m_rectAll;
-
- wxRect rect;
- rect.x = HEADER_OFFSET_X;
- rect.y = m_owner->GetLineY(m_lineIndex);
- rect.width = m_owner->GetHeaderWidth();
- rect.height = m_owner->GetLineHeight();
-
- return rect;
-}
-
-wxRect wxListLineData::GetLabelRect() const
-{
- if ( !InReportView() )
- return m_gi->m_rectLabel;
-
- wxRect rect;
- rect.x = HEADER_OFFSET_X;
- rect.y = m_owner->GetLineY(m_lineIndex);
- rect.width = m_owner->GetColumnWidth(0);
- rect.height = m_owner->GetLineHeight();
-
- return rect;
-}
-
-wxRect wxListLineData::GetIconRect() const
-{
- if ( !InReportView() )
- return m_gi->m_rectIcon;
-
- wxRect rect;
-
- wxListItemDataList::Node *node = m_items.GetFirst();
- wxCHECK_MSG( node, rect, _T("no subitems at all??") );
-
- wxListItemData *item = node->GetData();
- wxASSERT_MSG( item->HasImage(), _T("GetIconRect() called but no image") );
-
- rect.x = HEADER_OFFSET_X;
- rect.y = m_owner->GetLineY(m_lineIndex);
- m_owner->GetImageSize(item->GetImage(), rect.width, rect.height);
-
- return rect;
-}
-
-wxRect wxListLineData::GetHighlightRect() const
-{
- return InReportView() ? GetRect() : m_gi->m_rectHighlight;
-}
-
void wxListLineData::CalculateSize( wxDC *dc, int spacing )
{
wxListItemDataList::Node *node = m_items.GetFirst();
}
}
-long wxListLineData::IsHit( int x, int y )
-{
- wxListItemDataList::Node *node = m_items.GetFirst();
- wxCHECK_MSG( node, 0, _T("no subitems at all??") );
-
- wxListItemData *item = node->GetData();
- if ( item->HasImage() && GetIconRect().Inside(x, y) )
- return wxLIST_HITTEST_ONITEMICON;
-
- if ( item->HasText() )
- {
- wxRect rect = InReportView() ? GetRect() : GetLabelRect();
- if ( rect.Inside(x, y) )
- return wxLIST_HITTEST_ONITEMLABEL;
- }
-
- return 0;
-}
-
void wxListLineData::InitItems( int num )
{
for (int i = 0; i < num; i++)
return item->GetImage();
}
+wxListItemAttr *wxListLineData::GetAttr() const
+{
+ wxListItemDataList::Node *node = m_items.GetFirst();
+ wxCHECK_MSG( node, NULL, _T("invalid column index in GetAttr()") );
+
+ wxListItemData *item = node->GetData();
+ return item->GetAttr();
+}
+
+void wxListLineData::SetAttr(wxListItemAttr *attr)
+{
+ wxListItemDataList::Node *node = m_items.GetFirst();
+ wxCHECK_RET( node, _T("invalid column index in SetAttr()") );
+
+ wxListItemData *item = node->GetData();
+ item->SetAttr(attr);
+}
+
void wxListLineData::SetAttributes(wxDC *dc,
const wxListItemAttr *attr,
const wxColour& colText,
}
}
-void wxListLineData::Draw( wxDC *dc, int y, int height, bool highlighted )
+void wxListLineData::Draw( wxDC *dc )
{
- wxRect rect = GetRect();
- m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
+ wxListItemDataList::Node *node = m_items.GetFirst();
+ wxCHECK_RET( node, _T("no subitems at all??") );
- if ( !m_owner->IsExposed( rect ) )
- return;
+ wxListItemData *item = node->GetData();
+ if (item->HasImage())
+ {
+ wxRect rectIcon = m_gi->m_rectIcon;
+ m_owner->DrawImage( item->GetImage(), dc,
+ rectIcon.x, rectIcon.y );
+ }
- wxWindow *listctrl = m_owner->GetParent();
+ if (item->HasText())
+ {
+ wxRect rectLabel = m_gi->m_rectLabel;
+ dc->DrawText( item->GetText(), rectLabel.x, rectLabel.y );
+ }
+}
+void wxListLineData::DrawInReportMode( wxDC *dc,
+ const wxRect& rect,
+ const wxRect& rectHL,
+ bool highlighted )
+{
// use our own flag if we maintain it
- if ( !m_owner->IsVirtual() )
+ if ( !IsVirtual() )
highlighted = m_highlighted;
// default foreground colour
+ wxWindow *listctrl = m_owner->GetParent();
wxColour colText;
if ( highlighted )
{
// default font
wxFont font = listctrl->GetFont();
- // VZ: currently we set the colours/fonts only once, but like this (i.e.
- // using SetAttributes() inside the loop), it will be trivial to
- // customize the subitems (in report mode) too.
- wxListItemData *item = m_items.GetFirst()->GetData();
- wxListItemAttr *attr = item->GetAttributes();
+ // TODO: later we should support setting different attributes for
+ // different columns - to do it, just add "col" argument to
+ // GetAttr() and move this code into the loop below
+ wxListItemAttr *attr = GetAttr();
SetAttributes(dc, attr, colText, font, highlighted);
bool hasBgCol = attr && attr->HasBackgroundColour();
}
dc->SetPen( * wxTRANSPARENT_PEN );
- dc->DrawRectangle( GetHighlightRect() );
+ dc->DrawRectangle( rectHL );
}
wxListItemDataList::Node *node = m_items.GetFirst();
+ wxCHECK_RET( node, _T("no subitems at all??") );
- if ( GetMode() == wxLC_REPORT)
+ size_t col = 0;
+ wxCoord x = rect.x + HEADER_OFFSET_X,
+ y = rect.y + (LINE_SPACING + EXTRA_HEIGHT) / 2;
+
+ while ( node )
{
- size_t col = 0;
- int x = HEADER_OFFSET_X;
+ wxListItemData *item = node->GetData();
- y += (LINE_SPACING + EXTRA_HEIGHT) / 2;
+ int xOld = x;
- while ( node )
+ if ( item->HasImage() )
{
- wxListItemData *item = node->GetData();
-
- int xOld = x;
-
- if ( item->HasImage() )
- {
- int ix, iy;
- m_owner->DrawImage( item->GetImage(), dc, x, y );
- m_owner->GetImageSize( item->GetImage(), ix, iy );
- x += ix + 5; // FIXME: what is "5"?
- }
-
- int width = m_owner->GetColumnWidth(col++);
-
- dc->SetClippingRegion(x, y, width, height);
-
- if ( item->HasText() )
- {
- dc->DrawText( item->GetText(), x, y + 1 );
- }
+ int ix, iy;
+ m_owner->DrawImage( item->GetImage(), dc, x, y );
+ m_owner->GetImageSize( item->GetImage(), ix, iy );
+ x += ix + 5; // FIXME: what is "5"?
+ }
- dc->DestroyClippingRegion();
+ int width = m_owner->GetColumnWidth(col++);
- x = xOld + width;
+ wxDCClipper clipper(*dc, x, y, width, rect.height);
- node = node->GetNext();
- }
- }
- else // !report
- {
- if (node)
+ if ( item->HasText() )
{
- wxListItemData *item = node->GetData();
- if (item->HasImage())
- {
- wxRect rectIcon = GetIconRect();
- m_owner->DrawImage( item->GetImage(), dc,
- rectIcon.x, rectIcon.y );
- }
-
- if (item->HasText())
- {
- wxRect rectLabel = GetLabelRect();
- dc->DrawText( item->GetText(), rectLabel.x, rectLabel.y );
- }
+ dc->DrawText( item->GetText(), x, y );
}
+
+ x = xOld + width;
+
+ node = node->GetNext();
}
}
ld->SetText(col, listctrl->OnGetItemText(line, col));
}
- ld->SetImage(0, listctrl->OnGetItemImage(line));
- ld->SetLineIndex(line);
+ ld->SetImage(listctrl->OnGetItemImage(line));
+ ld->SetAttr(listctrl->OnGetItemAttr(line));
}
wxListLineData *wxListMainWindow::GetDummyLine() const
wxASSERT_MSG( IsVirtual(), _T("logic error") );
wxListMainWindow *self = wxConstCast(this, wxListMainWindow);
- wxListLineData *line = new wxListLineData( self, 0 );
+ wxListLineData *line = new wxListLineData(self);
self->m_lines.Add(line);
}
- m_lines[0].SetLineIndex(0);
-
return &m_lines[0];
}
+// ----------------------------------------------------------------------------
+// line geometry (report mode only)
+// ----------------------------------------------------------------------------
+
wxCoord wxListMainWindow::GetLineHeight() const
{
wxASSERT_MSG( HasFlag(wxLC_REPORT), _T("only works in report mode") );
return LINE_SPACING + line*GetLineHeight();
}
+wxRect wxListMainWindow::GetLineRect(size_t line) const
+{
+ if ( !InReportView() )
+ return GetLine(line)->m_gi->m_rectAll;
+
+ wxRect rect;
+ rect.x = HEADER_OFFSET_X;
+ rect.y = GetLineY(line);
+ rect.width = GetHeaderWidth();
+ rect.height = GetLineHeight();
+
+ return rect;
+}
+
+wxRect wxListMainWindow::GetLineLabelRect(size_t line) const
+{
+ if ( !InReportView() )
+ return GetLine(line)->m_gi->m_rectLabel;
+
+ wxRect rect;
+ rect.x = HEADER_OFFSET_X;
+ rect.y = GetLineY(line);
+ rect.width = GetColumnWidth(0);
+ rect.height = GetLineHeight();
+
+ return rect;
+}
+
+wxRect wxListMainWindow::GetLineIconRect(size_t line) const
+{
+ if ( !InReportView() )
+ return GetLine(line)->m_gi->m_rectIcon;
+
+ wxListLineData *ld = GetLine(line);
+ wxASSERT_MSG( ld->HasImage(), _T("should have an image") );
+
+ wxRect rect;
+ rect.x = HEADER_OFFSET_X;
+ rect.y = GetLineY(line);
+ GetImageSize(ld->GetImage(), rect.width, rect.height);
+
+ return rect;
+}
+
+wxRect wxListMainWindow::GetLineHighlightRect(size_t line) const
+{
+ return InReportView() ? GetLineRect(line)
+ : GetLine(line)->m_gi->m_rectHighlight;
+}
+
+long wxListMainWindow::HitTestLine(size_t line, int x, int y) const
+{
+ wxListLineData *ld = GetLine(line);
+
+ if ( ld->HasImage() && GetLineIconRect(line).Inside(x, y) )
+ return wxLIST_HITTEST_ONITEMICON;
+
+ if ( ld->HasText() )
+ {
+ wxRect rect = InReportView() ? GetLineRect(line)
+ : GetLineLabelRect(line);
+
+ if ( rect.Inside(x, y) )
+ return wxLIST_HITTEST_ONITEMLABEL;
+ }
+
+ return 0;
+}
+
+// ----------------------------------------------------------------------------
+// highlight (selection) handling
+// ----------------------------------------------------------------------------
+
bool wxListMainWindow::IsHighlighted(size_t line) const
{
if ( IsVirtual() )
if ( changed )
{
SendNotify( line, highlight ? wxEVT_COMMAND_LIST_ITEM_SELECTED
- : wxEVT_COMMAND_LIST_ITEM_DESELECTED );
+ : wxEVT_COMMAND_LIST_ITEM_DESELECTED );
}
return changed;
void wxListMainWindow::RefreshLine( size_t line )
{
- wxRect rect = GetLine(line)->GetRect();
+ wxRect rect = GetLineRect(line);
CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
RefreshRect( rect );
// we suppose that they are ordered by caller
wxASSERT_MSG( lineFrom <= lineTo, _T("indices in disorder") );
+ wxASSERT_MSG( lineTo < GetItemCount(), _T("invalid line range") );
+
if ( HasFlag(wxLC_REPORT) )
{
size_t visibleFrom, visibleTo;
}
}
+void wxListMainWindow::RefreshAfter( size_t lineFrom )
+{
+ if ( HasFlag(wxLC_REPORT) )
+ {
+ size_t visibleFrom;
+ GetVisibleLinesRange(&visibleFrom, NULL);
+
+ if ( lineFrom < visibleFrom )
+ lineFrom = visibleFrom;
+
+ wxRect rect;
+ rect.x = 0;
+ rect.y = GetLineY(lineFrom);
+
+ wxSize size = GetClientSize();
+ rect.width = size.x;
+ // refresh till the bottom of the window
+ rect.height = size.y - rect.y;
+
+ CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
+ RefreshRect( rect );
+ }
+ else // !report
+ {
+ // TODO: how to do it more efficiently?
+ m_dirty = TRUE;
+ }
+}
+
void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
{
// Note: a wxPaintDC must be constructed even if no drawing is
return;
}
+ if ( m_dirty )
+ {
+ // delay the repainting until we calculate all the items positions
+ return;
+ }
+
PrepareDC( dc );
int dev_x, dev_y;
size_t visibleFrom, visibleTo;
GetVisibleLinesRange(&visibleFrom, &visibleTo);
+
+ wxRect rectLine;
+ wxCoord xOrig, yOrig;
+ CalcUnscrolledPosition(0, 0, &xOrig, &yOrig);
+
for ( size_t line = visibleFrom; line <= visibleTo; line++ )
{
- GetLine(line)->Draw( &dc,
- GetLineY(line),
- lineHeight,
- IsHighlighted(line) );
+ rectLine = GetLineRect(line);
+
+ if ( !IsExposed(rectLine.x - xOrig, rectLine.y - yOrig,
+ rectLine.width, rectLine.height) )
+ {
+ // don't redraw unaffected lines to avoid flicker
+ continue;
+ }
+
+ GetLine(line)->DrawInReportMode( &dc,
+ rectLine,
+ GetLineHighlightRect(line),
+ IsHighlighted(line) );
}
if ( HasFlag(wxLC_HRULES) )
if ( HasCurrent() && m_hasFocus )
{
- wxRect rect;
-
- if ( IsVirtual() )
- {
- // just offset the rect of the first line to position it correctly
- wxListLineData *line = GetDummyLine();
- rect = line->GetHighlightRect();
- rect.y = GetLineY(m_current);
- }
- else
- {
- rect = GetLine(m_current)->GetHighlightRect();
- }
#ifdef __WXMAC__
// no rect outline, we already have the background color
#else
dc.SetPen( *wxBLACK_PEN );
dc.SetBrush( *wxTRANSPARENT_BRUSH );
- dc.DrawRectangle( rect );
+ dc.DrawRectangle( GetLineHighlightRect(m_current) );
#endif
}
PrepareDC( dc );
wxString s = data->GetText(0);
- wxRect rectLabel = data->GetLabelRect();
+ wxRect rectLabel = GetLineLabelRect(m_currentEdit);
rectLabel.x = dc.LogicalToDeviceX( rectLabel.x );
rectLabel.y = dc.LogicalToDeviceY( rectLabel.y );
int y = event.GetY();
CalcUnscrolledPosition( x, y, &x, &y );
- /* Did we actually hit an item ? */
+ // where did we hit it (if we did)?
long hitResult = 0;
size_t count = GetItemCount(),
if ( HasFlag(wxLC_REPORT) )
{
- wxCoord lineHeight = GetLineHeight();
-
- current = y / lineHeight;
- hitResult = GetDummyLine()->IsHit( x, y % lineHeight );
+ current = y / GetLineHeight();
+ if ( current < count )
+ hitResult = HitTestLine(current, x, y);
}
else // !report
{
// enumerating all items is still not a way to do it!!
for ( current = 0; current < count; current++ )
{
- wxListLineData *line = (wxListLineData *) NULL;
- line = GetLine(current);
- hitResult = line->IsHit( x, y );
- if (hitResult)
+ hitResult = HitTestLine(current, x, y);
+ if ( hitResult )
break;
}
}
if ( !HasCurrent() )
return;
- wxRect rect;
-
- if ( IsVirtual() )
- {
- // just offset the rect of the first line to position it correctly
- wxListLineData *line = GetDummyLine();
- rect = line->GetRect();
- rect.y = GetLineY(m_current);
- }
- else
- {
- rect = GetLine(m_current)->GetRect();
- }
+ wxRect rect = GetLineRect(m_current);
int client_w, client_h;
GetClientSize( &client_w, &client_h );
}
}
-void wxListMainWindow::GetImageSize( int index, int &width, int &height )
+void wxListMainWindow::GetImageSize( int index, int &width, int &height ) const
{
if ( HasFlag(wxLC_ICON) && m_normal_image_list )
{
}
}
-int wxListMainWindow::GetTextLength( const wxString &s )
+int wxListMainWindow::GetTextLength( const wxString &s ) const
{
- wxClientDC dc( this );
+ wxClientDC dc( wxConstCast(this, wxListMainWindow) );
dc.SetFont( GetFont() );
wxCoord lw;
wxCHECK_RET( id >= 0 && (size_t)id < GetItemCount(),
_T("invalid item index in SetItem") );
- if ( IsVirtual() )
+ if ( !IsVirtual() )
+ {
+ wxListLineData *line = GetLine((size_t)id);
+ line->SetItem( item.m_col, item );
+ }
+
+ if ( InReportView() )
{
// just refresh the line to show the new value of the text/image
RefreshLine((size_t)id);
}
- else // !virtual
+ else // !report
{
+ // refresh everything (resulting in horrible flicker - FIXME!)
m_dirty = TRUE;
-
- wxListLineData *line = GetLine((size_t)id);
- if ( HasFlag(wxLC_REPORT) )
- item.m_width = GetColumnWidth( item.m_col );
- line->SetItem( item.m_col, item );
}
}
wxCHECK_RET( index >= 0 && (size_t)index < GetItemCount(),
_T("invalid index in GetItemRect") );
- if ( HasFlag(wxLC_REPORT) )
- {
- rect = GetDummyLine()->GetRect();
- rect.y = GetLineY((size_t)index);
- }
- else
- {
- rect = GetLine((size_t)index)->GetRect();
- }
+ rect = GetLineRect((size_t)index);
CalcScrolledPosition(rect.x, rect.y, &rect.x, &rect.y);
}
GetScrollPos(wxHORIZONTAL),
GetScrollPos(wxVERTICAL),
TRUE );
-
- // we must have an integer number of lines on screen and so we fit
- // the real control size to the line height
- wxRect rect;
- rect.x = 0;
- rect.y = LINE_SPACING;
- rect.width = clientWidth;
- rect.height = ((clientHeight - LINE_SPACING) / lineHeight)*lineHeight;
- SetTargetRect(rect);
}
else // !report
{
line->CalculateSize( &dc, iconSpacing );
line->SetPosition( x, y, clientWidth, iconSpacing );
- wxSize sizeLine = line->GetSize();
+ wxSize sizeLine = GetLineSize(i);
if ( maxWidth < sizeLine.x )
maxWidth = sizeLine.x;
if ( m_current == index )
{
// the last valid index after deleting the item will be count-2
- if ( ++m_current >= count - 2 )
+ if ( m_current == count - 1 )
{
- m_current = count - 2;
+ m_current--;
}
}
SendNotify( index, wxEVT_COMMAND_LIST_DELETE_ITEM );
+ if ( InReportView() )
+ {
+ ResetVisibleLinesRange();
+ }
+
if ( IsVirtual() )
{
- if ( m_lineTo == --m_countVirt )
- {
- m_lineTo--;
- }
+ m_countVirt--;
m_selStore.OnItemDelete(index);
}
{
m_lines.RemoveAt( index );
}
+
+ m_dirty = TRUE;
+ RefreshAfter(index);
}
void wxListMainWindow::DeleteColumn( int col )
ResetVisibleLinesRange();
}
+ if ( InReportView() )
+ {
+ ResetVisibleLinesRange();
+ }
+
m_lines.Clear();
m_selStore.Clear();
{
CalcUnscrolledPosition( x, y, &x, &y );
- size_t count = GetItemCount();
- for (size_t i = 0; i < count; i++)
+ if ( HasFlag(wxLC_REPORT) )
{
- wxListLineData *line = GetLine(i);
- long ret = line->IsHit( x, y );
- if (ret)
+ size_t current = y / GetLineHeight();
+ flags = HitTestLine(current, x, y);
+ if ( flags )
+ return current;
+ }
+ else // !report
+ {
+ // TODO: optimize it too! this is less simple than for report view but
+ // enumerating all items is still not a way to do it!!
+ size_t count = GetItemCount();
+ for ( size_t current = 0; current < count; current++ )
{
- flags = (int)ret;
- return i;
+ flags = HitTestLine(current, x, y);
+ if ( flags )
+ return current;
}
}
wxFAIL_MSG( _T("unknown mode") );
}
- wxListLineData *line = new wxListLineData( this, id );
+ wxListLineData *line = new wxListLineData(this);
line->SetItem( 0, item );
m_lines.Insert( line, id );
+
+ m_dirty = TRUE;
+ RefreshLines(id, GetItemCount() - 1);
}
void wxListMainWindow::InsertColumn( long col, wxListItem &item )
}
}
+int wxListMainWindow::GetCountPerPage() const
+{
+ if ( !m_linesPerPage )
+ {
+ wxConstCast(this, wxListMainWindow)->
+ m_linesPerPage = GetClientSize().y / GetLineHeight();
+ }
+
+ return m_linesPerPage;
+}
+
void wxListMainWindow::GetVisibleLinesRange(size_t *from, size_t *to)
{
wxASSERT_MSG( HasFlag(wxLC_REPORT), _T("this is for report mode only") );
if ( m_lineFrom == (size_t)-1 )
{
- m_lineFrom = GetScrollPos(wxVERTICAL);
-
size_t count = GetItemCount();
+ if ( count )
+ {
+ m_lineFrom = GetScrollPos(wxVERTICAL);
- wxASSERT_MSG( m_lineFrom < count, _T("invalid scroll position?") );
+ // this may happen if SetScrollbars() hadn't been called yet
+ if ( m_lineFrom >= count )
+ m_lineFrom = count - 1;
- m_lineTo = m_lineFrom + m_linesPerPage - 1;
- if ( m_lineTo >= count )
- m_lineTo = count - 1;
+ // we redraw one extra line but this is needed to make the redrawing
+ // logic work when there is a fractional number of lines on screen
+ m_lineTo = m_lineFrom + m_linesPerPage;
+ if ( m_lineTo >= count )
+ m_lineTo = count - 1;
+ }
+ else // empty control
+ {
+ m_lineFrom = 0;
+ m_lineTo = (size_t)-1;
+ }
}
+ wxASSERT_MSG( IsEmpty() ||
+ (m_lineFrom <= m_lineTo && m_lineTo < GetItemCount()),
+ _T("GetVisibleLinesRange() returns incorrect result") );
+
if ( from )
*from = m_lineFrom;
if ( to )
return -1;
}
+wxListItemAttr *wxListCtrl::OnGetItemAttr(long item) const
+{
+ wxASSERT_MSG( item >= 0 && item < GetItemCount(),
+ _T("invalid item index in OnGetItemAttr()") );
+
+ // no attributes by default
+ return NULL;
+}
+
void wxListCtrl::SetItemCount(long count)
{
wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
m_mainWin->SetItemCount(count);
}
+void wxListCtrl::RefreshItem(long item)
+{
+ m_mainWin->RefreshLine(item);
+}
+
+void wxListCtrl::RefreshItems(long itemFrom, long itemTo)
+{
+ m_mainWin->RefreshLines(itemFrom, itemTo);
+}
+
#endif // wxUSE_LISTCTRL