1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxListCtrl class
4 // Author: Vadim Zeitlin
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_LISTBASE_H_BASE_
13 #define _WX_LISTBASE_H_BASE_
19 #include "wx/colour.h"
21 #include "wx/gdicmn.h"
25 // ----------------------------------------------------------------------------
27 // ----------------------------------------------------------------------------
29 // type of compare function for wxListCtrl sort operation
30 typedef int (wxCALLBACK
*wxListCtrlCompare
)(long item1
, long item2
, long sortData
);
32 // ----------------------------------------------------------------------------
33 // wxListCtrl constants
34 // ----------------------------------------------------------------------------
37 #define wxLC_VRULES 0x0001
38 #define wxLC_HRULES 0x0002
40 #define wxLC_ICON 0x0004
41 #define wxLC_SMALL_ICON 0x0008
42 #define wxLC_LIST 0x0010
43 #define wxLC_REPORT 0x0020
45 #define wxLC_ALIGN_TOP 0x0040
46 #define wxLC_ALIGN_LEFT 0x0080
47 #define wxLC_AUTOARRANGE 0x0100
48 #define wxLC_VIRTUAL 0x0200
49 #define wxLC_EDIT_LABELS 0x0400
50 #define wxLC_NO_HEADER 0x0800
51 #define wxLC_NO_SORT_HEADER 0x1000
52 #define wxLC_SINGLE_SEL 0x2000
53 #define wxLC_SORT_ASCENDING 0x4000
54 #define wxLC_SORT_DESCENDING 0x8000
56 #define wxLC_MASK_TYPE (wxLC_ICON | wxLC_SMALL_ICON | wxLC_LIST | wxLC_REPORT)
57 #define wxLC_MASK_ALIGN (wxLC_ALIGN_TOP | wxLC_ALIGN_LEFT)
58 #define wxLC_MASK_SORT (wxLC_SORT_ASCENDING | wxLC_SORT_DESCENDING)
60 // for compatibility only
61 #define wxLC_USER_TEXT wxLC_VIRTUAL
64 // (a) too much detail
65 // (b) not enough style flags
66 // (c) not implemented anyhow in the generic version
68 // #define wxLC_NO_SCROLL
69 // #define wxLC_NO_LABEL_WRAP
70 // #define wxLC_OWNERDRAW_FIXED
71 // #define wxLC_SHOW_SEL_ALWAYS
73 // Mask flags to tell app/GUI what fields of wxListItem are valid
74 #define wxLIST_MASK_STATE 0x0001
75 #define wxLIST_MASK_TEXT 0x0002
76 #define wxLIST_MASK_IMAGE 0x0004
77 #define wxLIST_MASK_DATA 0x0008
78 #define wxLIST_SET_ITEM 0x0010
79 #define wxLIST_MASK_WIDTH 0x0020
80 #define wxLIST_MASK_FORMAT 0x0040
82 // State flags for indicating the state of an item
83 #define wxLIST_STATE_DONTCARE 0x0000
84 #define wxLIST_STATE_DROPHILITED 0x0001 // MSW only
85 #define wxLIST_STATE_FOCUSED 0x0002
86 #define wxLIST_STATE_SELECTED 0x0004
87 #define wxLIST_STATE_CUT 0x0008 // MSW only
88 #define wxLIST_STATE_DISABLED 0x0010 // OS2 only
89 #define wxLIST_STATE_FILTERED 0x0020 // OS2 only
90 #define wxLIST_STATE_INUSE 0x0040 // OS2 only
91 #define wxLIST_STATE_PICKED 0x0080 // OS2 only
92 #define wxLIST_STATE_SOURCE 0x0100 // OS2 only
94 // Hit test flags, used in HitTest
95 #define wxLIST_HITTEST_ABOVE 0x0001 // Above the client area.
96 #define wxLIST_HITTEST_BELOW 0x0002 // Below the client area.
97 #define wxLIST_HITTEST_NOWHERE 0x0004 // In the client area but below the last item.
98 #define wxLIST_HITTEST_ONITEMICON 0x0020 // On the bitmap associated with an item.
99 #define wxLIST_HITTEST_ONITEMLABEL 0x0080 // On the label (string) associated with an item.
100 #define wxLIST_HITTEST_ONITEMRIGHT 0x0100 // In the area to the right of an item.
101 #define wxLIST_HITTEST_ONITEMSTATEICON 0x0200 // On the state icon for a tree view item that is in a user-defined state.
102 #define wxLIST_HITTEST_TOLEFT 0x0400 // To the left of the client area.
103 #define wxLIST_HITTEST_TORIGHT 0x0800 // To the right of the client area.
105 #define wxLIST_HITTEST_ONITEM (wxLIST_HITTEST_ONITEMICON | wxLIST_HITTEST_ONITEMLABEL | wxLIST_HITTEST_ONITEMSTATEICON)
107 // Flags for GetNextItem (MSW only except wxLIST_NEXT_ALL)
110 wxLIST_NEXT_ABOVE
, // Searches for an item above the specified item
111 wxLIST_NEXT_ALL
, // Searches for subsequent item by index
112 wxLIST_NEXT_BELOW
, // Searches for an item below the specified item
113 wxLIST_NEXT_LEFT
, // Searches for an item to the left of the specified item
114 wxLIST_NEXT_RIGHT
// Searches for an item to the right of the specified item
117 // Alignment flags for Arrange (MSW only except wxLIST_ALIGN_LEFT)
120 wxLIST_ALIGN_DEFAULT
,
123 wxLIST_ALIGN_SNAP_TO_GRID
126 // Column format (MSW only except wxLIST_FORMAT_LEFT)
127 enum wxListColumnFormat
131 wxLIST_FORMAT_CENTRE
,
132 wxLIST_FORMAT_CENTER
= wxLIST_FORMAT_CENTRE
135 // Autosize values for SetColumnWidth
138 wxLIST_AUTOSIZE
= -1,
139 wxLIST_AUTOSIZE_USEHEADER
= -2 // partly supported by generic version
142 // Flag values for GetItemRect
150 // Flag values for FindItem (MSW only)
159 // ----------------------------------------------------------------------------
160 // wxListItemAttr: a structure containing the visual attributes of an item
161 // ----------------------------------------------------------------------------
163 // TODO: this should be renamed to wxItemAttr or something general like this
164 // and used as base class for wxTextAttr which duplicates this class
165 // entirely currently
166 class WXDLLEXPORT wxListItemAttr
171 wxListItemAttr(const wxColour
& colText
,
172 const wxColour
& colBack
,
174 : m_colText(colText
), m_colBack(colBack
), m_font(font
)
178 // default copy ctor, assignment operator and dtor are ok
182 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
183 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
184 void SetFont(const wxFont
& font
) { m_font
= font
; }
187 bool HasTextColour() const { return m_colText
.Ok(); }
188 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
189 bool HasFont() const { return m_font
.Ok(); }
191 const wxColour
& GetTextColour() const { return m_colText
; }
192 const wxColour
& GetBackgroundColour() const { return m_colBack
; }
193 const wxFont
& GetFont() const { return m_font
; }
196 // this is almost like assignment operator except it doesn't overwrite the
197 // fields unset in the source attribute
198 void AssignFrom(const wxListItemAttr
& source
)
200 if ( source
.HasTextColour() )
201 SetTextColour(source
.GetTextColour());
202 if ( source
.HasBackgroundColour() )
203 SetBackgroundColour(source
.GetBackgroundColour());
204 if ( source
.HasFont() )
205 SetFont(source
.GetFont());
214 // ----------------------------------------------------------------------------
215 // wxListItem: the item or column info, used to exchange data with wxListCtrl
216 // ----------------------------------------------------------------------------
218 class WXDLLEXPORT wxListItem
: public wxObject
221 wxListItem() { Init(); m_attr
= NULL
; }
222 wxListItem(const wxListItem
& item
)
225 m_itemId(item
.m_itemId
),
227 m_state(item
.m_state
),
228 m_stateMask(item
.m_stateMask
),
230 m_image(item
.m_image
),
232 m_format(item
.m_format
),
233 m_width(item
.m_width
),
236 // copy list item attributes
237 if ( item
.HasAttributes() )
238 m_attr
= new wxListItemAttr(*item
.GetAttributes());
240 virtual ~wxListItem() { delete m_attr
; }
243 void Clear() { Init(); m_text
.clear(); ClearAttributes(); }
244 void ClearAttributes() { if ( m_attr
) { delete m_attr
; m_attr
= NULL
; } }
247 void SetMask(long mask
)
251 void SetColumn(int col
)
253 void SetState(long state
)
254 { m_mask
|= wxLIST_MASK_STATE
; m_state
= state
; m_stateMask
|= state
; }
255 void SetStateMask(long stateMask
)
256 { m_stateMask
= stateMask
; }
257 void SetText(const wxString
& text
)
258 { m_mask
|= wxLIST_MASK_TEXT
; m_text
= text
; }
259 void SetImage(int image
)
260 { m_mask
|= wxLIST_MASK_IMAGE
; m_image
= image
; }
261 void SetData(long data
)
262 { m_mask
|= wxLIST_MASK_DATA
; m_data
= data
; }
263 void SetData(void *data
)
264 { m_mask
|= wxLIST_MASK_DATA
; m_data
= wxPtrToUInt(data
); }
266 void SetWidth(int width
)
267 { m_mask
|= wxLIST_MASK_WIDTH
; m_width
= width
; }
268 void SetAlign(wxListColumnFormat align
)
269 { m_mask
|= wxLIST_MASK_FORMAT
; m_format
= align
; }
271 void SetTextColour(const wxColour
& colText
)
272 { Attributes().SetTextColour(colText
); }
273 void SetBackgroundColour(const wxColour
& colBack
)
274 { Attributes().SetBackgroundColour(colBack
); }
275 void SetFont(const wxFont
& font
)
276 { Attributes().SetFont(font
); }
279 long GetMask() const { return m_mask
; }
280 long GetId() const { return m_itemId
; }
281 int GetColumn() const { return m_col
; }
282 long GetState() const { return m_state
& m_stateMask
; }
283 const wxString
& GetText() const { return m_text
; }
284 int GetImage() const { return m_image
; }
285 wxUIntPtr
GetData() const { return m_data
; }
287 int GetWidth() const { return m_width
; }
288 wxListColumnFormat
GetAlign() const { return (wxListColumnFormat
)m_format
; }
290 wxListItemAttr
*GetAttributes() const { return m_attr
; }
291 bool HasAttributes() const { return m_attr
!= NULL
; }
293 wxColour
GetTextColour() const
294 { return HasAttributes() ? m_attr
->GetTextColour() : wxNullColour
; }
295 wxColour
GetBackgroundColour() const
296 { return HasAttributes() ? m_attr
->GetBackgroundColour()
298 wxFont
GetFont() const
299 { return HasAttributes() ? m_attr
->GetFont() : wxNullFont
; }
301 // this conversion is necessary to make old code using GetItem() to
303 operator long() const { return m_itemId
; }
305 // these members are public for compatibility
307 long m_mask
; // Indicates what fields are valid
308 long m_itemId
; // The zero-based item position
309 int m_col
; // Zero-based column, if in report mode
310 long m_state
; // The state of the item
311 long m_stateMask
;// Which flags of m_state are valid (uses same flags)
312 wxString m_text
; // The label/header text
313 int m_image
; // The zero-based index into an image list
314 wxUIntPtr m_data
; // App-defined data
317 int m_format
; // left, right, centre
318 int m_width
; // width of column
321 int m_miniImage
; // handle to the mini image for OS/2
325 // creates m_attr if we don't have it yet
326 wxListItemAttr
& Attributes()
329 m_attr
= new wxListItemAttr
;
344 m_format
= wxLIST_FORMAT_CENTRE
;
348 wxListItemAttr
*m_attr
; // optional pointer to the items style
351 // VZ: this is strange, we have a copy ctor but not operator=(), why?
352 wxListItem
& operator=(const wxListItem
& item
);
354 DECLARE_DYNAMIC_CLASS(wxListItem
)
357 // ----------------------------------------------------------------------------
358 // wxListEvent - the event class for the wxListCtrl notifications
359 // ----------------------------------------------------------------------------
361 class WXDLLEXPORT wxListEvent
: public wxNotifyEvent
364 wxListEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0)
365 : wxNotifyEvent(commandType
, winid
)
372 , m_editCancelled(false)
375 wxListEvent(const wxListEvent
& event
)
376 : wxNotifyEvent(event
)
377 , m_code(event
.m_code
)
378 , m_oldItemIndex(event
.m_oldItemIndex
)
379 , m_itemIndex(event
.m_itemIndex
)
381 , m_pointDrag(event
.m_pointDrag
)
382 , m_item(event
.m_item
)
383 , m_editCancelled(event
.m_editCancelled
)
386 int GetKeyCode() const { return m_code
; }
387 long GetIndex() const { return m_itemIndex
; }
388 int GetColumn() const { return m_col
; }
389 wxPoint
GetPoint() const { return m_pointDrag
; }
390 const wxString
& GetLabel() const { return m_item
.m_text
; }
391 const wxString
& GetText() const { return m_item
.m_text
; }
392 int GetImage() const { return m_item
.m_image
; }
393 long GetData() const { return wx_static_cast(long, m_item
.m_data
); }
394 long GetMask() const { return m_item
.m_mask
; }
395 const wxListItem
& GetItem() const { return m_item
; }
397 // for wxEVT_COMMAND_LIST_CACHE_HINT only
398 long GetCacheFrom() const { return m_oldItemIndex
; }
399 long GetCacheTo() const { return m_itemIndex
; }
401 // was label editing canceled? (for wxEVT_COMMAND_LIST_END_LABEL_EDIT only)
402 bool IsEditCancelled() const { return m_editCancelled
; }
403 void SetEditCanceled(bool editCancelled
) { m_editCancelled
= editCancelled
; }
405 virtual wxEvent
*Clone() const { return new wxListEvent(*this); }
407 //protected: -- not for backwards compatibility
409 long m_oldItemIndex
; // only for wxEVT_COMMAND_LIST_CACHE_HINT
417 bool m_editCancelled
;
420 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxListEvent
)
423 // ----------------------------------------------------------------------------
424 // wxListCtrl event macros
425 // ----------------------------------------------------------------------------
427 BEGIN_DECLARE_EVENT_TYPES()
428 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
, 700)
429 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
, 701)
430 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, 702)
431 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
, 703)
432 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
, 704)
433 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, 705)
434 #if WXWIN_COMPATIBILITY_2_4
435 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
, 706)
436 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
, 707)
438 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
, 708)
439 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
, 709)
440 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
, 710)
441 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
, 711)
442 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
, 712)
443 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, 713)
444 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
, 714)
445 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, 715)
446 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
, 716)
447 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
, 717)
448 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
, 718)
449 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING
, 719)
450 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG
, 720)
451 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED
, 721)
452 END_DECLARE_EVENT_TYPES()
454 typedef void (wxEvtHandler::*wxListEventFunction
)(wxListEvent
&);
456 #define wxListEventHandler(func) \
457 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxListEventFunction, &func)
459 #define wx__DECLARE_LISTEVT(evt, id, fn) \
460 wx__DECLARE_EVT1(wxEVT_COMMAND_LIST_ ## evt, id, wxListEventHandler(fn))
462 #define EVT_LIST_BEGIN_DRAG(id, fn) wx__DECLARE_LISTEVT(BEGIN_DRAG, id, fn)
463 #define EVT_LIST_BEGIN_RDRAG(id, fn) wx__DECLARE_LISTEVT(BEGIN_RDRAG, id, fn)
464 #define EVT_LIST_BEGIN_LABEL_EDIT(id, fn) wx__DECLARE_LISTEVT(BEGIN_LABEL_EDIT, id, fn)
465 #define EVT_LIST_END_LABEL_EDIT(id, fn) wx__DECLARE_LISTEVT(END_LABEL_EDIT, id, fn)
466 #define EVT_LIST_DELETE_ITEM(id, fn) wx__DECLARE_LISTEVT(DELETE_ITEM, id, fn)
467 #define EVT_LIST_DELETE_ALL_ITEMS(id, fn) wx__DECLARE_LISTEVT(DELETE_ALL_ITEMS, id, fn)
468 #define EVT_LIST_KEY_DOWN(id, fn) wx__DECLARE_LISTEVT(KEY_DOWN, id, fn)
469 #define EVT_LIST_INSERT_ITEM(id, fn) wx__DECLARE_LISTEVT(INSERT_ITEM, id, fn)
471 #define EVT_LIST_COL_CLICK(id, fn) wx__DECLARE_LISTEVT(COL_CLICK, id, fn)
472 #define EVT_LIST_COL_RIGHT_CLICK(id, fn) wx__DECLARE_LISTEVT(COL_RIGHT_CLICK, id, fn)
473 #define EVT_LIST_COL_BEGIN_DRAG(id, fn) wx__DECLARE_LISTEVT(COL_BEGIN_DRAG, id, fn)
474 #define EVT_LIST_COL_DRAGGING(id, fn) wx__DECLARE_LISTEVT(COL_DRAGGING, id, fn)
475 #define EVT_LIST_COL_END_DRAG(id, fn) wx__DECLARE_LISTEVT(COL_END_DRAG, id, fn)
477 #define EVT_LIST_ITEM_SELECTED(id, fn) wx__DECLARE_LISTEVT(ITEM_SELECTED, id, fn)
478 #define EVT_LIST_ITEM_DESELECTED(id, fn) wx__DECLARE_LISTEVT(ITEM_DESELECTED, id, fn)
479 #define EVT_LIST_ITEM_RIGHT_CLICK(id, fn) wx__DECLARE_LISTEVT(ITEM_RIGHT_CLICK, id, fn)
480 #define EVT_LIST_ITEM_MIDDLE_CLICK(id, fn) wx__DECLARE_LISTEVT(ITEM_MIDDLE_CLICK, id, fn)
481 #define EVT_LIST_ITEM_ACTIVATED(id, fn) wx__DECLARE_LISTEVT(ITEM_ACTIVATED, id, fn)
482 #define EVT_LIST_ITEM_FOCUSED(id, fn) wx__DECLARE_LISTEVT(ITEM_FOCUSED, id, fn)
484 #define EVT_LIST_CACHE_HINT(id, fn) wx__DECLARE_LISTEVT(CACHE_HINT, id, fn)
487 #if WXWIN_COMPATIBILITY_2_4
488 #define EVT_LIST_GET_INFO(id, fn) wx__DECLARE_LISTEVT(GET_INFO, id, fn)
489 #define EVT_LIST_SET_INFO(id, fn) wx__DECLARE_LISTEVT(SET_INFO, id, fn)
492 #endif // wxUSE_LISTCTRL
495 // _WX_LISTCTRL_H_BASE_