Add wxDataViewCtrl implementation for OSX/Cocoa (closes #10617: wxDataView for wxOSX-Cocoa)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60552 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2009-05-08 17:07:50 +00:00
parent 3df31b2d6e
commit e86edab05b
10 changed files with 6890 additions and 1552 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,494 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/osx/carbon/dataview.h
// Purpose: wxDataViewCtrl native implementation header for carbon
// Author:
// Id: $Id: dataview.h 57374 2009-01-27
// Copyright: (c) 2009
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_DATAVIEWCTRL_COCOOA_H_
#define _WX_DATAVIEWCTRL_COCOOA_H_
#include "wx/defs.h"
#if wxUSE_GUI
#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#endif
#include "wx/osx/core/dataview.h"
#include "wx/osx/private.h"
// Forward declaration
class wxCocoaDataViewControl;
// ============================================================================
// wxPointerObject
// ============================================================================
//
// 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
// means also that the hash value of a pointer object depends only on the
// stored pointer.
//
@interface wxPointerObject : NSObject
{
void* pointer;
}
//
// object initialization
//
-(id) initWithPointer:(void*)initPointer;
//
// access to pointer
//
-(void*) pointer;
-(void) setPointer:(void*)newPointer;
@end
// ============================================================================
// wxSortDescriptorObject
// ============================================================================
//
// This is a helper class to use native sorting facilities.
//
@interface wxSortDescriptorObject : NSSortDescriptor<NSCopying>
{
wxDataViewColumn* columnPtr; // pointer to the sorting column
wxDataViewModel* modelPtr; // pointer to model
}
//
// initialization
//
-(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;
@end
// ============================================================================
// wxDataViewColumnNativeData
// ============================================================================
class wxDataViewColumnNativeData
{
public:
//
// constructors / destructor
//
wxDataViewColumnNativeData(void) : m_NativeColumnPtr(NULL)
{
}
wxDataViewColumnNativeData(NSTableColumn* initNativeColumnPtr) : m_NativeColumnPtr(initNativeColumnPtr)
{
}
//
// data access methods
//
NSTableColumn* GetNativeColumnPtr(void) const
{
return this->m_NativeColumnPtr;
}
void SetNativeColumnPtr(NSTableColumn* newNativeColumnPtr)
{
this->m_NativeColumnPtr = newNativeColumnPtr;
}
protected:
private:
//
// variables
//
NSTableColumn* m_NativeColumnPtr; // this class does not take over ownership of the pointer nor retains it
};
// ============================================================================
// wxDataViewRendererNativeData
// ============================================================================
class wxDataViewRendererNativeData
{
public:
//
// constructors / destructor
//
wxDataViewRendererNativeData(void) : m_Object(NULL), m_ColumnCell(NULL)
{
}
wxDataViewRendererNativeData(NSCell* initColumnCell) : m_Object(NULL), m_ColumnCell([initColumnCell retain])
{
}
wxDataViewRendererNativeData(NSCell* initColumnCell, id initObject) : m_Object([initObject retain]), m_ColumnCell([initColumnCell retain])
{
}
~wxDataViewRendererNativeData(void)
{
[this->m_ColumnCell release];
[this->m_Object release];
}
//
// data access methods
//
NSCell* GetColumnCell(void) const
{
return this->m_ColumnCell;
}
NSTableColumn* GetColumnPtr(void) const
{
return this->m_TableColumnPtr;
}
id GetItem(void) const
{
return this->m_Item;
}
NSCell* GetItemCell(void) const
{
return this->m_ItemCell;
}
id GetObject(void) const
{
return this->m_Object;
}
void SetColumnCell(NSCell* newCell)
{
[newCell retain];
[this->m_ColumnCell release];
this->m_ColumnCell = newCell;
}
void SetColumnPtr(NSTableColumn* newColumnPtr)
{
this->m_TableColumnPtr = newColumnPtr;
}
void SetItem(id newItem)
{
this->m_Item = newItem;
}
void SetItemCell(NSCell* newCell)
{
this->m_ItemCell = newCell;
}
void SetObject(id newObject)
{
[newObject retain];
[this->m_Object release];
this->m_Object = newObject;
}
protected:
private:
//
// variables
//
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)
NSCell* m_ColumnCell; // column's cell is owned by renderer
NSCell* m_ItemCell; // item's cell is NOT owned by renderer
NSTableColumn* m_TableColumnPtr; // column NOT owned by renderer
};
// ============================================================================
// wxCocoaOutlineDataSource
// ============================================================================
//
// This class implements the data source delegate for the outline view.
// As only an informal protocol exists this class inherits from NSObject only.
//
// As mentioned in the documentation for NSOutlineView the native control does
// not own any data. Therefore, it has to be done by the data source.
// Unfortunately, wxWidget's data source is a C++ data source but
// NSOutlineDataSource requires objects as data. Therefore, the data (or better
// the native item objects) have to be stored additionally in the native data
// source.
// NSOutlineView requires quick access to the item objects and quick linear
// access to an item's children. This requires normally a hash type of storage
// for the item object itself and an array structure for each item's children.
// This means that basically two times the whole structure of wxWidget's model
// class has to be stored.
// This implementation is using a compromise: all items that are in use by the
// control are stored in a set (from there they can be easily retrieved) and
// owned by the set. Furthermore, children of the last parent are stored
// in a linear list.
//
@interface wxCocoaOutlineDataSource : NSObject
{
NSArray* sortDescriptors; // descriptors specifying the sorting (currently the array only holds one object only)
NSMutableArray* children; // buffered children
NSMutableSet* items; // stores all items that are in use by the control
wxCocoaDataViewControl* implementation;
wxDataViewModel* model;
wxPointerObject* currentParentItem; // parent of the buffered children; the object is owned
}
//
// methods of informal protocol:
//
-(BOOL) outlineView:(NSOutlineView*)outlineView acceptDrop:(id<NSDraggingInfo>)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<NSDraggingInfo>)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;
@end
// ============================================================================
// wxCustomCell
// ============================================================================
//
// This is a cell that is used for custom renderers.
//
@interface wxCustomCell : NSTextFieldCell
{
}
//
// other methods
//
-(NSSize) cellSize;
@end
// ============================================================================
// wxImageTextCell
// ============================================================================
//
// As the native cocoa environment does not have a cell displaying an icon/
// image and text at the same time, it has to be implemented by the user.
// This implementation follows the implementation of Chuck Pisula in Apple's
// DragNDropOutline sample application.
// Although in wxDataViewCtrl icons are used on OSX icons do not exist for
// display. Therefore, the cell is also called wxImageTextCell.
// Instead of displaying images of any size (which is possible) this cell uses
// a fixed size for displaying the image. Larger images are scaled to fit
// into their reserved space. Smaller or not existing images use the fixed
// reserved size and are scaled if necessary.
//
@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)
NSImage* image; // the image itself
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)
}
//
// 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;
@end
// ============================================================================
// wxCocoaOutlineView
// ============================================================================
@interface wxCocoaOutlineView : NSOutlineView
{
@private
BOOL isEditingCell; // flag indicating if a cell is currently being edited
wxCocoaDataViewControl* implementation;
}
//
// access to wxWidget's implementation
//
-(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
{
public:
//
// constructors / destructor
//
wxCocoaDataViewControl(wxWindow* peer, wxPoint const& pos, wxSize const& size, long style);
~wxCocoaDataViewControl(void);
//
// column related methods (inherited from wxDataViewWidgetImpl)
//
virtual bool ClearColumns (void);
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 (void) const;
virtual wxRect GetRectangle (wxDataViewItem const& item, wxDataViewColumn const* columnPtr);
virtual bool IsExpanded (wxDataViewItem const& item) const;
virtual bool Reload (void);
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 (void);
virtual void Unselect (wxDataViewItem const& item);
virtual void UnselectAll (void);
//
// sorting related methods
//
virtual wxDataViewColumn* GetSortingColumn (void) const;
virtual void Resort (void);
//
// 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 (void);
//
// other methods
//
wxDataViewCtrl* GetDataViewCtrl(void) const
{
return dynamic_cast<wxDataViewCtrl*>(this->GetWXPeer());
}
//
// 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;
wxCocoaOutlineView* m_OutlineView;
};
typedef wxCocoaDataViewControl* wxCocoaDataViewControlPointer;
#endif // wxUSE_GUI
#endif // _WX_DATAVIEWCTRL_COCOOA_H_

View File

@@ -0,0 +1,110 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/osx/core/dataview.h
// Purpose: wxDataViewCtrl native implementation header for OSX
// Author:
// Id: $Id: dataview.h 57374 2009-01-27
// Copyright: (c) 2009
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_DATAVIEWCTRL_CORE_H_
#define _WX_DATAVIEWCTRL_CORE_H_
#include "wx/dataview.h"
#if wxOSX_USE_CARBON
typedef wxMacControl wxWidgetImplType;
#else
typedef wxWidgetImpl wxWidgetImplType;
#endif
// ---------------------------------------------------------
// Helper functions for dataview implementation on OSX
// ---------------------------------------------------------
wxWidgetImplType* CreateDataView(wxWindowMac* wxpeer, wxWindowMac* parent, wxWindowID id,
wxPoint const& pos, wxSize const& size,
long style, long extraStyle);
wxString ConcatenateDataViewItemValues(wxDataViewCtrl const* dataViewCtrlPtr, wxDataViewItem const& dataViewItem); // concatenates all data of the visible columns of the passed control
// and item TAB separated into a string and returns it
// ---------------------------------------------------------
// wxDataViewWidgetImpl
// Common interface of the native dataview implementation
// for the carbon and cocoa environment.
// ATTENTION
// All methods assume that the passed column pointers are
// valid (unless a NULL pointer is explicitely allowed
// to be passed)!
// ATTENTION
// ---------------------------------------------------------
class WXDLLIMPEXP_CORE wxDataViewWidgetImpl
{
public:
//
// constructors / destructor
//
virtual ~wxDataViewWidgetImpl(void)
{
}
//
// column related methods
//
virtual bool ClearColumns (void) = 0; // deletes all columns in the native control
virtual bool DeleteColumn (wxDataViewColumn* columnPtr) = 0; // deletes the column in the native control
virtual void DoSetExpanderColumn(wxDataViewColumn const* columnPtr) = 0; // sets the disclosure column in the native control
virtual wxDataViewColumn* GetColumn (unsigned int pos) const = 0; // returns the column belonging to 'pos' in the native control
virtual int GetColumnPosition (wxDataViewColumn const* columnPtr) const = 0; // returns the position of the passed column in the native control
virtual bool InsertColumn (unsigned int pos, wxDataViewColumn* columnPtr) = 0; // inserts a column at pos in the native control;
// the method can assume that the column's owner is already set
//
// item related methods
//
virtual bool Add (wxDataViewItem const& parent, wxDataViewItem const& item) = 0; // adds an item to the native control
virtual bool Add (wxDataViewItem const& parent, wxDataViewItemArray const& itesm) = 0; // adds a items to the native control
virtual void Collapse (wxDataViewItem const& item) = 0; // collapses the passed item in the native control
virtual void EnsureVisible(wxDataViewItem const& item, wxDataViewColumn const* columnPtr) = 0; // ensures that the passed item's value in the passed column is visible (column pointer can be NULL)
virtual void Expand (wxDataViewItem const& item) = 0; // expands the passed item in the native control
virtual unsigned int GetCount (void) const = 0; // returns the number of items in the native control
virtual wxRect GetRectangle (wxDataViewItem const& item, wxDataViewColumn const* columnPtr) = 0; // returns the rectangle that is used by the passed item and column in the native control
virtual bool IsExpanded (wxDataViewItem const& item) const = 0; // checks if the passed item is expanded in the native control
virtual bool Reload (void) = 0; // clears the native control and reloads all data
virtual bool Remove (wxDataViewItem const& parent, wxDataViewItem const& item) = 0; // removes an item from the native control
virtual bool Remove (wxDataViewItem const& parent, wxDataViewItemArray const& item) = 0; // removes items from the native control
virtual bool Update (wxDataViewColumn const* columnPtr) = 0; // updates the items in the passed column of the native control
virtual bool Update (wxDataViewItem const& parent, wxDataViewItem const& item) = 0; // updates the passed item in the native control
virtual bool Update (wxDataViewItem const& parent, wxDataViewItemArray const& items) = 0; // updates the passed items in the native control
//
// model related methods
//
virtual bool AssociateModel(wxDataViewModel* model) = 0; // informs the native control that a model is present
//
// selection related methods
//
virtual int GetSelections(wxDataViewItemArray& sel) const = 0; // returns all selected items in the native control
virtual bool IsSelected (wxDataViewItem const& item) const = 0; // checks if the passed item is selected in the native control
virtual void Select (wxDataViewItem const& item) = 0; // selects the passed item in the native control
virtual void SelectAll (void) = 0; // selects all items in the native control
virtual void Unselect (wxDataViewItem const& item) = 0; // unselects the passed item in the native control
virtual void UnselectAll (void) = 0; // unselects all items in the native control
//
// sorting related methods
//
virtual wxDataViewColumn* GetSortingColumn (void) const = 0; // returns the column that is primarily responsible for sorting in the native control
virtual void Resort (void) = 0; // asks the native control to start a resorting process
//
// other methods
//
virtual void DoSetIndent (int indent) = 0; // sets the indention in the native control
virtual void HitTest (wxPoint const& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const = 0; // return the item and column pointer that contains with the passed point
virtual void SetRowHeight(wxDataViewItem const& item, unsigned int height) = 0; // sets the height of the row containg the passed item in the native control
virtual void OnSize (void) = 0; // updates the layout of the native control after a size event
};
#endif // _WX_DATAVIEWCTRL_CORE_H_

View File

@@ -1,5 +1,612 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/osx/dataview.h
// Purpose: wxDataViewCtrl native implementation header for OSX
// Author:
// Id: $Id$
// Copyright: (c) 2009
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_DATAVIEWCTRL_OSX_H_
#define _WX_DATAVIEWCTRL_OSX_H_
#ifdef __WXMAC_CLASSIC__
# error "Native wxDataViewCtrl for classic environment not defined. Please use generic control."
#else
# include "wx/osx/carbon/dataview.h"
#endif
// --------------------------------------------------------
// Class declarations to mask native types
// --------------------------------------------------------
class wxDataViewColumnNativeData; // class storing environment dependent data for the native implementation
class wxDataViewRendererNativeData; // class storing environment dependent data for the native renderer
class wxDataViewWidgetImpl; // class used as a common interface for carbon and cocoa implementation
// ---------------------------------------------------------
// wxDataViewRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewRenderer : public wxDataViewRendererBase
{
public:
//
// constructors / destructor
//
wxDataViewRenderer(wxString const& varianttype, wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
virtual ~wxDataViewRenderer(void);
//
// inherited methods from wxDataViewRendererBase
//
virtual int GetAlignment() const
{
return this->m_alignment;
}
virtual wxDataViewCellMode GetMode() const
{
return this->m_mode;
}
virtual bool GetValue(wxVariant& value) const
{
value = this->m_value;
return true;
}
virtual void SetAlignment(int align); // carbon: is always identical to the header alignment;
// cocoa: cell alignment is independent from header alignment
virtual void SetMode(wxDataViewCellMode mode);
virtual bool SetValue(wxVariant const& newValue)
{
this->m_value = newValue;
return true;
}
//
// implementation
//
wxVariant const& GetValue() const
{
return this->m_value;
}
wxDataViewRendererNativeData* GetNativeData() const
{
return this->m_NativeDataPtr;
}
virtual bool Render() = 0; // a call to the native data browser function to render the data;
// returns true if the data value could be rendered, false otherwise
void SetNativeData(wxDataViewRendererNativeData* newNativeDataPtr);
private:
//
// variables
//
int m_alignment; // contains the alignment flags
wxDataViewCellMode m_mode; // storing the mode that determines how the cell is going to be shown
wxDataViewRendererNativeData* m_NativeDataPtr; // data used by implementation of the native renderer
wxVariant m_value; // value that is going to be rendered
//
// wxWidget internal stuff
//
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer)
};
// ---------------------------------------------------------
// wxDataViewCustomRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewRenderer
{
public:
//
// constructors / destructor
//
wxDataViewCustomRenderer(wxString const& varianttype=wxT("string"), wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
virtual ~wxDataViewCustomRenderer();
void RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state );
//
// methods handling render space
//
virtual wxSize GetSize() const = 0;
//
// methods handling user actions
//
virtual bool Render(wxRect cell, wxDC* dc, int state) = 0;
virtual bool Activate( wxRect WXUNUSED(cell),
wxDataViewModel *WXUNUSED(model),
const wxDataViewItem & WXUNUSED(item),
unsigned int WXUNUSED(col) )
{ return false; }
virtual bool LeftClick( wxPoint WXUNUSED(cursor),
wxRect WXUNUSED(cell),
wxDataViewModel *WXUNUSED(model),
const wxDataViewItem & WXUNUSED(item),
unsigned int WXUNUSED(col) )
{ return false; }
virtual bool StartDrag( wxPoint WXUNUSED(cursor),
wxRect WXUNUSED(cell),
wxDataViewModel *WXUNUSED(model),
const wxDataViewItem & WXUNUSED(item),
unsigned int WXUNUSED(col) )
{ return false; }
//
// device context handling
//
virtual wxDC* GetDC(); // creates a device context and keeps it
//
// implementation
//
virtual bool Render();
void SetDC(wxDC* newDCPtr); // this method takes ownership of the pointer
protected:
private:
//
// variables
//
wxControl* m_editorCtrlPtr; // pointer to an in-place editor control
wxDC* m_DCPtr;
//
// wxWidget internal stuff
//
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
};
// ---------------------------------------------------------
// wxDataViewTextRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewRenderer
{
public:
//
// constructors / destructor
//
wxDataViewTextRenderer(wxString const& varianttype=wxT("string"), wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
//
// inherited functions from wxDataViewRenderer
//
virtual bool Render();
protected:
private:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
};
// ---------------------------------------------------------
// wxDataViewTextRendererAttr
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewTextRendererAttr: public wxDataViewTextRenderer
{
public:
//
// constructors / destructor
//
wxDataViewTextRendererAttr(wxString const& varianttype=wxT("string"), wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
private:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRendererAttr)
};
// ---------------------------------------------------------
// wxDataViewBitmapRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer
{
public:
//
// constructors / destructor
//
wxDataViewBitmapRenderer(wxString const& varianttype=wxT("wxBitmap"), wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
//
// inherited functions from wxDataViewRenderer
//
virtual bool Render();
protected:
private:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
};
#if !defined(wxUSE_GENERICDATAVIEWCTRL) && defined(__WXOSX_COCOA__)
// -------------------------------------
// wxDataViewChoiceRenderer
// -------------------------------------
class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer: public wxDataViewRenderer
{
public:
//
// constructors / destructor
//
wxDataViewChoiceRenderer(wxArrayString const& choices,
wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
int alignment = wxDVR_DEFAULT_ALIGNMENT );
//
// inherited functions from wxDataViewRenderer
//
virtual bool Render();
//
// implementation
//
wxString GetChoice(size_t index) const
{
return this->m_Choices[index];
}
wxArrayString const& GetChoices(void) const
{
return this->m_Choices;
}
private:
//
// variables
//
wxArrayString m_Choices;
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewChoiceRenderer)
};
#endif
// ---------------------------------------------------------
// wxDataViewIconTextRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewRenderer
{
public:
wxDataViewIconTextRenderer(wxString const& varianttype = wxT("wxDataViewIconText"), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
//
// inherited functions from wxDataViewRenderer
//
virtual bool Render();
protected:
private:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
};
// ---------------------------------------------------------
// wxDataViewToggleRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewRenderer
{
public:
wxDataViewToggleRenderer(wxString const& varianttype = wxT("bool"), wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
//
// inherited functions from wxDataViewRenderer
//
virtual bool Render();
protected:
private:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
};
// ---------------------------------------------------------
// wxDataViewProgressRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewRenderer
{
public:
wxDataViewProgressRenderer(wxString const& label = wxEmptyString, wxString const& varianttype=wxT("long"),
wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT);
//
// inherited functions from wxDataViewRenderer
//
virtual bool Render();
protected:
private:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
};
// ---------------------------------------------------------
// wxDataViewDateRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewRenderer
{
public:
wxDataViewDateRenderer(wxString const& varianttype=wxT("datetime"), wxDataViewCellMode mode=wxDATAVIEW_CELL_ACTIVATABLE, int align=wxDVR_DEFAULT_ALIGNMENT);
//
// inherited functions from wxDataViewRenderer
//
virtual bool Render();
protected:
private:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
};
// ---------------------------------------------------------
// wxDataViewColumn
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase
{
public:
// constructors / destructor
wxDataViewColumn(const wxString& title,
wxDataViewRenderer* renderer,
unsigned int model_column,
int width = wxDVC_DEFAULT_WIDTH,
wxAlignment align = wxALIGN_CENTER,
int flags = wxDATAVIEW_COL_RESIZABLE);
wxDataViewColumn(const wxBitmap& bitmap,
wxDataViewRenderer* renderer,
unsigned int model_column,
int width = wxDVC_DEFAULT_WIDTH,
wxAlignment align = wxALIGN_CENTER,
int flags = wxDATAVIEW_COL_RESIZABLE);
virtual ~wxDataViewColumn(void);
// implement wxHeaderColumnBase pure virtual methods
virtual wxAlignment GetAlignment() const { return m_alignment; }
virtual int GetFlags() const { return m_flags; }
virtual int GetMaxWidth() const { return m_maxWidth; }
virtual int GetMinWidth() const { return m_minWidth; }
virtual wxString GetTitle() const { return m_title; }
virtual int GetWidth() const { return m_width; }
virtual bool IsHidden() const { return false; } // TODO
virtual bool IsSortOrderAscending() const { return m_ascending; }
virtual bool IsSortKey() const;
virtual void SetAlignment (wxAlignment align);
virtual void SetBitmap (wxBitmap const& bitmap);
virtual void SetFlags (int flags) { SetIndividualFlags(flags); }
virtual void SetHidden (bool WXUNUSED(hidden)) { } // TODO
virtual void SetMaxWidth (int maxWidth);
virtual void SetMinWidth (int minWidth);
virtual void SetReorderable(bool reorderable);
virtual void SetResizeable (bool resizeable);
virtual void SetSortable (bool sortable);
virtual void SetSortOrder (bool ascending);
virtual void SetTitle (wxString const& title);
virtual void SetWidth (int width);
virtual void SetAsSortKey (bool sort = true);
// implementation only
wxDataViewColumnNativeData* GetNativeData(void) const
{
return this->m_NativeDataPtr;
}
void SetNativeData(wxDataViewColumnNativeData* newNativeDataPtr); // class takes ownership of pointer
void SetWidthVariable(int NewWidth)
{
m_width = NewWidth;
}
private:
// common part of all ctors
void InitCommon(int width, wxAlignment align, int flags)
{
m_ascending = true;
m_flags = flags & ~wxDATAVIEW_COL_HIDDEN; // TODO
m_maxWidth = 30000;
m_minWidth = 0;
m_width = width >= 0 ? width : wxDVC_DEFAULT_WIDTH;
m_alignment = align;
}
bool m_ascending; // sorting order
int m_flags; // flags for the column
int m_maxWidth; // maximum width for the column
int m_minWidth; // minimum width for the column
int m_width; // column width
wxAlignment m_alignment; // column header alignment
wxDataViewColumnNativeData* m_NativeDataPtr; // storing environment dependent data for the native implementation
wxString m_title; // column title
};
//
// type definitions related to wxDataViewColumn
//
WX_DEFINE_ARRAY(wxDataViewColumn*,wxDataViewColumnPtrArrayType);
// ---------------------------------------------------------
// wxDataViewCtrl
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase
{
public:
// Constructors / destructor:
wxDataViewCtrl()
{
this->Init();
}
wxDataViewCtrl(wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0,
const wxValidator& validator = wxDefaultValidator)
{
this->Init();
this->Create(parent, id, pos, size, style, validator );
}
~wxDataViewCtrl();
// explicit control creation
bool Create(wxWindow *parent, wxWindowID id, const wxPoint& pos=wxDefaultPosition, const wxSize& size=wxDefaultSize, long style=0,
const wxValidator& validator=wxDefaultValidator);
virtual wxControl* GetMainWindow() // not used for the native implementation
{
return this;
}
// inherited methods from wxDataViewCtrlBase:
virtual bool AssociateModel(wxDataViewModel* model);
virtual bool AppendColumn (wxDataViewColumn* columnPtr);
virtual bool ClearColumns (void);
virtual bool DeleteColumn (wxDataViewColumn* columnPtr);
virtual wxDataViewColumn* GetColumn (unsigned int pos) const;
virtual unsigned int GetColumnCount (void) const;
virtual int GetColumnPosition(const wxDataViewColumn* columnPtr) const;
virtual wxDataViewColumn* GetSortingColumn (void) const;
virtual bool InsertColumn (unsigned int pos, wxDataViewColumn *col);
virtual bool PrependColumn (wxDataViewColumn* columnPtr);
virtual void Collapse( const wxDataViewItem& item);
virtual void EnsureVisible(const wxDataViewItem& item, const wxDataViewColumn* columnPtr=NULL);
virtual void Expand(const wxDataViewItem& item);
virtual bool IsExpanded(const wxDataViewItem & item) const;
virtual unsigned int GetCount() const;
virtual wxRect GetItemRect(const wxDataViewItem& item, const wxDataViewColumn* columnPtr) const;
virtual wxDataViewItem GetSelection() const;
virtual int GetSelections(wxDataViewItemArray& sel) const;
virtual void HitTest(const wxPoint& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const;
virtual bool IsSelected(const wxDataViewItem& item) const;
virtual void SelectAll();
virtual void Select(const wxDataViewItem& item);
virtual void SetSelections(const wxDataViewItemArray& sel);
virtual void Unselect(const wxDataViewItem& item);
virtual void UnselectAll();
//
// implementation
//
// returns a pointer to the native implementation
wxDataViewWidgetImpl* GetDataViewPeer(void) const;
// adds all children of the passed parent to the control; if 'parentItem' is invalid the root(s) is/are added:
void AddChildren(wxDataViewItem const& parentItem);
// finishes editing of custom items; if no custom item is currently edited the method does nothing
void FinishCustomItemEditing(void);
// returns the n-th pointer to a column;
// this method is different from GetColumn(unsigned int pos) because here 'n' is not a position in the control but the n-th
// position in the internal list/array of column pointers
wxDataViewColumn* GetColumnPtr(size_t n) const
{
return this->m_ColumnPtrs[n];
}
// returns the current being rendered item of the customized renderer (this item is only valid during editing)
wxDataViewItem const& GetCustomRendererItem() const
{
return this->m_CustomRendererItem;
}
// returns a pointer to a customized renderer (this pointer is only valid during editing)
wxDataViewCustomRenderer* GetCustomRendererPtr() const
{
return this->m_CustomRendererPtr;
}
// checks if currently a delete process is running
bool IsDeleting() const
{
return this->m_Deleting;
}
// with CG, we need to get the context from an kEventControlDraw event
// unfortunately, the DataBrowser callbacks don't provide the context
// and we need it, so we need to set/remove it before and after draw
// events so we can access it in the callbacks.
void MacSetDrawingContext(void* context)
{
this->m_cgContext = context;
}
void* MacGetDrawingContext() const
{
return this->m_cgContext;
}
// sets the currently being edited item of the custom renderer
void SetCustomRendererItem(wxDataViewItem const& NewItem)
{
this->m_CustomRendererItem = NewItem;
}
// sets the custom renderer
void SetCustomRendererPtr(wxDataViewCustomRenderer* NewCustomRendererPtr)
{
this->m_CustomRendererPtr = NewCustomRendererPtr;
}
// sets the flag indicating a deletion process:
void SetDeleting(bool deleting)
{
this->m_Deleting = deleting;
}
virtual wxVisualAttributes GetDefaultAttributes() const
{
return GetClassDefaultAttributes(GetWindowVariant());
}
static wxVisualAttributes
GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
protected:
// inherited methods from wxDataViewCtrlBase
virtual void DoSetExpanderColumn();
virtual void DoSetIndent();
// event handling
void OnSize(wxSizeEvent &event);
private:
// initializing of local variables:
void Init();
//
// variables
//
bool m_Deleting; // flag indicating if a delete process is running; this flag is necessary because the notifier indicating an item deletion in the model may be called
// after the actual deletion of the item; then, native callback functions/delegates may try to update data of variables that are already deleted;
// if this flag is set all native variable update requests will be ignored
void* m_cgContext; // pointer to core graphics context
wxDataViewCustomRenderer* m_CustomRendererPtr; // pointer to a valid custom renderer while editing; this class does NOT own the pointer
wxDataViewItem m_CustomRendererItem; // currently edited item by the customrenderer; it is invalid while not editing a custom item
wxDataViewColumnPtrArrayType m_ColumnPtrs; // all column pointers are stored in an array
// wxWidget internal stuff:
DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
DECLARE_EVENT_TABLE()
};
#endif // _WX_DATAVIEWCTRL_OSX_H_