X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e86edab05be77792498289f0605b49629bb912af..29686ebc000a1d95ae56a58b9ff2a5a6f23eed84:/src/osx/dataview_osx.cpp diff --git a/src/osx/dataview_osx.cpp b/src/osx/dataview_osx.cpp index 7fd68d183c..2886e17934 100644 --- a/src/osx/dataview_osx.cpp +++ b/src/osx/dataview_osx.cpp @@ -2,7 +2,7 @@ // Name: src/osx/dataview_osx.cpp // Purpose: wxDataViewCtrl native mac implementation // Author: -// Id: $Id: dataview_osx.cpp 58317 2009-01-27 +// Id: $Id$ // Copyright: (c) 2009 // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -12,7 +12,6 @@ #if (wxUSE_DATAVIEWCTRL != 0) && (!defined(wxUSE_GENERICDATAVIEWCTRL) || (wxUSE_GENERICDATAVIEWCTRL == 0)) -#include #include #ifndef WX_PRECOMP @@ -21,6 +20,9 @@ #include "wx/dcclient.h" #include "wx/icon.h" #endif +#if wxOSX_USE_CARBON +#include "wx/osx/carbon/dataview.h" +#endif #include "wx/osx/core/dataview.h" #include "wx/osx/private.h" @@ -38,7 +40,7 @@ wxString ConcatenateDataViewItemValues(wxDataViewCtrl const* dataViewCtrlPtr, wx { // variable definition: wxVariant dataValue; - + dataViewCtrlPtr->GetModel()->GetValue(dataValue,dataViewItem,dataViewCtrlPtr->GetColumn(i)->GetModelColumn()); if (i > 0) dataString << wxT('\t'); @@ -77,6 +79,8 @@ protected: void AdjustRowHeight(wxDataViewItem const& item); // ... and the same method for a couple of items: void AdjustRowHeights(wxDataViewItemArray const& items); + // adjust wxCOL_WIDTH_AUTOSIZE columns to fit the data + void AdjustAutosizedColumns(); private: wxDataViewCtrl* m_DataViewCtrlPtr; @@ -89,7 +93,7 @@ wxOSXDataViewModelNotifier::wxOSXDataViewModelNotifier(wxDataViewCtrl* initDataV :m_DataViewCtrlPtr(initDataViewCtrlPtr) { if (initDataViewCtrlPtr == NULL) - wxFAIL_MSG(_("Pointer to dataview control must not be NULL")); + wxFAIL_MSG("Pointer to dataview control must not be NULL"); } bool wxOSXDataViewModelNotifier::ItemAdded(wxDataViewItem const& parent, wxDataViewItem const& item) @@ -97,9 +101,9 @@ bool wxOSXDataViewModelNotifier::ItemAdded(wxDataViewItem const& parent, wxDataV bool noFailureFlag; - wxCHECK_MSG(item.IsOk(),false,_("Added item is invalid.")); - noFailureFlag = this->m_DataViewCtrlPtr->GetDataViewPeer()->Add(parent,item); - this->AdjustRowHeight(item); + wxCHECK_MSG(item.IsOk(),false,"Added item is invalid."); + noFailureFlag = m_DataViewCtrlPtr->GetDataViewPeer()->Add(parent,item); + AdjustRowHeight(item); return noFailureFlag; } @@ -109,28 +113,29 @@ bool wxOSXDataViewModelNotifier::ItemsAdded(wxDataViewItem const& parent, wxData // insert all valid items into control: - noFailureFlag = this->m_DataViewCtrlPtr->GetDataViewPeer()->Add(parent,items); + noFailureFlag = m_DataViewCtrlPtr->GetDataViewPeer()->Add(parent,items); // adjust row heights: - this->AdjustRowHeights(items); + AdjustRowHeights(items); // done: return noFailureFlag; } bool wxOSXDataViewModelNotifier::ItemChanged(wxDataViewItem const& item) { - wxCHECK_MSG(item.IsOk(), false,_("Changed item is invalid.")); - wxCHECK_MSG(this->GetOwner() != NULL,false,_("Owner not initialized.")); - if (this->m_DataViewCtrlPtr->GetDataViewPeer()->Update(this->GetOwner()->GetParent(item),item)) + wxCHECK_MSG(item.IsOk(), false,"Changed item is invalid."); + wxCHECK_MSG(GetOwner() != NULL,false,"Owner not initialized."); + if (m_DataViewCtrlPtr->GetDataViewPeer()->Update(GetOwner()->GetParent(item),item)) { // sent the equivalent wxWidget event: - wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED,this->m_DataViewCtrlPtr->GetId()); + wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED,m_DataViewCtrlPtr->GetId()); - dataViewEvent.SetEventObject(this->m_DataViewCtrlPtr); + dataViewEvent.SetEventObject(m_DataViewCtrlPtr); dataViewEvent.SetItem(item); // sent the equivalent wxWidget event: - this->m_DataViewCtrlPtr->HandleWindowEvent(dataViewEvent); + m_DataViewCtrlPtr->HandleWindowEvent(dataViewEvent); // row height may have to be adjusted: - this->AdjustRowHeight(item); + AdjustRowHeight(item); + AdjustAutosizedColumns(); // done return true; } @@ -142,21 +147,22 @@ bool wxOSXDataViewModelNotifier::ItemsChanged(wxDataViewItemArray const& items) { size_t const noOfItems = items.GetCount(); - wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED,this->m_DataViewCtrlPtr->GetId()); + wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED,m_DataViewCtrlPtr->GetId()); - dataViewEvent.SetEventObject(this->m_DataViewCtrlPtr); + dataViewEvent.SetEventObject(m_DataViewCtrlPtr); for (size_t indexItem=0; indexItemm_DataViewCtrlPtr->GetDataViewPeer()->Update(this->GetOwner()->GetParent(items[indexItem]),items[indexItem])) + if (m_DataViewCtrlPtr->GetDataViewPeer()->Update(GetOwner()->GetParent(items[indexItem]),items[indexItem])) { // send for all changed items a wxWidget event: dataViewEvent.SetItem(items[indexItem]); - this->m_DataViewCtrlPtr->HandleWindowEvent(dataViewEvent); + m_DataViewCtrlPtr->HandleWindowEvent(dataViewEvent); } else return false; // if this location is reached all items have been updated: - this->AdjustRowHeights(items); + AdjustRowHeights(items); + AdjustAutosizedColumns(); // done: return true; } @@ -166,15 +172,17 @@ bool wxOSXDataViewModelNotifier::ItemDeleted(wxDataViewItem const& parent, wxDat bool noFailureFlag; - wxCHECK_MSG(item.IsOk(),false,_("To be deleted item is invalid.")); + wxCHECK_MSG(item.IsOk(),false,"To be deleted item is invalid."); // when this method is called and currently an item is being edited this item may have already been deleted in the model (the passed item and the being edited item have // not to be identical because the being edited item might be below the passed item in the hierarchy); // to prevent the control trying to ask the model to update an already deleted item the control is informed that currently a deleting process // has been started and that variables can currently not be updated even when requested by the system: - this->m_DataViewCtrlPtr->SetDeleting(true); - noFailureFlag = this->m_DataViewCtrlPtr->GetDataViewPeer()->Remove(parent,item); + m_DataViewCtrlPtr->SetDeleting(true); + noFailureFlag = m_DataViewCtrlPtr->GetDataViewPeer()->Remove(parent,item); // enable automatic updating again: - this->m_DataViewCtrlPtr->SetDeleting(false); + m_DataViewCtrlPtr->SetDeleting(false); + + AdjustAutosizedColumns(); // done: return noFailureFlag; } @@ -188,28 +196,32 @@ bool wxOSXDataViewModelNotifier::ItemsDeleted(wxDataViewItem const& parent, wxDa // not to be identical because the being edited item might be below the passed item in the hierarchy); // to prevent the control trying to ask the model to update an already deleted item the control is informed that currently a deleting process // has been started and that variables can currently not be updated even when requested by the system: - this->m_DataViewCtrlPtr->SetDeleting(true); + m_DataViewCtrlPtr->SetDeleting(true); // delete all specified items: - noFailureFlag = this->m_DataViewCtrlPtr->GetDataViewPeer()->Remove(parent,items); + noFailureFlag = m_DataViewCtrlPtr->GetDataViewPeer()->Remove(parent,items); // enable automatic updating again: - this->m_DataViewCtrlPtr->SetDeleting(false); + m_DataViewCtrlPtr->SetDeleting(false); + + AdjustAutosizedColumns(); // done: return noFailureFlag; } bool wxOSXDataViewModelNotifier::ValueChanged(wxDataViewItem const& item, unsigned int col) { - wxCHECK_MSG(item.IsOk(), false,_("Passed item is invalid.")); - wxCHECK_MSG(this->GetOwner() != NULL,false,_("Owner not initialized.")); - if (this->m_DataViewCtrlPtr->GetDataViewPeer()->Update(this->GetOwner()->GetParent(item),item)) + wxCHECK_MSG(item.IsOk(), false,"Passed item is invalid."); + wxCHECK_MSG(GetOwner() != NULL,false,"Owner not initialized."); + if (m_DataViewCtrlPtr->GetDataViewPeer()->Update(GetOwner()->GetParent(item),item)) { - wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED,this->m_DataViewCtrlPtr->GetId()); + wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED,m_DataViewCtrlPtr->GetId()); - dataViewEvent.SetEventObject(this->m_DataViewCtrlPtr); + dataViewEvent.SetEventObject(m_DataViewCtrlPtr); dataViewEvent.SetColumn(col); dataViewEvent.SetItem(item); // send the equivalent wxWidget event: - this->m_DataViewCtrlPtr->HandleWindowEvent(dataViewEvent); + m_DataViewCtrlPtr->HandleWindowEvent(dataViewEvent); + + AdjustAutosizedColumns(); // done return true; } @@ -219,27 +231,27 @@ bool wxOSXDataViewModelNotifier::ValueChanged(wxDataViewItem const& item, unsign bool wxOSXDataViewModelNotifier::Cleared() { - return this->m_DataViewCtrlPtr->GetDataViewPeer()->Reload(); + return m_DataViewCtrlPtr->GetDataViewPeer()->Reload(); } void wxOSXDataViewModelNotifier::Resort() { - this->m_DataViewCtrlPtr->GetDataViewPeer()->Resort(); + m_DataViewCtrlPtr->GetDataViewPeer()->Resort(); } void wxOSXDataViewModelNotifier::AdjustRowHeight(wxDataViewItem const& item) { - if ((this->m_DataViewCtrlPtr->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT) != 0) + if ((m_DataViewCtrlPtr->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT) != 0) { - wxDataViewModel *model = this->GetOwner(); + wxDataViewModel *model = GetOwner(); int height = 20; // TODO find out standard height - unsigned int num = this->m_DataViewCtrlPtr->GetColumnCount(); + unsigned int num = m_DataViewCtrlPtr->GetColumnCount(); unsigned int col; for (col = 0; col < num; col++) { - wxDataViewColumn* column(this->m_DataViewCtrlPtr->GetColumnPtr(col)); - + wxDataViewColumn* column(m_DataViewCtrlPtr->GetColumnPtr(col)); + if (!(column->IsHidden())) { wxDataViewCustomRenderer *renderer = dynamic_cast(column->GetRenderer()); @@ -253,28 +265,28 @@ void wxOSXDataViewModelNotifier::AdjustRowHeight(wxDataViewItem const& item) } } if (height > 20) - this->m_DataViewCtrlPtr->GetDataViewPeer()->SetRowHeight(item,height); + m_DataViewCtrlPtr->GetDataViewPeer()->SetRowHeight(item,height); } } void wxOSXDataViewModelNotifier::AdjustRowHeights(wxDataViewItemArray const& items) { - if ((this->m_DataViewCtrlPtr->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT) != 0) + if ((m_DataViewCtrlPtr->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT) != 0) { size_t const noOfItems = items.GetCount(); - wxDataViewModel *model = this->GetOwner(); + wxDataViewModel *model = GetOwner(); for (size_t itemIndex=0; itemIndexm_DataViewCtrlPtr->GetColumnCount(); + unsigned int num = m_DataViewCtrlPtr->GetColumnCount(); unsigned int col; for (col = 0; col < num; col++) { - wxDataViewColumn* column(this->m_DataViewCtrlPtr->GetColumnPtr(col)); - + wxDataViewColumn* column(m_DataViewCtrlPtr->GetColumnPtr(col)); + if (!(column->IsHidden())) { wxDataViewCustomRenderer *renderer = dynamic_cast(column->GetRenderer()); @@ -288,36 +300,39 @@ void wxOSXDataViewModelNotifier::AdjustRowHeights(wxDataViewItemArray const& ite } } if (height > 20) - this->m_DataViewCtrlPtr->GetDataViewPeer()->SetRowHeight(items[itemIndex],height); + m_DataViewCtrlPtr->GetDataViewPeer()->SetRowHeight(items[itemIndex],height); } } } +void wxOSXDataViewModelNotifier::AdjustAutosizedColumns() +{ + unsigned count = m_DataViewCtrlPtr->GetColumnCount(); + for ( unsigned col = 0; col < count; col++ ) + { + wxDataViewColumn *column = m_DataViewCtrlPtr->GetColumnPtr(col); + + if ( column->GetWidthVariable() == wxCOL_WIDTH_AUTOSIZE ) + m_DataViewCtrlPtr->GetDataViewPeer()->FitColumnWidthToContent(col); + } +} + // --------------------------------------------------------- // wxDataViewCustomRenderer // The constructor, the implementation macro and environment // dependent methods can be found in the environment's // source file. // --------------------------------------------------------- -wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void) +wxDataViewCustomRenderer::~wxDataViewCustomRenderer() { - delete this->m_DCPtr; -} - -void wxDataViewCustomRenderer::RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state ) -{ - wxDataViewCtrl *view = GetOwner()->GetOwner(); - - wxColour col = (state & wxDATAVIEW_CELL_SELECTED) ? *wxWHITE : view->GetForegroundColour(); - dc->SetTextForeground(col); - dc->DrawText( text, cell.x + xoffset, cell.y + ((cell.height - dc->GetCharHeight()) / 2)); + delete m_DCPtr; } wxDC* wxDataViewCustomRenderer::GetDC() { - if ((this->m_DCPtr == NULL) && (this->GetOwner() != NULL) && (this->GetOwner()->GetOwner() != NULL)) - this->m_DCPtr = new wxClientDC(this->GetOwner()->GetOwner()); - return this->m_DCPtr; + if ((m_DCPtr == NULL) && (GetOwner() != NULL) && (GetOwner()->GetOwner() != NULL)) + m_DCPtr = new wxClientDC(GetOwner()->GetOwner()); + return m_DCPtr; } void wxDataViewCustomRenderer::SetDC(wxDC* newDCPtr) @@ -326,50 +341,46 @@ void wxDataViewCustomRenderer::SetDC(wxDC* newDCPtr) m_DCPtr = newDCPtr; } -// --------------------------------------------------------- -// wxDataViewTextRendererAttr -// --------------------------------------------------------- -wxDataViewTextRendererAttr::wxDataViewTextRendererAttr(wxString const& varianttype, wxDataViewCellMode mode, int align) - :wxDataViewTextRenderer(varianttype,mode,align) -{ -} - -IMPLEMENT_CLASS(wxDataViewTextRendererAttr,wxDataViewTextRenderer) - //----------------------------------------------------------------------------- // wxDataViewCtrl //----------------------------------------------------------------------------- wxDataViewCtrl::~wxDataViewCtrl() { - this->ClearColumns(); + ClearColumns(); } void wxDataViewCtrl::Init() { m_CustomRendererPtr = NULL; m_Deleting = false; - m_macIsUserPane = false; m_cgContext = NULL; } -bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator ) +bool wxDataViewCtrl::Create(wxWindow *parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + long style, + const wxValidator& validator, + const wxString& name) { - if (!(this->wxControl::Create(parent,id,pos,size,style & ~(wxHSCROLL | wxVSCROLL),validator))) + DontCreatePeer(); + if (!(wxControl::Create(parent,id,pos,size,style,validator,name))) return false; - m_peer = ::CreateDataView(this,parent,id,pos,size,style,this->GetExtraStyle()); + SetPeer(::CreateDataView(this,parent,id,pos,size,style,GetExtraStyle())); - this->MacPostControlCreate(pos,size); + MacPostControlCreate(pos,size); return true; } bool wxDataViewCtrl::AssociateModel(wxDataViewModel* model) { - wxDataViewWidgetImpl* dataViewWidgetPtr(this->GetDataViewPeer()); + wxDataViewWidgetImpl* dataViewWidgetPtr(GetDataViewPeer()); - wxCHECK_MSG(dataViewWidgetPtr != NULL,false,_("Pointer to native control must not be NULL.")); + wxCHECK_MSG(dataViewWidgetPtr != NULL,false,"Pointer to native control must not be NULL."); if (wxDataViewCtrlBase::AssociateModel(model) && dataViewWidgetPtr->AssociateModel(model)) { if (model != NULL) @@ -392,38 +403,37 @@ bool wxDataViewCtrl::PrependColumn(wxDataViewColumn* columnPtr) bool wxDataViewCtrl::InsertColumn(unsigned int pos, wxDataViewColumn* columnPtr) { - wxDataViewWidgetImpl* dataViewWidgetPtr(this->GetDataViewPeer()); + wxDataViewWidgetImpl* dataViewWidgetPtr(GetDataViewPeer()); // first, some error checking: - wxCHECK_MSG(dataViewWidgetPtr != NULL, false,_("Pointer to native control must not be NULL.")); - wxCHECK_MSG(columnPtr != NULL, false,_("Column pointer must not be NULL.")); - wxCHECK_MSG(columnPtr->GetRenderer() != NULL, false,_("Column does not have a renderer.")); - wxCHECK_MSG(this->GetModel() != NULL, false,_("No model associated with control.")); - wxCHECK_MSG((columnPtr->GetModelColumn() >= 0) && - (columnPtr->GetModelColumn() < this->GetModel()->GetColumnCount()),false,_("Column's model column has no equivalent in the associated model.")); + wxCHECK_MSG(dataViewWidgetPtr != NULL, false,"Pointer to native control must not be NULL."); + wxCHECK_MSG(columnPtr != NULL, false,"Column pointer must not be NULL."); + wxCHECK_MSG(columnPtr->GetRenderer() != NULL, false,"Column does not have a renderer."); + wxCHECK_MSG(GetModel() != NULL, false,"No model associated with control."); + wxCHECK_MSG(columnPtr->GetModelColumn() < GetModel()->GetColumnCount(),false,"Column's model column has no equivalent in the associated model."); // add column to wxWidget's internal structure: - if (this->wxDataViewCtrlBase::InsertColumn(pos,columnPtr)) + if (wxDataViewCtrlBase::InsertColumn(pos,columnPtr)) { - this->m_ColumnPtrs.Add(columnPtr); + m_ColumnPtrs.Add(columnPtr); // if the insertion in the native control is successful the rest can also be initialized: if (dataViewWidgetPtr->InsertColumn(pos,columnPtr)) { // 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 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(columnPtr); + if (GetColumnCount() == 1) + SetExpanderColumn(columnPtr); // done: return true; } else { // clean-up: - this->m_ColumnPtrs.Remove(columnPtr); + m_ColumnPtrs.Remove(columnPtr); delete columnPtr; // and send a message in debug mode: - wxFAIL_MSG(_("Column could not be added to native control.")); + wxFAIL_MSG("Column could not be added to native control."); // failed: return false; } @@ -432,7 +442,7 @@ bool wxDataViewCtrl::InsertColumn(unsigned int pos, wxDataViewColumn* columnPtr) { // clean-up: delete columnPtr; - wxFAIL_MSG(_("Could not add column to internal structures.")); + wxFAIL_MSG("Could not add column to internal structures."); // failed: return false; } @@ -440,9 +450,9 @@ bool wxDataViewCtrl::InsertColumn(unsigned int pos, wxDataViewColumn* columnPtr) bool wxDataViewCtrl::ClearColumns() { - if (this->GetDataViewPeer()->ClearColumns()) + if (GetDataViewPeer()->ClearColumns()) { - WX_CLEAR_ARRAY(this->m_ColumnPtrs); + WX_CLEAR_ARRAY(m_ColumnPtrs); return true; } else @@ -451,9 +461,9 @@ bool wxDataViewCtrl::ClearColumns() bool wxDataViewCtrl::DeleteColumn(wxDataViewColumn* columnPtr) { - if (this->GetDataViewPeer()->DeleteColumn(columnPtr)) + if (GetDataViewPeer()->DeleteColumn(columnPtr)) { - this->m_ColumnPtrs.Remove(columnPtr); + m_ColumnPtrs.Remove(columnPtr); delete columnPtr; return true; } @@ -463,99 +473,103 @@ bool wxDataViewCtrl::DeleteColumn(wxDataViewColumn* columnPtr) wxDataViewColumn* wxDataViewCtrl::GetColumn(unsigned int pos) const { - return this->GetDataViewPeer()->GetColumn(pos); + return GetDataViewPeer()->GetColumn(pos); } unsigned int wxDataViewCtrl::GetColumnCount() const { - return this->m_ColumnPtrs.GetCount(); + return m_ColumnPtrs.GetCount(); } int wxDataViewCtrl::GetColumnPosition(wxDataViewColumn const* columnPtr) const { - return this->GetDataViewPeer()->GetColumnPosition(columnPtr); + return GetDataViewPeer()->GetColumnPosition(columnPtr); } void wxDataViewCtrl::Collapse(wxDataViewItem const& item) { - this->GetDataViewPeer()->Collapse(item); + GetDataViewPeer()->Collapse(item); } void wxDataViewCtrl::EnsureVisible(wxDataViewItem const& item, wxDataViewColumn const* columnPtr) { if (item.IsOk()) { - this->ExpandAncestors(item); // make sure that the item exists in the control - this->GetDataViewPeer()->EnsureVisible(item,columnPtr); + ExpandAncestors(item); // make sure that the item exists in the control + GetDataViewPeer()->EnsureVisible(item,columnPtr); } } void wxDataViewCtrl::Expand(wxDataViewItem const& item) { - return this->GetDataViewPeer()->Expand(item); + return GetDataViewPeer()->Expand(item); } bool wxDataViewCtrl::IsExpanded( const wxDataViewItem & item ) const { - return (item.IsOk() && this->GetDataViewPeer()->IsExpanded(item)); + return (item.IsOk() && GetDataViewPeer()->IsExpanded(item)); } wxDataViewColumn* wxDataViewCtrl::GetSortingColumn() const { - return this->GetDataViewPeer()->GetSortingColumn(); + return GetDataViewPeer()->GetSortingColumn(); } unsigned int wxDataViewCtrl::GetCount() const { - return this->GetDataViewPeer()->GetCount(); + return GetDataViewPeer()->GetCount(); +} + +wxDataViewItem wxDataViewCtrl::DoGetCurrentItem() const +{ + return GetDataViewPeer()->GetCurrentItem(); +} + +void wxDataViewCtrl::DoSetCurrentItem(const wxDataViewItem& item) +{ + GetDataViewPeer()->SetCurrentItem(item); } wxRect wxDataViewCtrl::GetItemRect(wxDataViewItem const& item, wxDataViewColumn const* columnPtr) const { if (item.IsOk() && (columnPtr != NULL)) - return this->GetDataViewPeer()->GetRectangle(item,columnPtr); + return GetDataViewPeer()->GetRectangle(item,columnPtr); else return wxRect(); } -wxDataViewItem wxDataViewCtrl::GetSelection() const +int wxDataViewCtrl::GetSelectedItemsCount() const { - wxDataViewItemArray itemIDs; - - - if (this->GetDataViewPeer()->GetSelections(itemIDs) > 0) - return itemIDs[0]; - else - return wxDataViewItem(); + return GetDataViewPeer()->GetSelectedItemsCount(); } int wxDataViewCtrl::GetSelections(wxDataViewItemArray& sel) const { - return this->GetDataViewPeer()->GetSelections(sel); + return GetDataViewPeer()->GetSelections(sel); } void wxDataViewCtrl::HitTest(wxPoint const& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const { - return this->GetDataViewPeer()->HitTest(point,item,columnPtr); + return GetDataViewPeer()->HitTest(point,item,columnPtr); } bool wxDataViewCtrl::IsSelected(wxDataViewItem const& item) const { - return this->GetDataViewPeer()->IsSelected(item); + return GetDataViewPeer()->IsSelected(item); } void wxDataViewCtrl::Select(wxDataViewItem const& item) { if (item.IsOk()) { - this->ExpandAncestors(item); // make sure that the item exists in the control - this->GetDataViewPeer()->Select(item); + ExpandAncestors(item); // make sure that the item exists in the control + GetDataViewPeer()->Select(item); } } -void wxDataViewCtrl::SelectAll(void) +void wxDataViewCtrl::SelectAll() { - this->GetDataViewPeer()->SelectAll(); + GetDataViewPeer()->SelectAll(); } void wxDataViewCtrl::SetSelections(wxDataViewItemArray const& sel) @@ -571,15 +585,15 @@ void wxDataViewCtrl::SetSelections(wxDataViewItemArray const& sel) for (i = 0; i < noOfSelections; i++) { wxDataViewItem item = sel[i]; - wxDataViewItem parent = this->GetModel()->GetParent( item ); + wxDataViewItem parent = GetModel()->GetParent( item ); if (parent.IsOk() && (parent != last_parent)) - this->ExpandAncestors(item); + ExpandAncestors(item); last_parent = parent; } // finally select the items: - wxDataViewWidgetImpl* dataViewWidgetPtr(this->GetDataViewPeer()); // variable definition for abbreviational purposes + wxDataViewWidgetImpl* dataViewWidgetPtr(GetDataViewPeer()); // variable definition for abbreviational purposes for (i=0; iSelect(sel[i]); @@ -588,20 +602,20 @@ void wxDataViewCtrl::SetSelections(wxDataViewItemArray const& sel) void wxDataViewCtrl::Unselect(wxDataViewItem const& item) { if (item.IsOk()) - this->GetDataViewPeer()->Unselect(item); + GetDataViewPeer()->Unselect(item); } -void wxDataViewCtrl::UnselectAll(void) +void wxDataViewCtrl::UnselectAll() { - this->GetDataViewPeer()->UnselectAll(); + GetDataViewPeer()->UnselectAll(); } // // implementation // -wxDataViewWidgetImpl* wxDataViewCtrl::GetDataViewPeer(void) const +wxDataViewWidgetImpl* wxDataViewCtrl::GetDataViewPeer() const { - return dynamic_cast(this->GetPeer()); + return dynamic_cast(GetPeer()); } void wxDataViewCtrl::AddChildren(wxDataViewItem const& parentItem) @@ -611,29 +625,36 @@ void wxDataViewCtrl::AddChildren(wxDataViewItem const& parentItem) wxDataViewItemArray items; - wxCHECK_RET(this->GetModel() != NULL,_("Model pointer not initialized.")); - noOfChildren = this->GetModel()->GetChildren(parentItem,items); - (void) this->GetModel()->ItemsAdded(parentItem,items); + wxCHECK_RET(GetModel() != NULL,"Model pointer not initialized."); + noOfChildren = GetModel()->GetChildren(parentItem,items); + (void) GetModel()->ItemsAdded(parentItem,items); } -void wxDataViewCtrl::FinishCustomItemEditing(void) +void wxDataViewCtrl::StartEditor( const wxDataViewItem & item, unsigned int column ) { - if (this->GetCustomRendererItem().IsOk()) + GetDataViewPeer()->StartEditor(item, column); +} + +void wxDataViewCtrl::FinishCustomItemEditing() +{ + if (GetCustomRendererItem().IsOk()) { - this->GetCustomRendererPtr()->FinishEditing(); - this->SetCustomRendererItem(wxDataViewItem()); - this->SetCustomRendererPtr (NULL); + GetCustomRendererPtr()->FinishEditing(); + SetCustomRendererItem(wxDataViewItem()); + SetCustomRendererPtr (NULL); } } /*static*/ -wxVisualAttributes wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant variant) +wxVisualAttributes +wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) { wxVisualAttributes attr; attr.colFg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT ); attr.colBg = wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX ); - attr.font.MacCreateFromThemeFont(kThemeViewsFont); + static wxFont font = wxFont(wxOSX_SYSTEM_FONT_VIEWS); + attr.font = font; return attr; } @@ -641,25 +662,25 @@ wxVisualAttributes wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant var // inherited methods from wxDataViewCtrlBase void wxDataViewCtrl::DoSetExpanderColumn() { - if (this->GetExpanderColumn() != NULL) - this->GetDataViewPeer()->DoSetExpanderColumn(this->GetExpanderColumn()); + if (GetExpanderColumn() != NULL) + GetDataViewPeer()->DoSetExpanderColumn(GetExpanderColumn()); } void wxDataViewCtrl::DoSetIndent() { - this->GetDataViewPeer()->DoSetIndent(this->GetIndent()); + GetDataViewPeer()->DoSetIndent(GetIndent()); } // event handling: void wxDataViewCtrl::OnSize(wxSizeEvent& event) { - unsigned int const noOfColumns = this->GetColumnCount(); + unsigned int const noOfColumns = GetColumnCount(); // reset DC of all custom renderers because DC has changed: for (unsigned int i=0; iGetColumn(i)); + wxDataViewColumn* dataViewColumnPtr(GetColumn(i)); if (dataViewColumnPtr != NULL) { @@ -671,15 +692,75 @@ void wxDataViewCtrl::OnSize(wxSizeEvent& event) } // update the layout of the native control after a size event: - this->GetDataViewPeer()->OnSize(); + GetDataViewPeer()->OnSize(); event.Skip(); } +wxSize wxDataViewCtrl::DoGetBestSize() const +{ + wxSize best = wxControl::DoGetBestSize(); + best.y = 80; + + return best; +} + +void wxDataViewCtrl::OnMouse(wxMouseEvent& event) +{ + event.Skip(); + +#if wxOSX_USE_CARBON + if (GetModel() == NULL) + return; + + wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast(GetPeer())); + + int NoOfChildren; + wxDataViewItemArray items; + NoOfChildren = GetModel()->GetChildren( wxDataViewItem(), items); + if (NoOfChildren == 0) + return; + wxDataViewItem firstChild = items[0]; + + UInt16 headerHeight = 0; + MacDataViewListCtrlPtr->GetHeaderButtonHeight(&headerHeight); + + + if (event.GetY() < headerHeight) + { + unsigned int col_count = GetColumnCount(); + unsigned int col; + for (col = 0; col < col_count; col++) + { + wxDataViewColumn *column = GetColumn( col ); + if (column->IsHidden()) + continue; + + Rect itemrect; + ::GetDataBrowserItemPartBounds( MacDataViewListCtrlPtr->GetControlRef(), + reinterpret_cast(firstChild.GetID()), column->GetNativeData()->GetPropertyID(), + kDataBrowserPropertyEnclosingPart, &itemrect ); + + if (abs( event.GetX() - itemrect.right) < 3) + { + if (column->GetFlags() & wxDATAVIEW_COL_RESIZABLE) + SetCursor( wxCursor( wxCURSOR_SIZEWE ) ); + else + SetCursor( *wxSTANDARD_CURSOR ); + return; + } + } + + } + SetCursor( *wxSTANDARD_CURSOR ); +#endif +} + IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl,wxDataViewCtrlBase) BEGIN_EVENT_TABLE(wxDataViewCtrl,wxDataViewCtrlBase) EVT_SIZE(wxDataViewCtrl::OnSize) + EVT_MOTION(wxDataViewCtrl::OnMouse) END_EVENT_TABLE() #endif // (wxUSE_DATAVIEWCTRL != 0) && (!defined(wxUSE_GENERICDATAVIEWCTRL) || (wxUSE_GENERICDATAVIEWCTRL == 0))