X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1b27b2bd2b6e290645516c180566222c6aa22149..8cb1060f1e2f2cbbcaebcc668dccefdd79804662:/src/mac/carbon/dataview.cpp diff --git a/src/mac/carbon/dataview.cpp b/src/mac/carbon/dataview.cpp index df0e175ccf..c21aa0f8a3 100644 --- a/src/mac/carbon/dataview.cpp +++ b/src/mac/carbon/dataview.cpp @@ -277,7 +277,7 @@ IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer,wxDataViewRendererBase) // --------------------------------------------------------- #pragma mark - wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align) - :wxDataViewRenderer(varianttype,mode,align), m_editorCtrlPtr(NULL) + :wxDataViewRenderer(varianttype,mode,align), m_editorCtrlPtr(NULL), m_DCPtr(NULL) { } /* wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString const&, wxDataViewCellMode) */ @@ -300,7 +300,7 @@ wxDC* wxDataViewCustomRenderer::GetDC(void) bool wxDataViewCustomRenderer::Render(void) { - return false; + return true; } /* wxDataViewCustomRenderer::Render(void) */ void wxDataViewCustomRenderer::SetDC(wxDC* newDCPtr) @@ -355,7 +355,7 @@ bool wxDataViewBitmapRenderer::Render(void) if (bitmap.Ok()) return (::SetDataBrowserItemDataIcon(this->GetDataReference(),bitmap.GetBitmapData()->GetIconRef()) == noErr); else - return false; + return true; } /* if */ else return false; @@ -363,6 +363,37 @@ bool wxDataViewBitmapRenderer::Render(void) IMPLEMENT_CLASS(wxDataViewBitmapRenderer,wxDataViewRenderer) +// --------------------------------------------------------- +// wxDataViewIconTextRenderer +// --------------------------------------------------------- +#pragma mark - +wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align) + :wxDataViewRenderer(varianttype,mode) +{ +} + +bool wxDataViewIconTextRenderer::Render(void) +{ + if (this->GetValue().GetType() == this->GetVariantType()) + { + // variable definition: + wxDataViewIconText iconText; + + iconText << this->GetValue(); + + // variable definition: + wxMacCFStringHolder cfString(iconText.GetText(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding())); + + return ((::SetDataBrowserItemDataIcon(this->GetDataReference(),MAC_WXHICON(iconText.GetIcon().GetHICON())) == noErr) && + (::SetDataBrowserItemDataText(this->GetDataReference(),cfString) == noErr)); + } /* if */ + else + return false; +} /* wxDataViewIconTextRenderer::Render(void) */ + +IMPLEMENT_ABSTRACT_CLASS(wxDataViewIconTextRenderer,wxDataViewRenderer) + + // --------------------------------------------------------- // wxDataViewToggleRenderer // --------------------------------------------------------- @@ -428,14 +459,14 @@ IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer,wxDataViewRenderer) #pragma mark - wxDataViewColumn::wxDataViewColumn(wxString const &title, wxDataViewRenderer *cell, unsigned int model_column, int width, wxAlignment align, int flags) :wxDataViewColumnBase(title,cell,model_column,width,wxALIGN_CENTER,flags), m_ascending(true), - m_flags(flags & ~(wxDATAVIEW_COL_HIDDEN | wxDATAVIEW_COL_RESIZABLE)), m_maxWidth(std::numeric_limits::max()), m_minWidth(0), m_width(width), + m_flags(flags & ~(wxDATAVIEW_COL_HIDDEN)), m_maxWidth(30000), m_minWidth(0), m_width(width >= 0 ? width : wxDVC_DEFAULT_WIDTH), m_alignment(align), m_title(title) { } /* wxDataViewColumn::wxDataViewColumn(wxString const &title, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */ wxDataViewColumn::wxDataViewColumn(wxBitmap const& bitmap, wxDataViewRenderer *cell, unsigned int model_column, int width, wxAlignment align, int flags) :wxDataViewColumnBase(bitmap,cell,model_column,width,wxALIGN_CENTER,flags), m_ascending(true), - m_flags(flags & (wxDATAVIEW_COL_HIDDEN | wxDATAVIEW_COL_RESIZABLE)), m_maxWidth(std::numeric_limits::max()), m_minWidth(0), m_width(width), + m_flags(flags & ~(wxDATAVIEW_COL_HIDDEN)), m_maxWidth(30000), m_minWidth(0), m_width(width >= 0 ? width : wxDVC_DEFAULT_WIDTH), m_alignment(align) { } /* wxDataViewColumn::wxDataViewColumn(wxBitmap const&, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */ @@ -613,6 +644,7 @@ void wxDataViewColumn::SetSortOrder(bool ascending) else headerDescription.initialOrder = kDataBrowserOrderDecreasing; verify_noerr(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription)); + macDataViewListCtrlPtr->SetSortProperty(this->GetPropertyID()); } /* if */ } /* if */ } /* wxDataViewColumn::SetSortOrder(bool) */ @@ -670,7 +702,6 @@ void wxDataViewCtrl::Init(void) { this->m_Deleting = false; this->m_macIsUserPane = false; - this->m_NotifierPtr = NULL; this->m_cgContext = NULL; } /* wxDataViewCtrl::Init(void) */ @@ -692,28 +723,41 @@ bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, return true; } /* wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator) */ +bool wxDataViewCtrl::AssociateModel(wxDataViewModel* model) +{ + if (!wxDataViewCtrlBase::AssociateModel(model)) + return false; + + model->AddNotifier(new wxMacDataViewModelNotifier(dynamic_cast(this->m_peer))); + + return true; +} /* wxDataViewCtrl::AssociateModel(wxDataViewModel*) */ + bool wxDataViewCtrl::AppendColumn(wxDataViewColumn* dataViewColumnPtr) { + DataBrowserPropertyID NewPropertyID; + + wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast(this->m_peer)); + + // first, some error checking: + wxCHECK_MSG(MacDataViewListCtrlPtr != NULL, false,_("m_peer is not or incorrectly initialized")); wxCHECK_MSG(dataViewColumnPtr != NULL, false,_("Column pointer must not be NULL.")); wxCHECK_MSG(dataViewColumnPtr->GetRenderer() != NULL, false,_("Column does not have a renderer.")); wxCHECK_MSG(this->GetModel() != NULL, false,_("No model associated with control.")); wxCHECK_MSG((dataViewColumnPtr->GetModelColumn() >= 0) && (dataViewColumnPtr->GetModelColumn() < this->GetModel()->GetColumnCount()),false,_("Column's model column has no equivalent in the associated model.")); - if (this->wxDataViewCtrlBase::AppendColumn(dataViewColumnPtr)) + if ((MacDataViewListCtrlPtr->GetFreePropertyID(&NewPropertyID) == noErr) && this->wxDataViewCtrlBase::AppendColumn(dataViewColumnPtr)) { + // insert column into hash map: + this->m_ColumnPointers.insert(ColumnPointerHashMapType::value_type(NewPropertyID,dataViewColumnPtr)); + // variable definitions: - DataBrowserPropertyID NewPropertyID; - DataBrowserListViewColumnDesc columnDescription; - wxMacCFStringHolder cfTitle(dataViewColumnPtr->GetTitle(),(this->m_font.Ok() ? this->m_font.GetEncoding() : wxLocale::GetSystemEncoding())); - wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast(this->m_peer)); + DataBrowserListViewColumnDesc columnDescription; + wxMacCFStringHolder cfTitle(dataViewColumnPtr->GetTitle(),(this->m_font.Ok() ? this->m_font.GetEncoding() : wxLocale::GetSystemEncoding())); // initialize column description: - wxCHECK_MSG(MacDataViewListCtrlPtr != NULL, false,_("m_peer is not or incorrectly initialized")); - wxCHECK_MSG(MacDataViewListCtrlPtr->GetFreePropertyID(&NewPropertyID) == noErr,false,_("Maximum number of columns reached.")); dataViewColumnPtr->SetPropertyID(NewPropertyID); - if (dataViewColumnPtr->GetWidth() <= 0) - dataViewColumnPtr->SetWidth(wxDVC_DEFAULT_WIDTH); columnDescription.propertyDesc.propertyID = NewPropertyID; columnDescription.propertyDesc.propertyType = dataViewColumnPtr->GetRenderer()->GetPropertyType(); columnDescription.propertyDesc.propertyFlags = kDataBrowserListViewSelectionColumn; // make the column selectable @@ -735,7 +779,7 @@ bool wxDataViewCtrl::AppendColumn(wxDataViewColumn* dataViewColumnPtr) columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewNoGapForIconInHeaderButton; #endif columnDescription.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc; - if (dataViewColumnPtr->IsResizable()) + if (dataViewColumnPtr->IsResizeable()) { columnDescription.headerBtnDesc.minimumWidth = 0; columnDescription.headerBtnDesc.maximumWidth = 30000; @@ -775,17 +819,15 @@ bool wxDataViewCtrl::AppendColumn(wxDataViewColumn* dataViewColumnPtr) // final adjustments for the layout: wxCHECK_MSG(MacDataViewListCtrlPtr->SetColumnWidth(NewPropertyID,dataViewColumnPtr->GetWidth()) == noErr,false,_("Column width could not be set.")); -#if 0 - if (dataViewColumnPtr->IsSortable()) // if the current column is marked sortable this column will become the active sortable column, otherwise don't do anything - MacDataViewListCtrlPtr->SetSortProperty(NewPropertyID); -#endif - if (dataViewColumnPtr == this->GetExpanderColumn()) // if the current column is marked expandable this column will become the active expandable column - MacDataViewListCtrlPtr->SetDisclosureColumn(NewPropertyID,true); // make sure that the data is up-to-date... - // if the newly appended column is the first column add the initial data to the control otherwise ask the control to 'update' the data in the newly appended column: + // if the newly appended column is the first column add the initial data to the control and mark the column as an expander column, + // otherwise ask the control to 'update' the data in the newly appended column: if (this->GetColumnCount() == 1) + { + this->SetExpanderColumn(dataViewColumnPtr); this->AddChildrenLevel(wxDataViewItem()); + } /* if */ else MacDataViewListCtrlPtr->UpdateItems(kDataBrowserNoItem,0,NULL,kDataBrowserItemNoProperty,NewPropertyID); // done: @@ -795,16 +837,82 @@ bool wxDataViewCtrl::AppendColumn(wxDataViewColumn* dataViewColumnPtr) return false; } /* wxDataViewCtrl::AppendColumn(wxDataViewColumn*) */ -bool wxDataViewCtrl::AssociateModel(wxDataViewModel* model) +bool wxDataViewCtrl::ClearColumns(void) { - if (!wxDataViewCtrlBase::AssociateModel(model)) + wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast(this->m_peer)); + + + while (this->m_ColumnPointers.begin() != this->m_ColumnPointers.end()) + { + wxCHECK_MSG(MacDataViewListCtrlPtr->RemoveColumnByProperty(this->m_ColumnPointers.begin()->first) == noErr,false,_("Could not remove column.")); + delete this->m_ColumnPointers.begin()->second; + this->m_ColumnPointers.erase(this->m_ColumnPointers.begin()); + } /* while */ + return true; +} /* wxDataViewCtrl::ClearColumns(void) */ + +bool wxDataViewCtrl::DeleteColumn(wxDataViewColumn* columnPtr) +{ + wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast(this->m_peer)); + + + if ((MacDataViewListCtrlPtr->RemoveColumnByProperty(columnPtr->GetPropertyID()) == noErr) && (this->m_ColumnPointers.erase(columnPtr->GetPropertyID()) > 0)) + { + delete columnPtr; + return true; + } /* if */ + else return false; +} /* wxDataViewCtrl::DeleteColumn(wxDataViewColumn*) */ + +wxDataViewColumn* wxDataViewCtrl::GetColumn(unsigned int pos) const +{ + DataBrowserPropertyID propertyID; - this->m_NotifierPtr = new wxMacDataViewModelNotifier(dynamic_cast(this->m_peer)); - model->AddNotifier(this->m_NotifierPtr); + wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast(this->m_peer)); - return true; -} /* wxDataViewCtrl::AssociateModel(wxDataViewModel*) */ + + if (MacDataViewListCtrlPtr->GetPropertyID(pos,&propertyID) == noErr) + { + // variable definition: + ColumnPointerHashMapType::const_iterator Result(this->m_ColumnPointers.find(propertyID)); + + if (Result != this->m_ColumnPointers.end()) + return Result->second; + else + return NULL; + } /* if */ + else + return NULL; +} /* wxDataViewCtrl::GetColumn(unsigned int pos) const */ + +unsigned int wxDataViewCtrl::GetColumnCount(void) const +{ + return this->m_ColumnPointers.size(); +} /* wxDataViewCtrl::GetColumnCount(void) const */ + +int wxDataViewCtrl::GetColumnPosition(wxDataViewColumn const* columnPtr) const +{ + if (columnPtr != NULL) + { + // variable definition and initialization: + DataBrowserTableViewColumnIndex Position; + wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast(this->m_peer)); + + wxCHECK_MSG(MacDataViewListCtrlPtr->GetColumnIndex(columnPtr->GetPropertyID(),&Position) == noErr,-1,_("Could not determine column's position")); + return static_cast(Position); + } /* if */ + else + return wxNOT_FOUND; +} /* wxDataViewCtrl::GetColumnPosition(wxDataViewColumn const*) const */ + +void wxDataViewCtrl::Collapse(wxDataViewItem const& item) +{ + wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast(this->m_peer)); + + + MacDataViewListCtrlPtr->CloseContainer(reinterpret_cast(item.GetID())); +} /* wxDataViewCtrl::Collapse(wxDataViewItem const&) */ void wxDataViewCtrl::EnsureVisible(wxDataViewItem const& item, wxDataViewColumn const* columnPtr) { @@ -822,6 +930,36 @@ void wxDataViewCtrl::EnsureVisible(wxDataViewItem const& item, wxDataViewColumn } /* if */ } /* wxDataViewCtrl::EnsureVisible(wxDataViewItem const&, wxDataViewColumn const*) */ +void wxDataViewCtrl::Expand(wxDataViewItem const& item) +{ + wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast(this->m_peer)); + + + MacDataViewListCtrlPtr->OpenContainer(reinterpret_cast(item.GetID())); +} /* wxDataViewCtrl::Expand(wxDataViewItem const&) */ + +wxDataViewColumn* wxDataViewCtrl::GetSortingColumn(void) const +{ + DataBrowserPropertyID propertyID; + + wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast(this->m_peer)); + + + if (MacDataViewListCtrlPtr->GetSortProperty(&propertyID) == noErr) + return this->GetColumnPtr(propertyID); + else + return NULL; +} /* wxDataViewCtrl::GetSortingColumn(void) const */ + +unsigned int wxDataViewCtrl::GetCount(void) const +{ + ItemCount noOfItems; + + + wxCHECK_MSG(dynamic_cast(this->m_peer)->GetItemCount(&noOfItems) == noErr,0,_("Could not determine number of items")); + return noOfItems; +} /* wxDataViewCtrl::GetCount(void) const */ + wxRect wxDataViewCtrl::GetItemRect(wxDataViewItem const& item, wxDataViewColumn const* columnPtr) const { if (item.IsOk() && (columnPtr != NULL)) @@ -972,35 +1110,47 @@ void wxDataViewCtrl::UnselectAll(void) // data handling: void wxDataViewCtrl::AddChildrenLevel(wxDataViewItem const& parentItem) { - wxDataViewItem item; + int NoOfChildren; + + wxDataViewItemArray items; wxCHECK_RET(this->GetModel() != NULL,_("Model pointer not initialized.")); - item = this->GetModel()->GetFirstChild(parentItem); - while (item.IsOk()) - { - (void) this->GetModel()->ItemAdded(parentItem,item); - item = this->GetModel()->GetNextSibling(item); - } /* while */ + NoOfChildren = this->GetModel()->GetChildren(parentItem,items); + for (int i=0; iGetModel()->ItemAdded(parentItem,items[i]); } /* wxDataViewCtrl::AddChildrenLevel(wxDataViewItem const&) */ +wxDataViewColumn* wxDataViewCtrl::GetColumnPtr(DataBrowserPropertyID propertyID) const +{ + // variable definition: + ColumnPointerHashMapType::const_iterator Result(this->m_ColumnPointers.find(propertyID)); + + if (Result != this->m_ColumnPointers.end()) + return Result->second; + else + return NULL; +} /* wxDataViewCtrl::GetColumnPtr(DataBrowserPropertyID) const */ + // inherited methods from wxDataViewCtrlBase void wxDataViewCtrl::DoSetExpanderColumn(void) { - if (this->GetExpanderColumn() < this->GetColumnCount()) + if (this->GetExpanderColumn() != NULL) { // variable definition and initialization: - DataBrowserPropertyID propertyID; wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast(this->m_peer)); - if (MacDataViewListCtrlPtr->GetPropertyID(this->GetExpanderColumn(),&propertyID) == noErr) - (void) MacDataViewListCtrlPtr->SetDisclosureColumn(propertyID); + (void) MacDataViewListCtrlPtr->SetDisclosureColumn(this->GetExpanderColumn()->GetPropertyID()); } /* if */ } /* wxDataViewCtrl::DoSetExpanderColumn(void) */ void wxDataViewCtrl::DoSetIndent(void) { -} /* wxDataViewCtrl::DoSetExpanderColumn(void) */ + wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast(this->m_peer)); + + + (void) MacDataViewListCtrlPtr->SetIndent(static_cast(this->GetIndent())); +} /* wxDataViewCtrl::DoSetIndent(void) */ // event handling: void wxDataViewCtrl::OnSize(wxSizeEvent& event)