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
40 #define wxLC_MODE_MASK \
41 (wxLC_ICON | wxLC_SMALL_ICON | wxLC_LIST | wxLC_REPORT)
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
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)
58 // for compatibility only
59 #define wxLC_USER_TEXT wxLC_VIRTUAL
62 // (a) too much detail
63 // (b) not enough style flags
64 // (c) not implemented anyhow in the generic version
66 // #define wxLC_NO_SCROLL
67 // #define wxLC_NO_LABEL_WRAP
68 // #define wxLC_OWNERDRAW_FIXED
69 // #define wxLC_SHOW_SEL_ALWAYS
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
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
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.
98 #define wxLIST_HITTEST_ONITEM (wxLIST_HITTEST_ONITEMICON | wxLIST_HITTEST_ONITEMLABEL | wxLIST_HITTEST_ONITEMSTATEICON)
100 // Flags for GetNextItem (MSW only except wxLIST_NEXT_ALL)
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
110 // Alignment flags for Arrange (MSW only except wxLIST_ALIGN_LEFT)
113 wxLIST_ALIGN_DEFAULT
,
116 wxLIST_ALIGN_SNAP_TO_GRID
119 // Column format (MSW only except wxLIST_FORMAT_LEFT)
120 enum wxListColumnFormat
124 wxLIST_FORMAT_CENTRE
,
125 wxLIST_FORMAT_CENTER
= wxLIST_FORMAT_CENTRE
128 // Autosize values for SetColumnWidth
131 wxLIST_AUTOSIZE
= -1,
132 wxLIST_AUTOSIZE_USEHEADER
= -2 // partly supported by generic version
135 // Flag values for GetItemRect
143 // Flag values for FindItem (MSW only)
152 // ----------------------------------------------------------------------------
153 // wxListItemAttr: a structure containing the visual attributes of an item
154 // ----------------------------------------------------------------------------
156 class WXDLLEXPORT wxListItemAttr
161 wxListItemAttr(const wxColour
& colText
,
162 const wxColour
& colBack
,
164 : m_colText(colText
), m_colBack(colBack
), m_font(font
) { }
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
; }
172 bool HasTextColour() const { return m_colText
.Ok(); }
173 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
174 bool HasFont() const { return m_font
.Ok(); }
176 const wxColour
& GetTextColour() const { return m_colText
; }
177 const wxColour
& GetBackgroundColour() const { return m_colBack
; }
178 const wxFont
& GetFont() const { return m_font
; }
186 // ----------------------------------------------------------------------------
187 // wxListItem: the item or column info, used to exchange data with wxListCtrl
188 // ----------------------------------------------------------------------------
190 class WXDLLEXPORT wxListItem
: public wxObject
194 ~wxListItem() { delete m_attr
; }
198 void ClearAttributes();
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
; }
211 void SetWidth(int width
) { m_width
= width
; }
212 void SetAlign(wxListColumnFormat align
) { m_format
= align
; }
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
); }
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
; }
230 int GetWidth() const { return m_width
; }
231 wxListColumnFormat
GetAlign() const { return (wxListColumnFormat
)m_format
; }
233 wxListItemAttr
*GetAttributes() const { return m_attr
; }
234 bool HasAttributes() const { return m_attr
!= NULL
; }
236 wxColour
GetTextColour() const
237 { return HasAttributes() ? m_attr
->GetTextColour() : wxNullColour
; }
238 wxColour
GetBackgroundColour() const
239 { return HasAttributes() ? m_attr
->GetBackgroundColour()
241 wxFont
GetFont() const
242 { return HasAttributes() ? m_attr
->GetFont() : wxNullFont
; }
244 // this conversion is necessary to make old code using GetItem() to
246 operator long() const { return m_itemId
; }
248 // these members are public for compatibility
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
260 int m_format
; // left, right, centre
261 int m_width
; // width of column
264 // creates m_attr if we don't have it yet
265 wxListItemAttr
& Attributes()
268 m_attr
= new wxListItemAttr
;
273 wxListItemAttr
*m_attr
; // optional pointer to the items style
276 DECLARE_DYNAMIC_CLASS(wxListItem
)
279 // ----------------------------------------------------------------------------
280 // include the wxListCtrl class declaration
281 // ----------------------------------------------------------------------------
283 #if defined(__WXUNIVERSAL__)
284 #include "wx/generic/listctrl.h"
285 #elif defined(__WXMSW__)
287 #include "wx/generic/listctrl.h"
289 #include "wx/msw/listctrl.h"
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"
305 // ----------------------------------------------------------------------------
306 // wxListEvent - the event class for the wxListCtrl notifications
307 // ----------------------------------------------------------------------------
309 class WXDLLEXPORT wxListEvent
: public wxNotifyEvent
312 wxListEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0);
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
; }
337 void CopyObject(wxObject
& object_dest
) const;
340 DECLARE_DYNAMIC_CLASS(wxListEvent
)
343 // ----------------------------------------------------------------------------
344 // wxListCtrl event macros
345 // ----------------------------------------------------------------------------
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()
366 typedef void (wxEvtHandler::*wxListEventFunction
)(wxListEvent
&);
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 ),
385 #endif // wxUSE_LISTCTRL
388 // _WX_LISTCTRL_H_BASE_