From: Vadim Zeitlin Date: Sat, 17 Oct 2009 01:04:20 +0000 (+0000) Subject: No changes, just attempts to make the code more readable. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/8e59cbe40ca6d003598e71c3c54d9a0c06bdff08 No changes, just attempts to make the code more readable. Reformat/reindent, use more wx coding style, wrap some extremely long lines. Use shorter and less Carbon-ish variable names. Clarify some comments. Also use static_cast<> because there is no need to use reinterpret_cast<> when a static_cast<> will do. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62435 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/osx/cocoa/dataview.h b/include/wx/osx/cocoa/dataview.h index 6efca71daf..ded2b5f9b7 100644 --- a/include/wx/osx/cocoa/dataview.h +++ b/include/wx/osx/cocoa/dataview.h @@ -12,11 +12,7 @@ #include "wx/defs.h" -#if wxUSE_GUI - -#ifdef __OBJC__ - #import -#endif +#import #include "wx/osx/core/dataview.h" #include "wx/osx/private.h" @@ -24,231 +20,217 @@ // Forward declaration class wxCocoaDataViewControl; +/* + Dramatis personae: + + [vertical arrows indicate inheritance, horizontal -- aggregation] + + + wxWindow ---> wxWidgetCocoaImpl wxDataViewWidgetImpl NSOutlineView + | \ / | + | \ / | + | \ / | + v \/ \/ v + wxDataViewCtrl -------> wxCocoaDataViewControl <-------> wxCocoaOutlineView + + + The right most classes are Objective-C only and can't be used from (pure) + C++ code. + */ + // ============================================================================ -// wxPointerObject +// wxPointerObject: simply stores a pointer, without taking its ownership // ============================================================================ -// -// This is a helper class to store a pointer in an object. This object just -// stores the pointer but does not take any ownership. -// To pointer objects are equal if the containing pointers are equal. This + +// Two pointer objects are equal if the containing pointers are equal. This // means also that the hash value of a pointer object depends only on the // stored pointer. -// + @interface wxPointerObject : NSObject { - void* pointer; + void* pointer; } - // - // object initialization - // - -(id) initWithPointer:(void*)initPointer; - - // - // access to pointer - // - -(void*) pointer; - -(void) setPointer:(void*)newPointer; + -(id) initWithPointer:(void*)initPointer; + -(void*) pointer; + -(void) setPointer:(void*)newPointer; @end // ============================================================================ -// wxSortDescriptorObject +// wxSortDescriptorObject: helper class to use native sorting facilities // ============================================================================ -// -// This is a helper class to use native sorting facilities. -// + @interface wxSortDescriptorObject : NSSortDescriptor { - wxDataViewColumn* columnPtr; // pointer to the sorting column + wxDataViewColumn* columnPtr; // pointer to the sorting column - wxDataViewModel* modelPtr; // pointer to model + wxDataViewModel* modelPtr; // pointer to model } - // - // initialization - // - -(id) initWithModelPtr:(wxDataViewModel*)initModelPtr sortingColumnPtr:(wxDataViewColumn*)initColumnPtr ascending:(BOOL)sortAscending; + -(id) + initWithModelPtr:(wxDataViewModel*)initModelPtr + sortingColumnPtr:(wxDataViewColumn*)initColumnPtr + ascending:(BOOL)sortAscending; - // - // access to variables - // - -(wxDataViewColumn*) columnPtr; - -(wxDataViewModel*) modelPtr; - - -(void) setColumnPtr:(wxDataViewColumn*)newColumnPtr; - -(void) setModelPtr:(wxDataViewModel*)newModelPtr; + -(wxDataViewColumn*) columnPtr; + -(wxDataViewModel*) modelPtr; + -(void) setColumnPtr:(wxDataViewColumn*)newColumnPtr; + -(void) setModelPtr:(wxDataViewModel*)newModelPtr; @end // ============================================================================ -// wxDataViewColumnNativeData +// wxDataViewColumnNativeData: extra data for wxDataViewColumn // ============================================================================ + class wxDataViewColumnNativeData { public: -// -// constructors / destructor -// - wxDataViewColumnNativeData(void) : m_NativeColumnPtr(NULL) - { - } - wxDataViewColumnNativeData(NSTableColumn* initNativeColumnPtr) : m_NativeColumnPtr(initNativeColumnPtr) - { - } + wxDataViewColumnNativeData() : m_NativeColumnPtr(NULL) + { + } -// -// data access methods -// - NSTableColumn* GetNativeColumnPtr() const - { - return m_NativeColumnPtr; - } + wxDataViewColumnNativeData(NSTableColumn* initNativeColumnPtr) + : m_NativeColumnPtr(initNativeColumnPtr) + { + } - void SetNativeColumnPtr(NSTableColumn* newNativeColumnPtr) - { - m_NativeColumnPtr = newNativeColumnPtr; - } + NSTableColumn* GetNativeColumnPtr() const + { + return m_NativeColumnPtr; + } + + void SetNativeColumnPtr(NSTableColumn* newNativeColumnPtr) + { + m_NativeColumnPtr = newNativeColumnPtr; + } -protected: private: -// -// variables -// - NSTableColumn* m_NativeColumnPtr; // this class does not take over ownership of the pointer nor retains it + // not owned by us + NSTableColumn* m_NativeColumnPtr; }; // ============================================================================ -// wxDataViewRendererNativeData +// wxDataViewRendererNativeData: extra data for wxDataViewRenderer // ============================================================================ + class wxDataViewRendererNativeData { public: -// -// constructors / destructor -// - wxDataViewRendererNativeData(void) : m_Object(NULL), m_ColumnCell(NULL) - { - Init(); - } - wxDataViewRendererNativeData(NSCell* initColumnCell) : m_Object(NULL), m_ColumnCell([initColumnCell retain]) - { - Init(); - } - wxDataViewRendererNativeData(NSCell* initColumnCell, id initObject) : m_Object([initObject retain]), m_ColumnCell([initColumnCell retain]) - { - Init(); - } - - ~wxDataViewRendererNativeData() - { - [m_ColumnCell release]; - [m_Object release]; - - [m_origFont release]; - [m_origTextColour release]; - } - - // - // data access methods - // - NSCell* GetColumnCell() const - { - return m_ColumnCell; - } - NSTableColumn* GetColumnPtr() const - { - return m_TableColumnPtr; - } - id GetItem() const - { - return m_Item; - } - NSCell* GetItemCell() const - { - return m_ItemCell; - } - id GetObject() const - { - return m_Object; - } - - void SetColumnCell(NSCell* newCell) - { - [newCell retain]; - [m_ColumnCell release]; - m_ColumnCell = newCell; - } - void SetColumnPtr(NSTableColumn* newColumnPtr) - { - m_TableColumnPtr = newColumnPtr; - } - void SetItem(id newItem) - { - m_Item = newItem; - } - void SetItemCell(NSCell* newCell) - { - m_ItemCell = newCell; - } - void SetObject(id newObject) - { - [newObject retain]; - [m_Object release]; - m_Object = newObject; - } - - // The original cell font and text colour stored here are NULL by default and - // are only initialized to the values retrieved from the cell when we change - // them from wxCocoaOutlineView:willDisplayCell:forTableColumn:item: which - // calls our SaveOriginalXXX() methods before changing the cell attributes. - // - // This allows us to avoid doing anything for the columns without any - // attributes but still be able to restore the correct attributes for the - // ones that do. - NSFont *GetOriginalFont() const { return m_origFont; } - NSColor *GetOriginalTextColour() const { return m_origTextColour; } - - void SaveOriginalFont(NSFont *font) - { - m_origFont = [font retain]; - } - - void SaveOriginalTextColour(NSColor *textColour) - { - m_origTextColour = [textColour retain]; - } - - // The ellipsization mode which we need to set for each cell being rendered. - void SetEllipsizeMode(wxEllipsizeMode mode) { m_ellipsizeMode = mode; } - wxEllipsizeMode GetEllipsizeMode() const { return m_ellipsizeMode; } - - // Set the line break mode for the given cell using our m_ellipsizeMode - void ApplyLineBreakMode(NSCell *cell); + wxDataViewRendererNativeData() + : m_Object(NULL), m_ColumnCell(NULL) + { + Init(); + } + + wxDataViewRendererNativeData(NSCell* initColumnCell) + : m_Object(NULL), m_ColumnCell([initColumnCell retain]) + { + Init(); + } + + wxDataViewRendererNativeData(NSCell* initColumnCell, id initObject) + : m_Object([initObject retain]), m_ColumnCell([initColumnCell retain]) + { + Init(); + } + + ~wxDataViewRendererNativeData() + { + [m_ColumnCell release]; + [m_Object release]; + + [m_origFont release]; + [m_origTextColour release]; + } + + NSCell* GetColumnCell() const { return m_ColumnCell; } + NSTableColumn* GetColumnPtr() const { return m_TableColumnPtr; } + id GetItem() const { return m_Item; } + NSCell* GetItemCell() const { return m_ItemCell; } + id GetObject() const { return m_Object; } + + void SetColumnCell(NSCell* newCell) + { + [newCell retain]; + [m_ColumnCell release]; + m_ColumnCell = newCell; + } + void SetColumnPtr(NSTableColumn* newColumnPtr) + { + m_TableColumnPtr = newColumnPtr; + } + void SetItem(id newItem) + { + m_Item = newItem; + } + void SetItemCell(NSCell* newCell) + { + m_ItemCell = newCell; + } + void SetObject(id newObject) + { + [newObject retain]; + [m_Object release]; + m_Object = newObject; + } + + // The original cell font and text colour stored here are NULL by default + // and are only initialized to the values retrieved from the cell when we + // change them from wxCocoaOutlineView:willDisplayCell:forTableColumn:item: + // which calls our SaveOriginalXXX() methods before changing the cell + // attributes. + // + // This allows us to avoid doing anything for the columns without any + // attributes but still be able to restore the correct attributes for the + // ones that do. + NSFont *GetOriginalFont() const { return m_origFont; } + NSColor *GetOriginalTextColour() const { return m_origTextColour; } + + void SaveOriginalFont(NSFont *font) + { + m_origFont = [font retain]; + } + + void SaveOriginalTextColour(NSColor *textColour) + { + m_origTextColour = [textColour retain]; + } + + // The ellipsization mode which we need to set for each cell being rendered. + void SetEllipsizeMode(wxEllipsizeMode mode) { m_ellipsizeMode = mode; } + wxEllipsizeMode GetEllipsizeMode() const { return m_ellipsizeMode; } + + // Set the line break mode for the given cell using our m_ellipsizeMode + void ApplyLineBreakMode(NSCell *cell); private: - // common part of all ctors - void Init(); + // common part of all ctors + void Init(); - id m_Item; // item NOT owned by renderer - id m_Object; // object that can be used by renderer for storing special data (owned by renderer) + id m_Item; // item NOT owned by renderer - NSCell* m_ColumnCell; // column's cell is owned by renderer - NSCell* m_ItemCell; // item's cell is NOT owned by renderer + // object that can be used by renderer for storing special data (owned by + // renderer) + id m_Object; - NSTableColumn* m_TableColumnPtr; // column NOT owned by renderer + NSCell* m_ColumnCell; // column's cell is owned by renderer + NSCell* m_ItemCell; // item's cell is NOT owned by renderer - // we own those if they're non-NULL - NSFont *m_origFont; - NSColor *m_origTextColour; + NSTableColumn* m_TableColumnPtr; // column NOT owned by renderer - wxEllipsizeMode m_ellipsizeMode; + // we own those if they're non-NULL + NSFont *m_origFont; + NSColor *m_origTextColour; + + wxEllipsizeMode m_ellipsizeMode; }; // ============================================================================ // wxCocoaOutlineDataSource // ============================================================================ -// + // This class implements the data source delegate for the outline view. // As only an informal protocol exists this class inherits from NSObject only. // @@ -270,92 +252,105 @@ private: // @interface wxCocoaOutlineDataSource : NSObject { - NSArray* sortDescriptors; // descriptors specifying the sorting (currently the array only holds one object only) + // descriptors specifying the sorting (currently the array only holds one + // object only) + NSArray* sortDescriptors; - NSMutableArray* children; // buffered children + NSMutableArray* children; // buffered children - NSMutableSet* items; // stores all items that are in use by the control + NSMutableSet* items; // stores all items that are in use by the control - wxCocoaDataViewControl* implementation; + wxCocoaDataViewControl* implementation; - wxDataViewModel* model; + wxDataViewModel* model; - wxPointerObject* currentParentItem; // parent of the buffered children; the object is owned + // parent of the buffered children; the object is owned + wxPointerObject* currentParentItem; } - // - // methods of informal protocol: - // - -(BOOL) outlineView:(NSOutlineView*)outlineView acceptDrop:(id)info item:(id)item childIndex:(NSInteger)index; - -(id) outlineView:(NSOutlineView*)outlineView child:(NSInteger)index ofItem:(id)item; - -(id) outlineView:(NSOutlineView*)outlineView objectValueForTableColumn:(NSTableColumn*)tableColumn byItem:(id)item; - -(BOOL) outlineView:(NSOutlineView*)outlineView isItemExpandable:(id)item; - -(NSInteger) outlineView:(NSOutlineView*)outlineView numberOfChildrenOfItem:(id)item; - -(NSDragOperation) outlineView:(NSOutlineView*)outlineView validateDrop:(id)info proposedItem:(id)item proposedChildIndex:(NSInteger)index; - -(BOOL) outlineView:(NSOutlineView*)outlineView writeItems:(NSArray*)items toPasteboard:(NSPasteboard*)pasteboard; - - // - // buffer for items handling - // - -(void) addToBuffer:(wxPointerObject*)item; - -(void) clearBuffer; - -(wxPointerObject*) getDataViewItemFromBuffer:(wxDataViewItem const&)item; // returns the item in the buffer that has got the same pointer as "item", - -(wxPointerObject*) getItemFromBuffer:(wxPointerObject*)item; // if such an item does not exist nil is returned - -(BOOL) isInBuffer:(wxPointerObject*)item; - -(void) removeFromBuffer:(wxPointerObject*)item; - - // - // buffered children handling - // - -(void) appendChild:(wxPointerObject*)item; - -(void) clearChildren; - -(wxPointerObject*) getChild:(NSUInteger)index; - -(NSUInteger) getChildCount; - -(void) removeChild:(NSUInteger)index; - - // - // buffer handling - // - -(void) clearBuffers; - - // - // sorting - // - -(NSArray*) sortDescriptors; - -(void) setSortDescriptors:(NSArray*)newSortDescriptors; - - // - // access to wxWidget's variables - // - -(wxPointerObject*) currentParentItem; - -(wxCocoaDataViewControl*) implementation; - -(wxDataViewModel*) model; - -(void) setCurrentParentItem:(wxPointerObject*)newCurrentParentItem; - -(void) setImplementation:(wxCocoaDataViewControl*)newImplementation; - -(void) setModel:(wxDataViewModel*)newModel; - - // - // other methods - // - -(void) bufferItem:(wxPointerObject*)parentItem withChildren:(wxDataViewItemArray*)dataViewChildrenPtr; - + // methods of informal protocol: + -(BOOL) + outlineView:(NSOutlineView*)outlineView + acceptDrop:(id)info + item:(id)item + childIndex:(NSInteger)index; + + -(id) + outlineView:(NSOutlineView*)outlineView + child:(NSInteger)index + ofItem:(id)item; + + -(id) + outlineView:(NSOutlineView*)outlineView + objectValueForTableColumn:(NSTableColumn*)tableColumn + byItem:(id)item; + + -(BOOL) + outlineView:(NSOutlineView*)outlineView + isItemExpandable:(id)item; + + -(NSInteger) + outlineView:(NSOutlineView*)outlineView + numberOfChildrenOfItem:(id)item; + + -(NSDragOperation) + outlineView:(NSOutlineView*)outlineView + validateDrop:(id)info + proposedItem:(id)item + proposedChildIndex:(NSInteger)index; + + -(BOOL) + outlineView:(NSOutlineView*)outlineView + writeItems:(NSArray*)items + toPasteboard:(NSPasteboard*)pasteboard; + + // buffer for items handling + -(void) addToBuffer:(wxPointerObject*)item; + -(void) clearBuffer; + // returns the item in the buffer that has got the same pointer as "item", + // if such an item does not exist nil is returned + -(wxPointerObject*) getDataViewItemFromBuffer:(const wxDataViewItem&)item; + -(wxPointerObject*) getItemFromBuffer:(wxPointerObject*)item; + -(BOOL) isInBuffer:(wxPointerObject*)item; + -(void) removeFromBuffer:(wxPointerObject*)item; + + // buffered children handling + -(void) appendChild:(wxPointerObject*)item; + -(void) clearChildren; + -(wxPointerObject*) getChild:(NSUInteger)index; + -(NSUInteger) getChildCount; + -(void) removeChild:(NSUInteger)index; + + // buffer handling + -(void) clearBuffers; + + // sorting + -(NSArray*) sortDescriptors; + -(void) setSortDescriptors:(NSArray*)newSortDescriptors; + + // access to wxWidgets variables + -(wxPointerObject*) currentParentItem; + -(wxCocoaDataViewControl*) implementation; + -(wxDataViewModel*) model; + -(void) setCurrentParentItem:(wxPointerObject*)newCurrentParentItem; + -(void) setImplementation:(wxCocoaDataViewControl*)newImplementation; + -(void) setModel:(wxDataViewModel*)newModel; + + // other methods + -(void) + bufferItem:(wxPointerObject*)parentItem + withChildren:(wxDataViewItemArray*)dataViewChildrenPtr; @end // ============================================================================ -// wxCustomCell +// wxCustomCell: used for custom renderers // ============================================================================ -// -// This is a cell that is used for custom renderers. -// + @interface wxCustomCell : NSTextFieldCell { } - // - // other methods - // - -(NSSize) cellSize; - + -(NSSize) cellSize; @end // ============================================================================ @@ -376,161 +371,137 @@ private: @interface wxImageTextCell : NSTextFieldCell { @private - CGFloat xImageShift; // shift for the image in x-direction from border - CGFloat spaceImageText; // space between image and text ("belongs" to the image) + CGFloat xImageShift; // shift for the image in x-direction from border + CGFloat spaceImageText; // space between image and text - NSImage* image; // the image itself + NSImage* image; // the image itself - NSSize imageSize; // largest size of the image; default size is (16, 16) + NSSize imageSize; // largest size of the image; default size is (16, 16) - NSTextAlignment cellAlignment; // the text alignment is used to align the whole - // cell (image and text) + // the text alignment is used to align the whole cell (image and text) + NSTextAlignment cellAlignment; } - // - // alignment - // - -(NSTextAlignment) alignment; - -(void) setAlignment:(NSTextAlignment)newAlignment; - - // - // image access - // - -(NSImage*) image; - -(void) setImage:(NSImage*)newImage; - - // - // size access - // - -(NSSize) imageSize; - -(void) setImageSize:(NSSize) newImageSize; - - // - // other methods - // - -(NSSize) cellSize; + -(NSTextAlignment) alignment; + -(void) setAlignment:(NSTextAlignment)newAlignment; + + -(NSImage*) image; + -(void) setImage:(NSImage*)newImage; + -(NSSize) imageSize; + -(void) setImageSize:(NSSize) newImageSize; + + -(NSSize) cellSize; @end // ============================================================================ // wxCocoaOutlineView // ============================================================================ + @interface wxCocoaOutlineView : NSOutlineView { @private - // column and row of the cell being edited or -1 if none - int currentlyEditedColumn, - currentlyEditedRow; + // column and row of the cell being edited or -1 if none + int currentlyEditedColumn, + currentlyEditedRow; - wxCocoaDataViewControl* implementation; + wxCocoaDataViewControl* implementation; } - // - // access to wxWidget's implementation - // - -(wxCocoaDataViewControl*) implementation; - -(void) setImplementation:(wxCocoaDataViewControl*) newImplementation; - + -(wxCocoaDataViewControl*) implementation; + -(void) setImplementation:(wxCocoaDataViewControl*) newImplementation; @end // ============================================================================ // wxCocoaDataViewControl // ============================================================================ -// + // This is the internal interface class between wxDataViewCtrl (wxWidget) and // the native source view (Mac OS X cocoa). -// -class wxCocoaDataViewControl : public wxWidgetCocoaImpl, public wxDataViewWidgetImpl +class wxCocoaDataViewControl : public wxWidgetCocoaImpl, + public wxDataViewWidgetImpl { public: - // - // constructors / destructor - // - wxCocoaDataViewControl(wxWindow* peer, wxPoint const& pos, wxSize const& size, long style); - ~wxCocoaDataViewControl(); - - // - // column related methods (inherited from wxDataViewWidgetImpl) - // - virtual bool ClearColumns (); - virtual bool DeleteColumn (wxDataViewColumn* columnPtr); - virtual void DoSetExpanderColumn(wxDataViewColumn const* columnPtr); - virtual wxDataViewColumn* GetColumn (unsigned int pos) const; - virtual int GetColumnPosition (wxDataViewColumn const* columnPtr) const; - virtual bool InsertColumn (unsigned int pos, wxDataViewColumn* columnPtr); - - // - // item related methods (inherited from wxDataViewWidgetImpl) - // - virtual bool Add (wxDataViewItem const& parent, wxDataViewItem const& item); - virtual bool Add (wxDataViewItem const& parent, wxDataViewItemArray const& items); - virtual void Collapse (wxDataViewItem const& item); - virtual void EnsureVisible(wxDataViewItem const& item, wxDataViewColumn const* columnPtr); - virtual void Expand (wxDataViewItem const& item); - virtual unsigned int GetCount () const; - virtual wxRect GetRectangle (wxDataViewItem const& item, wxDataViewColumn const* columnPtr); - virtual bool IsExpanded (wxDataViewItem const& item) const; - virtual bool Reload (); - virtual bool Remove (wxDataViewItem const& parent, wxDataViewItem const& item); - virtual bool Remove (wxDataViewItem const& parent, wxDataViewItemArray const& item); - virtual bool Update (wxDataViewColumn const* columnPtr); - virtual bool Update (wxDataViewItem const& parent, wxDataViewItem const& item); - virtual bool Update (wxDataViewItem const& parent, wxDataViewItemArray const& items); - - // - // model related methods - // - virtual bool AssociateModel(wxDataViewModel* model); // informs the native control that a model is present - - // - // selection related methods (inherited from wxDataViewWidgetImpl) - // - virtual int GetSelections(wxDataViewItemArray& sel) const; - virtual bool IsSelected (wxDataViewItem const& item) const; - virtual void Select (wxDataViewItem const& item); - virtual void SelectAll (); - virtual void Unselect (wxDataViewItem const& item); - virtual void UnselectAll (); - - // - // sorting related methods - // - virtual wxDataViewColumn* GetSortingColumn () const; - virtual void Resort (); - - // - // other methods (inherited from wxDataViewWidgetImpl) - // - virtual void DoSetIndent (int indent); - virtual void HitTest (wxPoint const& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const; - virtual void SetRowHeight(wxDataViewItem const& item, unsigned int height); - virtual void OnSize (); - - // - // other methods - // - wxDataViewCtrl* GetDataViewCtrl() const - { - return dynamic_cast(GetWXPeer()); - } + // constructors / destructor + wxCocoaDataViewControl(wxWindow* peer, + const wxPoint& pos, + const wxSize& size, + long style); + virtual ~wxCocoaDataViewControl(); + + wxDataViewCtrl* GetDataViewCtrl() const + { + return static_cast(GetWXPeer()); + } + + // column related methods (inherited from wxDataViewWidgetImpl) + virtual bool ClearColumns(); + virtual bool DeleteColumn(wxDataViewColumn* columnPtr); + virtual void DoSetExpanderColumn(wxDataViewColumn const* columnPtr); + virtual wxDataViewColumn* GetColumn(unsigned int pos) const; + virtual int GetColumnPosition(wxDataViewColumn const* columnPtr) const; + virtual bool InsertColumn(unsigned int pos, wxDataViewColumn* columnPtr); + + // item related methods (inherited from wxDataViewWidgetImpl) + virtual bool Add(const wxDataViewItem& parent, const wxDataViewItem& item); + virtual bool Add(const wxDataViewItem& parent, + const wxDataViewItemArray& items); + virtual void Collapse(const wxDataViewItem& item); + virtual void EnsureVisible(const wxDataViewItem& item, + wxDataViewColumn const* columnPtr); + virtual void Expand(const wxDataViewItem& item); + virtual unsigned int GetCount() const; + virtual wxRect GetRectangle(const wxDataViewItem& item, + wxDataViewColumn const* columnPtr); + virtual bool IsExpanded(const wxDataViewItem& item) const; + virtual bool Reload(); + virtual bool Remove(const wxDataViewItem& parent, + const wxDataViewItem& item); + virtual bool Remove(const wxDataViewItem& parent, + const wxDataViewItemArray& item); + virtual bool Update(const wxDataViewColumn* columnPtr); + virtual bool Update(const wxDataViewItem& parent, + const wxDataViewItem& item); + virtual bool Update(const wxDataViewItem& parent, + const wxDataViewItemArray& items); + + // model related methods + virtual bool AssociateModel(wxDataViewModel* model); + + // + // selection related methods (inherited from wxDataViewWidgetImpl) + // + virtual int GetSelections(wxDataViewItemArray& sel) const; + virtual bool IsSelected(const wxDataViewItem& item) const; + virtual void Select(const wxDataViewItem& item); + virtual void SelectAll(); + virtual void Unselect(const wxDataViewItem& item); + virtual void UnselectAll(); + + // + // sorting related methods + // + virtual wxDataViewColumn* GetSortingColumn () const; + virtual void Resort(); + + // + // other methods (inherited from wxDataViewWidgetImpl) + // + virtual void DoSetIndent(int indent); + virtual void HitTest(const wxPoint& point, + wxDataViewItem& item, + wxDataViewColumn*& columnPtr) const; + virtual void SetRowHeight(const wxDataViewItem& item, unsigned int height); + virtual void OnSize(); + + // drag & drop helper methods + wxDataFormat GetDnDDataFormat(wxDataObjectComposite* dataObjects); + wxDataObjectComposite* GetDnDDataObjects(NSData* dataObject) const; -// -// drag & drop helper methods -// - wxDataFormat GetDnDDataFormat(wxDataObjectComposite* dataObjects); - wxDataObjectComposite* GetDnDDataObjects(NSData* dataObject) const; // create the data objects from the native dragged object -protected: private: -// -// variables -// - wxCocoaOutlineDataSource* m_DataSource; + wxCocoaOutlineDataSource* m_DataSource; - wxCocoaOutlineView* m_OutlineView; + wxCocoaOutlineView* m_OutlineView; }; -typedef wxCocoaDataViewControl* wxCocoaDataViewControlPointer; - - -#endif // wxUSE_GUI #endif // _WX_DATAVIEWCTRL_COCOOA_H_ diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index 9ecff40856..c5b3635ad9 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -25,10 +25,10 @@ #include "wx/osx/private.h" #include "wx/renderer.h" - // ============================================================================ // Constants used locally // ============================================================================ + #define DataViewPboardType @"OutlineViewItem" // ============================================================================ @@ -37,184 +37,186 @@ @interface wxCustomRendererObject : NSObject { @public - wxDataViewCustomRenderer* customRenderer; // not owned by the class + wxDataViewCustomRenderer* customRenderer; // not owned by the class } - // - // initialization - // - -(id) init; - -(id) initWithRenderer:(wxDataViewCustomRenderer*)renderer; - + -(id) init; + -(id) initWithRenderer:(wxDataViewCustomRenderer*)renderer; @end @implementation wxCustomRendererObject -// -// initialization -// + -(id) init { - self = [super init]; - if (self != nil) - { - customRenderer = NULL; - } - return self; + self = [super init]; + if (self != nil) + { + customRenderer = NULL; + } + return self; } -(id) initWithRenderer:(wxDataViewCustomRenderer*)renderer { - self = [super init]; - if (self != nil) - { - customRenderer = renderer; - } - return self; + self = [super init]; + if (self != nil) + { + customRenderer = renderer; + } + return self; } -(id) copyWithZone:(NSZone*)zone { - wxCustomRendererObject* copy; + wxCustomRendererObject* copy; - copy = [[[self class] allocWithZone:zone] init]; - copy->customRenderer = customRenderer; + copy = [[[self class] allocWithZone:zone] init]; + copy->customRenderer = customRenderer; - return copy; + return copy; } - @end // ============================================================================ -// Functions used locally in dataview.mm +// local helpers // ============================================================================ -static NSInteger CompareItems(id item1, id item2, void* context) -{ - NSArray* const sortDescriptors = (NSArray*) context; - - NSUInteger const noOfDescriptors = [sortDescriptors count]; - - NSInteger result(NSOrderedAscending); +namespace +{ - for (NSUInteger i=0; iCompare(wxDataViewItem([((wxPointerObject*) item1) pointer]), - wxDataViewItem([((wxPointerObject*) item2) pointer]), - [sortDescriptor columnPtr]->GetModelColumn(), - [sortDescriptor ascending] == YES); - if (wxComparisonResult < 0) - { - result = NSOrderedAscending; - break; - } - else if (wxComparisonResult > 0) + NSInteger result = NSOrderedSame; + for ( NSUInteger i = 0; i < count && result == NSOrderedSame; ++i ) { - result = NSOrderedDescending; - break; + // constant definition for abbreviational purposes: + wxSortDescriptorObject* const + sortDescriptor = (wxSortDescriptorObject*) + [sortDescriptors objectAtIndex:i]; + + int rc = [sortDescriptor modelPtr]->Compare + ( + wxDataViewItem([((wxPointerObject*) item1) pointer]), + wxDataViewItem([((wxPointerObject*) item2) pointer]), + [sortDescriptor columnPtr]->GetModelColumn(), + [sortDescriptor ascending] == YES + ); + + if ( rc < 0 ) + result = NSOrderedAscending; + else if ( rc > 0 ) + result = NSOrderedDescending; } - else - result = NSOrderedSame; - } - return result; + + return result; } -static NSTextAlignment ConvertToNativeHorizontalTextAlignment(int alignment) +NSTextAlignment ConvertToNativeHorizontalTextAlignment(int alignment) { - if (alignment & wxALIGN_CENTER_HORIZONTAL) // center alignment is chosen also if alignment is equal to -1 - return NSCenterTextAlignment; - else if (alignment & wxALIGN_RIGHT) - return NSRightTextAlignment; - else - return NSLeftTextAlignment; + if (alignment & wxALIGN_CENTER_HORIZONTAL) + return NSCenterTextAlignment; + else if (alignment & wxALIGN_RIGHT) + return NSRightTextAlignment; + else + return NSLeftTextAlignment; } -static NSTableColumn* CreateNativeColumn(wxDataViewColumn const* columnPtr) +NSTableColumn* CreateNativeColumn(const wxDataViewColumn *column) { - NSTableColumn* nativeColumn([[NSTableColumn alloc] initWithIdentifier:[[[wxPointerObject alloc] initWithPointer:const_cast(columnPtr)] autorelease]]); + wxDataViewRenderer * const renderer = column->GetRenderer(); + + wxCHECK_MSG( renderer, NULL, "column should have a renderer" ); + NSTableColumn * const nativeColumn( + [[NSTableColumn alloc] initWithIdentifier: + [[[wxPointerObject alloc] initWithPointer: + const_cast(column)] + autorelease]] + ); - // initialize the native column: - if ((nativeColumn != NULL) && (columnPtr->GetRenderer() != NULL)) - { - // setting the size related parameters: - if (columnPtr->IsResizeable()) + // setting the size related parameters: + if (column->IsResizeable()) { - [nativeColumn setResizingMask:NSTableColumnUserResizingMask]; - [nativeColumn setMinWidth:columnPtr->GetMinWidth()]; - [nativeColumn setMaxWidth:columnPtr->GetMaxWidth()]; + [nativeColumn setResizingMask:NSTableColumnUserResizingMask]; + [nativeColumn setMinWidth:column->GetMinWidth()]; + [nativeColumn setMaxWidth:column->GetMaxWidth()]; } else { - [nativeColumn setResizingMask:NSTableColumnNoResizing]; - [nativeColumn setMinWidth:columnPtr->GetWidth()]; - [nativeColumn setMaxWidth:columnPtr->GetWidth()]; + [nativeColumn setResizingMask:NSTableColumnNoResizing]; + [nativeColumn setMinWidth:column->GetWidth()]; + [nativeColumn setMaxWidth:column->GetWidth()]; } - [nativeColumn setWidth:columnPtr->GetWidth()]; + [nativeColumn setWidth:column->GetWidth()]; + #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 - // setting the visibility: - [nativeColumn setHidden:static_cast(columnPtr->IsHidden())]; + // setting the visibility: + [nativeColumn setHidden:static_cast(column->IsHidden())]; #endif - wxDataViewRendererNativeData * const - renderData = columnPtr->GetRenderer()->GetNativeData(); + wxDataViewRendererNativeData * const renderData = renderer->GetNativeData(); - // setting the header: - [[nativeColumn headerCell] setAlignment:ConvertToNativeHorizontalTextAlignment(columnPtr->GetAlignment())]; - [[nativeColumn headerCell] setStringValue:[[wxCFStringRef(columnPtr->GetTitle()).AsNSString() retain] autorelease]]; + // setting the header: + [[nativeColumn headerCell] setAlignment: + ConvertToNativeHorizontalTextAlignment(column->GetAlignment())]; + [[nativeColumn headerCell] setStringValue: + [[wxCFStringRef(column->GetTitle()).AsNSString() retain] autorelease]]; renderData->ApplyLineBreakMode([nativeColumn headerCell]); - // setting data cell's properties: + // setting data cell's properties: [[nativeColumn dataCell] setWraps:NO]; - // setting the default data cell: + // setting the default data cell: [nativeColumn setDataCell:renderData->GetColumnCell()]; - // setting the editablility: - bool const dataCellIsEditable = (columnPtr->GetRenderer()->GetMode() == wxDATAVIEW_CELL_EDITABLE); + // setting the editablility: + const bool isEditable = renderer->GetMode() == wxDATAVIEW_CELL_EDITABLE; - [nativeColumn setEditable:dataCellIsEditable]; - [[nativeColumn dataCell] setEditable:dataCellIsEditable]; - } - // done: - return nativeColumn; + [nativeColumn setEditable:isEditable]; + [[nativeColumn dataCell] setEditable:isEditable]; + + return nativeColumn; } +} // anonymous namespace + // ============================================================================ // Public helper functions for dataview implementation on OSX // ============================================================================ -wxWidgetImplType* CreateDataView(wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(parent), wxWindowID WXUNUSED(id), wxPoint const& pos, wxSize const& size, - long style, long WXUNUSED(extraStyle)) + +wxWidgetImplType* CreateDataView(wxWindowMac* wxpeer, + wxWindowMac* WXUNUSED(parent), + wxWindowID WXUNUSED(id), + const wxPoint& pos, + const wxSize& size, + long style, + long WXUNUSED(extraStyle)) { - return new wxCocoaDataViewControl(wxpeer,pos,size,style); + return new wxCocoaDataViewControl(wxpeer,pos,size,style); } // ============================================================================ // wxPointerObject // ============================================================================ -// -// This is a helper class to store a pointer in an object. -// + @implementation wxPointerObject -// -// object initialization -// + -(id) init { - self = [super init]; - if (self != nil) - self->pointer = NULL; - return self; + self = [super init]; + if (self != nil) + self->pointer = NULL; + return self; } -(id) initWithPointer:(void*) initPointer { - self = [super init]; - if (self != nil) - self->pointer = initPointer; - return self; + self = [super init]; + if (self != nil) + self->pointer = initPointer; + return self; } // @@ -222,25 +224,24 @@ wxWidgetImplType* CreateDataView(wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(pare // -(BOOL) isEqual:(id)object { - return (object != nil) && ([object isKindOfClass:[wxPointerObject class]]) && (pointer == [((wxPointerObject*) object) pointer]); + return (object != nil) && + ([object isKindOfClass:[wxPointerObject class]]) && + (pointer == [((wxPointerObject*) object) pointer]); } -(NSUInteger) hash { - return (NSUInteger) pointer; + return (NSUInteger) pointer; } -// -// access to pointer -// -(void*) pointer { - return pointer; + return pointer; } -(void) setPointer:(void*) newPointer { - pointer = newPointer; + pointer = newPointer; } @end @@ -248,42 +249,43 @@ wxWidgetImplType* CreateDataView(wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(pare // ============================================================================ // wxSortDescriptorObject // ============================================================================ + @implementation wxSortDescriptorObject -// -// initialization -// -(id) init { - self = [super init]; - if (self != nil) - { - columnPtr = NULL; - modelPtr = NULL; - } - return self; + self = [super init]; + if (self != nil) + { + columnPtr = NULL; + modelPtr = NULL; + } + return self; } --(id) initWithModelPtr:(wxDataViewModel*)initModelPtr sortingColumnPtr:(wxDataViewColumn*)initColumnPtr ascending:(BOOL)sortAscending +-(id) +initWithModelPtr:(wxDataViewModel*)initModelPtr + sortingColumnPtr:(wxDataViewColumn*)initColumnPtr + ascending:(BOOL)sortAscending { - self = [super initWithKey:@"dummy" ascending:sortAscending]; - if (self != nil) - { - columnPtr = initColumnPtr; - modelPtr = initModelPtr; - } - return self; + self = [super initWithKey:@"dummy" ascending:sortAscending]; + if (self != nil) + { + columnPtr = initColumnPtr; + modelPtr = initModelPtr; + } + return self; } -(id) copyWithZone:(NSZone*)zone { - wxSortDescriptorObject* copy; + wxSortDescriptorObject* copy; - copy = [super copyWithZone:zone]; - copy->columnPtr = columnPtr; - copy->modelPtr = modelPtr; + copy = [super copyWithZone:zone]; + copy->columnPtr = columnPtr; + copy->modelPtr = modelPtr; - return copy; + return copy; } // @@ -291,22 +293,22 @@ wxWidgetImplType* CreateDataView(wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(pare // -(wxDataViewColumn*) columnPtr { - return columnPtr; + return columnPtr; } -(wxDataViewModel*) modelPtr { - return modelPtr; + return modelPtr; } -(void) setColumnPtr:(wxDataViewColumn*)newColumnPtr { - columnPtr = newColumnPtr; + columnPtr = newColumnPtr; } -(void) setModelPtr:(wxDataViewModel*)newModelPtr { - modelPtr = newModelPtr; + modelPtr = newModelPtr; } @end @@ -321,500 +323,507 @@ wxWidgetImplType* CreateDataView(wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(pare // -(id) init { - self = [super init]; - if (self != nil) - { - implementation = NULL; - model = NULL; + self = [super init]; + if (self != nil) + { + implementation = NULL; + model = NULL; - currentParentItem = nil; + currentParentItem = nil; - children = [[NSMutableArray alloc] init]; - items = [[NSMutableSet alloc] init]; - } - return self; + children = [[NSMutableArray alloc] init]; + items = [[NSMutableSet alloc] init]; + } + return self; } -(void) dealloc { - [currentParentItem release]; + [currentParentItem release]; - [children release]; - [items release]; + [children release]; + [items release]; - [super dealloc]; + [super dealloc]; } // // methods of informal protocol: // --(BOOL) outlineView:(NSOutlineView*)outlineView acceptDrop:(id)info item:(id)item childIndex:(NSInteger)index +-(BOOL) +outlineView:(NSOutlineView*)outlineView + acceptDrop:(id)info + item:(id)item childIndex:(NSInteger)index { - bool dragSuccessful; + NSArray* supportedTypes( + [NSArray arrayWithObjects:DataViewPboardType,NSStringPboardType,nil] + ); - NSArray* supportedTypes([NSArray arrayWithObjects:DataViewPboardType,NSStringPboardType,nil]); + NSPasteboard* pasteboard([info draggingPasteboard]); - NSPasteboard* pasteboard([info draggingPasteboard]); + NSString* bestType([pasteboard availableTypeFromArray:supportedTypes]); - NSString* bestType([pasteboard availableTypeFromArray:supportedTypes]); + if ( bestType == nil ) + return FALSE; + wxDataViewCtrl * const dvc(implementation->GetDataViewCtrl()); - if (bestType != nil) - { - wxDataViewCtrl* const dataViewCtrlPtr(implementation->GetDataViewCtrl()); + wxCHECK_MSG( dvc, false, + "Pointer to data view control not set correctly." ); + wxCHECK_MSG( dvc->GetModel(), false, + "Pointer to model not set correctly." ); - 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.")); - // create wxWidget's event: - wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_DROP,dataViewCtrlPtr->GetId()); + wxDataViewEvent event(wxEVT_COMMAND_DATAVIEW_ITEM_DROP, dvc->GetId()); + event.SetEventObject(dvc); + event.SetItem(wxDataViewItem([((wxPointerObject*) item) pointer])); + event.SetModel(dvc->GetModel()); - dataViewEvent.SetEventObject(dataViewCtrlPtr); - dataViewEvent.SetItem(wxDataViewItem([((wxPointerObject*) item) pointer])); - dataViewEvent.SetModel(dataViewCtrlPtr->GetModel()); - if ([bestType compare:DataViewPboardType] == NSOrderedSame) + BOOL dragSuccessful; + if ( [bestType compare:DataViewPboardType] == NSOrderedSame ) { - NSArray* dataArray((NSArray*)[pasteboard propertyListForType:DataViewPboardType]); - NSUInteger indexDraggedItem, noOfDraggedItems([dataArray count]); - - indexDraggedItem = 0; - while (indexDraggedItem < noOfDraggedItems) - { - wxDataObjectComposite* dataObjects(implementation->GetDnDDataObjects((NSData*)[dataArray objectAtIndex:indexDraggedItem])); + NSArray* dataArray((NSArray*)[pasteboard propertyListForType:DataViewPboardType]); + NSUInteger indexDraggedItem, noOfDraggedItems([dataArray count]); - if ((dataObjects != NULL) && (dataObjects->GetFormatCount() > 0)) + indexDraggedItem = 0; + while (indexDraggedItem < noOfDraggedItems) { - wxMemoryBuffer buffer; - - // copy data into data object: - dataViewEvent.SetDataObject(dataObjects); - dataViewEvent.SetDataFormat(implementation->GetDnDDataFormat(dataObjects)); - // copy data into buffer: - dataObjects->GetDataHere(dataViewEvent.GetDataFormat().GetType(),buffer.GetWriteBuf(dataViewEvent.GetDataSize())); - buffer.UngetWriteBuf(dataViewEvent.GetDataSize()); - dataViewEvent.SetDataBuffer(buffer.GetData()); - // finally, send event: - if (dataViewCtrlPtr->HandleWindowEvent(dataViewEvent) && dataViewEvent.IsAllowed()) - { - dragSuccessful = true; - ++indexDraggedItem; - } - else - { - dragSuccessful = true; - indexDraggedItem = noOfDraggedItems; // stop loop - } - } - else - { - dragSuccessful = false; - indexDraggedItem = noOfDraggedItems; // stop loop + wxDataObjectComposite* dataObjects(implementation->GetDnDDataObjects((NSData*)[dataArray objectAtIndex:indexDraggedItem])); + + if (dataObjects && (dataObjects->GetFormatCount() > 0)) + { + wxMemoryBuffer buffer; + + // copy data into data object: + event.SetDataObject(dataObjects); + event.SetDataFormat(implementation->GetDnDDataFormat(dataObjects)); + // copy data into buffer: + dataObjects->GetDataHere(event.GetDataFormat().GetType(),buffer.GetWriteBuf(event.GetDataSize())); + buffer.UngetWriteBuf(event.GetDataSize()); + event.SetDataBuffer(buffer.GetData()); + // finally, send event: + if (dvc->HandleWindowEvent(event) && event.IsAllowed()) + { + dragSuccessful = true; + ++indexDraggedItem; + } + else + { + dragSuccessful = true; + indexDraggedItem = noOfDraggedItems; // stop loop + } + } + else + { + dragSuccessful = false; + indexDraggedItem = noOfDraggedItems; // stop loop + } + // clean-up: + delete dataObjects; } - // clean-up: - delete dataObjects; - } } else { - CFDataRef osxData; // needed to convert internally used UTF-16 representation to a UTF-8 representation - wxDataObjectComposite* dataObjects (new wxDataObjectComposite()); - wxTextDataObject* textDataObject(new wxTextDataObject()); - - osxData = ::CFStringCreateExternalRepresentation(kCFAllocatorDefault,(CFStringRef)[pasteboard stringForType:NSStringPboardType],kCFStringEncodingUTF8,32); - if (textDataObject->SetData(::CFDataGetLength(osxData),::CFDataGetBytePtr(osxData))) - dataObjects->Add(textDataObject); - else - delete textDataObject; - // send event if data could be copied: - if (dataObjects->GetFormatCount() > 0) - { - dataViewEvent.SetDataObject(dataObjects); - dataViewEvent.SetDataFormat(implementation->GetDnDDataFormat(dataObjects)); - if (dataViewCtrlPtr->HandleWindowEvent(dataViewEvent) && dataViewEvent.IsAllowed()) - dragSuccessful = true; + CFDataRef osxData; // needed to convert internally used UTF-16 representation to a UTF-8 representation + wxDataObjectComposite* dataObjects (new wxDataObjectComposite()); + wxTextDataObject* textDataObject(new wxTextDataObject()); + + osxData = ::CFStringCreateExternalRepresentation(kCFAllocatorDefault,(CFStringRef)[pasteboard stringForType:NSStringPboardType],kCFStringEncodingUTF8,32); + if (textDataObject->SetData(::CFDataGetLength(osxData),::CFDataGetBytePtr(osxData))) + dataObjects->Add(textDataObject); else - dragSuccessful = false; - } - else - dragSuccessful = false; - // clean up: - ::CFRelease(osxData); - delete dataObjects; + delete textDataObject; + // send event if data could be copied: + if (dataObjects->GetFormatCount() > 0) + { + event.SetDataObject(dataObjects); + event.SetDataFormat(implementation->GetDnDDataFormat(dataObjects)); + if (dvc->HandleWindowEvent(event) && event.IsAllowed()) + dragSuccessful = true; + else + dragSuccessful = false; + } + else + dragSuccessful = false; + // clean up: + ::CFRelease(osxData); + delete dataObjects; } - } - else - dragSuccessful = false; - return dragSuccessful; } -(id) outlineView:(NSOutlineView*)outlineView child:(NSInteger)index ofItem:(id)item { - if ((item == currentParentItem) && (index < ((NSInteger) [self getChildCount]))) - return [self getChild:index]; - else - { - wxDataViewItemArray dataViewChildren; - - wxCHECK_MSG(model != NULL,0,_("Valid model in data source does not exist.")); - (void) model->GetChildren((item == nil) ? wxDataViewItem() : wxDataViewItem([((wxPointerObject*) item) pointer]),dataViewChildren); - [self bufferItem:item withChildren:&dataViewChildren]; - if ([sortDescriptors count] > 0) - [children sortUsingFunction:CompareItems context:sortDescriptors]; - return [self getChild:index]; - } + if ((item == currentParentItem) && (index < ((NSInteger) [self getChildCount]))) + return [self getChild:index]; + else + { + wxDataViewItemArray dataViewChildren; + + wxCHECK_MSG( model, 0, "Valid model in data source does not exist." ); + (void) model->GetChildren((item == nil) ? wxDataViewItem() : wxDataViewItem([((wxPointerObject*) item) pointer]),dataViewChildren); + [self bufferItem:item withChildren:&dataViewChildren]; + if ([sortDescriptors count] > 0) + [children sortUsingFunction:CompareItems context:sortDescriptors]; + return [self getChild:index]; + } } -(BOOL) outlineView:(NSOutlineView*)outlineView isItemExpandable:(id)item { - wxCHECK_MSG(model != NULL,0,_("Valid model in data source does not exist.")); - return model->IsContainer(wxDataViewItem([((wxPointerObject*) item) pointer])); + wxCHECK_MSG( model, 0, "Valid model in data source does not exist." ); + return model->IsContainer(wxDataViewItem([((wxPointerObject*) item) pointer])); } -(NSInteger) outlineView:(NSOutlineView*)outlineView numberOfChildrenOfItem:(id)item { - NSInteger noOfChildren; + NSInteger noOfChildren; - wxDataViewItemArray dataViewChildren; + wxDataViewItemArray dataViewChildren; - wxCHECK_MSG(model != NULL,0,_("Valid model in data source does not exist.")); - noOfChildren = model->GetChildren((item == nil) ? wxDataViewItem() : wxDataViewItem([((wxPointerObject*) item) pointer]),dataViewChildren); - [self bufferItem:item withChildren:&dataViewChildren]; - if ([sortDescriptors count] > 0) - [children sortUsingFunction:CompareItems context:sortDescriptors]; - return noOfChildren; + wxCHECK_MSG( model, 0, "Valid model in data source does not exist." ); + noOfChildren = model->GetChildren((item == nil) ? wxDataViewItem() : wxDataViewItem([((wxPointerObject*) item) pointer]),dataViewChildren); + [self bufferItem:item withChildren:&dataViewChildren]; + if ([sortDescriptors count] > 0) + [children sortUsingFunction:CompareItems context:sortDescriptors]; + return noOfChildren; } --(id) outlineView:(NSOutlineView*)outlineView objectValueForTableColumn:(NSTableColumn*)tableColumn byItem:(id)item +-(id) +outlineView:(NSOutlineView*)outlineView + objectValueForTableColumn:(NSTableColumn*)tableColumn + byItem:(id)item { - wxDataViewColumn* dataViewColumnPtr(reinterpret_cast([[tableColumn identifier] pointer])); + wxDataViewColumn* col(static_cast([[tableColumn identifier] pointer])); - wxDataViewItem dataViewItem([((wxPointerObject*) item) pointer]); + wxDataViewItem dataViewItem([((wxPointerObject*) item) pointer]); - wxVariant value; + wxVariant value; - wxCHECK_MSG(model != NULL,0,_("Valid model in data source does not exist.")); - model->GetValue(value,dataViewItem,dataViewColumnPtr->GetModelColumn()); - dataViewColumnPtr->GetRenderer()->SetValue(value); - return nil; + wxCHECK_MSG( model, 0, "Valid model in data source does not exist." ); + model->GetValue(value,dataViewItem,col->GetModelColumn()); + col->GetRenderer()->SetValue(value); + return nil; } --(void) outlineView:(NSOutlineView*)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn*)tableColumn byItem:(id)item +-(void) +outlineView:(NSOutlineView*)outlineView + setObjectValue:(id)object + forTableColumn:(NSTableColumn*)tableColumn + byItem:(id)item { - wxDataViewColumn* dataViewColumnPtr(reinterpret_cast([[tableColumn identifier] pointer])); + wxDataViewColumn* col(static_cast([[tableColumn identifier] pointer])); - wxDataViewItem dataViewItem([((wxPointerObject*) item) pointer]); + wxDataViewItem dataViewItem([((wxPointerObject*) item) pointer]); - if (((dynamic_cast(dataViewColumnPtr->GetRenderer()) != NULL) || (dynamic_cast(dataViewColumnPtr->GetRenderer()) != NULL)) && - ([object isKindOfClass:[NSString class]] == YES)) - { - model->SetValue(wxVariant(wxCFStringRef([((NSString*) object) retain]).AsString()),dataViewItem,dataViewColumnPtr->GetModelColumn()); // the string has to be retained before being passed to wxCFStringRef - model->ValueChanged(dataViewItem,dataViewColumnPtr->GetModelColumn()); - } - else if (dynamic_cast(dataViewColumnPtr->GetRenderer()) != NULL) - { - if ([object isKindOfClass:[NSNumber class]] == YES) + if (((dynamic_cast(col->GetRenderer()) != NULL) || (dynamic_cast(col->GetRenderer()) != NULL)) && + ([object isKindOfClass:[NSString class]] == YES)) + { + model->SetValue(wxVariant(wxCFStringRef([((NSString*) object) retain]).AsString()),dataViewItem,col->GetModelColumn()); // the string has to be retained before being passed to wxCFStringRef + model->ValueChanged(dataViewItem,col->GetModelColumn()); + } + else if (dynamic_cast(col->GetRenderer()) != NULL) + { + if ([object isKindOfClass:[NSNumber class]] == YES) + { + model->SetValue(wxVariant(dynamic_cast(col->GetRenderer())->GetChoice([((NSNumber*) object) intValue])), + dataViewItem,col->GetModelColumn()); + model->ValueChanged(dataViewItem,col->GetModelColumn()); + } + else if ([object isKindOfClass:[NSString class]] == YES) // do not know if this case can occur but initializing using strings works + { + model->SetValue(wxVariant(wxCFStringRef((NSString*) object).AsString()),dataViewItem,col->GetModelColumn()); + model->ValueChanged(dataViewItem,col->GetModelColumn()); + } + } + else if ((dynamic_cast(col->GetRenderer()) != NULL) && ([object isKindOfClass:[NSDate class]] == YES)) { - model->SetValue(wxVariant(dynamic_cast(dataViewColumnPtr->GetRenderer())->GetChoice([((NSNumber*) object) intValue])), - dataViewItem,dataViewColumnPtr->GetModelColumn()); - model->ValueChanged(dataViewItem,dataViewColumnPtr->GetModelColumn()); + wxDateTime wxDateTimeValue(1,wxDateTime::Jan,1970); + + wxLongLong seconds; + + seconds.Assign([((NSDate*) object) timeIntervalSince1970]); // get the number of seconds since 1970-01-01 UTC and this is + // the only way to convert a double to a wxLongLong + // the user has entered a date in the local timezone but seconds contains the number of seconds from date in the local timezone since 1970-01-01 UTC; + // therefore, the timezone information has to be transferred to wxWidgets, too: + wxDateTimeValue.Add(wxTimeSpan(0,0,seconds)); + wxDateTimeValue.MakeFromTimezone(wxDateTime::UTC); + model->SetValue(wxVariant(wxDateTimeValue),dataViewItem,col->GetModelColumn()); + model->ValueChanged(dataViewItem,col->GetModelColumn()); } - else if ([object isKindOfClass:[NSString class]] == YES) // do not know if this case can occur but initializing using strings works + else if ((dynamic_cast(col->GetRenderer()) != NULL) && ([object isKindOfClass:[NSNumber class]] == YES)) { - model->SetValue(wxVariant(wxCFStringRef((NSString*) object).AsString()),dataViewItem,dataViewColumnPtr->GetModelColumn()); - model->ValueChanged(dataViewItem,dataViewColumnPtr->GetModelColumn()); + model->SetValue(wxVariant((bool) [((NSNumber*) object) boolValue]),dataViewItem,col->GetModelColumn()); + model->ValueChanged(dataViewItem,col->GetModelColumn()); } - } - else if ((dynamic_cast(dataViewColumnPtr->GetRenderer()) != NULL) && ([object isKindOfClass:[NSDate class]] == YES)) - { - wxDateTime wxDateTimeValue(1,wxDateTime::Jan,1970); - - wxLongLong seconds; - - seconds.Assign([((NSDate*) object) timeIntervalSince1970]); // get the number of seconds since 1970-01-01 UTC and this is - // the only way to convert a double to a wxLongLong - // the user has entered a date in the local timezone but seconds contains the number of seconds from date in the local timezone since 1970-01-01 UTC; - // therefore, the timezone information has to be transferred to wxWidgets, too: - wxDateTimeValue.Add(wxTimeSpan(0,0,seconds)); - wxDateTimeValue.MakeFromTimezone(wxDateTime::UTC); - model->SetValue(wxVariant(wxDateTimeValue),dataViewItem,dataViewColumnPtr->GetModelColumn()); - model->ValueChanged(dataViewItem,dataViewColumnPtr->GetModelColumn()); - } - else if ((dynamic_cast(dataViewColumnPtr->GetRenderer()) != NULL) && ([object isKindOfClass:[NSNumber class]] == YES)) - { - model->SetValue(wxVariant((bool) [((NSNumber*) object) boolValue]),dataViewItem,dataViewColumnPtr->GetModelColumn()); - model->ValueChanged(dataViewItem,dataViewColumnPtr->GetModelColumn()); - } } -(void) outlineView:(NSOutlineView*)outlineView sortDescriptorsDidChange:(NSArray*)oldDescriptors - // Warning: the new sort descriptors are guaranteed to be only of type NSSortDescriptor! Therefore, the - // sort descriptors for the data source have to be converted. +// Warning: the new sort descriptors are guaranteed to be only of type NSSortDescriptor! Therefore, the +// sort descriptors for the data source have to be converted. { - NSArray* newDescriptors; + NSArray* newDescriptors; - NSMutableArray* wxSortDescriptors; + NSMutableArray* wxSortDescriptors; - NSUInteger noOfDescriptors; + NSUInteger noOfDescriptors; - wxDataViewCtrl* const dataViewCtrlPtr = implementation->GetDataViewCtrl(); + wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl(); - // convert NSSortDescriptors to wxSortDescriptorObjects: - newDescriptors = [outlineView sortDescriptors]; - noOfDescriptors = [newDescriptors count]; - wxSortDescriptors = [NSMutableArray arrayWithCapacity:noOfDescriptors]; - for (NSUInteger i=0; iGetColumn([[newDescriptor key] intValue]) - ascending:[newDescriptor ascending]] autorelease]]; - } - [[outlineView dataSource] setSortDescriptors:wxSortDescriptors]; + [wxSortDescriptors addObject:[[[wxSortDescriptorObject alloc] initWithModelPtr:model + sortingColumnPtr:dvc->GetColumn([[newDescriptor key] intValue]) + ascending:[newDescriptor ascending]] autorelease]]; + } + [[outlineView dataSource] setSortDescriptors:wxSortDescriptors]; - // send first the event to wxWidgets that the sorting has changed so that the program can do special actions before - // the sorting actually starts: - wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED,dataViewCtrlPtr->GetId()); // variable defintion + // send first the event to wxWidgets that the sorting has changed so that the program can do special actions before + // the sorting actually starts: + wxDataViewEvent event(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED,dvc->GetId()); // variable defintion - dataViewEvent.SetEventObject(dataViewCtrlPtr); - if (noOfDescriptors > 0) - { - // constant definition for abbreviational purposes: - wxDataViewColumn* const dataViewColumnPtr = [[wxSortDescriptors objectAtIndex:0] columnPtr]; + event.SetEventObject(dvc); + if (noOfDescriptors > 0) + { + // constant definition for abbreviational purposes: + wxDataViewColumn* const col = [[wxSortDescriptors objectAtIndex:0] columnPtr]; - dataViewEvent.SetColumn(dataViewCtrlPtr->GetColumnPosition(dataViewColumnPtr)); - dataViewEvent.SetDataViewColumn(dataViewColumnPtr); - } - dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); + event.SetColumn(dvc->GetColumnPosition(col)); + event.SetDataViewColumn(col); + } + dvc->GetEventHandler()->ProcessEvent(event); - // start re-ordering the data; - // children's buffer must be cleared first because it contains the old order: - [self clearChildren]; - // sorting is done while reloading the data: - [outlineView reloadData]; + // start re-ordering the data; + // children's buffer must be cleared first because it contains the old order: + [self clearChildren]; + // sorting is done while reloading the data: + [outlineView reloadData]; } -(NSDragOperation) outlineView:(NSOutlineView*)outlineView validateDrop:(id)info proposedItem:(id)item proposedChildIndex:(NSInteger)index { - NSArray* supportedTypes([NSArray arrayWithObjects:DataViewPboardType,NSStringPboardType,nil]); + NSArray* supportedTypes([NSArray arrayWithObjects:DataViewPboardType,NSStringPboardType,nil]); - NSDragOperation dragOperation; + NSPasteboard* pasteboard([info draggingPasteboard]); - NSPasteboard* pasteboard([info draggingPasteboard]); + NSString* bestType([pasteboard availableTypeFromArray:supportedTypes]); + if (bestType == nil) + return NSDragOperationNone; - NSString* bestType([pasteboard availableTypeFromArray:supportedTypes]); + NSDragOperation dragOperation; + wxDataViewCtrl* const dvc(implementation->GetDataViewCtrl()); + wxCHECK_MSG(dvc, false, "Pointer to data view control not set correctly."); + wxCHECK_MSG(dvc->GetModel(), false, "Pointer to model not set correctly."); - if (bestType != nil) - { - wxDataViewCtrl* const dataViewCtrlPtr(implementation->GetDataViewCtrl()); + wxDataViewEvent + event(wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE,dvc->GetId()); - 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.")); - // create wxWidget's event: - wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE,dataViewCtrlPtr->GetId()); - - dataViewEvent.SetEventObject(dataViewCtrlPtr); - dataViewEvent.SetItem(wxDataViewItem([((wxPointerObject*) item) pointer])); - dataViewEvent.SetModel(dataViewCtrlPtr->GetModel()); + event.SetEventObject(dvc); + event.SetItem(wxDataViewItem([((wxPointerObject*) item) pointer])); + event.SetModel(dvc->GetModel()); if ([bestType compare:DataViewPboardType] == NSOrderedSame) { - NSArray* dataArray((NSArray*)[pasteboard propertyListForType:DataViewPboardType]); - NSUInteger indexDraggedItem, noOfDraggedItems([dataArray count]); - - indexDraggedItem = 0; - while (indexDraggedItem < noOfDraggedItems) - { - wxDataObjectComposite* dataObjects(implementation->GetDnDDataObjects((NSData*)[dataArray objectAtIndex:indexDraggedItem])); + NSArray* dataArray((NSArray*)[pasteboard propertyListForType:DataViewPboardType]); + NSUInteger indexDraggedItem, noOfDraggedItems([dataArray count]); - if ((dataObjects != NULL) && (dataObjects->GetFormatCount() > 0)) - { - wxMemoryBuffer buffer; - - // copy data into data object: - dataViewEvent.SetDataObject(dataObjects); - dataViewEvent.SetDataFormat(implementation->GetDnDDataFormat(dataObjects)); - // copy data into buffer: - dataObjects->GetDataHere(dataViewEvent.GetDataFormat().GetType(),buffer.GetWriteBuf(dataViewEvent.GetDataSize())); - buffer.UngetWriteBuf(dataViewEvent.GetDataSize()); - dataViewEvent.SetDataBuffer(buffer.GetData()); - // finally, send event: - if (dataViewCtrlPtr->HandleWindowEvent(dataViewEvent) && dataViewEvent.IsAllowed()) - { - dragOperation = NSDragOperationEvery; - ++indexDraggedItem; - } - else - { - dragOperation = NSDragOperationNone; - indexDraggedItem = noOfDraggedItems; // stop loop - } - } - else + indexDraggedItem = 0; + while (indexDraggedItem < noOfDraggedItems) { - dragOperation = NSDragOperationNone; - indexDraggedItem = noOfDraggedItems; // stop loop + wxDataObjectComposite* dataObjects(implementation->GetDnDDataObjects((NSData*)[dataArray objectAtIndex:indexDraggedItem])); + + if (dataObjects && (dataObjects->GetFormatCount() > 0)) + { + wxMemoryBuffer buffer; + + // copy data into data object: + event.SetDataObject(dataObjects); + event.SetDataFormat(implementation->GetDnDDataFormat(dataObjects)); + // copy data into buffer: + dataObjects->GetDataHere(event.GetDataFormat().GetType(),buffer.GetWriteBuf(event.GetDataSize())); + buffer.UngetWriteBuf(event.GetDataSize()); + event.SetDataBuffer(buffer.GetData()); + // finally, send event: + if (dvc->HandleWindowEvent(event) && event.IsAllowed()) + { + dragOperation = NSDragOperationEvery; + ++indexDraggedItem; + } + else + { + dragOperation = NSDragOperationNone; + indexDraggedItem = noOfDraggedItems; // stop loop + } + } + else + { + dragOperation = NSDragOperationNone; + indexDraggedItem = noOfDraggedItems; // stop loop + } + // clean-up: + delete dataObjects; } - // clean-up: - delete dataObjects; - } } else { - CFDataRef osxData; // needed to convert internally used UTF-16 representation to a UTF-8 representation - wxDataObjectComposite* dataObjects (new wxDataObjectComposite()); - wxTextDataObject* textDataObject(new wxTextDataObject()); - - osxData = ::CFStringCreateExternalRepresentation(kCFAllocatorDefault,(CFStringRef)[pasteboard stringForType:NSStringPboardType],kCFStringEncodingUTF8,32); - if (textDataObject->SetData(::CFDataGetLength(osxData),::CFDataGetBytePtr(osxData))) - dataObjects->Add(textDataObject); - else - delete textDataObject; - // send event if data could be copied: - if (dataObjects->GetFormatCount() > 0) - { - dataViewEvent.SetDataObject(dataObjects); - dataViewEvent.SetDataFormat(implementation->GetDnDDataFormat(dataObjects)); - if (dataViewCtrlPtr->HandleWindowEvent(dataViewEvent) && dataViewEvent.IsAllowed()) - dragOperation = NSDragOperationEvery; + CFDataRef osxData; // needed to convert internally used UTF-16 representation to a UTF-8 representation + wxDataObjectComposite* dataObjects (new wxDataObjectComposite()); + wxTextDataObject* textDataObject(new wxTextDataObject()); + + osxData = ::CFStringCreateExternalRepresentation(kCFAllocatorDefault,(CFStringRef)[pasteboard stringForType:NSStringPboardType],kCFStringEncodingUTF8,32); + if (textDataObject->SetData(::CFDataGetLength(osxData),::CFDataGetBytePtr(osxData))) + dataObjects->Add(textDataObject); + else + delete textDataObject; + // send event if data could be copied: + if (dataObjects->GetFormatCount() > 0) + { + event.SetDataObject(dataObjects); + event.SetDataFormat(implementation->GetDnDDataFormat(dataObjects)); + if (dvc->HandleWindowEvent(event) && event.IsAllowed()) + dragOperation = NSDragOperationEvery; + else + dragOperation = NSDragOperationNone; + } else - dragOperation = NSDragOperationNone; - } - else - dragOperation = NSDragOperationNone; - // clean up: - ::CFRelease(osxData); - delete dataObjects; + dragOperation = NSDragOperationNone; + // clean up: + ::CFRelease(osxData); + delete dataObjects; } - } - else - dragOperation = NSDragOperationNone; - return dragOperation; + + return dragOperation; } -(BOOL) outlineView:(NSOutlineView*)outlineView writeItems:(NSArray*)writeItems toPasteboard:(NSPasteboard*)pasteboard - // the pasteboard will be filled up with an array containing the data as returned by the events (including the data type) - // and a concatenation of text (string) data; the text data will only be put onto the pasteboard if for all items a - // string representation exists +// the pasteboard will be filled up with an array containing the data as returned by the events (including the data type) +// and a concatenation of text (string) data; the text data will only be put onto the pasteboard if for all items a +// string representation exists { - wxDataViewCtrl* const dataViewCtrlPtr = implementation->GetDataViewCtrl(); + wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl(); - wxDataViewItemArray dataViewItems; + wxDataViewItemArray dataViewItems; - 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.")); + wxCHECK_MSG(dvc, false,"Pointer to data view control not set correctly."); + wxCHECK_MSG(dvc->GetModel(),false,"Pointer to model not set correctly."); - if ([writeItems count] > 0) - { - bool dataStringAvailable(true); // a flag indicating if for all items a data string is available - NSMutableArray* dataArray = [[NSMutableArray arrayWithCapacity:[writeItems count]] retain]; // data of all items - wxString dataString; // contains the string data of all items + if ([writeItems count] > 0) + { + bool dataStringAvailable(true); // a flag indicating if for all items a data string is available + NSMutableArray* dataArray = [[NSMutableArray arrayWithCapacity:[writeItems count]] retain]; // data of all items + wxString dataString; // contains the string data of all items - // send a begin drag event for all selected items and proceed with dragging unless the event is vetoed: - wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG,dataViewCtrlPtr->GetId()); + // send a begin drag event for all selected items and proceed with dragging unless the event is vetoed: + wxDataViewEvent + event(wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG,dvc->GetId()); - dataViewEvent.SetEventObject(dataViewCtrlPtr); - dataViewEvent.SetModel(dataViewCtrlPtr->GetModel()); - for (size_t itemCounter=0; itemCounter<[writeItems count]; ++itemCounter) - { - bool itemStringAvailable(false); // a flag indicating if for the current item a string is available - wxDataObjectComposite* itemObject(new wxDataObjectComposite()); // data object for current item - wxString itemString; // contains the TAB concatenated data of an item - - dataViewEvent.SetItem(wxDataViewItem([((wxPointerObject*) [writeItems objectAtIndex:itemCounter]) pointer])); - itemString = ::ConcatenateDataViewItemValues(dataViewCtrlPtr,dataViewEvent.GetItem()); - itemObject->Add(new wxTextDataObject(itemString)); - dataViewEvent.SetDataObject(itemObject); - // check if event has not been vetoed: - if (dataViewCtrlPtr->HandleWindowEvent(dataViewEvent) && dataViewEvent.IsAllowed() && (dataViewEvent.GetDataObject()->GetFormatCount() > 0)) - { - // constant definition for abbreviational purposes: - size_t const noOfFormats = dataViewEvent.GetDataObject()->GetFormatCount(); - // variable definition and initialization: - wxDataFormat* dataFormats(new wxDataFormat[noOfFormats]); - - dataViewEvent.GetDataObject()->GetAllFormats(dataFormats,wxDataObject::Get); - for (size_t formatCounter=0; formatCounterGetModel()); + for (size_t itemCounter=0; itemCounter<[writeItems count]; ++itemCounter) { - // constant definitions for abbreviational purposes: - wxDataFormatId const idDataFormat = dataFormats[formatCounter].GetType(); - size_t const dataSize = dataViewEvent.GetDataObject()->GetDataSize(idDataFormat); - size_t const dataBufferSize = sizeof(wxDataFormatId)+dataSize; - // variable definitions (used in all case statements): - wxMemoryBuffer dataBuffer(dataBufferSize); - - dataBuffer.AppendData(&idDataFormat,sizeof(wxDataFormatId)); - switch (idDataFormat) - { - case wxDF_TEXT: - if (!itemStringAvailable) // otherwise wxDF_UNICODETEXT already filled up the string; and the UNICODE representation has priority - { - dataViewEvent.GetDataObject()->GetDataHere(wxDF_TEXT,dataBuffer.GetAppendBuf(dataSize)); - dataBuffer.UngetAppendBuf(dataSize); - [dataArray addObject:[NSData dataWithBytes:dataBuffer.GetData() length:dataBufferSize]]; - itemString = wxString(reinterpret_cast(dataBuffer.GetData())+sizeof(wxDataFormatId),wxConvLocal); - itemStringAvailable = true; - } - break; - case wxDF_UNICODETEXT: - { - dataViewEvent.GetDataObject()->GetDataHere(wxDF_UNICODETEXT,dataBuffer.GetAppendBuf(dataSize)); - dataBuffer.UngetAppendBuf(dataSize); - if (itemStringAvailable) // does an object already exist as an ASCII text (see wxDF_TEXT case statement)? - [dataArray replaceObjectAtIndex:itemCounter withObject:[NSData dataWithBytes:dataBuffer.GetData() length:dataBufferSize]]; - else - [dataArray addObject:[NSData dataWithBytes:dataBuffer.GetData() length:dataBufferSize]]; - itemString = wxString::FromUTF8(reinterpret_cast(dataBuffer.GetData())+sizeof(wxDataFormatId),dataSize); - itemStringAvailable = true; - } /* block */ - break; - default: - wxFAIL_MSG(_("Data object has invalid or unsupported data format")); - [dataArray release]; - return NO; - } + bool itemStringAvailable(false); // a flag indicating if for the current item a string is available + wxDataObjectComposite* itemObject(new wxDataObjectComposite()); // data object for current item + wxString itemString; // contains the TAB concatenated data of an item + + event.SetItem(wxDataViewItem([((wxPointerObject*) [writeItems objectAtIndex:itemCounter]) pointer])); + itemString = ::ConcatenateDataViewItemValues(dvc,event.GetItem()); + itemObject->Add(new wxTextDataObject(itemString)); + event.SetDataObject(itemObject); + // check if event has not been vetoed: + if (dvc->HandleWindowEvent(event) && event.IsAllowed() && (event.GetDataObject()->GetFormatCount() > 0)) + { + // constant definition for abbreviational purposes: + size_t const noOfFormats = event.GetDataObject()->GetFormatCount(); + // variable definition and initialization: + wxDataFormat* dataFormats(new wxDataFormat[noOfFormats]); + + event.GetDataObject()->GetAllFormats(dataFormats,wxDataObject::Get); + for (size_t formatCounter=0; formatCounterGetDataSize(idDataFormat); + size_t const dataBufferSize = sizeof(wxDataFormatId)+dataSize; + // variable definitions (used in all case statements): + wxMemoryBuffer dataBuffer(dataBufferSize); + + dataBuffer.AppendData(&idDataFormat,sizeof(wxDataFormatId)); + switch (idDataFormat) + { + case wxDF_TEXT: + if (!itemStringAvailable) // otherwise wxDF_UNICODETEXT already filled up the string; and the UNICODE representation has priority + { + event.GetDataObject()->GetDataHere(wxDF_TEXT,dataBuffer.GetAppendBuf(dataSize)); + dataBuffer.UngetAppendBuf(dataSize); + [dataArray addObject:[NSData dataWithBytes:dataBuffer.GetData() length:dataBufferSize]]; + itemString = wxString(static_cast(dataBuffer.GetData())+sizeof(wxDataFormatId),wxConvLocal); + itemStringAvailable = true; + } + break; + case wxDF_UNICODETEXT: + { + event.GetDataObject()->GetDataHere(wxDF_UNICODETEXT,dataBuffer.GetAppendBuf(dataSize)); + dataBuffer.UngetAppendBuf(dataSize); + if (itemStringAvailable) // does an object already exist as an ASCII text (see wxDF_TEXT case statement)? + [dataArray replaceObjectAtIndex:itemCounter withObject:[NSData dataWithBytes:dataBuffer.GetData() length:dataBufferSize]]; + else + [dataArray addObject:[NSData dataWithBytes:dataBuffer.GetData() length:dataBufferSize]]; + itemString = wxString::FromUTF8(static_cast(dataBuffer.GetData())+sizeof(wxDataFormatId),dataSize); + itemStringAvailable = true; + } /* block */ + break; + default: + wxFAIL_MSG("Data object has invalid or unsupported data format"); + [dataArray release]; + return NO; + } + } + delete[] dataFormats; + delete itemObject; + if (dataStringAvailable) + if (itemStringAvailable) + { + if (itemCounter > 0) + dataString << wxT('\n'); + dataString << itemString; + } + else + dataStringAvailable = false; + } + else + { + [dataArray release]; + delete itemObject; + return NO; // dragging was vetoed or no data available + } } - delete[] dataFormats; - delete itemObject; if (dataStringAvailable) - if (itemStringAvailable) - { - if (itemCounter > 0) - dataString << wxT('\n'); - dataString << itemString; - } - else - dataStringAvailable = false; - } - else - { - [dataArray release]; - delete itemObject; - return NO; // dragging was vetoed or no data available - } - } - if (dataStringAvailable) - { - wxCFStringRef osxString(dataString); + { + wxCFStringRef osxString(dataString); - [pasteboard declareTypes:[NSArray arrayWithObjects:DataViewPboardType,NSStringPboardType,nil] owner:nil]; - [pasteboard setPropertyList:dataArray forType:DataViewPboardType]; - [pasteboard setString:osxString.AsNSString() forType:NSStringPboardType]; + [pasteboard declareTypes:[NSArray arrayWithObjects:DataViewPboardType,NSStringPboardType,nil] owner:nil]; + [pasteboard setPropertyList:dataArray forType:DataViewPboardType]; + [pasteboard setString:osxString.AsNSString() forType:NSStringPboardType]; + } + else + { + [pasteboard declareTypes:[NSArray arrayWithObject:DataViewPboardType] owner:nil]; + [pasteboard setPropertyList:dataArray forType:DataViewPboardType]; + } + return YES; } else - { - [pasteboard declareTypes:[NSArray arrayWithObject:DataViewPboardType] owner:nil]; - [pasteboard setPropertyList:dataArray forType:DataViewPboardType]; - } - return YES; - } - else - return NO; // no items to drag (should never occur) + return NO; // no items to drag (should never occur) } // @@ -822,32 +831,32 @@ wxWidgetImplType* CreateDataView(wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(pare // -(void) addToBuffer:(wxPointerObject*)item { - [items addObject:item]; + [items addObject:item]; } -(void) clearBuffer { - [items removeAllObjects]; + [items removeAllObjects]; } --(wxPointerObject*) getDataViewItemFromBuffer:(wxDataViewItem const&)item +-(wxPointerObject*) getDataViewItemFromBuffer:(const wxDataViewItem&)item { - return [items member:[[[wxPointerObject alloc] initWithPointer:item.GetID()] autorelease]]; + return [items member:[[[wxPointerObject alloc] initWithPointer:item.GetID()] autorelease]]; } -(wxPointerObject*) getItemFromBuffer:(wxPointerObject*)item { - return [items member:item]; + return [items member:item]; } -(BOOL) isInBuffer:(wxPointerObject*)item { - return [items containsObject:item]; + return [items containsObject:item]; } -(void) removeFromBuffer:(wxPointerObject*)item { - [items removeObject:item]; + [items removeObject:item]; } // @@ -855,27 +864,27 @@ wxWidgetImplType* CreateDataView(wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(pare // -(void) appendChild:(wxPointerObject*)item { - [children addObject:item]; + [children addObject:item]; } -(void) clearChildren { - [children removeAllObjects]; + [children removeAllObjects]; } -(wxPointerObject*) getChild:(NSUInteger)index { - return [children objectAtIndex:index]; + return [children objectAtIndex:index]; } -(NSUInteger) getChildCount { - return [children count]; + return [children count]; } -(void) removeChild:(NSUInteger)index { - [children removeObjectAtIndex:index]; + [children removeObjectAtIndex:index]; } // @@ -883,9 +892,9 @@ wxWidgetImplType* CreateDataView(wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(pare // -(void) clearBuffers { - [self clearBuffer]; - [self clearChildren]; - [self setCurrentParentItem:nil]; + [self clearBuffer]; + [self clearChildren]; + [self setCurrentParentItem:nil]; } // @@ -893,14 +902,14 @@ wxWidgetImplType* CreateDataView(wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(pare // -(NSArray*) sortDescriptors { - return sortDescriptors; + return sortDescriptors; } -(void) setSortDescriptors:(NSArray*)newSortDescriptors { - [newSortDescriptors retain]; - [sortDescriptors release]; - sortDescriptors = newSortDescriptors; + [newSortDescriptors retain]; + [sortDescriptors release]; + sortDescriptors = newSortDescriptors; } // @@ -908,34 +917,34 @@ wxWidgetImplType* CreateDataView(wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(pare // -(wxPointerObject*) currentParentItem { - return currentParentItem; + return currentParentItem; } -(wxCocoaDataViewControl*) implementation { - return implementation; + return implementation; } -(wxDataViewModel*) model { - return model; + return model; } -(void) setCurrentParentItem:(wxPointerObject*)newCurrentParentItem { - [newCurrentParentItem retain]; - [currentParentItem release]; - currentParentItem = newCurrentParentItem; + [newCurrentParentItem retain]; + [currentParentItem release]; + currentParentItem = newCurrentParentItem; } -(void) setImplementation:(wxCocoaDataViewControl*) newImplementation { - implementation = newImplementation; + implementation = newImplementation; } -(void) setModel:(wxDataViewModel*) newModel { - model = newModel; + model = newModel; } // @@ -943,32 +952,37 @@ wxWidgetImplType* CreateDataView(wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(pare // -(void) bufferItem:(wxPointerObject*)parentItem withChildren:(wxDataViewItemArray*)dataViewChildrenPtr { - NSInteger const noOfChildren = (*dataViewChildrenPtr).GetCount(); - - [self setCurrentParentItem:parentItem]; - [self clearChildren]; - for (NSInteger indexChild=0; indexChildimage = [image retain]; - cell->imageSize = imageSize; - cell->spaceImageText = spaceImageText; - cell->xImageShift = xImageShift; + cell = (wxImageTextCell*) [super copyWithZone:zone]; + cell->image = [image retain]; + cell->imageSize = imageSize; + cell->spaceImageText = spaceImageText; + cell->xImageShift = xImageShift; - return cell; + return cell; } -(void) dealloc { - [image release]; + [image release]; - [super dealloc]; + [super dealloc]; } // @@ -1068,26 +1082,26 @@ wxWidgetImplType* CreateDataView(wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(pare // -(NSTextAlignment) alignment { - return cellAlignment; + return cellAlignment; } -(void) setAlignment:(NSTextAlignment)newAlignment { - cellAlignment = newAlignment; - switch (newAlignment) - { - case NSCenterTextAlignment: - case NSLeftTextAlignment: - case NSJustifiedTextAlignment: - case NSNaturalTextAlignment: - [super setAlignment:NSLeftTextAlignment]; - break; - case NSRightTextAlignment: - [super setAlignment:NSRightTextAlignment]; - break; - default: - wxFAIL_MSG(_("Unknown alignment type.")); - } + cellAlignment = newAlignment; + switch (newAlignment) + { + case NSCenterTextAlignment: + case NSLeftTextAlignment: + case NSJustifiedTextAlignment: + case NSNaturalTextAlignment: + [super setAlignment:NSLeftTextAlignment]; + break; + case NSRightTextAlignment: + [super setAlignment:NSRightTextAlignment]; + break; + default: + wxFAIL_MSG("Unknown alignment type."); + } } // @@ -1095,24 +1109,24 @@ wxWidgetImplType* CreateDataView(wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(pare // -(NSImage*) image { - return image; + return image; } -(void) setImage:(NSImage*)newImage { - [newImage retain]; - [image release]; - image = newImage; + [newImage retain]; + [image release]; + image = newImage; } -(NSSize) imageSize { - return imageSize; + return imageSize; } -(void) setImageSize:(NSSize) newImageSize { - imageSize = newImageSize; + imageSize = newImageSize; } // @@ -1120,24 +1134,24 @@ wxWidgetImplType* CreateDataView(wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(pare // -(NSSize) cellImageSize { - return NSMakeSize(imageSize.width+xImageShift+spaceImageText,imageSize.height); + return NSMakeSize(imageSize.width+xImageShift+spaceImageText,imageSize.height); } -(NSSize) cellSize { - NSSize cellSize([super cellSize]); + NSSize cellSize([super cellSize]); - if (imageSize.height > cellSize.height) - cellSize.height = imageSize.height; - cellSize.width += imageSize.width+xImageShift+spaceImageText; + if (imageSize.height > cellSize.height) + cellSize.height = imageSize.height; + cellSize.width += imageSize.width+xImageShift+spaceImageText; - return cellSize; + return cellSize; } -(NSSize) cellTextSize { - return [super cellSize]; + return [super cellSize]; } // @@ -1145,182 +1159,182 @@ wxWidgetImplType* CreateDataView(wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(pare // -(void) determineCellParts:(NSRect)cellFrame imagePart:(NSRect*)imageFrame textPart:(NSRect*)textFrame { - switch (cellAlignment) - { - case NSCenterTextAlignment: - { - CGFloat const cellSpace = cellFrame.size.width-[self cellSize].width; - - if (cellSpace <= 0) // if the cell's frame is smaller than its contents (at least in x-direction) make sure that the image is visible: - NSDivideRect(cellFrame,imageFrame,textFrame,xImageShift+imageSize.width+spaceImageText,NSMinXEdge); - else // otherwise center the image and text in the cell's frame - NSDivideRect(cellFrame,imageFrame,textFrame,xImageShift+imageSize.width+spaceImageText+0.5*cellSpace,NSMinXEdge); - } - break; - case NSJustifiedTextAlignment: - case NSLeftTextAlignment: - case NSNaturalTextAlignment: // how to determine the natural writing direction? TODO - NSDivideRect(cellFrame,imageFrame,textFrame,xImageShift+imageSize.width+spaceImageText,NSMinXEdge); - break; - case NSRightTextAlignment: - { - CGFloat const cellSpace = cellFrame.size.width-[self cellSize].width; - - if (cellSpace <= 0) // if the cell's frame is smaller than its contents (at least in x-direction) make sure that the image is visible: - NSDivideRect(cellFrame,imageFrame,textFrame,xImageShift+imageSize.width+spaceImageText,NSMinXEdge); - else // otherwise right align the image and text in the cell's frame - NSDivideRect(cellFrame,imageFrame,textFrame,xImageShift+imageSize.width+spaceImageText+cellSpace,NSMinXEdge); - } - break; - default: - *imageFrame = NSZeroRect; - *textFrame = NSZeroRect; - wxFAIL_MSG(_("Unhandled alignment type.")); - } + switch (cellAlignment) + { + case NSCenterTextAlignment: + { + CGFloat const cellSpace = cellFrame.size.width-[self cellSize].width; + + if (cellSpace <= 0) // if the cell's frame is smaller than its contents (at least in x-direction) make sure that the image is visible: + NSDivideRect(cellFrame,imageFrame,textFrame,xImageShift+imageSize.width+spaceImageText,NSMinXEdge); + else // otherwise center the image and text in the cell's frame + NSDivideRect(cellFrame,imageFrame,textFrame,xImageShift+imageSize.width+spaceImageText+0.5*cellSpace,NSMinXEdge); + } + break; + case NSJustifiedTextAlignment: + case NSLeftTextAlignment: + case NSNaturalTextAlignment: // how to determine the natural writing direction? TODO + NSDivideRect(cellFrame,imageFrame,textFrame,xImageShift+imageSize.width+spaceImageText,NSMinXEdge); + break; + case NSRightTextAlignment: + { + CGFloat const cellSpace = cellFrame.size.width-[self cellSize].width; + + if (cellSpace <= 0) // if the cell's frame is smaller than its contents (at least in x-direction) make sure that the image is visible: + NSDivideRect(cellFrame,imageFrame,textFrame,xImageShift+imageSize.width+spaceImageText,NSMinXEdge); + else // otherwise right align the image and text in the cell's frame + NSDivideRect(cellFrame,imageFrame,textFrame,xImageShift+imageSize.width+spaceImageText+cellSpace,NSMinXEdge); + } + break; + default: + *imageFrame = NSZeroRect; + *textFrame = NSZeroRect; + wxFAIL_MSG("Unhandled alignment type."); + } } -(void) drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { - NSRect textFrame, imageFrame; + NSRect textFrame, imageFrame; - [self determineCellParts:cellFrame imagePart:&imageFrame textPart:&textFrame]; -// draw the image part by ourselves; - // check if the cell has to draw its own background (checking is done by the parameter of the textfield's cell): - if ([self drawsBackground]) - { - [[self backgroundColor] set]; - NSRectFill(imageFrame); - } - if (image != nil) - { - // the image is slightly shifted (xImageShift) and has a fixed size but the image's frame might be larger and starts - // currently on the left side of the cell's frame; therefore, the origin and the image's frame size have to be adjusted: - if (imageFrame.size.width >= xImageShift+imageSize.width+spaceImageText) + [self determineCellParts:cellFrame imagePart:&imageFrame textPart:&textFrame]; + // draw the image part by ourselves; + // check if the cell has to draw its own background (checking is done by the parameter of the textfield's cell): + if ([self drawsBackground]) { - imageFrame.origin.x += imageFrame.size.width-imageSize.width-spaceImageText; - imageFrame.size.width = imageSize.width; + [[self backgroundColor] set]; + NSRectFill(imageFrame); } - else + if (image != nil) { - imageFrame.origin.x += xImageShift; - imageFrame.size.width -= xImageShift+spaceImageText; - } - // ...and the image has to be centered in the y-direction: - if (imageFrame.size.height > imageSize.height) - imageFrame.size.height = imageSize.height; - imageFrame.origin.y += ceil(0.5*(cellFrame.size.height-imageFrame.size.height)); + // the image is slightly shifted (xImageShift) and has a fixed size but the image's frame might be larger and starts + // currently on the left side of the cell's frame; therefore, the origin and the image's frame size have to be adjusted: + if (imageFrame.size.width >= xImageShift+imageSize.width+spaceImageText) + { + imageFrame.origin.x += imageFrame.size.width-imageSize.width-spaceImageText; + imageFrame.size.width = imageSize.width; + } + else + { + imageFrame.origin.x += xImageShift; + imageFrame.size.width -= xImageShift+spaceImageText; + } + // ...and the image has to be centered in the y-direction: + if (imageFrame.size.height > imageSize.height) + imageFrame.size.height = imageSize.height; + imageFrame.origin.y += ceil(0.5*(cellFrame.size.height-imageFrame.size.height)); - // according to the documentation the coordinate system should be flipped for NSTableViews (y-coordinate goes from top to bottom); - // to draw an image correctly the coordinate system has to be transformed to a bottom-top coordinate system, otherwise the image's - // content is flipped: - NSAffineTransform* coordinateTransform([NSAffineTransform transform]); + // according to the documentation the coordinate system should be flipped for NSTableViews (y-coordinate goes from top to bottom); + // to draw an image correctly the coordinate system has to be transformed to a bottom-top coordinate system, otherwise the image's + // content is flipped: + NSAffineTransform* coordinateTransform([NSAffineTransform transform]); - if ([controlView isFlipped]) - { - [coordinateTransform scaleXBy: 1.0 yBy:-1.0]; // first the coordinate system is brought back to bottom-top orientation - [coordinateTransform translateXBy:0.0 yBy:(-2.0)*imageFrame.origin.y-imageFrame.size.height]; // the coordinate system has to be moved to compensate for the - [coordinateTransform concat]; // other orientation and the position of the image's frame + if ([controlView isFlipped]) + { + [coordinateTransform scaleXBy: 1.0 yBy:-1.0]; // first the coordinate system is brought back to bottom-top orientation + [coordinateTransform translateXBy:0.0 yBy:(-2.0)*imageFrame.origin.y-imageFrame.size.height]; // the coordinate system has to be moved to compensate for the + [coordinateTransform concat]; // other orientation and the position of the image's frame + } + [image drawInRect:imageFrame fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0]; // suggested method to draw the image + // instead of compositeToPoint:operation: + // take back previous transformation (if the view is not flipped the coordinate transformation matrix contains the identity matrix + // and the next two operations do not change the content's transformation matrix): + [coordinateTransform invert]; + [coordinateTransform concat]; } - [image drawInRect:imageFrame fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0]; // suggested method to draw the image - // instead of compositeToPoint:operation: - // take back previous transformation (if the view is not flipped the coordinate transformation matrix contains the identity matrix - // and the next two operations do not change the content's transformation matrix): - [coordinateTransform invert]; - [coordinateTransform concat]; - } - // let the textfield cell draw the text part: - if (textFrame.size.width > [self cellTextSize].width) // for unknown reasons the alignment of the text cell is ignored; therefore change the size so that - textFrame.size.width = [self cellTextSize].width; // alignment does not influence the visualization anymore - [super drawWithFrame:textFrame inView:controlView]; + // let the textfield cell draw the text part: + if (textFrame.size.width > [self cellTextSize].width) // for unknown reasons the alignment of the text cell is ignored; therefore change the size so that + textFrame.size.width = [self cellTextSize].width; // alignment does not influence the visualization anymore + [super drawWithFrame:textFrame inView:controlView]; } -(void) editWithFrame:(NSRect)aRect inView:(NSView*)controlView editor:(NSText*)textObj delegate:(id)anObject event:(NSEvent*)theEvent { - NSRect textFrame, imageFrame; + NSRect textFrame, imageFrame; - [self determineCellParts:aRect imagePart:&imageFrame textPart:&textFrame]; - [super editWithFrame:textFrame inView:controlView editor:textObj delegate:anObject event:theEvent]; + [self determineCellParts:aRect imagePart:&imageFrame textPart:&textFrame]; + [super editWithFrame:textFrame inView:controlView editor:textObj delegate:anObject event:theEvent]; } #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 -(NSUInteger) hitTestForEvent:(NSEvent*)event inRect:(NSRect)cellFrame ofView:(NSView*)controlView { - NSPoint point = [controlView convertPoint:[event locationInWindow] fromView:nil]; + NSPoint point = [controlView convertPoint:[event locationInWindow] fromView:nil]; - NSRect imageFrame, textFrame; + NSRect imageFrame, textFrame; - [self determineCellParts:cellFrame imagePart:&imageFrame textPart:&textFrame]; - if (image != nil) - { - // the image is shifted... - if (imageFrame.size.width >= xImageShift+imageSize.width+spaceImageText) - { - imageFrame.origin.x += imageFrame.size.width-imageSize.width-spaceImageText; - imageFrame.size.width = imageSize.width; - } - else + [self determineCellParts:cellFrame imagePart:&imageFrame textPart:&textFrame]; + if (image != nil) { - imageFrame.origin.x += xImageShift; - imageFrame.size.width -= xImageShift+spaceImageText; + // the image is shifted... + if (imageFrame.size.width >= xImageShift+imageSize.width+spaceImageText) + { + imageFrame.origin.x += imageFrame.size.width-imageSize.width-spaceImageText; + imageFrame.size.width = imageSize.width; + } + else + { + imageFrame.origin.x += xImageShift; + imageFrame.size.width -= xImageShift+spaceImageText; + } + // ...and centered: + if (imageFrame.size.height > imageSize.height) + imageFrame.size.height = imageSize.height; + imageFrame.origin.y += ceil(0.5*(cellFrame.size.height-imageFrame.size.height)); + // If the point is in the image rect, then it is a content hit (see documentation for hitTestForEvent:inRect:ofView): + if (NSMouseInRect(point, imageFrame, [controlView isFlipped])) + return NSCellHitContentArea; } - // ...and centered: - if (imageFrame.size.height > imageSize.height) - imageFrame.size.height = imageSize.height; - imageFrame.origin.y += ceil(0.5*(cellFrame.size.height-imageFrame.size.height)); - // If the point is in the image rect, then it is a content hit (see documentation for hitTestForEvent:inRect:ofView): - if (NSMouseInRect(point, imageFrame, [controlView isFlipped])) - return NSCellHitContentArea; - } - // if the image was not hit let's try the text part: - if (textFrame.size.width > [self cellTextSize].width) // for unknown reasons the alignment of the text cell is ignored; therefore change the size so that - textFrame.size.width = [self cellTextSize].width; // alignment does not influence the visualization anymore - return [super hitTestForEvent:event inRect:textFrame ofView:controlView]; + // if the image was not hit let's try the text part: + if (textFrame.size.width > [self cellTextSize].width) // for unknown reasons the alignment of the text cell is ignored; therefore change the size so that + textFrame.size.width = [self cellTextSize].width; // alignment does not influence the visualization anymore + return [super hitTestForEvent:event inRect:textFrame ofView:controlView]; } #endif -(NSRect) imageRectForBounds:(NSRect)cellFrame { - NSRect textFrame, imageFrame; + NSRect textFrame, imageFrame; - [self determineCellParts:cellFrame imagePart:&imageFrame textPart:&textFrame]; - if (imageFrame.size.width >= xImageShift+imageSize.width+spaceImageText) - { - imageFrame.origin.x += imageFrame.size.width-imageSize.width-spaceImageText; - imageFrame.size.width = imageSize.width; - } - else - { - imageFrame.origin.x += xImageShift; - imageFrame.size.width -= xImageShift+spaceImageText; - } - // ...and centered: - if (imageFrame.size.height > imageSize.height) - imageFrame.size.height = imageSize.height; - imageFrame.origin.y += ceil(0.5*(cellFrame.size.height-imageFrame.size.height)); + [self determineCellParts:cellFrame imagePart:&imageFrame textPart:&textFrame]; + if (imageFrame.size.width >= xImageShift+imageSize.width+spaceImageText) + { + imageFrame.origin.x += imageFrame.size.width-imageSize.width-spaceImageText; + imageFrame.size.width = imageSize.width; + } + else + { + imageFrame.origin.x += xImageShift; + imageFrame.size.width -= xImageShift+spaceImageText; + } + // ...and centered: + if (imageFrame.size.height > imageSize.height) + imageFrame.size.height = imageSize.height; + imageFrame.origin.y += ceil(0.5*(cellFrame.size.height-imageFrame.size.height)); - return imageFrame; + return imageFrame; } -(void) selectWithFrame:(NSRect)aRect inView:(NSView*)controlView editor:(NSText*)textObj delegate:(id)anObject start:(NSInteger)selStart length:(NSInteger)selLength { - NSRect textFrame, imageFrame; + NSRect textFrame, imageFrame; - [self determineCellParts:aRect imagePart:&imageFrame textPart:&textFrame]; - [super selectWithFrame:textFrame inView:controlView editor:textObj delegate:anObject start:selStart length:selLength]; + [self determineCellParts:aRect imagePart:&imageFrame textPart:&textFrame]; + [super selectWithFrame:textFrame inView:controlView editor:textObj delegate:anObject start:selStart length:selLength]; } -(NSRect) titleRectForBounds:(NSRect)cellFrame { - NSRect textFrame, imageFrame; + NSRect textFrame, imageFrame; - [self determineCellParts:cellFrame imagePart:&imageFrame textPart:&textFrame]; - return textFrame; + [self determineCellParts:cellFrame imagePart:&imageFrame textPart:&textFrame]; + return textFrame; } @end @@ -1335,20 +1349,20 @@ wxWidgetImplType* CreateDataView(wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(pare // -(id) init { - self = [super init]; - if (self != nil) - { - currentlyEditedColumn = - currentlyEditedRow = -1; - - [self registerForDraggedTypes:[NSArray arrayWithObjects:DataViewPboardType,NSStringPboardType,nil]]; - [self setDelegate:self]; - [self setDoubleAction:@selector(actionDoubleClick:)]; - [self setDraggingSourceOperationMask:NSDragOperationEvery forLocal:NO]; - [self setDraggingSourceOperationMask:NSDragOperationEvery forLocal:YES]; - [self setTarget:self]; - } - return self; + self = [super init]; + if (self != nil) + { + currentlyEditedColumn = + currentlyEditedRow = -1; + + [self registerForDraggedTypes:[NSArray arrayWithObjects:DataViewPboardType,NSStringPboardType,nil]]; + [self setDelegate:self]; + [self setDoubleAction:@selector(actionDoubleClick:)]; + [self setDraggingSourceOperationMask:NSDragOperationEvery forLocal:NO]; + [self setDraggingSourceOperationMask:NSDragOperationEvery forLocal:YES]; + [self setTarget:self]; + } + return self; } // @@ -1356,29 +1370,29 @@ wxWidgetImplType* CreateDataView(wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(pare // -(wxCocoaDataViewControl*) implementation { - return implementation; + return implementation; } -(void) setImplementation:(wxCocoaDataViewControl*) newImplementation { - implementation = newImplementation; + implementation = newImplementation; } // // actions // -(void) actionDoubleClick:(id)sender - // actually the documentation (NSTableView 2007-10-31) for doubleAction: and setDoubleAction: seems to be wrong as this action message is always sent - // whether the cell is editable or not +// actually the documentation (NSTableView 2007-10-31) for doubleAction: and setDoubleAction: seems to be wrong as this action message is always sent +// whether the cell is editable or not { - wxDataViewCtrl* const dataViewCtrlPtr = implementation->GetDataViewCtrl(); + wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl(); - wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED,dataViewCtrlPtr->GetId()); // variable definition + wxDataViewEvent event(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED,dvc->GetId()); // variable definition - dataViewEvent.SetEventObject(dataViewCtrlPtr); - dataViewEvent.SetItem(wxDataViewItem([((wxPointerObject*) [self itemAtRow:[self clickedRow]]) pointer])); - dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); + event.SetEventObject(dvc); + event.SetItem(wxDataViewItem([((wxPointerObject*) [self itemAtRow:[self clickedRow]]) pointer])); + dvc->GetEventHandler()->ProcessEvent(event); } @@ -1386,26 +1400,26 @@ wxWidgetImplType* CreateDataView(wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(pare // contextual menus // -(NSMenu*) menuForEvent:(NSEvent*)theEvent - // this method does not do any special menu event handling but only sends an event message; therefore, the user - // has full control if a context menu should be shown or not +// this method does not do any special menu event handling but only sends an event message; therefore, the user +// has full control if a context menu should be shown or not { - wxDataViewCtrl* const dataViewCtrlPtr = implementation->GetDataViewCtrl(); + wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl(); - wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU,dataViewCtrlPtr->GetId()); + wxDataViewEvent event(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU,dvc->GetId()); - wxDataViewItemArray selectedItems; + wxDataViewItemArray selectedItems; - dataViewEvent.SetEventObject(dataViewCtrlPtr); - dataViewEvent.SetModel(dataViewCtrlPtr->GetModel()); - // get the item information; - // theoretically more than one ID can be returned but the event can only handle one item, therefore only the first - // item of the array is returned: - if (dataViewCtrlPtr->GetSelections(selectedItems) > 0) - dataViewEvent.SetItem(selectedItems[0]); - dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); - // nothing is done: - return nil; + event.SetEventObject(dvc); + event.SetModel(dvc->GetModel()); + // get the item information; + // theoretically more than one ID can be returned but the event can only handle one item, therefore only the first + // item of the array is returned: + if (dvc->GetSelections(selectedItems) > 0) + event.SetItem(selectedItems[0]); + dvc->GetEventHandler()->ProcessEvent(event); + // nothing is done: + return nil; } // @@ -1413,94 +1427,95 @@ wxWidgetImplType* CreateDataView(wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(pare // -(void) outlineView:(NSOutlineView*)outlineView mouseDownInHeaderOfTableColumn:(NSTableColumn*)tableColumn { - wxDataViewColumn* const dataViewColumnPtr(reinterpret_cast([[tableColumn identifier] pointer])); - - wxDataViewCtrl* const dataViewCtrlPtr = implementation->GetDataViewCtrl(); - - wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK,dataViewCtrlPtr->GetId()); + wxDataViewColumn* const col(static_cast([[tableColumn identifier] pointer])); + wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl(); - // first, send an event that the user clicked into a column's header: - dataViewEvent.SetEventObject(dataViewCtrlPtr); - dataViewEvent.SetColumn(dataViewCtrlPtr->GetColumnPosition(dataViewColumnPtr)); - dataViewEvent.SetDataViewColumn(dataViewColumnPtr); - dataViewCtrlPtr->HandleWindowEvent(dataViewEvent); + wxDataViewEvent + event(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK,dvc->GetId()); - // now, check if the click may have had an influence on sorting, too; - // the sorting setup has to be done only if the clicked table column is sortable and has not been used for - // sorting before the click; if the column is already responsible for sorting the native control changes - // the sorting direction automatically and informs the data source via outlineView:sortDescriptorsDidChange: - if (dataViewColumnPtr->IsSortable() && ([tableColumn sortDescriptorPrototype] == nil)) - { - // remove the sort order from the previously sorted column table (it can also be that - // no sorted column table exists): - UInt32 const noOfColumns = [outlineView numberOfColumns]; - for (UInt32 i=0; iGetColumnPosition(col)); + event.SetDataViewColumn(col); + dvc->HandleWindowEvent(event); - sortDescriptor = [[NSSortDescriptor alloc] initWithKey:[NSString stringWithFormat:@"%d",[outlineView columnWithIdentifier:[tableColumn identifier]]] - ascending:YES]; - sortDescriptors = [NSArray arrayWithObject:sortDescriptor]; - [tableColumn setSortDescriptorPrototype:sortDescriptor]; - [outlineView setSortDescriptors:sortDescriptors]; - [sortDescriptor release]; - } + // now, check if the click may have had an influence on sorting, too; + // the sorting setup has to be done only if the clicked table column is sortable and has not been used for + // sorting before the click; if the column is already responsible for sorting the native control changes + // the sorting direction automatically and informs the data source via outlineView:sortDescriptorsDidChange: + if (col->IsSortable() && ([tableColumn sortDescriptorPrototype] == nil)) + { + // remove the sort order from the previously sorted column table (it can also be that + // no sorted column table exists): + UInt32 const noOfColumns = [outlineView numberOfColumns]; + + for (UInt32 i=0; iGetDataViewCtrl(); + wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl(); - wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING,dataViewCtrlPtr->GetId()); // variable definition + wxDataViewEvent event(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING,dvc->GetId()); // variable definition - dataViewEvent.SetEventObject(dataViewCtrlPtr); - dataViewEvent.SetItem (wxDataViewItem([((wxPointerObject*) item) pointer])); - dataViewEvent.SetModel (dataViewCtrlPtr->GetModel()); - // finally send the equivalent wxWidget event: - dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); - // opening the container is allowed if not vetoed: - return dataViewEvent.IsAllowed(); + event.SetEventObject(dvc); + event.SetItem (wxDataViewItem([((wxPointerObject*) item) pointer])); + event.SetModel (dvc->GetModel()); + // finally send the equivalent wxWidget event: + dvc->GetEventHandler()->ProcessEvent(event); + // opening the container is allowed if not vetoed: + return event.IsAllowed(); } -(BOOL) outlineView:(NSOutlineView*)outlineView shouldExpandItem:(id)item { - wxDataViewCtrl* const dataViewCtrlPtr = implementation->GetDataViewCtrl(); + wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl(); - wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING,dataViewCtrlPtr->GetId()); // variable definition + wxDataViewEvent event(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING,dvc->GetId()); // variable definition - dataViewEvent.SetEventObject(dataViewCtrlPtr); - dataViewEvent.SetItem (wxDataViewItem([((wxPointerObject*) item) pointer])); - dataViewEvent.SetModel (dataViewCtrlPtr->GetModel()); - // finally send the equivalent wxWidget event: - dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); - // opening the container is allowed if not vetoed: - return dataViewEvent.IsAllowed(); + event.SetEventObject(dvc); + event.SetItem (wxDataViewItem([((wxPointerObject*) item) pointer])); + event.SetModel (dvc->GetModel()); + // finally send the equivalent wxWidget event: + dvc->GetEventHandler()->ProcessEvent(event); + // opening the container is allowed if not vetoed: + return event.IsAllowed(); } -(BOOL) outlineView:(NSOutlineView*)outlineView shouldSelectTableColumn:(NSTableColumn*)tableColumn { - return NO; + return NO; } -(void) outlineView:(wxCocoaOutlineView*)outlineView - willDisplayCell:(id)cell - forTableColumn:(NSTableColumn*)tableColumn - item:(id)item +willDisplayCell:(id)cell +forTableColumn:(NSTableColumn*)tableColumn +item:(id)item { wxDataViewCtrl * const dvc = implementation->GetDataViewCtrl(); wxDataViewModel * const model = dvc->GetModel(); wxDataViewColumn * const - dvCol(reinterpret_cast( - [[tableColumn identifier] pointer] - ) - ); + dvCol(static_cast( + [[tableColumn identifier] pointer] + ) + ); wxDataViewRenderer * const renderer = dvCol->GetRenderer(); wxDataViewRendererNativeData * const data = renderer->GetNativeData(); @@ -1555,9 +1570,9 @@ wxWidgetImplType* CreateDataView(wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(pare const wxColour& c = attr.GetColour(); colText = [NSColor colorWithDeviceRed:c.Red() / 255. - green:c.Green() / 255. - blue:c.Blue() / 255. - alpha:c.Alpha() / 255.]; + green:c.Green() / 255. + blue:c.Blue() / 255. + alpha:c.Alpha() / 255.]; } } } @@ -1586,125 +1601,126 @@ wxWidgetImplType* CreateDataView(wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(pare // -(void) outlineViewColumnDidMove:(NSNotification*)notification { - int const newColumnPosition = [[[notification userInfo] objectForKey:@"NSNewColumn"] intValue]; + int const newColumnPosition = [[[notification userInfo] objectForKey:@"NSNewColumn"] intValue]; - wxDataViewColumn* const dataViewColumnPtr(reinterpret_cast([[[[self tableColumns] objectAtIndex:newColumnPosition] identifier] pointer])); + wxDataViewColumn* const col(static_cast([[[[self tableColumns] objectAtIndex:newColumnPosition] identifier] pointer])); - wxDataViewCtrl* const dataViewCtrlPtr = implementation->GetDataViewCtrl(); + wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl(); - wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED,dataViewCtrlPtr->GetId()); + wxDataViewEvent event(wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED,dvc->GetId()); - dataViewEvent.SetEventObject(dataViewCtrlPtr); - dataViewEvent.SetColumn(dataViewCtrlPtr->GetColumnPosition(dataViewColumnPtr)); - dataViewEvent.SetDataViewColumn(dataViewColumnPtr); - dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); + event.SetEventObject(dvc); + event.SetColumn(dvc->GetColumnPosition(col)); + event.SetDataViewColumn(col); + dvc->GetEventHandler()->ProcessEvent(event); } -(void) outlineViewItemDidCollapse:(NSNotification*)notification { - wxDataViewCtrl* const dataViewCtrlPtr = implementation->GetDataViewCtrl(); + wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl(); - wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED,dataViewCtrlPtr->GetId()); + wxDataViewEvent event(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED,dvc->GetId()); - dataViewEvent.SetEventObject(dataViewCtrlPtr); - dataViewEvent.SetItem(wxDataViewItem([((wxPointerObject*) [[notification userInfo] objectForKey:@"NSObject"]) pointer])); - dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); + event.SetEventObject(dvc); + event.SetItem(wxDataViewItem([((wxPointerObject*) [[notification userInfo] objectForKey:@"NSObject"]) pointer])); + dvc->GetEventHandler()->ProcessEvent(event); } -(void) outlineViewItemDidExpand:(NSNotification*)notification { - wxDataViewCtrl* const dataViewCtrlPtr = implementation->GetDataViewCtrl(); + wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl(); - wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED,dataViewCtrlPtr->GetId()); + wxDataViewEvent event(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED,dvc->GetId()); - dataViewEvent.SetEventObject(dataViewCtrlPtr); - dataViewEvent.SetItem(wxDataViewItem([((wxPointerObject*) [[notification userInfo] objectForKey:@"NSObject"]) pointer])); - dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); + event.SetEventObject(dvc); + event.SetItem(wxDataViewItem([((wxPointerObject*) [[notification userInfo] objectForKey:@"NSObject"]) pointer])); + dvc->GetEventHandler()->ProcessEvent(event); } -(void) outlineViewSelectionDidChange:(NSNotification*)notification { - wxDataViewCtrl* const dataViewCtrlPtr = implementation->GetDataViewCtrl(); + wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl(); - wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED,dataViewCtrlPtr->GetId()); // variable definition + wxDataViewEvent event(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED,dvc->GetId()); // variable definition - dataViewEvent.SetEventObject(dataViewCtrlPtr); - dataViewEvent.SetModel (dataViewCtrlPtr->GetModel()); - // finally send the equivalent wxWidget event: - dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); + event.SetEventObject(dvc); + event.SetModel (dvc->GetModel()); + dvc->GetEventHandler()->ProcessEvent(event); } -(void) textDidBeginEditing:(NSNotification*)notification - // this notification is only sent if the user started modifying the cell (not when the user clicked into the cell - // and the cell's editor is called!) +// this notification is only sent if the user started modifying the cell (not when the user clicked into the cell +// and the cell's editor is called!) { - // call method of superclass (otherwise editing does not work correctly - the outline data source class is not - // informed about a change of data): - [super textDidBeginEditing:notification]; + // call method of superclass (otherwise editing does not work correctly - the outline data source class is not + // informed about a change of data): + [super textDidBeginEditing:notification]; - // remember the column being edited, it will be used in textDidEndEditing: - currentlyEditedColumn = [self editedColumn]; - currentlyEditedRow = [self editedRow]; + // remember the column being edited, it will be used in textDidEndEditing: + currentlyEditedColumn = [self editedColumn]; + currentlyEditedRow = [self editedRow]; - wxDataViewColumn* const dataViewColumnPtr = - static_cast( - [[[[self tableColumns] objectAtIndex:currentlyEditedColumn] identifier] pointer]); + wxDataViewColumn* const col = + static_cast( + [[[[self tableColumns] objectAtIndex:currentlyEditedColumn] identifier] pointer]); - wxDataViewCtrl* const dataViewCtrlPtr = implementation->GetDataViewCtrl(); + wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl(); - // stop editing of a custom item first (if necessary) - dataViewCtrlPtr->FinishCustomItemEditing(); + // stop editing of a custom item first (if necessary) + dvc->FinishCustomItemEditing(); - // now, send the event: - wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED,dataViewCtrlPtr->GetId()); // variable definition + // now, send the event: + wxDataViewEvent + event(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED,dvc->GetId()); // variable definition - dataViewEvent.SetEventObject(dataViewCtrlPtr); - dataViewEvent.SetItem( - wxDataViewItem([((wxPointerObject*) [self itemAtRow:currentlyEditedRow]) pointer])); - dataViewEvent.SetColumn(dataViewCtrlPtr->GetColumnPosition(dataViewColumnPtr)); - dataViewEvent.SetDataViewColumn(dataViewColumnPtr); - dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); + event.SetEventObject(dvc); + event.SetItem( + wxDataViewItem([((wxPointerObject*) [self itemAtRow:currentlyEditedRow]) pointer])); + event.SetColumn(dvc->GetColumnPosition(col)); + event.SetDataViewColumn(col); + dvc->GetEventHandler()->ProcessEvent(event); } -(void) textDidEndEditing:(NSNotification*)notification { - // call method of superclass (otherwise editing does not work correctly - the outline data source class is not - // informed about a change of data): - [super textDidEndEditing:notification]; - - // under OSX an event indicating the end of an editing session can be sent even if no event indicating a start of an - // editing session has been sent (see Documentation for NSControl controlTextDidEndEditing:); this is not expected by a user - // of the wxWidgets library and therefore an wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE event is only sent if a corresponding - // wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED has been sent before; to check if a wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED - // has been sent the last edited column/row are valid: - if ( currentlyEditedColumn != -1 && currentlyEditedRow != -1 ) - { - wxDataViewColumn* const dataViewColumnPtr = - static_cast( - [[[[self tableColumns] objectAtIndex:currentlyEditedColumn] identifier] pointer]); + // call method of superclass (otherwise editing does not work correctly - the outline data source class is not + // informed about a change of data): + [super textDidEndEditing:notification]; - wxDataViewCtrl* const dataViewCtrlPtr = implementation->GetDataViewCtrl(); + // under OSX an event indicating the end of an editing session can be sent even if no event indicating a start of an + // editing session has been sent (see Documentation for NSControl controlTextDidEndEditing:); this is not expected by a user + // of the wxWidgets library and therefore an wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE event is only sent if a corresponding + // wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED has been sent before; to check if a wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED + // has been sent the last edited column/row are valid: + if ( currentlyEditedColumn != -1 && currentlyEditedRow != -1 ) + { + wxDataViewColumn* const col = + static_cast( + [[[[self tableColumns] objectAtIndex:currentlyEditedColumn] identifier] pointer]); + + wxDataViewCtrl* const dvc = implementation->GetDataViewCtrl(); - // send event to wxWidgets: - wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE,dataViewCtrlPtr->GetId()); // variable definition + // send event to wxWidgets: + wxDataViewEvent + event(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE,dvc->GetId()); // variable definition - dataViewEvent.SetEventObject(dataViewCtrlPtr); - dataViewEvent.SetItem( - wxDataViewItem([((wxPointerObject*) [self itemAtRow:currentlyEditedRow]) pointer])); - dataViewEvent.SetColumn(dataViewCtrlPtr->GetColumnPosition(dataViewColumnPtr)); - dataViewEvent.SetDataViewColumn(dataViewColumnPtr); - dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent); + event.SetEventObject(dvc); + event.SetItem( + wxDataViewItem([((wxPointerObject*) [self itemAtRow:currentlyEditedRow]) pointer])); + event.SetColumn(dvc->GetColumnPosition(col)); + event.SetDataViewColumn(col); + dvc->GetEventHandler()->ProcessEvent(event); - // we're not editing any more - currentlyEditedColumn = - currentlyEditedRow = -1; - } + // we're not editing any more + currentlyEditedColumn = + currentlyEditedRow = -1; + } } @end @@ -1714,40 +1730,40 @@ wxWidgetImplType* CreateDataView(wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(pare // // constructors / destructor // -wxCocoaDataViewControl::wxCocoaDataViewControl(wxWindow* peer, wxPoint const& pos, wxSize const& size, long style) - :wxWidgetCocoaImpl(peer,[[NSScrollView alloc] initWithFrame:wxOSXGetFrameForControl(peer,pos,size)]), - m_DataSource(NULL), m_OutlineView([[wxCocoaOutlineView alloc] init]) + wxCocoaDataViewControl::wxCocoaDataViewControl(wxWindow* peer, const wxPoint& pos, const wxSize& size, long style) +:wxWidgetCocoaImpl(peer,[[NSScrollView alloc] initWithFrame:wxOSXGetFrameForControl(peer,pos,size)]), + m_DataSource(NULL), m_OutlineView([[wxCocoaOutlineView alloc] init]) { - // initialize scrollview (the outline view is part of a scrollview): - NSScrollView* scrollview = (NSScrollView*) GetWXWidget(); // definition for abbreviational purposes + // initialize scrollview (the outline view is part of a scrollview): + NSScrollView* scrollview = (NSScrollView*) GetWXWidget(); // definition for abbreviational purposes - [scrollview setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; - [scrollview setBorderType:NSNoBorder]; - [scrollview setHasVerticalScroller:YES]; - [scrollview setHasHorizontalScroller:YES]; - [scrollview setAutohidesScrollers:YES]; - [scrollview setDocumentView:m_OutlineView]; + [scrollview setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; + [scrollview setBorderType:NSNoBorder]; + [scrollview setHasVerticalScroller:YES]; + [scrollview setHasHorizontalScroller:YES]; + [scrollview setAutohidesScrollers:YES]; + [scrollview setDocumentView:m_OutlineView]; - // setting up the native control itself - NSUInteger maskGridStyle(NSTableViewGridNone); + // setting up the native control itself + NSUInteger maskGridStyle(NSTableViewGridNone); - [m_OutlineView setImplementation:this]; - [m_OutlineView setColumnAutoresizingStyle:NSTableViewSequentialColumnAutoresizingStyle]; - [m_OutlineView setIndentationPerLevel:GetDataViewCtrl()->GetIndent()]; - if (style & wxDV_HORIZ_RULES) - maskGridStyle |= NSTableViewSolidHorizontalGridLineMask; - if (style & wxDV_VERT_RULES) - maskGridStyle |= NSTableViewSolidVerticalGridLineMask; - [m_OutlineView setGridStyleMask:maskGridStyle]; - [m_OutlineView setAllowsMultipleSelection: (style & wxDV_MULTIPLE) != 0]; - [m_OutlineView setUsesAlternatingRowBackgroundColors:(style & wxDV_ROW_LINES) != 0]; + [m_OutlineView setImplementation:this]; + [m_OutlineView setColumnAutoresizingStyle:NSTableViewSequentialColumnAutoresizingStyle]; + [m_OutlineView setIndentationPerLevel:GetDataViewCtrl()->GetIndent()]; + if (style & wxDV_HORIZ_RULES) + maskGridStyle |= NSTableViewSolidHorizontalGridLineMask; + if (style & wxDV_VERT_RULES) + maskGridStyle |= NSTableViewSolidVerticalGridLineMask; + [m_OutlineView setGridStyleMask:maskGridStyle]; + [m_OutlineView setAllowsMultipleSelection: (style & wxDV_MULTIPLE) != 0]; + [m_OutlineView setUsesAlternatingRowBackgroundColors:(style & wxDV_ROW_LINES) != 0]; } wxCocoaDataViewControl::~wxCocoaDataViewControl() { - [m_DataSource release]; - [m_OutlineView release]; + [m_DataSource release]; + [m_OutlineView release]; } // @@ -1755,167 +1771,164 @@ wxCocoaDataViewControl::~wxCocoaDataViewControl() // bool wxCocoaDataViewControl::ClearColumns() { - bool const bufAllowsMultipleSelection = [m_OutlineView allowsMultipleSelection]; + bool const bufAllowsMultipleSelection = [m_OutlineView allowsMultipleSelection]; - // as there is a bug in NSOutlineView version (OSX 10.5.6 #6555162) the columns cannot be deleted if there is an outline column in the view; - // therefore, the whole view is deleted and newly constructed: - [m_OutlineView release]; - m_OutlineView = [[wxCocoaOutlineView alloc] init]; - [((NSScrollView*) GetWXWidget()) setDocumentView:m_OutlineView]; + // as there is a bug in NSOutlineView version (OSX 10.5.6 #6555162) the columns cannot be deleted if there is an outline column in the view; + // therefore, the whole view is deleted and newly constructed: + [m_OutlineView release]; + m_OutlineView = [[wxCocoaOutlineView alloc] init]; + [((NSScrollView*) GetWXWidget()) setDocumentView:m_OutlineView]; - // setting up the native control itself - [m_OutlineView setImplementation:this]; - [m_OutlineView setColumnAutoresizingStyle:NSTableViewSequentialColumnAutoresizingStyle]; - [m_OutlineView setIndentationPerLevel:GetDataViewCtrl()->GetIndent()]; - if (bufAllowsMultipleSelection) - [m_OutlineView setAllowsMultipleSelection:YES]; - [m_OutlineView setDataSource:m_DataSource]; - // done: - return true; + // setting up the native control itself + [m_OutlineView setImplementation:this]; + [m_OutlineView setColumnAutoresizingStyle:NSTableViewSequentialColumnAutoresizingStyle]; + [m_OutlineView setIndentationPerLevel:GetDataViewCtrl()->GetIndent()]; + if (bufAllowsMultipleSelection) + [m_OutlineView setAllowsMultipleSelection:YES]; + [m_OutlineView setDataSource:m_DataSource]; + // done: + return true; } bool wxCocoaDataViewControl::DeleteColumn(wxDataViewColumn* columnPtr) { - if ([m_OutlineView outlineTableColumn] == columnPtr->GetNativeData()->GetNativeColumnPtr()) - [m_OutlineView setOutlineTableColumn:nil]; // due to a bug this does not work - [m_OutlineView removeTableColumn:columnPtr->GetNativeData()->GetNativeColumnPtr()]; // due to a confirmed bug #6555162 the deletion does not work for - // outline table columns (... and there is no workaround) - return (([m_OutlineView columnWithIdentifier:[[[wxPointerObject alloc] initWithPointer:columnPtr] autorelease]]) == -1); + if ([m_OutlineView outlineTableColumn] == columnPtr->GetNativeData()->GetNativeColumnPtr()) + [m_OutlineView setOutlineTableColumn:nil]; // due to a bug this does not work + [m_OutlineView removeTableColumn:columnPtr->GetNativeData()->GetNativeColumnPtr()]; // due to a confirmed bug #6555162 the deletion does not work for + // outline table columns (... and there is no workaround) + return (([m_OutlineView columnWithIdentifier:[[[wxPointerObject alloc] initWithPointer:columnPtr] autorelease]]) == -1); } -void wxCocoaDataViewControl::DoSetExpanderColumn(wxDataViewColumn const* columnPtr) +void wxCocoaDataViewControl::DoSetExpanderColumn(const wxDataViewColumn *columnPtr) { - [m_OutlineView setOutlineTableColumn:columnPtr->GetNativeData()->GetNativeColumnPtr()]; + [m_OutlineView setOutlineTableColumn:columnPtr->GetNativeData()->GetNativeColumnPtr()]; } wxDataViewColumn* wxCocoaDataViewControl::GetColumn(unsigned int pos) const { - return reinterpret_cast([[[[m_OutlineView tableColumns] objectAtIndex:pos] identifier] pointer]); + return static_cast([[[[m_OutlineView tableColumns] objectAtIndex:pos] identifier] pointer]); } -int wxCocoaDataViewControl::GetColumnPosition(wxDataViewColumn const* columnPtr) const +int wxCocoaDataViewControl::GetColumnPosition(const wxDataViewColumn *columnPtr) const { - return [m_OutlineView columnWithIdentifier:[[[wxPointerObject alloc] initWithPointer:const_cast(columnPtr)] autorelease]]; + return [m_OutlineView columnWithIdentifier:[[[wxPointerObject alloc] initWithPointer:const_cast(columnPtr)] autorelease]]; } bool wxCocoaDataViewControl::InsertColumn(unsigned int pos, wxDataViewColumn* columnPtr) { - NSTableColumn* nativeColumn; - - - // create column and set the native data of the dataview column: - nativeColumn = ::CreateNativeColumn(columnPtr); - columnPtr->GetNativeData()->SetNativeColumnPtr(nativeColumn); - // as the native control does not allow the insertion of a column at a specified position the column is first appended and - // - if necessary - moved to its final position: - [m_OutlineView addTableColumn:nativeColumn]; - if (pos != static_cast([m_OutlineView numberOfColumns]-1)) - [m_OutlineView moveColumn:[m_OutlineView numberOfColumns]-1 toColumn:pos]; - // done: - return true; + // create column and set the native data of the dataview column: + NSTableColumn *nativeColumn = ::CreateNativeColumn(columnPtr); + columnPtr->GetNativeData()->SetNativeColumnPtr(nativeColumn); + // as the native control does not allow the insertion of a column at a specified position the column is first appended and + // - if necessary - moved to its final position: + [m_OutlineView addTableColumn:nativeColumn]; + if (pos != static_cast([m_OutlineView numberOfColumns]-1)) + [m_OutlineView moveColumn:[m_OutlineView numberOfColumns]-1 toColumn:pos]; + // done: + return true; } // // item related methods (inherited from wxDataViewWidgetImpl) // -bool wxCocoaDataViewControl::Add(wxDataViewItem const& parent, wxDataViewItem const& WXUNUSED(item)) +bool wxCocoaDataViewControl::Add(const wxDataViewItem& parent, const wxDataViewItem& WXUNUSED(item)) { - if (parent.IsOk()) - [m_OutlineView reloadItem:[m_DataSource getDataViewItemFromBuffer:parent] reloadChildren:YES]; - else - [m_OutlineView reloadData]; - return true; + if (parent.IsOk()) + [m_OutlineView reloadItem:[m_DataSource getDataViewItemFromBuffer:parent] reloadChildren:YES]; + else + [m_OutlineView reloadData]; + return true; } -bool wxCocoaDataViewControl::Add(wxDataViewItem const& parent, wxDataViewItemArray const& WXUNUSED(items)) +bool wxCocoaDataViewControl::Add(const wxDataViewItem& parent, const wxDataViewItemArray& WXUNUSED(items)) { - if (parent.IsOk()) - [m_OutlineView reloadItem:[m_DataSource getDataViewItemFromBuffer:parent] reloadChildren:YES]; - else - [m_OutlineView reloadData]; - return true; + if (parent.IsOk()) + [m_OutlineView reloadItem:[m_DataSource getDataViewItemFromBuffer:parent] reloadChildren:YES]; + else + [m_OutlineView reloadData]; + return true; } -void wxCocoaDataViewControl::Collapse(wxDataViewItem const& item) +void wxCocoaDataViewControl::Collapse(const wxDataViewItem& item) { - [m_OutlineView collapseItem:[m_DataSource getDataViewItemFromBuffer:item]]; + [m_OutlineView collapseItem:[m_DataSource getDataViewItemFromBuffer:item]]; } -void wxCocoaDataViewControl::EnsureVisible(wxDataViewItem const& item, wxDataViewColumn const* columnPtr) +void wxCocoaDataViewControl::EnsureVisible(const wxDataViewItem& item, const wxDataViewColumn *columnPtr) { - if (item.IsOk()) - { - [m_OutlineView scrollRowToVisible:[m_OutlineView rowForItem:[m_DataSource getDataViewItemFromBuffer:item]]]; - if (columnPtr != NULL) - [m_OutlineView scrollColumnToVisible:GetColumnPosition(columnPtr)]; - } + if (item.IsOk()) + { + [m_OutlineView scrollRowToVisible:[m_OutlineView rowForItem:[m_DataSource getDataViewItemFromBuffer:item]]]; + if (columnPtr) + [m_OutlineView scrollColumnToVisible:GetColumnPosition(columnPtr)]; + } } -void wxCocoaDataViewControl::Expand(wxDataViewItem const& item) +void wxCocoaDataViewControl::Expand(const wxDataViewItem& item) { - [m_OutlineView expandItem:[m_DataSource getDataViewItemFromBuffer:item]]; + [m_OutlineView expandItem:[m_DataSource getDataViewItemFromBuffer:item]]; } unsigned int wxCocoaDataViewControl::GetCount() const { - return [m_OutlineView numberOfRows]; + return [m_OutlineView numberOfRows]; } -wxRect wxCocoaDataViewControl::GetRectangle(wxDataViewItem const& item, wxDataViewColumn const* columnPtr) +wxRect wxCocoaDataViewControl::GetRectangle(const wxDataViewItem& item, const wxDataViewColumn *columnPtr) { - return wxFromNSRect([m_osxView superview],[m_OutlineView frameOfCellAtColumn:GetColumnPosition(columnPtr) - row:[m_OutlineView rowForItem:[m_DataSource getDataViewItemFromBuffer:item]]]); + return wxFromNSRect([m_osxView superview],[m_OutlineView frameOfCellAtColumn:GetColumnPosition(columnPtr) + row:[m_OutlineView rowForItem:[m_DataSource getDataViewItemFromBuffer:item]]]); } -bool wxCocoaDataViewControl::IsExpanded(wxDataViewItem const& item) const +bool wxCocoaDataViewControl::IsExpanded(const wxDataViewItem& item) const { - return [m_OutlineView isItemExpanded:[m_DataSource getDataViewItemFromBuffer:item]]; + return [m_OutlineView isItemExpanded:[m_DataSource getDataViewItemFromBuffer:item]]; } bool wxCocoaDataViewControl::Reload() { - [m_DataSource clearBuffers]; - [m_OutlineView scrollColumnToVisible:0]; - [m_OutlineView scrollRowToVisible:0]; - [m_OutlineView reloadData]; - return true; + [m_DataSource clearBuffers]; + [m_OutlineView scrollColumnToVisible:0]; + [m_OutlineView scrollRowToVisible:0]; + [m_OutlineView reloadData]; + return true; } -bool wxCocoaDataViewControl::Remove(wxDataViewItem const& parent, wxDataViewItem const& WXUNUSED(item)) +bool wxCocoaDataViewControl::Remove(const wxDataViewItem& parent, const wxDataViewItem& WXUNUSED(item)) { - if (parent.IsOk()) - [m_OutlineView reloadItem:[m_DataSource getDataViewItemFromBuffer:parent] reloadChildren:YES]; - else - [m_OutlineView reloadData]; - return true; + if (parent.IsOk()) + [m_OutlineView reloadItem:[m_DataSource getDataViewItemFromBuffer:parent] reloadChildren:YES]; + else + [m_OutlineView reloadData]; + return true; } -bool wxCocoaDataViewControl::Remove(wxDataViewItem const& parent, wxDataViewItemArray const& WXUNUSED(item)) +bool wxCocoaDataViewControl::Remove(const wxDataViewItem& parent, const wxDataViewItemArray& WXUNUSED(item)) { - if (parent.IsOk()) - [m_OutlineView reloadItem:[m_DataSource getDataViewItemFromBuffer:parent] reloadChildren:YES]; - else - [m_OutlineView reloadData]; - return true; + if (parent.IsOk()) + [m_OutlineView reloadItem:[m_DataSource getDataViewItemFromBuffer:parent] reloadChildren:YES]; + else + [m_OutlineView reloadData]; + return true; } -bool wxCocoaDataViewControl::Update(wxDataViewColumn const* columnPtr) +bool wxCocoaDataViewControl::Update(const wxDataViewColumn *columnPtr) { - return false; + return false; } -bool wxCocoaDataViewControl::Update(wxDataViewItem const& WXUNUSED(parent), wxDataViewItem const& item) +bool wxCocoaDataViewControl::Update(const wxDataViewItem& WXUNUSED(parent), const wxDataViewItem& item) { - [m_OutlineView reloadItem:[m_DataSource getDataViewItemFromBuffer:item]]; - return true; + [m_OutlineView reloadItem:[m_DataSource getDataViewItemFromBuffer:item]]; + return true; } -bool wxCocoaDataViewControl::Update(wxDataViewItem const& WXUNUSED(parent), wxDataViewItemArray const& items) +bool wxCocoaDataViewControl::Update(const wxDataViewItem& WXUNUSED(parent), const wxDataViewItemArray& items) { - for (size_t i=0; i([[[columns objectAtIndex:i] identifier] pointer]); - return NULL; + for (UInt32 i=0; i([[[columns objectAtIndex:i] identifier] pointer]); + return NULL; } void wxCocoaDataViewControl::Resort() { - [m_DataSource clearChildren]; - [m_OutlineView reloadData]; + [m_DataSource clearChildren]; + [m_OutlineView reloadData]; } // @@ -2012,40 +2025,40 @@ void wxCocoaDataViewControl::Resort() // void wxCocoaDataViewControl::DoSetIndent(int indent) { - [m_OutlineView setIndentationPerLevel:static_cast(indent)]; + [m_OutlineView setIndentationPerLevel:static_cast(indent)]; } -void wxCocoaDataViewControl::HitTest(wxPoint const& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const +void wxCocoaDataViewControl::HitTest(const wxPoint& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const { - NSPoint const nativePoint = wxToNSPoint((NSScrollView*) GetWXWidget(),point); + NSPoint const nativePoint = wxToNSPoint((NSScrollView*) GetWXWidget(),point); - int indexColumn; - int indexRow; + int indexColumn; + int indexRow; - indexColumn = [m_OutlineView columnAtPoint:nativePoint]; - indexRow = [m_OutlineView rowAtPoint: nativePoint]; - if ((indexColumn >= 0) && (indexRow >= 0)) - { - columnPtr = reinterpret_cast([[[[m_OutlineView tableColumns] objectAtIndex:indexColumn] identifier] pointer]); - item = wxDataViewItem([[m_OutlineView itemAtRow:indexRow] pointer]); - } - else - { - columnPtr = NULL; - item = wxDataViewItem(); - } + indexColumn = [m_OutlineView columnAtPoint:nativePoint]; + indexRow = [m_OutlineView rowAtPoint: nativePoint]; + if ((indexColumn >= 0) && (indexRow >= 0)) + { + columnPtr = static_cast([[[[m_OutlineView tableColumns] objectAtIndex:indexColumn] identifier] pointer]); + item = wxDataViewItem([[m_OutlineView itemAtRow:indexRow] pointer]); + } + else + { + columnPtr = NULL; + item = wxDataViewItem(); + } } -void wxCocoaDataViewControl::SetRowHeight(wxDataViewItem const& WXUNUSED(item), unsigned int WXUNUSED(height)) - // Not supported by the native control +void wxCocoaDataViewControl::SetRowHeight(const wxDataViewItem& WXUNUSED(item), unsigned int WXUNUSED(height)) + // Not supported by the native control { } void wxCocoaDataViewControl::OnSize() { - if ([m_OutlineView numberOfColumns] == 1) - [m_OutlineView sizeLastColumnToFit]; + if ([m_OutlineView numberOfColumns] == 1) + [m_OutlineView sizeLastColumnToFit]; } // @@ -2053,11 +2066,10 @@ void wxCocoaDataViewControl::OnSize() // wxDataFormat wxCocoaDataViewControl::GetDnDDataFormat(wxDataObjectComposite* dataObjects) { - wxDataFormat resultFormat; + wxDataFormat resultFormat; + if ( !dataObjects ) + return resultFormat; - - if (dataObjects != NULL) - { bool compatible(true); size_t const noOfFormats = dataObjects->GetFormatCount(); @@ -2065,78 +2077,79 @@ wxDataFormat wxCocoaDataViewControl::GetDnDDataFormat(wxDataObjectComposite* dat wxDataFormat* formats; - // get all formats and check afterwards if the formats are compatible; if they are compatible the preferred format is returned otherwise - // wxDF_INVALID is returned; - // currently compatible types (ordered by priority are): - // - wxDF_UNICODETEXT - wxDF_TEXT + // get all formats and check afterwards if the formats are compatible; if + // they are compatible the preferred format is returned otherwise + // wxDF_INVALID is returned; + // currently compatible types (ordered by priority are): + // - wxDF_UNICODETEXT - wxDF_TEXT formats = new wxDataFormat[noOfFormats]; dataObjects->GetAllFormats(formats); indexFormat = 0; while ((indexFormat < noOfFormats) && compatible) { - switch (resultFormat.GetType()) - { - case wxDF_INVALID: - resultFormat.SetType(formats[indexFormat].GetType()); // first format (should only be reached if indexFormat == 0) - break; - case wxDF_TEXT: - if (formats[indexFormat].GetType() == wxDF_UNICODETEXT) - resultFormat.SetType(wxDF_UNICODETEXT); - else // incompatible - { - resultFormat.SetType(wxDF_INVALID); - compatible = false; - } - break; - case wxDF_UNICODETEXT: - if (formats[indexFormat].GetType() != wxDF_TEXT) - { - resultFormat.SetType(wxDF_INVALID); - compatible = false; - } - break; - default: - resultFormat.SetType(wxDF_INVALID); // not (yet) supported format - compatible = false; - } - ++indexFormat; - } /* while */ - // clean up: + switch (resultFormat.GetType()) + { + case wxDF_INVALID: + resultFormat.SetType(formats[indexFormat].GetType()); // first format (should only be reached if indexFormat == 0) + break; + case wxDF_TEXT: + if (formats[indexFormat].GetType() == wxDF_UNICODETEXT) + resultFormat.SetType(wxDF_UNICODETEXT); + else // incompatible + { + resultFormat.SetType(wxDF_INVALID); + compatible = false; + } + break; + case wxDF_UNICODETEXT: + if (formats[indexFormat].GetType() != wxDF_TEXT) + { + resultFormat.SetType(wxDF_INVALID); + compatible = false; + } + break; + default: + resultFormat.SetType(wxDF_INVALID); // not (yet) supported format + compatible = false; + } + ++indexFormat; + } + delete[] formats; - } - return resultFormat; + + return resultFormat; } wxDataObjectComposite* wxCocoaDataViewControl::GetDnDDataObjects(NSData* dataObject) const { - wxDataFormatId dataFormatID; + wxDataFormatId dataFormatID; - [dataObject getBytes:&dataFormatID length:sizeof(wxDataFormatId)]; - switch (dataFormatID) - { - case wxDF_TEXT: - case wxDF_UNICODETEXT: - { - wxTextDataObject* textDataObject(new wxTextDataObject()); + [dataObject getBytes:&dataFormatID length:sizeof(wxDataFormatId)]; + switch (dataFormatID) + { + case wxDF_TEXT: + case wxDF_UNICODETEXT: + { + wxTextDataObject* textDataObject(new wxTextDataObject()); - if (textDataObject->SetData(wxDataFormat(dataFormatID),[dataObject length]-sizeof(wxDataFormatId),reinterpret_cast([dataObject bytes])+sizeof(wxDataFormatId))) - { - wxDataObjectComposite* dataObjectComposite(new wxDataObjectComposite()); + if (textDataObject->SetData(wxDataFormat(dataFormatID),[dataObject length]-sizeof(wxDataFormatId),static_cast([dataObject bytes])+sizeof(wxDataFormatId))) + { + wxDataObjectComposite* dataObjectComposite(new wxDataObjectComposite()); - dataObjectComposite->Add(textDataObject); - return dataObjectComposite; - } - else - { - delete textDataObject; - return NULL; - } - } - break; - default: - return NULL; - } + dataObjectComposite->Add(textDataObject); + return dataObjectComposite; + } + else + { + delete textDataObject; + return NULL; + } + } + break; + default: + return NULL; + } } // ---------------------------------------------------------------------------- @@ -2183,33 +2196,33 @@ void wxDataViewRendererNativeData::ApplyLineBreakMode(NSCell *cell) // --------------------------------------------------------- // wxDataViewRenderer // --------------------------------------------------------- -wxDataViewRenderer::wxDataViewRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align) - :wxDataViewRendererBase(varianttype,mode,align), m_alignment(align), m_mode(mode), m_NativeDataPtr(NULL) + wxDataViewRenderer::wxDataViewRenderer(const wxString& varianttype, wxDataViewCellMode mode, int align) +:wxDataViewRendererBase(varianttype,mode,align), m_alignment(align), m_mode(mode), m_NativeDataPtr(NULL) { } wxDataViewRenderer::~wxDataViewRenderer() { - delete m_NativeDataPtr; + delete m_NativeDataPtr; } void wxDataViewRenderer::SetAlignment(int align) { - m_alignment = align; - [GetNativeData()->GetColumnCell() setAlignment:ConvertToNativeHorizontalTextAlignment(align)]; + m_alignment = align; + [GetNativeData()->GetColumnCell() setAlignment:ConvertToNativeHorizontalTextAlignment(align)]; } void wxDataViewRenderer::SetMode(wxDataViewCellMode mode) { - m_mode = mode; - if (GetOwner() != NULL) - [GetOwner()->GetNativeData()->GetNativeColumnPtr() setEditable:(mode == wxDATAVIEW_CELL_EDITABLE)]; + m_mode = mode; + if ( GetOwner() ) + [GetOwner()->GetNativeData()->GetNativeColumnPtr() setEditable:(mode == wxDATAVIEW_CELL_EDITABLE)]; } void wxDataViewRenderer::SetNativeData(wxDataViewRendererNativeData* newNativeDataPtr) { - delete m_NativeDataPtr; - m_NativeDataPtr = newNativeDataPtr; + delete m_NativeDataPtr; + m_NativeDataPtr = newNativeDataPtr; } void wxDataViewRenderer::EnableEllipsize(wxEllipsizeMode mode) @@ -2233,16 +2246,20 @@ IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer,wxDataViewRendererBase) // --------------------------------------------------------- // wxDataViewCustomRenderer // --------------------------------------------------------- -wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align) - :wxDataViewRenderer(varianttype,mode,align), m_editorCtrlPtr(NULL), m_DCPtr(NULL) +wxDataViewCustomRenderer::wxDataViewCustomRenderer(const wxString& varianttype, + wxDataViewCellMode mode, + int align) + : wxDataViewRenderer(varianttype, mode, align), + m_editorCtrlPtr(NULL), + m_DCPtr(NULL) { - SetNativeData(new wxDataViewRendererNativeData([[wxCustomCell alloc] init])); + SetNativeData(new wxDataViewRendererNativeData([[wxCustomCell alloc] init])); } bool wxDataViewCustomRenderer::MacRender() { - [GetNativeData()->GetItemCell() setObjectValue:[[[wxCustomRendererObject alloc] initWithRenderer:this] autorelease]]; - return true; + [GetNativeData()->GetItemCell() setObjectValue:[[[wxCustomRendererObject alloc] initWithRenderer:this] autorelease]]; + return true; } IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer, wxDataViewRenderer) @@ -2250,30 +2267,32 @@ IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer, wxDataViewRenderer) // --------------------------------------------------------- // wxDataViewTextRenderer // --------------------------------------------------------- -wxDataViewTextRenderer::wxDataViewTextRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align) - :wxDataViewRenderer(varianttype,mode,align) +wxDataViewTextRenderer::wxDataViewTextRenderer(const wxString& varianttype, + wxDataViewCellMode mode, + int align) + : wxDataViewRenderer(varianttype,mode,align) { - NSTextFieldCell* cell; + NSTextFieldCell* cell; - cell = [[NSTextFieldCell alloc] init]; - [cell setAlignment:ConvertToNativeHorizontalTextAlignment(align)]; - SetNativeData(new wxDataViewRendererNativeData(cell)); - [cell release]; + cell = [[NSTextFieldCell alloc] init]; + [cell setAlignment:ConvertToNativeHorizontalTextAlignment(align)]; + SetNativeData(new wxDataViewRendererNativeData(cell)); + [cell release]; } bool wxDataViewTextRenderer::MacRender() { - if (GetValue().GetType() == GetVariantType()) - { - [GetNativeData()->GetItemCell() setObjectValue:wxCFStringRef(GetValue().GetString()).AsNSString()]; - return true; - } - else - { - wxFAIL_MSG(wxString(_("Text renderer cannot render value because of wrong value type; value type: ")) << GetValue().GetType()); - return false; - } + if (GetValue().GetType() == GetVariantType()) + { + [GetNativeData()->GetItemCell() setObjectValue:wxCFStringRef(GetValue().GetString()).AsNSString()]; + return true; + } + else + { + wxFAIL_MSG(wxString("Text renderer cannot render value because of wrong value type; value type: ") << GetValue().GetType()); + return false; + } } IMPLEMENT_CLASS(wxDataViewTextRenderer,wxDataViewRenderer) @@ -2281,31 +2300,33 @@ IMPLEMENT_CLASS(wxDataViewTextRenderer,wxDataViewRenderer) // --------------------------------------------------------- // wxDataViewBitmapRenderer // --------------------------------------------------------- -wxDataViewBitmapRenderer::wxDataViewBitmapRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align) - :wxDataViewRenderer(varianttype,mode,align) +wxDataViewBitmapRenderer::wxDataViewBitmapRenderer(const wxString& varianttype, + wxDataViewCellMode mode, + int align) + : wxDataViewRenderer(varianttype,mode,align) { - NSImageCell* cell; + NSImageCell* cell; - cell = [[NSImageCell alloc] init]; - SetNativeData(new wxDataViewRendererNativeData(cell)); - [cell release]; + cell = [[NSImageCell alloc] init]; + SetNativeData(new wxDataViewRendererNativeData(cell)); + [cell release]; } bool wxDataViewBitmapRenderer::MacRender() - // This method returns 'true' if - // - the passed bitmap is valid and it could be assigned to the native data browser; - // - the passed bitmap is invalid (or is not initialized); this case simulates a non-existing bitmap. - // In all other cases the method returns 'false'. + // This method returns 'true' if + // - the passed bitmap is valid and it could be assigned to the native data browser; + // - the passed bitmap is invalid (or is not initialized); this case simulates a non-existing bitmap. + // In all other cases the method returns 'false'. { - wxCHECK_MSG(GetValue().GetType() == GetVariantType(),false,wxString(_("Bitmap renderer cannot render value; value type: ")) << GetValue().GetType()); + wxCHECK_MSG(GetValue().GetType() == GetVariantType(),false,wxString("Bitmap renderer cannot render value; value type: ") << GetValue().GetType()); - wxBitmap bitmap; + wxBitmap bitmap; - bitmap << GetValue(); - if (bitmap.IsOk()) - [GetNativeData()->GetItemCell() setObjectValue:[[bitmap.GetNSImage() retain] autorelease]]; - return true; + bitmap << GetValue(); + if (bitmap.IsOk()) + [GetNativeData()->GetItemCell() setObjectValue:[[bitmap.GetNSImage() retain] autorelease]]; + return true; } IMPLEMENT_CLASS(wxDataViewBitmapRenderer,wxDataViewRenderer) @@ -2313,33 +2334,35 @@ IMPLEMENT_CLASS(wxDataViewBitmapRenderer,wxDataViewRenderer) // ------------------------------------- // wxDataViewChoiceRenderer // ------------------------------------- -wxDataViewChoiceRenderer::wxDataViewChoiceRenderer(wxArrayString const& choices, wxDataViewCellMode mode, int alignment) - :wxDataViewRenderer(wxT("string"),mode,alignment), m_Choices(choices) +wxDataViewChoiceRenderer::wxDataViewChoiceRenderer(const wxArrayString& choices, + wxDataViewCellMode mode, + int alignment) + : wxDataViewRenderer(wxT("string"),mode,alignment), m_Choices(choices) { - NSPopUpButtonCell* cell; + NSPopUpButtonCell* cell; - cell = [[NSPopUpButtonCell alloc] init]; - [cell setControlSize:NSMiniControlSize]; - [cell setFont:[[NSFont fontWithName:[[cell font] fontName] size:[NSFont systemFontSizeForControlSize:NSMiniControlSize]] autorelease]]; - for (size_t i=0; iGetItemCell()) selectItemWithTitle:[[wxCFStringRef(GetValue().GetString()).AsNSString() retain] autorelease]]; - return true; - } - else - { - wxFAIL_MSG(wxString(_("Choice renderer cannot render value because of wrong value type; value type: ")) << GetValue().GetType()); - return false; - } + if (GetValue().GetType() == GetVariantType()) + { + [((NSPopUpButtonCell*) GetNativeData()->GetItemCell()) selectItemWithTitle:[[wxCFStringRef(GetValue().GetString()).AsNSString() retain] autorelease]]; + return true; + } + else + { + wxFAIL_MSG(wxString("Choice renderer cannot render value because of wrong value type; value type: ") << GetValue().GetType()); + return false; + } } IMPLEMENT_CLASS(wxDataViewChoiceRenderer,wxDataViewRenderer) @@ -2347,67 +2370,70 @@ IMPLEMENT_CLASS(wxDataViewChoiceRenderer,wxDataViewRenderer) // --------------------------------------------------------- // wxDataViewDateRenderer // --------------------------------------------------------- -wxDataViewDateRenderer::wxDataViewDateRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align) - :wxDataViewRenderer(varianttype,mode,align) + +wxDataViewDateRenderer::wxDataViewDateRenderer(const wxString& varianttype, + wxDataViewCellMode mode, + int align) + : wxDataViewRenderer(varianttype,mode,align) { - NSTextFieldCell* cell; + NSTextFieldCell* cell; - NSDateFormatter* dateFormatter; + NSDateFormatter* dateFormatter; - dateFormatter = [[NSDateFormatter alloc] init]; - [dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4]; - [dateFormatter setDateStyle:NSDateFormatterShortStyle]; - cell = [[NSTextFieldCell alloc] init]; - [cell setFormatter:dateFormatter]; - SetNativeData(new wxDataViewRendererNativeData(cell,[NSDate dateWithString:@"2000-12-30 20:00:00 +0000"])); - [cell release]; - [dateFormatter release]; + dateFormatter = [[NSDateFormatter alloc] init]; + [dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4]; + [dateFormatter setDateStyle:NSDateFormatterShortStyle]; + cell = [[NSTextFieldCell alloc] init]; + [cell setFormatter:dateFormatter]; + SetNativeData(new wxDataViewRendererNativeData(cell,[NSDate dateWithString:@"2000-12-30 20:00:00 +0000"])); + [cell release]; + [dateFormatter release]; } bool wxDataViewDateRenderer::MacRender() { - if (GetValue().GetType() == GetVariantType()) - { - if (GetValue().GetDateTime().IsValid()) + if (GetValue().GetType() == GetVariantType()) { - // -- find best fitting style to show the date -- - // as the style should be identical for all cells a reference date instead of the actual cell's date - // value is used for all cells; this reference date is stored in the renderer's native data section - // for speed purposes; otherwise, the reference date's string has to be recalculated for each item that - // may become timewise long if a lot of rows using dates exist; - // the algorithm has the preference to display as much information as possible in the first instance; - // but as this is often impossible due to space restrictions the style is shortened per loop; finally, - // if the shortest time and date format does not fit into the cell the time part is dropped; - // remark: the time part itself is not modified per iteration loop and only uses the short style, - // means that only the hours and minutes are being shown - [GetNativeData()->GetItemCell() setObjectValue:GetNativeData()->GetObject()]; // GetObject() returns a date for testing the size of a date object - [[GetNativeData()->GetItemCell() formatter] setTimeStyle:NSDateFormatterShortStyle]; - for (int dateFormatterStyle=4; dateFormatterStyle>0; --dateFormatterStyle) - { - [[GetNativeData()->GetItemCell() formatter] setDateStyle:(NSDateFormatterStyle)dateFormatterStyle]; - if (dateFormatterStyle == 1) + if (GetValue().GetDateTime().IsValid()) { - // if the shortest style for displaying the date and time is too long to be fully visible remove the time part of the date: - if ([GetNativeData()->GetItemCell() cellSize].width > [GetNativeData()->GetColumnPtr() width]) - [[GetNativeData()->GetItemCell() formatter] setTimeStyle:NSDateFormatterNoStyle]; - break; // basically not necessary as the loop would end anyway but let's save the last comparison + // -- find best fitting style to show the date -- + // as the style should be identical for all cells a reference date instead of the actual cell's date + // value is used for all cells; this reference date is stored in the renderer's native data section + // for speed purposes; otherwise, the reference date's string has to be recalculated for each item that + // may become timewise long if a lot of rows using dates exist; + // the algorithm has the preference to display as much information as possible in the first instance; + // but as this is often impossible due to space restrictions the style is shortened per loop; finally, + // if the shortest time and date format does not fit into the cell the time part is dropped; + // remark: the time part itself is not modified per iteration loop and only uses the short style, + // means that only the hours and minutes are being shown + [GetNativeData()->GetItemCell() setObjectValue:GetNativeData()->GetObject()]; // GetObject() returns a date for testing the size of a date object + [[GetNativeData()->GetItemCell() formatter] setTimeStyle:NSDateFormatterShortStyle]; + for (int dateFormatterStyle=4; dateFormatterStyle>0; --dateFormatterStyle) + { + [[GetNativeData()->GetItemCell() formatter] setDateStyle:(NSDateFormatterStyle)dateFormatterStyle]; + if (dateFormatterStyle == 1) + { + // if the shortest style for displaying the date and time is too long to be fully visible remove the time part of the date: + if ([GetNativeData()->GetItemCell() cellSize].width > [GetNativeData()->GetColumnPtr() width]) + [[GetNativeData()->GetItemCell() formatter] setTimeStyle:NSDateFormatterNoStyle]; + break; // basically not necessary as the loop would end anyway but let's save the last comparison + } + else if ([GetNativeData()->GetItemCell() cellSize].width <= [GetNativeData()->GetColumnPtr() width]) + break; + } + // set data (the style is set by the previous loop); + // on OSX the date has to be specified with respect to UTC; in wxWidgets the date is always entered in the local timezone; so, we have to do a conversion + // from the local to UTC timezone when adding the seconds to 1970-01-01 UTC: + [GetNativeData()->GetItemCell() setObjectValue:[NSDate dateWithTimeIntervalSince1970:GetValue().GetDateTime().ToUTC().Subtract(wxDateTime(1,wxDateTime::Jan,1970)).GetSeconds().ToDouble()]]; } - else if ([GetNativeData()->GetItemCell() cellSize].width <= [GetNativeData()->GetColumnPtr() width]) - break; - } - // set data (the style is set by the previous loop); - // on OSX the date has to be specified with respect to UTC; in wxWidgets the date is always entered in the local timezone; so, we have to do a conversion - // from the local to UTC timezone when adding the seconds to 1970-01-01 UTC: - [GetNativeData()->GetItemCell() setObjectValue:[NSDate dateWithTimeIntervalSince1970:GetValue().GetDateTime().ToUTC().Subtract(wxDateTime(1,wxDateTime::Jan,1970)).GetSeconds().ToDouble()]]; + return true; + } + else + { + wxFAIL_MSG(wxString("Date renderer cannot render value because of wrong value type; value type: ") << GetValue().GetType()); + return false; } - return true; - } - else - { - wxFAIL_MSG(wxString(_("Date renderer cannot render value because of wrong value type; value type: ")) << GetValue().GetType()); - return false; - } } IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer,wxDataViewRenderer) @@ -2415,38 +2441,40 @@ IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer,wxDataViewRenderer) // --------------------------------------------------------- // wxDataViewIconTextRenderer // --------------------------------------------------------- -wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align) - :wxDataViewRenderer(varianttype,mode) +wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(const wxString& varianttype, + wxDataViewCellMode mode, + int align) + : wxDataViewRenderer(varianttype,mode) { - wxImageTextCell* cell; + wxImageTextCell* cell; - cell = [[wxImageTextCell alloc] init]; - [cell setAlignment:ConvertToNativeHorizontalTextAlignment(align)]; - SetNativeData(new wxDataViewRendererNativeData(cell)); - [cell release]; + cell = [[wxImageTextCell alloc] init]; + [cell setAlignment:ConvertToNativeHorizontalTextAlignment(align)]; + SetNativeData(new wxDataViewRendererNativeData(cell)); + [cell release]; } bool wxDataViewIconTextRenderer::MacRender() { - if (GetValue().GetType() == GetVariantType()) - { - wxDataViewIconText iconText; + if (GetValue().GetType() == GetVariantType()) + { + wxDataViewIconText iconText; - wxImageTextCell* cell; + wxImageTextCell* cell; - cell = (wxImageTextCell*) GetNativeData()->GetItemCell(); - iconText << GetValue(); - if (iconText.GetIcon().IsOk()) - [cell setImage:[[wxBitmap(iconText.GetIcon()).GetNSImage() retain] autorelease]]; - [cell setStringValue:[[wxCFStringRef(iconText.GetText()).AsNSString() retain] autorelease]]; - return true; - } - else - { - wxFAIL_MSG(wxString(_("Icon & text renderer cannot render value because of wrong value type; value type: ")) << GetValue().GetType()); - return false; - } + cell = (wxImageTextCell*) GetNativeData()->GetItemCell(); + iconText << GetValue(); + if (iconText.GetIcon().IsOk()) + [cell setImage:[[wxBitmap(iconText.GetIcon()).GetNSImage() retain] autorelease]]; + [cell setStringValue:[[wxCFStringRef(iconText.GetText()).AsNSString() retain] autorelease]]; + return true; + } + else + { + wxFAIL_MSG(wxString("Icon & text renderer cannot render value because of wrong value type; value type: ") << GetValue().GetType()); + return false; + } } IMPLEMENT_ABSTRACT_CLASS(wxDataViewIconTextRenderer,wxDataViewRenderer) @@ -2454,32 +2482,34 @@ IMPLEMENT_ABSTRACT_CLASS(wxDataViewIconTextRenderer,wxDataViewRenderer) // --------------------------------------------------------- // wxDataViewToggleRenderer // --------------------------------------------------------- -wxDataViewToggleRenderer::wxDataViewToggleRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align) - :wxDataViewRenderer(varianttype,mode) +wxDataViewToggleRenderer::wxDataViewToggleRenderer(const wxString& varianttype, + wxDataViewCellMode mode, + int align) + : wxDataViewRenderer(varianttype,mode) { - NSButtonCell* cell; + NSButtonCell* cell; - cell = [[NSButtonCell alloc] init]; - [cell setAlignment:ConvertToNativeHorizontalTextAlignment(align)]; - [cell setButtonType:NSSwitchButton]; - [cell setImagePosition:NSImageOnly]; - SetNativeData(new wxDataViewRendererNativeData(cell)); - [cell release]; + cell = [[NSButtonCell alloc] init]; + [cell setAlignment:ConvertToNativeHorizontalTextAlignment(align)]; + [cell setButtonType:NSSwitchButton]; + [cell setImagePosition:NSImageOnly]; + SetNativeData(new wxDataViewRendererNativeData(cell)); + [cell release]; } bool wxDataViewToggleRenderer::MacRender() { - if (GetValue().GetType() == GetVariantType()) - { - [GetNativeData()->GetItemCell() setIntValue:GetValue().GetLong()]; - return true; - } - else - { - wxFAIL_MSG(wxString(_("Toggle renderer cannot render value because of wrong value type; value type: ")) << GetValue().GetType()); - return false; - } + if (GetValue().GetType() == GetVariantType()) + { + [GetNativeData()->GetItemCell() setIntValue:GetValue().GetLong()]; + return true; + } + else + { + wxFAIL_MSG(wxString("Toggle renderer cannot render value because of wrong value type; value type: ") << GetValue().GetType()); + return false; + } } IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer,wxDataViewRenderer) @@ -2487,31 +2517,33 @@ IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer,wxDataViewRenderer) // --------------------------------------------------------- // wxDataViewProgressRenderer // --------------------------------------------------------- -wxDataViewProgressRenderer::wxDataViewProgressRenderer(wxString const& label, wxString const& varianttype, wxDataViewCellMode mode, int align) - :wxDataViewRenderer(varianttype,mode,align) +wxDataViewProgressRenderer::wxDataViewProgressRenderer(const wxString& label, + const wxString& varianttype, + wxDataViewCellMode mode, + int align) + : wxDataViewRenderer(varianttype,mode,align) { - NSLevelIndicatorCell* cell; - + NSLevelIndicatorCell* cell; - cell = [[NSLevelIndicatorCell alloc] initWithLevelIndicatorStyle:NSContinuousCapacityLevelIndicatorStyle]; - [cell setMinValue:0]; - [cell setMaxValue:100]; - SetNativeData(new wxDataViewRendererNativeData(cell)); - [cell release]; + cell = [[NSLevelIndicatorCell alloc] initWithLevelIndicatorStyle:NSContinuousCapacityLevelIndicatorStyle]; + [cell setMinValue:0]; + [cell setMaxValue:100]; + SetNativeData(new wxDataViewRendererNativeData(cell)); + [cell release]; } bool wxDataViewProgressRenderer::MacRender() { - if (GetValue().GetType() == GetVariantType()) - { - [GetNativeData()->GetItemCell() setIntValue:GetValue().GetLong()]; - return true; - } - else - { - wxFAIL_MSG(wxString(_("Progress renderer cannot render value because of wrong value type; value type: ")) << GetValue().GetType()); - return false; - } + if (GetValue().GetType() == GetVariantType()) + { + [GetNativeData()->GetItemCell() setIntValue:GetValue().GetLong()]; + return true; + } + else + { + wxFAIL_MSG(wxString("Progress renderer cannot render value because of wrong value type; value type: ") << GetValue().GetType()); + return false; + } } IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer,wxDataViewRenderer) @@ -2519,58 +2551,73 @@ IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer,wxDataViewRenderer) // --------------------------------------------------------- // wxDataViewColumn // --------------------------------------------------------- -wxDataViewColumn::wxDataViewColumn(const wxString& title, wxDataViewRenderer* renderer, unsigned int model_column, int width, wxAlignment align, int flags) - :wxDataViewColumnBase(renderer, model_column), m_NativeDataPtr(new wxDataViewColumnNativeData()), m_title(title) + +wxDataViewColumn::wxDataViewColumn(const wxString& title, + wxDataViewRenderer* renderer, + unsigned int model_column, + int width, + wxAlignment align, + int flags) + : wxDataViewColumnBase(renderer, model_column), + m_NativeDataPtr(new wxDataViewColumnNativeData()), + m_title(title) { - InitCommon(width, align, flags); - if ((renderer != NULL) && (renderer->GetAlignment() == wxDVR_DEFAULT_ALIGNMENT)) - renderer->SetAlignment(align); + InitCommon(width, align, flags); + if (renderer && (renderer->GetAlignment() == wxDVR_DEFAULT_ALIGNMENT)) + renderer->SetAlignment(align); } -wxDataViewColumn::wxDataViewColumn(const wxBitmap& bitmap, wxDataViewRenderer* renderer, unsigned int model_column, int width, wxAlignment align, int flags) - :wxDataViewColumnBase(bitmap, renderer, model_column), m_NativeDataPtr(new wxDataViewColumnNativeData()) +wxDataViewColumn::wxDataViewColumn(const wxBitmap& bitmap, + wxDataViewRenderer* renderer, + unsigned int model_column, + int width, + wxAlignment align, + int flags) + : wxDataViewColumnBase(bitmap, renderer, model_column), + m_NativeDataPtr(new wxDataViewColumnNativeData()) { - InitCommon(width, align, flags); - if ((renderer != NULL) && (renderer->GetAlignment() == wxDVR_DEFAULT_ALIGNMENT)) - renderer->SetAlignment(align); + InitCommon(width, align, flags); + if (renderer && (renderer->GetAlignment() == wxDVR_DEFAULT_ALIGNMENT)) + renderer->SetAlignment(align); } wxDataViewColumn::~wxDataViewColumn() { - delete m_NativeDataPtr; + delete m_NativeDataPtr; } bool wxDataViewColumn::IsSortKey() const { - return ((GetNativeData()->GetNativeColumnPtr() != NULL) && ([GetNativeData()->GetNativeColumnPtr() sortDescriptorPrototype] != nil)); + NSTableColumn *nsCol = GetNativeData()->GetNativeColumnPtr(); + return nsCol && ([nsCol sortDescriptorPrototype] != nil); } void wxDataViewColumn::SetAlignment(wxAlignment align) { - m_alignment = align; - [[m_NativeDataPtr->GetNativeColumnPtr() headerCell] setAlignment:ConvertToNativeHorizontalTextAlignment(align)]; - if ((m_renderer != NULL) && (m_renderer->GetAlignment() == wxDVR_DEFAULT_ALIGNMENT)) - m_renderer->SetAlignment(align); + m_alignment = align; + [[m_NativeDataPtr->GetNativeColumnPtr() headerCell] setAlignment:ConvertToNativeHorizontalTextAlignment(align)]; + if (m_renderer && (m_renderer->GetAlignment() == wxDVR_DEFAULT_ALIGNMENT)) + m_renderer->SetAlignment(align); } -void wxDataViewColumn::SetBitmap(wxBitmap const& bitmap) +void wxDataViewColumn::SetBitmap(const wxBitmap& bitmap) { - // bitmaps and titles cannot exist at the same time - if the bitmap is set the title is removed: - m_title = wxEmptyString; - wxDataViewColumnBase::SetBitmap(bitmap); - [[m_NativeDataPtr->GetNativeColumnPtr() headerCell] setImage:[[bitmap.GetNSImage() retain] autorelease]]; + // bitmaps and titles cannot exist at the same time - if the bitmap is set the title is removed: + m_title = wxEmptyString; + wxDataViewColumnBase::SetBitmap(bitmap); + [[m_NativeDataPtr->GetNativeColumnPtr() headerCell] setImage:[[bitmap.GetNSImage() retain] autorelease]]; } void wxDataViewColumn::SetMaxWidth(int maxWidth) { - m_maxWidth = maxWidth; - [m_NativeDataPtr->GetNativeColumnPtr() setMaxWidth:maxWidth]; + m_maxWidth = maxWidth; + [m_NativeDataPtr->GetNativeColumnPtr() setMaxWidth:maxWidth]; } void wxDataViewColumn::SetMinWidth(int minWidth) { - m_minWidth = minWidth; - [m_NativeDataPtr->GetNativeColumnPtr() setMinWidth:minWidth]; + m_minWidth = minWidth; + [m_NativeDataPtr->GetNativeColumnPtr() setMinWidth:minWidth]; } void wxDataViewColumn::SetReorderable(bool reorderable) @@ -2579,63 +2626,64 @@ void wxDataViewColumn::SetReorderable(bool reorderable) void wxDataViewColumn::SetResizeable(bool resizeable) { - wxDataViewColumnBase::SetResizeable(resizeable); - if (resizeable) - [m_NativeDataPtr->GetNativeColumnPtr() setResizingMask:NSTableColumnUserResizingMask]; - else - [m_NativeDataPtr->GetNativeColumnPtr() setResizingMask:NSTableColumnNoResizing]; + wxDataViewColumnBase::SetResizeable(resizeable); + if (resizeable) + [m_NativeDataPtr->GetNativeColumnPtr() setResizingMask:NSTableColumnUserResizingMask]; + else + [m_NativeDataPtr->GetNativeColumnPtr() setResizingMask:NSTableColumnNoResizing]; } void wxDataViewColumn::SetSortable(bool sortable) { - wxDataViewColumnBase::SetSortable(sortable); + wxDataViewColumnBase::SetSortable(sortable); } void wxDataViewColumn::SetSortOrder(bool ascending) { - if (m_ascending != ascending) - { - m_ascending = ascending; - if (IsSortKey()) + if (m_ascending != ascending) { - // change sorting order: - NSArray* sortDescriptors; - NSSortDescriptor* sortDescriptor; - NSTableColumn* tableColumn; - - tableColumn = m_NativeDataPtr->GetNativeColumnPtr(); - sortDescriptor = [[NSSortDescriptor alloc] initWithKey:[[tableColumn sortDescriptorPrototype] key] ascending:m_ascending]; - sortDescriptors = [NSArray arrayWithObject:sortDescriptor]; - [tableColumn setSortDescriptorPrototype:sortDescriptor]; - [[tableColumn tableView] setSortDescriptors:sortDescriptors]; - [sortDescriptor release]; + m_ascending = ascending; + if (IsSortKey()) + { + // change sorting order: + NSArray* sortDescriptors; + NSSortDescriptor* sortDescriptor; + NSTableColumn* tableColumn; + + tableColumn = m_NativeDataPtr->GetNativeColumnPtr(); + sortDescriptor = [[NSSortDescriptor alloc] initWithKey:[[tableColumn sortDescriptorPrototype] key] ascending:m_ascending]; + sortDescriptors = [NSArray arrayWithObject:sortDescriptor]; + [tableColumn setSortDescriptorPrototype:sortDescriptor]; + [[tableColumn tableView] setSortDescriptors:sortDescriptors]; + [sortDescriptor release]; + } } - } } -void wxDataViewColumn::SetTitle(wxString const& title) +void wxDataViewColumn::SetTitle(const wxString& title) { - // bitmaps and titles cannot exist at the same time - if the title is set the bitmap is removed: - wxDataViewColumnBase::SetBitmap(wxBitmap()); - m_title = title; - [[m_NativeDataPtr->GetNativeColumnPtr() headerCell] setStringValue:[[wxCFStringRef(title).AsNSString() retain] autorelease]]; + // bitmaps and titles cannot exist at the same time - if the title is set the bitmap is removed: + wxDataViewColumnBase::SetBitmap(wxBitmap()); + m_title = title; + [[m_NativeDataPtr->GetNativeColumnPtr() headerCell] setStringValue:[[wxCFStringRef(title).AsNSString() retain] autorelease]]; } void wxDataViewColumn::SetWidth(int width) { - [m_NativeDataPtr->GetNativeColumnPtr() setWidth:width]; - m_width = width; + [m_NativeDataPtr->GetNativeColumnPtr() setWidth:width]; + m_width = width; } void wxDataViewColumn::SetAsSortKey(bool WXUNUSED(sort)) { - // see wxGTK native wxDataViewColumn implementation - wxFAIL_MSG(_("not implemented")); + // see wxGTK native wxDataViewColumn implementation + wxFAIL_MSG("not implemented"); } void wxDataViewColumn::SetNativeData(wxDataViewColumnNativeData* newNativeDataPtr) { - delete m_NativeDataPtr; - m_NativeDataPtr = newNativeDataPtr; + delete m_NativeDataPtr; + m_NativeDataPtr = newNativeDataPtr; } + #endif // (wxUSE_DATAVIEWCTRL == 1) && !defined(wxUSE_GENERICDATAVIEWCTRL)