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_
15 #include "wx/colour.h"
17 #include "wx/gdicmn.h"
20 // ----------------------------------------------------------------------------
22 // ----------------------------------------------------------------------------
24 // type of compare function for wxListCtrl sort operation
25 typedef int (wxCALLBACK
*wxListCtrlCompare
)(long item1
, long item2
, long sortData
);
27 // ----------------------------------------------------------------------------
28 // wxListCtrl constants
29 // ----------------------------------------------------------------------------
32 #define wxLC_VRULES 0x0001
33 #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
40 #define wxLC_ALIGN_TOP 0x0040
41 #define wxLC_ALIGN_LEFT 0x0080
42 #define wxLC_AUTOARRANGE 0x0100
43 #define wxLC_VIRTUAL 0x0200
44 #define wxLC_EDIT_LABELS 0x0400
45 #define wxLC_NO_HEADER 0x0800
46 #define wxLC_NO_SORT_HEADER 0x1000
47 #define wxLC_SINGLE_SEL 0x2000
48 #define wxLC_SORT_ASCENDING 0x4000
49 #define wxLC_SORT_DESCENDING 0x8000
51 #define wxLC_MASK_TYPE (wxLC_ICON | wxLC_SMALL_ICON | wxLC_LIST | wxLC_REPORT)
52 #define wxLC_MASK_ALIGN (wxLC_ALIGN_TOP | wxLC_ALIGN_LEFT)
53 #define wxLC_MASK_SORT (wxLC_SORT_ASCENDING | wxLC_SORT_DESCENDING)
55 // for compatibility only
56 #define wxLC_USER_TEXT wxLC_VIRTUAL
59 // (a) too much detail
60 // (b) not enough style flags
61 // (c) not implemented anyhow in the generic version
63 // #define wxLC_NO_SCROLL
64 // #define wxLC_NO_LABEL_WRAP
65 // #define wxLC_OWNERDRAW_FIXED
66 // #define wxLC_SHOW_SEL_ALWAYS
68 // Mask flags to tell app/GUI what fields of wxListItem are valid
69 #define wxLIST_MASK_STATE 0x0001
70 #define wxLIST_MASK_TEXT 0x0002
71 #define wxLIST_MASK_IMAGE 0x0004
72 #define wxLIST_MASK_DATA 0x0008
73 #define wxLIST_SET_ITEM 0x0010
74 #define wxLIST_MASK_WIDTH 0x0020
75 #define wxLIST_MASK_FORMAT 0x0040
77 // State flags for indicating the state of an item
78 #define wxLIST_STATE_DONTCARE 0x0000
79 #define wxLIST_STATE_DROPHILITED 0x0001 // MSW only
80 #define wxLIST_STATE_FOCUSED 0x0002
81 #define wxLIST_STATE_SELECTED 0x0004
82 #define wxLIST_STATE_CUT 0x0008 // MSW only
83 #define wxLIST_STATE_DISABLED 0x0010 // OS2 only
84 #define wxLIST_STATE_FILTERED 0x0020 // OS2 only
85 #define wxLIST_STATE_INUSE 0x0040 // OS2 only
86 #define wxLIST_STATE_PICKED 0x0080 // OS2 only
87 #define wxLIST_STATE_SOURCE 0x0100 // OS2 only
89 // Hit test flags, used in HitTest
90 #define wxLIST_HITTEST_ABOVE 0x0001 // Above the client area.
91 #define wxLIST_HITTEST_BELOW 0x0002 // Below the client area.
92 #define wxLIST_HITTEST_NOWHERE 0x0004 // In the client area but below the last item.
93 #define wxLIST_HITTEST_ONITEMICON 0x0020 // On the bitmap associated with an item.
94 #define wxLIST_HITTEST_ONITEMLABEL 0x0080 // On the label (string) associated with an item.
95 #define wxLIST_HITTEST_ONITEMRIGHT 0x0100 // In the area to the right of an item.
96 #define wxLIST_HITTEST_ONITEMSTATEICON 0x0200 // On the state icon for a tree view item that is in a user-defined state.
97 #define wxLIST_HITTEST_TOLEFT 0x0400 // To the left of the client area.
98 #define wxLIST_HITTEST_TORIGHT 0x0800 // To the right of the client area.
100 #define wxLIST_HITTEST_ONITEM (wxLIST_HITTEST_ONITEMICON | wxLIST_HITTEST_ONITEMLABEL | wxLIST_HITTEST_ONITEMSTATEICON)
102 // GetSubItemRect constants
103 #define wxLIST_GETSUBITEMRECT_WHOLEITEM -1l
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 // TODO: this should be renamed to wxItemAttr or something general like this
162 // and used as base class for wxTextAttr which duplicates this class
163 // entirely currently
164 class WXDLLEXPORT wxListItemAttr
169 wxListItemAttr(const wxColour
& colText
,
170 const wxColour
& colBack
,
172 : m_colText(colText
), m_colBack(colBack
), m_font(font
)
176 // default copy ctor, assignment operator and dtor are ok
180 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
181 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
182 void SetFont(const wxFont
& font
) { m_font
= font
; }
185 bool HasTextColour() const { return m_colText
.Ok(); }
186 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
187 bool HasFont() const { return m_font
.Ok(); }
189 const wxColour
& GetTextColour() const { return m_colText
; }
190 const wxColour
& GetBackgroundColour() const { return m_colBack
; }
191 const wxFont
& GetFont() const { return m_font
; }
194 // this is almost like assignment operator except it doesn't overwrite the
195 // fields unset in the source attribute
196 void AssignFrom(const wxListItemAttr
& source
)
198 if ( source
.HasTextColour() )
199 SetTextColour(source
.GetTextColour());
200 if ( source
.HasBackgroundColour() )
201 SetBackgroundColour(source
.GetBackgroundColour());
202 if ( source
.HasFont() )
203 SetFont(source
.GetFont());
212 // ----------------------------------------------------------------------------
213 // wxListItem: the item or column info, used to exchange data with wxListCtrl
214 // ----------------------------------------------------------------------------
216 class WXDLLEXPORT wxListItem
: public wxObject
219 wxListItem() { Init(); m_attr
= NULL
; }
220 wxListItem(const wxListItem
& item
)
223 m_itemId(item
.m_itemId
),
225 m_state(item
.m_state
),
226 m_stateMask(item
.m_stateMask
),
228 m_image(item
.m_image
),
230 m_format(item
.m_format
),
231 m_width(item
.m_width
),
234 // copy list item attributes
235 if ( item
.HasAttributes() )
236 m_attr
= new wxListItemAttr(*item
.GetAttributes());
238 virtual ~wxListItem() { delete m_attr
; }
241 void Clear() { Init(); m_text
.clear(); ClearAttributes(); }
242 void ClearAttributes() { if ( m_attr
) { delete m_attr
; m_attr
= NULL
; } }
245 void SetMask(long mask
)
249 void SetColumn(int col
)
251 void SetState(long state
)
252 { m_mask
|= wxLIST_MASK_STATE
; m_state
= state
; m_stateMask
|= state
; }
253 void SetStateMask(long stateMask
)
254 { m_stateMask
= stateMask
; }
255 void SetText(const wxString
& text
)
256 { m_mask
|= wxLIST_MASK_TEXT
; m_text
= text
; }
257 void SetImage(int image
)
258 { m_mask
|= wxLIST_MASK_IMAGE
; m_image
= image
; }
259 void SetData(long data
)
260 { m_mask
|= wxLIST_MASK_DATA
; m_data
= data
; }
261 void SetData(void *data
)
262 { m_mask
|= wxLIST_MASK_DATA
; m_data
= wxPtrToUInt(data
); }
264 void SetWidth(int width
)
265 { m_mask
|= wxLIST_MASK_WIDTH
; m_width
= width
; }
266 void SetAlign(wxListColumnFormat align
)
267 { m_mask
|= wxLIST_MASK_FORMAT
; m_format
= align
; }
269 void SetTextColour(const wxColour
& colText
)
270 { Attributes().SetTextColour(colText
); }
271 void SetBackgroundColour(const wxColour
& colBack
)
272 { Attributes().SetBackgroundColour(colBack
); }
273 void SetFont(const wxFont
& font
)
274 { Attributes().SetFont(font
); }
277 long GetMask() const { return m_mask
; }
278 long GetId() const { return m_itemId
; }
279 int GetColumn() const { return m_col
; }
280 long GetState() const { return m_state
& m_stateMask
; }
281 const wxString
& GetText() const { return m_text
; }
282 int GetImage() const { return m_image
; }
283 wxUIntPtr
GetData() const { return m_data
; }
285 int GetWidth() const { return m_width
; }
286 wxListColumnFormat
GetAlign() const { return (wxListColumnFormat
)m_format
; }
288 wxListItemAttr
*GetAttributes() const { return m_attr
; }
289 bool HasAttributes() const { return m_attr
!= NULL
; }
291 wxColour
GetTextColour() const
292 { return HasAttributes() ? m_attr
->GetTextColour() : wxNullColour
; }
293 wxColour
GetBackgroundColour() const
294 { return HasAttributes() ? m_attr
->GetBackgroundColour()
296 wxFont
GetFont() const
297 { return HasAttributes() ? m_attr
->GetFont() : wxNullFont
; }
299 // this conversion is necessary to make old code using GetItem() to
301 operator long() const { return m_itemId
; }
303 // these members are public for compatibility
305 long m_mask
; // Indicates what fields are valid
306 long m_itemId
; // The zero-based item position
307 int m_col
; // Zero-based column, if in report mode
308 long m_state
; // The state of the item
309 long m_stateMask
;// Which flags of m_state are valid (uses same flags)
310 wxString m_text
; // The label/header text
311 int m_image
; // The zero-based index into an image list
312 wxUIntPtr m_data
; // App-defined data
315 int m_format
; // left, right, centre
316 int m_width
; // width of column
319 int m_miniImage
; // handle to the mini image for OS/2
323 // creates m_attr if we don't have it yet
324 wxListItemAttr
& Attributes()
327 m_attr
= new wxListItemAttr
;
342 m_format
= wxLIST_FORMAT_CENTRE
;
346 wxListItemAttr
*m_attr
; // optional pointer to the items style
349 // VZ: this is strange, we have a copy ctor but not operator=(), why?
350 wxListItem
& operator=(const wxListItem
& item
);
352 DECLARE_DYNAMIC_CLASS(wxListItem
)
355 // ----------------------------------------------------------------------------
356 // wxListEvent - the event class for the wxListCtrl notifications
357 // ----------------------------------------------------------------------------
359 class WXDLLEXPORT wxListEvent
: public wxNotifyEvent
362 wxListEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0)
363 : wxNotifyEvent(commandType
, winid
)
370 , m_editCancelled(false)
373 wxListEvent(const wxListEvent
& event
)
374 : wxNotifyEvent(event
)
375 , m_code(event
.m_code
)
376 , m_oldItemIndex(event
.m_oldItemIndex
)
377 , m_itemIndex(event
.m_itemIndex
)
379 , m_pointDrag(event
.m_pointDrag
)
380 , m_item(event
.m_item
)
381 , m_editCancelled(event
.m_editCancelled
)
384 int GetKeyCode() const { return m_code
; }
385 long GetIndex() const { return m_itemIndex
; }
386 int GetColumn() const { return m_col
; }
387 wxPoint
GetPoint() const { return m_pointDrag
; }
388 const wxString
& GetLabel() const { return m_item
.m_text
; }
389 const wxString
& GetText() const { return m_item
.m_text
; }
390 int GetImage() const { return m_item
.m_image
; }
391 long GetData() const { return wx_static_cast(long, m_item
.m_data
); }
392 long GetMask() const { return m_item
.m_mask
; }
393 const wxListItem
& GetItem() const { return m_item
; }
395 // for wxEVT_COMMAND_LIST_CACHE_HINT only
396 long GetCacheFrom() const { return m_oldItemIndex
; }
397 long GetCacheTo() const { return m_itemIndex
; }
399 // was label editing canceled? (for wxEVT_COMMAND_LIST_END_LABEL_EDIT only)
400 bool IsEditCancelled() const { return m_editCancelled
; }
401 void SetEditCanceled(bool editCancelled
) { m_editCancelled
= editCancelled
; }
403 virtual wxEvent
*Clone() const { return new wxListEvent(*this); }
405 //protected: -- not for backwards compatibility
407 long m_oldItemIndex
; // only for wxEVT_COMMAND_LIST_CACHE_HINT
415 bool m_editCancelled
;
418 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxListEvent
)
421 // ----------------------------------------------------------------------------
422 // wxListCtrl event macros
423 // ----------------------------------------------------------------------------
425 BEGIN_DECLARE_EVENT_TYPES()
426 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
, 700)
427 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
, 701)
428 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, 702)
429 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
, 703)
430 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
, 704)
431 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, 705)
433 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
, 708)
434 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
, 709)
435 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
, 710)
436 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
, 711)
437 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
, 712)
438 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, 713)
439 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
, 714)
440 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, 715)
441 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
, 716)
442 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
, 717)
443 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
, 718)
444 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING
, 719)
445 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG
, 720)
446 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED
, 721)
447 END_DECLARE_EVENT_TYPES()
449 typedef void (wxEvtHandler::*wxListEventFunction
)(wxListEvent
&);
451 #define wxListEventHandler(func) \
452 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxListEventFunction, &func)
454 #define wx__DECLARE_LISTEVT(evt, id, fn) \
455 wx__DECLARE_EVT1(wxEVT_COMMAND_LIST_ ## evt, id, wxListEventHandler(fn))
457 #define EVT_LIST_BEGIN_DRAG(id, fn) wx__DECLARE_LISTEVT(BEGIN_DRAG, id, fn)
458 #define EVT_LIST_BEGIN_RDRAG(id, fn) wx__DECLARE_LISTEVT(BEGIN_RDRAG, id, fn)
459 #define EVT_LIST_BEGIN_LABEL_EDIT(id, fn) wx__DECLARE_LISTEVT(BEGIN_LABEL_EDIT, id, fn)
460 #define EVT_LIST_END_LABEL_EDIT(id, fn) wx__DECLARE_LISTEVT(END_LABEL_EDIT, id, fn)
461 #define EVT_LIST_DELETE_ITEM(id, fn) wx__DECLARE_LISTEVT(DELETE_ITEM, id, fn)
462 #define EVT_LIST_DELETE_ALL_ITEMS(id, fn) wx__DECLARE_LISTEVT(DELETE_ALL_ITEMS, id, fn)
463 #define EVT_LIST_KEY_DOWN(id, fn) wx__DECLARE_LISTEVT(KEY_DOWN, id, fn)
464 #define EVT_LIST_INSERT_ITEM(id, fn) wx__DECLARE_LISTEVT(INSERT_ITEM, id, fn)
466 #define EVT_LIST_COL_CLICK(id, fn) wx__DECLARE_LISTEVT(COL_CLICK, id, fn)
467 #define EVT_LIST_COL_RIGHT_CLICK(id, fn) wx__DECLARE_LISTEVT(COL_RIGHT_CLICK, id, fn)
468 #define EVT_LIST_COL_BEGIN_DRAG(id, fn) wx__DECLARE_LISTEVT(COL_BEGIN_DRAG, id, fn)
469 #define EVT_LIST_COL_DRAGGING(id, fn) wx__DECLARE_LISTEVT(COL_DRAGGING, id, fn)
470 #define EVT_LIST_COL_END_DRAG(id, fn) wx__DECLARE_LISTEVT(COL_END_DRAG, id, fn)
472 #define EVT_LIST_ITEM_SELECTED(id, fn) wx__DECLARE_LISTEVT(ITEM_SELECTED, id, fn)
473 #define EVT_LIST_ITEM_DESELECTED(id, fn) wx__DECLARE_LISTEVT(ITEM_DESELECTED, id, fn)
474 #define EVT_LIST_ITEM_RIGHT_CLICK(id, fn) wx__DECLARE_LISTEVT(ITEM_RIGHT_CLICK, id, fn)
475 #define EVT_LIST_ITEM_MIDDLE_CLICK(id, fn) wx__DECLARE_LISTEVT(ITEM_MIDDLE_CLICK, id, fn)
476 #define EVT_LIST_ITEM_ACTIVATED(id, fn) wx__DECLARE_LISTEVT(ITEM_ACTIVATED, id, fn)
477 #define EVT_LIST_ITEM_FOCUSED(id, fn) wx__DECLARE_LISTEVT(ITEM_FOCUSED, id, fn)
479 #define EVT_LIST_CACHE_HINT(id, fn) wx__DECLARE_LISTEVT(CACHE_HINT, id, fn)
483 // _WX_LISTCTRL_H_BASE_