// Name: src/osx/dataview_osx.cpp
// Purpose: wxDataViewCtrl native mac implementation
// Author:
-// Id: $Id: dataview_osx.cpp 58317 2009-01-27
// Copyright: (c) 2009
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#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(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)
bool noFailureFlag;
- wxCHECK_MSG(item.IsOk(),false,_("Added item is invalid."));
+ wxCHECK_MSG(item.IsOk(),false,"Added item is invalid.");
noFailureFlag = m_DataViewCtrlPtr->GetDataViewPeer()->Add(parent,item);
AdjustRowHeight(item);
return noFailureFlag;
bool wxOSXDataViewModelNotifier::ItemChanged(wxDataViewItem const& item)
{
- wxCHECK_MSG(item.IsOk(), false,_("Changed item is invalid."));
- wxCHECK_MSG(GetOwner() != NULL,false,_("Owner not initialized."));
+ 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,m_DataViewCtrlPtr->GetId());
+ wxDataViewEvent dataViewEvent(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED,m_DataViewCtrlPtr->GetId());
dataViewEvent.SetEventObject(m_DataViewCtrlPtr);
dataViewEvent.SetItem(item);
m_DataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
// row height may have to be adjusted:
AdjustRowHeight(item);
+ AdjustAutosizedColumns();
// done
return true;
}
{
size_t const noOfItems = items.GetCount();
- wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED,m_DataViewCtrlPtr->GetId());
+ wxDataViewEvent dataViewEvent(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED,m_DataViewCtrlPtr->GetId());
dataViewEvent.SetEventObject(m_DataViewCtrlPtr);
return false;
// if this location is reached all items have been updated:
AdjustRowHeights(items);
+ AdjustAutosizedColumns();
// done:
return true;
}
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
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;
}
bool wxOSXDataViewModelNotifier::ValueChanged(wxDataViewItem const& item, unsigned int col)
{
- wxCHECK_MSG(item.IsOk(), false,_("Passed item is invalid."));
- wxCHECK_MSG(GetOwner() != NULL,false,_("Owner not initialized."));
+ 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,m_DataViewCtrlPtr->GetId());
+ wxDataViewEvent dataViewEvent(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED,m_DataViewCtrlPtr->GetId());
dataViewEvent.SetEventObject(m_DataViewCtrlPtr);
dataViewEvent.SetColumn(col);
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
delete 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));
-}
-
wxDC* wxDataViewCustomRenderer::GetDC()
{
if ((m_DCPtr == NULL) && (GetOwner() != NULL) && (GetOwner()->GetOwner() != NULL))
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, 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 (!(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,GetExtraStyle());
+ SetPeer(::CreateDataView(this,parent,id,pos,size,style,GetExtraStyle()));
MacPostControlCreate(pos,size);
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.");
+
+ // 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
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(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(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 (wxDataViewCtrlBase::InsertColumn(pos,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;
}
{
// 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;
}
return GetDataViewPeer()->GetCount();
}
+wxDataViewItem wxDataViewCtrl::DoGetCurrentItem() const
+{
+ return GetDataViewPeer()->GetCurrentItem();
+}
+
+void wxDataViewCtrl::DoSetCurrentItem(const wxDataViewItem& item)
+{
+ 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
wxDataViewItemArray items;
- wxCHECK_RET(GetModel() != NULL,_("Model pointer not initialized."));
+ wxCHECK_RET(GetModel() != NULL,"Model pointer not initialized.");
noOfChildren = GetModel()->GetChildren(parentItem,items);
(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())
attr.colFg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
attr.colBg = wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX );
- attr.font.CreateSystemFont(wxOSX_SYSTEM_FONT_VIEWS);
+ static wxFont font = wxFont(wxOSX_SYSTEM_FONT_VIEWS);
+ attr.font = font;
return attr;
}
{
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
}