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