return *(GetOwner()->GetColumn(idx));
}
- // FIXME: currently unused
virtual bool UpdateColumnWidthToFit(unsigned int idx, int widthTitle)
{
wxDataViewCtrl * const owner = GetOwner();
bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item );
bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item );
bool ItemChanged( const wxDataViewItem &item );
- bool ValueChanged( const wxDataViewItem &item, unsigned int col );
+ bool ValueChanged( const wxDataViewItem &item, unsigned int model_column );
bool Cleared();
void Resort()
{
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
return true;
}
-bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem & item, unsigned int col )
+bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem & item, unsigned int model_column )
{
- GetOwner()->InvalidateColBestWidth(col);
+ int view_column = -1;
+ unsigned int n_col = m_owner->GetColumnCount();
+ for (unsigned i = 0; i < n_col; i++)
+ {
+ wxDataViewColumn *column = m_owner->GetColumn( i );
+ if (column->GetModelColumn() == model_column)
+ {
+ view_column = (int) i;
+ break;
+ }
+ }
+ if (view_column == -1)
+ return false;
+
+ GetOwner()->InvalidateColBestWidth(view_column);
// NOTE: to be valid, we cannot use e.g. INT_MAX - 1
/*#define MAX_VIRTUAL_WIDTH 100000
le.SetEventObject(parent);
le.SetModel(GetOwner()->GetModel());
le.SetItem(item);
- le.SetColumn(col);
- le.SetDataViewColumn(GetOwner()->GetColumn(col));
+ le.SetColumn(view_column);
+ le.SetDataViewColumn(GetOwner()->GetColumn(view_column));
parent->GetEventHandler()->ProcessEvent(le);
return true;
void wxDataViewMainWindow::ScrollWindow( int dx, int dy, const wxRect *rect )
{
+ m_underMouse = NULL;
+
wxWindow::ScrollWindow( dx, dy, rect );
if (GetOwner()->m_headerArea)
void wxDataViewMainWindow::ScrollTo( int rows, int column )
{
+ m_underMouse = NULL;
+
int x, y;
m_owner->GetScrollPixelsPerUnit( &x, &y );
int sy = GetLineStart( rows )/y;
{
const unsigned colIdx = col->GetModelColumn();
- wxVariant value;
- model->GetValue( value, item, colIdx );
+ cell->PrepareForItem(model, item, colIdx);
- cell->WXOnActivate(model, value, item, colIdx);
-
- if ( wxDataViewCustomRenderer *custom = cell->WXGetAsCustom() )
- {
- cell->SetValue( value );
-
- 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
{
// 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());
}
}
}
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);
}
}
wxRect itemRect = GetItemRect(item, col);
wxDataViewRenderer* renderer = col->GetRenderer();
- renderer->StartEditing(item, itemRect);
+ if (renderer->GetMode() == wxDATAVIEW_CELL_EDITABLE)
+ renderer->StartEditing(item, itemRect);
}
#endif // !wxUSE_GENERICDATAVIEWCTRL