Applied Hartwig's implementation of OS X wxDataViewCtrl

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48052 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling 2007-08-13 15:56:28 +00:00
parent 967d3d9783
commit 194027acb3
4 changed files with 370 additions and 708 deletions

View File

@ -53,17 +53,16 @@ typedef SInt32 SRefCon;
#if wxUSE_GUI
#include "wx/hashmap.h"
#include "wx/mac/private.h"
WX_DEFINE_ARRAY_SIZE_T(size_t,wxArrayDataBrowserItemID);
// ============================================================================
// DataBrowser Wrapper
// wxMacDataBrowserTableViewControl
// ============================================================================
//
// basing on DataBrowserItemIDs
// this is a wrapper class for the Mac OS X data browser environment,
// it covers all general data brower functionality,
//
// data browser's property IDs have a reserved ID range from 0 - 1023
@ -127,18 +126,18 @@ public:
// column handling
//
OSStatus GetColumnCount (UInt32* numColumns) const;
OSStatus GetColumnID (DataBrowserTableViewColumnIndex position, DataBrowserTableViewColumnID* id);
OSStatus GetFreePropertyID(DataBrowserPropertyID* id) const; // this method returns a property id that is valid and currently not used; if it cannot be found 'errDataBrowerPropertyNotSupported' is returned
OSStatus GetPropertyColumn(DataBrowserPropertyID propertyID, DataBrowserTableViewColumnIndex* index) const;
OSStatus GetColumnIndex (DataBrowserPropertyID propertyID, DataBrowserTableViewColumnIndex* index) const; // returns for the passed property the corresponding column index
OSStatus GetFreePropertyID(DataBrowserPropertyID* propertyID) const; // this method returns a property id that is valid and currently not used; if it cannot be found 'errDataBrowerPropertyNotSupported' is returned
OSStatus GetPropertyFlags (DataBrowserPropertyID propertyID, DataBrowserPropertyFlags *flags ) const;
OSStatus GetPropertyID (DataBrowserTableViewColumnIndex index, DataBrowserTableViewColumnID* propertyId); // returns for the passed column index the corresponding property ID
OSStatus IsUsedPropertyID(DataBrowserPropertyID propertyID) const; // checks if passed property id is used by the control; no error is returned if the id exists
OSStatus RemoveColumn(DataBrowserTableViewColumnIndex position);
OSStatus RemoveColumn(DataBrowserTableViewColumnIndex index);
OSStatus SetColumnPosition (DataBrowserPropertyID column, DataBrowserTableViewColumnIndex position);
OSStatus SetDisclosureColumn(DataBrowserPropertyID property, Boolean expandableRows );
OSStatus SetPropertyFlags (DataBrowserPropertyID property, DataBrowserPropertyFlags flags );
OSStatus SetColumnIndex (DataBrowserPropertyID propertyID, DataBrowserTableViewColumnIndex index);
OSStatus SetDisclosureColumn(DataBrowserPropertyID propertyID, Boolean expandableRows=true);
OSStatus SetPropertyFlags (DataBrowserPropertyID propertyID, DataBrowserPropertyFlags flags);
//
// item handling
@ -199,10 +198,10 @@ public:
// item sorting
//
OSStatus GetSortOrder (DataBrowserSortOrder* order) const;
OSStatus GetSortProperty(DataBrowserPropertyID* column) const;
OSStatus GetSortProperty(DataBrowserPropertyID* propertyID) const;
OSStatus SetSortOrder (DataBrowserSortOrder order);
OSStatus SetSortProperty(DataBrowserPropertyID column);
OSStatus SetSortProperty(DataBrowserPropertyID propertyID);
protected :
//
@ -225,9 +224,14 @@ private:
};
// ============================================================================
// Databrowser class for the list view control
// wxMacDataBrowserListViewControl
// ============================================================================
//
// this class is a wrapper for a list view which incorporates all general
// data browser functionality of the inherited table view control class;
// the term list view is in this case Mac OS X specific and is not related
// to any wxWidget naming conventions
//
class wxMacDataBrowserListViewControl : public wxMacDataBrowserTableViewControl
{
public:
@ -249,39 +253,20 @@ private:
// ============================================================================
// Databrowser class for the data view list control model
// wxMacDataViewDataBrowserListViewControl
// ============================================================================
//
// internal interface class between wxDataViewCtrl (wxWidget) and the data
// browser (Mac OS X)
//
// Hash maps used by the data browser for the data view model
//
WX_DECLARE_HASH_MAP(DataBrowserItemID,unsigned long,wxIntegerHash,wxIntegerEqual,ItemIDRowNumberHashMap); // stores for each item ID the model's row number
class wxMacDataViewDataBrowserListViewControl : public wxMacDataBrowserListViewControl
{
public:
//
// constructors / destructor
//
wxMacDataViewDataBrowserListViewControl(wxWindow* peer, wxPoint const& pos, wxSize const& size, long style);
//
// item ID and model matching
//
void ClearItemIDRowPairs(void); // removes all ID row pairs
bool DeleteItemIDRowPair(DataBrowserItemID itemID); // if the id has been removed, 'true' is returned, 'false' is returned if the id did not exist or another error occurred
bool GetRowIndex(unsigned long& rowIndex, DataBrowserItemID itemID) const; // returns 'true' and the rowIndex if the id has been found in the map, otherwise 'false' is returned and rowIndex remains untouched
bool InsertItemIDRowPair(DataBrowserItemID itemID, unsigned long rowIndex); // the pair will only be inserted if the item ID does not exist before the call
void RenumberItemIDRowIndices (unsigned int* newIndices); // for each item ID - row index pair the row index is changed
void RenumberItemIDRowIndicesDeletion (unsigned long decreaseFromIndex); // decreases all row indices by one that are equal or larger than 'decreaseFromIndex'
void RenumberItemIDRowIndicesInsertion(unsigned long increaseFromIndex); // increases all row indices by one that are equal or larger than 'increaseFromIndex'
void ReverseRowIndexNumbering(void); // reverses the order of the indices
protected:
//
// callback functions (inherited from wxMacDataBrowserTableViewControl)
@ -292,10 +277,6 @@ protected:
virtual OSStatus DataBrowserGetSetItemDataProc (DataBrowserItemID itemID, DataBrowserPropertyID property, DataBrowserItemDataRef itemData, Boolean getValue);
private:
//
// variables
//
ItemIDRowNumberHashMap m_itemIDRowNumberMap; // contains for each data browser ID the corresponding line number in the model
};
typedef wxMacDataViewDataBrowserListViewControl* wxMacDataViewDataBrowserListViewControlPointer;

View File

@ -128,22 +128,22 @@ public:
//
virtual bool Render(wxRect cell, wxDC* dc, int state) = 0;
virtual bool Activate(wxRect WXUNUSED(cell), wxDataViewListModel *WXUNUSED(model), unsigned int WXUNUSED(col), unsigned int WXUNUSED(row))
virtual bool Activate(wxRect WXUNUSED(cell), wxDataViewModel *WXUNUSED(model), unsigned int WXUNUSED(col), unsigned int WXUNUSED(row))
{
return false;
}
virtual bool LeftClick(wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell), wxDataViewListModel *WXUNUSED(model), unsigned int WXUNUSED(col), unsigned int WXUNUSED(row))
virtual bool LeftClick(wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell), wxDataViewModel *WXUNUSED(model), unsigned int WXUNUSED(col), unsigned int WXUNUSED(row))
{
return false;
}
virtual bool RightClick(wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell), wxDataViewListModel *WXUNUSED(model), unsigned int WXUNUSED(col), unsigned int WXUNUSED(row))
virtual bool RightClick(wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell), wxDataViewModel *WXUNUSED(model), unsigned int WXUNUSED(col), unsigned int WXUNUSED(row))
{
return false;
}
virtual bool StartDrag(wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell), wxDataViewListModel *WXUNUSED(model), unsigned int WXUNUSED(col), unsigned int WXUNUSED(row))
virtual bool StartDrag(wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell), wxDataViewModel *WXUNUSED(model), unsigned int WXUNUSED(col), unsigned int WXUNUSED(row))
{
return false;
}
@ -471,47 +471,44 @@ private:
// ---------------------------------------------------------
// wxDataViewCtrl
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase
{
public:
// Constructors / destructor:
wxDataViewCtrl()
{
this->Init();
}
wxDataViewCtrl(wxWindow *parent, wxWindowID id, wxPoint const& pos = wxDefaultPosition, wxSize const& size = wxDefaultSize, long style = 0,
wxValidator const& validator = wxDefaultValidator)
{
this->Init();
this->Create(parent, id, pos, size, style, validator );
}
wxDataViewCtrl()
{
this->Init();
}
wxDataViewCtrl(wxWindow *parent, wxWindowID id, wxPoint const& pos = wxDefaultPosition, wxSize const& size = wxDefaultSize, long style = 0,
wxValidator const& validator = wxDefaultValidator)
{
this->Init();
this->Create(parent, id, pos, size, style, validator );
}
bool Create(wxWindow *parent, wxWindowID id, wxPoint const& pos=wxDefaultPosition, wxSize const& size=wxDefaultSize, long style=0,
wxValidator const& validator=wxDefaultValidator);
// explicit control creation
bool Create(wxWindow *parent, wxWindowID id, wxPoint const& pos=wxDefaultPosition, wxSize const& size=wxDefaultSize, long style=0,
wxValidator const& validator=wxDefaultValidator);
virtual bool AppendColumn(wxDataViewColumn* columnPtr);
// inherited methods from 'wxDataViewCtrlBase':
virtual bool AppendColumn(wxDataViewColumn* columnPtr);
virtual bool AssociateModel(wxDataViewListModel* model);
virtual bool AssociateModel(wxDataViewModel* model);
virtual void SetSelection( int row ); // -1 for unselect
virtual void SetSelectionRange( unsigned int from, unsigned int to );
virtual void SetSelections( const wxArrayInt& aSelections);
virtual void Unselect( unsigned int row );
virtual bool IsSelected( unsigned int row ) const;
virtual int GetSelection() const;
virtual int GetSelections(wxArrayInt& aSelections) const;
virtual wxControl* GetMainWindow(void) // should disappear as it is not of any use for the native implementation
{
return this;
}
virtual wxControl* GetMainWindow(void) // should disappear as it is not of any use for the native implementation
{
return this;
}
virtual wxDataViewItem GetSelection(void);
//
// implementation
//
// adds all children of the passed parent to the control; if 'parentItem' is invalid the root(s) is/are added:
void AddChildrenLevel(wxDataViewItem const& parentItem);
// with CG, we need to get the context from an kEventControlDraw event
// unfortunately, the DataBrowser callbacks don't provide the context
// and we need it, so we need to set/remove it before and after draw
@ -525,11 +522,11 @@ public:
return this->m_cgContext;
}
// reverts the sorting order of the hash map if wxDataViewColumn data and control data do not match;
// wxDataViewColumn data will NOT be updated
void ReverseSorting(DataBrowserPropertyID columnID);
protected:
// inherited methods from wxDataViewCtrlBase:
virtual void DoSetExpanderColumn(void);
virtual void DoSetIndent(void);
// event handling:
void OnSize(wxSizeEvent &event);
@ -541,7 +538,7 @@ private:
// variables
//
wxDataViewListModelNotifier* m_NotifierPtr; // the notifier is NOT owned by this class but by the associated model
wxDataViewModelNotifier* m_NotifierPtr; // the notifier is NOT owned by this class but by the associated model
void* m_cgContext; // pointer to core graphics context

View File

@ -56,11 +56,8 @@
#include "wx/dataview.h"
// ============================================================================
// DataBrowser Wrapper
// wxMacDataBrowserTableViewControl
// ============================================================================
//
// basing on DataBrowserItemIDs
//
pascal Boolean wxMacDataBrowserTableViewControl::DataBrowserCompareProc(ControlRef browser, DataBrowserItemID itemOneID, DataBrowserItemID itemTwoID, DataBrowserPropertyID sortProperty)
{
@ -219,24 +216,24 @@ OSStatus wxMacDataBrowserTableViewControl::GetAttributes(OptionBits* attributes)
} /* wxMacDataBrowserTableViewControl::GetAttributes(OptionBits*) */
#endif
OSStatus wxMacDataBrowserTableViewControl::GetColumnWidth( DataBrowserPropertyID column , UInt16 *width ) const
OSStatus wxMacDataBrowserTableViewControl::GetColumnWidth(DataBrowserPropertyID propertyID, UInt16* width) const
{
return GetDataBrowserTableViewNamedColumnWidth( m_controlRef , column , width );
return ::GetDataBrowserTableViewNamedColumnWidth(this->m_controlRef,propertyID,width);
}
OSStatus wxMacDataBrowserTableViewControl::GetDefaultRowHeight( UInt16 * height ) const
OSStatus wxMacDataBrowserTableViewControl::GetDefaultRowHeight(UInt16* height) const
{
return GetDataBrowserTableViewRowHeight( m_controlRef, height );
return ::GetDataBrowserTableViewRowHeight(this->m_controlRef,height);
}
OSStatus wxMacDataBrowserTableViewControl::GetHeaderButtonHeight(UInt16 *height)
{
return GetDataBrowserListViewHeaderBtnHeight( m_controlRef, height );
return ::GetDataBrowserListViewHeaderBtnHeight(this->m_controlRef,height);
}
OSStatus wxMacDataBrowserTableViewControl::GetDefaultColumnWidth( UInt16 *width ) const
{
return GetDataBrowserTableViewColumnWidth( m_controlRef , width );
return GetDataBrowserTableViewColumnWidth(this->m_controlRef, width );
}
OSStatus wxMacDataBrowserTableViewControl::GetRowHeight( DataBrowserItemID item , UInt16 *height) const
@ -246,7 +243,7 @@ OSStatus wxMacDataBrowserTableViewControl::GetRowHeight( DataBrowserItemID item
OSStatus wxMacDataBrowserTableViewControl::GetScrollPosition( UInt32 *top , UInt32 *left ) const
{
return GetDataBrowserScrollPosition( m_controlRef , top , left );
return GetDataBrowserScrollPosition(this->m_controlRef, top , left );
}
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
@ -256,34 +253,34 @@ OSStatus wxMacDataBrowserTableViewControl::SetAttributes(OptionBits attributes)
} /* wxMacDataBrowserTableViewControl::SetAttributes(OptionBits) */
#endif
OSStatus wxMacDataBrowserTableViewControl::SetColumnWidth( DataBrowserPropertyID column , UInt16 width )
OSStatus wxMacDataBrowserTableViewControl::SetColumnWidth(DataBrowserPropertyID propertyID, UInt16 width)
{
return SetDataBrowserTableViewNamedColumnWidth( m_controlRef , column , width );
return ::SetDataBrowserTableViewNamedColumnWidth(this->m_controlRef,propertyID,width);
}
OSStatus wxMacDataBrowserTableViewControl::SetDefaultColumnWidth( UInt16 width )
OSStatus wxMacDataBrowserTableViewControl::SetDefaultColumnWidth(UInt16 width)
{
return SetDataBrowserTableViewColumnWidth( m_controlRef , width );
return ::SetDataBrowserTableViewColumnWidth(this->m_controlRef,width);
}
OSStatus wxMacDataBrowserTableViewControl::SetDefaultRowHeight( UInt16 height )
OSStatus wxMacDataBrowserTableViewControl::SetDefaultRowHeight(UInt16 height)
{
return SetDataBrowserTableViewRowHeight( m_controlRef , height );
return ::SetDataBrowserTableViewRowHeight(this->m_controlRef,height);
}
OSStatus wxMacDataBrowserTableViewControl::SetHasScrollBars( bool horiz, bool vert )
{
return SetDataBrowserHasScrollBars( m_controlRef, horiz, vert );
return SetDataBrowserHasScrollBars(this->m_controlRef, horiz, vert );
}
OSStatus wxMacDataBrowserTableViewControl::SetHeaderButtonHeight(UInt16 height)
{
return SetDataBrowserListViewHeaderBtnHeight( m_controlRef, height );
return SetDataBrowserListViewHeaderBtnHeight(this->m_controlRef, height );
}
OSStatus wxMacDataBrowserTableViewControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle )
{
return SetDataBrowserTableViewHiliteStyle( m_controlRef, hiliteStyle );
return SetDataBrowserTableViewHiliteStyle(this->m_controlRef, hiliteStyle );
}
OSStatus wxMacDataBrowserTableViewControl::SetRowHeight(DataBrowserItemID item, UInt16 height)
@ -301,32 +298,32 @@ OSStatus wxMacDataBrowserTableViewControl::SetScrollPosition(UInt32 top, UInt32
//
OSStatus wxMacDataBrowserTableViewControl::GetColumnCount(UInt32* numColumns) const
{
return GetDataBrowserTableViewColumnCount(this->m_controlRef,numColumns);
return ::GetDataBrowserTableViewColumnCount(this->m_controlRef,numColumns);
}
OSStatus wxMacDataBrowserTableViewControl::GetColumnID(DataBrowserTableViewColumnIndex position, DataBrowserTableViewColumnID* id)
OSStatus wxMacDataBrowserTableViewControl::GetColumnIndex(DataBrowserPropertyID propertyID, DataBrowserTableViewColumnIndex* index) const
{
return GetDataBrowserTableViewColumnProperty(this->m_controlRef,position,id);
} /* wxMacDataBrowserTableViewControl::GetColumnID(DataBrowserTableViewColumnIndex position, DataBrowserTableViewColumnID* id) */
return ::GetDataBrowserTableViewColumnPosition(this->m_controlRef,propertyID,index);
} /* wxMacDataBrowserTableViewControl::GetColumnIndex(DataBrowserPropertyID, DataBrowserTableViewColumnIndex*) const */
OSStatus wxMacDataBrowserTableViewControl::GetFreePropertyID(DataBrowserPropertyID* id) const
OSStatus wxMacDataBrowserTableViewControl::GetFreePropertyID(DataBrowserPropertyID* propertyID) const
{
for (*id=kMinPropertyID; *id<std::numeric_limits<DataBrowserPropertyID>::max(); ++(*id))
if (this->IsUsedPropertyID(*id) == errDataBrowserPropertyNotFound)
for (*propertyID=kMinPropertyID; *propertyID<std::numeric_limits<DataBrowserPropertyID>::max(); ++(*propertyID))
if (this->IsUsedPropertyID(*propertyID) == errDataBrowserPropertyNotFound)
return noErr;
return errDataBrowserPropertyNotSupported;
} /* wxMacDataBrowserTableViewControl::GetFreePropertyID(DataBrowserPropertyID*) const */
OSStatus wxMacDataBrowserTableViewControl::GetPropertyColumn(DataBrowserPropertyID propertyID, DataBrowserTableViewColumnIndex* column) const
OSStatus wxMacDataBrowserTableViewControl::GetPropertyFlags(DataBrowserPropertyID propertyID, DataBrowserPropertyFlags *flags) const
{
return GetDataBrowserTableViewColumnPosition(this->m_controlRef,propertyID,column);
} /* wxMacDataBrowserTableViewControl::GetPropertyColumn(DataBrowserPropertyID, DataBrowserTableViewColumnIndex*) const */
OSStatus wxMacDataBrowserTableViewControl::GetPropertyFlags(DataBrowserPropertyID property, DataBrowserPropertyFlags *flags) const
{
return GetDataBrowserPropertyFlags( m_controlRef , property , flags );
return ::GetDataBrowserPropertyFlags(this->m_controlRef,propertyID,flags);
}
OSStatus wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserTableViewColumnIndex index, DataBrowserTableViewColumnID* propertyID)
{
return ::GetDataBrowserTableViewColumnProperty(this->m_controlRef,index,propertyID);
} /* wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserTableViewColumnIndex, DataBrowserTableViewColumnID*) */
OSStatus wxMacDataBrowserTableViewControl::IsUsedPropertyID(DataBrowserPropertyID propertyID) const
{
// as the Mac interface does not provide a function that checks if the property id is in use or not a function is chosen that should not
@ -337,28 +334,30 @@ OSStatus wxMacDataBrowserTableViewControl::IsUsedPropertyID(DataBrowserPropertyI
return ::GetDataBrowserTableViewColumnPosition(this->m_controlRef,propertyID,&index);
} /* wxMacDataBrowserTableViewControl::IsUsedPropertyId(DataBrowserPropertyID) const */
OSStatus wxMacDataBrowserTableViewControl::RemoveColumn(DataBrowserTableViewColumnIndex position)
OSStatus wxMacDataBrowserTableViewControl::RemoveColumn(DataBrowserTableViewColumnIndex index)
{
DataBrowserTableViewColumnID id;
GetColumnID( position, &id );
return RemoveDataBrowserTableViewColumn( m_controlRef, id );
DataBrowserTableViewColumnID propertyID;
this->GetPropertyID(index,&propertyID);
return ::RemoveDataBrowserTableViewColumn(this->m_controlRef,propertyID);
} /* wxMacDataBrowserTableViewControl::RemoveColumn(DataBrowserTableViewColumnIndex) */
OSStatus wxMacDataBrowserTableViewControl::SetColumnIndex(DataBrowserPropertyID propertyID, DataBrowserTableViewColumnIndex index)
{
return ::SetDataBrowserTableViewColumnPosition(this->m_controlRef,propertyID,index);
} /* wxMacDataBrowserTableViewControl::SetColumnIndex(DataBrowserPropertyID, DataBrowserTableViewColumnIndex) */
OSStatus wxMacDataBrowserTableViewControl::SetDisclosureColumn(DataBrowserPropertyID propertyID, Boolean expandableRows)
{
return ::SetDataBrowserListViewDisclosureColumn(this->m_controlRef,propertyID,expandableRows);
}
OSStatus wxMacDataBrowserTableViewControl::SetColumnPosition(DataBrowserPropertyID column, DataBrowserTableViewColumnIndex position)
OSStatus wxMacDataBrowserTableViewControl::SetPropertyFlags(DataBrowserPropertyID propertyID, DataBrowserPropertyFlags flags)
{
return ::SetDataBrowserTableViewColumnPosition(this->m_controlRef,column,position);
}
OSStatus wxMacDataBrowserTableViewControl::SetPropertyFlags(DataBrowserPropertyID property, DataBrowserPropertyFlags flags)
{
return ::SetDataBrowserPropertyFlags(this->m_controlRef,property,flags);
return ::SetDataBrowserPropertyFlags(this->m_controlRef,propertyID,flags);
} /* wxMacDataBrowserTableViewControl::SetPropertyFlags(DataBrowserPropertyID, DataBrowserPropertyFlags) */
OSStatus wxMacDataBrowserTableViewControl::SetDisclosureColumn(DataBrowserPropertyID property, Boolean expandableRows)
{
return SetDataBrowserListViewDisclosureColumn( m_controlRef, property, expandableRows);
}
//
// item handling
//
@ -467,10 +466,10 @@ size_t wxMacDataBrowserTableViewControl::GetSelectedItemIDs(wxArrayDataBrowserIt
return NoOfItems;
} /* wxMacDataBrowserTableViewControl::GetSelectedItemIDs(wxArrayDataBrowserItemID&) const*/
OSStatus wxMacDataBrowserTableViewControl::GetSelectionAnchor( DataBrowserItemID *first, DataBrowserItemID *last ) const
OSStatus wxMacDataBrowserTableViewControl::GetSelectionAnchor(DataBrowserItemID* first, DataBrowserItemID* last) const
{
return GetDataBrowserSelectionAnchor( m_controlRef, first, last );
}
return ::GetDataBrowserSelectionAnchor(this->m_controlRef,first,last);
} /* wxMacDataBrowserTableViewControl::GetSelectionAnchor(DataBrowserItemID*, DataBrowserItemID*) const */
OSStatus wxMacDataBrowserTableViewControl::GetSelectionFlags(DataBrowserSelectionFlags* flags) const
{
@ -489,35 +488,34 @@ OSStatus wxMacDataBrowserTableViewControl::SetSelectionFlags(DataBrowserSelectio
OSStatus wxMacDataBrowserTableViewControl::SetSelectedItems(UInt32 numItems, DataBrowserItemID const* items, DataBrowserSetOption operation)
{
return ::SetDataBrowserSelectedItems( m_controlRef, numItems, items, operation );
return ::SetDataBrowserSelectedItems(this->m_controlRef, numItems, items, operation );
} /* wxMacDataBrowserTableViewControl::SetSelectedItems(UInt32, DataBrowserItemID const*, DataBrowserSetOption) */
OSStatus wxMacDataBrowserTableViewControl::GetSortProperty( DataBrowserPropertyID *column ) const
OSStatus wxMacDataBrowserTableViewControl::GetSortProperty(DataBrowserPropertyID* propertyID) const
{
return GetDataBrowserSortProperty( m_controlRef , column );
return ::GetDataBrowserSortProperty(this->m_controlRef,propertyID);
}
OSStatus wxMacDataBrowserTableViewControl::SetSortProperty( DataBrowserPropertyID column )
OSStatus wxMacDataBrowserTableViewControl::SetSortProperty(DataBrowserPropertyID propertyID)
{
return SetDataBrowserSortProperty( m_controlRef , column );
return ::SetDataBrowserSortProperty(this->m_controlRef,propertyID);
}
OSStatus wxMacDataBrowserTableViewControl::GetSortOrder( DataBrowserSortOrder *order ) const
OSStatus wxMacDataBrowserTableViewControl::GetSortOrder(DataBrowserSortOrder* order) const
{
return GetDataBrowserSortOrder( m_controlRef , order );
return ::GetDataBrowserSortOrder(this->m_controlRef,order);
}
OSStatus wxMacDataBrowserTableViewControl::SetSortOrder( DataBrowserSortOrder order )
OSStatus wxMacDataBrowserTableViewControl::SetSortOrder(DataBrowserSortOrder order)
{
return SetDataBrowserSortOrder( m_controlRef , order );
return ::SetDataBrowserSortOrder(this->m_controlRef,order);
}
IMPLEMENT_ABSTRACT_CLASS(wxMacDataBrowserTableViewControl,wxMacControl)
// ============================================================================
// Databrowser class for the list view control
// wxMacDataBrowserListViewControl
// ============================================================================
//
#pragma mark -
//
// column handling
@ -528,9 +526,8 @@ OSStatus wxMacDataBrowserListViewControl::AddColumn(DataBrowserListViewColumnDes
} /* wxMacDataBrowserListViewControl::AddColumn(DataBrowserListViewColumnDesc*, DataBrowserTableViewColumnIndex) */
// ============================================================================
// Databrowser class for the data view control
// wxMacDataViewDataBrowserListViewControl
// ============================================================================
//
#pragma mark -
//
// constructors / destructor
@ -540,110 +537,30 @@ wxMacDataViewDataBrowserListViewControl::wxMacDataViewDataBrowserListViewControl
{
} /* wxMacDataViewDataBrowserListViewControl::wxMacDataViewDataBrowserListViewControl(wxWindow* , const wxPoint&, const wxSize&, long) */
//
// item ID and model matching
//
void wxMacDataViewDataBrowserListViewControl::ClearItemIDRowPairs(void)
{
this->m_itemIDRowNumberMap.clear();
} /* wxMacDataViewDataBrowserListViewControl::ClearItemIDRowPairs(void) */
bool wxMacDataViewDataBrowserListViewControl::DeleteItemIDRowPair(DataBrowserItemID itemID)
{
return (this->m_itemIDRowNumberMap.erase(itemID) == 1);
} /* wxMacDataViewDataBrowserListViewControl::DeleteItemIDRowPair(DataBrowseritemID) */
bool wxMacDataViewDataBrowserListViewControl::GetRowIndex(unsigned long& rowIndex, DataBrowserItemID itemID) const
{
ItemIDRowNumberHashMap::const_iterator iteratorHashMap(this->m_itemIDRowNumberMap.find(itemID));
if (iteratorHashMap == this->m_itemIDRowNumberMap.end())
return false;
else
{
rowIndex = iteratorHashMap->second;
return true;
} /* if */
} /* wxMacDataViewDataBrowserListViewControl::GetRowIndex(unsigned int& rowIndex, DataBrowserItemID itemID) const */
bool wxMacDataViewDataBrowserListViewControl::InsertItemIDRowPair(DataBrowserItemID itemID, unsigned long rowIndex)
{
return this->m_itemIDRowNumberMap.insert(ItemIDRowNumberHashMap::value_type(itemID,rowIndex)).second;
} /* wxMacDataViewDataBrowserListViewControl::InsertItemIDRowPair(DataBrowserItemID, unsigned long) */
void wxMacDataViewDataBrowserListViewControl::RenumberItemIDRowIndices(unsigned int* newIndices)
{
ItemIDRowNumberHashMap::iterator hashMapIterator(this->m_itemIDRowNumberMap.begin());
while (hashMapIterator != this->m_itemIDRowNumberMap.end())
{
hashMapIterator->second = newIndices[hashMapIterator->second];
++hashMapIterator;
} /* while */
} /* wxMacDataViewDataBrowserListViewControl::RenumberItemIDRowIndices(unsigned int*) */
void wxMacDataViewDataBrowserListViewControl::RenumberItemIDRowIndicesDeletion (unsigned long decreaseFromIndex)
{
ItemIDRowNumberHashMap::iterator hashMapIterator(this->m_itemIDRowNumberMap.begin());
while (hashMapIterator != this->m_itemIDRowNumberMap.end())
{
if (hashMapIterator->second >= decreaseFromIndex)
--(hashMapIterator->second);
++hashMapIterator;
} /* while */
} /* wxMacDataViewDataBrowserListViewControl::RenumberItemIDRowIndicesDeletion (unsigned int) */
void wxMacDataViewDataBrowserListViewControl::RenumberItemIDRowIndicesInsertion(unsigned long increaseFromIndex)
{
ItemIDRowNumberHashMap::iterator hashMapIterator(this->m_itemIDRowNumberMap.begin());
while (hashMapIterator != this->m_itemIDRowNumberMap.end())
{
if (hashMapIterator->second >= increaseFromIndex)
++(hashMapIterator->second);
++hashMapIterator;
} /* while */
} /* wxMacDataViewDataBrowserListViewControl::RenumberItemIDRowIndicesInsertion(unsigned int) */
void wxMacDataViewDataBrowserListViewControl::ReverseRowIndexNumbering(void)
{
if (this->m_itemIDRowNumberMap.size() > 0)
{
size_t const maxIndex = this->m_itemIDRowNumberMap.size()-1;
ItemIDRowNumberHashMap::iterator hashMapIterator(this->m_itemIDRowNumberMap.begin());
while (hashMapIterator != this->m_itemIDRowNumberMap.end())
{
hashMapIterator->second = maxIndex-hashMapIterator->second;
++hashMapIterator;
} /* while */
} /* if */
} /* wxMacDataViewDataBrowserListViewControl::ReverseRowIndexNumbering(void) */
//
// callback functions (inherited from wxMacDataBrowserTableViewControl)
//
Boolean wxMacDataViewDataBrowserListViewControl::DataBrowserCompareProc(DataBrowserItemID itemOneID, DataBrowserItemID itemTwoID, DataBrowserPropertyID WXUNUSED(sortProperty))
Boolean wxMacDataViewDataBrowserListViewControl::DataBrowserCompareProc(DataBrowserItemID itemOneID, DataBrowserItemID itemTwoID, DataBrowserPropertyID sortProperty)
{
unsigned long rowIndex1, rowIndex2;
wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->GetPeer()));
bool result = (this->GetRowIndex(rowIndex1,itemOneID) && this->GetRowIndex(rowIndex2,itemTwoID) && (rowIndex1 < rowIndex2));
return result;
wxCHECK_MSG(dataViewCtrlPtr != NULL, false,_("Pointer to data view control not set correctly."));
wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,false,_("Pointer to model not set correctly."));
if (sortProperty >= kMinPropertyID)
{
// variable definition:
DataBrowserTableViewColumnIndex columnIndex;
wxCHECK_MSG(this->GetColumnIndex(sortProperty,&columnIndex) == noErr,false,_("Could not determine column index."));
dataViewCtrlPtr->GetModel()->SetSortingColumn(columnIndex);
} /* if */
return static_cast<Boolean>(dataViewCtrlPtr->GetModel()->Compare(wxDataViewItem(reinterpret_cast<void*>(itemOneID)),wxDataViewItem(reinterpret_cast<void*>(itemTwoID))) < 0);
} /* wxMacDataViewDataBrowserListViewControl::DataBrowserCompareProc(DataBrowserItemID, DataBrowserItemID, DataBrowserPropertyID) */
void wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowserItemID itemID, DataBrowserPropertyID property, DataBrowserItemState state, Rect const* rectangle, SInt16 bitDepth, Boolean colorDevice)
void wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowserItemID itemID, DataBrowserPropertyID propertyID, DataBrowserItemState state, Rect const* rectangle, SInt16 bitDepth, Boolean colorDevice)
{
OSStatus errorStatus;
unsigned long column;
unsigned long row;
DataBrowserTableViewColumnIndex columnIndex;
wxDataViewColumn* dataViewColumnPtr;
@ -654,23 +571,15 @@ void wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowse
wxVariant dataToRender;
wxCHECK_RET(this->GetPropertyColumn(property,&column) == noErr,_("Could not determine column index."));
dataViewCtrlPtr = dynamic_cast<wxDataViewCtrl*>(this->GetPeer());
wxCHECK_RET(dataViewCtrlPtr != NULL, _("Pointer to data view control not set correctly."));
wxCHECK_RET(dataViewCtrlPtr->GetModel() != NULL,_("Pointer to model not set correctly."));
if (dynamic_cast<wxDataViewSortedListModel*>(dataViewCtrlPtr->GetModel()) == NULL)
{
wxCHECK_RET(this->GetRowIndex(row,itemID),_("Row index does not exist."));
} /* if */
else
{
wxCHECK_RET(this->GetItemRow(itemID,&row) == noErr,_("Row index does not exist."));
} /* if */
dataViewColumnPtr = dataViewCtrlPtr->GetColumn(column);
wxCHECK_RET(dataViewCtrlPtr != NULL, _("Pointer to data view control not set correctly."));
wxCHECK_RET(dataViewCtrlPtr->GetModel() != NULL, _("Pointer to model not set correctly."));
wxCHECK_RET(this->GetColumnIndex(propertyID,&columnIndex) == noErr,_("Could not determine column index."));
dataViewColumnPtr = dataViewCtrlPtr->GetColumn(columnIndex);
wxCHECK_RET(dataViewColumnPtr != NULL,_("No column for the specified column index existing."));
dataViewCustomRendererPtr = dynamic_cast<wxDataViewCustomRenderer*>(dataViewColumnPtr->GetRenderer());
wxCHECK_RET(dataViewCustomRendererPtr != NULL,_("No renderer or invalid renderer type specified for custom data column."));
dataViewCtrlPtr->GetModel()->GetValue(dataToRender,column,row);
dataViewCtrlPtr->GetModel()->GetValue(dataToRender,wxDataViewItem(reinterpret_cast<void*>(itemID)),columnIndex);
dataViewCustomRendererPtr->SetValue(dataToRender);
// try to determine the content's size (drawable part):
@ -703,36 +612,29 @@ void wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowse
dataViewCustomRendererPtr->GetDC()->DestroyClippingRegion(); // probably not necessary
} /* wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemState, Rect const*, SInt16, Boolean) */
OSStatus wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(DataBrowserItemID itemID, DataBrowserPropertyID property, DataBrowserItemDataRef itemData, Boolean getValue)
OSStatus wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(DataBrowserItemID itemID, DataBrowserPropertyID propertyID, DataBrowserItemDataRef itemData, Boolean getValue)
{
if (getValue)
{
// variable definition:
unsigned long column;
unsigned long row;
wxDataViewCtrl* dataViewCtrlPtr;
wxDataViewColumn* dataViewColumnPtr;
// variable definitions:
DataBrowserTableViewColumnIndex columnIndex;
OSStatus errorStatus;
wxDataViewCtrl* dataViewCtrlPtr;
wxDataViewColumn* dataViewColumnPtr;
verify_noerr(this->GetPropertyColumn(property,&column));
dataViewCtrlPtr = dynamic_cast<wxDataViewCtrl*>(this->GetPeer());
wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
if (dynamic_cast<wxDataViewSortedListModel*>(dataViewCtrlPtr->GetModel()) == NULL)
{
wxCHECK_MSG(this->GetRowIndex(row,itemID),errDataBrowserNotConfigured,_("Row index does not exist."));
} /* if */
else
{
wxCHECK_MSG(this->GetItemRow(itemID,&row) == noErr,errDataBrowserNotConfigured,_("Row index does not exist."));
} /* if */
dataViewColumnPtr = dataViewCtrlPtr->GetColumn(column);
wxCHECK_MSG((dataViewColumnPtr != NULL) && (dataViewColumnPtr->GetRenderer() != NULL),errDataBrowserNotConfigured,_("There is no column for the specified column index."));
wxCHECK_MSG(dataViewCtrlPtr != NULL, errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,errDataBrowserNotConfigured,_("Pointer to model not set correctly."));
errorStatus = this->GetColumnIndex(propertyID,&columnIndex);
wxCHECK_MSG(errorStatus == noErr,errorStatus,_("Could not determine column index"));
dataViewColumnPtr = dataViewCtrlPtr->GetColumn(columnIndex);
wxCHECK_MSG((dataViewColumnPtr != NULL) && (dataViewColumnPtr->GetRenderer() != NULL),errDataBrowserNotConfigured,_("There is no column or renderer for the specified column index."));
switch (dataViewColumnPtr->GetRenderer()->GetPropertyType())
{
case kDataBrowserCheckboxType:
{
// variable definitions:
// variable definition:
ThemeButtonValue buttonValue;
OSStatus errorStatus;
errorStatus = ::GetDataBrowserItemDataButtonValue(itemData,&buttonValue);
if (errorStatus == noErr)
@ -742,14 +644,14 @@ OSStatus wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(
// variable definition and initialization:
wxVariant modifiedData(true);
return (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,static_cast<unsigned int>(column),static_cast<unsigned int>(row)) ? noErr : errDataBrowserNotConfigured);
return (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,wxDataViewItem(reinterpret_cast<void*>(itemID)),static_cast<unsigned int>(columnIndex)) ? OSStatus(noErr) : OSStatus(errDataBrowserNotConfigured));
} /* if */
else if (buttonValue == kThemeButtonOff)
{
// variable definition and initialization:
wxVariant modifiedData(false);
return (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,static_cast<unsigned int>(column),static_cast<unsigned int>(row)) ? noErr : errDataBrowserNotConfigured);
return (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,wxDataViewItem(reinterpret_cast<void*>(itemID)),static_cast<unsigned int>(columnIndex)) ? OSStatus(noErr) : OSStatus(errDataBrowserNotConfigured));
} /* if */
else
return errDataBrowserInvalidPropertyData;
@ -761,7 +663,6 @@ OSStatus wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(
{
// variable definitions:
CFStringRef stringReference;
OSStatus errorStatus;
errorStatus = ::GetDataBrowserItemDataText(itemData,&stringReference);
if (errorStatus == noErr)
@ -770,7 +671,7 @@ OSStatus wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(
wxMacCFStringHolder modifiedString(stringReference);
wxVariant modifiedData(modifiedString.AsString());
if (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,static_cast<unsigned int>(column),static_cast<unsigned int>(row)))
if (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,wxDataViewItem(reinterpret_cast<void*>(itemID)),static_cast<unsigned int>(columnIndex)))
return noErr;
else
return errDataBrowserNotConfigured;
@ -784,39 +685,40 @@ OSStatus wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(
} /* if */
else
{
if (property >= kMinPropertyID) // in case of data columns set the data
if (propertyID >= kMinPropertyID) // in case of data columns set the data
{
// variable definitions:
OSStatus errorStatus;
unsigned long columnPosition;
unsigned long rowPosition;
wxVariant variant;
wxDataViewColumn* dataViewColumnPtr;
wxDataViewCtrl* dataViewCtrlPtr;
DataBrowserTableViewColumnIndex columnIndex;
OSStatus errorStatus;
wxVariant variant;
wxDataViewColumn* dataViewColumnPtr;
wxDataViewCtrl* dataViewCtrlPtr;
errorStatus = this->GetPropertyColumn(property,&columnPosition);
dataViewCtrlPtr = dynamic_cast<wxDataViewCtrl*>(this->GetPeer());
wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,errDataBrowserNotConfigured,_("Pointer to model not set correctly."));
errorStatus = this->GetColumnIndex(propertyID,&columnIndex);
wxCHECK_MSG(errorStatus == noErr,errorStatus,_("Column index does not exist."));
dataViewCtrlPtr = dynamic_cast<wxDataViewCtrl*>(this->GetPeer());wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
dataViewColumnPtr = dataViewCtrlPtr->GetColumn(columnPosition); wxCHECK_MSG(dataViewColumnPtr != NULL,errDataBrowserNotConfigured,_("No column for the specified column position existing."));
if (dynamic_cast<wxDataViewSortedListModel*>(dataViewCtrlPtr->GetModel()) == NULL)
{
wxCHECK_MSG(this->GetRowIndex(rowPosition,itemID),errDataBrowserNotConfigured,_("Row index does not exist."));
} /* if */
else
{
wxCHECK_MSG(this->GetItemRow(itemID,&rowPosition) == noErr,errDataBrowserNotConfigured,_("Row index does not exist."));
} /* if */
dataViewCtrlPtr->GetModel()->GetValue(variant,dataViewColumnPtr->GetModelColumn(),rowPosition);
dataViewColumnPtr = dataViewCtrlPtr->GetColumn(columnIndex);
wxCHECK_MSG(dataViewColumnPtr != NULL,errDataBrowserNotConfigured,_("No column for the specified column position existing."));
wxCHECK_MSG(dataViewColumnPtr->GetRenderer() != NULL,errDataBrowserNotConfigured,_("No renderer specified for column."));
dataViewCtrlPtr->GetModel()->GetValue(variant,wxDataViewItem(reinterpret_cast<void*>(itemID)),dataViewColumnPtr->GetModelColumn());
dataViewColumnPtr->GetRenderer()->SetDataReference(itemData);
dataViewColumnPtr->GetRenderer()->SetValue(variant);
wxCHECK_MSG(dataViewColumnPtr->GetRenderer()->Render(),errDataBrowserNotConfigured,_("Rendering failed."));
} /* if */
else // react on special system requests
switch (property)
switch (propertyID)
{
case kDataBrowserItemIsContainerProperty:
return ::SetDataBrowserItemDataBooleanValue(itemData,false);
{
// variable definition:
wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->GetPeer()));
wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,errDataBrowserNotConfigured,_("Pointer to model not set correctly."));
return ::SetDataBrowserItemDataBooleanValue(itemData,dataViewCtrlPtr->GetModel()->IsContainer(wxDataViewItem(reinterpret_cast<void*>(itemID))));
} /* block */
case kDataBrowserItemIsEditableProperty:
return ::SetDataBrowserItemDataBooleanValue(itemData,true);
} /* switch */
@ -828,19 +730,26 @@ void wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(Da
{
switch (message)
{
case kDataBrowserContainerOpened:
{
// variable definitions:
wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->GetPeer()));
wxCHECK_RET(dataViewCtrlPtr != NULL,_("Pointer to data view control not set correctly."));
dataViewCtrlPtr->AddChildrenLevel(wxDataViewItem(reinterpret_cast<void*>(itemID)));
} /* block */
break;
case kDataBrowserItemDoubleClicked:
{
// variable definitions:
unsigned long row;
wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->GetPeer()));
wxCHECK_RET(dataViewCtrlPtr != NULL, _("Pointer to data view control not set correctly."));
wxCHECK_RET(this->GetRowIndex(row,itemID),_("Row index does not exist."));
wxCHECK_RET(dataViewCtrlPtr != NULL,_("Pointer to data view control not set correctly."));
// initialize wxWidget event:
wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ROW_ACTIVATED,dataViewCtrlPtr->GetId()); // variable defintion
wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED,dataViewCtrlPtr->GetId()); // variable definition
dataViewEvent.SetEventObject(dataViewCtrlPtr);
dataViewEvent.SetRow(row);
dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
// finally sent the equivalent wxWidget event:
dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
} /* block */
@ -848,49 +757,41 @@ void wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(Da
case kDataBrowserItemSelected:
{
// variable definitions:
unsigned long row;
wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->GetPeer()));
wxCHECK_RET(dataViewCtrlPtr != NULL, _("Pointer to data view control not set correctly."));
if (dynamic_cast<wxDataViewSortedListModel*>(dataViewCtrlPtr->GetModel()) == NULL)
{
wxCHECK_RET(this->GetRowIndex(row,itemID),_("Row index does not exist."));
} /* if */
else
{
wxCHECK_RET(this->GetItemRow(itemID,&row) == noErr,_("Row index does not exist."));
} /* if */
wxCHECK_RET(dataViewCtrlPtr != NULL,_("Pointer to data view control not set correctly."));
// initialize wxWidget event:
wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ROW_SELECTED,dataViewCtrlPtr->GetId()); // variable defintion
wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_SELECTED,dataViewCtrlPtr->GetId()); // variable definition
dataViewEvent.SetEventObject(dataViewCtrlPtr);
dataViewEvent.SetRow(row);
dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
// finally sent the equivalent wxWidget event:
dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
} /* block */
break;
case kDataBrowserUserStateChanged:
{
DataBrowserPropertyID propertyId;
DataBrowserPropertyID propertyID;
if ((this->GetSortProperty(&propertyId) == noErr) && (propertyId >= kMinPropertyID))
if ((this->GetSortProperty(&propertyID) == noErr) && (propertyID >= kMinPropertyID))
{
DataBrowserSortOrder sortOrder;
unsigned long column;
DataBrowserSortOrder sortOrder;
DataBrowserTableViewColumnIndex columnIndex;
if ((this->GetSortOrder(&sortOrder) == noErr) && (this->GetPropertyColumn(propertyId,&column) == noErr))
if ((this->GetSortOrder(&sortOrder) == noErr) && (this->GetColumnIndex(propertyID,&columnIndex) == noErr))
{
// variable definition and initialization:
wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->GetPeer()));
if ( dataViewCtrlPtr->GetColumn(column)->IsSortOrderAscending() && (sortOrder == kDataBrowserOrderDecreasing) ||
!(dataViewCtrlPtr->GetColumn(column)->IsSortOrderAscending()) && (sortOrder == kDataBrowserOrderIncreasing))
if ( dataViewCtrlPtr->GetColumn(columnIndex)->IsSortOrderAscending() && (sortOrder == kDataBrowserOrderDecreasing) ||
!(dataViewCtrlPtr->GetColumn(columnIndex)->IsSortOrderAscending()) && (sortOrder == kDataBrowserOrderIncreasing))
{
// initialize wxWidget event:
wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED,dataViewCtrlPtr->GetId()); // variable defintion
dataViewEvent.SetEventObject(dataViewCtrlPtr);
dataViewEvent.SetColumn(column);
dataViewEvent.SetDataViewColumn(dataViewCtrlPtr->GetColumn(column));
dataViewEvent.SetColumn(columnIndex);
dataViewEvent.SetDataViewColumn(dataViewCtrlPtr->GetColumn(columnIndex));
// finally sent the equivalent wxWidget event:
dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
} /* if */

View File

@ -99,32 +99,56 @@ static pascal OSStatus wxMacDataViewCtrlEventHandler(EventHandlerCallRef handler
DEFINE_ONE_SHOT_HANDLER_GETTER(wxMacDataViewCtrlEventHandler)
// ---------------------------------------------------------
// wxMacDataViewListModelNotifier
// wxMacDataViewModelNotifier
// ---------------------------------------------------------
#pragma mark -
class wxMacDataViewListModelNotifier : public wxDataViewListModelNotifier
class wxMacDataViewModelNotifier : public wxDataViewModelNotifier
{
public:
wxMacDataViewListModelNotifier(wxMacDataViewDataBrowserListViewControl* initDataViewControlPtr) : m_dataViewControlPtr(initDataViewControlPtr)
wxMacDataViewModelNotifier(wxMacDataViewDataBrowserListViewControl* initDataViewControlPtr) : m_dataViewControlPtr(initDataViewControlPtr)
{
}
virtual bool RowAppended(void)
virtual bool ItemAdded(const wxDataViewItem &parent, const wxDataViewItem &item)
{
DataBrowserItemID newRowID;
DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
wxCHECK_MSG(item.IsOk(),false,_("Added item is invalid."));
if (!(parent.IsOk()) && (this->m_dataViewControlPtr->AddItem(kDataBrowserNoItem, &itemID) == noErr) ||
parent.IsOk() && (this->m_dataViewControlPtr->AddItem(reinterpret_cast<DataBrowserItemID>(parent.GetID()),&itemID) == noErr))
{
// variable definitions and initializations:
wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
wxDataViewEvent dataViewEvent (wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_ADDED,dataViewCtrlPtr->GetId());
dataViewEvent.SetEventObject(dataViewCtrlPtr);
dataViewEvent.SetItem(item);
// sent the equivalent wxWidget event:
dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
// done:
return true;
} /* if */
else
return false;
} /* ItemAdded(wxDataViewItem const&, wxDataViewItem const&) */
virtual bool ItemChanged(wxDataViewItem const& item)
{
DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
if ((this->m_dataViewControlPtr->GetFreeItemID(&newRowID) == noErr) &&
this->m_dataViewControlPtr->InsertItemIDRowPair(newRowID,this->GetOwner()->GetRowCount()-1) &&
(this->m_dataViewControlPtr->AddItem(kDataBrowserNoItem,&newRowID) == noErr))
wxCHECK_MSG(item.IsOk(), false,_("Changed item is invalid."));
wxCHECK_MSG(this->GetOwner() != NULL,false,_("Owner not initialized."));
if (this->m_dataViewControlPtr->UpdateItems(&itemID) == noErr)
{
wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
// sent the equivalent wxWidget event:
wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_MODEL_ROW_APPENDED,dataViewCtrlPtr->GetId()); // variable defintion
wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_CHANGED,dataViewCtrlPtr->GetId()); // variable defintion
dataViewEvent.SetEventObject(dataViewCtrlPtr);
dataViewEvent.SetRow(this->GetOwner()->GetRowCount()-1);
dataViewEvent.SetItem(item);
// sent the equivalent wxWidget event:
dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
// done
@ -132,21 +156,22 @@ public:
} /* if */
else
return false;
}
virtual bool RowChanged(unsigned int row)
} /* ItemChanged(wxDataViewItem const&) */
virtual bool ItemDeleted(wxDataViewItem const& parent, wxDataViewItem const& item)
{
DataBrowserItemID itemID;
if (this->m_dataViewControlPtr->GetItemID(row,&itemID) == noErr)
DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
wxCHECK_MSG(item.IsOk(),false,_("Deleted item is invalid."));
if (this->m_dataViewControlPtr->RemoveItem(reinterpret_cast<DataBrowserItemID>(parent.GetID()),&itemID) == noErr)
{
// variable definitions and initializations:
wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
// sent the equivalent wxWidget event:
wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_MODEL_ROW_CHANGED,dataViewCtrlPtr->GetId()); // variable defintion
wxDataViewEvent dataViewEvent (wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_DELETED,dataViewCtrlPtr->GetId());
dataViewEvent.SetEventObject(dataViewCtrlPtr);
dataViewEvent.SetRow(row);
dataViewEvent.SetItem(item);
// sent the equivalent wxWidget event:
dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
// done
@ -154,191 +179,57 @@ public:
} /* if */
else
return false;
}
virtual bool RowDeleted(unsigned int row)
} /* ItemDeleted(wxDataViewItem const&) */
virtual bool ValueChanged(wxDataViewItem const& item, unsigned int col)
{
DataBrowserItemID itemID;
if (this->m_dataViewControlPtr->GetItemID(row,&itemID) == noErr)
{
// variable definition:
unsigned long rowIndex;
wxCHECK_MSG(this->m_dataViewControlPtr->GetRowIndex(rowIndex,itemID) && this->m_dataViewControlPtr->DeleteItemIDRowPair(itemID),false,_("Unable to delete row data."));
this->m_dataViewControlPtr->RenumberItemIDRowIndicesDeletion(rowIndex);
if (this->m_dataViewControlPtr->RemoveItem(kDataBrowserNoItem,&itemID) == noErr)
{
wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
// sent the equivalent wxWidget event:
wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_MODEL_ROW_DELETED,dataViewCtrlPtr->GetId()); // variable defintion
dataViewEvent.SetEventObject(dataViewCtrlPtr);
dataViewEvent.SetRow(row);
// sent the equivalent wxWidget event:
dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
// done
return true;
} /* if */
else
return false;
} /* if */
else
return false;
}
virtual bool RowInserted(unsigned int before)
{
DataBrowserItemID newRowID;
if (this->m_dataViewControlPtr->GetFreeItemID(&newRowID) == noErr)
{
this->m_dataViewControlPtr->RenumberItemIDRowIndicesInsertion(before);
if (this->m_dataViewControlPtr->InsertItemIDRowPair(newRowID,before) && (this->m_dataViewControlPtr->AddItem(kDataBrowserNoItem,&newRowID) == noErr))
{
wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
// sent the equivalent wxWidget event:
wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_MODEL_ROW_INSERTED,dataViewCtrlPtr->GetId()); // variable defintion
dataViewEvent.SetEventObject(dataViewCtrlPtr);
dataViewEvent.SetRow(before);
// sent the equivalent wxWidget event:
dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
// done
return true;
} /* if */
else
return false;
} /* if */
else
return false;
}
virtual bool RowPrepended(void)
{
DataBrowserItemID newRowID;
if (this->m_dataViewControlPtr->GetFreeItemID(&newRowID) == noErr)
{
this->m_dataViewControlPtr->RenumberItemIDRowIndicesInsertion(0);
if (this->m_dataViewControlPtr->InsertItemIDRowPair(newRowID,0) && (this->m_dataViewControlPtr->AddItem(kDataBrowserNoItem,&newRowID) == noErr))
{
wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
// sent the equivalent wxWidget event:
wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_MODEL_ROW_PREPENDED,dataViewCtrlPtr->GetId()); // variable defintion
dataViewEvent.SetEventObject(dataViewCtrlPtr);
dataViewEvent.SetRow(0);
// sent the equivalent wxWidget event:
dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
// done
return true;
} /* if */
else
return false;
} /* if */
else
return false;
}
virtual bool ValueChanged(unsigned int col, unsigned int row)
{
DataBrowserItemID itemID;
DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
DataBrowserItemID parentID;
DataBrowserPropertyID propertyID;
wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
if ((dataViewCtrlPtr != NULL) && (this->m_dataViewControlPtr->GetItemID(row,&itemID) == noErr) && (this->m_dataViewControlPtr->GetColumnID(col,&propertyID) == noErr) &&
(this->m_dataViewControlPtr->UpdateItems(kDataBrowserNoItem,1,&itemID,dataViewCtrlPtr->GetColumn(col)->GetPropertyID(),propertyID) == noErr))
wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
wxCHECK_MSG(item.IsOk(), false,_("Passed item is invalid."));
wxCHECK_MSG(this->GetOwner() != NULL,false,_("Owner not initialized."));
wxCHECK_MSG(dataViewCtrlPtr != NULL, false,_("Control is wrongly initialized."));
parentID = reinterpret_cast<DataBrowserItemID>(this->GetOwner()->GetParent(item).GetID());
if ((this->m_dataViewControlPtr->GetPropertyID(col,&propertyID) == noErr) &&
(this->m_dataViewControlPtr->UpdateItems(parentID,1,&itemID,dataViewCtrlPtr->GetColumn(col)->GetPropertyID(),propertyID) == noErr))
{
wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
// sent the equivalent wxWidget event:
wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_MODEL_VALUE_CHANGED,dataViewCtrlPtr->GetId()); // variable defintion
// variable definition and initialization:
wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_MODEL_VALUE_CHANGED,dataViewCtrlPtr->GetId());
dataViewEvent.SetEventObject(dataViewCtrlPtr);
dataViewEvent.SetColumn(col);
dataViewEvent.SetRow(row);
// sent the equivalent wxWidget event:
dataViewEvent.SetItem(item);
// send the equivalent wxWidget event:
dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
// done
return true;
} /* if */
else
return false;
}
virtual bool RowsReordered(unsigned int* new_order)
{
DataBrowserPropertyID propertyId;
} /* ValueChanged(wxDataViewItem const&, unsigned int) */
if ((new_order != NULL) && (this->m_dataViewControlPtr->GetSortProperty(&propertyId) == noErr) && (propertyId >= kMinPropertyID))
{
DataBrowserSortOrder sortOrder;
unsigned long column;
if ((this->m_dataViewControlPtr->GetSortOrder(&sortOrder) == noErr) && (this->m_dataViewControlPtr->GetPropertyColumn(propertyId,&column) == noErr))
{
wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
if (dataViewCtrlPtr->GetColumn(column)->IsSortOrderAscending())
this->m_dataViewControlPtr->RenumberItemIDRowIndices(new_order);
else // the sort order of the control is descending but the passed sort order is always ordered top - down
{
ItemCount itemCount;
if (this->m_dataViewControlPtr->GetItemCount(&itemCount) != noErr)
return false;
unsigned int* reversedOrder(new unsigned int[itemCount]);
for (ItemCount i=0; i<itemCount; ++i)
reversedOrder[i] = itemCount-new_order[i];
this->m_dataViewControlPtr->RenumberItemIDRowIndices(reversedOrder);
delete[] reversedOrder;
} /* if */
if (this->m_dataViewControlPtr->UpdateItems())
{
// sent the equivalent wxWidget event:
wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_MODEL_ROWS_REORDERED,dataViewCtrlPtr->GetId()); // variable defintion
dataViewEvent.SetEventObject(dataViewCtrlPtr);
// sent the equivalent wxWidget event:
dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
// done
return true;
} /* if */
else
return false;
} /* if */
else
return false;
} /* if */
else
return false;
}
virtual bool Cleared(void)
{
this->m_dataViewControlPtr->ClearItemIDRowPairs();
if (this->m_dataViewControlPtr->RemoveItems() == noErr)
{
// variable definitions and initializations:
wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
// sent the equivalent wxWidget event:
wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_MODEL_CLEARED,dataViewCtrlPtr->GetId()); // variable defintion
wxDataViewEvent dataViewEvent (wxEVT_COMMAND_DATAVIEW_MODEL_CLEARED,dataViewCtrlPtr->GetId());
dataViewEvent.SetEventObject(dataViewCtrlPtr);
// sent the equivalent wxWidget event:
// send the equivalent wxWidget event:
dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
// done
return true;
} /* if */
else
return false;
}
} /* Cleared(void) */
protected:
private:
@ -547,14 +438,16 @@ 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_alignment(align), m_ascending(true),
m_flags(flags & ~(wxDATAVIEW_COL_HIDDEN | wxDATAVIEW_COL_RESIZABLE)), m_minWidth(0), m_maxWidth(std::numeric_limits<int>::max()), m_width(width), m_title(title)
: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<int>::max()), m_minWidth(0), m_width(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_alignment(align),
m_flags(flags & (wxDATAVIEW_COL_HIDDEN | wxDATAVIEW_COL_RESIZABLE)), m_minWidth(0), m_maxWidth(std::numeric_limits<int>::max()), m_width(width)
: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<int>::max()), m_minWidth(0), m_width(width),
m_alignment(align)
{
} /* wxDataViewColumn::wxDataViewColumn(wxBitmap const&, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
@ -808,56 +701,27 @@ 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) */
void wxDataViewCtrl::OnSize(wxSizeEvent& event)
{
unsigned int const NoOfColumns = this->GetColumnCount();
for (unsigned int i=0; i<NoOfColumns; ++i)
{
// variable definition and initialization:
wxDataViewColumn* dataViewColumnPtr(this->GetColumn(i));
if (dataViewColumnPtr != NULL)
{
// variable definition and initialization:
wxDataViewCustomRenderer* dataViewCustomRendererPtr(dynamic_cast<wxDataViewCustomRenderer*>(dataViewColumnPtr->GetRenderer()));
if (dataViewCustomRendererPtr != NULL)
dataViewCustomRendererPtr->SetDC(NULL); // reset DC because DC has changed
} /* if */
} /* for */
event.Skip();
} /* wxDataViewCtrl::OnSize(wxSizeEvent&) */
bool wxDataViewCtrl::AssociateModel(wxDataViewListModel *model)
{
if (!wxDataViewCtrlBase::AssociateModel(model))
return false;
this->m_NotifierPtr = new wxMacDataViewListModelNotifier(dynamic_cast<wxMacDataViewDataBrowserListViewControl*>(this->m_peer));
model->AddNotifier(this->m_NotifierPtr);
return true;
}
bool wxDataViewCtrl::AppendColumn(wxDataViewColumn* dataViewColumnPtr)
{
wxCHECK_MSG(dataViewColumnPtr != NULL, false,_("Column pointer must not be NULL."));
wxCHECK_MSG(dataViewColumnPtr->GetRenderer() != NULL,false,_("Column does not have a renderer."));
// first, some error checking:
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))
{
// variable definition:
DataBrowserPropertyID FreeID;
DataBrowserPropertyID NewPropertyID;
DataBrowserListViewColumnDesc columnDescription;
wxMacCFStringHolder cfTitle(dataViewColumnPtr->GetTitle(),(this->m_font.Ok() ? this->m_font.GetEncoding() : wxLocale::GetSystemEncoding()));
wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
// initialize column description:
wxCHECK_MSG (MacDataViewListCtrlPtr != NULL,false,_("m_peer is not or incorrectly initialized"));
verify_noerr(MacDataViewListCtrlPtr->GetFreePropertyID(&FreeID));
dataViewColumnPtr->SetPropertyID(FreeID);
columnDescription.propertyDesc.propertyID = FreeID;
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);
columnDescription.propertyDesc.propertyID = NewPropertyID;
columnDescription.propertyDesc.propertyType = dataViewColumnPtr->GetRenderer()->GetPropertyType();
columnDescription.propertyDesc.propertyFlags = kDataBrowserListViewSelectionColumn;
if (dataViewColumnPtr->IsSortable())
@ -904,40 +768,23 @@ bool wxDataViewCtrl::AppendColumn(wxDataViewColumn* dataViewColumnPtr)
if (dataViewColumnPtr->GetBitmap().Ok())
columnDescription.headerBtnDesc.btnContentInfo.u.iconRef = dataViewColumnPtr->GetBitmap().GetBitmapData()->GetIconRef();
// add column:
verify_noerr(MacDataViewListCtrlPtr->AddColumn(&columnDescription,kDataBrowserListViewAppendColumn));
wxCHECK_MSG(MacDataViewListCtrlPtr->AddColumn(&columnDescription,kDataBrowserListViewAppendColumn) == noErr,false,_("Column could not be added."));
// final adjustments for the layout:
if (dataViewColumnPtr->GetWidth() <= 0)
{
// variable definition:
UInt16 defaultColumnWidth;
MacDataViewListCtrlPtr->GetDefaultColumnWidth(&defaultColumnWidth);
dataViewColumnPtr->SetWidth(defaultColumnWidth);
} /* if */
verify_noerr(MacDataViewListCtrlPtr->SetColumnWidth(dataViewColumnPtr->GetPropertyID(),dataViewColumnPtr->GetWidth()));
if (dataViewColumnPtr->IsSortable()) // if the current column is sortable and there is no active sortable column yet, the new column will become active
{
// variable definition:
DataBrowserPropertyID sortedProperty;
dataViewColumnPtr->SetWidth(wxDVC_DEFAULT_WIDTH);
wxCHECK_MSG(MacDataViewListCtrlPtr->SetColumnWidth(NewPropertyID,dataViewColumnPtr->GetWidth()) == noErr,false,_("Column width could not be set."));
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);
if (this->GetColumnCount()-1 == this->GetExpanderColumn()) // if the current column is marked expandable this column will become the active expandable column
MacDataViewListCtrlPtr->SetDisclosureColumn(NewPropertyID,true);
if ((MacDataViewListCtrlPtr->GetSortProperty(&sortedProperty) == noErr) && (sortedProperty < kMinPropertyID))
MacDataViewListCtrlPtr->SetSortProperty(dataViewColumnPtr->GetPropertyID());
} /* if */
// now, make sure that data is shown in the newly appended column:
if ((this->GetModel() != NULL) && (this->m_NotifierPtr != NULL) && (dataViewColumnPtr->GetModelColumn() >= 0) && (dataViewColumnPtr->GetModelColumn() < this->GetModel()->GetColumnCount()))
if (this->GetColumnCount() == 1) // the newly appended column is the only one and this means that no data has been inserted yet, so do it now:
{
// variable definition:
DataBrowserItemID newID;
for (size_t i=0; i<this->GetModel()->GetRowCount(); ++i)
if (!((MacDataViewListCtrlPtr->GetFreeItemID(&newID) == noErr) && MacDataViewListCtrlPtr->InsertItemIDRowPair(newID,i) && (MacDataViewListCtrlPtr->AddItem(kDataBrowserNoItem,&newID) == noErr)))
return false;
} /* if */
else
for (size_t i=0; i<this->GetModel()->GetRowCount(); ++i)
(void) this->m_NotifierPtr->ValueChanged(dataViewColumnPtr->GetModelColumn(),i);
// 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 (this->GetColumnCount() == 1)
this->AddChildrenLevel(wxDataViewItem());
else
MacDataViewListCtrlPtr->UpdateItems(kDataBrowserNoItem,0,NULL,kDataBrowserItemNoProperty,NewPropertyID);
// done:
return true;
} /* if */
@ -945,149 +792,85 @@ bool wxDataViewCtrl::AppendColumn(wxDataViewColumn* dataViewColumnPtr)
return false;
} /* wxDataViewCtrl::AppendColumn(wxDataViewColumn*) */
int wxDataViewCtrl::GetSelection(void) const
wxDataViewItem wxDataViewCtrl::GetSelection(void)
{
wxArrayInt selectedRows;
if (this->GetSelections(selectedRows) > 0)
return selectedRows[0];
else
return wxNOT_FOUND;
} /* wxDataViewCtrl::GetSelection(void) const */
int wxDataViewCtrl::GetSelections(wxArrayInt& selectedRows) const
{
size_t NoOfSelections;
wxArrayDataBrowserItemID itemIDs;
wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
wxMacDataViewDataBrowserListViewControlPointer dataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
if (dataViewListCtrlPtr == NULL)
NoOfSelections = 0;
if (MacDataViewListCtrlPtr->GetSelectedItemIDs(itemIDs) > 0)
return wxDataViewItem(reinterpret_cast<void*>(itemIDs[0]));
else
NoOfSelections = dataViewListCtrlPtr->GetSelectedItemIDs(itemIDs);
selectedRows.Empty();
selectedRows.Alloc(NoOfSelections);
for (size_t i=0; i<NoOfSelections; ++i)
return wxDataViewItem();
} /* wxDataViewCtrl::GetSelection(void) */
bool wxDataViewCtrl::AssociateModel(wxDataViewModel* model)
{
if (!wxDataViewCtrlBase::AssociateModel(model))
return false;
this->m_NotifierPtr = new wxMacDataViewModelNotifier(dynamic_cast<wxMacDataViewDataBrowserListViewControl*>(this->m_peer));
model->AddNotifier(this->m_NotifierPtr);
return true;
} /* wxDataViewCtrl::AssociateModel(wxDataViewModel*) */
// data handling:
void wxDataViewCtrl::AddChildrenLevel(wxDataViewItem const& parentItem)
{
wxDataViewItem item;
wxCHECK_RET(this->GetModel() != NULL,_("Model pointer not initialized."));
item = this->GetModel()->GetFirstChild(parentItem);
while (item.IsOk())
{
// variable definition:
DataBrowserTableViewRowIndex rowIndex;
wxCHECK_MSG(dataViewListCtrlPtr->GetRowIndex(rowIndex,itemIDs[i]),0,_("Could not determine row index."));
selectedRows[i] = static_cast<int>(rowIndex);
} /* for */
return static_cast<int>(NoOfSelections);
} /* wxDataViewCtrl::GetSelections(wxArrayInt&) const */
(void) this->GetModel()->ItemAdded(parentItem,item);
item = this->GetModel()->GetNextSibling(item);
} /* while */
} /* wxDataViewCtrl::AddChildrenLevel(wxDataViewItem const&) */
bool wxDataViewCtrl::IsSelected(unsigned int row) const
// inherited methods from wxDataViewCtrlBase
void wxDataViewCtrl::DoSetExpanderColumn(void)
{
DataBrowserItemID itemID;
wxMacDataViewDataBrowserListViewControlPointer dataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
return ((dataViewListCtrlPtr != NULL) && (dataViewListCtrlPtr->GetItemID(row,&itemID) == noErr) && dataViewListCtrlPtr->IsItemSelected(itemID));
} /* wxDataViewCtrl::IsSelected(unsigned int row) const */
void wxDataViewCtrl::SetSelection(int row)
{
wxArrayDataBrowserItemID selectedItemIDs;
size_t NoOfSelections;
wxMacDataViewDataBrowserListViewControlPointer dataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
wxCHECK_RET(dataViewListCtrlPtr != NULL,_("Peer pointer not initialized."));
if (row == -1) // unselect all selected items
{
NoOfSelections = dataViewListCtrlPtr->GetSelectedItemIDs(selectedItemIDs);
for (size_t i=0; i<NoOfSelections; ++i)
(void) dataViewListCtrlPtr->SetSelectedItems(1,&(selectedItemIDs[i]),kDataBrowserItemsRemove);
} /* if */
else if (row >= 0) // select specified item
{
// variable definition:
DataBrowserItemID itemID;
verify_noerr(dataViewListCtrlPtr->GetItemID(row,&itemID));
verify_noerr(dataViewListCtrlPtr->SetSelectedItems(1,&itemID,kDataBrowserItemsAdd)); // should also deselect automatically all other items
} /* if */
} /* wxDataViewCtrl::SetSelection(int) */
void wxDataViewCtrl::SetSelectionRange(unsigned int from, unsigned int to)
{
wxCHECK_RET(from <= to,_("Invalid specified range ('from' has to be smaller or equal to 'to')."));
// variable definition:
wxArrayInt selectedRows;
selectedRows.Alloc(to-from+1);
for (unsigned int i=from; i<=to; ++i)
selectedRows.Add(i);
this->SetSelections(selectedRows);
} /* wxDataViewCtrl::SetSelectionRange(unsigned int, unsigned int) */
void wxDataViewCtrl::SetSelections(wxArrayInt const& selectedRows)
{
wxMacDataViewDataBrowserListViewControlPointer dataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
wxCHECK_RET(dataViewListCtrlPtr != NULL,_("Peer pointer not initialized."));
// unselect all selected items:
this->SetSelection(-1);
for (size_t i=0; i<selectedRows.GetCount(); ++i)
{
// variable definition:
DataBrowserItemID itemID;
verify_noerr(dataViewListCtrlPtr->GetItemID(selectedRows[i],&itemID));
verify_noerr(dataViewListCtrlPtr->SetSelectedItems(1,&itemID,kDataBrowserItemsAssign));
} /* if */
} /* wxDataViewCtrl::SetSelections(wxArrayInt const&) */
void wxDataViewCtrl::Unselect(unsigned int row)
{
DataBrowserItemID itemID;
wxMacDataViewDataBrowserListViewControlPointer dataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
wxCHECK_RET( dataViewListCtrlPtr != NULL, _("Peer pointer not initialized."));
wxCHECK_RET((dataViewListCtrlPtr->GetItemID(row,&itemID) == noErr) && (dataViewListCtrlPtr->SetSelectedItems(1,&itemID,kDataBrowserItemsRemove) == noErr),_("Unselection impossible."));
} /* wxDataViewCtrl::Unselect(unsigned int) */
void wxDataViewCtrl::ReverseSorting(DataBrowserPropertyID columnID)
{
if (columnID >= kMinPropertyID)
if (this->GetExpanderColumn() < this->GetColumnCount())
{
// variable definition and initialization:
DataBrowserPropertyID sortPropertyID;
wxMacDataViewDataBrowserListViewControlPointer dataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
DataBrowserPropertyID propertyID;
wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
wxCHECK_RET(dataViewListCtrlPtr != NULL,_("Peer pointer not initialized."));
wxCHECK_RET(dataViewListCtrlPtr->GetSortProperty(&sortPropertyID) == noErr,_("Determination of sort property impossible."));
if (sortPropertyID == columnID)
{
// variable defintion:
DataBrowserSortOrder sortOrderCtrl;
DataBrowserTableViewColumnID columnIndex;
wxDataViewColumn* dataViewColumnPtr;
wxCHECK_RET(dataViewListCtrlPtr->GetPropertyColumn(columnID,&columnIndex) == noErr,_("Determination of column index impossible"));
wxCHECK_RET(dataViewListCtrlPtr->GetSortOrder(&sortOrderCtrl) == noErr,_("Determination of sort order impossible"));
dataViewColumnPtr = this->GetColumn(columnIndex);
wxCHECK_RET(dataViewColumnPtr != NULL,_("Column could not be obtained."));
if ((sortOrderCtrl == kDataBrowserOrderIncreasing) && !(dataViewColumnPtr->IsSortOrderAscending()) ||
(sortOrderCtrl == kDataBrowserOrderDecreasing) && dataViewColumnPtr->IsSortOrderAscending())
dataViewListCtrlPtr->ReverseRowIndexNumbering();
} /* if */
if (MacDataViewListCtrlPtr->GetPropertyID(this->GetExpanderColumn(),&propertyID) == noErr)
(void) MacDataViewListCtrlPtr->SetDisclosureColumn(propertyID);
} /* if */
} /* wxDataViewCtrl::ReverseSorting(DataBrowserPropertyID columnID) */
} /* wxDataViewCtrl::DoSetExpanderColumn(void) */
void wxDataViewCtrl::DoSetIndent(void)
{
} /* wxDataViewCtrl::DoSetExpanderColumn(void) */
// event handling:
void wxDataViewCtrl::OnSize(wxSizeEvent& event)
{
unsigned int const NoOfColumns = this->GetColumnCount();
for (unsigned int i=0; i<NoOfColumns; ++i)
{
// variable definition and initialization:
wxDataViewColumn* dataViewColumnPtr(this->GetColumn(i));
if (dataViewColumnPtr != NULL)
{
// variable definition and initialization:
wxDataViewCustomRenderer* dataViewCustomRendererPtr(dynamic_cast<wxDataViewCustomRenderer*>(dataViewColumnPtr->GetRenderer()));
if (dataViewCustomRendererPtr != NULL)
dataViewCustomRendererPtr->SetDC(NULL); // reset DC because DC has changed
} /* if */
} /* for */
event.Skip();
} /* wxDataViewCtrl::OnSize(wxSizeEvent&) */
IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl,wxDataViewCtrlBase)