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
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
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)
54 // for compatibility only
55 #define wxLC_USER_TEXT wxLC_VIRTUAL
58 // (a) too much detail
59 // (b) not enough style flags
60 // (c) not implemented anyhow in the generic version
62 // #define wxLC_NO_SCROLL
63 // #define wxLC_NO_LABEL_WRAP
64 // #define wxLC_OWNERDRAW_FIXED
65 // #define wxLC_SHOW_SEL_ALWAYS
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
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
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.
94 #define wxLIST_HITTEST_ONITEM (wxLIST_HITTEST_ONITEMICON | wxLIST_HITTEST_ONITEMLABEL | wxLIST_HITTEST_ONITEMSTATEICON)
96 // Flags for GetNextItem (MSW only except wxLIST_NEXT_ALL)
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
106 // Alignment flags for Arrange (MSW only except wxLIST_ALIGN_LEFT)
109 wxLIST_ALIGN_DEFAULT
,
112 wxLIST_ALIGN_SNAP_TO_GRID
115 // Column format (MSW only except wxLIST_FORMAT_LEFT)
116 enum wxListColumnFormat
120 wxLIST_FORMAT_CENTRE
,
121 wxLIST_FORMAT_CENTER
= wxLIST_FORMAT_CENTRE
124 // Autosize values for SetColumnWidth
127 wxLIST_AUTOSIZE
= -1,
128 wxLIST_AUTOSIZE_USEHEADER
= -2 // partly supported by generic version
131 // Flag values for GetItemRect
139 // Flag values for FindItem (MSW only)
148 // ----------------------------------------------------------------------------
149 // wxListItemAttr: a structure containing the visual attributes of an item
150 // ----------------------------------------------------------------------------
152 class WXDLLEXPORT wxListItemAttr
157 wxListItemAttr(const wxColour
& colText
,
158 const wxColour
& colBack
,
160 : m_colText(colText
), m_colBack(colBack
), m_font(font
) { }
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
; }
168 bool HasTextColour() const { return m_colText
.Ok(); }
169 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
170 bool HasFont() const { return m_font
.Ok(); }
172 const wxColour
& GetTextColour() const { return m_colText
; }
173 const wxColour
& GetBackgroundColour() const { return m_colBack
; }
174 const wxFont
& GetFont() const { return m_font
; }
182 // ----------------------------------------------------------------------------
183 // wxListItem: the item or column info, used to exchange data with wxListCtrl
184 // ----------------------------------------------------------------------------
186 class WXDLLEXPORT wxListItem
: public wxObject
190 ~wxListItem() { delete m_attr
; }
194 void ClearAttributes();
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
; }
207 void SetWidth(int width
) { m_width
= width
; }
208 void SetAlign(wxListColumnFormat align
) { m_format
= align
; }
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
); }
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
; }
226 int GetWidth() const { return m_width
; }
227 wxListColumnFormat
GetAlign() const { return (wxListColumnFormat
)m_format
; }
229 wxListItemAttr
*GetAttributes() const { return m_attr
; }
230 bool HasAttributes() const { return m_attr
!= NULL
; }
232 wxColour
GetTextColour() const
233 { return HasAttributes() ? m_attr
->GetTextColour() : wxNullColour
; }
234 wxColour
GetBackgroundColour() const
235 { return HasAttributes() ? m_attr
->GetBackgroundColour()
237 wxFont
GetFont() const
238 { return HasAttributes() ? m_attr
->GetFont() : wxNullFont
; }
240 // this conversion is necessary to make old code using GetItem() to
242 operator long() const { return m_itemId
; }
244 // these members are public for compatibility
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
256 int m_format
; // left, right, centre
257 int m_width
; // width of column
260 // creates m_attr if we don't have it yet
261 wxListItemAttr
& Attributes()
264 m_attr
= new wxListItemAttr
;
269 wxListItemAttr
*m_attr
; // optional pointer to the items style
272 DECLARE_DYNAMIC_CLASS(wxListItem
)
275 // ----------------------------------------------------------------------------
276 // include the wxListCtrl class declaration
277 // ----------------------------------------------------------------------------
279 #if defined(__WXUNIVERSAL__)
280 #include "wx/generic/listctrl.h"
281 #elif defined(__WXMSW__)
283 #include "wx/generic/listctrl.h"
285 #include "wx/msw/listctrl.h"
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"
301 // ----------------------------------------------------------------------------
302 // wxListEvent - the event class for the wxListCtrl notifications
303 // ----------------------------------------------------------------------------
305 class WXDLLEXPORT wxListEvent
: public wxNotifyEvent
308 wxListEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0);
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
; }
333 void CopyObject(wxObject
& object_dest
) const;
336 DECLARE_DYNAMIC_CLASS(wxListEvent
)
339 // ----------------------------------------------------------------------------
340 // wxListCtrl event macros
341 // ----------------------------------------------------------------------------
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()
362 typedef void (wxEvtHandler::*wxListEventFunction
)(wxListEvent
&);
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 ),
381 #endif // wxUSE_LISTCTRL
384 // _WX_LISTCTRL_H_BASE_