// the displaying number of the tree are changing along with the
// expanding/collapsing of the tree nodes
unsigned int GetLastVisibleRow();
- unsigned int GetRowCount();
+ unsigned int GetRowCount() const;
const wxDataViewSelection& GetSelections() const { return m_selection; }
void SetSelections( const wxDataViewSelection & sel )
void StartEditing(const wxDataViewItem& item, const wxDataViewColumn* col);
private:
- int RecalculateCount();
+ int RecalculateCount() const;
// Return false only if the event was vetoed by its handler.
bool SendExpanderEvent(wxEventType type, const wxDataViewItem& item);
m_useCellFocus = false;
m_currentRow = 0;
- m_lineHeight = wxMax( 17, GetCharHeight() + 4 ); // 17 = mini icon height + 1
+#ifdef __WXMSW__
+ // We would like to use the same line height that Explorer uses. This is
+ // different from standard ListView control since Vista.
+ if ( wxGetWinVersion() >= wxWinVersion_Vista )
+ m_lineHeight = wxMax(16, GetCharHeight()) + 6; // 16 = mini icon height
+ else
+#endif // __WXMSW__
+ m_lineHeight = wxMax(16, GetCharHeight()) + 1; // 16 = mini icon height
#if wxUSE_DRAG_AND_DROP
m_dragCount = 0;
x_last += col->GetWidth();
}
+ // Draw background of alternate rows specially if required
+ if ( m_owner->HasFlag(wxDV_ROW_LINES) )
+ {
+ wxColour altRowColour = m_owner->m_alternateRowColour;
+ if ( !altRowColour.IsOk() )
+ {
+ // Determine the alternate rows colour automatically from the
+ // background colour.
+ const wxColour bgColour = m_owner->GetBackgroundColour();
+
+ // Depending on the background, alternate row color
+ // will be 3% more dark or 50% brighter.
+ int alpha = bgColour.GetRGB() > 0x808080 ? 97 : 150;
+ altRowColour = bgColour.ChangeLightness(alpha);
+ }
+
+ dc.SetPen(*wxTRANSPARENT_PEN);
+ dc.SetBrush(wxBrush(altRowColour));
+
+ for (unsigned int item = item_start; item < item_last; item++)
+ {
+ if ( item % 2 )
+ {
+ dc.DrawRectangle(x_start,
+ GetLineStart(item),
+ GetClientSize().GetWidth(),
+ GetLineHeight(item));
+ }
+ }
+ }
+
// Draw horizontal rules if required
if ( m_owner->HasFlag(wxDV_HORIZ_RULES) )
{
return wxMin( GetRowCount()-1, row );
}
-unsigned int wxDataViewMainWindow::GetRowCount()
+unsigned int wxDataViewMainWindow::GetRowCount() const
{
if ( m_count == -1 )
{
- m_count = RecalculateCount();
- UpdateDisplay();
+ wxDataViewMainWindow* const
+ self = const_cast<wxDataViewMainWindow*>(this);
+ self->m_count = RecalculateCount();
+ self->UpdateDisplay();
}
return m_count;
}
wxDataViewItem wxDataViewMainWindow::GetItemByRow(unsigned int row) const
{
+ wxDataViewItem item;
if (IsVirtualList())
{
- return wxDataViewItem( wxUIntToPtr(row+1) );
+ if ( row < GetRowCount() )
+ item = wxDataViewItem(wxUIntToPtr(row+1));
}
else
{
wxDataViewTreeNode *node = GetTreeNodeByRow(row);
- return node ? node->GetItem() : wxDataViewItem();
+ if ( node )
+ item = node->GetItem();
}
+
+ return item;
}
bool
return itemRect;
}
-int wxDataViewMainWindow::RecalculateCount()
+int wxDataViewMainWindow::RecalculateCount() const
{
if (IsVirtualList())
{
switch ( event.GetKeyCode() )
{
case WXK_RETURN:
- if ( !event.HasModifiers() )
+ if ( event.HasModifiers() )
+ {
+ event.Skip();
+ break;
+ }
+ else
{
// Enter activates the item, i.e. sends wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED to
// it. Only if that event is not handled do we activate column renderer (which
}
case WXK_SPACE:
- if ( !event.HasModifiers() )
+ if ( event.HasModifiers() )
+ {
+ event.Skip();
+ break;
+ }
+ else
{
// Space toggles activatable items or -- if not activatable --
// starts inline editing (this is normally done using F2 on
}
case WXK_F2:
- if ( !event.HasModifiers() )
+ if ( event.HasModifiers() )
+ {
+ event.Skip();
+ break;
+ }
+ else
{
if( !m_selection.empty() )
{
wxDataViewColumn *editableCol = FindColumnForEditing(item, wxDATAVIEW_CELL_EDITABLE);
if ( editableCol )
- GetOwner()->StartEditor(item, GetOwner()->GetColumnIndex(editableCol));
+ GetOwner()->EditItem(item, editableCol);
}
}
break;
return false;
}
+void wxDataViewCtrl::SetAlternateRowColour(const wxColour& colour)
+{
+ m_alternateRowColour = colour;
+}
+
void wxDataViewCtrl::SelectAll()
{
m_clientArea->SelectAllRows(true);
return false;
}
-void wxDataViewCtrl::StartEditor( const wxDataViewItem & item, unsigned int column )
+void wxDataViewCtrl::EditItem(const wxDataViewItem& item, const wxDataViewColumn *column)
{
- wxDataViewColumn* col = GetColumn( column );
- if (!col)
- return;
+ wxCHECK_RET( item.IsOk(), "invalid item" );
+ wxCHECK_RET( column, "no column provided" );
- m_clientArea->StartEditing(item, col);
+ m_clientArea->StartEditing(item, column);
}
#endif // !wxUSE_GENERICDATAVIEWCTRL