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