X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/baa9ebc473dba4e4ca0c4f288e6ed7c8c277295e..4a9eae369e6f1908be8c757cb82e022171dff03d:/src/common/datavcmn.cpp diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index 646005e095..73fa33d507 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -25,18 +25,11 @@ const wxChar wxDataViewCtrlNameStr[] = wxT("dataviewCtrl"); -// --------------------------------------------------------- -// wxDataViewModel -// --------------------------------------------------------- - -IMPLEMENT_ABSTRACT_CLASS(wxDataViewModel, wxObject) // --------------------------------------------------------- // wxDataViewListModel // --------------------------------------------------------- -IMPLEMENT_ABSTRACT_CLASS(wxDataViewListModel, wxDataViewModel) - wxDataViewListModel::wxDataViewListModel() { m_viewingColumns.DeleteContents( true ); @@ -45,6 +38,13 @@ wxDataViewListModel::wxDataViewListModel() wxDataViewListModel::~wxDataViewListModel() { + wxList::compatibility_iterator node = m_notifiers.GetFirst(); + while (node) + { + wxDataViewListModelNotifier* notifier = (wxDataViewListModelNotifier*) node->GetData(); + notifier->Freed(); + node = node->GetNext(); + } } bool wxDataViewListModel::RowAppended() @@ -242,6 +242,9 @@ public: virtual bool Cleared() { return m_model->ChildCleared(); } + virtual bool Freed() + { m_model->m_child = NULL; return wxDataViewListModelNotifier::Freed(); } + wxDataViewSortedListModel *m_model; }; @@ -287,9 +290,15 @@ int wxCALLBACK wxDataViewListModelSortedDefaultCompare 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 ) { @@ -300,15 +309,12 @@ 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 ); @@ -318,13 +324,27 @@ wxDataViewSortedListModel::wxDataViewSortedListModel( wxDataViewListModel *child 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 ); @@ -333,7 +353,7 @@ void wxDataViewSortedListModel::Resort() #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++) { @@ -559,22 +579,22 @@ bool wxDataViewSortedListModel::ChildCleared() 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 ); @@ -681,10 +701,16 @@ bool wxDataViewSortedListModel::Cleared() 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(); } // --------------------------------------------------------- @@ -693,16 +719,32 @@ wxDataViewRendererBase::wxDataViewRendererBase( const wxString &varianttype, wxD 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), + wxAlignment WXUNUSED(align), + int WXUNUSED(flags)) +{ + m_renderer = renderer; + m_model_column = model_column; + 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_title = title; + m_bitmap = bitmap; m_owner = NULL; m_renderer->SetOwner( (wxDataViewColumn*) this ); } @@ -718,16 +760,28 @@ wxDataViewColumnBase::~wxDataViewColumnBase() } } -void wxDataViewColumnBase::SetTitle( const wxString &title ) +int wxDataViewColumnBase::GetFlags() const { - m_title = title; + int ret = 0; + + if (IsSortable()) + ret |= wxDATAVIEW_COL_SORTABLE; + if (IsResizeable()) + ret |= wxDATAVIEW_COL_RESIZABLE; + if (IsHidden()) + ret |= wxDATAVIEW_COL_HIDDEN; + + return ret; } -wxString wxDataViewColumnBase::GetTitle() +void wxDataViewColumnBase::SetFlags(int flags) { - return m_title; + SetSortable((flags & wxDATAVIEW_COL_SORTABLE) != 0); + SetResizeable((flags & wxDATAVIEW_COL_RESIZABLE) != 0); + SetHidden((flags & wxDATAVIEW_COL_HIDDEN) != 0); } + // --------------------------------------------------------- // wxDataViewCtrlBase // --------------------------------------------------------- @@ -742,11 +796,27 @@ wxDataViewCtrlBase::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; } @@ -756,24 +826,84 @@ wxDataViewListModel* wxDataViewCtrlBase::GetModel() 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( wxT("string"), mode, (int)align ), + model_column, width, align, flags ) ); +} + +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( wxT("bool"), mode, (int)align ), + model_column, width, align, flags ) ); +} + +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( wxEmptyString, wxT("long"), mode, (int)align ), + model_column, width, align, flags ) ); +} + +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( wxT("datetime"), mode, (int)align ), + model_column, width, align, flags ) ); +} + +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( wxT("wxBitmap"), mode, (int)align ), + model_column, width, align, flags ) ); +} + +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( wxT("string"), mode, (int)align ), + model_column, width, align, flags ) ); +} + +bool wxDataViewCtrlBase::AppendToggleColumn( 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 wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ), + model_column, width, align, flags ) ); } -bool wxDataViewCtrlBase::AppendToggleColumn( const wxString &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 wxDataViewToggleRenderer(), model_column, 30 ) ); + return AppendColumn( new wxDataViewColumn( label, + new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ), + model_column, width, align, flags ) ); } -bool wxDataViewCtrlBase::AppendProgressColumn( const wxString &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 wxDataViewProgressRenderer(), model_column, 70 ) ); + return AppendColumn( new wxDataViewColumn( label, + new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ), + model_column, width, align, flags ) ); } -bool wxDataViewCtrlBase::AppendDateColumn( const wxString &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 wxDataViewDateRenderer(), model_column ) ); + return AppendColumn( new wxDataViewColumn( label, + new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ), + model_column, width, align, flags ) ); } bool wxDataViewCtrlBase::AppendColumn( wxDataViewColumn *col ) @@ -784,7 +914,7 @@ bool wxDataViewCtrlBase::AppendColumn( wxDataViewColumn *col ) return true; } -unsigned int wxDataViewCtrlBase::GetNumberOfColumns() +unsigned int wxDataViewCtrlBase::GetColumnCount() const { return m_cols.GetCount(); } @@ -811,6 +941,9 @@ wxDataViewColumn* wxDataViewCtrlBase::GetColumn( unsigned int pos ) IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent,wxNotifyEvent) 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