]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/carbon/listctrl.h
Added wxDataViewBitmapCell
[wxWidgets.git] / include / wx / mac / carbon / listctrl.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: listctrl.h
3 // Purpose: wxListCtrl class
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_LISTCTRL_H_
13 #define _WX_LISTCTRL_H_
14
15 #include "wx/control.h"
16 #include "wx/event.h"
17 #include "wx/imaglist.h"
18 #include "wx/generic/listctrl.h"
19
20 class wxMacDataBrowserListCtrlControl;
21 class wxMacListControl;
22
23 // type of compare function for wxListCtrl sort operation
24 typedef int (*wxListCtrlCompare)(long item1, long item2, long sortData);
25
26 class WXDLLEXPORT wxListCtrl: public wxControl
27 {
28 DECLARE_DYNAMIC_CLASS(wxListCtrl)
29 public:
30 /*
31 * Public interface
32 */
33
34 wxListCtrl() { Init(); }
35
36 wxListCtrl(wxWindow *parent,
37 wxWindowID id = wxID_ANY,
38 const wxPoint& pos = wxDefaultPosition,
39 const wxSize& size = wxDefaultSize,
40 long style = wxLC_ICON,
41 const wxValidator& validator = wxDefaultValidator,
42 const wxString& name = wxListCtrlNameStr)
43 {
44 Init();
45
46 Create(parent, id, pos, size, style, validator, name);
47 }
48
49 virtual ~wxListCtrl();
50
51 bool Create(wxWindow *parent,
52 wxWindowID id = wxID_ANY,
53 const wxPoint& pos = wxDefaultPosition,
54 const wxSize& size = wxDefaultSize,
55 long style = wxLC_ICON,
56 const wxValidator& validator = wxDefaultValidator,
57 const wxString& name = wxListCtrlNameStr);
58
59 // Attributes
60 ////////////////////////////////////////////////////////////////////////////
61
62 // Gets information about this column
63 bool GetColumn(int col, wxListItem& item) const;
64
65 // Sets information about this column
66 // TODO: NOT const to be compatible with wxGenericListCtrl API
67 bool SetColumn(int col, wxListItem& item) ;
68
69 // Gets the column width
70 int GetColumnWidth(int col) const;
71
72 // Sets the column width
73 bool SetColumnWidth(int col, int width) ;
74
75 // Gets the number of items that can fit vertically in the
76 // visible area of the list control (list or report view)
77 // or the total number of items in the list control (icon
78 // or small icon view)
79 int GetCountPerPage() const;
80
81 // Gets the edit control for editing labels.
82 wxTextCtrl* GetEditControl() const;
83
84 // Gets information about the item
85 bool GetItem(wxListItem& info) const ;
86
87 // Sets information about the item
88 bool SetItem(wxListItem& info) ;
89
90 // Sets a string field at a particular column
91 long SetItem(long index, int col, const wxString& label, int imageId = -1);
92
93 // Gets the item state
94 int GetItemState(long item, long stateMask) const ;
95
96 // Sets the item state
97 bool SetItemState(long item, long state, long stateMask) ;
98
99 void AssignImageList(wxImageList *imageList, int which);
100
101 // Sets the item image
102 bool SetItemImage(long item, int image, int selImage = -1) ;
103 bool SetItemColumnImage(long item, long column, int image);
104
105 // Gets the item text
106 wxString GetItemText(long item) const ;
107
108 // Sets the item text
109 void SetItemText(long item, const wxString& str) ;
110
111 void SetItemTextColour(long item, const wxColour& colour) ;
112 wxColour GetItemTextColour(long item) const;
113
114 void SetItemBackgroundColour(long item, const wxColour& colour) ;
115 wxColour GetItemBackgroundColour(long item) const;
116
117 void SetItemFont( long item, const wxFont &f);
118 wxFont GetItemFont( long item ) const;
119
120 // Gets the item data
121 long GetItemData(long item) const ;
122
123 // Sets the item data
124 bool SetItemData(long item, long data) ;
125
126 // Gets the item rectangle
127 bool GetItemRect(long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS) const ;
128
129 // Gets the item position
130 bool GetItemPosition(long item, wxPoint& pos) const ;
131
132 // Sets the item position
133 bool SetItemPosition(long item, const wxPoint& pos) ;
134
135 // Gets the number of items in the list control
136 int GetItemCount() const;
137
138 // Gets the number of columns in the list control
139 int GetColumnCount() const;
140
141 void SetItemSpacing( int spacing, bool isSmall = false );
142 wxSize GetItemSpacing() const;
143
144 // Gets the number of selected items in the list control
145 int GetSelectedItemCount() const;
146
147 wxRect GetViewRect() const;
148
149 // Gets the text colour of the listview
150 wxColour GetTextColour() const;
151
152 // Sets the text colour of the listview
153 void SetTextColour(const wxColour& col);
154
155 // Gets the index of the topmost visible item when in
156 // list or report view
157 long GetTopItem() const ;
158
159 // are we in report mode?
160 bool InReportView() const { return HasFlag(wxLC_REPORT); }
161
162 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL); }
163
164 // Add or remove a single window style
165 void SetSingleStyle(long style, bool add = true) ;
166
167 // Set the whole window style
168 void SetWindowStyleFlag(long style) ;
169
170 // Searches for an item, starting from 'item'.
171 // item can be -1 to find the first item that matches the
172 // specified flags.
173 // Returns the item or -1 if unsuccessful.
174 long GetNextItem(long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE) const ;
175
176 // Implementation: converts wxWidgets style to MSW style.
177 // Can be a single style flag or a bit list.
178 // oldStyle is 'normalised' so that it doesn't contain
179 // conflicting styles.
180 long ConvertToMSWStyle(long& oldStyle, long style) const;
181
182 // Gets one of the three image lists
183 wxImageList *GetImageList(int which) const ;
184
185 // Sets the image list
186 // N.B. There's a quirk in the Win95 list view implementation.
187 // If in wxLC_LIST mode, it'll *still* display images by the labels if
188 // there's a small-icon image list set for the control - even though you
189 // haven't specified wxLIST_MASK_IMAGE when inserting.
190 // So you have to set a NULL small-icon image list to be sure that
191 // the wxLC_LIST mode works without icons. Of course, you may want icons...
192 void SetImageList(wxImageList *imageList, int which) ;
193
194 // Operations
195 ////////////////////////////////////////////////////////////////////////////
196
197 // Arranges the items
198 bool Arrange(int flag = wxLIST_ALIGN_DEFAULT);
199
200 // Deletes an item
201 bool DeleteItem(long item);
202
203 // Deletes all items
204 bool DeleteAllItems() ;
205
206 // Deletes a column
207 bool DeleteColumn(int col);
208
209 // Deletes all columns
210 bool DeleteAllColumns();
211
212 // Clears items, and columns if there are any.
213 void ClearAll();
214
215 // Edit the label
216 wxTextCtrl* EditLabel(long item, wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl));
217
218 // End label editing, optionally cancelling the edit
219 bool EndEditLabel(bool cancel);
220
221 // Ensures this item is visible
222 bool EnsureVisible(long item) ;
223
224 // Find an item whose label matches this string, starting from the item after 'start'
225 // or the beginning if 'start' is -1.
226 long FindItem(long start, const wxString& str, bool partial = false);
227
228 // Find an item whose data matches this data, starting from the item after 'start'
229 // or the beginning if 'start' is -1.
230 long FindItem(long start, long data);
231
232 // Find an item nearest this position in the specified direction, starting from
233 // the item after 'start' or the beginning if 'start' is -1.
234 long FindItem(long start, const wxPoint& pt, int direction);
235
236 // Determines which item (if any) is at the specified point,
237 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
238 // Request the subitem number as well at the given coordinate.
239 long HitTest(const wxPoint& point, int& flags, long* ptrSubItem = NULL) const;
240
241 // Inserts an item, returning the index of the new item if successful,
242 // -1 otherwise.
243 // TOD: Should also have some further convenience functions
244 // which don't require setting a wxListItem object
245 long InsertItem(wxListItem& info);
246
247 // Insert a string item
248 long InsertItem(long index, const wxString& label);
249
250 // Insert an image item
251 long InsertItem(long index, int imageIndex);
252
253 // Insert an image/string item
254 long InsertItem(long index, const wxString& label, int imageIndex);
255
256 // For list view mode (only), inserts a column.
257 long InsertColumn(long col, wxListItem& info);
258
259 long InsertColumn(long col, const wxString& heading, int format = wxLIST_FORMAT_LEFT,
260 int width = -1);
261
262 // Scrolls the list control. If in icon, small icon or report view mode,
263 // x specifies the number of pixels to scroll. If in list view mode, x
264 // specifies the number of columns to scroll.
265 // If in icon, small icon or list view mode, y specifies the number of pixels
266 // to scroll. If in report view mode, y specifies the number of lines to scroll.
267 bool ScrollList(int dx, int dy);
268
269 // Sort items.
270
271 // fn is a function which takes 3 long arguments: item1, item2, data.
272 // item1 is the long data associated with a first item (NOT the index).
273 // item2 is the long data associated with a second item (NOT the index).
274 // data is the same value as passed to SortItems.
275 // The return value is a negative number if the first item should precede the second
276 // item, a positive number of the second item should precede the first,
277 // or zero if the two items are equivalent.
278
279 // data is arbitrary data to be passed to the sort function.
280 bool SortItems(wxListCtrlCompare fn, long data);
281
282 wxMacListControl* GetPeer() const;
283
284 // these functions are only used for virtual list view controls, i.e. the
285 // ones with wxLC_VIRTUAL style
286
287 void SetItemCount(long count);
288 void RefreshItem(long item);
289 void RefreshItems(long itemFrom, long itemTo);
290
291 // return the text for the given column of the given item
292 virtual wxString OnGetItemText(long item, long column) const;
293
294 // return the icon for the given item. In report view, OnGetItemImage will
295 // only be called for the first column. See OnGetItemColumnImage for
296 // details.
297 virtual int OnGetItemImage(long item) const;
298
299 // return the icon for the given item and column.
300 virtual int OnGetItemColumnImage(long item, long column) const;
301
302 // return the attribute for the item (may return NULL if none)
303 virtual wxListItemAttr *OnGetItemAttr(long item) const;
304
305 /* Why should we need this function? Leave for now.
306 * We might need it because item data may have changed,
307 * but the display needs refreshing (in string callback mode)
308 // Updates an item. If the list control has the wxLI_AUTO_ARRANGE style,
309 // the items will be rearranged.
310 bool Update(long item);
311 */
312
313 void Command(wxCommandEvent& event) { ProcessCommand(event); };
314
315 protected:
316 // overrides needed for pimpl approach
317 virtual void DoSetSize(int x, int y,
318 int width, int height,
319 int sizeFlags = wxSIZE_AUTO);
320
321 // common part of all ctors
322 void Init();
323
324 wxGenericListCtrl* m_genericImpl; // allow use of the generic impl.
325 wxMacDataBrowserListCtrlControl* m_dbImpl;
326
327 wxTextCtrl* m_textCtrl; // The control used for editing a label
328 wxImageList * m_imageListNormal; // The image list for normal icons
329 wxImageList * m_imageListSmall; // The image list for small icons
330 wxImageList * m_imageListState; // The image list state icons (not implemented yet)
331
332 // keep track of whether or not we should delete the image list ourselves.
333 bool m_ownsImageListNormal,
334 m_ownsImageListSmall,
335 m_ownsImageListState;
336
337 long m_baseStyle; // Basic Windows style flags, for recreation purposes
338 wxStringList m_stringPool; // Pool of 3 strings to satisfy Windows callback
339 // requirements
340 int m_colCount; // Windows doesn't have GetColumnCount so must
341 // keep track of inserted/deleted columns
342
343 int m_count; // for virtual lists, store item count
344 };
345
346 typedef void (wxEvtHandler::*wxListEventFunction)(wxListEvent&);
347
348 #endif
349 // _WX_LISTCTRL_H_