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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 // #pragma interface "listctrlbase.h"
23 #include "wx/colour.h"
25 #include "wx/gdicmn.h"
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 // type of compare function for wxListCtrl sort operation
34 typedef int (wxCALLBACK
*wxListCtrlCompare
)(long item1
, long item2
, long sortData
);
36 // ----------------------------------------------------------------------------
37 // wxListCtrl constants
38 // ----------------------------------------------------------------------------
41 #define wxLC_VRULES 0x0001
42 #define wxLC_HRULES 0x0002
44 #define wxLC_ICON 0x0004
45 #define wxLC_SMALL_ICON 0x0008
46 #define wxLC_LIST 0x0010
47 #define wxLC_REPORT 0x0020
49 #define wxLC_ALIGN_TOP 0x0040
50 #define wxLC_ALIGN_LEFT 0x0080
51 #define wxLC_AUTOARRANGE 0x0100
52 #define wxLC_VIRTUAL 0x0200
53 #define wxLC_EDIT_LABELS 0x0400
54 #define wxLC_NO_HEADER 0x0800
55 #define wxLC_NO_SORT_HEADER 0x1000
56 #define wxLC_SINGLE_SEL 0x2000
57 #define wxLC_SORT_ASCENDING 0x4000
58 #define wxLC_SORT_DESCENDING 0x8000
60 #define wxLC_MASK_TYPE (wxLC_ICON | wxLC_SMALL_ICON | wxLC_LIST | wxLC_REPORT)
61 #define wxLC_MASK_ALIGN (wxLC_ALIGN_TOP | wxLC_ALIGN_LEFT)
62 #define wxLC_MASK_SORT (wxLC_SORT_ASCENDING | wxLC_SORT_DESCENDING)
64 // for compatibility only
65 #define wxLC_USER_TEXT wxLC_VIRTUAL
68 // (a) too much detail
69 // (b) not enough style flags
70 // (c) not implemented anyhow in the generic version
72 // #define wxLC_NO_SCROLL
73 // #define wxLC_NO_LABEL_WRAP
74 // #define wxLC_OWNERDRAW_FIXED
75 // #define wxLC_SHOW_SEL_ALWAYS
77 // Mask flags to tell app/GUI what fields of wxListItem are valid
78 #define wxLIST_MASK_STATE 0x0001
79 #define wxLIST_MASK_TEXT 0x0002
80 #define wxLIST_MASK_IMAGE 0x0004
81 #define wxLIST_MASK_DATA 0x0008
82 #define wxLIST_SET_ITEM 0x0010
83 #define wxLIST_MASK_WIDTH 0x0020
84 #define wxLIST_MASK_FORMAT 0x0040
86 // State flags for indicating the state of an item
87 #define wxLIST_STATE_DONTCARE 0x0000
88 #define wxLIST_STATE_DROPHILITED 0x0001 // MSW only
89 #define wxLIST_STATE_FOCUSED 0x0002
90 #define wxLIST_STATE_SELECTED 0x0004
91 #define wxLIST_STATE_CUT 0x0008 // MSW only
92 #define wxLIST_STATE_DISABLED 0x0010 // OS2 only
93 #define wxLIST_STATE_FILTERED 0x0020 // OS2 only
94 #define wxLIST_STATE_INUSE 0x0040 // OS2 only
95 #define wxLIST_STATE_PICKED 0x0080 // OS2 only
96 #define wxLIST_STATE_SOURCE 0x0100 // OS2 only
98 // Hit test flags, used in HitTest
99 #define wxLIST_HITTEST_ABOVE 0x0001 // Above the client area.
100 #define wxLIST_HITTEST_BELOW 0x0002 // Below the client area.
101 #define wxLIST_HITTEST_NOWHERE 0x0004 // In the client area but below the last item.
102 #define wxLIST_HITTEST_ONITEMICON 0x0020 // On the bitmap associated with an item.
103 #define wxLIST_HITTEST_ONITEMLABEL 0x0080 // On the label (string) associated with an item.
104 #define wxLIST_HITTEST_ONITEMRIGHT 0x0100 // In the area to the right of an item.
105 #define wxLIST_HITTEST_ONITEMSTATEICON 0x0200 // On the state icon for a tree view item that is in a user-defined state.
106 #define wxLIST_HITTEST_TOLEFT 0x0400 // To the left of the client area.
107 #define wxLIST_HITTEST_TORIGHT 0x0800 // To the right of the client area.
109 #define wxLIST_HITTEST_ONITEM (wxLIST_HITTEST_ONITEMICON | wxLIST_HITTEST_ONITEMLABEL | wxLIST_HITTEST_ONITEMSTATEICON)
111 // Flags for GetNextItem (MSW only except wxLIST_NEXT_ALL)
114 wxLIST_NEXT_ABOVE
, // Searches for an item above the specified item
115 wxLIST_NEXT_ALL
, // Searches for subsequent item by index
116 wxLIST_NEXT_BELOW
, // Searches for an item below the specified item
117 wxLIST_NEXT_LEFT
, // Searches for an item to the left of the specified item
118 wxLIST_NEXT_RIGHT
// Searches for an item to the right of the specified item
121 // Alignment flags for Arrange (MSW only except wxLIST_ALIGN_LEFT)
124 wxLIST_ALIGN_DEFAULT
,
127 wxLIST_ALIGN_SNAP_TO_GRID
130 // Column format (MSW only except wxLIST_FORMAT_LEFT)
131 enum wxListColumnFormat
135 wxLIST_FORMAT_CENTRE
,
136 wxLIST_FORMAT_CENTER
= wxLIST_FORMAT_CENTRE
139 // Autosize values for SetColumnWidth
142 wxLIST_AUTOSIZE
= -1,
143 wxLIST_AUTOSIZE_USEHEADER
= -2 // partly supported by generic version
146 // Flag values for GetItemRect
154 // Flag values for FindItem (MSW only)
163 // ----------------------------------------------------------------------------
164 // wxListItemAttr: a structure containing the visual attributes of an item
165 // ----------------------------------------------------------------------------
167 class WXDLLEXPORT wxListItemAttr
172 wxListItemAttr(const wxColour
& colText
,
173 const wxColour
& colBack
,
175 : m_colText(colText
), m_colBack(colBack
), m_font(font
) { }
178 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
179 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
180 void SetFont(const wxFont
& font
) { m_font
= font
; }
183 bool HasTextColour() const { return m_colText
.Ok(); }
184 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
185 bool HasFont() const { return m_font
.Ok(); }
187 const wxColour
& GetTextColour() const { return m_colText
; }
188 const wxColour
& GetBackgroundColour() const { return m_colBack
; }
189 const wxFont
& GetFont() const { return m_font
; }
197 // ----------------------------------------------------------------------------
198 // wxListItem: the item or column info, used to exchange data with wxListCtrl
199 // ----------------------------------------------------------------------------
201 class WXDLLEXPORT wxListItem
: public wxObject
204 wxListItem() { Init(); m_attr
= NULL
; }
205 wxListItem(const wxListItem
& item
)
208 m_itemId(item
.m_itemId
),
210 m_state(item
.m_state
),
211 m_stateMask(item
.m_stateMask
),
213 m_image(item
.m_image
),
215 m_format(item
.m_format
),
216 m_width(item
.m_width
),
219 // copy list item attributes
220 if( item
.HasAttributes() )
221 m_attr
= new wxListItemAttr(*item
.GetAttributes());
223 virtual ~wxListItem() { delete m_attr
; }
226 void Clear() { Init(); m_text
.clear(); ClearAttributes(); }
227 void ClearAttributes() { if ( m_attr
) { delete m_attr
; m_attr
= NULL
; } }
230 void SetMask(long mask
)
234 void SetColumn(int col
)
236 void SetState(long state
)
237 { m_mask
|= wxLIST_MASK_STATE
; m_state
= state
; m_stateMask
|= state
; }
238 void SetStateMask(long stateMask
)
239 { m_stateMask
= stateMask
; }
240 void SetText(const wxString
& text
)
241 { m_mask
|= wxLIST_MASK_TEXT
; m_text
= text
; }
242 void SetImage(int image
)
243 { m_mask
|= wxLIST_MASK_IMAGE
; m_image
= image
; }
244 void SetData(long data
)
245 { m_mask
|= wxLIST_MASK_DATA
; m_data
= data
; }
246 void SetData(void *data
)
247 { m_mask
|= wxLIST_MASK_DATA
; m_data
= wxPtrToUInt(data
); }
249 void SetWidth(int width
)
250 { m_mask
|= wxLIST_MASK_WIDTH
; m_width
= width
; }
251 void SetAlign(wxListColumnFormat align
)
252 { m_mask
|= wxLIST_MASK_FORMAT
; m_format
= align
; }
254 void SetTextColour(const wxColour
& colText
)
255 { Attributes().SetTextColour(colText
); }
256 void SetBackgroundColour(const wxColour
& colBack
)
257 { Attributes().SetBackgroundColour(colBack
); }
258 void SetFont(const wxFont
& font
)
259 { Attributes().SetFont(font
); }
262 long GetMask() const { return m_mask
; }
263 long GetId() const { return m_itemId
; }
264 int GetColumn() const { return m_col
; }
265 long GetState() const { return m_state
& m_stateMask
; }
266 const wxString
& GetText() const { return m_text
; }
267 int GetImage() const { return m_image
; }
268 wxUIntPtr
GetData() const { return m_data
; }
270 int GetWidth() const { return m_width
; }
271 wxListColumnFormat
GetAlign() const { return (wxListColumnFormat
)m_format
; }
273 wxListItemAttr
*GetAttributes() const { return m_attr
; }
274 bool HasAttributes() const { return m_attr
!= NULL
; }
276 wxColour
GetTextColour() const
277 { return HasAttributes() ? m_attr
->GetTextColour() : wxNullColour
; }
278 wxColour
GetBackgroundColour() const
279 { return HasAttributes() ? m_attr
->GetBackgroundColour()
281 wxFont
GetFont() const
282 { return HasAttributes() ? m_attr
->GetFont() : wxNullFont
; }
284 // this conversion is necessary to make old code using GetItem() to
286 operator long() const { return m_itemId
; }
288 // these members are public for compatibility
290 long m_mask
; // Indicates what fields are valid
291 long m_itemId
; // The zero-based item position
292 int m_col
; // Zero-based column, if in report mode
293 long m_state
; // The state of the item
294 long m_stateMask
;// Which flags of m_state are valid (uses same flags)
295 wxString m_text
; // The label/header text
296 int m_image
; // The zero-based index into an image list
297 wxUIntPtr m_data
; // App-defined data
300 int m_format
; // left, right, centre
301 int m_width
; // width of column
304 int m_miniImage
; // handle to the mini image for OS/2
308 // creates m_attr if we don't have it yet
309 wxListItemAttr
& Attributes()
312 m_attr
= new wxListItemAttr
;
327 m_format
= wxLIST_FORMAT_CENTRE
;
331 wxListItemAttr
*m_attr
; // optional pointer to the items style
334 // VZ: this is strange, we have a copy ctor but not operator=(), why?
335 wxListItem
& operator=(const wxListItem
& item
);
337 DECLARE_DYNAMIC_CLASS(wxListItem
)
340 // ----------------------------------------------------------------------------
341 // wxListEvent - the event class for the wxListCtrl notifications
342 // ----------------------------------------------------------------------------
344 class WXDLLEXPORT wxListEvent
: public wxNotifyEvent
347 wxListEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0)
348 : wxNotifyEvent(commandType
, winid
)
355 , m_editCancelled(false)
358 wxListEvent(const wxListEvent
& event
)
359 : wxNotifyEvent(event
)
360 , m_code(event
.m_code
)
361 , m_oldItemIndex(event
.m_oldItemIndex
)
362 , m_itemIndex(event
.m_itemIndex
)
364 , m_pointDrag(event
.m_pointDrag
)
365 , m_item(event
.m_item
)
366 , m_editCancelled(event
.m_editCancelled
)
369 int GetKeyCode() const { return m_code
; }
370 long GetIndex() const { return m_itemIndex
; }
371 int GetColumn() const { return m_col
; }
372 wxPoint
GetPoint() const { return m_pointDrag
; }
373 const wxString
& GetLabel() const { return m_item
.m_text
; }
374 const wxString
& GetText() const { return m_item
.m_text
; }
375 int GetImage() const { return m_item
.m_image
; }
376 long GetData() const { return m_item
.m_data
; }
377 long GetMask() const { return m_item
.m_mask
; }
378 const wxListItem
& GetItem() const { return m_item
; }
380 // for wxEVT_COMMAND_LIST_CACHE_HINT only
381 long GetCacheFrom() const { return m_oldItemIndex
; }
382 long GetCacheTo() const { return m_itemIndex
; }
384 // was label editing canceled? (for wxEVT_COMMAND_LIST_END_LABEL_EDIT only)
385 bool IsEditCancelled() const { return m_editCancelled
; }
386 void SetEditCanceled(bool editCancelled
) { m_editCancelled
= editCancelled
; }
388 #if WXWIN_COMPATIBILITY_2_2
389 // these methods don't do anything at all
390 long GetOldIndex() const { return 0; }
391 long GetOldItem() const { return 0; }
393 // this one is superseded by GetKeyCode()
394 int GetCode() const { return GetKeyCode(); }
395 #endif // WXWIN_COMPATIBILITY_2_2
397 virtual wxEvent
*Clone() const { return new wxListEvent(*this); }
399 //protected: -- not for backwards compatibility
401 long m_oldItemIndex
; // only for wxEVT_COMMAND_LIST_CACHE_HINT
409 bool m_editCancelled
;
412 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxListEvent
)
415 // ----------------------------------------------------------------------------
416 // wxListCtrl event macros
417 // ----------------------------------------------------------------------------
419 BEGIN_DECLARE_EVENT_TYPES()
420 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
, 700)
421 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
, 701)
422 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, 702)
423 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
, 703)
424 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
, 704)
425 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, 705)
426 #if WXWIN_COMPATIBILITY_2_4
427 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
, 706)
428 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
, 707)
430 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
, 708)
431 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
, 709)
432 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
, 710)
433 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
, 711)
434 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
, 712)
435 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, 713)
436 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
, 714)
437 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, 715)
438 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
, 716)
439 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
, 717)
440 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
, 718)
441 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING
, 719)
442 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG
, 720)
443 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED
, 721)
444 END_DECLARE_EVENT_TYPES()
446 typedef void (wxEvtHandler::*wxListEventFunction
)(wxListEvent
&);
448 #define wxListEventHandler(func) \
449 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxListEventFunction, &func)
451 #define wx__DECLARE_LISTEVT(evt, id, fn) \
452 wx__DECLARE_EVT1(wxEVT_COMMAND_LIST_ ## evt, id, wxListEventHandler(fn))
454 #define EVT_LIST_BEGIN_DRAG(id, fn) wx__DECLARE_LISTEVT(BEGIN_DRAG, id, fn)
455 #define EVT_LIST_BEGIN_RDRAG(id, fn) wx__DECLARE_LISTEVT(BEGIN_RDRAG, id, fn)
456 #define EVT_LIST_BEGIN_LABEL_EDIT(id, fn) wx__DECLARE_LISTEVT(BEGIN_LABEL_EDIT, id, fn)
457 #define EVT_LIST_END_LABEL_EDIT(id, fn) wx__DECLARE_LISTEVT(END_LABEL_EDIT, id, fn)
458 #define EVT_LIST_DELETE_ITEM(id, fn) wx__DECLARE_LISTEVT(DELETE_ITEM, id, fn)
459 #define EVT_LIST_DELETE_ALL_ITEMS(id, fn) wx__DECLARE_LISTEVT(DELETE_ALL_ITEMS, id, fn)
460 #define EVT_LIST_KEY_DOWN(id, fn) wx__DECLARE_LISTEVT(KEY_DOWN, id, fn)
461 #define EVT_LIST_INSERT_ITEM(id, fn) wx__DECLARE_LISTEVT(INSERT_ITEM, id, fn)
463 #define EVT_LIST_COL_CLICK(id, fn) wx__DECLARE_LISTEVT(COL_CLICK, id, fn)
464 #define EVT_LIST_COL_RIGHT_CLICK(id, fn) wx__DECLARE_LISTEVT(COL_RIGHT_CLICK, id, fn)
465 #define EVT_LIST_COL_BEGIN_DRAG(id, fn) wx__DECLARE_LISTEVT(COL_BEGIN_DRAG, id, fn)
466 #define EVT_LIST_COL_DRAGGING(id, fn) wx__DECLARE_LISTEVT(COL_DRAGGING, id, fn)
467 #define EVT_LIST_COL_END_DRAG(id, fn) wx__DECLARE_LISTEVT(COL_END_DRAG, id, fn)
469 #define EVT_LIST_ITEM_SELECTED(id, fn) wx__DECLARE_LISTEVT(ITEM_SELECTED, id, fn)
470 #define EVT_LIST_ITEM_DESELECTED(id, fn) wx__DECLARE_LISTEVT(ITEM_DESELECTED, id, fn)
471 #define EVT_LIST_ITEM_RIGHT_CLICK(id, fn) wx__DECLARE_LISTEVT(ITEM_RIGHT_CLICK, id, fn)
472 #define EVT_LIST_ITEM_MIDDLE_CLICK(id, fn) wx__DECLARE_LISTEVT(ITEM_MIDDLE_CLICK, id, fn)
473 #define EVT_LIST_ITEM_ACTIVATED(id, fn) wx__DECLARE_LISTEVT(ITEM_ACTIVATED, id, fn)
474 #define EVT_LIST_ITEM_FOCUSED(id, fn) wx__DECLARE_LISTEVT(ITEM_FOCUSED, id, fn)
476 #define EVT_LIST_CACHE_HINT(id, fn) wx__DECLARE_LISTEVT(CACHE_HINT, id, fn)
479 #if WXWIN_COMPATIBILITY_2_4
480 #define EVT_LIST_GET_INFO(id, fn) wx__DECLARE_LISTEVT(GET_INFO, id, fn)
481 #define EVT_LIST_SET_INFO(id, fn) wx__DECLARE_LISTEVT(SET_INFO, id, fn)
484 #endif // wxUSE_LISTCTRL
487 // _WX_LISTCTRL_H_BASE_