return *(GetOwner()->GetColumn(idx));
}
- // FIXME: currently unused
virtual bool UpdateColumnWidthToFit(unsigned int idx, int widthTitle)
{
wxDataViewCtrl * const owner = GetOwner();
model->Resort();
owner->OnColumnChange(idx);
+
+ SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, idx);
}
void OnRClick(wxHeaderCtrlEvent& event)
int GetLineHeight( unsigned int row ) const; // m_lineHeight in fixed mode
int GetLineAt( unsigned int y ) const; // y / m_lineHeight in fixed mode
+ void SetRowHeight( int lineHeight ) { m_lineHeight = lineHeight; }
+
// Some useful functions for row and item mapping
wxDataViewItem GetItemByRow( unsigned int row ) const;
int GetRowByItem( const wxDataViewItem & item ) const;
return true;
}
-wxControl* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow *parent,
+wxWindow* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow *parent,
wxRect labelRect, const wxVariant &value )
{
wxTextCtrl* ctrl = new wxTextCtrl( parent, wxID_ANY, value,
return ctrl;
}
-bool wxDataViewTextRenderer::GetValueFromEditorCtrl( wxControl *editor, wxVariant &value )
+bool wxDataViewTextRenderer::GetValueFromEditorCtrl( wxWindow *editor, wxVariant &value )
{
wxTextCtrl *text = (wxTextCtrl*) editor;
value = text->GetValue();
bool wxDataViewBitmapRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state) )
{
- if (m_bitmap.Ok())
+ if (m_bitmap.IsOk())
dc->DrawBitmap( m_bitmap, cell.x, cell.y );
- else if (m_icon.Ok())
+ else if (m_icon.IsOk())
dc->DrawIcon( m_icon, cell.x, cell.y );
return true;
wxSize wxDataViewBitmapRenderer::GetSize() const
{
- if (m_bitmap.Ok())
+ if (m_bitmap.IsOk())
return wxSize( m_bitmap.GetWidth(), m_bitmap.GetHeight() );
- else if (m_icon.Ok())
+ else if (m_icon.IsOk())
return wxSize( m_icon.GetWidth(), m_icon.GetHeight() );
return wxSize(wxDVC_DEFAULT_RENDERER_SIZE,wxDVC_DEFAULT_RENDERER_SIZE);
return true;
}
-void wxDataViewToggleRenderer::WXOnActivate(wxDataViewModel *model,
- const wxVariant& valueOld,
- const wxDataViewItem & item,
- unsigned int col)
+bool wxDataViewToggleRenderer::WXOnLeftClick(const wxPoint& cursor,
+ const wxRect& WXUNUSED(cell),
+ wxDataViewModel *model,
+ const wxDataViewItem& item,
+ unsigned int col)
{
+ // only react to clicks directly on the checkbox, not elsewhere in the same cell:
+ if (!wxRect(GetSize()).Contains(cursor))
+ return false;
+
if (model->IsEnabled(item, col))
{
- model->ChangeValue(!valueOld.GetBool(), item, col);
+ model->ChangeValue(!m_toggle, item, col);
+ return true;
}
+
+ return false;
}
wxSize wxDataViewToggleRenderer::GetSize() const
return GetTextExtent(m_date.FormatDate());
}
-void wxDataViewDateRenderer::WXOnActivate(wxDataViewModel *model,
- const wxVariant& valueOld,
- const wxDataViewItem & item,
- unsigned int col )
+bool wxDataViewDateRenderer::WXOnActivate(const wxRect& WXUNUSED(cell),
+ wxDataViewModel *model,
+ const wxDataViewItem& item,
+ unsigned int col)
{
- wxDateTime dtOld = valueOld.GetDateTime();
+ wxDateTime dtOld = m_date;
#if wxUSE_DATE_RENDERER_POPUP
wxDataViewDateRendererPopupTransient *popup = new wxDataViewDateRendererPopupTransient(
#else // !wxUSE_DATE_RENDERER_POPUP
wxMessageBox(dtOld.Format());
#endif // wxUSE_DATE_RENDERER_POPUP/!wxUSE_DATE_RENDERER_POPUP
+
+ return true;
}
// ---------------------------------------------------------
return wxSize(80,20);
}
-wxControl* wxDataViewIconTextRenderer::CreateEditorCtrl(wxWindow *parent, wxRect labelRect, const wxVariant& value)
+wxWindow* wxDataViewIconTextRenderer::CreateEditorCtrl(wxWindow *parent, wxRect labelRect, const wxVariant& value)
{
wxDataViewIconText iconText;
iconText << value;
return ctrl;
}
-bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( wxControl *editor, wxVariant& value )
+bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( wxWindow *editor, wxVariant& value )
{
wxTextCtrl *text = (wxTextCtrl*) editor;
dc.DrawRectangle(GetClientSize());
#endif
+ if ( IsEmpty() )
+ {
+ // No items to draw.
+ return;
+ }
+
// prepare the DC
GetOwner()->PrepareDC( dc );
dc.SetFont( GetFont() );
wxMin( (int)( GetLineAt( wxMax(0,update.y+update.height) ) - item_start + 1),
(int)(GetRowCount( ) - item_start));
unsigned int item_last = item_start + item_count;
- // Get the parent of DataViewCtrl
- wxWindow *parent = GetParent()->GetParent();
+
+ // Send the event to wxDataViewCtrl itself.
+ wxWindow * const parent = GetParent();
wxDataViewEvent cache_event(wxEVT_COMMAND_DATAVIEW_CACHE_HINT, parent->GetId());
- cache_event.SetEventObject(GetParent());
+ cache_event.SetEventObject(parent);
cache_event.SetCache(item_start, item_last - 1);
parent->ProcessWindowEvent(cache_event);
dc.SetPen(m_penRule);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
- int x = x_start;
+ // NB: Vertical rules are drawn in the last pixel of a column so that
+ // they align perfectly with native MSW wxHeaderCtrl as well as for
+ // consistency with MSW native list control. There's no vertical
+ // rule at the most-left side of the control.
+
+ int x = x_start - 1;
for (unsigned int i = col_start; i < col_last; i++)
{
wxDataViewColumn *col = GetOwner()->GetColumnAt(i);
if (col->IsHidden())
continue; // skip it
+ x += col->GetWidth();
+
dc.DrawLine(x, GetLineStart( item_start ),
x, GetLineStart( item_last ) );
-
- x += col->GetWidth();
}
-
- // Draw last vertical rule
- dc.DrawLine(x, GetLineStart( item_start ),
- x, GetLineStart( item_last ) );
}
// redraw the background for the items which are selected/current
dataitem = node->GetItem();
- if ((i > 0) && model->IsContainer(dataitem) &&
- !model->HasContainerColumns(dataitem))
+ // Skip all columns of "container" rows except the expander
+ // column itself unless HasContainerColumns() overrides this.
+ if ( col != GetOwner()->GetExpanderColumn() &&
+ model->IsContainer(dataitem) &&
+ !model->HasContainerColumns(dataitem) )
continue;
}
else
// Find the item along the parent-chain.
// This algorithm is designed to speed up the node-finding method
wxDataViewTreeNode* node = m_root;
- for( unsigned iter = parentChain.size()-1; iter>=0; --iter )
+ for( unsigned iter = parentChain.size()-1; ; --iter )
{
if( node->HasChildren() )
{
}
else
return NULL;
+
+ if ( !iter )
+ break;
}
return NULL;
}
break;
case WXK_DOWN:
- if ( m_currentRow < GetRowCount() - 1 )
+ if ( m_currentRow + 1 < GetRowCount() )
OnArrowChar( m_currentRow + 1, event );
break;
// Add the process for tree expanding/collapsing
{
const unsigned colIdx = col->GetModelColumn();
- wxVariant value;
- model->GetValue( value, item, colIdx );
-
- cell->WXOnActivate(model, value, item, colIdx);
-
- if ( wxDataViewCustomRenderer *custom = cell->WXGetAsCustom() )
- {
- cell->SetValue( value );
+ cell->PrepareForItem(model, item, colIdx);
- wxRect cell_rect( xpos, GetLineStart( current ),
- col->GetWidth(), GetLineHeight( current ) );
- custom->Activate( cell_rect, model, item, colIdx );
- }
+ wxRect cell_rect( xpos, GetLineStart( current ),
+ col->GetWidth(), GetLineHeight( current ) );
+ cell->WXOnActivate( cell_rect, model, item, colIdx );
}
else
{
if (!IsRowSelected(current))
{
SelectAllRows(false);
+ const unsigned oldCurrent = m_currentRow;
ChangeCurrentRow(current);
SelectRow(m_currentRow,true);
+ RefreshRow(oldCurrent);
SendSelectionChangedEvent(GetItemByRow( m_currentRow ) );
}
}
// Call LeftClick after everything else as under GTK+
if (cell->GetMode() & wxDATAVIEW_CELL_ACTIVATABLE)
{
- if ( wxDataViewCustomRenderer *custom = cell->WXGetAsCustom() )
- {
- // notify cell about click
- custom->PrepareForItem(model, item, col->GetModelColumn());
+ // notify cell about click
+ cell->PrepareForItem(model, item, col->GetModelColumn());
- wxRect cell_rect( xpos, GetLineStart( current ),
- col->GetWidth(), GetLineHeight( current ) );
+ wxRect cell_rect( xpos, GetLineStart( current ),
+ col->GetWidth(), GetLineHeight( current ) );
- // Report position relative to the cell's custom area, i.e.
- // no the entire space as given by the control but the one
- // used by the renderer after calculation of alignment etc.
+ // Report position relative to the cell's custom area, i.e.
+ // no the entire space as given by the control but the one
+ // used by the renderer after calculation of alignment etc.
- // adjust the rectangle ourselves to account for the alignment
- wxRect rectItem = cell_rect;
- const int align = custom->GetAlignment();
- if ( align != wxDVR_DEFAULT_ALIGNMENT )
- {
- const wxSize size = custom->GetSize();
+ // adjust the rectangle ourselves to account for the alignment
+ wxRect rectItem = cell_rect;
+ const int align = cell->GetAlignment();
+ if ( align != wxDVR_DEFAULT_ALIGNMENT )
+ {
+ const wxSize size = cell->GetSize();
- if ( size.x >= 0 && size.x < cell_rect.width )
- {
- if ( align & wxALIGN_CENTER_HORIZONTAL )
- rectItem.x += (cell_rect.width - size.x)/2;
- else if ( align & wxALIGN_RIGHT )
- rectItem.x += cell_rect.width - size.x;
- // else: wxALIGN_LEFT is the default
- }
+ if ( size.x >= 0 && size.x < cell_rect.width )
+ {
+ if ( align & wxALIGN_CENTER_HORIZONTAL )
+ rectItem.x += (cell_rect.width - size.x)/2;
+ else if ( align & wxALIGN_RIGHT )
+ rectItem.x += cell_rect.width - size.x;
+ // else: wxALIGN_LEFT is the default
+ }
- if ( size.y >= 0 && size.y < cell_rect.height )
- {
- if ( align & wxALIGN_CENTER_VERTICAL )
- rectItem.y += (cell_rect.height - size.y)/2;
- else if ( align & wxALIGN_BOTTOM )
- rectItem.y += cell_rect.height - size.y;
- // else: wxALIGN_TOP is the default
- }
+ if ( size.y >= 0 && size.y < cell_rect.height )
+ {
+ if ( align & wxALIGN_CENTER_VERTICAL )
+ rectItem.y += (cell_rect.height - size.y)/2;
+ else if ( align & wxALIGN_BOTTOM )
+ rectItem.y += cell_rect.height - size.y;
+ // else: wxALIGN_TOP is the default
}
+ }
- wxPoint pos( event.GetPosition() );
- pos.x -= rectItem.x;
- pos.y -= rectItem.y;
+ wxPoint pos( event.GetPosition() );
+ pos.x -= rectItem.x;
+ pos.y -= rectItem.y;
- m_owner->CalcUnscrolledPosition( pos.x, pos.y, &pos.x, &pos.y );
+ m_owner->CalcUnscrolledPosition( pos.x, pos.y, &pos.x, &pos.y );
- /* ignore ret */ custom->LeftClick( pos, cell_rect,
- model, item, col->GetModelColumn());
- }
+ /* ignore ret */ cell->WXOnLeftClick( pos, cell_rect,
+ model, item, col->GetModelColumn());
}
}
}
Layout();
AdjustScrollbars();
+
+ // We must redraw the headers if their height changed. Normally this
+ // shouldn't happen as the control shouldn't let itself be resized beneath
+ // its minimal height but avoid the display artefacts that appear if it
+ // does happen, e.g. because there is really not enough vertical space.
+ if ( !HasFlag(wxDV_NO_HEADER) && m_headerArea &&
+ m_headerArea->GetSize().y <= m_headerArea->GetBestSize(). y )
+ {
+ m_headerArea->Refresh();
+ }
}
void wxDataViewCtrl::SetFocus()
return m_cols.GetCount();
}
+bool wxDataViewCtrl::SetRowHeight( int lineHeight )
+{
+ if ( !m_clientArea )
+ return false;
+
+ m_clientArea->SetRowHeight(lineHeight);
+
+ return true;
+}
+
wxDataViewColumn* wxDataViewCtrl::GetColumn( unsigned int idx ) const
{
return m_cols[idx];
calculator.UpdateWithRow(row);
}
- // row is the first unmeasured item now; that's out value of N/2
+ // row is the first unmeasured item now; that's our value of N/2
if ( row < count )
{
const_cast<wxDataViewCtrl*>(this)->m_colsBestWidths[idx] = max_width;
return max_width;
-
- #undef MEASURE_ITEM
}
void wxDataViewCtrl::ColumnMoved(wxDataViewColumn * WXUNUSED(col),
if ( m_headerArea )
{
- // this updates visual appearance of columns 0 and up, not just 0
- m_headerArea->UpdateColumn(0);
+ const unsigned cols = m_headerArea->GetColumnCount();
+ for ( unsigned i = 0; i < cols; i++ )
+ m_headerArea->UpdateColumn(i);
}
}