From 6eec70b984525aac09528c32411f19113620e284 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 10 Nov 2009 17:40:58 +0000 Subject: [PATCH 1/1] 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 --- Makefile.in | 12 ++ build/bakefiles/files.bkl | 9 + build/msw/wx_adv.dsp | 12 ++ build/msw/wx_core.dsp | 12 ++ build/msw/wx_vc7_adv.vcproj | 9 + build/msw/wx_vc7_core.vcproj | 9 + build/msw/wx_vc8_adv.vcproj | 12 ++ build/msw/wx_vc8_core.vcproj | 12 ++ build/msw/wx_vc9_adv.vcproj | 12 ++ build/msw/wx_vc9_core.vcproj | 12 ++ include/wx/dataview.h | 199 ++---------------- include/wx/dvrenderers.h | 309 +++++++++++++++++++++++++++ include/wx/generic/dataview.h | 317 ---------------------------- include/wx/generic/dvrenderer.h | 116 ++++++++++ include/wx/generic/dvrenderers.h | 224 ++++++++++++++++++++ include/wx/gtk/dataview.h | 301 -------------------------- include/wx/gtk/dvrenderer.h | 77 +++++++ include/wx/gtk/dvrenderers.h | 243 +++++++++++++++++++++ include/wx/osx/dataview.h | 349 ------------------------------- include/wx/osx/dvrenderer.h | 105 ++++++++++ include/wx/osx/dvrenderers.h | 209 ++++++++++++++++++ src/generic/datavgen.cpp | 177 ++++++++-------- src/gtk/dataview.cpp | 7 +- src/osx/carbon/dataview.cpp | 4 +- src/osx/cocoa/dataview.mm | 5 +- 25 files changed, 1507 insertions(+), 1246 deletions(-) create mode 100644 include/wx/dvrenderers.h create mode 100644 include/wx/generic/dvrenderer.h create mode 100644 include/wx/generic/dvrenderers.h create mode 100644 include/wx/gtk/dvrenderer.h create mode 100644 include/wx/gtk/dvrenderers.h create mode 100644 include/wx/osx/dvrenderer.h create mode 100644 include/wx/osx/dvrenderers.h diff --git a/Makefile.in b/Makefile.in index 096a307fe3..6d634b5985 100644 --- a/Makefile.in +++ b/Makefile.in @@ -3400,6 +3400,8 @@ COND_TOOLKIT_MOTIF_ADVANCED_PLATFORM_HDR = \ COND_TOOLKIT_OSX_CARBON_ADVANCED_PLATFORM_HDR = \ wx/generic/animate.h \ wx/osx/dataview.h \ + wx/osx/dvrenderer.h \ + wx/osx/dvrenderers.h \ wx/osx/joystick.h \ wx/osx/sound.h \ wx/osx/taskbarosx.h \ @@ -3410,6 +3412,8 @@ COND_TOOLKIT_OSX_CARBON_ADVANCED_PLATFORM_HDR = \ COND_TOOLKIT_OSX_COCOA_ADVANCED_PLATFORM_HDR = \ wx/generic/animate.h \ wx/osx/dataview.h \ + wx/osx/dvrenderer.h \ + wx/osx/dvrenderers.h \ wx/osx/joystick.h \ wx/osx/sound.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/calctrl.h \ wx/gtk/dataview.h \ + wx/gtk/dvrenderer.h \ + wx/gtk/dvrenderers.h \ wx/gtk/hyperlink.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) @@ -3445,12 +3451,15 @@ COND_WXUNIV_0_ADVANCED_HDR = \ wx/datectrl.h \ wx/dateevt.h \ wx/dcbuffer.h \ + wx/dvrenderers.h \ wx/editlbox.h \ wx/generic/aboutdlgg.h \ wx/generic/bmpcbox.h \ wx/generic/calctrlg.h \ wx/generic/datectrl.h \ wx/generic/dataview.h \ + wx/generic/dvrenderer.h \ + wx/generic/dvrenderers.h \ wx/generic/grid.h \ wx/generic/gridctrl.h \ wx/generic/grideditors.h \ @@ -3490,12 +3499,15 @@ COND_WXUNIV_1_ADVANCED_HDR = \ wx/datectrl.h \ wx/dateevt.h \ wx/dcbuffer.h \ + wx/dvrenderers.h \ wx/editlbox.h \ wx/generic/aboutdlgg.h \ wx/generic/bmpcbox.h \ wx/generic/calctrlg.h \ wx/generic/datectrl.h \ wx/generic/dataview.h \ + wx/generic/dvrenderer.h \ + wx/generic/dvrenderers.h \ wx/generic/grid.h \ wx/generic/gridctrl.h \ wx/generic/grideditors.h \ diff --git a/build/bakefiles/files.bkl b/build/bakefiles/files.bkl index 763e0eff83..c4946e00d0 100644 --- a/build/bakefiles/files.bkl +++ b/build/bakefiles/files.bkl @@ -2865,12 +2865,15 @@ src/osx/iphone/window.mm wx/datectrl.h wx/dateevt.h wx/dcbuffer.h + wx/dvrenderers.h wx/editlbox.h wx/generic/aboutdlgg.h wx/generic/bmpcbox.h wx/generic/calctrlg.h wx/generic/datectrl.h wx/generic/dataview.h + wx/generic/dvrenderer.h + wx/generic/dvrenderers.h wx/generic/grid.h wx/generic/gridctrl.h wx/generic/grideditors.h @@ -2952,6 +2955,8 @@ src/osx/iphone/window.mm wx/generic/animate.h wx/osx/dataview.h + wx/osx/dvrenderer.h + wx/osx/dvrenderers.h wx/osx/joystick.h wx/osx/sound.h wx/osx/taskbarosx.h @@ -2976,6 +2981,8 @@ src/osx/iphone/window.mm wx/generic/animate.h wx/osx/dataview.h + wx/osx/dvrenderer.h + wx/osx/dvrenderers.h wx/osx/joystick.h wx/osx/sound.h wx/osx/taskbarosx.h @@ -3051,6 +3058,8 @@ src/osx/iphone/window.mm wx/gtk/bmpcbox.h wx/gtk/calctrl.h wx/gtk/dataview.h + wx/gtk/dvrenderer.h + wx/gtk/dvrenderers.h wx/gtk/hyperlink.h wx/gtk/infobar.h diff --git a/build/msw/wx_adv.dsp b/build/msw/wx_adv.dsp index fa36d2fb32..1a2bc5ae71 100644 --- a/build/msw/wx_adv.dsp +++ b/build/msw/wx_adv.dsp @@ -858,6 +858,14 @@ SOURCE=..\..\include\wx\generic\datectrl.h # End 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 # End Source File # Begin Source File @@ -946,6 +954,10 @@ SOURCE=..\..\include\wx\dcbuffer.h # End Source File # Begin Source File +SOURCE=..\..\include\wx\dvrenderers.h +# End Source File +# Begin Source File + SOURCE=..\..\include\wx\editlbox.h # End Source File # Begin Source File diff --git a/build/msw/wx_core.dsp b/build/msw/wx_core.dsp index edff22967e..991b462004 100644 --- a/build/msw/wx_core.dsp +++ b/build/msw/wx_core.dsp @@ -5275,6 +5275,14 @@ SOURCE=..\..\include\wx\generic\dragimgg.h # End 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 # End Source File # Begin Source File @@ -5927,6 +5935,10 @@ SOURCE=..\..\include\wx\dragimag.h # End Source File # Begin Source File +SOURCE=..\..\include\wx\dvrenderers.h +# End Source File +# Begin Source File + SOURCE=..\..\include\wx\editlbox.h # End Source File # Begin Source File diff --git a/build/msw/wx_vc7_adv.vcproj b/build/msw/wx_vc7_adv.vcproj index ef4603bbb0..5d26bd763e 100644 --- a/build/msw/wx_vc7_adv.vcproj +++ b/build/msw/wx_vc7_adv.vcproj @@ -982,6 +982,12 @@ RelativePath="..\..\include\wx\generic\datectrl.h"> + + + + + + + + + + + + + + + + @@ -1417,6 +1425,10 @@ > + + diff --git a/build/msw/wx_vc8_core.vcproj b/build/msw/wx_vc8_core.vcproj index ce6040a55a..8e168f0ebf 100644 --- a/build/msw/wx_vc8_core.vcproj +++ b/build/msw/wx_vc8_core.vcproj @@ -6113,6 +6113,14 @@ > + + + + @@ -6768,6 +6776,10 @@ > + + diff --git a/build/msw/wx_vc9_adv.vcproj b/build/msw/wx_vc9_adv.vcproj index 05ab959d7b..a12393ae07 100644 --- a/build/msw/wx_vc9_adv.vcproj +++ b/build/msw/wx_vc9_adv.vcproj @@ -1324,6 +1324,14 @@ > + + + + @@ -1413,6 +1421,10 @@ > + + diff --git a/build/msw/wx_vc9_core.vcproj b/build/msw/wx_vc9_core.vcproj index f7fecff887..c6f961fc0b 100644 --- a/build/msw/wx_vc9_core.vcproj +++ b/build/msw/wx_vc9_core.vcproj @@ -6109,6 +6109,14 @@ > + + + + @@ -6764,6 +6772,10 @@ > + + diff --git a/include/wx/dataview.h b/include/wx/dataview.h index 66ef3ea532..fd2ec0b4d7 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -32,6 +32,14 @@ class WXDLLIMPEXP_FWD_CORE wxImageList; #define wxHAS_GENERIC_DATAVIEWCTRL #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 // ---------------------------------------------------------------------------- @@ -436,134 +444,11 @@ private: DECLARE_EVENT_TABLE() }; -// --------------------------------------------------------- -// 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 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); -} +// ---------------------------------------------------------------------------- +// wxDataViewRenderer and related classes +// ---------------------------------------------------------------------------- -DECLARE_VARIANT_OBJECT_EXPORTED(wxDataViewIconText, WXDLLIMPEXP_ADV) +#include "wx/dvrenderers.h" // --------------------------------------------------------- // wxDataViewColumnBase @@ -998,12 +883,6 @@ typedef void (wxEvtHandler::*wxDataViewEventFunction)(wxDataViewEvent&); #define EVT_DATAVIEW_ITEM_DROP(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_DROP, id, fn) #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" #elif defined(__WXGTK20__) #include "wx/gtk/dataview.h" @@ -1013,60 +892,6 @@ typedef void (wxEvtHandler::*wxDataViewEventFunction)(wxDataViewEvent&); #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 - -// this class is obsolete, its functionality was merged in -// wxDataViewTextRenderer itself now, don't use it any more -#define wxDataViewTextRendererAttr wxDataViewTextRenderer - //----------------------------------------------------------------------------- // wxDataViewListStore //----------------------------------------------------------------------------- diff --git a/include/wx/dvrenderers.h b/include/wx/dvrenderers.h new file mode 100644 index 0000000000..94a4330dcb --- /dev/null +++ b/include/wx/dvrenderers.h @@ -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 +// 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 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_ + diff --git a/include/wx/generic/dataview.h b/include/wx/generic/dataview.h index 23d6fe531c..d8b141f0f9 100644 --- a/include/wx/generic/dataview.h +++ b/include/wx/generic/dataview.h @@ -18,326 +18,9 @@ #include "wx/scrolwin.h" #include "wx/icon.h" -// --------------------------------------------------------- -// classes -// --------------------------------------------------------- - -class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl; class WXDLLIMPEXP_FWD_ADV wxDataViewMainWindow; 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 // --------------------------------------------------------- diff --git a/include/wx/generic/dvrenderer.h b/include/wx/generic/dvrenderer.h new file mode 100644 index 0000000000..6726b0fef3 --- /dev/null +++ b/include/wx/generic/dvrenderer.h @@ -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 +// 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 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_ + diff --git a/include/wx/generic/dvrenderers.h b/include/wx/generic/dvrenderers.h new file mode 100644 index 0000000000..61592258ca --- /dev/null +++ b/include/wx/generic/dvrenderers.h @@ -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 +// 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_ + diff --git a/include/wx/gtk/dataview.h b/include/wx/gtk/dataview.h index 589da74a9a..e01b0ece10 100644 --- a/include/wx/gtk/dataview.h +++ b/include/wx/gtk/dataview.h @@ -12,309 +12,8 @@ #include "wx/list.h" -// --------------------------------------------------------- -// classes -// --------------------------------------------------------- - -class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl; 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 // --------------------------------------------------------- diff --git a/include/wx/gtk/dvrenderer.h b/include/wx/gtk/dvrenderer.h new file mode 100644 index 0000000000..9513104c1c --- /dev/null +++ b/include/wx/gtk/dvrenderer.h @@ -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 +// 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_ + diff --git a/include/wx/gtk/dvrenderers.h b/include/wx/gtk/dvrenderers.h new file mode 100644 index 0000000000..667de363b9 --- /dev/null +++ b/include/wx/gtk/dvrenderers.h @@ -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 +// 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_ + diff --git a/include/wx/osx/dataview.h b/include/wx/osx/dataview.h index c7f9433b68..3aaabd5a76 100644 --- a/include/wx/osx/dataview.h +++ b/include/wx/osx/dataview.h @@ -1,4 +1,3 @@ - ///////////////////////////////////////////////////////////////////////////// // Name: wx/osx/dataview.h // Purpose: wxDataViewCtrl native implementation header for OSX @@ -19,356 +18,8 @@ // Class declarations to mask native types // -------------------------------------------------------- class wxDataViewColumnNativeData; // class storing environment dependent data for the native implementation -class wxDataViewRendererNativeData; // class storing environment dependent data for the native renderer class wxDataViewWidgetImpl; // class used as a common interface for carbon and cocoa implementation -// --------------------------------------------------------- -// wxDataViewRenderer -// --------------------------------------------------------- -class WXDLLIMPEXP_ADV wxDataViewRenderer : public wxDataViewRendererBase -{ -public: -// -// constructors / destructor -// - wxDataViewRenderer(wxString const& varianttype, wxDataViewCellMode mode=wxDATAVIEW_CELL_INERT, int align=wxDVR_DEFAULT_ALIGNMENT); - - virtual ~wxDataViewRenderer(); - -// -// 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 // --------------------------------------------------------- diff --git a/include/wx/osx/dvrenderer.h b/include/wx/osx/dvrenderer.h new file mode 100644 index 0000000000..cbfe4e28e0 --- /dev/null +++ b/include/wx/osx/dvrenderer.h @@ -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 +// 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_ + diff --git a/include/wx/osx/dvrenderers.h b/include/wx/osx/dvrenderers.h new file mode 100644 index 0000000000..b25ca48e5a --- /dev/null +++ b/include/wx/osx/dvrenderers.h @@ -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 +// 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_ + diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 04924b89dd..fcfbbd77fc 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -607,18 +607,54 @@ IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer, wxDataViewRendererBase) wxDataViewRenderer::wxDataViewRenderer( const wxString &varianttype, wxDataViewCellMode mode, int align) : - wxDataViewRendererBase( varianttype, mode, align ) + wxDataViewCustomRendererBase( varianttype, mode, align ) { - m_dc = NULL; m_align = align; m_mode = mode; m_ellipsizeMode = wxELLIPSIZE_MIDDLE; + m_dc = NULL; } 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 @@ -669,63 +705,14 @@ wxDataViewRenderer::RenderWithAttr(wxDC& dc, 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 -wxDataViewCustomRenderer::RenderText(wxDC& dc, - const wxRect& rect, - int align, - const wxString& text, - const wxDataViewItemAttr *attr, - int state, - int xoffset) +wxDataViewRenderer::RenderText(wxDC& dc, + const wxRect& rect, + int align, + const wxString& text, + const wxDataViewItemAttr *attr, + int state, + int xoffset) { // override custom foreground with the standard one for the selected items // because we currently don't allow changing the selection background and @@ -774,15 +761,27 @@ wxDataViewCustomRenderer::RenderText(wxDC& dc, rectText, align); } +// --------------------------------------------------------- +// wxDataViewCustomRenderer +// --------------------------------------------------------- + +IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer, wxDataViewRenderer) + +wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString &varianttype, + wxDataViewCellMode mode, int align ) : + wxDataViewRenderer( varianttype, mode, align ) +{ +} + // --------------------------------------------------------- // wxDataViewTextRenderer // --------------------------------------------------------- -IMPLEMENT_CLASS(wxDataViewTextRenderer, wxDataViewCustomRenderer) +IMPLEMENT_CLASS(wxDataViewTextRenderer, wxDataViewRenderer) wxDataViewTextRenderer::wxDataViewTextRenderer( const wxString &varianttype, wxDataViewCellMode mode, int align ) : - wxDataViewCustomRenderer( varianttype, mode, align ) + wxDataViewRenderer( varianttype, mode, align ) { } @@ -847,11 +846,11 @@ wxSize wxDataViewTextRenderer::GetSize() const // wxDataViewBitmapRenderer // --------------------------------------------------------- -IMPLEMENT_CLASS(wxDataViewBitmapRenderer, wxDataViewCustomRenderer) +IMPLEMENT_CLASS(wxDataViewBitmapRenderer, wxDataViewRenderer) wxDataViewBitmapRenderer::wxDataViewBitmapRenderer( const wxString &varianttype, wxDataViewCellMode mode, int align ) : - wxDataViewCustomRenderer( varianttype, mode, align ) + wxDataViewRenderer( varianttype, mode, align ) { } @@ -894,11 +893,11 @@ wxSize wxDataViewBitmapRenderer::GetSize() const // wxDataViewToggleRenderer // --------------------------------------------------------- -IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer, wxDataViewCustomRenderer) +IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer, wxDataViewRenderer) wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString &varianttype, wxDataViewCellMode mode, int align ) : - wxDataViewCustomRenderer( varianttype, mode, align ) + wxDataViewRenderer( varianttype, mode, align ) { m_toggle = false; } @@ -951,11 +950,11 @@ wxSize wxDataViewToggleRenderer::GetSize() const // wxDataViewProgressRenderer // --------------------------------------------------------- -IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer, wxDataViewCustomRenderer) +IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer, wxDataViewRenderer) wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString &label, const wxString &varianttype, wxDataViewCellMode mode, int align ) : - wxDataViewCustomRenderer( varianttype, mode, align ) + wxDataViewRenderer( varianttype, mode, align ) { m_label = label; m_value = 0; @@ -1057,11 +1056,11 @@ void wxDataViewDateRendererPopupTransient::OnCalendar( wxCalendarEvent &event ) #endif // wxUSE_DATE_RENDERER_POPUP -IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer, wxDataViewCustomRenderer) +IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer, wxDataViewRenderer) wxDataViewDateRenderer::wxDataViewDateRenderer( const wxString &varianttype, 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 // --------------------------------------------------------- -IMPLEMENT_CLASS(wxDataViewIconTextRenderer, wxDataViewCustomRenderer) +IMPLEMENT_CLASS(wxDataViewIconTextRenderer, wxDataViewRenderer) wxDataViewIconTextRenderer::wxDataViewIconTextRenderer( const wxString &varianttype, wxDataViewCellMode mode, int align ) : - wxDataViewCustomRenderer( varianttype, mode, align ) + wxDataViewRenderer( varianttype, mode, align ) { SetMode(mode); SetAlignment(align); @@ -3665,12 +3664,15 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event ) { if ((!ignore_other_columns) && (cell->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE)) { - wxVariant value; - model->GetValue( value, item, col->GetModelColumn() ); - cell->SetValue( value ); - wxRect cell_rect( xpos, GetLineStart( current ), - col->GetWidth(), GetLineHeight( current ) ); - cell->Activate( cell_rect, model, item, col->GetModelColumn() ); + if ( wxDataViewCustomRenderer *custom = cell->WXGetAsCustom() ) + { + wxVariant value; + model->GetValue( value, item, col->GetModelColumn() ); + custom->SetValue( value ); + wxRect cell_rect( xpos, GetLineStart( current ), + col->GetWidth(), GetLineHeight( current ) ); + custom->Activate( cell_rect, model, item, col->GetModelColumn() ); + } } else { @@ -3839,14 +3841,17 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event ) // Call LeftClick after everything else as under GTK+ if (cell->GetMode() & wxDATAVIEW_CELL_ACTIVATABLE) { - // notify cell about right click - wxVariant value; - model->GetValue( value, item, col->GetModelColumn() ); - cell->SetValue( value ); - wxRect cell_rect( xpos, GetLineStart( current ), - col->GetWidth(), GetLineHeight( current ) ); - /* ignore ret */ cell->LeftClick( event.GetPosition(), cell_rect, - model, item, col->GetModelColumn()); + if ( wxDataViewCustomRenderer *custom = cell->WXGetAsCustom() ) + { + // notify cell about click + wxVariant value; + model->GetValue( value, item, col->GetModelColumn() ); + custom->SetValue( value ); + wxRect cell_rect( xpos, GetLineStart( current ), + col->GetWidth(), GetLineHeight( current ) ); + /* ignore ret */ custom->LeftClick( event.GetPosition(), cell_rect, + model, item, col->GetModelColumn()); + } } } } diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index a35bbbd9f8..cf0ab2efeb 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -2030,9 +2030,10 @@ public: IMPLEMENT_CLASS(wxDataViewCustomRenderer, wxDataViewRenderer) wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString &varianttype, - wxDataViewCellMode mode, int align, - bool no_init ) : - wxDataViewRenderer( varianttype, mode, align ) + wxDataViewCellMode mode, + int align, + bool no_init ) + : wxDataViewCustomRendererBase( varianttype, mode, align ) { m_dc = NULL; m_text_renderer = NULL; diff --git a/src/osx/carbon/dataview.cpp b/src/osx/carbon/dataview.cpp index 2e19bcd1e1..5abd1ecd48 100644 --- a/src/osx/carbon/dataview.cpp +++ b/src/osx/carbon/dataview.cpp @@ -2305,7 +2305,9 @@ IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer,wxDataViewRendererBase) // wxDataViewCustomRenderer // --------------------------------------------------------- wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align) - :wxDataViewRenderer(varianttype,mode,align), m_editorCtrlPtr(NULL), m_DCPtr(NULL) + :wxDataViewCustomRendererBase(varianttype,mode,align), + m_editorCtrlPtr(NULL), + m_DCPtr(NULL) { SetNativeData(new wxDataViewRendererNativeData(kDataBrowserCustomType)); } diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index 955b7bb1cb..3951253a5c 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -2389,7 +2389,7 @@ IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer,wxDataViewRendererBase) wxDataViewCustomRenderer::wxDataViewCustomRenderer(const wxString& varianttype, wxDataViewCellMode mode, int align) - : wxDataViewRenderer(varianttype, mode, align), + : wxDataViewCustomRendererBase(varianttype, mode, align), m_editorCtrlPtr(NULL), m_DCPtr(NULL) { @@ -2486,7 +2486,8 @@ IMPLEMENT_CLASS(wxDataViewBitmapRenderer,wxDataViewRenderer) wxDataViewChoiceRenderer::wxDataViewChoiceRenderer(const wxArrayString& choices, wxDataViewCellMode mode, int alignment) - : wxDataViewRenderer(wxT("string"),mode,alignment), m_Choices(choices) + : wxDataViewRenderer(wxT("string"), mode, alignment), + m_choices(choices) { NSPopUpButtonCell* cell; -- 2.45.2