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

View File

@@ -2175,6 +2175,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
src/osx/checkbox_osx.cpp
src/osx/checklst_osx.cpp
src/osx/choice_osx.cpp
src/osx/dataview_osx.cpp
src/osx/dialog_osx.cpp
src/osx/fontutil.cpp
src/osx/gauge_osx.cpp
@@ -2208,6 +2209,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
src/osx/core/bitmap.cpp
src/osx/core/colour.cpp
src/osx/core/dataview.cpp
src/osx/core/dcmemory.cpp
src/osx/core/display.cpp
src/osx/core/fontenum.cpp
@@ -2941,6 +2943,7 @@ src/osx/iphone/window.mm
src/generic/animateg.cpp
src/osx/carbon/sound.cpp
src/osx/cocoa/aboutdlg.mm
src/osx/cocoa/dataview.mm
src/osx/cocoa/taskbar.mm
src/osx/core/hidjoystick.cpp
</set>
@@ -2952,6 +2955,7 @@ src/osx/iphone/window.mm
wx/osx/sound.h
wx/osx/taskbarosx.h
wx/osx/core/joystick.h
wx/osx/cocoa/dataview.h
</set>
<set var="ADVANCED_COCOA_SRC" hints="files">

View File

@@ -27,7 +27,7 @@
class WXDLLIMPEXP_FWD_CORE wxImageList;
#if !(defined(__WXGTK20__) || defined(__WXOSX_CARBON__)) || defined(__WXUNIVERSAL__)
#if !(defined(__WXGTK20__) || defined(__WXOSX__)) || defined(__WXUNIVERSAL__)
// #if !(defined(__WXMAC__)) || defined(__WXUNIVERSAL__)
#define wxHAS_GENERIC_DATAVIEWCTRL
#endif
@@ -525,8 +525,7 @@ public:
{ m_owner = owner; }
// getters:
unsigned int GetModelColumn() const
{ return static_cast<unsigned int>(m_model_column); }
unsigned int GetModelColumn() const { return static_cast<unsigned int>(m_model_column); }
wxDataViewCtrl *GetOwner() const { return m_owner; }
wxDataViewRenderer* GetRenderer() const { return m_renderer; }
@@ -929,7 +928,7 @@ private:
long m_min,m_max;
};
#if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXMAC__)
#if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXOSX_CARBON__)
// -------------------------------------
// wxDataViewChoiceRenderer

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_

View File

@@ -1298,7 +1298,7 @@ bool wxDataViewSpinRenderer::GetValue( wxVariant &value ) const
// wxDataViewChoiceRenderer
// -------------------------------------
#if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXMAC__)
#if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXOSX_CARBON__)
wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString& choices, wxDataViewCellMode mode, int alignment ) :
wxDataViewCustomRenderer(wxT("string"), mode, alignment )

File diff suppressed because it is too large Load Diff

2512
src/osx/cocoa/dataview.mm Normal file

File diff suppressed because it is too large Load Diff

686
src/osx/dataview_osx.cpp Normal file
View File

@@ -0,0 +1,686 @@
/////////////////////////////////////////////////////////////////////////////
// Name: src/osx/dataview_osx.cpp
// Purpose: wxDataViewCtrl native mac implementation
// Author:
// Id: $Id: dataview_osx.cpp 58317 2009-01-27
// Copyright: (c) 2009
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#if (wxUSE_DATAVIEWCTRL != 0) && (!defined(wxUSE_GENERICDATAVIEWCTRL) || (wxUSE_GENERICDATAVIEWCTRL == 0))
#include <carbon/carbon.h>
#include <limits>
#ifndef WX_PRECOMP
#include "wx/timer.h"
#include "wx/settings.h"
#include "wx/dcclient.h"
#include "wx/icon.h"
#endif
#include "wx/osx/core/dataview.h"
#include "wx/osx/private.h"
#include "wx/renderer.h"
// ============================================================================
// Helper functions for dataviewe implementation on OSX
// ============================================================================
wxString ConcatenateDataViewItemValues(wxDataViewCtrl const* dataViewCtrlPtr, wxDataViewItem const& dataViewItem)
{
wxString dataString; // contains the TAB concatenated data
for (size_t i=0; i<dataViewCtrlPtr->GetColumnCount(); i++)
{
// variable definition:
wxVariant dataValue;
dataViewCtrlPtr->GetModel()->GetValue(dataValue,dataViewItem,dataViewCtrlPtr->GetColumn(i)->GetModelColumn());
if (i > 0)
dataString << wxT('\t');
dataString << dataValue.MakeString();
}
return dataString;
}
// ============================================================================
// wxOSXDataViewModelNotifier
// ============================================================================
class wxOSXDataViewModelNotifier : public wxDataViewModelNotifier
{
public:
//
// constructors / destructor
//
wxOSXDataViewModelNotifier(wxDataViewCtrl* initDataViewCtrlPtr);
//
// inherited methods from wxDataViewModelNotifier
//
virtual bool ItemAdded (wxDataViewItem const &parent, wxDataViewItem const &item);
virtual bool ItemsAdded (wxDataViewItem const& parent, wxDataViewItemArray const& items);
virtual bool ItemChanged (wxDataViewItem const& item);
virtual bool ItemsChanged(wxDataViewItemArray const& items);
virtual bool ItemDeleted (wxDataViewItem const& parent, wxDataViewItem const& item);
virtual bool ItemsDeleted(wxDataViewItem const& parent, wxDataViewItemArray const& items);
virtual bool ValueChanged(wxDataViewItem const& item, unsigned int col);
virtual bool Cleared();
virtual void Resort();
protected:
// if the dataview control can have a variable row height this method sets the dataview's control row height of
// the passed item to the maximum value occupied by the item in all columns
void AdjustRowHeight(wxDataViewItem const& item);
// ... and the same method for a couple of items:
void AdjustRowHeights(wxDataViewItemArray const& items);
private:
wxDataViewCtrl* m_DataViewCtrlPtr;
};
//
// constructors / destructor
//
wxOSXDataViewModelNotifier::wxOSXDataViewModelNotifier(wxDataViewCtrl* initDataViewCtrlPtr)
:m_DataViewCtrlPtr(initDataViewCtrlPtr)
{
if (initDataViewCtrlPtr == NULL)
wxFAIL_MSG(_("Pointer to dataview control must not be NULL"));
}
bool wxOSXDataViewModelNotifier::ItemAdded(wxDataViewItem const& parent, wxDataViewItem const& item)
{
bool noFailureFlag;
wxCHECK_MSG(item.IsOk(),false,_("Added item is invalid."));
noFailureFlag = this->m_DataViewCtrlPtr->GetDataViewPeer()->Add(parent,item);
this->AdjustRowHeight(item);
return noFailureFlag;
}
bool wxOSXDataViewModelNotifier::ItemsAdded(wxDataViewItem const& parent, wxDataViewItemArray const& items)
{
bool noFailureFlag;
// insert all valid items into control:
noFailureFlag = this->m_DataViewCtrlPtr->GetDataViewPeer()->Add(parent,items);
// adjust row heights:
this->AdjustRowHeights(items);
// done:
return noFailureFlag;
}
bool wxOSXDataViewModelNotifier::ItemChanged(wxDataViewItem const& item)
{
wxCHECK_MSG(item.IsOk(), false,_("Changed item is invalid."));
wxCHECK_MSG(this->GetOwner() != NULL,false,_("Owner not initialized."));
if (this->m_DataViewCtrlPtr->GetDataViewPeer()->Update(this->GetOwner()->GetParent(item),item))
{
// sent the equivalent wxWidget event:
wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED,this->m_DataViewCtrlPtr->GetId());
dataViewEvent.SetEventObject(this->m_DataViewCtrlPtr);
dataViewEvent.SetItem(item);
// sent the equivalent wxWidget event:
this->m_DataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
// row height may have to be adjusted:
this->AdjustRowHeight(item);
// done
return true;
}
else
return false;
}
bool wxOSXDataViewModelNotifier::ItemsChanged(wxDataViewItemArray const& items)
{
size_t const noOfItems = items.GetCount();
wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED,this->m_DataViewCtrlPtr->GetId());
dataViewEvent.SetEventObject(this->m_DataViewCtrlPtr);
for (size_t indexItem=0; indexItem<noOfItems; ++indexItem)
if (this->m_DataViewCtrlPtr->GetDataViewPeer()->Update(this->GetOwner()->GetParent(items[indexItem]),items[indexItem]))
{
// send for all changed items a wxWidget event:
dataViewEvent.SetItem(items[indexItem]);
this->m_DataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
}
else
return false;
// if this location is reached all items have been updated:
this->AdjustRowHeights(items);
// done:
return true;
}
bool wxOSXDataViewModelNotifier::ItemDeleted(wxDataViewItem const& parent, wxDataViewItem const& item)
{
bool noFailureFlag;
wxCHECK_MSG(item.IsOk(),false,_("To be deleted item is invalid."));
// when this method is called and currently an item is being edited this item may have already been deleted in the model (the passed item and the being edited item have
// not to be identical because the being edited item might be below the passed item in the hierarchy);
// to prevent the control trying to ask the model to update an already deleted item the control is informed that currently a deleting process
// has been started and that variables can currently not be updated even when requested by the system:
this->m_DataViewCtrlPtr->SetDeleting(true);
noFailureFlag = this->m_DataViewCtrlPtr->GetDataViewPeer()->Remove(parent,item);
// enable automatic updating again:
this->m_DataViewCtrlPtr->SetDeleting(false);
// done:
return noFailureFlag;
}
bool wxOSXDataViewModelNotifier::ItemsDeleted(wxDataViewItem const& parent, wxDataViewItemArray const& items)
{
bool noFailureFlag;
// when this method is called and currently an item is being edited this item may have already been deleted in the model (the passed item and the being edited item have
// not to be identical because the being edited item might be below the passed item in the hierarchy);
// to prevent the control trying to ask the model to update an already deleted item the control is informed that currently a deleting process
// has been started and that variables can currently not be updated even when requested by the system:
this->m_DataViewCtrlPtr->SetDeleting(true);
// delete all specified items:
noFailureFlag = this->m_DataViewCtrlPtr->GetDataViewPeer()->Remove(parent,items);
// enable automatic updating again:
this->m_DataViewCtrlPtr->SetDeleting(false);
// done:
return noFailureFlag;
}
bool wxOSXDataViewModelNotifier::ValueChanged(wxDataViewItem const& item, unsigned int col)
{
wxCHECK_MSG(item.IsOk(), false,_("Passed item is invalid."));
wxCHECK_MSG(this->GetOwner() != NULL,false,_("Owner not initialized."));
if (this->m_DataViewCtrlPtr->GetDataViewPeer()->Update(this->GetOwner()->GetParent(item),item))
{
wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED,this->m_DataViewCtrlPtr->GetId());
dataViewEvent.SetEventObject(this->m_DataViewCtrlPtr);
dataViewEvent.SetColumn(col);
dataViewEvent.SetItem(item);
// send the equivalent wxWidget event:
this->m_DataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
// done
return true;
}
else
return false;
}
bool wxOSXDataViewModelNotifier::Cleared()
{
return this->m_DataViewCtrlPtr->GetDataViewPeer()->Reload();
}
void wxOSXDataViewModelNotifier::Resort()
{
this->m_DataViewCtrlPtr->GetDataViewPeer()->Resort();
}
void wxOSXDataViewModelNotifier::AdjustRowHeight(wxDataViewItem const& item)
{
if ((this->m_DataViewCtrlPtr->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT) != 0)
{
wxDataViewModel *model = this->GetOwner();
int height = 20; // TODO find out standard height
unsigned int num = this->m_DataViewCtrlPtr->GetColumnCount();
unsigned int col;
for (col = 0; col < num; col++)
{
wxDataViewColumn* column(this->m_DataViewCtrlPtr->GetColumnPtr(col));
if (!(column->IsHidden()))
{
wxDataViewCustomRenderer *renderer = dynamic_cast<wxDataViewCustomRenderer*>(column->GetRenderer());
if (renderer)
{
wxVariant value;
model->GetValue( value, item, column->GetModelColumn() );
renderer->SetValue( value );
height = wxMax( height, renderer->GetSize().y );
}
}
}
if (height > 20)
this->m_DataViewCtrlPtr->GetDataViewPeer()->SetRowHeight(item,height);
}
}
void wxOSXDataViewModelNotifier::AdjustRowHeights(wxDataViewItemArray const& items)
{
if ((this->m_DataViewCtrlPtr->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT) != 0)
{
size_t const noOfItems = items.GetCount();
wxDataViewModel *model = this->GetOwner();
for (size_t itemIndex=0; itemIndex<noOfItems; ++itemIndex)
{
int height = 20; // TODO find out standard height
unsigned int num = this->m_DataViewCtrlPtr->GetColumnCount();
unsigned int col;
for (col = 0; col < num; col++)
{
wxDataViewColumn* column(this->m_DataViewCtrlPtr->GetColumnPtr(col));
if (!(column->IsHidden()))
{
wxDataViewCustomRenderer *renderer = dynamic_cast<wxDataViewCustomRenderer*>(column->GetRenderer());
if (renderer)
{
wxVariant value;
model->GetValue( value, items[itemIndex], column->GetModelColumn() );
renderer->SetValue( value );
height = wxMax( height, renderer->GetSize().y );
}
}
}
if (height > 20)
this->m_DataViewCtrlPtr->GetDataViewPeer()->SetRowHeight(items[itemIndex],height);
}
}
}
// ---------------------------------------------------------
// wxDataViewCustomRenderer
// The constructor, the implementation macro and environment
// dependent methods can be found in the environment's
// source file.
// ---------------------------------------------------------
wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void)
{
delete this->m_DCPtr;
}
void wxDataViewCustomRenderer::RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state )
{
wxDataViewCtrl *view = GetOwner()->GetOwner();
wxColour col = (state & wxDATAVIEW_CELL_SELECTED) ? *wxWHITE : view->GetForegroundColour();
dc->SetTextForeground(col);
dc->DrawText( text, cell.x + xoffset, cell.y + ((cell.height - dc->GetCharHeight()) / 2));
}
wxDC* wxDataViewCustomRenderer::GetDC()
{
if ((this->m_DCPtr == NULL) && (this->GetOwner() != NULL) && (this->GetOwner()->GetOwner() != NULL))
this->m_DCPtr = new wxClientDC(this->GetOwner()->GetOwner());
return this->m_DCPtr;
}
void wxDataViewCustomRenderer::SetDC(wxDC* newDCPtr)
{
delete m_DCPtr;
m_DCPtr = newDCPtr;
}
// ---------------------------------------------------------
// wxDataViewTextRendererAttr
// ---------------------------------------------------------
wxDataViewTextRendererAttr::wxDataViewTextRendererAttr(wxString const& varianttype, wxDataViewCellMode mode, int align)
:wxDataViewTextRenderer(varianttype,mode,align)
{
}
IMPLEMENT_CLASS(wxDataViewTextRendererAttr,wxDataViewTextRenderer)
//-----------------------------------------------------------------------------
// wxDataViewCtrl
//-----------------------------------------------------------------------------
wxDataViewCtrl::~wxDataViewCtrl()
{
this->ClearColumns();
}
void wxDataViewCtrl::Init()
{
m_CustomRendererPtr = NULL;
m_Deleting = false;
m_macIsUserPane = false;
m_cgContext = NULL;
}
bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator )
{
if (!(this->wxControl::Create(parent,id,pos,size,style & ~(wxHSCROLL | wxVSCROLL),validator)))
return false;
m_peer = ::CreateDataView(this,parent,id,pos,size,style,this->GetExtraStyle());
this->MacPostControlCreate(pos,size);
return true;
}
bool wxDataViewCtrl::AssociateModel(wxDataViewModel* model)
{
wxDataViewWidgetImpl* dataViewWidgetPtr(this->GetDataViewPeer());
wxCHECK_MSG(dataViewWidgetPtr != NULL,false,_("Pointer to native control must not be NULL."));
if (wxDataViewCtrlBase::AssociateModel(model) && dataViewWidgetPtr->AssociateModel(model))
{
if (model != NULL)
model->AddNotifier(new wxOSXDataViewModelNotifier(this));
return true;
}
else
return false;
}
bool wxDataViewCtrl::AppendColumn(wxDataViewColumn* columnPtr)
{
return wxDataViewCtrl::InsertColumn( GetColumnCount(), columnPtr );
}
bool wxDataViewCtrl::PrependColumn(wxDataViewColumn* columnPtr)
{
return wxDataViewCtrl::InsertColumn( 0, columnPtr );
}
bool wxDataViewCtrl::InsertColumn(unsigned int pos, wxDataViewColumn* columnPtr)
{
wxDataViewWidgetImpl* dataViewWidgetPtr(this->GetDataViewPeer());
// first, some error checking:
wxCHECK_MSG(dataViewWidgetPtr != NULL, false,_("Pointer to native control must not be NULL."));
wxCHECK_MSG(columnPtr != NULL, false,_("Column pointer must not be NULL."));
wxCHECK_MSG(columnPtr->GetRenderer() != NULL, false,_("Column does not have a renderer."));
wxCHECK_MSG(this->GetModel() != NULL, false,_("No model associated with control."));
wxCHECK_MSG((columnPtr->GetModelColumn() >= 0) &&
(columnPtr->GetModelColumn() < this->GetModel()->GetColumnCount()),false,_("Column's model column has no equivalent in the associated model."));
// add column to wxWidget's internal structure:
if (this->wxDataViewCtrlBase::InsertColumn(pos,columnPtr))
{
this->m_ColumnPtrs.Add(columnPtr);
// if the insertion in the native control is successful the rest can also be initialized:
if (dataViewWidgetPtr->InsertColumn(pos,columnPtr))
{
// make sure that the data is up-to-date...
// if the newly appended column is the first column add the initial data to the control and mark the column as an expander column,
// otherwise ask the control to 'update' the data in the newly appended column:
if (this->GetColumnCount() == 1)
this->SetExpanderColumn(columnPtr);
// done:
return true;
}
else
{
// clean-up:
this->m_ColumnPtrs.Remove(columnPtr);
delete columnPtr;
// and send a message in debug mode:
wxFAIL_MSG(_("Column could not be added to native control."));
// failed:
return false;
}
}
else
{
// clean-up:
delete columnPtr;
wxFAIL_MSG(_("Could not add column to internal structures."));
// failed:
return false;
}
}
bool wxDataViewCtrl::ClearColumns()
{
if (this->GetDataViewPeer()->ClearColumns())
{
WX_CLEAR_ARRAY(this->m_ColumnPtrs);
return true;
}
else
return false;
}
bool wxDataViewCtrl::DeleteColumn(wxDataViewColumn* columnPtr)
{
if (this->GetDataViewPeer()->DeleteColumn(columnPtr))
{
this->m_ColumnPtrs.Remove(columnPtr);
delete columnPtr;
return true;
}
else
return false;
}
wxDataViewColumn* wxDataViewCtrl::GetColumn(unsigned int pos) const
{
return this->GetDataViewPeer()->GetColumn(pos);
}
unsigned int wxDataViewCtrl::GetColumnCount() const
{
return this->m_ColumnPtrs.GetCount();
}
int wxDataViewCtrl::GetColumnPosition(wxDataViewColumn const* columnPtr) const
{
return this->GetDataViewPeer()->GetColumnPosition(columnPtr);
}
void wxDataViewCtrl::Collapse(wxDataViewItem const& item)
{
this->GetDataViewPeer()->Collapse(item);
}
void wxDataViewCtrl::EnsureVisible(wxDataViewItem const& item, wxDataViewColumn const* columnPtr)
{
if (item.IsOk())
{
this->ExpandAncestors(item); // make sure that the item exists in the control
this->GetDataViewPeer()->EnsureVisible(item,columnPtr);
}
}
void wxDataViewCtrl::Expand(wxDataViewItem const& item)
{
return this->GetDataViewPeer()->Expand(item);
}
bool wxDataViewCtrl::IsExpanded( const wxDataViewItem & item ) const
{
return (item.IsOk() && this->GetDataViewPeer()->IsExpanded(item));
}
wxDataViewColumn* wxDataViewCtrl::GetSortingColumn() const
{
return this->GetDataViewPeer()->GetSortingColumn();
}
unsigned int wxDataViewCtrl::GetCount() const
{
return this->GetDataViewPeer()->GetCount();
}
wxRect wxDataViewCtrl::GetItemRect(wxDataViewItem const& item, wxDataViewColumn const* columnPtr) const
{
if (item.IsOk() && (columnPtr != NULL))
return this->GetDataViewPeer()->GetRectangle(item,columnPtr);
else
return wxRect();
}
wxDataViewItem wxDataViewCtrl::GetSelection() const
{
wxDataViewItemArray itemIDs;
if (this->GetDataViewPeer()->GetSelections(itemIDs) > 0)
return itemIDs[0];
else
return wxDataViewItem();
}
int wxDataViewCtrl::GetSelections(wxDataViewItemArray& sel) const
{
return this->GetDataViewPeer()->GetSelections(sel);
}
void wxDataViewCtrl::HitTest(wxPoint const& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const
{
return this->GetDataViewPeer()->HitTest(point,item,columnPtr);
}
bool wxDataViewCtrl::IsSelected(wxDataViewItem const& item) const
{
return this->GetDataViewPeer()->IsSelected(item);
}
void wxDataViewCtrl::Select(wxDataViewItem const& item)
{
if (item.IsOk())
{
this->ExpandAncestors(item); // make sure that the item exists in the control
this->GetDataViewPeer()->Select(item);
}
}
void wxDataViewCtrl::SelectAll(void)
{
this->GetDataViewPeer()->SelectAll();
}
void wxDataViewCtrl::SetSelections(wxDataViewItemArray const& sel)
{
size_t const noOfSelections = sel.GetCount();
size_t i;
wxDataViewItem last_parent;
// make sure that all to be selected items are visible in the control:
for (i = 0; i < noOfSelections; i++)
{
wxDataViewItem item = sel[i];
wxDataViewItem parent = this->GetModel()->GetParent( item );
if (parent.IsOk() && (parent != last_parent))
this->ExpandAncestors(item);
last_parent = parent;
}
// finally select the items:
wxDataViewWidgetImpl* dataViewWidgetPtr(this->GetDataViewPeer()); // variable definition for abbreviational purposes
for (i=0; i<noOfSelections; ++i)
dataViewWidgetPtr->Select(sel[i]);
}
void wxDataViewCtrl::Unselect(wxDataViewItem const& item)
{
if (item.IsOk())
this->GetDataViewPeer()->Unselect(item);
}
void wxDataViewCtrl::UnselectAll(void)
{
this->GetDataViewPeer()->UnselectAll();
}
//
// implementation
//
wxDataViewWidgetImpl* wxDataViewCtrl::GetDataViewPeer(void) const
{
return dynamic_cast<wxDataViewWidgetImpl*>(this->GetPeer());
}
void wxDataViewCtrl::AddChildren(wxDataViewItem const& parentItem)
{
int noOfChildren;
wxDataViewItemArray items;
wxCHECK_RET(this->GetModel() != NULL,_("Model pointer not initialized."));
noOfChildren = this->GetModel()->GetChildren(parentItem,items);
(void) this->GetModel()->ItemsAdded(parentItem,items);
}
void wxDataViewCtrl::FinishCustomItemEditing(void)
{
if (this->GetCustomRendererItem().IsOk())
{
this->GetCustomRendererPtr()->FinishEditing();
this->SetCustomRendererItem(wxDataViewItem());
this->SetCustomRendererPtr (NULL);
}
}
/*static*/
wxVisualAttributes wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant variant)
{
wxVisualAttributes attr;
attr.colFg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
attr.colBg = wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX );
attr.font.MacCreateFromThemeFont(kThemeViewsFont);
return attr;
}
// inherited methods from wxDataViewCtrlBase
void wxDataViewCtrl::DoSetExpanderColumn()
{
if (this->GetExpanderColumn() != NULL)
this->GetDataViewPeer()->DoSetExpanderColumn(this->GetExpanderColumn());
}
void wxDataViewCtrl::DoSetIndent()
{
this->GetDataViewPeer()->DoSetIndent(this->GetIndent());
}
// event handling:
void wxDataViewCtrl::OnSize(wxSizeEvent& event)
{
unsigned int const noOfColumns = this->GetColumnCount();
// reset DC of all custom renderers because DC has changed:
for (unsigned int i=0; i<noOfColumns; ++i)
{
wxDataViewColumn* dataViewColumnPtr(this->GetColumn(i));
if (dataViewColumnPtr != NULL)
{
wxDataViewCustomRenderer* dataViewCustomRendererPtr(dynamic_cast<wxDataViewCustomRenderer*>(dataViewColumnPtr->GetRenderer()));
if (dataViewCustomRendererPtr != NULL)
dataViewCustomRendererPtr->SetDC(NULL);
}
}
// update the layout of the native control after a size event:
this->GetDataViewPeer()->OnSize();
event.Skip();
}
IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl,wxDataViewCtrlBase)
BEGIN_EVENT_TABLE(wxDataViewCtrl,wxDataViewCtrlBase)
EVT_SIZE(wxDataViewCtrl::OnSize)
END_EVENT_TABLE()
#endif // (wxUSE_DATAVIEWCTRL != 0) && (!defined(wxUSE_GENERICDATAVIEWCTRL) || (wxUSE_GENERICDATAVIEWCTRL == 0))