added virtual listctrl support
[wxWidgets.git] / include / wx / listctrl.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/listctrl.h
3 // Purpose: wxListCtrl class
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 04.12.99
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_LISTCTRL_H_BASE_
13 #define _WX_LISTCTRL_H_BASE_
14
15 #ifdef __GNUG__
16 #pragma interface "listctrlbase.h"
17 #endif
18
19 #if wxUSE_LISTCTRL
20
21 // ----------------------------------------------------------------------------
22 // types
23 // ----------------------------------------------------------------------------
24
25 // type of compare function for wxListCtrl sort operation
26 typedef int (wxCALLBACK *wxListCtrlCompare)(long item1, long item2, long sortData);
27
28 // ----------------------------------------------------------------------------
29 // wxListCtrl constants
30 // ----------------------------------------------------------------------------
31
32 // style flags
33 #define wxLC_VRULES 0x0001
34 #define wxLC_HRULES 0x0002
35 #define wxLC_ICON 0x0004
36 #define wxLC_SMALL_ICON 0x0008
37 #define wxLC_LIST 0x0010
38 #define wxLC_REPORT 0x0020
39 #define wxLC_ALIGN_TOP 0x0040
40 #define wxLC_ALIGN_LEFT 0x0080
41 #define wxLC_AUTOARRANGE 0x0100
42 #define wxLC_VIRTUAL 0x0200
43 #define wxLC_EDIT_LABELS 0x0400
44 #define wxLC_NO_HEADER 0x0800
45 #define wxLC_NO_SORT_HEADER 0x1000
46 #define wxLC_SINGLE_SEL 0x2000
47 #define wxLC_SORT_ASCENDING 0x4000
48 #define wxLC_SORT_DESCENDING 0x8000
49
50 #define wxLC_MASK_TYPE (wxLC_ICON | wxLC_SMALL_ICON | wxLC_LIST | wxLC_REPORT)
51 #define wxLC_MASK_ALIGN (wxLC_ALIGN_TOP | wxLC_ALIGN_LEFT)
52 #define wxLC_MASK_SORT (wxLC_SORT_ASCENDING | wxLC_SORT_DESCENDING)
53
54 // for compatibility only
55 #define wxLC_USER_TEXT wxLC_VIRTUAL
56
57 // Omitted because
58 // (a) too much detail
59 // (b) not enough style flags
60 // (c) not implemented anyhow in the generic version
61 //
62 // #define wxLC_NO_SCROLL
63 // #define wxLC_NO_LABEL_WRAP
64 // #define wxLC_OWNERDRAW_FIXED
65 // #define wxLC_SHOW_SEL_ALWAYS
66
67 // Mask flags to tell app/GUI what fields of wxListItem are valid
68 #define wxLIST_MASK_STATE 0x0001
69 #define wxLIST_MASK_TEXT 0x0002
70 #define wxLIST_MASK_IMAGE 0x0004
71 #define wxLIST_MASK_DATA 0x0008
72 #define wxLIST_SET_ITEM 0x0010
73 #define wxLIST_MASK_WIDTH 0x0020
74 #define wxLIST_MASK_FORMAT 0x0040
75
76 // State flags for indicating the state of an item
77 #define wxLIST_STATE_DONTCARE 0x0000
78 #define wxLIST_STATE_DROPHILITED 0x0001 // MSW only
79 #define wxLIST_STATE_FOCUSED 0x0002
80 #define wxLIST_STATE_SELECTED 0x0004
81 #define wxLIST_STATE_CUT 0x0008 // MSW only
82
83 // Hit test flags, used in HitTest
84 #define wxLIST_HITTEST_ABOVE 0x0001 // Above the client area.
85 #define wxLIST_HITTEST_BELOW 0x0002 // Below the client area.
86 #define wxLIST_HITTEST_NOWHERE 0x0004 // In the client area but below the last item.
87 #define wxLIST_HITTEST_ONITEMICON 0x0020 // On the bitmap associated with an item.
88 #define wxLIST_HITTEST_ONITEMLABEL 0x0080 // On the label (string) associated with an item.
89 #define wxLIST_HITTEST_ONITEMRIGHT 0x0100 // In the area to the right of an item.
90 #define wxLIST_HITTEST_ONITEMSTATEICON 0x0200 // On the state icon for a tree view item that is in a user-defined state.
91 #define wxLIST_HITTEST_TOLEFT 0x0400 // To the left of the client area.
92 #define wxLIST_HITTEST_TORIGHT 0x0800 // To the right of the client area.
93
94 #define wxLIST_HITTEST_ONITEM (wxLIST_HITTEST_ONITEMICON | wxLIST_HITTEST_ONITEMLABEL | wxLIST_HITTEST_ONITEMSTATEICON)
95
96 // Flags for GetNextItem (MSW only except wxLIST_NEXT_ALL)
97 enum
98 {
99 wxLIST_NEXT_ABOVE, // Searches for an item above the specified item
100 wxLIST_NEXT_ALL, // Searches for subsequent item by index
101 wxLIST_NEXT_BELOW, // Searches for an item below the specified item
102 wxLIST_NEXT_LEFT, // Searches for an item to the left of the specified item
103 wxLIST_NEXT_RIGHT // Searches for an item to the right of the specified item
104 };
105
106 // Alignment flags for Arrange (MSW only except wxLIST_ALIGN_LEFT)
107 enum
108 {
109 wxLIST_ALIGN_DEFAULT,
110 wxLIST_ALIGN_LEFT,
111 wxLIST_ALIGN_TOP,
112 wxLIST_ALIGN_SNAP_TO_GRID
113 };
114
115 // Column format (MSW only except wxLIST_FORMAT_LEFT)
116 enum wxListColumnFormat
117 {
118 wxLIST_FORMAT_LEFT,
119 wxLIST_FORMAT_RIGHT,
120 wxLIST_FORMAT_CENTRE,
121 wxLIST_FORMAT_CENTER = wxLIST_FORMAT_CENTRE
122 };
123
124 // Autosize values for SetColumnWidth
125 enum
126 {
127 wxLIST_AUTOSIZE = -1,
128 wxLIST_AUTOSIZE_USEHEADER = -2 // partly supported by generic version
129 };
130
131 // Flag values for GetItemRect
132 enum
133 {
134 wxLIST_RECT_BOUNDS,
135 wxLIST_RECT_ICON,
136 wxLIST_RECT_LABEL
137 };
138
139 // Flag values for FindItem (MSW only)
140 enum
141 {
142 wxLIST_FIND_UP,
143 wxLIST_FIND_DOWN,
144 wxLIST_FIND_LEFT,
145 wxLIST_FIND_RIGHT
146 };
147
148 // ----------------------------------------------------------------------------
149 // wxListItemAttr: a structure containing the visual attributes of an item
150 // ----------------------------------------------------------------------------
151
152 class WXDLLEXPORT wxListItemAttr
153 {
154 public:
155 // ctors
156 wxListItemAttr() { }
157 wxListItemAttr(const wxColour& colText,
158 const wxColour& colBack,
159 const wxFont& font)
160 : m_colText(colText), m_colBack(colBack), m_font(font) { }
161
162 // setters
163 void SetTextColour(const wxColour& colText) { m_colText = colText; }
164 void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; }
165 void SetFont(const wxFont& font) { m_font = font; }
166
167 // accessors
168 bool HasTextColour() const { return m_colText.Ok(); }
169 bool HasBackgroundColour() const { return m_colBack.Ok(); }
170 bool HasFont() const { return m_font.Ok(); }
171
172 const wxColour& GetTextColour() const { return m_colText; }
173 const wxColour& GetBackgroundColour() const { return m_colBack; }
174 const wxFont& GetFont() const { return m_font; }
175
176 private:
177 wxColour m_colText,
178 m_colBack;
179 wxFont m_font;
180 };
181
182 // ----------------------------------------------------------------------------
183 // wxListItem: the item or column info, used to exchange data with wxListCtrl
184 // ----------------------------------------------------------------------------
185
186 class WXDLLEXPORT wxListItem : public wxObject
187 {
188 public:
189 wxListItem();
190 ~wxListItem() { delete m_attr; }
191
192 // resetting
193 void Clear();
194 void ClearAttributes();
195
196 // setters
197 void SetMask(long mask) { m_mask = mask; }
198 void SetId(long id) { m_itemId = id; }
199 void SetColumn(int col) { m_col = col; }
200 void SetState(long state) { m_state = state; m_stateMask |= state; }
201 void SetStateMask(long stateMask) { m_stateMask = stateMask; }
202 void SetText(const wxString& text) { m_text = text; }
203 void SetImage(int image) { m_image = image; }
204 void SetData(long data) { m_data = data; }
205 void SetData(void *data) { m_data = (long)data; }
206
207 void SetWidth(int width) { m_width = width; }
208 void SetAlign(wxListColumnFormat align) { m_format = align; }
209
210 void SetTextColour(const wxColour& colText)
211 { Attributes().SetTextColour(colText); }
212 void SetBackgroundColour(const wxColour& colBack)
213 { Attributes().SetBackgroundColour(colBack); }
214 void SetFont(const wxFont& font)
215 { Attributes().SetFont(font); }
216
217 // accessors
218 long GetMask() const { return m_mask; }
219 long GetId() const { return m_itemId; }
220 int GetColumn() const { return m_col; }
221 long GetState() const { return m_state & m_stateMask; }
222 const wxString& GetText() const { return m_text; }
223 int GetImage() const { return m_image; }
224 long GetData() const { return m_data; }
225
226 int GetWidth() const { return m_width; }
227 wxListColumnFormat GetAlign() const { return (wxListColumnFormat)m_format; }
228
229 wxListItemAttr *GetAttributes() const { return m_attr; }
230 bool HasAttributes() const { return m_attr != NULL; }
231
232 wxColour GetTextColour() const
233 { return HasAttributes() ? m_attr->GetTextColour() : wxNullColour; }
234 wxColour GetBackgroundColour() const
235 { return HasAttributes() ? m_attr->GetBackgroundColour()
236 : wxNullColour; }
237 wxFont GetFont() const
238 { return HasAttributes() ? m_attr->GetFont() : wxNullFont; }
239
240 // this conversion is necessary to make old code using GetItem() to
241 // compile
242 operator long() const { return m_itemId; }
243
244 // these members are public for compatibility
245
246 long m_mask; // Indicates what fields are valid
247 long m_itemId; // The zero-based item position
248 int m_col; // Zero-based column, if in report mode
249 long m_state; // The state of the item
250 long m_stateMask;// Which flags of m_state are valid (uses same flags)
251 wxString m_text; // The label/header text
252 int m_image; // The zero-based index into an image list
253 long m_data; // App-defined data
254
255 // For columns only
256 int m_format; // left, right, centre
257 int m_width; // width of column
258
259 protected:
260 // creates m_attr if we don't have it yet
261 wxListItemAttr& Attributes()
262 {
263 if ( !m_attr )
264 m_attr = new wxListItemAttr;
265
266 return *m_attr;
267 }
268
269 wxListItemAttr *m_attr; // optional pointer to the items style
270
271 private:
272 DECLARE_DYNAMIC_CLASS(wxListItem)
273 };
274
275 // ----------------------------------------------------------------------------
276 // include the wxListCtrl class declaration
277 // ----------------------------------------------------------------------------
278
279 #if defined(__WXUNIVERSAL__)
280 #include "wx/generic/listctrl.h"
281 #elif defined(__WXMSW__)
282 #ifdef __WIN16__
283 #include "wx/generic/listctrl.h"
284 #else
285 #include "wx/msw/listctrl.h"
286 #endif
287 #elif defined(__WXMOTIF__)
288 #include "wx/generic/listctrl.h"
289 #elif defined(__WXGTK__)
290 #include "wx/generic/listctrl.h"
291 #elif defined(__WXQT__)
292 #include "wx/generic/listctrl.h"
293 #elif defined(__WXMAC__)
294 #include "wx/generic/listctrl.h"
295 #elif defined(__WXPM__)
296 #include "wx/generic/listctrl.h"
297 #elif defined(__WXSTUBS__)
298 #include "wx/generic/listctrl.h"
299 #endif
300
301 // ----------------------------------------------------------------------------
302 // wxListEvent - the event class for the wxListCtrl notifications
303 // ----------------------------------------------------------------------------
304
305 class WXDLLEXPORT wxListEvent : public wxNotifyEvent
306 {
307 public:
308 wxListEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
309
310 int m_code;
311 long m_itemIndex;
312 long m_oldItemIndex;
313 int m_col;
314 bool m_cancelled;
315 wxPoint m_pointDrag;
316
317 wxListItem m_item;
318
319 int GetCode() const { return m_code; }
320 long GetIndex() const { return m_itemIndex; }
321 long GetOldIndex() const { return m_oldItemIndex; }
322 long GetOldItem() const { return m_oldItemIndex; }
323 int GetColumn() const { return m_col; }
324 bool Cancelled() const { return m_cancelled; }
325 wxPoint GetPoint() const { return m_pointDrag; }
326 const wxString& GetLabel() const { return m_item.m_text; }
327 const wxString& GetText() const { return m_item.m_text; }
328 int GetImage() const { return m_item.m_image; }
329 long GetData() const { return m_item.m_data; }
330 long GetMask() const { return m_item.m_mask; }
331 const wxListItem& GetItem() const { return m_item; }
332
333 void CopyObject(wxObject& object_dest) const;
334
335 private:
336 DECLARE_DYNAMIC_CLASS(wxListEvent)
337 };
338
339 // ----------------------------------------------------------------------------
340 // wxListCtrl event macros
341 // ----------------------------------------------------------------------------
342
343 BEGIN_DECLARE_EVENT_TYPES()
344 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG, 700)
345 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG, 701)
346 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, 702)
347 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT, 703)
348 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM, 704)
349 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, 705)
350 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO, 706)
351 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO, 707)
352 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED, 708)
353 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED, 709)
354 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN, 710)
355 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM, 711)
356 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK, 712)
357 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, 713)
358 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, 714)
359 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED, 715)
360 END_DECLARE_EVENT_TYPES()
361
362 typedef void (wxEvtHandler::*wxListEventFunction)(wxListEvent&);
363
364 #define EVT_LIST_BEGIN_DRAG(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
365 #define EVT_LIST_BEGIN_RDRAG(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
366 #define EVT_LIST_BEGIN_LABEL_EDIT(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
367 #define EVT_LIST_END_LABEL_EDIT(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_END_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
368 #define EVT_LIST_DELETE_ITEM(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_DELETE_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
369 #define EVT_LIST_DELETE_ALL_ITEMS(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
370 #define EVT_LIST_GET_INFO(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_GET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
371 #define EVT_LIST_SET_INFO(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_SET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
372 #define EVT_LIST_ITEM_SELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_SELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
373 #define EVT_LIST_ITEM_DESELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_DESELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
374 #define EVT_LIST_KEY_DOWN(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
375 #define EVT_LIST_INSERT_ITEM(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_INSERT_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
376 #define EVT_LIST_COL_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_COL_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
377 #define EVT_LIST_ITEM_RIGHT_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL ),
378 #define EVT_LIST_ITEM_MIDDLE_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL ),
379 #define EVT_LIST_ITEM_ACTIVATED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL ),
380
381 #endif // wxUSE_LISTCTRL
382
383 #endif
384 // _WX_LISTCTRL_H_BASE_