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