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