1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxListCtrl class
4 // Author: Vadim Zeitlin
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_LISTBASE_H_BASE_
13 #define _WX_LISTBASE_H_BASE_
15 #if defined(__GNUG__) && !defined(__APPLE__)
16 // #pragma interface "listctrlbase.h"
21 // ----------------------------------------------------------------------------
23 // ----------------------------------------------------------------------------
25 // type of compare function for wxListCtrl sort operation
26 typedef int (wxCALLBACK
*wxListCtrlCompare
)(long item1
, long item2
, long sortData
);
28 // ----------------------------------------------------------------------------
29 // wxListCtrl constants
30 // ----------------------------------------------------------------------------
33 #define wxLC_VRULES 0x0001
34 #define wxLC_HRULES 0x0002
36 #define wxLC_ICON 0x0004
37 #define wxLC_SMALL_ICON 0x0008
38 #define wxLC_LIST 0x0010
39 #define wxLC_REPORT 0x0020
41 #define wxLC_ALIGN_TOP 0x0040
42 #define wxLC_ALIGN_LEFT 0x0080
43 #define wxLC_AUTOARRANGE 0x0100
44 #define wxLC_VIRTUAL 0x0200
45 #define wxLC_EDIT_LABELS 0x0400
46 #define wxLC_NO_HEADER 0x0800
47 #define wxLC_NO_SORT_HEADER 0x1000
48 #define wxLC_SINGLE_SEL 0x2000
49 #define wxLC_SORT_ASCENDING 0x4000
50 #define wxLC_SORT_DESCENDING 0x8000
52 #define wxLC_MASK_TYPE (wxLC_ICON | wxLC_SMALL_ICON | wxLC_LIST | wxLC_REPORT)
53 #define wxLC_MASK_ALIGN (wxLC_ALIGN_TOP | wxLC_ALIGN_LEFT)
54 #define wxLC_MASK_SORT (wxLC_SORT_ASCENDING | wxLC_SORT_DESCENDING)
56 // for compatibility only
57 #define wxLC_USER_TEXT wxLC_VIRTUAL
60 // (a) too much detail
61 // (b) not enough style flags
62 // (c) not implemented anyhow in the generic version
64 // #define wxLC_NO_SCROLL
65 // #define wxLC_NO_LABEL_WRAP
66 // #define wxLC_OWNERDRAW_FIXED
67 // #define wxLC_SHOW_SEL_ALWAYS
69 // Mask flags to tell app/GUI what fields of wxListItem are valid
70 #define wxLIST_MASK_STATE 0x0001
71 #define wxLIST_MASK_TEXT 0x0002
72 #define wxLIST_MASK_IMAGE 0x0004
73 #define wxLIST_MASK_DATA 0x0008
74 #define wxLIST_SET_ITEM 0x0010
75 #define wxLIST_MASK_WIDTH 0x0020
76 #define wxLIST_MASK_FORMAT 0x0040
78 // State flags for indicating the state of an item
79 #define wxLIST_STATE_DONTCARE 0x0000
80 #define wxLIST_STATE_DROPHILITED 0x0001 // MSW only
81 #define wxLIST_STATE_FOCUSED 0x0002
82 #define wxLIST_STATE_SELECTED 0x0004
83 #define wxLIST_STATE_CUT 0x0008 // MSW only
85 // Hit test flags, used in HitTest
86 #define wxLIST_HITTEST_ABOVE 0x0001 // Above the client area.
87 #define wxLIST_HITTEST_BELOW 0x0002 // Below the client area.
88 #define wxLIST_HITTEST_NOWHERE 0x0004 // In the client area but below the last item.
89 #define wxLIST_HITTEST_ONITEMICON 0x0020 // On the bitmap associated with an item.
90 #define wxLIST_HITTEST_ONITEMLABEL 0x0080 // On the label (string) associated with an item.
91 #define wxLIST_HITTEST_ONITEMRIGHT 0x0100 // In the area to the right of an item.
92 #define wxLIST_HITTEST_ONITEMSTATEICON 0x0200 // On the state icon for a tree view item that is in a user-defined state.
93 #define wxLIST_HITTEST_TOLEFT 0x0400 // To the left of the client area.
94 #define wxLIST_HITTEST_TORIGHT 0x0800 // To the right of the client area.
96 #define wxLIST_HITTEST_ONITEM (wxLIST_HITTEST_ONITEMICON | wxLIST_HITTEST_ONITEMLABEL | wxLIST_HITTEST_ONITEMSTATEICON)
98 // Flags for GetNextItem (MSW only except wxLIST_NEXT_ALL)
101 wxLIST_NEXT_ABOVE
, // Searches for an item above the specified item
102 wxLIST_NEXT_ALL
, // Searches for subsequent item by index
103 wxLIST_NEXT_BELOW
, // Searches for an item below the specified item
104 wxLIST_NEXT_LEFT
, // Searches for an item to the left of the specified item
105 wxLIST_NEXT_RIGHT
// Searches for an item to the right of the specified item
108 // Alignment flags for Arrange (MSW only except wxLIST_ALIGN_LEFT)
111 wxLIST_ALIGN_DEFAULT
,
114 wxLIST_ALIGN_SNAP_TO_GRID
117 // Column format (MSW only except wxLIST_FORMAT_LEFT)
118 enum wxListColumnFormat
122 wxLIST_FORMAT_CENTRE
,
123 wxLIST_FORMAT_CENTER
= wxLIST_FORMAT_CENTRE
126 // Autosize values for SetColumnWidth
129 wxLIST_AUTOSIZE
= -1,
130 wxLIST_AUTOSIZE_USEHEADER
= -2 // partly supported by generic version
133 // Flag values for GetItemRect
141 // Flag values for FindItem (MSW only)
150 // ----------------------------------------------------------------------------
151 // wxListItemAttr: a structure containing the visual attributes of an item
152 // ----------------------------------------------------------------------------
154 class WXDLLEXPORT wxListItemAttr
159 wxListItemAttr(const wxColour
& colText
,
160 const wxColour
& colBack
,
162 : m_colText(colText
), m_colBack(colBack
), m_font(font
) { }
165 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
166 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
167 void SetFont(const wxFont
& font
) { m_font
= font
; }
170 bool HasTextColour() const { return m_colText
.Ok(); }
171 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
172 bool HasFont() const { return m_font
.Ok(); }
174 const wxColour
& GetTextColour() const { return m_colText
; }
175 const wxColour
& GetBackgroundColour() const { return m_colBack
; }
176 const wxFont
& GetFont() const { return m_font
; }
184 // ----------------------------------------------------------------------------
185 // wxListItem: the item or column info, used to exchange data with wxListCtrl
186 // ----------------------------------------------------------------------------
188 class WXDLLEXPORT wxListItem
: public wxObject
191 wxListItem() { Init(); m_attr
= NULL
; }
192 wxListItem(const wxListItem
& item
)
195 m_itemId(item
.m_itemId
),
197 m_state(item
.m_state
),
198 m_stateMask(item
.m_stateMask
),
200 m_image(item
.m_image
),
202 m_format(item
.m_format
),
203 m_width(item
.m_width
),
206 // copy list item attributes
207 if( item
.HasAttributes() )
208 m_attr
= new wxListItemAttr(*item
.GetAttributes());
210 virtual ~wxListItem() { delete m_attr
; }
213 void Clear() { Init(); m_text
.clear(); ClearAttributes(); }
214 void ClearAttributes() { if ( m_attr
) { delete m_attr
; m_attr
= NULL
; } }
217 void SetMask(long mask
)
221 void SetColumn(int col
)
223 void SetState(long state
)
224 { m_mask
|= wxLIST_MASK_STATE
; m_state
= state
; m_stateMask
|= state
; }
225 void SetStateMask(long stateMask
)
226 { m_stateMask
= stateMask
; }
227 void SetText(const wxString
& text
)
228 { m_mask
|= wxLIST_MASK_TEXT
; m_text
= text
; }
229 void SetImage(int image
)
230 { m_mask
|= wxLIST_MASK_IMAGE
; m_image
= image
; }
231 void SetData(long data
)
232 { m_mask
|= wxLIST_MASK_DATA
; m_data
= data
; }
233 void SetData(void *data
)
234 { m_mask
|= wxLIST_MASK_DATA
; m_data
= (long)data
; }
236 void SetWidth(int width
)
237 { m_mask
|= wxLIST_MASK_WIDTH
; m_width
= width
; }
238 void SetAlign(wxListColumnFormat align
)
239 { m_mask
|= wxLIST_MASK_FORMAT
; m_format
= align
; }
241 void SetTextColour(const wxColour
& colText
)
242 { Attributes().SetTextColour(colText
); }
243 void SetBackgroundColour(const wxColour
& colBack
)
244 { Attributes().SetBackgroundColour(colBack
); }
245 void SetFont(const wxFont
& font
)
246 { Attributes().SetFont(font
); }
249 long GetMask() const { return m_mask
; }
250 long GetId() const { return m_itemId
; }
251 int GetColumn() const { return m_col
; }
252 long GetState() const { return m_state
& m_stateMask
; }
253 const wxString
& GetText() const { return m_text
; }
254 int GetImage() const { return m_image
; }
255 long GetData() const { return m_data
; }
257 int GetWidth() const { return m_width
; }
258 wxListColumnFormat
GetAlign() const { return (wxListColumnFormat
)m_format
; }
260 wxListItemAttr
*GetAttributes() const { return m_attr
; }
261 bool HasAttributes() const { return m_attr
!= NULL
; }
263 wxColour
GetTextColour() const
264 { return HasAttributes() ? m_attr
->GetTextColour() : wxNullColour
; }
265 wxColour
GetBackgroundColour() const
266 { return HasAttributes() ? m_attr
->GetBackgroundColour()
268 wxFont
GetFont() const
269 { return HasAttributes() ? m_attr
->GetFont() : wxNullFont
; }
271 // this conversion is necessary to make old code using GetItem() to
273 operator long() const { return m_itemId
; }
275 // these members are public for compatibility
277 long m_mask
; // Indicates what fields are valid
278 long m_itemId
; // The zero-based item position
279 int m_col
; // Zero-based column, if in report mode
280 long m_state
; // The state of the item
281 long m_stateMask
;// Which flags of m_state are valid (uses same flags)
282 wxString m_text
; // The label/header text
283 int m_image
; // The zero-based index into an image list
284 long m_data
; // App-defined data
287 int m_format
; // left, right, centre
288 int m_width
; // width of column
291 // creates m_attr if we don't have it yet
292 wxListItemAttr
& Attributes()
295 m_attr
= new wxListItemAttr
;
310 m_format
= wxLIST_FORMAT_CENTRE
;
314 wxListItemAttr
*m_attr
; // optional pointer to the items style
317 // VZ: this is strange, we have a copy ctor but not operator=(), why?
318 wxListItem
& operator=(const wxListItem
& item
);
320 DECLARE_DYNAMIC_CLASS(wxListItem
)
323 // ----------------------------------------------------------------------------
324 // wxListEvent - the event class for the wxListCtrl notifications
325 // ----------------------------------------------------------------------------
327 class WXDLLEXPORT wxListEvent
: public wxNotifyEvent
330 wxListEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0)
331 : wxNotifyEvent(commandType
, id
)
340 wxListEvent(const wxListEvent
& event
)
341 : wxNotifyEvent(event
)
342 , m_code(event
.m_code
)
343 , m_oldItemIndex(event
.m_oldItemIndex
)
344 , m_itemIndex(event
.m_itemIndex
)
346 , m_pointDrag(event
.m_pointDrag
)
347 , m_item(event
.m_item
)
350 int GetKeyCode() const { return m_code
; }
351 long GetIndex() const { return m_itemIndex
; }
352 int GetColumn() const { return m_col
; }
353 wxPoint
GetPoint() const { return m_pointDrag
; }
354 const wxString
& GetLabel() const { return m_item
.m_text
; }
355 const wxString
& GetText() const { return m_item
.m_text
; }
356 int GetImage() const { return m_item
.m_image
; }
357 long GetData() const { return m_item
.m_data
; }
358 long GetMask() const { return m_item
.m_mask
; }
359 const wxListItem
& GetItem() const { return m_item
; }
361 // for wxEVT_COMMAND_LIST_CACHE_HINT only
362 long GetCacheFrom() const { return m_oldItemIndex
; }
363 long GetCacheTo() const { return m_itemIndex
; }
365 #if WXWIN_COMPATIBILITY_2_2
366 // these methods don't do anything at all
367 long GetOldIndex() const { return 0; }
368 long GetOldItem() const { return 0; }
370 // this one is superseded by GetKeyCode()
371 int GetCode() const { return GetKeyCode(); }
372 #endif // WXWIN_COMPATIBILITY_2_2
374 virtual wxEvent
*Clone() const { return new wxListEvent(*this); }
376 //protected: -- not for backwards compatibility
378 long m_oldItemIndex
; // only for wxEVT_COMMAND_LIST_CACHE_HINT
386 DECLARE_DYNAMIC_CLASS(wxListEvent
)
389 // ----------------------------------------------------------------------------
390 // wxListCtrl event macros
391 // ----------------------------------------------------------------------------
393 BEGIN_DECLARE_EVENT_TYPES()
394 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
, 700)
395 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
, 701)
396 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, 702)
397 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
, 703)
398 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
, 704)
399 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, 705)
400 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
, 706)
401 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
, 707)
402 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
, 708)
403 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
, 709)
404 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
, 710)
405 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
, 711)
406 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
, 712)
407 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, 713)
408 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
, 714)
409 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, 715)
410 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
, 716)
411 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
, 717)
412 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
, 718)
413 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING
, 719)
414 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG
, 720)
415 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED
, 721)
416 END_DECLARE_EVENT_TYPES()
418 typedef void (wxEvtHandler::*wxListEventFunction
)(wxListEvent
&);
420 #define EVT_LIST_BEGIN_DRAG(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
421 #define EVT_LIST_BEGIN_RDRAG(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
422 #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 ),
423 #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 ),
424 #define EVT_LIST_DELETE_ITEM(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_DELETE_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
425 #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 ),
426 #define EVT_LIST_GET_INFO(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_GET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
427 #define EVT_LIST_SET_INFO(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_SET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
428 #define EVT_LIST_KEY_DOWN(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
429 #define EVT_LIST_INSERT_ITEM(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_INSERT_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
431 #define EVT_LIST_COL_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_COL_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
432 #define EVT_LIST_COL_RIGHT_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_COL_RIGHT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
433 #define EVT_LIST_COL_BEGIN_DRAG(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_COL_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
434 #define EVT_LIST_COL_DRAGGING(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_COL_DRAGGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
435 #define EVT_LIST_COL_END_DRAG(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_COL_END_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
437 #define EVT_LIST_ITEM_SELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_SELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
438 #define EVT_LIST_ITEM_DESELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_DESELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
439 #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 ),
440 #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 ),
441 #define EVT_LIST_ITEM_ACTIVATED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL ),
442 #define EVT_LIST_ITEM_FOCUSED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_FOCUSED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL ),
444 #define EVT_LIST_CACHE_HINT(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_CACHE_HINT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL ),
446 #endif // wxUSE_LISTCTRL
449 // _WX_LISTCTRL_H_BASE_