dvrenderer.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/gtk/dvrenderer.h
  3. // Purpose: wxDataViewRenderer for GTK wxDataViewCtrl implementation
  4. // Author: Robert Roebling, Vadim Zeitlin
  5. // Created: 2009-11-07 (extracted from wx/gtk/dataview.h)
  6. // Copyright: (c) 2006 Robert Roebling
  7. // (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_GTK_DVRENDERER_H_
  11. #define _WX_GTK_DVRENDERER_H_
  12. typedef struct _GtkCellRendererText GtkCellRendererText;
  13. typedef struct _GtkTreeViewColumn GtkTreeViewColumn;
  14. // ----------------------------------------------------------------------------
  15. // wxDataViewRenderer
  16. // ----------------------------------------------------------------------------
  17. class WXDLLIMPEXP_ADV wxDataViewRenderer: public wxDataViewRendererBase
  18. {
  19. public:
  20. wxDataViewRenderer( const wxString &varianttype,
  21. wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
  22. int align = wxDVR_DEFAULT_ALIGNMENT );
  23. virtual void SetMode( wxDataViewCellMode mode );
  24. virtual wxDataViewCellMode GetMode() const;
  25. virtual void SetAlignment( int align );
  26. virtual int GetAlignment() const;
  27. virtual void EnableEllipsize(wxEllipsizeMode mode = wxELLIPSIZE_MIDDLE);
  28. virtual wxEllipsizeMode GetEllipsizeMode() const;
  29. // GTK-specific implementation
  30. // ---------------------------
  31. // pack the GTK cell renderers used by this renderer to the given column
  32. //
  33. // by default only a single m_renderer is used but some renderers use more
  34. // than one GTK cell renderer
  35. virtual void GtkPackIntoColumn(GtkTreeViewColumn *column);
  36. // called when the cell value was edited by user with the new value
  37. //
  38. // it validates the new value and notifies the model about the change by
  39. // calling GtkOnCellChanged() if it was accepted
  40. virtual void GtkOnTextEdited(const char *itempath, const wxString& value);
  41. GtkCellRenderer* GetGtkHandle() { return m_renderer; }
  42. void GtkInitHandlers();
  43. void GtkUpdateAlignment() { GtkApplyAlignment(m_renderer); }
  44. // should be overridden to return true if the renderer supports properties
  45. // corresponding to wxDataViewItemAttr field, see wxGtkTreeCellDataFunc()
  46. // for details
  47. virtual bool GtkSupportsAttrs() const { return false; }
  48. // if GtkSupportsAttrs() returns true, this function will be called to
  49. // effectively set the attribute to use for rendering the next item
  50. //
  51. // it should return true if the attribute had any non-default properties
  52. virtual bool GtkSetAttr(const wxDataViewItemAttr& WXUNUSED(attr))
  53. { return false; }
  54. // these functions are only called if GtkSupportsAttrs() returns true and
  55. // are used to remember whether the renderer currently uses the default
  56. // attributes or if we changed (and not reset them)
  57. bool GtkIsUsingDefaultAttrs() const { return m_usingDefaultAttrs; }
  58. void GtkSetUsingDefaultAttrs(bool def) { m_usingDefaultAttrs = def; }
  59. // return the text renderer used by this renderer for setting text cell
  60. // specific attributes: can return NULL if this renderer doesn't render any
  61. // text
  62. virtual GtkCellRendererText *GtkGetTextRenderer() const { return NULL; }
  63. wxDataViewCellMode GtkGetMode() { return m_mode; }
  64. protected:
  65. virtual void GtkOnCellChanged(const wxVariant& value,
  66. const wxDataViewItem& item,
  67. unsigned col);
  68. // Apply our effective alignment (i.e. m_alignment if specified or the
  69. // associated column alignment by default) to the given renderer.
  70. void GtkApplyAlignment(GtkCellRenderer *renderer);
  71. GtkCellRenderer *m_renderer;
  72. int m_alignment;
  73. wxDataViewCellMode m_mode;
  74. // true if we hadn't changed any visual attributes or restored them since
  75. // doing this
  76. bool m_usingDefaultAttrs;
  77. protected:
  78. DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer)
  79. };
  80. #endif // _WX_GTK_DVRENDERER_H_