const wxChar wxDataViewCtrlNameStr[] = wxT("dataviewCtrl");
-// ---------------------------------------------------------
-// wxDataViewModel
-// ---------------------------------------------------------
-
-IMPLEMENT_ABSTRACT_CLASS(wxDataViewModel, wxObject)
// ---------------------------------------------------------
// wxDataViewListModel
// ---------------------------------------------------------
-IMPLEMENT_ABSTRACT_CLASS(wxDataViewListModel, wxDataViewModel)
-
wxDataViewListModel::wxDataViewListModel()
{
m_viewingColumns.DeleteContents( true );
wxDataViewListModel::~wxDataViewListModel()
{
+ wxList::compatibility_iterator node = m_notifiers.GetFirst();
+ while (node)
+ {
+ wxDataViewListModelNotifier* notifier = (wxDataViewListModelNotifier*) node->GetData();
+ notifier->Freed();
+ node = node->GetNext();
+ }
}
bool wxDataViewListModel::RowAppended()
virtual bool Cleared()
{ return m_model->ChildCleared(); }
+ virtual bool Freed()
+ { m_model->m_child = NULL; return wxDataViewListModelNotifier::Freed(); }
+
wxDataViewSortedListModel *m_model;
};
return 0;
}
+int wxCALLBACK wxDataViewListModelSortedDefaultCompareDescending
+ (unsigned int row1, unsigned int row2, unsigned int col, wxDataViewListModel* model )
+{
+ return wxDataViewListModelSortedDefaultCompare( row2, row1, col, model );
+}
+
static wxDataViewListModelCompare s_CmpFunc;
static wxDataViewListModel *s_CmpModel;
-static unsigned int s_CmpCol;
+static unsigned int s_CmpCol;
int LINKAGEMODE wxDataViewIntermediateCmp( unsigned int row1, unsigned int row2 )
{
// wxDataViewSortedListModel
// ---------------------------------------------------------
-IMPLEMENT_ABSTRACT_CLASS(wxDataViewSortedListModel, wxDataViewListModel)
-
wxDataViewSortedListModel::wxDataViewSortedListModel( wxDataViewListModel *child ) :
m_array( wxDataViewIntermediateCmp )
{
m_child = child;
- s_CmpCol = 0;
- s_CmpModel = child;
- s_CmpFunc = wxDataViewListModelSortedDefaultCompare;
+
+ m_ascending = true;
m_notifierOnChild = new wxDataViewSortedListModelNotifier( this );
m_child->AddNotifier( m_notifierOnChild );
wxDataViewSortedListModel::~wxDataViewSortedListModel()
{
+ if (m_child)
m_child->RemoveNotifier( m_notifierOnChild );
}
+// FIXME
+void wxDataViewSortedListModel::InitStatics()
+{
+ s_CmpCol = 0;
+ s_CmpModel = m_child;
+ if (m_ascending)
+ s_CmpFunc = wxDataViewListModelSortedDefaultCompare;
+ else
+ s_CmpFunc = wxDataViewListModelSortedDefaultCompareDescending;
+}
+
void wxDataViewSortedListModel::Resort()
{
+ InitStatics();
+
m_array.Clear();
- unsigned int n = m_child->GetNumberOfRows();
+ unsigned int n = m_child->GetRowCount();
unsigned int i;
for (i = 0; i < n; i++)
m_array.Add( i );
#if 0
static void Dump( wxDataViewListModel *model, unsigned int col )
{
- unsigned int n = model->GetNumberOfRows();
+ unsigned int n = model->GetRowCount();
unsigned int i;
for (i = 0; i < n; i++)
{
return wxDataViewListModel::Cleared();
}
-unsigned int wxDataViewSortedListModel::GetNumberOfRows()
+unsigned int wxDataViewSortedListModel::GetRowCount() const
{
return m_array.GetCount();
}
-unsigned int wxDataViewSortedListModel::GetNumberOfCols()
+unsigned int wxDataViewSortedListModel::GetColumnCount() const
{
- return m_child->GetNumberOfCols();
+ return m_child->GetColumnCount();
}
-wxString wxDataViewSortedListModel::GetColType( unsigned int col )
+wxString wxDataViewSortedListModel::GetColumnType( unsigned int col ) const
{
- return m_child->GetColType( col );
+ return m_child->GetColumnType( col );
}
-void wxDataViewSortedListModel::GetValue( wxVariant &variant, unsigned int col, unsigned int row )
+void wxDataViewSortedListModel::GetValue( wxVariant &variant, unsigned int col, unsigned int row ) const
{
unsigned int child_row = m_array[row];
m_child->GetValue( variant, col, child_row );
IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase, wxObject)
-wxDataViewRendererBase::wxDataViewRendererBase( const wxString &varianttype, wxDataViewCellMode mode )
+wxDataViewRendererBase::wxDataViewRendererBase( const wxString &varianttype,
+ wxDataViewCellMode WXUNUSED(mode),
+ int WXUNUSED(align) )
{
m_variantType = varianttype;
- m_mode = mode;
+}
+
+const wxDataViewCtrl* wxDataViewRendererBase::GetView() const
+{
+ return wx_const_cast(wxDataViewRendererBase*, this)->GetOwner()->GetOwner();
}
// ---------------------------------------------------------
IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumnBase, wxObject)
-wxDataViewColumnBase::wxDataViewColumnBase(const wxString& title,
+wxDataViewColumnBase::wxDataViewColumnBase(const wxString& WXUNUSED(title),
wxDataViewRenderer *renderer,
unsigned int model_column,
int WXUNUSED(width),
- int flags )
+ wxAlignment WXUNUSED(align),
+ int WXUNUSED(flags))
{
m_renderer = renderer;
m_model_column = model_column;
- m_flags = flags;
- m_title = title;
m_owner = NULL;
m_renderer->SetOwner( (wxDataViewColumn*) this );
+
+ // NOTE: the wxDataViewColumn's ctor must store the width, align, flags
+ // parameters inside the native control!
}
wxDataViewColumnBase::wxDataViewColumnBase(const wxBitmap& bitmap,
wxDataViewRenderer *renderer,
unsigned int model_column,
int WXUNUSED(width),
- int flags )
+ wxAlignment WXUNUSED(align),
+ int WXUNUSED(flags) )
{
m_renderer = renderer;
m_model_column = model_column;
- m_flags = flags;
m_bitmap = bitmap;
m_owner = NULL;
m_renderer->SetOwner( (wxDataViewColumn*) this );
}
}
-void wxDataViewColumnBase::SetTitle( const wxString &title )
+int wxDataViewColumnBase::GetFlags() const
{
- m_title = title;
-}
+ int ret = 0;
-wxString wxDataViewColumnBase::GetTitle()
-{
- return m_title;
-}
+ if (IsSortable())
+ ret |= wxDATAVIEW_COL_SORTABLE;
+ if (IsResizeable())
+ ret |= wxDATAVIEW_COL_RESIZABLE;
+ if (IsHidden())
+ ret |= wxDATAVIEW_COL_HIDDEN;
-void wxDataViewColumnBase::SetBitmap( const wxBitmap &bitmap )
-{
- m_bitmap = bitmap;
+ return ret;
}
-const wxBitmap &wxDataViewColumnBase::GetBitmap()
+void wxDataViewColumnBase::SetFlags(int flags)
{
- return m_bitmap;
+ SetSortable((flags & wxDATAVIEW_COL_SORTABLE) != 0);
+ SetResizeable((flags & wxDATAVIEW_COL_RESIZABLE) != 0);
+ SetHidden((flags & wxDATAVIEW_COL_HIDDEN) != 0);
}
+
// ---------------------------------------------------------
// wxDataViewCtrlBase
// ---------------------------------------------------------
wxDataViewCtrlBase::~wxDataViewCtrlBase()
{
+ // IMPORTANT: before calling DecRef() on our model (since it may
+ // result in a free() call), erase all columns (since
+ // they hold a pointer to our model)
+ m_cols.Clear();
+
+ if (m_model)
+ {
+ m_model->DecRef();
+ m_model = NULL;
+ }
}
bool wxDataViewCtrlBase::AssociateModel( wxDataViewListModel *model )
{
+ if ( m_model )
+ m_model->DecRef(); // discard old model, if any
+
+ // add our own reference to the new model:
m_model = model;
+ if ( m_model )
+ m_model->IncRef();
return true;
}
return m_model;
}
-bool wxDataViewCtrlBase::AppendTextColumn( const wxString &label, unsigned int model_column )
+bool wxDataViewCtrlBase::AppendTextColumn( const wxString &label, unsigned int model_column,
+ wxDataViewCellMode mode, int width, wxAlignment align, int flags )
{
- return AppendColumn( new wxDataViewColumn( label, new wxDataViewTextRenderer(), model_column ) );
+ return AppendColumn( new wxDataViewColumn( label,
+ new wxDataViewTextRenderer( wxT("string"), mode, (int)align ),
+ model_column, width, align, flags ) );
}
-bool wxDataViewCtrlBase::AppendToggleColumn( const wxString &label, unsigned int model_column )
+bool wxDataViewCtrlBase::AppendToggleColumn( const wxString &label, unsigned int model_column,
+ wxDataViewCellMode mode, int width, wxAlignment align, int flags )
{
- return AppendColumn( new wxDataViewColumn( label, new wxDataViewToggleRenderer(), model_column, 30 ) );
+ return AppendColumn( new wxDataViewColumn( label,
+ new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ),
+ model_column, width, align, flags ) );
}
-bool wxDataViewCtrlBase::AppendProgressColumn( const wxString &label, unsigned int model_column )
+bool wxDataViewCtrlBase::AppendProgressColumn( const wxString &label, unsigned int model_column,
+ wxDataViewCellMode mode, int width, wxAlignment align, int flags )
{
- return AppendColumn( new wxDataViewColumn( label, new wxDataViewProgressRenderer(), model_column, 70 ) );
+ return AppendColumn( new wxDataViewColumn( label,
+ new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ),
+ model_column, width, align, flags ) );
}
-bool wxDataViewCtrlBase::AppendDateColumn( const wxString &label, unsigned int model_column )
+bool wxDataViewCtrlBase::AppendDateColumn( const wxString &label, unsigned int model_column,
+ wxDataViewCellMode mode, int width, wxAlignment align, int flags )
{
- return AppendColumn( new wxDataViewColumn( label, new wxDataViewDateRenderer(), model_column ) );
+ return AppendColumn( new wxDataViewColumn( label,
+ new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ),
+ model_column, width, align, flags ) );
}
-bool wxDataViewCtrlBase::AppendBitmapColumn( const wxString &label, unsigned int model_column )
+bool wxDataViewCtrlBase::AppendBitmapColumn( const wxString &label, unsigned int model_column,
+ wxDataViewCellMode mode, int width, wxAlignment align, int flags )
{
- return AppendColumn( new wxDataViewColumn( label, new wxDataViewBitmapRenderer(), model_column ) );
+ return AppendColumn( new wxDataViewColumn( label,
+ new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ),
+ model_column, width, align, flags ) );
}
-bool wxDataViewCtrlBase::AppendTextColumn( const wxBitmap &label, unsigned int model_column )
+bool wxDataViewCtrlBase::AppendTextColumn( const wxBitmap &label, unsigned int model_column,
+ wxDataViewCellMode mode, int width, wxAlignment align, int flags )
{
- return AppendColumn( new wxDataViewColumn( label, new wxDataViewTextRenderer(), model_column ) );
+ return AppendColumn( new wxDataViewColumn( label,
+ new wxDataViewTextRenderer( wxT("string"), mode, (int)align ),
+ model_column, width, align, flags ) );
}
-bool wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap &label, unsigned int model_column )
+bool wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap &label, unsigned int model_column,
+ wxDataViewCellMode mode, int width, wxAlignment align, int flags )
{
- return AppendColumn( new wxDataViewColumn( label, new wxDataViewToggleRenderer(), model_column, 30 ) );
+ return AppendColumn( new wxDataViewColumn( label,
+ new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ),
+ model_column, width, align, flags ) );
}
-bool wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap &label, unsigned int model_column )
+bool wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap &label, unsigned int model_column,
+ wxDataViewCellMode mode, int width, wxAlignment align, int flags )
{
- return AppendColumn( new wxDataViewColumn( label, new wxDataViewProgressRenderer(), model_column, 70 ) );
+ return AppendColumn( new wxDataViewColumn( label,
+ new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ),
+ model_column, width, align, flags ) );
}
-bool wxDataViewCtrlBase::AppendDateColumn( const wxBitmap &label, unsigned int model_column )
+bool wxDataViewCtrlBase::AppendDateColumn( const wxBitmap &label, unsigned int model_column,
+ wxDataViewCellMode mode, int width, wxAlignment align, int flags )
{
- return AppendColumn( new wxDataViewColumn( label, new wxDataViewDateRenderer(), model_column ) );
+ return AppendColumn( new wxDataViewColumn( label,
+ new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ),
+ model_column, width, align, flags ) );
}
-bool wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap &label, unsigned int model_column )
+bool wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap &label, unsigned int model_column,
+ wxDataViewCellMode mode, int width, wxAlignment align, int flags )
{
- return AppendColumn( new wxDataViewColumn( label, new wxDataViewBitmapRenderer(), model_column ) );
+ return AppendColumn( new wxDataViewColumn( label,
+ new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ),
+ model_column, width, align, flags ) );
}
bool wxDataViewCtrlBase::AppendColumn( wxDataViewColumn *col )
return true;
}
-unsigned int wxDataViewCtrlBase::GetNumberOfColumns()
+unsigned int wxDataViewCtrlBase::GetColumnCount() const
{
return m_cols.GetCount();
}
DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ROW_SELECTED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ROW_ACTIVATED)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK)
#endif