]>
Commit | Line | Data |
---|---|---|
e86edab0 RR |
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 | ||
5c6eb3a8 SC |
13 | #ifdef __WXMAC_CLASSIC__ |
14 | # error "Native wxDataViewCtrl for classic environment not defined. Please use generic control." | |
5c6eb3a8 | 15 | #endif |
e86edab0 RR |
16 | |
17 | // -------------------------------------------------------- | |
18 | // Class declarations to mask native types | |
19 | // -------------------------------------------------------- | |
20 | class wxDataViewColumnNativeData; // class storing environment dependent data for the native implementation | |
e86edab0 RR |
21 | class wxDataViewWidgetImpl; // class used as a common interface for carbon and cocoa implementation |
22 | ||
e86edab0 RR |
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); | |
de40d736 | 43 | virtual ~wxDataViewColumn(); |
e86edab0 RR |
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; } | |
d831e2db | 51 | virtual int GetWidth() const; |
e86edab0 RR |
52 | virtual bool IsSortOrderAscending() const { return m_ascending; } |
53 | virtual bool IsSortKey() const; | |
f6cb92b8 | 54 | virtual bool IsHidden() const; |
e86edab0 RR |
55 | |
56 | virtual void SetAlignment (wxAlignment align); | |
57 | virtual void SetBitmap (wxBitmap const& bitmap); | |
58 | virtual void SetFlags (int flags) { SetIndividualFlags(flags); } | |
f6cb92b8 | 59 | virtual void SetHidden (bool hidden); |
e86edab0 RR |
60 | virtual void SetMaxWidth (int maxWidth); |
61 | virtual void SetMinWidth (int minWidth); | |
62 | virtual void SetReorderable(bool reorderable); | |
63 | virtual void SetResizeable (bool resizeable); | |
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 | |
de40d736 | 71 | wxDataViewColumnNativeData* GetNativeData() const |
e86edab0 | 72 | { |
de40d736 | 73 | return m_NativeDataPtr; |
e86edab0 | 74 | } |
03647350 | 75 | |
e86edab0 | 76 | void SetNativeData(wxDataViewColumnNativeData* newNativeDataPtr); // class takes ownership of pointer |
d831e2db VZ |
77 | int GetWidthVariable() const |
78 | { | |
79 | return m_width; | |
80 | } | |
e86edab0 RR |
81 | void SetWidthVariable(int NewWidth) |
82 | { | |
83 | m_width = NewWidth; | |
84 | } | |
8ba01d35 RR |
85 | void SetSortOrderVariable(bool NewOrder) |
86 | { | |
87 | m_ascending = NewOrder; | |
88 | } | |
e86edab0 RR |
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_width = width >= 0 ? width : wxDVC_DEFAULT_WIDTH; | |
99 | m_alignment = align; | |
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 | { | |
de40d736 | 130 | Init(); |
e86edab0 RR |
131 | } |
132 | wxDataViewCtrl(wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, | |
133 | const wxValidator& validator = wxDefaultValidator) | |
134 | { | |
de40d736 VZ |
135 | Init(); |
136 | Create(parent, id, pos, size, style, validator ); | |
e86edab0 RR |
137 | } |
138 | ||
139 | ~wxDataViewCtrl(); | |
140 | ||
141 | // explicit control creation | |
142 | bool Create(wxWindow *parent, wxWindowID id, const wxPoint& pos=wxDefaultPosition, const wxSize& size=wxDefaultSize, long style=0, | |
143 | const wxValidator& validator=wxDefaultValidator); | |
144 | ||
145 | virtual wxControl* GetMainWindow() // not used for the native implementation | |
146 | { | |
147 | return this; | |
148 | } | |
149 | ||
150 | // inherited methods from wxDataViewCtrlBase: | |
151 | virtual bool AssociateModel(wxDataViewModel* model); | |
152 | ||
153 | virtual bool AppendColumn (wxDataViewColumn* columnPtr); | |
de40d736 | 154 | virtual bool ClearColumns (); |
e86edab0 RR |
155 | virtual bool DeleteColumn (wxDataViewColumn* columnPtr); |
156 | virtual wxDataViewColumn* GetColumn (unsigned int pos) const; | |
de40d736 | 157 | virtual unsigned int GetColumnCount () const; |
e86edab0 | 158 | virtual int GetColumnPosition(const wxDataViewColumn* columnPtr) const; |
de40d736 | 159 | virtual wxDataViewColumn* GetSortingColumn () const; |
e86edab0 RR |
160 | virtual bool InsertColumn (unsigned int pos, wxDataViewColumn *col); |
161 | virtual bool PrependColumn (wxDataViewColumn* columnPtr); | |
162 | ||
163 | virtual void Collapse( const wxDataViewItem& item); | |
164 | virtual void EnsureVisible(const wxDataViewItem& item, const wxDataViewColumn* columnPtr=NULL); | |
165 | virtual void Expand(const wxDataViewItem& item); | |
166 | virtual bool IsExpanded(const wxDataViewItem & item) const; | |
167 | ||
168 | ||
169 | virtual unsigned int GetCount() const; | |
170 | virtual wxRect GetItemRect(const wxDataViewItem& item, const wxDataViewColumn* columnPtr) const; | |
171 | virtual wxDataViewItem GetSelection() const; | |
172 | virtual int GetSelections(wxDataViewItemArray& sel) const; | |
173 | ||
174 | virtual void HitTest(const wxPoint& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const; | |
175 | ||
176 | virtual bool IsSelected(const wxDataViewItem& item) const; | |
177 | ||
178 | virtual void SelectAll(); | |
179 | virtual void Select(const wxDataViewItem& item); | |
180 | virtual void SetSelections(const wxDataViewItemArray& sel); | |
181 | ||
182 | virtual void Unselect(const wxDataViewItem& item); | |
183 | virtual void UnselectAll(); | |
184 | ||
185 | // | |
186 | // implementation | |
187 | // | |
188 | // returns a pointer to the native implementation | |
de40d736 | 189 | wxDataViewWidgetImpl* GetDataViewPeer() const; |
e86edab0 RR |
190 | |
191 | // adds all children of the passed parent to the control; if 'parentItem' is invalid the root(s) is/are added: | |
192 | void AddChildren(wxDataViewItem const& parentItem); | |
193 | ||
194 | // finishes editing of custom items; if no custom item is currently edited the method does nothing | |
de40d736 | 195 | void FinishCustomItemEditing(); |
e86edab0 RR |
196 | |
197 | // returns the n-th pointer to a column; | |
198 | // this method is different from GetColumn(unsigned int pos) because here 'n' is not a position in the control but the n-th | |
199 | // position in the internal list/array of column pointers | |
200 | wxDataViewColumn* GetColumnPtr(size_t n) const | |
201 | { | |
de40d736 | 202 | return m_ColumnPtrs[n]; |
e86edab0 RR |
203 | } |
204 | // returns the current being rendered item of the customized renderer (this item is only valid during editing) | |
205 | wxDataViewItem const& GetCustomRendererItem() const | |
206 | { | |
de40d736 | 207 | return m_CustomRendererItem; |
e86edab0 RR |
208 | } |
209 | // returns a pointer to a customized renderer (this pointer is only valid during editing) | |
210 | wxDataViewCustomRenderer* GetCustomRendererPtr() const | |
211 | { | |
de40d736 | 212 | return m_CustomRendererPtr; |
e86edab0 RR |
213 | } |
214 | ||
215 | // checks if currently a delete process is running | |
216 | bool IsDeleting() const | |
217 | { | |
de40d736 | 218 | return m_Deleting; |
e86edab0 RR |
219 | } |
220 | ||
221 | // with CG, we need to get the context from an kEventControlDraw event | |
222 | // unfortunately, the DataBrowser callbacks don't provide the context | |
223 | // and we need it, so we need to set/remove it before and after draw | |
224 | // events so we can access it in the callbacks. | |
225 | void MacSetDrawingContext(void* context) | |
226 | { | |
de40d736 | 227 | m_cgContext = context; |
e86edab0 RR |
228 | } |
229 | void* MacGetDrawingContext() const | |
230 | { | |
de40d736 | 231 | return m_cgContext; |
e86edab0 RR |
232 | } |
233 | ||
234 | // sets the currently being edited item of the custom renderer | |
235 | void SetCustomRendererItem(wxDataViewItem const& NewItem) | |
236 | { | |
de40d736 | 237 | m_CustomRendererItem = NewItem; |
e86edab0 RR |
238 | } |
239 | // sets the custom renderer | |
240 | void SetCustomRendererPtr(wxDataViewCustomRenderer* NewCustomRendererPtr) | |
241 | { | |
de40d736 | 242 | m_CustomRendererPtr = NewCustomRendererPtr; |
e86edab0 RR |
243 | } |
244 | // sets the flag indicating a deletion process: | |
245 | void SetDeleting(bool deleting) | |
246 | { | |
de40d736 | 247 | m_Deleting = deleting; |
e86edab0 RR |
248 | } |
249 | ||
250 | virtual wxVisualAttributes GetDefaultAttributes() const | |
251 | { | |
252 | return GetClassDefaultAttributes(GetWindowVariant()); | |
253 | } | |
254 | ||
255 | static wxVisualAttributes | |
256 | GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); | |
257 | ||
258 | protected: | |
259 | // inherited methods from wxDataViewCtrlBase | |
260 | virtual void DoSetExpanderColumn(); | |
261 | virtual void DoSetIndent(); | |
262 | ||
ca6de8c0 RR |
263 | virtual wxSize DoGetBestSize() const; |
264 | ||
e86edab0 RR |
265 | // event handling |
266 | void OnSize(wxSizeEvent &event); | |
ca6de8c0 | 267 | void OnMouse(wxMouseEvent &event); |
e86edab0 RR |
268 | |
269 | private: | |
270 | // initializing of local variables: | |
271 | void Init(); | |
272 | ||
273 | // | |
274 | // variables | |
275 | // | |
276 | 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 | |
277 | // after the actual deletion of the item; then, native callback functions/delegates may try to update data of variables that are already deleted; | |
278 | // if this flag is set all native variable update requests will be ignored | |
279 | ||
280 | void* m_cgContext; // pointer to core graphics context | |
281 | ||
282 | wxDataViewCustomRenderer* m_CustomRendererPtr; // pointer to a valid custom renderer while editing; this class does NOT own the pointer | |
283 | ||
284 | wxDataViewItem m_CustomRendererItem; // currently edited item by the customrenderer; it is invalid while not editing a custom item | |
285 | ||
286 | wxDataViewColumnPtrArrayType m_ColumnPtrs; // all column pointers are stored in an array | |
287 | ||
288 | // wxWidget internal stuff: | |
289 | DECLARE_DYNAMIC_CLASS(wxDataViewCtrl) | |
290 | DECLARE_NO_COPY_CLASS(wxDataViewCtrl) | |
291 | DECLARE_EVENT_TABLE() | |
292 | }; | |
293 | ||
294 | #endif // _WX_DATAVIEWCTRL_OSX_H_ | |
295 |