1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxListCtrl class
4 // Author: Vadim Zeitlin
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_LISTCTRL_H_BASE_
13 #define _WX_LISTCTRL_H_BASE_
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
192 ~wxListItem() { delete m_attr
; }
196 void ClearAttributes();
199 void SetMask(long mask
) { m_mask
= mask
; }
200 void SetId(long id
) { m_itemId
= id
; }
201 void SetColumn(int col
) { m_col
= col
; }
202 void SetState(long state
) { m_state
= state
; m_stateMask
|= state
; }
203 void SetStateMask(long stateMask
) { m_stateMask
= stateMask
; }
204 void SetText(const wxString
& text
) { m_text
= text
; }
205 void SetImage(int image
) { m_image
= image
; }
206 void SetData(long data
) { m_data
= data
; }
207 void SetData(void *data
) { m_data
= (long)data
; }
209 void SetWidth(int width
) { m_width
= width
; }
210 void SetAlign(wxListColumnFormat align
) { m_format
= align
; }
212 void SetTextColour(const wxColour
& colText
)
213 { Attributes().SetTextColour(colText
); }
214 void SetBackgroundColour(const wxColour
& colBack
)
215 { Attributes().SetBackgroundColour(colBack
); }
216 void SetFont(const wxFont
& font
)
217 { Attributes().SetFont(font
); }
220 long GetMask() const { return m_mask
; }
221 long GetId() const { return m_itemId
; }
222 int GetColumn() const { return m_col
; }
223 long GetState() const { return m_state
& m_stateMask
; }
224 const wxString
& GetText() const { return m_text
; }
225 int GetImage() const { return m_image
; }
226 long GetData() const { return m_data
; }
228 int GetWidth() const { return m_width
; }
229 wxListColumnFormat
GetAlign() const { return (wxListColumnFormat
)m_format
; }
231 wxListItemAttr
*GetAttributes() const { return m_attr
; }
232 bool HasAttributes() const { return m_attr
!= NULL
; }
234 wxColour
GetTextColour() const
235 { return HasAttributes() ? m_attr
->GetTextColour() : wxNullColour
; }
236 wxColour
GetBackgroundColour() const
237 { return HasAttributes() ? m_attr
->GetBackgroundColour()
239 wxFont
GetFont() const
240 { return HasAttributes() ? m_attr
->GetFont() : wxNullFont
; }
242 // this conversion is necessary to make old code using GetItem() to
244 operator long() const { return m_itemId
; }
246 // these members are public for compatibility
248 long m_mask
; // Indicates what fields are valid
249 long m_itemId
; // The zero-based item position
250 int m_col
; // Zero-based column, if in report mode
251 long m_state
; // The state of the item
252 long m_stateMask
;// Which flags of m_state are valid (uses same flags)
253 wxString m_text
; // The label/header text
254 int m_image
; // The zero-based index into an image list
255 long m_data
; // App-defined data
258 int m_format
; // left, right, centre
259 int m_width
; // width of column
262 // creates m_attr if we don't have it yet
263 wxListItemAttr
& Attributes()
266 m_attr
= new wxListItemAttr
;
271 wxListItemAttr
*m_attr
; // optional pointer to the items style
274 DECLARE_DYNAMIC_CLASS(wxListItem
)
277 // ----------------------------------------------------------------------------
278 // include the wxListCtrl class declaration
279 // ----------------------------------------------------------------------------
281 #if defined(__WIN32__) && !defined(__WXUNIVERSAL__)
282 #include "wx/msw/listctrl.h"
284 #include "wx/generic/listctrl.h"
287 // ----------------------------------------------------------------------------
288 // wxListView: a class which provides a better API for list control
289 // ----------------------------------------------------------------------------
291 class WXDLLEXPORT wxListView
: public wxListCtrl
295 wxListView( wxWindow
*parent
,
297 const wxPoint
& pos
= wxDefaultPosition
,
298 const wxSize
& size
= wxDefaultSize
,
299 long style
= wxLC_REPORT
,
300 const wxValidator
& validator
= wxDefaultValidator
,
301 const wxString
&name
= "listctrl" )
303 Create(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
306 // [de]select an item
307 void Select(long n
, bool on
= TRUE
)
309 SetItemState(n
, on
? wxLIST_STATE_SELECTED
: 0, wxLIST_STATE_SELECTED
);
312 // focus and show the given item
313 void Focus(long index
)
315 SetItemState(index
, wxLIST_STATE_FOCUSED
, wxLIST_STATE_FOCUSED
);
316 EnsureVisible(index
);
319 // get the currently focused item or -1 if none
320 long GetFocusedItem() const
322 return GetNextItem(-1, wxLIST_NEXT_ALL
, wxLIST_STATE_FOCUSED
);
325 // get first and subsequent selected items, return -1 when no more
326 long GetNextSelected(long item
) const
327 { return GetNextItem(item
, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
); }
328 long GetFirstSelected() const
329 { return GetNextSelected(-1); }
331 // return TRUE if the item is selected
332 bool IsSelected(long index
)
333 { return GetItemState(index
, wxLIST_STATE_SELECTED
) != 0; }
335 DECLARE_DYNAMIC_CLASS(wxListView
)
338 // ----------------------------------------------------------------------------
339 // wxListEvent - the event class for the wxListCtrl notifications
340 // ----------------------------------------------------------------------------
342 class WXDLLEXPORT wxListEvent
: public wxNotifyEvent
345 wxListEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0);
356 int GetCode() const { return m_code
; }
357 long GetIndex() const { return m_itemIndex
; }
358 long GetOldIndex() const { return m_oldItemIndex
; }
359 long GetOldItem() const { return m_oldItemIndex
; }
360 int GetColumn() const { return m_col
; }
361 bool Cancelled() const { return m_cancelled
; }
362 wxPoint
GetPoint() const { return m_pointDrag
; }
363 const wxString
& GetLabel() const { return m_item
.m_text
; }
364 const wxString
& GetText() const { return m_item
.m_text
; }
365 int GetImage() const { return m_item
.m_image
; }
366 long GetData() const { return m_item
.m_data
; }
367 long GetMask() const { return m_item
.m_mask
; }
368 const wxListItem
& GetItem() const { return m_item
; }
370 // for wxEVT_COMMAND_LIST_CACHE_HINT only
371 long GetCacheFrom() const { return m_oldItemIndex
; }
372 long GetCacheTo() const { return m_itemIndex
; }
374 void CopyObject(wxObject
& object_dest
) const;
377 DECLARE_DYNAMIC_CLASS(wxListEvent
)
380 // ----------------------------------------------------------------------------
381 // wxListCtrl event macros
382 // ----------------------------------------------------------------------------
384 BEGIN_DECLARE_EVENT_TYPES()
385 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
, 700)
386 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
, 701)
387 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, 702)
388 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
, 703)
389 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
, 704)
390 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, 705)
391 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
, 706)
392 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
, 707)
393 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
, 708)
394 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
, 709)
395 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
, 710)
396 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
, 711)
397 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
, 712)
398 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, 713)
399 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
, 714)
400 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, 715)
401 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
, 716)
402 END_DECLARE_EVENT_TYPES()
404 typedef void (wxEvtHandler::*wxListEventFunction
)(wxListEvent
&);
406 #define EVT_LIST_BEGIN_DRAG(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
407 #define EVT_LIST_BEGIN_RDRAG(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
408 #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 ),
409 #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 ),
410 #define EVT_LIST_DELETE_ITEM(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_DELETE_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
411 #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 ),
412 #define EVT_LIST_GET_INFO(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_GET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
413 #define EVT_LIST_SET_INFO(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_SET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
414 #define EVT_LIST_ITEM_SELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_SELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
415 #define EVT_LIST_ITEM_DESELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_DESELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
416 #define EVT_LIST_KEY_DOWN(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
417 #define EVT_LIST_INSERT_ITEM(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_INSERT_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
418 #define EVT_LIST_COL_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_COL_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
419 #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 ),
420 #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 ),
421 #define EVT_LIST_ITEM_ACTIVATED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL ),
422 #define EVT_LIST_CACHE_HINT(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_CACHE_HINT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL ),
424 #endif // wxUSE_LISTCTRL
427 // _WX_LISTCTRL_H_BASE_