dataview.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/gtk/dataview.h
  3. // Purpose: wxDataViewCtrl GTK+2 implementation header
  4. // Author: Robert Roebling
  5. // Copyright: (c) 1998 Robert Roebling
  6. // Licence: wxWindows licence
  7. /////////////////////////////////////////////////////////////////////////////
  8. #ifndef _WX_GTKDATAVIEWCTRL_H_
  9. #define _WX_GTKDATAVIEWCTRL_H_
  10. #include "wx/list.h"
  11. class WXDLLIMPEXP_FWD_ADV wxDataViewCtrlInternal;
  12. struct _GtkTreePath;
  13. // ---------------------------------------------------------
  14. // wxDataViewColumn
  15. // ---------------------------------------------------------
  16. class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase
  17. {
  18. public:
  19. wxDataViewColumn( const wxString &title, wxDataViewRenderer *renderer,
  20. unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
  21. wxAlignment align = wxALIGN_CENTER,
  22. int flags = wxDATAVIEW_COL_RESIZABLE );
  23. wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *renderer,
  24. unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
  25. wxAlignment align = wxALIGN_CENTER,
  26. int flags = wxDATAVIEW_COL_RESIZABLE );
  27. // setters:
  28. virtual void SetTitle( const wxString &title );
  29. virtual void SetBitmap( const wxBitmap &bitmap );
  30. virtual void SetOwner( wxDataViewCtrl *owner );
  31. virtual void SetAlignment( wxAlignment align );
  32. virtual void SetSortable( bool sortable );
  33. virtual void SetSortOrder( bool ascending );
  34. virtual void SetResizeable( bool resizable );
  35. virtual void SetHidden( bool hidden );
  36. virtual void SetMinWidth( int minWidth );
  37. virtual void SetWidth( int width );
  38. virtual void SetReorderable( bool reorderable );
  39. virtual void SetFlags(int flags) { SetIndividualFlags(flags); }
  40. // getters:
  41. virtual wxString GetTitle() const;
  42. virtual wxAlignment GetAlignment() const;
  43. virtual bool IsSortable() const;
  44. virtual bool IsSortOrderAscending() const;
  45. virtual bool IsSortKey() const;
  46. virtual bool IsResizeable() const;
  47. virtual bool IsHidden() const;
  48. virtual int GetWidth() const;
  49. virtual int GetMinWidth() const;
  50. virtual bool IsReorderable() const;
  51. virtual int GetFlags() const { return GetFromIndividualFlags(); }
  52. // implementation
  53. GtkWidget* GetGtkHandle() const { return m_column; }
  54. private:
  55. // holds the GTK handle
  56. GtkWidget *m_column;
  57. // holds GTK handles for title/bitmap in the header
  58. GtkWidget *m_image;
  59. GtkWidget *m_label;
  60. // delayed connection to mouse events
  61. friend class wxDataViewCtrl;
  62. void OnInternalIdle();
  63. bool m_isConnected;
  64. void Init(wxAlignment align, int flags, int width);
  65. };
  66. WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn, wxDataViewColumnList,
  67. class WXDLLIMPEXP_ADV);
  68. // ---------------------------------------------------------
  69. // wxDataViewCtrl
  70. // ---------------------------------------------------------
  71. class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase
  72. {
  73. public:
  74. wxDataViewCtrl()
  75. {
  76. Init();
  77. }
  78. wxDataViewCtrl( wxWindow *parent, wxWindowID id,
  79. const wxPoint& pos = wxDefaultPosition,
  80. const wxSize& size = wxDefaultSize, long style = 0,
  81. const wxValidator& validator = wxDefaultValidator,
  82. const wxString& name = wxDataViewCtrlNameStr )
  83. {
  84. Init();
  85. Create(parent, id, pos, size, style, validator, name);
  86. }
  87. bool Create(wxWindow *parent, wxWindowID id,
  88. const wxPoint& pos = wxDefaultPosition,
  89. const wxSize& size = wxDefaultSize, long style = 0,
  90. const wxValidator& validator = wxDefaultValidator,
  91. const wxString& name = wxDataViewCtrlNameStr);
  92. virtual ~wxDataViewCtrl();
  93. virtual bool AssociateModel( wxDataViewModel *model );
  94. virtual bool PrependColumn( wxDataViewColumn *col );
  95. virtual bool AppendColumn( wxDataViewColumn *col );
  96. virtual bool InsertColumn( unsigned int pos, wxDataViewColumn *col );
  97. virtual unsigned int GetColumnCount() const;
  98. virtual wxDataViewColumn* GetColumn( unsigned int pos ) const;
  99. virtual bool DeleteColumn( wxDataViewColumn *column );
  100. virtual bool ClearColumns();
  101. virtual int GetColumnPosition( const wxDataViewColumn *column ) const;
  102. virtual wxDataViewColumn *GetSortingColumn() const;
  103. virtual int GetSelectedItemsCount() const;
  104. virtual int GetSelections( wxDataViewItemArray & sel ) const;
  105. virtual void SetSelections( const wxDataViewItemArray & sel );
  106. virtual void Select( const wxDataViewItem & item );
  107. virtual void Unselect( const wxDataViewItem & item );
  108. virtual bool IsSelected( const wxDataViewItem & item ) const;
  109. virtual void SelectAll();
  110. virtual void UnselectAll();
  111. virtual void EnsureVisible( const wxDataViewItem& item,
  112. const wxDataViewColumn *column = NULL );
  113. virtual void HitTest( const wxPoint &point,
  114. wxDataViewItem &item,
  115. wxDataViewColumn *&column ) const;
  116. virtual wxRect GetItemRect( const wxDataViewItem &item,
  117. const wxDataViewColumn *column = NULL ) const;
  118. virtual bool SetRowHeight( int rowHeight );
  119. virtual void EditItem(const wxDataViewItem& item, const wxDataViewColumn *column);
  120. virtual void Expand( const wxDataViewItem & item );
  121. virtual void Collapse( const wxDataViewItem & item );
  122. virtual bool IsExpanded( const wxDataViewItem & item ) const;
  123. virtual bool EnableDragSource( const wxDataFormat &format );
  124. virtual bool EnableDropTarget( const wxDataFormat &format );
  125. virtual wxDataViewColumn *GetCurrentColumn() const;
  126. static wxVisualAttributes
  127. GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
  128. wxWindow *GetMainWindow() { return (wxWindow*) this; }
  129. GtkWidget *GtkGetTreeView() { return m_treeview; }
  130. wxDataViewCtrlInternal* GtkGetInternal() { return m_internal; }
  131. // Convert GTK path to our item. Returned item may be invalid if get_iter()
  132. // failed.
  133. wxDataViewItem GTKPathToItem(struct _GtkTreePath *path) const;
  134. virtual void OnInternalIdle();
  135. int GTKGetUniformRowHeight() const { return m_uniformRowHeight; }
  136. protected:
  137. virtual void DoSetExpanderColumn();
  138. virtual void DoSetIndent();
  139. virtual void DoApplyWidgetStyle(GtkRcStyle *style);
  140. private:
  141. void Init();
  142. virtual wxDataViewItem DoGetCurrentItem() const;
  143. virtual void DoSetCurrentItem(const wxDataViewItem& item);
  144. // Return wxDataViewColumn matching the given GtkTreeViewColumn.
  145. //
  146. // If the input argument is NULL, return NULL too. Otherwise we must find
  147. // the matching column and assert if we didn't.
  148. wxDataViewColumn* FromGTKColumn(GtkTreeViewColumn *gtk_col) const;
  149. friend class wxDataViewCtrlDCImpl;
  150. friend class wxDataViewColumn;
  151. friend class wxDataViewCtrlInternal;
  152. GtkWidget *m_treeview;
  153. wxDataViewCtrlInternal *m_internal;
  154. wxDataViewColumnList m_cols;
  155. wxDataViewItem m_ensureVisibleDefered;
  156. // By default this is set to -1 and the height of the rows is determined by
  157. // GetRect() methods of the renderers but this can be set to a positive
  158. // value to force the height of all rows to the given value.
  159. int m_uniformRowHeight;
  160. virtual void AddChildGTK(wxWindowGTK* child);
  161. void GtkEnableSelectionEvents();
  162. void GtkDisableSelectionEvents();
  163. DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
  164. wxDECLARE_NO_COPY_CLASS(wxDataViewCtrl);
  165. };
  166. #endif // _WX_GTKDATAVIEWCTRL_H_