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