dataview.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/osx/dataview.h
  3. // Purpose: wxDataViewCtrl native implementation header for OSX
  4. // Author:
  5. // Copyright: (c) 2009
  6. // Licence: wxWindows licence
  7. /////////////////////////////////////////////////////////////////////////////
  8. #ifndef _WX_DATAVIEWCTRL_OSX_H_
  9. #define _WX_DATAVIEWCTRL_OSX_H_
  10. #ifdef __WXMAC_CLASSIC__
  11. # error "Native wxDataViewCtrl for classic environment not defined. Please use generic control."
  12. #endif
  13. // --------------------------------------------------------
  14. // Class declarations to mask native types
  15. // --------------------------------------------------------
  16. class wxDataViewColumnNativeData; // class storing environment dependent data for the native implementation
  17. class wxDataViewWidgetImpl; // class used as a common interface for carbon and cocoa implementation
  18. // ---------------------------------------------------------
  19. // wxDataViewColumn
  20. // ---------------------------------------------------------
  21. class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase
  22. {
  23. public:
  24. // constructors / destructor
  25. wxDataViewColumn(const wxString& title,
  26. wxDataViewRenderer* renderer,
  27. unsigned int model_column,
  28. int width = wxDVC_DEFAULT_WIDTH,
  29. wxAlignment align = wxALIGN_CENTER,
  30. int flags = wxDATAVIEW_COL_RESIZABLE);
  31. wxDataViewColumn(const wxBitmap& bitmap,
  32. wxDataViewRenderer* renderer,
  33. unsigned int model_column,
  34. int width = wxDVC_DEFAULT_WIDTH,
  35. wxAlignment align = wxALIGN_CENTER,
  36. int flags = wxDATAVIEW_COL_RESIZABLE);
  37. virtual ~wxDataViewColumn();
  38. // implement wxHeaderColumnBase pure virtual methods
  39. virtual wxAlignment GetAlignment() const { return m_alignment; }
  40. virtual int GetFlags() const { return m_flags; }
  41. virtual int GetMaxWidth() const { return m_maxWidth; }
  42. virtual int GetMinWidth() const { return m_minWidth; }
  43. virtual wxString GetTitle() const { return m_title; }
  44. virtual int GetWidth() const;
  45. virtual bool IsSortOrderAscending() const { return m_ascending; }
  46. virtual bool IsSortKey() const;
  47. virtual bool IsHidden() const;
  48. virtual void SetAlignment (wxAlignment align);
  49. virtual void SetBitmap (wxBitmap const& bitmap);
  50. virtual void SetFlags (int flags) { m_flags = flags; /*SetIndividualFlags(flags); */ }
  51. virtual void SetHidden (bool hidden);
  52. virtual void SetMaxWidth (int maxWidth);
  53. virtual void SetMinWidth (int minWidth);
  54. virtual void SetReorderable(bool reorderable);
  55. virtual void SetResizeable (bool resizable);
  56. virtual void SetSortable (bool sortable);
  57. virtual void SetSortOrder (bool ascending);
  58. virtual void SetTitle (wxString const& title);
  59. virtual void SetWidth (int width);
  60. // implementation only
  61. wxDataViewColumnNativeData* GetNativeData() const
  62. {
  63. return m_NativeDataPtr;
  64. }
  65. void SetNativeData(wxDataViewColumnNativeData* newNativeDataPtr); // class takes ownership of pointer
  66. int GetWidthVariable() const
  67. {
  68. return m_width;
  69. }
  70. void SetWidthVariable(int NewWidth)
  71. {
  72. m_width = NewWidth;
  73. }
  74. void SetSortOrderVariable(bool NewOrder)
  75. {
  76. m_ascending = NewOrder;
  77. }
  78. private:
  79. // common part of all ctors
  80. void InitCommon(int width, wxAlignment align, int flags)
  81. {
  82. m_ascending = true;
  83. m_flags = flags & ~wxDATAVIEW_COL_HIDDEN; // TODO
  84. m_maxWidth = 30000;
  85. m_minWidth = 0;
  86. m_alignment = align;
  87. SetWidth(width);
  88. }
  89. bool m_ascending; // sorting order
  90. int m_flags; // flags for the column
  91. int m_maxWidth; // maximum width for the column
  92. int m_minWidth; // minimum width for the column
  93. int m_width; // column width
  94. wxAlignment m_alignment; // column header alignment
  95. wxDataViewColumnNativeData* m_NativeDataPtr; // storing environment dependent data for the native implementation
  96. wxString m_title; // column title
  97. };
  98. //
  99. // type definitions related to wxDataViewColumn
  100. //
  101. WX_DEFINE_ARRAY(wxDataViewColumn*,wxDataViewColumnPtrArrayType);
  102. // ---------------------------------------------------------
  103. // wxDataViewCtrl
  104. // ---------------------------------------------------------
  105. class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase
  106. {
  107. public:
  108. // Constructors / destructor:
  109. wxDataViewCtrl()
  110. {
  111. Init();
  112. }
  113. wxDataViewCtrl(wxWindow *parent,
  114. wxWindowID winid,
  115. const wxPoint& pos = wxDefaultPosition,
  116. const wxSize& size = wxDefaultSize,
  117. long style = 0,
  118. const wxValidator& validator = wxDefaultValidator,
  119. const wxString& name = wxDataViewCtrlNameStr )
  120. {
  121. Init();
  122. Create(parent, winid, pos, size, style, validator, name);
  123. }
  124. ~wxDataViewCtrl();
  125. bool Create(wxWindow *parent,
  126. wxWindowID winid,
  127. const wxPoint& pos = wxDefaultPosition,
  128. const wxSize& size = wxDefaultSize,
  129. long style = 0,
  130. const wxValidator& validator = wxDefaultValidator,
  131. const wxString& name = wxDataViewCtrlNameStr);
  132. virtual wxWindow* GetMainWindow() // not used for the native implementation
  133. {
  134. return this;
  135. }
  136. // inherited methods from wxDataViewCtrlBase:
  137. virtual bool AssociateModel(wxDataViewModel* model);
  138. virtual bool AppendColumn (wxDataViewColumn* columnPtr);
  139. virtual bool ClearColumns ();
  140. virtual bool DeleteColumn (wxDataViewColumn* columnPtr);
  141. virtual wxDataViewColumn* GetColumn (unsigned int pos) const;
  142. virtual unsigned int GetColumnCount () const;
  143. virtual int GetColumnPosition(const wxDataViewColumn* columnPtr) const;
  144. virtual wxDataViewColumn* GetSortingColumn () const;
  145. virtual bool InsertColumn (unsigned int pos, wxDataViewColumn *col);
  146. virtual bool PrependColumn (wxDataViewColumn* columnPtr);
  147. virtual void Collapse( const wxDataViewItem& item);
  148. virtual void EnsureVisible(const wxDataViewItem& item, const wxDataViewColumn* columnPtr=NULL);
  149. virtual void Expand(const wxDataViewItem& item);
  150. virtual bool IsExpanded(const wxDataViewItem & item) const;
  151. virtual unsigned int GetCount() const;
  152. virtual wxRect GetItemRect(const wxDataViewItem& item,
  153. const wxDataViewColumn* columnPtr = NULL) const;
  154. virtual int GetSelectedItemsCount() const;
  155. virtual int GetSelections(wxDataViewItemArray& sel) const;
  156. virtual void HitTest(const wxPoint& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const;
  157. virtual bool IsSelected(const wxDataViewItem& item) const;
  158. virtual void SelectAll();
  159. virtual void Select(const wxDataViewItem& item);
  160. virtual void SetSelections(const wxDataViewItemArray& sel);
  161. virtual void Unselect(const wxDataViewItem& item);
  162. virtual void UnselectAll();
  163. //
  164. // implementation
  165. //
  166. // returns a pointer to the native implementation
  167. wxDataViewWidgetImpl* GetDataViewPeer() const;
  168. // adds all children of the passed parent to the control; if 'parentItem' is invalid the root(s) is/are added:
  169. void AddChildren(wxDataViewItem const& parentItem);
  170. // finishes editing of custom items; if no custom item is currently edited the method does nothing
  171. void FinishCustomItemEditing();
  172. virtual void EditItem(const wxDataViewItem& item, const wxDataViewColumn *column);
  173. // returns the n-th pointer to a column;
  174. // this method is different from GetColumn(unsigned int pos) because here 'n' is not a position in the control but the n-th
  175. // position in the internal list/array of column pointers
  176. wxDataViewColumn* GetColumnPtr(size_t n) const
  177. {
  178. return m_ColumnPtrs[n];
  179. }
  180. // returns the current being rendered item of the customized renderer (this item is only valid during editing)
  181. wxDataViewItem const& GetCustomRendererItem() const
  182. {
  183. return m_CustomRendererItem;
  184. }
  185. // returns a pointer to a customized renderer (this pointer is only valid during editing)
  186. wxDataViewCustomRenderer* GetCustomRendererPtr() const
  187. {
  188. return m_CustomRendererPtr;
  189. }
  190. // checks if currently a delete process is running
  191. bool IsDeleting() const
  192. {
  193. return m_Deleting;
  194. }
  195. // with CG, we need to get the context from an kEventControlDraw event
  196. // unfortunately, the DataBrowser callbacks don't provide the context
  197. // and we need it, so we need to set/remove it before and after draw
  198. // events so we can access it in the callbacks.
  199. void MacSetDrawingContext(void* context)
  200. {
  201. m_cgContext = context;
  202. }
  203. void* MacGetDrawingContext() const
  204. {
  205. return m_cgContext;
  206. }
  207. // sets the currently being edited item of the custom renderer
  208. void SetCustomRendererItem(wxDataViewItem const& NewItem)
  209. {
  210. m_CustomRendererItem = NewItem;
  211. }
  212. // sets the custom renderer
  213. void SetCustomRendererPtr(wxDataViewCustomRenderer* NewCustomRendererPtr)
  214. {
  215. m_CustomRendererPtr = NewCustomRendererPtr;
  216. }
  217. // sets the flag indicating a deletion process:
  218. void SetDeleting(bool deleting)
  219. {
  220. m_Deleting = deleting;
  221. }
  222. virtual wxDataViewColumn *GetCurrentColumn() const;
  223. virtual wxVisualAttributes GetDefaultAttributes() const
  224. {
  225. return GetClassDefaultAttributes(GetWindowVariant());
  226. }
  227. static wxVisualAttributes
  228. GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
  229. protected:
  230. // inherited methods from wxDataViewCtrlBase
  231. virtual void DoSetExpanderColumn();
  232. virtual void DoSetIndent();
  233. virtual wxSize DoGetBestSize() const;
  234. // event handling
  235. void OnSize(wxSizeEvent &event);
  236. void OnMouse(wxMouseEvent &event);
  237. private:
  238. // initializing of local variables:
  239. void Init();
  240. virtual wxDataViewItem DoGetCurrentItem() const;
  241. virtual void DoSetCurrentItem(const wxDataViewItem& item);
  242. //
  243. // variables
  244. //
  245. bool m_Deleting; // flag indicating if a delete process is running; this flag is necessary because the notifier indicating an item deletion in the model may be called
  246. // after the actual deletion of the item; then, native callback functions/delegates may try to update data of variables that are already deleted;
  247. // if this flag is set all native variable update requests will be ignored
  248. void* m_cgContext; // pointer to core graphics context
  249. wxDataViewCustomRenderer* m_CustomRendererPtr; // pointer to a valid custom renderer while editing; this class does NOT own the pointer
  250. wxDataViewItem m_CustomRendererItem; // currently edited item by the customrenderer; it is invalid while not editing a custom item
  251. wxDataViewColumnPtrArrayType m_ColumnPtrs; // all column pointers are stored in an array
  252. wxDataViewModelNotifier* m_ModelNotifier; // stores the model notifier for the control (does not own the notifier)
  253. // wxWidget internal stuff:
  254. DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
  255. DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
  256. DECLARE_EVENT_TABLE()
  257. };
  258. #endif // _WX_DATAVIEWCTRL_OSX_H_