Big wxDataViewCtrl renderer classes refactoring.

This commit adds no changes in functionality but paves way for the upcoming
improvements of wxDataViewCustomRenderer.

First, introduce wxDataViewCustomRendererBase class in order to allow
implementing behaviour common to custom renderers in all ports in this class
instead of triplicating it.

This required splitting monolithic dataview.h in more parts, now we have
wx/dvrenderer.h which defines wxDataViewRendererBase and the new
wxDataViewCustomRendererBase and includes wx/port/dvrenderer.h which define
wxDataViewRenderer and wx/port/dvrenderers.h which defines all the other
renderer classes.

Also bring renderers hierarchy in the generic version closer to other ports:
all standard renderer classes now inherit from wxDataViewRenderer and not
wxDataViewCustomRenderer in for consistency with the other ports.
wxDataViewRenderer itself still does derive from wxDataViewCustomRendererBase,
unlike elsewhere, but this is unavoidable considering that all generic
renderers are custom ones.

Finally do some cleanup in OS X part of the code: correct indentation,
spacing, comment style.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62589 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2009-11-10 17:40:58 +00:00
parent ef6833f9ab
commit 6eec70b984
25 changed files with 1507 additions and 1246 deletions

View File

@@ -3400,6 +3400,8 @@ COND_TOOLKIT_MOTIF_ADVANCED_PLATFORM_HDR = \
COND_TOOLKIT_OSX_CARBON_ADVANCED_PLATFORM_HDR = \ COND_TOOLKIT_OSX_CARBON_ADVANCED_PLATFORM_HDR = \
wx/generic/animate.h \ wx/generic/animate.h \
wx/osx/dataview.h \ wx/osx/dataview.h \
wx/osx/dvrenderer.h \
wx/osx/dvrenderers.h \
wx/osx/joystick.h \ wx/osx/joystick.h \
wx/osx/sound.h \ wx/osx/sound.h \
wx/osx/taskbarosx.h \ wx/osx/taskbarosx.h \
@@ -3410,6 +3412,8 @@ COND_TOOLKIT_OSX_CARBON_ADVANCED_PLATFORM_HDR = \
COND_TOOLKIT_OSX_COCOA_ADVANCED_PLATFORM_HDR = \ COND_TOOLKIT_OSX_COCOA_ADVANCED_PLATFORM_HDR = \
wx/generic/animate.h \ wx/generic/animate.h \
wx/osx/dataview.h \ wx/osx/dataview.h \
wx/osx/dvrenderer.h \
wx/osx/dvrenderers.h \
wx/osx/joystick.h \ wx/osx/joystick.h \
wx/osx/sound.h \ wx/osx/sound.h \
wx/osx/taskbarosx.h \ wx/osx/taskbarosx.h \
@@ -3427,6 +3431,8 @@ COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_ADVANCED_PLATFORM_NATIVE_HDR = \
wx/gtk/bmpcbox.h \ wx/gtk/bmpcbox.h \
wx/gtk/calctrl.h \ wx/gtk/calctrl.h \
wx/gtk/dataview.h \ wx/gtk/dataview.h \
wx/gtk/dvrenderer.h \
wx/gtk/dvrenderers.h \
wx/gtk/hyperlink.h \ wx/gtk/hyperlink.h \
wx/gtk/infobar.h wx/gtk/infobar.h
@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2@ADVANCED_PLATFORM_NATIVE_HDR = $(COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_ADVANCED_PLATFORM_NATIVE_HDR) @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2@ADVANCED_PLATFORM_NATIVE_HDR = $(COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_ADVANCED_PLATFORM_NATIVE_HDR)
@@ -3445,12 +3451,15 @@ COND_WXUNIV_0_ADVANCED_HDR = \
wx/datectrl.h \ wx/datectrl.h \
wx/dateevt.h \ wx/dateevt.h \
wx/dcbuffer.h \ wx/dcbuffer.h \
wx/dvrenderers.h \
wx/editlbox.h \ wx/editlbox.h \
wx/generic/aboutdlgg.h \ wx/generic/aboutdlgg.h \
wx/generic/bmpcbox.h \ wx/generic/bmpcbox.h \
wx/generic/calctrlg.h \ wx/generic/calctrlg.h \
wx/generic/datectrl.h \ wx/generic/datectrl.h \
wx/generic/dataview.h \ wx/generic/dataview.h \
wx/generic/dvrenderer.h \
wx/generic/dvrenderers.h \
wx/generic/grid.h \ wx/generic/grid.h \
wx/generic/gridctrl.h \ wx/generic/gridctrl.h \
wx/generic/grideditors.h \ wx/generic/grideditors.h \
@@ -3490,12 +3499,15 @@ COND_WXUNIV_1_ADVANCED_HDR = \
wx/datectrl.h \ wx/datectrl.h \
wx/dateevt.h \ wx/dateevt.h \
wx/dcbuffer.h \ wx/dcbuffer.h \
wx/dvrenderers.h \
wx/editlbox.h \ wx/editlbox.h \
wx/generic/aboutdlgg.h \ wx/generic/aboutdlgg.h \
wx/generic/bmpcbox.h \ wx/generic/bmpcbox.h \
wx/generic/calctrlg.h \ wx/generic/calctrlg.h \
wx/generic/datectrl.h \ wx/generic/datectrl.h \
wx/generic/dataview.h \ wx/generic/dataview.h \
wx/generic/dvrenderer.h \
wx/generic/dvrenderers.h \
wx/generic/grid.h \ wx/generic/grid.h \
wx/generic/gridctrl.h \ wx/generic/gridctrl.h \
wx/generic/grideditors.h \ wx/generic/grideditors.h \

View File

@@ -2865,12 +2865,15 @@ src/osx/iphone/window.mm
wx/datectrl.h wx/datectrl.h
wx/dateevt.h wx/dateevt.h
wx/dcbuffer.h wx/dcbuffer.h
wx/dvrenderers.h
wx/editlbox.h wx/editlbox.h
wx/generic/aboutdlgg.h wx/generic/aboutdlgg.h
wx/generic/bmpcbox.h wx/generic/bmpcbox.h
wx/generic/calctrlg.h wx/generic/calctrlg.h
wx/generic/datectrl.h wx/generic/datectrl.h
wx/generic/dataview.h wx/generic/dataview.h
wx/generic/dvrenderer.h
wx/generic/dvrenderers.h
wx/generic/grid.h wx/generic/grid.h
wx/generic/gridctrl.h wx/generic/gridctrl.h
wx/generic/grideditors.h wx/generic/grideditors.h
@@ -2952,6 +2955,8 @@ src/osx/iphone/window.mm
<set var="ADVANCED_OSX_CARBON_HDR" hints="files"> <set var="ADVANCED_OSX_CARBON_HDR" hints="files">
wx/generic/animate.h wx/generic/animate.h
wx/osx/dataview.h wx/osx/dataview.h
wx/osx/dvrenderer.h
wx/osx/dvrenderers.h
wx/osx/joystick.h wx/osx/joystick.h
wx/osx/sound.h wx/osx/sound.h
wx/osx/taskbarosx.h wx/osx/taskbarosx.h
@@ -2976,6 +2981,8 @@ src/osx/iphone/window.mm
<set var="ADVANCED_OSX_COCOA_HDR" hints="files"> <set var="ADVANCED_OSX_COCOA_HDR" hints="files">
wx/generic/animate.h wx/generic/animate.h
wx/osx/dataview.h wx/osx/dataview.h
wx/osx/dvrenderer.h
wx/osx/dvrenderers.h
wx/osx/joystick.h wx/osx/joystick.h
wx/osx/sound.h wx/osx/sound.h
wx/osx/taskbarosx.h wx/osx/taskbarosx.h
@@ -3051,6 +3058,8 @@ src/osx/iphone/window.mm
wx/gtk/bmpcbox.h wx/gtk/bmpcbox.h
wx/gtk/calctrl.h wx/gtk/calctrl.h
wx/gtk/dataview.h wx/gtk/dataview.h
wx/gtk/dvrenderer.h
wx/gtk/dvrenderers.h
wx/gtk/hyperlink.h wx/gtk/hyperlink.h
wx/gtk/infobar.h wx/gtk/infobar.h
</set> </set>

View File

@@ -858,6 +858,14 @@ SOURCE=..\..\include\wx\generic\datectrl.h
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=..\..\include\wx\generic\dvrenderer.h
# End Source File
# Begin Source File
SOURCE=..\..\include\wx\generic\dvrenderers.h
# End Source File
# Begin Source File
SOURCE=..\..\include\wx\generic\grid.h SOURCE=..\..\include\wx\generic\grid.h
# End Source File # End Source File
# Begin Source File # Begin Source File
@@ -946,6 +954,10 @@ SOURCE=..\..\include\wx\dcbuffer.h
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=..\..\include\wx\dvrenderers.h
# End Source File
# Begin Source File
SOURCE=..\..\include\wx\editlbox.h SOURCE=..\..\include\wx\editlbox.h
# End Source File # End Source File
# Begin Source File # Begin Source File

View File

@@ -5275,6 +5275,14 @@ SOURCE=..\..\include\wx\generic\dragimgg.h
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=..\..\include\wx\generic\dvrenderer.h
# End Source File
# Begin Source File
SOURCE=..\..\include\wx\generic\dvrenderers.h
# End Source File
# Begin Source File
SOURCE=..\..\include\wx\generic\fdrepdlg.h SOURCE=..\..\include\wx\generic\fdrepdlg.h
# End Source File # End Source File
# Begin Source File # Begin Source File
@@ -5927,6 +5935,10 @@ SOURCE=..\..\include\wx\dragimag.h
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=..\..\include\wx\dvrenderers.h
# End Source File
# Begin Source File
SOURCE=..\..\include\wx\editlbox.h SOURCE=..\..\include\wx\editlbox.h
# End Source File # End Source File
# Begin Source File # Begin Source File

View File

@@ -981,6 +981,12 @@
<File <File
RelativePath="..\..\include\wx\generic\datectrl.h"> RelativePath="..\..\include\wx\generic\datectrl.h">
</File> </File>
<File
RelativePath="..\..\include\wx\generic\dvrenderer.h">
</File>
<File
RelativePath="..\..\include\wx\generic\dvrenderers.h">
</File>
<File <File
RelativePath="..\..\include\wx\generic\grid.h"> RelativePath="..\..\include\wx\generic\grid.h">
</File> </File>
@@ -1048,6 +1054,9 @@
<File <File
RelativePath="..\..\include\wx\dcbuffer.h"> RelativePath="..\..\include\wx\dcbuffer.h">
</File> </File>
<File
RelativePath="..\..\include\wx\dvrenderers.h">
</File>
<File <File
RelativePath="..\..\include\wx\editlbox.h"> RelativePath="..\..\include\wx\editlbox.h">
</File> </File>

View File

@@ -4570,6 +4570,12 @@
<File <File
RelativePath="..\..\include\wx\generic\dragimgg.h"> RelativePath="..\..\include\wx\generic\dragimgg.h">
</File> </File>
<File
RelativePath="..\..\include\wx\generic\dvrenderer.h">
</File>
<File
RelativePath="..\..\include\wx\generic\dvrenderers.h">
</File>
<File <File
RelativePath="..\..\include\wx\generic\fdrepdlg.h"> RelativePath="..\..\include\wx\generic\fdrepdlg.h">
</File> </File>
@@ -5062,6 +5068,9 @@
<File <File
RelativePath="..\..\include\wx\dragimag.h"> RelativePath="..\..\include\wx\dragimag.h">
</File> </File>
<File
RelativePath="..\..\include\wx\dvrenderers.h">
</File>
<File <File
RelativePath="..\..\include\wx\editlbox.h"> RelativePath="..\..\include\wx\editlbox.h">
</File> </File>

View File

@@ -1327,6 +1327,14 @@
RelativePath="..\..\include\wx\generic\datectrl.h" RelativePath="..\..\include\wx\generic\datectrl.h"
> >
</File> </File>
<File
RelativePath="..\..\include\wx\generic\dvrenderer.h"
>
</File>
<File
RelativePath="..\..\include\wx\generic\dvrenderers.h"
>
</File>
<File <File
RelativePath="..\..\include\wx\generic\grid.h" RelativePath="..\..\include\wx\generic\grid.h"
> >
@@ -1416,6 +1424,10 @@
RelativePath="..\..\include\wx\dcbuffer.h" RelativePath="..\..\include\wx\dcbuffer.h"
> >
</File> </File>
<File
RelativePath="..\..\include\wx\dvrenderers.h"
>
</File>
<File <File
RelativePath="..\..\include\wx\editlbox.h" RelativePath="..\..\include\wx\editlbox.h"
> >

View File

@@ -6112,6 +6112,14 @@
RelativePath="..\..\include\wx\generic\dragimgg.h" RelativePath="..\..\include\wx\generic\dragimgg.h"
> >
</File> </File>
<File
RelativePath="..\..\include\wx\generic\dvrenderer.h"
>
</File>
<File
RelativePath="..\..\include\wx\generic\dvrenderers.h"
>
</File>
<File <File
RelativePath="..\..\include\wx\generic\fdrepdlg.h" RelativePath="..\..\include\wx\generic\fdrepdlg.h"
> >
@@ -6767,6 +6775,10 @@
RelativePath="..\..\include\wx\dragimag.h" RelativePath="..\..\include\wx\dragimag.h"
> >
</File> </File>
<File
RelativePath="..\..\include\wx\dvrenderers.h"
>
</File>
<File <File
RelativePath="..\..\include\wx\editlbox.h" RelativePath="..\..\include\wx\editlbox.h"
> >

View File

@@ -1323,6 +1323,14 @@
RelativePath="..\..\include\wx\generic\datectrl.h" RelativePath="..\..\include\wx\generic\datectrl.h"
> >
</File> </File>
<File
RelativePath="..\..\include\wx\generic\dvrenderer.h"
>
</File>
<File
RelativePath="..\..\include\wx\generic\dvrenderers.h"
>
</File>
<File <File
RelativePath="..\..\include\wx\generic\grid.h" RelativePath="..\..\include\wx\generic\grid.h"
> >
@@ -1412,6 +1420,10 @@
RelativePath="..\..\include\wx\dcbuffer.h" RelativePath="..\..\include\wx\dcbuffer.h"
> >
</File> </File>
<File
RelativePath="..\..\include\wx\dvrenderers.h"
>
</File>
<File <File
RelativePath="..\..\include\wx\editlbox.h" RelativePath="..\..\include\wx\editlbox.h"
> >

View File

@@ -6108,6 +6108,14 @@
RelativePath="..\..\include\wx\generic\dragimgg.h" RelativePath="..\..\include\wx\generic\dragimgg.h"
> >
</File> </File>
<File
RelativePath="..\..\include\wx\generic\dvrenderer.h"
>
</File>
<File
RelativePath="..\..\include\wx\generic\dvrenderers.h"
>
</File>
<File <File
RelativePath="..\..\include\wx\generic\fdrepdlg.h" RelativePath="..\..\include\wx\generic\fdrepdlg.h"
> >
@@ -6763,6 +6771,10 @@
RelativePath="..\..\include\wx\dragimag.h" RelativePath="..\..\include\wx\dragimag.h"
> >
</File> </File>
<File
RelativePath="..\..\include\wx\dvrenderers.h"
>
</File>
<File <File
RelativePath="..\..\include\wx\editlbox.h" RelativePath="..\..\include\wx\editlbox.h"
> >

View File

@@ -32,6 +32,14 @@ class WXDLLIMPEXP_FWD_CORE wxImageList;
#define wxHAS_GENERIC_DATAVIEWCTRL #define wxHAS_GENERIC_DATAVIEWCTRL
#endif #endif
#ifdef wxHAS_GENERIC_DATAVIEWCTRL
// this symbol doesn't follow the convention for wxUSE_XXX symbols which
// are normally always defined as either 0 or 1, so its use is deprecated
// and it only exists for backwards compatibility, don't use it any more
// and use wxHAS_GENERIC_DATAVIEWCTRL instead
#define wxUSE_GENERICDATAVIEWCTRL
#endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxDataViewCtrl globals // wxDataViewCtrl globals
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -436,134 +444,11 @@ private:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
// --------------------------------------------------------- // ----------------------------------------------------------------------------
// wxDataViewRendererBase // wxDataViewRenderer and related classes
// --------------------------------------------------------- // ----------------------------------------------------------------------------
enum wxDataViewCellMode #include "wx/dvrenderers.h"
{
wxDATAVIEW_CELL_INERT,
wxDATAVIEW_CELL_ACTIVATABLE,
wxDATAVIEW_CELL_EDITABLE
};
enum wxDataViewCellRenderState
{
wxDATAVIEW_CELL_SELECTED = 1,
wxDATAVIEW_CELL_PRELIT = 2,
wxDATAVIEW_CELL_INSENSITIVE = 4,
wxDATAVIEW_CELL_FOCUSED = 8
};
class WXDLLIMPEXP_ADV wxDataViewRendererBase: public wxObject
{
public:
wxDataViewRendererBase( const wxString &varianttype,
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int alignment = wxDVR_DEFAULT_ALIGNMENT );
virtual ~wxDataViewRendererBase();
virtual bool Validate( wxVariant& WXUNUSED(value) )
{ return true; }
void SetOwner( wxDataViewColumn *owner ) { m_owner = owner; }
wxDataViewColumn* GetOwner() const { return m_owner; }
// renderer properties:
virtual bool SetValue( const wxVariant& WXUNUSED(value) ) = 0;
virtual bool GetValue( wxVariant& WXUNUSED(value) ) const = 0;
wxString GetVariantType() const { return m_variantType; }
virtual void SetMode( wxDataViewCellMode mode ) = 0;
virtual wxDataViewCellMode GetMode() const = 0;
// NOTE: Set/GetAlignment do not take/return a wxAlignment enum but
// rather an "int"; that's because for rendering cells it's allowed
// to combine alignment flags (e.g. wxALIGN_LEFT|wxALIGN_BOTTOM)
virtual void SetAlignment( int align ) = 0;
virtual int GetAlignment() const = 0;
// enable or disable (if called with wxELLIPSIZE_NONE) replacing parts of
// the item text (hence this only makes sense for renderers showing
// text...) with ellipsis in order to make it fit the column width
virtual void EnableEllipsize(wxEllipsizeMode mode = wxELLIPSIZE_MIDDLE) = 0;
void DisableEllipsize() { EnableEllipsize(wxELLIPSIZE_NONE); }
virtual wxEllipsizeMode GetEllipsizeMode() const = 0;
// in-place editing
virtual bool HasEditorCtrl() const
{ return false; }
virtual wxControl* CreateEditorCtrl(wxWindow * WXUNUSED(parent),
wxRect WXUNUSED(labelRect),
const wxVariant& WXUNUSED(value))
{ return NULL; }
virtual bool GetValueFromEditorCtrl(wxControl * WXUNUSED(editor),
wxVariant& WXUNUSED(value))
{ return false; }
virtual bool StartEditing( const wxDataViewItem &item, wxRect labelRect );
virtual void CancelEditing();
virtual bool FinishEditing();
wxControl *GetEditorCtrl() { return m_editorCtrl; }
protected:
wxString m_variantType;
wxDataViewColumn *m_owner;
wxWeakRef<wxControl> m_editorCtrl;
wxDataViewItem m_item; // for m_editorCtrl
// internal utility:
const wxDataViewCtrl* GetView() const;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRendererBase)
};
//-----------------------------------------------------------------------------
// wxDataViewIconText
//-----------------------------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewIconText: public wxObject
{
public:
wxDataViewIconText( const wxString &text = wxEmptyString, const wxIcon& icon = wxNullIcon )
: m_text(text), m_icon(icon)
{ }
wxDataViewIconText( const wxDataViewIconText &other )
: wxObject()
{ m_icon = other.m_icon; m_text = other.m_text; }
void SetText( const wxString &text ) { m_text = text; }
wxString GetText() const { return m_text; }
void SetIcon( const wxIcon &icon ) { m_icon = icon; }
const wxIcon &GetIcon() const { return m_icon; }
private:
wxString m_text;
wxIcon m_icon;
private:
DECLARE_DYNAMIC_CLASS(wxDataViewIconText)
};
inline
bool operator==(const wxDataViewIconText& left, const wxDataViewIconText& right)
{
return left.GetText() == right.GetText() &&
left.GetIcon().IsSameAs(right.GetIcon());
}
inline
bool operator!=(const wxDataViewIconText& left, const wxDataViewIconText& right)
{
return !(left == right);
}
DECLARE_VARIANT_OBJECT_EXPORTED(wxDataViewIconText, WXDLLIMPEXP_ADV)
// --------------------------------------------------------- // ---------------------------------------------------------
// wxDataViewColumnBase // wxDataViewColumnBase
@@ -998,12 +883,6 @@ typedef void (wxEvtHandler::*wxDataViewEventFunction)(wxDataViewEvent&);
#define EVT_DATAVIEW_ITEM_DROP(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_DROP, id, fn) #define EVT_DATAVIEW_ITEM_DROP(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_DROP, id, fn)
#ifdef wxHAS_GENERIC_DATAVIEWCTRL #ifdef wxHAS_GENERIC_DATAVIEWCTRL
// this symbol doesn't follow the convention for wxUSE_XXX symbols which
// are normally always defined as either 0 or 1, so its use is deprecated
// and it only exists for backwards compatibility, don't use it any more
// and use wxHAS_GENERIC_DATAVIEWCTRL instead
#define wxUSE_GENERICDATAVIEWCTRL
#include "wx/generic/dataview.h" #include "wx/generic/dataview.h"
#elif defined(__WXGTK20__) #elif defined(__WXGTK20__)
#include "wx/gtk/dataview.h" #include "wx/gtk/dataview.h"
@@ -1013,60 +892,6 @@ typedef void (wxEvtHandler::*wxDataViewEventFunction)(wxDataViewEvent&);
#error "unknown native wxDataViewCtrl implementation" #error "unknown native wxDataViewCtrl implementation"
#endif #endif
// -------------------------------------
// wxDataViewSpinRenderer
// -------------------------------------
class WXDLLIMPEXP_ADV wxDataViewSpinRenderer: public wxDataViewCustomRenderer
{
public:
wxDataViewSpinRenderer( int min, int max,
wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
int alignment = wxDVR_DEFAULT_ALIGNMENT );
virtual bool HasEditorCtrl() const { return true; }
virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
virtual bool Render( wxRect rect, wxDC *dc, int state );
virtual wxSize GetSize() const;
virtual bool SetValue( const wxVariant &value );
virtual bool GetValue( wxVariant &value ) const;
private:
long m_data;
long m_min,m_max;
};
#if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXOSX_CARBON__)
// -------------------------------------
// wxDataViewChoiceRenderer
// -------------------------------------
class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer: public wxDataViewCustomRenderer
{
public:
wxDataViewChoiceRenderer( const wxArrayString &choices,
wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
int alignment = wxDVR_DEFAULT_ALIGNMENT );
virtual bool HasEditorCtrl() const { return true; }
virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
virtual bool Render( wxRect rect, wxDC *dc, int state );
virtual wxSize GetSize() const;
virtual bool SetValue( const wxVariant &value );
virtual bool GetValue( wxVariant &value ) const;
private:
wxArrayString m_choices;
wxString m_data;
};
#endif
// this class is obsolete, its functionality was merged in
// wxDataViewTextRenderer itself now, don't use it any more
#define wxDataViewTextRendererAttr wxDataViewTextRenderer
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxDataViewListStore // wxDataViewListStore
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

309
include/wx/dvrenderers.h Normal file
View File

@@ -0,0 +1,309 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/dvrenderers.h
// Purpose: Declare all wxDataViewCtrl classes
// Author: Robert Roebling, Vadim Zeitlin
// Created: 2009-11-08 (extracted from wx/dataview.h)
// RCS-ID: $Id: wxhead.h,v 1.11 2009-06-29 10:23:04 zeitlin Exp $
// Copyright: (c) 2006 Robert Roebling
// (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_DVRENDERERS_H_
#define _WX_DVRENDERERS_H_
/*
Note about the structure of various headers: they're organized in a more
complicated way than usual because of the various dependencies which are
different for different ports. In any case the only public header, i.e. the
one which can be included directly is wx/dataview.h. It, in turn, includes
this one to define all the renderer classes.
We define the base wxDataViewRendererBase class first and then include a
port-dependent wx/xxx/dvrenderer.h which defines wxDataViewRenderer itself.
After this we can define wxDataViewRendererCustomBase (and maybe in the
future base classes for other renderers if the need arises, i.e. if there
is any non-trivial code or API which it makes sense to keep in common code)
and include wx/xxx/dvrenderers.h (notice the plural) which defines all the
rest of the renderer classes.
*/
class WXDLLIMPEXP_FWD_ADV wxDataViewCustomRenderer;
// ----------------------------------------------------------------------------
// wxDataViewIconText: helper class used by wxDataViewIconTextRenderer
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewIconText : public wxObject
{
public:
wxDataViewIconText( const wxString &text = wxEmptyString,
const wxIcon& icon = wxNullIcon )
: m_text(text),
m_icon(icon)
{ }
wxDataViewIconText( const wxDataViewIconText &other )
: wxObject(),
m_text(other.m_text),
m_icon(other.m_icon)
{ }
void SetText( const wxString &text ) { m_text = text; }
wxString GetText() const { return m_text; }
void SetIcon( const wxIcon &icon ) { m_icon = icon; }
const wxIcon &GetIcon() const { return m_icon; }
private:
wxString m_text;
wxIcon m_icon;
DECLARE_DYNAMIC_CLASS(wxDataViewIconText)
};
inline
bool operator==(const wxDataViewIconText& left, const wxDataViewIconText& right)
{
return left.GetText() == right.GetText() &&
left.GetIcon().IsSameAs(right.GetIcon());
}
inline
bool operator!=(const wxDataViewIconText& left, const wxDataViewIconText& right)
{
return !(left == right);
}
DECLARE_VARIANT_OBJECT_EXPORTED(wxDataViewIconText, WXDLLIMPEXP_ADV)
// ----------------------------------------------------------------------------
// wxDataViewRendererBase
// ----------------------------------------------------------------------------
enum wxDataViewCellMode
{
wxDATAVIEW_CELL_INERT,
wxDATAVIEW_CELL_ACTIVATABLE,
wxDATAVIEW_CELL_EDITABLE
};
enum wxDataViewCellRenderState
{
wxDATAVIEW_CELL_SELECTED = 1,
wxDATAVIEW_CELL_PRELIT = 2,
wxDATAVIEW_CELL_INSENSITIVE = 4,
wxDATAVIEW_CELL_FOCUSED = 8
};
class WXDLLIMPEXP_ADV wxDataViewRendererBase: public wxObject
{
public:
wxDataViewRendererBase( const wxString &varianttype,
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int alignment = wxDVR_DEFAULT_ALIGNMENT );
virtual ~wxDataViewRendererBase();
virtual bool Validate( wxVariant& WXUNUSED(value) )
{ return true; }
void SetOwner( wxDataViewColumn *owner ) { m_owner = owner; }
wxDataViewColumn* GetOwner() const { return m_owner; }
// renderer properties:
virtual bool SetValue( const wxVariant& WXUNUSED(value) ) = 0;
virtual bool GetValue( wxVariant& WXUNUSED(value) ) const = 0;
wxString GetVariantType() const { return m_variantType; }
virtual void SetMode( wxDataViewCellMode mode ) = 0;
virtual wxDataViewCellMode GetMode() const = 0;
// NOTE: Set/GetAlignment do not take/return a wxAlignment enum but
// rather an "int"; that's because for rendering cells it's allowed
// to combine alignment flags (e.g. wxALIGN_LEFT|wxALIGN_BOTTOM)
virtual void SetAlignment( int align ) = 0;
virtual int GetAlignment() const = 0;
// enable or disable (if called with wxELLIPSIZE_NONE) replacing parts of
// the item text (hence this only makes sense for renderers showing
// text...) with ellipsis in order to make it fit the column width
virtual void EnableEllipsize(wxEllipsizeMode mode = wxELLIPSIZE_MIDDLE) = 0;
void DisableEllipsize() { EnableEllipsize(wxELLIPSIZE_NONE); }
virtual wxEllipsizeMode GetEllipsizeMode() const = 0;
// in-place editing
virtual bool HasEditorCtrl() const
{ return false; }
virtual wxControl* CreateEditorCtrl(wxWindow * WXUNUSED(parent),
wxRect WXUNUSED(labelRect),
const wxVariant& WXUNUSED(value))
{ return NULL; }
virtual bool GetValueFromEditorCtrl(wxControl * WXUNUSED(editor),
wxVariant& WXUNUSED(value))
{ return false; }
virtual bool StartEditing( const wxDataViewItem &item, wxRect labelRect );
virtual void CancelEditing();
virtual bool FinishEditing();
wxControl *GetEditorCtrl() { return m_editorCtrl; }
protected:
wxString m_variantType;
wxDataViewColumn *m_owner;
wxWeakRef<wxControl> m_editorCtrl;
wxDataViewItem m_item; // for m_editorCtrl
// internal utility:
const wxDataViewCtrl* GetView() const;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRendererBase)
};
// include the real wxDataViewRenderer declaration for the native ports
#ifdef wxHAS_GENERIC_DATAVIEWCTRL
// in the generic implementation there is no real wxDataViewRenderer, all
// renderers are custom so it's the same as wxDataViewCustomRenderer and
// wxDataViewCustomRendererBase derives from wxDataViewRendererBase directly
//
// this is a rather ugly hack but unfortunately it just doesn't seem to be
// possible to have the same class hierarchy in all ports and avoid
// duplicating the entire wxDataViewCustomRendererBase in the generic
// wxDataViewRenderer class (well, we could use a mix-in but this would
// make classes hierarchy non linear and arguably even more complex)
#define wxDataViewCustomRendererRealBase wxDataViewRendererBase
#else
#if defined(__WXGTK20__)
#include "wx/gtk/dvrenderer.h"
#elif defined(__WXMAC__)
#include "wx/osx/dvrenderer.h"
#else
#error "unknown native wxDataViewCtrl implementation"
#endif
#define wxDataViewCustomRendererRealBase wxDataViewRenderer
#endif
// ----------------------------------------------------------------------------
// wxDataViewCustomRendererBase
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewCustomRendererBase
: public wxDataViewCustomRendererRealBase
{
public:
// Constructor must specify the usual renderer parameters which we simply
// pass to the base class
wxDataViewCustomRendererBase(const wxString& varianttype = "string",
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT)
: wxDataViewCustomRendererRealBase(varianttype, mode, align)
{
}
// Define virtual function which are called when the item is activated
// (double-clicked or Enter is pressed on it), clicked or the user starts
// to drag it: by default they all simply return false indicating that the
// events are not handled
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; }
private:
wxDECLARE_NO_COPY_CLASS(wxDataViewCustomRendererBase);
};
// include the declaration of all the other renderers to get the real
// wxDataViewCustomRenderer from which we need to inherit below
#ifdef wxHAS_GENERIC_DATAVIEWCTRL
// because of the different renderer classes hierarchy in the generic
// version, as explained above, we can include the header defining
// wxDataViewRenderer only here and not before wxDataViewCustomRendererBase
// declaration as for the native ports
#include "wx/generic/dvrenderer.h"
#include "wx/generic/dvrenderers.h"
#elif defined(__WXGTK20__)
#include "wx/gtk/dvrenderers.h"
#elif defined(__WXMAC__)
#include "wx/osx/dvrenderers.h"
#else
#error "unknown native wxDataViewCtrl implementation"
#endif
// ----------------------------------------------------------------------------
// wxDataViewSpinRenderer
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewSpinRenderer: public wxDataViewCustomRenderer
{
public:
wxDataViewSpinRenderer( int min, int max,
wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
int alignment = wxDVR_DEFAULT_ALIGNMENT );
virtual bool HasEditorCtrl() const { return true; }
virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
virtual bool Render( wxRect rect, wxDC *dc, int state );
virtual wxSize GetSize() const;
virtual bool SetValue( const wxVariant &value );
virtual bool GetValue( wxVariant &value ) const;
private:
long m_data;
long m_min,m_max;
};
#if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXOSX_CARBON__)
// ----------------------------------------------------------------------------
// wxDataViewChoiceRenderer
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer: public wxDataViewCustomRenderer
{
public:
wxDataViewChoiceRenderer( const wxArrayString &choices,
wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
int alignment = wxDVR_DEFAULT_ALIGNMENT );
virtual bool HasEditorCtrl() const { return true; }
virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
virtual bool Render( wxRect rect, wxDC *dc, int state );
virtual wxSize GetSize() const;
virtual bool SetValue( const wxVariant &value );
virtual bool GetValue( wxVariant &value ) const;
private:
wxArrayString m_choices;
wxString m_data;
};
#endif // generic or Carbon versions
// this class is obsolete, its functionality was merged in
// wxDataViewTextRenderer itself now, don't use it any more
#define wxDataViewTextRendererAttr wxDataViewTextRenderer
#endif // _WX_DVRENDERERS_H_

View File

@@ -18,326 +18,9 @@
#include "wx/scrolwin.h" #include "wx/scrolwin.h"
#include "wx/icon.h" #include "wx/icon.h"
// ---------------------------------------------------------
// classes
// ---------------------------------------------------------
class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl;
class WXDLLIMPEXP_FWD_ADV wxDataViewMainWindow; class WXDLLIMPEXP_FWD_ADV wxDataViewMainWindow;
class WXDLLIMPEXP_FWD_ADV wxDataViewHeaderWindow; class WXDLLIMPEXP_FWD_ADV wxDataViewHeaderWindow;
// ---------------------------------------------------------
// wxDataViewRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewRenderer: public wxDataViewRendererBase
{
public:
wxDataViewRenderer( const wxString &varianttype,
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT );
virtual ~wxDataViewRenderer();
// these methods are used to draw the cell contents, Render() doesn't care
// about the attributes while RenderWithAttr() does -- override it if you
// want to take the attributes defined for this cell into account, otherwise
// overriding Render() is enough
virtual bool Render( wxRect cell, wxDC *dc, int state ) = 0;
// NB: RenderWithAttr() also has more standard parameter order and types
virtual bool
RenderWithAttr(wxDC& dc,
const wxRect& rect,
int align, // combination of horizontal and vertical
const wxDataViewItemAttr *attr, // may be NULL if none
int state);
virtual wxSize GetSize() const = 0;
virtual void SetAlignment( int align );
virtual int GetAlignment() const;
virtual void EnableEllipsize(wxEllipsizeMode mode = wxELLIPSIZE_MIDDLE)
{ m_ellipsizeMode = mode; }
virtual wxEllipsizeMode GetEllipsizeMode() const
{ return m_ellipsizeMode; }
virtual void SetMode( wxDataViewCellMode mode )
{ m_mode=mode; }
virtual wxDataViewCellMode GetMode() const
{ return m_mode; }
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; }
// Create DC on request
virtual wxDC *GetDC();
// implementation
int CalculateAlignment() const;
protected:
// This is just a convenience for the derived classes overriding
// RenderWithAttr() to avoid repeating the same wxFAIL_MSG() in all of them
bool DummyRender(wxRect WXUNUSED(cell),
wxDC * WXUNUSED(dc),
int WXUNUSED(state))
{
wxFAIL_MSG("shouldn't be called at all, use RenderWithAttr() instead");
return false;
}
private:
wxDC *m_dc;
int m_align;
wxDataViewCellMode m_mode;
wxEllipsizeMode m_ellipsizeMode;
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer)
};
// ---------------------------------------------------------
// wxDataViewCustomRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewRenderer
{
public:
wxDataViewCustomRenderer( const wxString &varianttype = wxT("string"),
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT );
// Draw the text using the provided attributes
void RenderText(wxDC& dc,
const wxRect& rect,
int align,
const wxString& text,
const wxDataViewItemAttr *attr, // may be NULL if none
int state,
int xoffset = 0);
// Overload using standard attributes
void RenderText(const wxString& text,
int xoffset,
wxRect cell,
wxDC *dc,
int state)
{
RenderText(*dc, cell, wxALIGN_NOT, text, NULL, state, xoffset);
}
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
};
// ---------------------------------------------------------
// wxDataViewTextRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewCustomRenderer
{
public:
wxDataViewTextRenderer( const wxString &varianttype = wxT("string"),
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT );
bool SetValue( const wxVariant &value );
bool GetValue( wxVariant &value ) const;
virtual bool RenderWithAttr(wxDC& dc,
const wxRect& rect,
int align,
const wxDataViewItemAttr *attr,
int state);
virtual bool Render(wxRect cell, wxDC *dc, int state)
{
return DummyRender(cell, dc, state);
}
wxSize GetSize() const;
// in-place editing
virtual bool HasEditorCtrl() const;
virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect,
const wxVariant &value );
virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
protected:
wxString m_text;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
};
// ---------------------------------------------------------
// wxDataViewBitmapRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewCustomRenderer
{
public:
wxDataViewBitmapRenderer( const wxString &varianttype = wxT("wxBitmap"),
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT );
bool SetValue( const wxVariant &value );
bool GetValue( wxVariant &value ) const;
bool Render( wxRect cell, wxDC *dc, int state );
wxSize GetSize() const;
private:
wxIcon m_icon;
wxBitmap m_bitmap;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
};
// ---------------------------------------------------------
// wxDataViewToggleRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewCustomRenderer
{
public:
wxDataViewToggleRenderer( const wxString &varianttype = wxT("bool"),
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT );
bool SetValue( const wxVariant &value );
bool GetValue( wxVariant &value ) const;
bool Render( wxRect cell, wxDC *dc, int state );
bool Activate( wxRect cell, wxDataViewModel *model, const wxDataViewItem & item,
unsigned int col );
wxSize GetSize() const;
private:
bool m_toggle;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
};
// ---------------------------------------------------------
// wxDataViewProgressRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer
{
public:
wxDataViewProgressRenderer( const wxString &label = wxEmptyString,
const wxString &varianttype = wxT("long"),
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT );
bool SetValue( const wxVariant &value );
bool GetValue( wxVariant& value ) const;
virtual bool RenderWithAttr(wxDC& dc,
const wxRect& rect,
int align,
const wxDataViewItemAttr *attr,
int state);
virtual bool Render(wxRect cell, wxDC *dc, int state)
{
return DummyRender(cell, dc, state);
}
virtual wxSize GetSize() const;
private:
wxString m_label;
int m_value;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
};
// ---------------------------------------------------------
// wxDataViewIconTextRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewCustomRenderer
{
public:
wxDataViewIconTextRenderer( const wxString &varianttype = wxT("wxDataViewIconText"),
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT );
bool SetValue( const wxVariant &value );
bool GetValue( wxVariant &value ) const;
virtual bool RenderWithAttr(wxDC& dc,
const wxRect& rect,
int align,
const wxDataViewItemAttr *attr,
int state);
virtual bool Render(wxRect cell, wxDC *dc, int state)
{
return DummyRender(cell, dc, state);
}
virtual wxSize GetSize() const;
virtual bool HasEditorCtrl() const { return true; }
virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect,
const wxVariant &value );
virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
private:
wxDataViewIconText m_value;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
};
// ---------------------------------------------------------
// wxDataViewDateRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer
{
public:
wxDataViewDateRenderer( const wxString &varianttype = wxT("datetime"),
wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
int align = wxDVR_DEFAULT_ALIGNMENT );
bool SetValue( const wxVariant &value );
bool GetValue( wxVariant& value ) const;
virtual bool Render( wxRect cell, wxDC *dc, int state );
virtual wxSize GetSize() const;
virtual bool Activate( wxRect cell,
wxDataViewModel *model,
const wxDataViewItem& item,
unsigned int col );
private:
wxDateTime m_date;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
};
// --------------------------------------------------------- // ---------------------------------------------------------
// wxDataViewColumn // wxDataViewColumn
// --------------------------------------------------------- // ---------------------------------------------------------

View File

@@ -0,0 +1,116 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/generic/dvrenderer.h
// Purpose: wxDataViewRenderer for generic wxDataViewCtrl implementation
// Author: Robert Roebling, Vadim Zeitlin
// Created: 2009-11-07 (extracted from wx/generic/dataview.h)
// RCS-ID: $Id: wxhead.h,v 1.11 2009-06-29 10:23:04 zeitlin Exp $
// Copyright: (c) 2006 Robert Roebling
// (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_GENERIC_DVRENDERER_H_
#define _WX_GENERIC_DVRENDERER_H_
// ----------------------------------------------------------------------------
// wxDataViewRenderer
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewRenderer: public wxDataViewCustomRendererBase
{
public:
wxDataViewRenderer( const wxString &varianttype,
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT );
virtual ~wxDataViewRenderer();
// these methods are used to draw the cell contents, Render() doesn't care
// about the attributes while RenderWithAttr() does -- override it if you
// want to take the attributes defined for this cell into account, otherwise
// overriding Render() is enough
virtual bool Render( wxRect cell, wxDC *dc, int state ) = 0;
// NB: RenderWithAttr() also has more standard parameter order and types
virtual bool
RenderWithAttr(wxDC& dc,
const wxRect& rect,
int align, // combination of horizontal and vertical
const wxDataViewItemAttr *attr, // may be NULL if none
int state);
virtual wxSize GetSize() const = 0;
virtual wxDC *GetDC();
// Draw the text using the provided attributes
void RenderText(wxDC& dc,
const wxRect& rect,
int align,
const wxString& text,
const wxDataViewItemAttr *attr, // may be NULL if none
int state,
int xoffset = 0);
// Overload using standard attributes
void RenderText(const wxString& text,
int xoffset,
wxRect cell,
wxDC *dc,
int state)
{
RenderText(*dc, cell, wxALIGN_NOT, text, NULL, state, xoffset);
}
virtual void SetAlignment( int align );
virtual int GetAlignment() const;
virtual void EnableEllipsize(wxEllipsizeMode mode = wxELLIPSIZE_MIDDLE)
{ m_ellipsizeMode = mode; }
virtual wxEllipsizeMode GetEllipsizeMode() const
{ return m_ellipsizeMode; }
virtual void SetMode( wxDataViewCellMode mode )
{ m_mode = mode; }
virtual wxDataViewCellMode GetMode() const
{ return m_mode; }
// implementation
int CalculateAlignment() const;
// this is a replacement for dynamic_cast<wxDataViewCustomRenderer> in the
// code checking whether the renderer is interested in mouse events, it's
// overridden in wxDataViewCustomRenderer to return the object itself but
// intentionally returns NULL for all the other renderer classes as the
// user should _not_ be able to override Activate/LeftClick() when deriving
// from them for consistency with the other ports and while we can't
// prevent this from working at compile-time because all renderer are
// custom renderers in the generic implementation, we at least make sure
// that it doesn't work at run-time because Activate/LeftClick() would
// never be called
virtual wxDataViewCustomRenderer *WXGetAsCustom() { return NULL; }
protected:
// This is just a convenience for the derived classes overriding
// RenderWithAttr() to avoid repeating the same wxFAIL_MSG() in all of them
bool DummyRender(wxRect WXUNUSED(cell),
wxDC * WXUNUSED(dc),
int WXUNUSED(state))
{
wxFAIL_MSG("shouldn't be called at all, use RenderWithAttr() instead");
return false;
}
private:
int m_align;
wxDataViewCellMode m_mode;
wxEllipsizeMode m_ellipsizeMode;
wxDC *m_dc;
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer)
};
#endif // _WX_GENERIC_DVRENDERER_H_

View File

@@ -0,0 +1,224 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/generic/dvrenderers.h
// Purpose: All generic wxDataViewCtrl renderer classes
// Author: Robert Roebling, Vadim Zeitlin
// Created: 2009-11-07 (extracted from wx/generic/dataview.h)
// RCS-ID: $Id: wxhead.h,v 1.11 2009-06-29 10:23:04 zeitlin Exp $
// Copyright: (c) 2006 Robert Roebling
// (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_GENERIC_DVRENDERERS_H_
#define _WX_GENERIC_DVRENDERERS_H_
// ---------------------------------------------------------
// wxDataViewCustomRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewRenderer
{
public:
wxDataViewCustomRenderer( const wxString &varianttype = wxT("string"),
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT );
virtual wxDataViewCustomRenderer *WXGetAsCustom() { return this; }
private:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
};
// ---------------------------------------------------------
// wxDataViewTextRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewRenderer
{
public:
wxDataViewTextRenderer( const wxString &varianttype = wxT("string"),
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT );
bool SetValue( const wxVariant &value );
bool GetValue( wxVariant &value ) const;
virtual bool RenderWithAttr(wxDC& dc,
const wxRect& rect,
int align,
const wxDataViewItemAttr *attr,
int state);
virtual bool Render(wxRect cell, wxDC *dc, int state)
{
return DummyRender(cell, dc, state);
}
wxSize GetSize() const;
// in-place editing
virtual bool HasEditorCtrl() const;
virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect,
const wxVariant &value );
virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
protected:
wxString m_text;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
};
// ---------------------------------------------------------
// wxDataViewBitmapRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer
{
public:
wxDataViewBitmapRenderer( const wxString &varianttype = wxT("wxBitmap"),
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT );
bool SetValue( const wxVariant &value );
bool GetValue( wxVariant &value ) const;
bool Render( wxRect cell, wxDC *dc, int state );
wxSize GetSize() const;
private:
wxIcon m_icon;
wxBitmap m_bitmap;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
};
// ---------------------------------------------------------
// wxDataViewToggleRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewRenderer
{
public:
wxDataViewToggleRenderer( const wxString &varianttype = wxT("bool"),
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT );
bool SetValue( const wxVariant &value );
bool GetValue( wxVariant &value ) const;
bool Render( wxRect cell, wxDC *dc, int state );
bool Activate( wxRect cell, wxDataViewModel *model, const wxDataViewItem & item,
unsigned int col );
wxSize GetSize() const;
private:
bool m_toggle;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
};
// ---------------------------------------------------------
// wxDataViewProgressRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewRenderer
{
public:
wxDataViewProgressRenderer( const wxString &label = wxEmptyString,
const wxString &varianttype = wxT("long"),
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT );
bool SetValue( const wxVariant &value );
bool GetValue( wxVariant& value ) const;
virtual bool RenderWithAttr(wxDC& dc,
const wxRect& rect,
int align,
const wxDataViewItemAttr *attr,
int state);
virtual bool Render(wxRect cell, wxDC *dc, int state)
{
return DummyRender(cell, dc, state);
}
virtual wxSize GetSize() const;
private:
wxString m_label;
int m_value;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
};
// ---------------------------------------------------------
// wxDataViewIconTextRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewRenderer
{
public:
wxDataViewIconTextRenderer( const wxString &varianttype = wxT("wxDataViewIconText"),
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT );
bool SetValue( const wxVariant &value );
bool GetValue( wxVariant &value ) const;
virtual bool RenderWithAttr(wxDC& dc,
const wxRect& rect,
int align,
const wxDataViewItemAttr *attr,
int state);
virtual bool Render(wxRect cell, wxDC *dc, int state)
{
return DummyRender(cell, dc, state);
}
virtual wxSize GetSize() const;
virtual bool HasEditorCtrl() const { return true; }
virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect,
const wxVariant &value );
virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
private:
wxDataViewIconText m_value;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
};
// ---------------------------------------------------------
// wxDataViewDateRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewRenderer
{
public:
wxDataViewDateRenderer( const wxString &varianttype = wxT("datetime"),
wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
int align = wxDVR_DEFAULT_ALIGNMENT );
bool SetValue( const wxVariant &value );
bool GetValue( wxVariant& value ) const;
virtual bool Render( wxRect cell, wxDC *dc, int state );
virtual wxSize GetSize() const;
virtual bool Activate( wxRect cell,
wxDataViewModel *model,
const wxDataViewItem& item,
unsigned int col );
private:
wxDateTime m_date;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
};
#endif // _WX_GENERIC_DVRENDERERS_H_

View File

@@ -12,309 +12,8 @@
#include "wx/list.h" #include "wx/list.h"
// ---------------------------------------------------------
// classes
// ---------------------------------------------------------
class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl;
class WXDLLIMPEXP_FWD_ADV wxDataViewCtrlInternal; class WXDLLIMPEXP_FWD_ADV wxDataViewCtrlInternal;
typedef struct _GtkTreeViewColumn GtkTreeViewColumn;
// ---------------------------------------------------------
// wxDataViewRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewRenderer: public wxDataViewRendererBase
{
public:
wxDataViewRenderer( const wxString &varianttype,
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT );
virtual void SetMode( wxDataViewCellMode mode );
virtual wxDataViewCellMode GetMode() const;
virtual void SetAlignment( int align );
virtual int GetAlignment() const;
virtual void EnableEllipsize(wxEllipsizeMode mode = wxELLIPSIZE_MIDDLE);
virtual wxEllipsizeMode GetEllipsizeMode() const;
// GTK-specific implementation
// ---------------------------
// pack the GTK cell renderers used by this renderer to the given column
//
// by default only a single m_renderer is used but some renderers use more
// than one GTK cell renderer
virtual void GtkPackIntoColumn(GtkTreeViewColumn *column);
// called when the cell value was edited by user with the new value
//
// it validates the new value and notifies the model about the change by
// calling GtkOnCellChanged() if it was accepted
void GtkOnTextEdited(const gchar *itempath, const wxString& value);
GtkCellRenderer* GetGtkHandle() { return m_renderer; }
void GtkInitHandlers();
void GtkUpdateAlignment();
bool GtkIsUsingDefaultAttrs() const { return m_usingDefaultAttrs; }
void GtkSetUsingDefaultAttrs(bool def) { m_usingDefaultAttrs = def; }
protected:
virtual void GtkOnCellChanged(const wxVariant& value,
const wxDataViewItem& item,
unsigned col);
GtkCellRenderer *m_renderer;
int m_alignment;
// true if we hadn't changed any visual attributes or restored them since
// doing this
bool m_usingDefaultAttrs;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer)
};
// ---------------------------------------------------------
// wxDataViewTextRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewRenderer
{
public:
wxDataViewTextRenderer( const wxString &varianttype = wxT("string"),
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT );
virtual bool SetValue( const wxVariant &value )
{
return SetTextValue(value);
}
virtual bool GetValue( wxVariant &value ) const
{
wxString str;
if ( !GetTextValue(str) )
return false;
value = str;
return true;
}
virtual void SetAlignment( int align );
protected:
// implementation of Set/GetValue()
bool SetTextValue(const wxString& str);
bool GetTextValue(wxString& str) const;
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
};
// ---------------------------------------------------------
// wxDataViewBitmapRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer
{
public:
wxDataViewBitmapRenderer( const wxString &varianttype = wxT("wxBitmap"),
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT );
bool SetValue( const wxVariant &value );
bool GetValue( wxVariant &value ) const;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
};
// ---------------------------------------------------------
// wxDataViewToggleRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewRenderer
{
public:
wxDataViewToggleRenderer( const wxString &varianttype = wxT("bool"),
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT );
bool SetValue( const wxVariant &value );
bool GetValue( wxVariant &value ) const;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
};
// ---------------------------------------------------------
// wxDataViewCustomRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewRenderer
{
public:
wxDataViewCustomRenderer( const wxString &varianttype = wxT("string"),
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT,
bool no_init = false );
virtual ~wxDataViewCustomRenderer();
virtual bool Render( wxRect cell, wxDC *dc, int state ) = 0;
void RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state );
virtual wxSize GetSize() const = 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; }
// Create DC on request
virtual wxDC *GetDC();
protected:
bool Init(wxDataViewCellMode mode, int align);
private:
wxDC *m_dc;
public:
// Internal, temporary for RenderText.
GtkCellRenderer *m_text_renderer;
GdkWindow *window;
GtkWidget *widget;
void *background_area;
void *cell_area;
void *expose_area;
int flags;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
};
// ---------------------------------------------------------
// wxDataViewProgressRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer
{
public:
wxDataViewProgressRenderer( const wxString &label = wxEmptyString,
const wxString &varianttype = wxT("long"),
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT );
virtual ~wxDataViewProgressRenderer();
bool SetValue( const wxVariant &value );
bool GetValue( wxVariant &value ) const;
virtual bool Render( wxRect cell, wxDC *dc, int state );
virtual wxSize GetSize() const;
private:
wxString m_label;
int m_value;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
};
// ---------------------------------------------------------
// wxDataViewIconTextRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewTextRenderer
{
public:
wxDataViewIconTextRenderer( const wxString &varianttype = wxT("wxDataViewIconText"),
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT );
virtual ~wxDataViewIconTextRenderer();
bool SetValue( const wxVariant &value );
bool GetValue( wxVariant &value ) const;
virtual void GtkPackIntoColumn(GtkTreeViewColumn *column);
protected:
virtual void GtkOnCellChanged(const wxVariant& value,
const wxDataViewItem& item,
unsigned col);
private:
wxDataViewIconText m_value;
// we use the base class m_renderer for the text and this one for the icon
GtkCellRenderer *m_rendererIcon;
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
};
// ---------------------------------------------------------
// wxDataViewDateRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer
{
public:
wxDataViewDateRenderer( const wxString &varianttype = wxT("datetime"),
wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
int align = wxDVR_DEFAULT_ALIGNMENT );
bool SetValue( const wxVariant &value );
bool GetValue( wxVariant &value ) const;
virtual bool Render( wxRect cell, wxDC *dc, int state );
virtual wxSize GetSize() const;
virtual bool Activate( wxRect cell,
wxDataViewModel *model, const wxDataViewItem &item, unsigned int col );
private:
wxDateTime m_date;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
};
// -------------------------------------
// wxDataViewChoiceRenderer
// -------------------------------------
class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer: public wxDataViewCustomRenderer
{
public:
wxDataViewChoiceRenderer( const wxArrayString &choices,
wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
int alignment = wxDVR_DEFAULT_ALIGNMENT );
virtual bool Render( wxRect rect, wxDC *dc, int state );
virtual wxSize GetSize() const;
virtual bool SetValue( const wxVariant &value );
virtual bool GetValue( wxVariant &value ) const;
void SetAlignment( int align );
private:
wxArrayString m_choices;
wxString m_data;
};
// --------------------------------------------------------- // ---------------------------------------------------------
// wxDataViewColumn // wxDataViewColumn
// --------------------------------------------------------- // ---------------------------------------------------------

View File

@@ -0,0 +1,77 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/gtk/dvrenderer.h
// Purpose: wxDataViewRenderer for GTK wxDataViewCtrl implementation
// Author: Robert Roebling, Vadim Zeitlin
// Created: 2009-11-07 (extracted from wx/gtk/dataview.h)
// RCS-ID: $Id: wxhead.h,v 1.11 2009-06-29 10:23:04 zeitlin Exp $
// Copyright: (c) 2006 Robert Roebling
// (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_GTK_DVRENDERER_H_
#define _WX_GTK_DVRENDERER_H_
typedef struct _GtkTreeViewColumn GtkTreeViewColumn;
// ----------------------------------------------------------------------------
// wxDataViewRenderer
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewRenderer: public wxDataViewRendererBase
{
public:
wxDataViewRenderer( const wxString &varianttype,
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT );
virtual void SetMode( wxDataViewCellMode mode );
virtual wxDataViewCellMode GetMode() const;
virtual void SetAlignment( int align );
virtual int GetAlignment() const;
virtual void EnableEllipsize(wxEllipsizeMode mode = wxELLIPSIZE_MIDDLE);
virtual wxEllipsizeMode GetEllipsizeMode() const;
// GTK-specific implementation
// ---------------------------
// pack the GTK cell renderers used by this renderer to the given column
//
// by default only a single m_renderer is used but some renderers use more
// than one GTK cell renderer
virtual void GtkPackIntoColumn(GtkTreeViewColumn *column);
// called when the cell value was edited by user with the new value
//
// it validates the new value and notifies the model about the change by
// calling GtkOnCellChanged() if it was accepted
void GtkOnTextEdited(const gchar *itempath, const wxString& value);
GtkCellRenderer* GetGtkHandle() { return m_renderer; }
void GtkInitHandlers();
void GtkUpdateAlignment();
bool GtkIsUsingDefaultAttrs() const { return m_usingDefaultAttrs; }
void GtkSetUsingDefaultAttrs(bool def) { m_usingDefaultAttrs = def; }
protected:
virtual void GtkOnCellChanged(const wxVariant& value,
const wxDataViewItem& item,
unsigned col);
GtkCellRenderer *m_renderer;
int m_alignment;
// true if we hadn't changed any visual attributes or restored them since
// doing this
bool m_usingDefaultAttrs;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer)
};
#endif // _WX_GTK_DVRENDERER_H_

View File

@@ -0,0 +1,243 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/gtk/dvrenderers.h
// Purpose: All GTK wxDataViewCtrl renderer classes
// Author: Robert Roebling, Vadim Zeitlin
// Created: 2009-11-07 (extracted from wx/gtk/dataview.h)
// RCS-ID: $Id: wxhead.h,v 1.11 2009-06-29 10:23:04 zeitlin Exp $
// Copyright: (c) 2006 Robert Roebling
// (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_GTK_DVRENDERERS_H_
#define _WX_GTK_DVRENDERERS_H_
// ---------------------------------------------------------
// wxDataViewTextRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewRenderer
{
public:
wxDataViewTextRenderer( const wxString &varianttype = "string",
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT );
virtual bool SetValue( const wxVariant &value )
{
return SetTextValue(value);
}
virtual bool GetValue( wxVariant &value ) const
{
wxString str;
if ( !GetTextValue(str) )
return false;
value = str;
return true;
}
virtual void SetAlignment( int align );
protected:
// implementation of Set/GetValue()
bool SetTextValue(const wxString& str);
bool GetTextValue(wxString& str) const;
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
};
// ---------------------------------------------------------
// wxDataViewBitmapRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer
{
public:
wxDataViewBitmapRenderer( const wxString &varianttype = "wxBitmap",
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT );
bool SetValue( const wxVariant &value );
bool GetValue( wxVariant &value ) const;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
};
// ---------------------------------------------------------
// wxDataViewToggleRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewRenderer
{
public:
wxDataViewToggleRenderer( const wxString &varianttype = "bool",
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT );
bool SetValue( const wxVariant &value );
bool GetValue( wxVariant &value ) const;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
};
// ---------------------------------------------------------
// wxDataViewCustomRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewCustomRendererBase
{
public:
wxDataViewCustomRenderer( const wxString &varianttype = "string",
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT,
bool no_init = false );
virtual ~wxDataViewCustomRenderer();
virtual bool Render( wxRect cell, wxDC *dc, int state ) = 0;
void RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state );
virtual wxSize GetSize() const = 0;
// Create DC on request
virtual wxDC *GetDC();
protected:
bool Init(wxDataViewCellMode mode, int align);
private:
wxDC *m_dc;
public:
// Internal, temporary for RenderText.
GtkCellRenderer *m_text_renderer;
GdkWindow *window;
GtkWidget *widget;
void *background_area;
void *cell_area;
void *expose_area;
int flags;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
};
// ---------------------------------------------------------
// wxDataViewProgressRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer
{
public:
wxDataViewProgressRenderer( const wxString &label = wxEmptyString,
const wxString &varianttype = "long",
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT );
virtual ~wxDataViewProgressRenderer();
bool SetValue( const wxVariant &value );
bool GetValue( wxVariant &value ) const;
virtual bool Render( wxRect cell, wxDC *dc, int state );
virtual wxSize GetSize() const;
private:
wxString m_label;
int m_value;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
};
// ---------------------------------------------------------
// wxDataViewIconTextRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewTextRenderer
{
public:
wxDataViewIconTextRenderer( const wxString &varianttype = "wxDataViewIconText",
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT );
virtual ~wxDataViewIconTextRenderer();
bool SetValue( const wxVariant &value );
bool GetValue( wxVariant &value ) const;
virtual void GtkPackIntoColumn(GtkTreeViewColumn *column);
protected:
virtual void GtkOnCellChanged(const wxVariant& value,
const wxDataViewItem& item,
unsigned col);
private:
wxDataViewIconText m_value;
// we use the base class m_renderer for the text and this one for the icon
GtkCellRenderer *m_rendererIcon;
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
};
// ---------------------------------------------------------
// wxDataViewDateRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer
{
public:
wxDataViewDateRenderer( const wxString &varianttype = "datetime",
wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
int align = wxDVR_DEFAULT_ALIGNMENT );
bool SetValue( const wxVariant &value );
bool GetValue( wxVariant &value ) const;
virtual bool Render( wxRect cell, wxDC *dc, int state );
virtual wxSize GetSize() const;
virtual bool Activate( wxRect cell,
wxDataViewModel *model,
const wxDataViewItem &item,
unsigned int col );
private:
wxDateTime m_date;
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
};
// -------------------------------------
// wxDataViewChoiceRenderer
// -------------------------------------
class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer: public wxDataViewCustomRenderer
{
public:
wxDataViewChoiceRenderer(const wxArrayString &choices,
wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
int alignment = wxDVR_DEFAULT_ALIGNMENT );
virtual bool Render( wxRect rect, wxDC *dc, int state );
virtual wxSize GetSize() const;
virtual bool SetValue( const wxVariant &value );
virtual bool GetValue( wxVariant &value ) const;
void SetAlignment( int align );
private:
wxArrayString m_choices;
wxString m_data;
};
#endif // _WX_GTK_DVRENDERERS_H_

View File

@@ -1,4 +1,3 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: wx/osx/dataview.h // Name: wx/osx/dataview.h
// Purpose: wxDataViewCtrl native implementation header for OSX // Purpose: wxDataViewCtrl native implementation header for OSX
@@ -19,356 +18,8 @@
// Class declarations to mask native types // Class declarations to mask native types
// -------------------------------------------------------- // --------------------------------------------------------
class wxDataViewColumnNativeData; // class storing environment dependent data for the native implementation 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 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();
//
// inherited methods from wxDataViewRendererBase
//
virtual int GetAlignment() const
{
return m_alignment;
}
virtual wxDataViewCellMode GetMode() const
{
return m_mode;
}
virtual bool GetValue(wxVariant& value) const
{
value = 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)
{
m_value = newValue;
return true;
}
virtual void EnableEllipsize(wxEllipsizeMode mode = wxELLIPSIZE_MIDDLE);
virtual wxEllipsizeMode GetEllipsizeMode() const;
//
// implementation
//
wxVariant const& GetValue() const
{
return m_value;
}
wxDataViewRendererNativeData* GetNativeData() const
{
return m_NativeDataPtr;
}
virtual bool MacRender() = 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);
#if wxOSX_USE_COCOA
// called when a value was edited by user
virtual void OSXOnCellChanged(NSObject *value,
const wxDataViewItem& item,
unsigned col);
#endif // Cocoa
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 MacRender();
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 MacRender();
#if wxOSX_USE_COCOA
virtual void OSXOnCellChanged(NSObject *value,
const wxDataViewItem& item,
unsigned col);
#endif // Cocoa
private:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
};
// ---------------------------------------------------------
// 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 MacRender();
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 MacRender();
//
// implementation
//
wxString GetChoice(size_t index) const
{
return m_Choices[index];
}
wxArrayString const& GetChoices() const
{
return 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 MacRender();
#if wxOSX_USE_COCOA
virtual void OSXOnCellChanged(NSObject *value,
const wxDataViewItem& item,
unsigned col);
#endif // Cocoa
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 MacRender();
#if wxOSX_USE_COCOA
virtual void OSXOnCellChanged(NSObject *value,
const wxDataViewItem& item,
unsigned col);
#endif // Cocoa
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 MacRender();
#if wxOSX_USE_COCOA
virtual void OSXOnCellChanged(NSObject *value,
const wxDataViewItem& item,
unsigned col);
#endif // Cocoa
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 MacRender();
#if wxOSX_USE_COCOA
virtual void OSXOnCellChanged(NSObject *value,
const wxDataViewItem& item,
unsigned col);
#endif // Cocoa
private:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
};
// --------------------------------------------------------- // ---------------------------------------------------------
// wxDataViewColumn // wxDataViewColumn
// --------------------------------------------------------- // ---------------------------------------------------------

105
include/wx/osx/dvrenderer.h Normal file
View File

@@ -0,0 +1,105 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/osx/dvrenderer.h
// Purpose: wxDataViewRenderer for OS X wxDataViewCtrl implementations
// Author: Vadim Zeitlin
// Created: 2009-11-07 (extracted from wx/osx/dataview.h)
// RCS-ID: $Id: wxhead.h,v 1.11 2009-06-29 10:23:04 zeitlin Exp $
// Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_OSX_DVRENDERER_H_
#define _WX_OSX_DVRENDERER_H_
class wxDataViewRendererNativeData;
// ----------------------------------------------------------------------------
// wxDataViewRenderer
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewRenderer : public wxDataViewRendererBase
{
public:
// constructors / destructor
// -------------------------
wxDataViewRenderer(const wxString& varianttype,
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT);
virtual ~wxDataViewRenderer();
// inherited methods from wxDataViewRendererBase
// ---------------------------------------------
virtual int GetAlignment() const
{
return m_alignment;
}
virtual wxDataViewCellMode GetMode() const
{
return m_mode;
}
virtual bool GetValue(wxVariant& value) const
{
value = m_value;
return true;
}
// NB: in Carbon this is always identical to the header alignment
virtual void SetAlignment(int align);
virtual void SetMode(wxDataViewCellMode mode);
virtual bool SetValue(const wxVariant& newValue)
{
m_value = newValue;
return true;
}
virtual void EnableEllipsize(wxEllipsizeMode mode = wxELLIPSIZE_MIDDLE);
virtual wxEllipsizeMode GetEllipsizeMode() const;
// implementation
// --------------
const wxVariant& GetValue() const
{
return m_value;
}
wxDataViewRendererNativeData* GetNativeData() const
{
return m_NativeDataPtr;
}
// a call to the native data browser function to render the data;
// returns true if the data value could be rendered, false otherwise
virtual bool MacRender() = 0;
void SetNativeData(wxDataViewRendererNativeData* newNativeDataPtr);
#if wxOSX_USE_COCOA
// called when a value was edited by user
virtual void OSXOnCellChanged(NSObject *value,
const wxDataViewItem& item,
unsigned col);
#endif // Cocoa
private:
// contains the alignment flags
int m_alignment;
// storing the mode that determines how the cell is going to be shown
wxDataViewCellMode m_mode;
// data used by implementation of the native renderer
wxDataViewRendererNativeData* m_NativeDataPtr;
// value that is going to be rendered
wxVariant m_value;
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer)
};
#endif // _WX_OSX_DVRENDERER_H_

View File

@@ -0,0 +1,209 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/osx/dvrenderers.h
// Purpose: All OS X wxDataViewCtrl renderer classes
// Author: Vadim Zeitlin
// Created: 2009-11-07 (extracted from wx/osx/dataview.h)
// RCS-ID: $Id: wxhead.h,v 1.11 2009-06-29 10:23:04 zeitlin Exp $
// Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_OSX_DVRENDERERS_H_
#define _WX_OSX_DVRENDERERS_H_
// ---------------------------------------------------------
// wxDataViewCustomRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewCustomRenderer : public wxDataViewCustomRendererBase
{
public:
wxDataViewCustomRenderer(const wxString& varianttype = "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 );
virtual wxSize GetSize() const = 0;
virtual bool Render(wxRect cell, wxDC* dc, int state) = 0;
// implementation only
// -------------------
virtual bool MacRender();
virtual wxDC* GetDC(); // creates a device context and keeps it
void SetDC(wxDC* newDCPtr); // this method takes ownership of the pointer
private:
wxControl* m_editorCtrlPtr; // pointer to an in-place editor control
wxDC* m_DCPtr;
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
};
// ---------------------------------------------------------
// wxDataViewTextRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewRenderer
{
public:
wxDataViewTextRenderer(const wxString& varianttype = "string",
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT);
virtual bool MacRender();
#if wxOSX_USE_COCOA
virtual void OSXOnCellChanged(NSObject *value,
const wxDataViewItem& item,
unsigned col);
#endif // Cocoa
private:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
};
// ---------------------------------------------------------
// wxDataViewBitmapRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer
{
public:
wxDataViewBitmapRenderer(const wxString& varianttype = "wxBitmap",
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT);
virtual bool MacRender();
private:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
};
#if wxOSX_USE_COCOA
// -------------------------------------
// wxDataViewChoiceRenderer
// -------------------------------------
class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer: public wxDataViewRenderer
{
public:
wxDataViewChoiceRenderer(const wxArrayString& choices,
wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
int alignment = wxDVR_DEFAULT_ALIGNMENT );
virtual bool MacRender();
wxString GetChoice(size_t index) const { return m_choices[index]; }
const wxArrayString& GetChoices() const { return m_choices; }
private:
wxArrayString m_choices;
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewChoiceRenderer)
};
#endif // wxOSX_USE_COCOA
// ---------------------------------------------------------
// wxDataViewIconTextRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewRenderer
{
public:
wxDataViewIconTextRenderer(const wxString& varianttype = "wxDataViewIconText",
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT);
virtual bool MacRender();
#if wxOSX_USE_COCOA
virtual void OSXOnCellChanged(NSObject *value,
const wxDataViewItem& item,
unsigned col);
#endif // Cocoa
private:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
};
// ---------------------------------------------------------
// wxDataViewToggleRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewRenderer
{
public:
wxDataViewToggleRenderer(const wxString& varianttype = "bool",
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT);
virtual bool MacRender();
#if wxOSX_USE_COCOA
virtual void OSXOnCellChanged(NSObject *value,
const wxDataViewItem& item,
unsigned col);
#endif // Cocoa
private:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
};
// ---------------------------------------------------------
// wxDataViewProgressRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewRenderer
{
public:
wxDataViewProgressRenderer(const wxString& label = wxEmptyString,
const wxString& varianttype = "long",
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
int align = wxDVR_DEFAULT_ALIGNMENT);
virtual bool MacRender();
#if wxOSX_USE_COCOA
virtual void OSXOnCellChanged(NSObject *value,
const wxDataViewItem& item,
unsigned col);
#endif // Cocoa
private:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
};
// ---------------------------------------------------------
// wxDataViewDateRenderer
// ---------------------------------------------------------
class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewRenderer
{
public:
wxDataViewDateRenderer(const wxString& varianttype = "datetime",
wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
int align = wxDVR_DEFAULT_ALIGNMENT);
virtual bool MacRender();
#if wxOSX_USE_COCOA
virtual void OSXOnCellChanged(NSObject *value,
const wxDataViewItem& item,
unsigned col);
#endif // Cocoa
private:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
};
#endif // _WX_OSX_DVRENDERERS_H_

View File

@@ -607,20 +607,56 @@ IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer, wxDataViewRendererBase)
wxDataViewRenderer::wxDataViewRenderer( const wxString &varianttype, wxDataViewRenderer::wxDataViewRenderer( const wxString &varianttype,
wxDataViewCellMode mode, wxDataViewCellMode mode,
int align) : int align) :
wxDataViewRendererBase( varianttype, mode, align ) wxDataViewCustomRendererBase( varianttype, mode, align )
{ {
m_dc = NULL;
m_align = align; m_align = align;
m_mode = mode; m_mode = mode;
m_ellipsizeMode = wxELLIPSIZE_MIDDLE; m_ellipsizeMode = wxELLIPSIZE_MIDDLE;
m_dc = NULL;
} }
wxDataViewRenderer::~wxDataViewRenderer() wxDataViewRenderer::~wxDataViewRenderer()
{ {
if (m_dc)
delete m_dc; delete m_dc;
} }
wxDC *wxDataViewRenderer::GetDC()
{
if (m_dc == NULL)
{
if (GetOwner() == NULL)
return NULL;
if (GetOwner()->GetOwner() == NULL)
return NULL;
m_dc = new wxClientDC( GetOwner()->GetOwner() );
}
return m_dc;
}
void wxDataViewRenderer::SetAlignment( int align )
{
m_align=align;
}
int wxDataViewRenderer::GetAlignment() const
{
return m_align;
}
int wxDataViewRenderer::CalculateAlignment() const
{
if (m_align == wxDVR_DEFAULT_ALIGNMENT)
{
if (GetOwner() == NULL)
return wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL;
return GetOwner()->GetAlignment() | wxALIGN_CENTRE_VERTICAL;
}
return m_align;
}
bool bool
wxDataViewRenderer::RenderWithAttr(wxDC& dc, wxDataViewRenderer::RenderWithAttr(wxDC& dc,
const wxRect& cell_rect, const wxRect& cell_rect,
@@ -669,57 +705,8 @@ wxDataViewRenderer::RenderWithAttr(wxDC& dc,
return Render(item_rect, &dc, state); return Render(item_rect, &dc, state);
} }
wxDC *wxDataViewRenderer::GetDC()
{
if (m_dc == NULL)
{
if (GetOwner() == NULL)
return NULL;
if (GetOwner()->GetOwner() == NULL)
return NULL;
m_dc = new wxClientDC( GetOwner()->GetOwner() );
}
return m_dc;
}
void wxDataViewRenderer::SetAlignment( int align )
{
m_align=align;
}
int wxDataViewRenderer::GetAlignment() const
{
return m_align;
}
int wxDataViewRenderer::CalculateAlignment() const
{
if (m_align == wxDVR_DEFAULT_ALIGNMENT)
{
if (GetOwner() == NULL)
return wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL;
return GetOwner()->GetAlignment() | wxALIGN_CENTRE_VERTICAL;
}
return m_align;
}
// ---------------------------------------------------------
// wxDataViewCustomRenderer
// ---------------------------------------------------------
IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer, wxDataViewRenderer)
wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString &varianttype,
wxDataViewCellMode mode, int align ) :
wxDataViewRenderer( varianttype, mode, align )
{
}
void void
wxDataViewCustomRenderer::RenderText(wxDC& dc, wxDataViewRenderer::RenderText(wxDC& dc,
const wxRect& rect, const wxRect& rect,
int align, int align,
const wxString& text, const wxString& text,
@@ -774,15 +761,27 @@ wxDataViewCustomRenderer::RenderText(wxDC& dc,
rectText, align); rectText, align);
} }
// ---------------------------------------------------------
// wxDataViewCustomRenderer
// ---------------------------------------------------------
IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer, wxDataViewRenderer)
wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString &varianttype,
wxDataViewCellMode mode, int align ) :
wxDataViewRenderer( varianttype, mode, align )
{
}
// --------------------------------------------------------- // ---------------------------------------------------------
// wxDataViewTextRenderer // wxDataViewTextRenderer
// --------------------------------------------------------- // ---------------------------------------------------------
IMPLEMENT_CLASS(wxDataViewTextRenderer, wxDataViewCustomRenderer) IMPLEMENT_CLASS(wxDataViewTextRenderer, wxDataViewRenderer)
wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString &varianttype, wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString &varianttype,
wxDataViewCellMode mode, int align ) : wxDataViewCellMode mode, int align ) :
wxDataViewCustomRenderer( varianttype, mode, align ) wxDataViewRenderer( varianttype, mode, align )
{ {
} }
@@ -847,11 +846,11 @@ wxSize wxDataViewTextRenderer::GetSize() const
// wxDataViewBitmapRenderer // wxDataViewBitmapRenderer
// --------------------------------------------------------- // ---------------------------------------------------------
IMPLEMENT_CLASS(wxDataViewBitmapRenderer, wxDataViewCustomRenderer) IMPLEMENT_CLASS(wxDataViewBitmapRenderer, wxDataViewRenderer)
wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString &varianttype, wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString &varianttype,
wxDataViewCellMode mode, int align ) : wxDataViewCellMode mode, int align ) :
wxDataViewCustomRenderer( varianttype, mode, align ) wxDataViewRenderer( varianttype, mode, align )
{ {
} }
@@ -894,11 +893,11 @@ wxSize wxDataViewBitmapRenderer::GetSize() const
// wxDataViewToggleRenderer // wxDataViewToggleRenderer
// --------------------------------------------------------- // ---------------------------------------------------------
IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer, wxDataViewCustomRenderer) IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer, wxDataViewRenderer)
wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString &varianttype, wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString &varianttype,
wxDataViewCellMode mode, int align ) : wxDataViewCellMode mode, int align ) :
wxDataViewCustomRenderer( varianttype, mode, align ) wxDataViewRenderer( varianttype, mode, align )
{ {
m_toggle = false; m_toggle = false;
} }
@@ -951,11 +950,11 @@ wxSize wxDataViewToggleRenderer::GetSize() const
// wxDataViewProgressRenderer // wxDataViewProgressRenderer
// --------------------------------------------------------- // ---------------------------------------------------------
IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer, wxDataViewCustomRenderer) IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer, wxDataViewRenderer)
wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString &label, wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString &label,
const wxString &varianttype, wxDataViewCellMode mode, int align ) : const wxString &varianttype, wxDataViewCellMode mode, int align ) :
wxDataViewCustomRenderer( varianttype, mode, align ) wxDataViewRenderer( varianttype, mode, align )
{ {
m_label = label; m_label = label;
m_value = 0; m_value = 0;
@@ -1057,11 +1056,11 @@ void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent &event )
#endif // wxUSE_DATE_RENDERER_POPUP #endif // wxUSE_DATE_RENDERER_POPUP
IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer, wxDataViewCustomRenderer) IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer, wxDataViewRenderer)
wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString &varianttype, wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString &varianttype,
wxDataViewCellMode mode, int align ) : wxDataViewCellMode mode, int align ) :
wxDataViewCustomRenderer( varianttype, mode, align ) wxDataViewRenderer( varianttype, mode, align )
{ {
} }
@@ -1118,11 +1117,11 @@ bool wxDataViewDateRenderer::Activate( wxRect WXUNUSED(cell), wxDataViewModel *m
// wxDataViewIconTextRenderer // wxDataViewIconTextRenderer
// --------------------------------------------------------- // ---------------------------------------------------------
IMPLEMENT_CLASS(wxDataViewIconTextRenderer, wxDataViewCustomRenderer) IMPLEMENT_CLASS(wxDataViewIconTextRenderer, wxDataViewRenderer)
wxDataViewIconTextRenderer::wxDataViewIconTextRenderer( wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
const wxString &varianttype, wxDataViewCellMode mode, int align ) : const wxString &varianttype, wxDataViewCellMode mode, int align ) :
wxDataViewCustomRenderer( varianttype, mode, align ) wxDataViewRenderer( varianttype, mode, align )
{ {
SetMode(mode); SetMode(mode);
SetAlignment(align); SetAlignment(align);
@@ -3664,13 +3663,16 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
else if ( current == m_lineLastClicked ) else if ( current == m_lineLastClicked )
{ {
if ((!ignore_other_columns) && (cell->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE)) if ((!ignore_other_columns) && (cell->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE))
{
if ( wxDataViewCustomRenderer *custom = cell->WXGetAsCustom() )
{ {
wxVariant value; wxVariant value;
model->GetValue( value, item, col->GetModelColumn() ); model->GetValue( value, item, col->GetModelColumn() );
cell->SetValue( value ); custom->SetValue( value );
wxRect cell_rect( xpos, GetLineStart( current ), wxRect cell_rect( xpos, GetLineStart( current ),
col->GetWidth(), GetLineHeight( current ) ); col->GetWidth(), GetLineHeight( current ) );
cell->Activate( cell_rect, model, item, col->GetModelColumn() ); custom->Activate( cell_rect, model, item, col->GetModelColumn() );
}
} }
else else
{ {
@@ -3839,17 +3841,20 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
// Call LeftClick after everything else as under GTK+ // Call LeftClick after everything else as under GTK+
if (cell->GetMode() & wxDATAVIEW_CELL_ACTIVATABLE) if (cell->GetMode() & wxDATAVIEW_CELL_ACTIVATABLE)
{ {
// notify cell about right click if ( wxDataViewCustomRenderer *custom = cell->WXGetAsCustom() )
{
// notify cell about click
wxVariant value; wxVariant value;
model->GetValue( value, item, col->GetModelColumn() ); model->GetValue( value, item, col->GetModelColumn() );
cell->SetValue( value ); custom->SetValue( value );
wxRect cell_rect( xpos, GetLineStart( current ), wxRect cell_rect( xpos, GetLineStart( current ),
col->GetWidth(), GetLineHeight( current ) ); col->GetWidth(), GetLineHeight( current ) );
/* ignore ret */ cell->LeftClick( event.GetPosition(), cell_rect, /* ignore ret */ custom->LeftClick( event.GetPosition(), cell_rect,
model, item, col->GetModelColumn()); model, item, col->GetModelColumn());
} }
} }
} }
}
void wxDataViewMainWindow::OnSetFocus( wxFocusEvent &event ) void wxDataViewMainWindow::OnSetFocus( wxFocusEvent &event )
{ {

View File

@@ -2030,9 +2030,10 @@ public:
IMPLEMENT_CLASS(wxDataViewCustomRenderer, wxDataViewRenderer) IMPLEMENT_CLASS(wxDataViewCustomRenderer, wxDataViewRenderer)
wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString &varianttype, wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString &varianttype,
wxDataViewCellMode mode, int align, wxDataViewCellMode mode,
bool no_init ) : int align,
wxDataViewRenderer( varianttype, mode, align ) bool no_init )
: wxDataViewCustomRendererBase( varianttype, mode, align )
{ {
m_dc = NULL; m_dc = NULL;
m_text_renderer = NULL; m_text_renderer = NULL;

View File

@@ -2305,7 +2305,9 @@ IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer,wxDataViewRendererBase)
// wxDataViewCustomRenderer // wxDataViewCustomRenderer
// --------------------------------------------------------- // ---------------------------------------------------------
wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align) wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
:wxDataViewRenderer(varianttype,mode,align), m_editorCtrlPtr(NULL), m_DCPtr(NULL) :wxDataViewCustomRendererBase(varianttype,mode,align),
m_editorCtrlPtr(NULL),
m_DCPtr(NULL)
{ {
SetNativeData(new wxDataViewRendererNativeData(kDataBrowserCustomType)); SetNativeData(new wxDataViewRendererNativeData(kDataBrowserCustomType));
} }

View File

@@ -2389,7 +2389,7 @@ IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer,wxDataViewRendererBase)
wxDataViewCustomRenderer::wxDataViewCustomRenderer(const wxString& varianttype, wxDataViewCustomRenderer::wxDataViewCustomRenderer(const wxString& varianttype,
wxDataViewCellMode mode, wxDataViewCellMode mode,
int align) int align)
: wxDataViewRenderer(varianttype, mode, align), : wxDataViewCustomRendererBase(varianttype, mode, align),
m_editorCtrlPtr(NULL), m_editorCtrlPtr(NULL),
m_DCPtr(NULL) m_DCPtr(NULL)
{ {
@@ -2486,7 +2486,8 @@ IMPLEMENT_CLASS(wxDataViewBitmapRenderer,wxDataViewRenderer)
wxDataViewChoiceRenderer::wxDataViewChoiceRenderer(const wxArrayString& choices, wxDataViewChoiceRenderer::wxDataViewChoiceRenderer(const wxArrayString& choices,
wxDataViewCellMode mode, wxDataViewCellMode mode,
int alignment) int alignment)
: wxDataViewRenderer(wxT("string"),mode,alignment), m_Choices(choices) : wxDataViewRenderer(wxT("string"), mode, alignment),
m_choices(choices)
{ {
NSPopUpButtonCell* cell; NSPopUpButtonCell* cell;