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