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_
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // type of compare function for wxListCtrl sort operation
20 typedef int (wxCALLBACK
*wxListCtrlCompare
)(long item1
, long item2
, long sortData
);
22 // ----------------------------------------------------------------------------
23 // wxListCtrl constants
24 // ----------------------------------------------------------------------------
26 // Mask flags to tell app/GUI what fields of wxListItem are valid
27 #define wxLIST_MASK_STATE 0x0001
28 #define wxLIST_MASK_TEXT 0x0002
29 #define wxLIST_MASK_IMAGE 0x0004
30 #define wxLIST_MASK_DATA 0x0008
31 #define wxLIST_SET_ITEM 0x0010
32 #define wxLIST_MASK_WIDTH 0x0020
33 #define wxLIST_MASK_FORMAT 0x0040
35 // State flags for indicating the state of an item
36 #define wxLIST_STATE_DONTCARE 0x0000
37 #define wxLIST_STATE_DROPHILITED 0x0001 // MSW only
38 #define wxLIST_STATE_FOCUSED 0x0002
39 #define wxLIST_STATE_SELECTED 0x0004
40 #define wxLIST_STATE_CUT 0x0008 // MSW only
42 // Hit test flags, used in HitTest
43 #define wxLIST_HITTEST_ABOVE 0x0001 // Above the client area.
44 #define wxLIST_HITTEST_BELOW 0x0002 // Below the client area.
45 #define wxLIST_HITTEST_NOWHERE 0x0004 // In the client area but below the last item.
46 #define wxLIST_HITTEST_ONITEMICON 0x0020 // On the bitmap associated with an item.
47 #define wxLIST_HITTEST_ONITEMLABEL 0x0080 // On the label (string) associated with an item.
48 #define wxLIST_HITTEST_ONITEMRIGHT 0x0100 // In the area to the right of an item.
49 #define wxLIST_HITTEST_ONITEMSTATEICON 0x0200 // On the state icon for a tree view item that is in a user-defined state.
50 #define wxLIST_HITTEST_TOLEFT 0x0400 // To the left of the client area.
51 #define wxLIST_HITTEST_TORIGHT 0x0800 // To the right of the client area.
53 #define wxLIST_HITTEST_ONITEM (wxLIST_HITTEST_ONITEMICON | wxLIST_HITTEST_ONITEMLABEL | wxLIST_HITTEST_ONITEMSTATEICON)
55 // Flags for GetNextItem (MSW only except wxLIST_NEXT_ALL)
58 wxLIST_NEXT_ABOVE
, // Searches for an item above the specified item
59 wxLIST_NEXT_ALL
, // Searches for subsequent item by index
60 wxLIST_NEXT_BELOW
, // Searches for an item below the specified item
61 wxLIST_NEXT_LEFT
, // Searches for an item to the left of the specified item
62 wxLIST_NEXT_RIGHT
// Searches for an item to the right of the specified item
65 // Alignment flags for Arrange (MSW only except wxLIST_ALIGN_LEFT)
71 wxLIST_ALIGN_SNAP_TO_GRID
74 // Column format (MSW only except wxLIST_FORMAT_LEFT)
75 enum wxListColumnFormat
80 wxLIST_FORMAT_CENTER
= wxLIST_FORMAT_CENTRE
83 // Autosize values for SetColumnWidth
87 wxLIST_AUTOSIZE_USEHEADER
= -2 // partly supported by generic version
90 // Flag values for GetItemRect
98 // Flag values for FindItem (MSW only)
107 // ----------------------------------------------------------------------------
108 // wxListItemAttr: a structure containing the visual attributes of an item
109 // ----------------------------------------------------------------------------
111 class WXDLLEXPORT wxListItemAttr
116 wxListItemAttr(const wxColour
& colText
,
117 const wxColour
& colBack
,
119 : m_colText(colText
), m_colBack(colBack
), m_font(font
) { }
122 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
123 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
124 void SetFont(const wxFont
& font
) { m_font
= font
; }
127 bool HasTextColour() const { return m_colText
.Ok(); }
128 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
129 bool HasFont() const { return m_font
.Ok(); }
131 const wxColour
& GetTextColour() const { return m_colText
; }
132 const wxColour
& GetBackgroundColour() const { return m_colBack
; }
133 const wxFont
& GetFont() const { return m_font
; }
141 // ----------------------------------------------------------------------------
142 // wxListItem: the item or column info, used to exchange data with wxListCtrl
143 // ----------------------------------------------------------------------------
145 class WXDLLEXPORT wxListItem
: public wxObject
149 ~wxListItem() { delete m_attr
; }
153 void ClearAttributes();
156 void SetMask(long mask
) { m_mask
= mask
; }
157 void SetId(long id
) { m_itemId
= id
; }
158 void SetColumn(int col
) { m_col
= col
; }
159 void SetState(long state
) { m_state
= state
; m_stateMask
|= state
; }
160 void SetStateMask(long stateMask
) { m_stateMask
= stateMask
; }
161 void SetText(const wxString
& text
) { m_text
= text
; }
162 void SetImage(int image
) { m_image
= image
; }
163 void SetData(long data
) { m_data
= data
; }
164 void SetData(void *data
) { m_data
= (long)data
; }
166 void SetWidth(int width
) { m_width
= width
; }
167 void SetAlign(wxListColumnFormat align
) { m_format
= align
; }
169 void SetTextColour(const wxColour
& colText
)
170 { Attributes().SetTextColour(colText
); }
171 void SetBackgroundColour(const wxColour
& colBack
)
172 { Attributes().SetBackgroundColour(colBack
); }
173 void SetFont(const wxFont
& font
)
174 { Attributes().SetFont(font
); }
177 long GetMask() const { return m_mask
; }
178 long GetId() const { return m_itemId
; }
179 int GetColumn() const { return m_col
; }
180 long GetState() const { return m_state
& m_stateMask
; }
181 const wxString
& GetText() const { return m_text
; }
182 int GetImage() const { return m_image
; }
183 long GetData() const { return m_data
; }
185 int GetWidth() const { return m_width
; }
186 wxListColumnFormat
GetAlign() const { return (wxListColumnFormat
)m_format
; }
188 wxListItemAttr
*GetAttributes() const { return m_attr
; }
189 bool HasAttributes() const { return m_attr
!= NULL
; }
191 const wxColour
& GetTextColour() const
192 { return HasAttributes() ? m_attr
->GetTextColour() : wxNullColour
; }
193 const wxColour
& GetBackgroundColour() const
194 { return HasAttributes() ? m_attr
->GetBackgroundColour()
196 const wxFont
& GetFont() const
197 { return HasAttributes() ? m_attr
->GetFont() : wxNullFont
; }
199 // these members are public for compatibility
201 long m_mask
; // Indicates what fields are valid
202 long m_itemId
; // The zero-based item position
203 int m_col
; // Zero-based column, if in report mode
204 long m_state
; // The state of the item
205 long m_stateMask
;// Which flags of m_state are valid (uses same flags)
206 wxString m_text
; // The label/header text
207 int m_image
; // The zero-based index into an image list
208 long m_data
; // App-defined data
211 int m_format
; // left, right, centre
212 int m_width
; // width of column
215 // creates m_attr if we don't have it yet
216 wxListItemAttr
& Attributes()
219 m_attr
= new wxListItemAttr
;
224 wxListItemAttr
*m_attr
; // optional pointer to the items style
227 DECLARE_DYNAMIC_CLASS(wxListItem
)
230 // ----------------------------------------------------------------------------
231 // include the wxListCtrl class declaration
232 // ----------------------------------------------------------------------------
234 #if defined(__WXMSW__)
236 #include "wx/generic/listctrl.h"
238 #include "wx/msw/listctrl.h"
240 #elif defined(__WXMOTIF__)
241 #include "wx/generic/listctrl.h"
242 #elif defined(__WXGTK__)
243 #include "wx/generic/listctrl.h"
244 #elif defined(__WXQT__)
245 #include "wx/generic/listctrl.h"
246 #elif defined(__WXMAC__)
247 #include "wx/generic/listctrl.h"
248 #elif defined(__WXPM__)
249 #include "wx/generic/listctrl.h"
250 #elif defined(__WXSTUBS__)
251 #include "wx/generic/listctrl.h"
254 // ----------------------------------------------------------------------------
255 // wxListEvent - the event class for the wxListCtrl notifications
256 // ----------------------------------------------------------------------------
258 class WXDLLEXPORT wxListEvent
: public wxNotifyEvent
261 wxListEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0);
272 inline int GetCode() { return m_code
; }
273 inline long GetIndex() { return m_itemIndex
; }
274 inline long GetOldIndex() { return m_oldItemIndex
; }
275 inline long GetItem() { return m_itemIndex
; }
276 inline long GetOldItem() { return m_oldItemIndex
; }
277 inline int GetColumn() { return m_col
; }
278 inline bool Cancelled() { return m_cancelled
; }
279 inline wxPoint
GetPoint() { return m_pointDrag
; }
280 inline const wxString
&GetLabel() const { return m_item
.m_text
; }
281 inline const wxString
&GetText() const { return m_item
.m_text
; }
282 inline int GetImage() { return m_item
.m_image
; }
283 inline long GetData() { return m_item
.m_data
; }
284 inline long GetMask() { return m_item
.m_mask
; }
285 inline const wxListItem
&GetItem() const { return m_item
; }
287 void CopyObject(wxObject
& object_dest
) const;
290 DECLARE_DYNAMIC_CLASS(wxListEvent
)
293 typedef void (wxEvtHandler::*wxListEventFunction
)(wxListEvent
&);
295 #define EVT_LIST_BEGIN_DRAG(id, fn) { wxEVT_COMMAND_LIST_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL },
296 #define EVT_LIST_BEGIN_RDRAG(id, fn) { wxEVT_COMMAND_LIST_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL },
297 #define EVT_LIST_BEGIN_LABEL_EDIT(id, fn) { wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL },
298 #define EVT_LIST_END_LABEL_EDIT(id, fn) { wxEVT_COMMAND_LIST_END_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL },
299 #define EVT_LIST_DELETE_ITEM(id, fn) { wxEVT_COMMAND_LIST_DELETE_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL },
300 #define EVT_LIST_DELETE_ALL_ITEMS(id, fn) { wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL },
301 #define EVT_LIST_GET_INFO(id, fn) { wxEVT_COMMAND_LIST_GET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL },
302 #define EVT_LIST_SET_INFO(id, fn) { wxEVT_COMMAND_LIST_SET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL },
303 #define EVT_LIST_ITEM_SELECTED(id, fn) { wxEVT_COMMAND_LIST_ITEM_SELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL },
304 #define EVT_LIST_ITEM_DESELECTED(id, fn) { wxEVT_COMMAND_LIST_ITEM_DESELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL },
305 #define EVT_LIST_KEY_DOWN(id, fn) { wxEVT_COMMAND_LIST_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL },
306 #define EVT_LIST_INSERT_ITEM(id, fn) { wxEVT_COMMAND_LIST_INSERT_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL },
307 #define EVT_LIST_COL_CLICK(id, fn) { wxEVT_COMMAND_LIST_COL_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL },
308 #define EVT_LIST_ITEM_RIGHT_CLICK(id, fn) { wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL },
309 #define EVT_LIST_ITEM_MIDDLE_CLICK(id, fn) { wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL },
310 #define EVT_LIST_ITEM_ACTIVATED(id, fn) { wxEVT_COMMAND_LIST_ITEM_ACTIVATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL },
313 // _WX_LISTCTRL_H_BASE_