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"
23 // ----------------------------------------------------------------------------
25 // ----------------------------------------------------------------------------
27 // type of compare function for wxListCtrl sort operation
28 typedef int (wxCALLBACK
*wxListCtrlCompare
)(long item1
, long item2
, long sortData
);
30 // ----------------------------------------------------------------------------
31 // wxListCtrl constants
32 // ----------------------------------------------------------------------------
35 #define wxLC_VRULES 0x0001
36 #define wxLC_HRULES 0x0002
38 #define wxLC_ICON 0x0004
39 #define wxLC_SMALL_ICON 0x0008
40 #define wxLC_LIST 0x0010
41 #define wxLC_REPORT 0x0020
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
86 #define wxLIST_STATE_DISABLED 0x0010 // OS2 only
87 #define wxLIST_STATE_FILTERED 0x0020 // OS2 only
88 #define wxLIST_STATE_INUSE 0x0040 // OS2 only
89 #define wxLIST_STATE_PICKED 0x0080 // OS2 only
90 #define wxLIST_STATE_SOURCE 0x0100 // OS2 only
92 // Hit test flags, used in HitTest
93 #define wxLIST_HITTEST_ABOVE 0x0001 // Above the client area.
94 #define wxLIST_HITTEST_BELOW 0x0002 // Below the client area.
95 #define wxLIST_HITTEST_NOWHERE 0x0004 // In the client area but below the last item.
96 #define wxLIST_HITTEST_ONITEMICON 0x0020 // On the bitmap associated with an item.
97 #define wxLIST_HITTEST_ONITEMLABEL 0x0080 // On the label (string) associated with an item.
98 #define wxLIST_HITTEST_ONITEMRIGHT 0x0100 // In the area to the right of an item.
99 #define wxLIST_HITTEST_ONITEMSTATEICON 0x0200 // On the state icon for a tree view item that is in a user-defined state.
100 #define wxLIST_HITTEST_TOLEFT 0x0400 // To the left of the client area.
101 #define wxLIST_HITTEST_TORIGHT 0x0800 // To the right of the client area.
103 #define wxLIST_HITTEST_ONITEM (wxLIST_HITTEST_ONITEMICON | wxLIST_HITTEST_ONITEMLABEL | wxLIST_HITTEST_ONITEMSTATEICON)
105 // Flags for GetNextItem (MSW only except wxLIST_NEXT_ALL)
108 wxLIST_NEXT_ABOVE
, // Searches for an item above the specified item
109 wxLIST_NEXT_ALL
, // Searches for subsequent item by index
110 wxLIST_NEXT_BELOW
, // Searches for an item below the specified item
111 wxLIST_NEXT_LEFT
, // Searches for an item to the left of the specified item
112 wxLIST_NEXT_RIGHT
// Searches for an item to the right of the specified item
115 // Alignment flags for Arrange (MSW only except wxLIST_ALIGN_LEFT)
118 wxLIST_ALIGN_DEFAULT
,
121 wxLIST_ALIGN_SNAP_TO_GRID
124 // Column format (MSW only except wxLIST_FORMAT_LEFT)
125 enum wxListColumnFormat
129 wxLIST_FORMAT_CENTRE
,
130 wxLIST_FORMAT_CENTER
= wxLIST_FORMAT_CENTRE
133 // Autosize values for SetColumnWidth
136 wxLIST_AUTOSIZE
= -1,
137 wxLIST_AUTOSIZE_USEHEADER
= -2 // partly supported by generic version
140 // Flag values for GetItemRect
148 // Flag values for FindItem (MSW only)
157 // ----------------------------------------------------------------------------
158 // wxListItemAttr: a structure containing the visual attributes of an item
159 // ----------------------------------------------------------------------------
161 class WXDLLEXPORT wxListItemAttr
166 wxListItemAttr(const wxColour
& colText
,
167 const wxColour
& colBack
,
169 : m_colText(colText
), m_colBack(colBack
), m_font(font
) { }
172 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
173 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
174 void SetFont(const wxFont
& font
) { m_font
= font
; }
177 bool HasTextColour() const { return m_colText
.Ok(); }
178 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
179 bool HasFont() const { return m_font
.Ok(); }
181 const wxColour
& GetTextColour() const { return m_colText
; }
182 const wxColour
& GetBackgroundColour() const { return m_colBack
; }
183 const wxFont
& GetFont() const { return m_font
; }
191 // ----------------------------------------------------------------------------
192 // wxListItem: the item or column info, used to exchange data with wxListCtrl
193 // ----------------------------------------------------------------------------
195 class WXDLLEXPORT wxListItem
: public wxObject
198 wxListItem() { Init(); m_attr
= NULL
; }
199 wxListItem(const wxListItem
& item
)
202 m_itemId(item
.m_itemId
),
204 m_state(item
.m_state
),
205 m_stateMask(item
.m_stateMask
),
207 m_image(item
.m_image
),
209 m_format(item
.m_format
),
210 m_width(item
.m_width
),
213 // copy list item attributes
214 if( item
.HasAttributes() )
215 m_attr
= new wxListItemAttr(*item
.GetAttributes());
217 virtual ~wxListItem() { delete m_attr
; }
220 void Clear() { Init(); m_text
.clear(); ClearAttributes(); }
221 void ClearAttributes() { if ( m_attr
) { delete m_attr
; m_attr
= NULL
; } }
224 void SetMask(long mask
)
228 void SetColumn(int col
)
230 void SetState(long state
)
231 { m_mask
|= wxLIST_MASK_STATE
; m_state
= state
; m_stateMask
|= state
; }
232 void SetStateMask(long stateMask
)
233 { m_stateMask
= stateMask
; }
234 void SetText(const wxString
& text
)
235 { m_mask
|= wxLIST_MASK_TEXT
; m_text
= text
; }
236 void SetImage(int image
)
237 { m_mask
|= wxLIST_MASK_IMAGE
; m_image
= image
; }
238 void SetData(long data
)
239 { m_mask
|= wxLIST_MASK_DATA
; m_data
= data
; }
240 void SetData(void *data
)
241 { m_mask
|= wxLIST_MASK_DATA
; m_data
= (long)data
; }
243 void SetWidth(int width
)
244 { m_mask
|= wxLIST_MASK_WIDTH
; m_width
= width
; }
245 void SetAlign(wxListColumnFormat align
)
246 { m_mask
|= wxLIST_MASK_FORMAT
; m_format
= align
; }
248 void SetTextColour(const wxColour
& colText
)
249 { Attributes().SetTextColour(colText
); }
250 void SetBackgroundColour(const wxColour
& colBack
)
251 { Attributes().SetBackgroundColour(colBack
); }
252 void SetFont(const wxFont
& font
)
253 { Attributes().SetFont(font
); }
256 long GetMask() const { return m_mask
; }
257 long GetId() const { return m_itemId
; }
258 int GetColumn() const { return m_col
; }
259 long GetState() const { return m_state
& m_stateMask
; }
260 const wxString
& GetText() const { return m_text
; }
261 int GetImage() const { return m_image
; }
262 long GetData() const { return m_data
; }
264 int GetWidth() const { return m_width
; }
265 wxListColumnFormat
GetAlign() const { return (wxListColumnFormat
)m_format
; }
267 wxListItemAttr
*GetAttributes() const { return m_attr
; }
268 bool HasAttributes() const { return m_attr
!= NULL
; }
270 wxColour
GetTextColour() const
271 { return HasAttributes() ? m_attr
->GetTextColour() : wxNullColour
; }
272 wxColour
GetBackgroundColour() const
273 { return HasAttributes() ? m_attr
->GetBackgroundColour()
275 wxFont
GetFont() const
276 { return HasAttributes() ? m_attr
->GetFont() : wxNullFont
; }
278 // this conversion is necessary to make old code using GetItem() to
280 operator long() const { return m_itemId
; }
282 // these members are public for compatibility
284 long m_mask
; // Indicates what fields are valid
285 long m_itemId
; // The zero-based item position
286 int m_col
; // Zero-based column, if in report mode
287 long m_state
; // The state of the item
288 long m_stateMask
;// Which flags of m_state are valid (uses same flags)
289 wxString m_text
; // The label/header text
290 int m_image
; // The zero-based index into an image list
291 long m_data
; // App-defined data
294 int m_format
; // left, right, centre
295 int m_width
; // width of column
298 int m_miniImage
; // handle to the mini image for OS/2
302 // creates m_attr if we don't have it yet
303 wxListItemAttr
& Attributes()
306 m_attr
= new wxListItemAttr
;
321 m_format
= wxLIST_FORMAT_CENTRE
;
325 wxListItemAttr
*m_attr
; // optional pointer to the items style
328 // VZ: this is strange, we have a copy ctor but not operator=(), why?
329 wxListItem
& operator=(const wxListItem
& item
);
331 DECLARE_DYNAMIC_CLASS(wxListItem
)
334 // ----------------------------------------------------------------------------
335 // wxListEvent - the event class for the wxListCtrl notifications
336 // ----------------------------------------------------------------------------
338 class WXDLLEXPORT wxListEvent
: public wxNotifyEvent
341 wxListEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0)
342 : wxNotifyEvent(commandType
, id
)
351 wxListEvent(const wxListEvent
& event
)
352 : wxNotifyEvent(event
)
353 , m_code(event
.m_code
)
354 , m_oldItemIndex(event
.m_oldItemIndex
)
355 , m_itemIndex(event
.m_itemIndex
)
357 , m_pointDrag(event
.m_pointDrag
)
358 , m_item(event
.m_item
)
361 int GetKeyCode() const { return m_code
; }
362 long GetIndex() const { return m_itemIndex
; }
363 int GetColumn() const { return m_col
; }
364 wxPoint
GetPoint() const { return m_pointDrag
; }
365 const wxString
& GetLabel() const { return m_item
.m_text
; }
366 const wxString
& GetText() const { return m_item
.m_text
; }
367 int GetImage() const { return m_item
.m_image
; }
368 long GetData() const { return m_item
.m_data
; }
369 long GetMask() const { return m_item
.m_mask
; }
370 const wxListItem
& GetItem() const { return m_item
; }
372 // for wxEVT_COMMAND_LIST_CACHE_HINT only
373 long GetCacheFrom() const { return m_oldItemIndex
; }
374 long GetCacheTo() const { return m_itemIndex
; }
376 #if WXWIN_COMPATIBILITY_2_2
377 // these methods don't do anything at all
378 long GetOldIndex() const { return 0; }
379 long GetOldItem() const { return 0; }
381 // this one is superseded by GetKeyCode()
382 int GetCode() const { return GetKeyCode(); }
383 #endif // WXWIN_COMPATIBILITY_2_2
385 virtual wxEvent
*Clone() const { return new wxListEvent(*this); }
387 //protected: -- not for backwards compatibility
389 long m_oldItemIndex
; // only for wxEVT_COMMAND_LIST_CACHE_HINT
397 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxListEvent
)
400 // ----------------------------------------------------------------------------
401 // wxListCtrl event macros
402 // ----------------------------------------------------------------------------
404 BEGIN_DECLARE_EVENT_TYPES()
405 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
, 700)
406 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
, 701)
407 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, 702)
408 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
, 703)
409 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
, 704)
410 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, 705)
411 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
, 706)
412 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
, 707)
413 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
, 708)
414 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
, 709)
415 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
, 710)
416 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
, 711)
417 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
, 712)
418 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, 713)
419 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
, 714)
420 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, 715)
421 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
, 716)
422 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
, 717)
423 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
, 718)
424 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING
, 719)
425 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG
, 720)
426 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED
, 721)
427 END_DECLARE_EVENT_TYPES()
429 typedef void (wxEvtHandler::*wxListEventFunction
)(wxListEvent
&);
431 #define EVT_LIST_BEGIN_DRAG(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
432 #define EVT_LIST_BEGIN_RDRAG(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
433 #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 ),
434 #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 ),
435 #define EVT_LIST_DELETE_ITEM(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_DELETE_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
436 #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 ),
437 #define EVT_LIST_GET_INFO(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_GET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
438 #define EVT_LIST_SET_INFO(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_SET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
439 #define EVT_LIST_KEY_DOWN(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
440 #define EVT_LIST_INSERT_ITEM(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_INSERT_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
442 #define EVT_LIST_COL_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_COL_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
443 #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 ),
444 #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 ),
445 #define EVT_LIST_COL_DRAGGING(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_COL_DRAGGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
446 #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 ),
448 #define EVT_LIST_ITEM_SELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_SELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
449 #define EVT_LIST_ITEM_DESELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_DESELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
450 #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 ),
451 #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 ),
452 #define EVT_LIST_ITEM_ACTIVATED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL ),
453 #define EVT_LIST_ITEM_FOCUSED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_FOCUSED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL ),
455 #define EVT_LIST_CACHE_HINT(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_CACHE_HINT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL ),
457 #endif // wxUSE_LISTCTRL
460 // _WX_LISTCTRL_H_BASE_