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