#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"
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;
m_DataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
// row height may have to be adjusted:
AdjustRowHeight(item);
+ AdjustAutosizedColumns();
// done
return true;
}
return false;
// if this location is reached all items have been updated:
AdjustRowHeights(items);
+ AdjustAutosizedColumns();
// done:
return true;
}
noFailureFlag = m_DataViewCtrlPtr->GetDataViewPeer()->Remove(parent,item);
// enable automatic updating again:
m_DataViewCtrlPtr->SetDeleting(false);
+
+ AdjustAutosizedColumns();
// done:
return noFailureFlag;
}
noFailureFlag = m_DataViewCtrlPtr->GetDataViewPeer()->Remove(parent,items);
// enable automatic updating again:
m_DataViewCtrlPtr->SetDeleting(false);
+
+ AdjustAutosizedColumns();
// done:
return noFailureFlag;
}
dataViewEvent.SetItem(item);
// send the equivalent wxWidget event:
m_DataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
+
+ AdjustAutosizedColumns();
// done
return true;
}
}
}
+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
wxDataViewCtrl::~wxDataViewCtrl()
{
ClearColumns();
+
+ // Ensure that the already destructed controls is not notified about changes
+ // in the model any more.
+ if (m_ModelNotifier != NULL)
+ m_ModelNotifier->GetOwner()->RemoveNotifier(m_ModelNotifier);
}
void wxDataViewCtrl::Init()
{
m_CustomRendererPtr = NULL;
m_Deleting = false;
- m_macIsUserPane = false;
m_cgContext = NULL;
+ m_ModelNotifier = NULL;
}
bool wxDataViewCtrl::Create(wxWindow *parent,
const wxValidator& validator,
const wxString& name)
{
+ DontCreatePeer();
if (!(wxControl::Create(parent,id,pos,size,style,validator,name)))
return false;
- m_peer = ::CreateDataView(this,parent,id,pos,size,style,GetExtraStyle());
+ SetPeer(::CreateDataView(this,parent,id,pos,size,style,GetExtraStyle()));
MacPostControlCreate(pos,size);
wxCHECK_MSG(dataViewWidgetPtr != NULL,false,"Pointer to native control must not be NULL.");
+
+ // We could have been associated with another model previously, break the
+ // association in this case.
+ if ( m_ModelNotifier )
+ m_ModelNotifier->GetOwner()->RemoveNotifier(m_ModelNotifier);
+
if (wxDataViewCtrlBase::AssociateModel(model) && dataViewWidgetPtr->AssociateModel(model))
{
if (model != NULL)
- model->AddNotifier(new wxOSXDataViewModelNotifier(this));
+ {
+ m_ModelNotifier = new wxOSXDataViewModelNotifier(this);
+ model->AddNotifier(m_ModelNotifier);
+ }
return true;
}
else
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() >= 0) &&
- (columnPtr->GetModelColumn() < GetModel()->GetColumnCount()),false,"Column's model column has no equivalent in the associated model.");
+ 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 (wxDataViewCtrlBase::InsertColumn(pos,columnPtr))
GetDataViewPeer()->SetCurrentItem(item);
}
+wxDataViewColumn *wxDataViewCtrl::GetCurrentColumn() const
+{
+ return GetDataViewPeer()->GetCurrentColumn();
+}
+
wxRect wxDataViewCtrl::GetItemRect(wxDataViewItem const& item, wxDataViewColumn const* columnPtr) const
{
if (item.IsOk() && (columnPtr != NULL))
return wxRect();
}
-wxDataViewItem wxDataViewCtrl::GetSelection() const
+int wxDataViewCtrl::GetSelectedItemsCount() const
{
- wxDataViewItemArray itemIDs;
-
-
- if (GetDataViewPeer()->GetSelections(itemIDs) > 0)
- return itemIDs[0];
- else
- return wxDataViewItem();
+ return GetDataViewPeer()->GetSelectedItemsCount();
}
int wxDataViewCtrl::GetSelections(wxDataViewItemArray& sel) const
(void) GetModel()->ItemsAdded(parentItem,items);
}
+void wxDataViewCtrl::EditItem(const wxDataViewItem& item, const wxDataViewColumn *column)
+{
+ GetDataViewPeer()->StartEditor(item, GetColumnPosition(column));
+}
+
void wxDataViewCtrl::FinishCustomItemEditing()
{
if (GetCustomRendererItem().IsOk())
{
event.Skip();
+#if wxOSX_USE_CARBON
if (GetModel() == NULL)
return;
-#if 0
- // Doesn't compile anymore
- wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(m_peer));
+ wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(GetPeer()));
int NoOfChildren;
wxDataViewItemArray items;
Rect itemrect;
::GetDataBrowserItemPartBounds( MacDataViewListCtrlPtr->GetControlRef(),
- reinterpret_cast<DataBrowserItemID>(firstChild.GetID()), column->GetPropertyID(),
+ reinterpret_cast<DataBrowserItemID>(firstChild.GetID()), column->GetNativeData()->GetPropertyID(),
kDataBrowserPropertyEnclosingPart, &itemrect );
if (abs( event.GetX() - itemrect.right) < 3)
}
}
-
SetCursor( *wxSTANDARD_CURSOR );
#endif
}