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_
16 #pragma interface "listctrlbase.h"
19 // ----------------------------------------------------------------------------
21 // ----------------------------------------------------------------------------
23 // type of compare function for wxListCtrl sort operation
24 typedef int (wxCALLBACK
*wxListCtrlCompare
)(long item1
, long item2
, long sortData
);
26 // ----------------------------------------------------------------------------
27 // wxListCtrl constants
28 // ----------------------------------------------------------------------------
30 // Mask flags to tell app/GUI what fields of wxListItem are valid
31 #define wxLIST_MASK_STATE 0x0001
32 #define wxLIST_MASK_TEXT 0x0002
33 #define wxLIST_MASK_IMAGE 0x0004
34 #define wxLIST_MASK_DATA 0x0008
35 #define wxLIST_SET_ITEM 0x0010
36 #define wxLIST_MASK_WIDTH 0x0020
37 #define wxLIST_MASK_FORMAT 0x0040
39 // State flags for indicating the state of an item
40 #define wxLIST_STATE_DONTCARE 0x0000
41 #define wxLIST_STATE_DROPHILITED 0x0001 // MSW only
42 #define wxLIST_STATE_FOCUSED 0x0002
43 #define wxLIST_STATE_SELECTED 0x0004
44 #define wxLIST_STATE_CUT 0x0008 // MSW only
46 // Hit test flags, used in HitTest
47 #define wxLIST_HITTEST_ABOVE 0x0001 // Above the client area.
48 #define wxLIST_HITTEST_BELOW 0x0002 // Below the client area.
49 #define wxLIST_HITTEST_NOWHERE 0x0004 // In the client area but below the last item.
50 #define wxLIST_HITTEST_ONITEMICON 0x0020 // On the bitmap associated with an item.
51 #define wxLIST_HITTEST_ONITEMLABEL 0x0080 // On the label (string) associated with an item.
52 #define wxLIST_HITTEST_ONITEMRIGHT 0x0100 // In the area to the right of an item.
53 #define wxLIST_HITTEST_ONITEMSTATEICON 0x0200 // On the state icon for a tree view item that is in a user-defined state.
54 #define wxLIST_HITTEST_TOLEFT 0x0400 // To the left of the client area.
55 #define wxLIST_HITTEST_TORIGHT 0x0800 // To the right of the client area.
57 #define wxLIST_HITTEST_ONITEM (wxLIST_HITTEST_ONITEMICON | wxLIST_HITTEST_ONITEMLABEL | wxLIST_HITTEST_ONITEMSTATEICON)
59 // Flags for GetNextItem (MSW only except wxLIST_NEXT_ALL)
62 wxLIST_NEXT_ABOVE
, // Searches for an item above the specified item
63 wxLIST_NEXT_ALL
, // Searches for subsequent item by index
64 wxLIST_NEXT_BELOW
, // Searches for an item below the specified item
65 wxLIST_NEXT_LEFT
, // Searches for an item to the left of the specified item
66 wxLIST_NEXT_RIGHT
// Searches for an item to the right of the specified item
69 // Alignment flags for Arrange (MSW only except wxLIST_ALIGN_LEFT)
75 wxLIST_ALIGN_SNAP_TO_GRID
78 // Column format (MSW only except wxLIST_FORMAT_LEFT)
79 enum wxListColumnFormat
84 wxLIST_FORMAT_CENTER
= wxLIST_FORMAT_CENTRE
87 // Autosize values for SetColumnWidth
91 wxLIST_AUTOSIZE_USEHEADER
= -2 // partly supported by generic version
94 // Flag values for GetItemRect
102 // Flag values for FindItem (MSW only)
111 // ----------------------------------------------------------------------------
112 // wxListItemAttr: a structure containing the visual attributes of an item
113 // ----------------------------------------------------------------------------
115 class WXDLLEXPORT wxListItemAttr
120 wxListItemAttr(const wxColour
& colText
,
121 const wxColour
& colBack
,
123 : m_colText(colText
), m_colBack(colBack
), m_font(font
) { }
126 void SetTextColour(const wxColour
& colText
) { m_colText
= colText
; }
127 void SetBackgroundColour(const wxColour
& colBack
) { m_colBack
= colBack
; }
128 void SetFont(const wxFont
& font
) { m_font
= font
; }
131 bool HasTextColour() const { return m_colText
.Ok(); }
132 bool HasBackgroundColour() const { return m_colBack
.Ok(); }
133 bool HasFont() const { return m_font
.Ok(); }
135 const wxColour
& GetTextColour() const { return m_colText
; }
136 const wxColour
& GetBackgroundColour() const { return m_colBack
; }
137 const wxFont
& GetFont() const { return m_font
; }
145 // ----------------------------------------------------------------------------
146 // wxListItem: the item or column info, used to exchange data with wxListCtrl
147 // ----------------------------------------------------------------------------
149 class WXDLLEXPORT wxListItem
: public wxObject
153 ~wxListItem() { delete m_attr
; }
157 void ClearAttributes();
160 void SetMask(long mask
) { m_mask
= mask
; }
161 void SetId(long id
) { m_itemId
= id
; }
162 void SetColumn(int col
) { m_col
= col
; }
163 void SetState(long state
) { m_state
= state
; m_stateMask
|= state
; }
164 void SetStateMask(long stateMask
) { m_stateMask
= stateMask
; }
165 void SetText(const wxString
& text
) { m_text
= text
; }
166 void SetImage(int image
) { m_image
= image
; }
167 void SetData(long data
) { m_data
= data
; }
168 void SetData(void *data
) { m_data
= (long)data
; }
170 void SetWidth(int width
) { m_width
= width
; }
171 void SetAlign(wxListColumnFormat align
) { m_format
= align
; }
173 void SetTextColour(const wxColour
& colText
)
174 { Attributes().SetTextColour(colText
); }
175 void SetBackgroundColour(const wxColour
& colBack
)
176 { Attributes().SetBackgroundColour(colBack
); }
177 void SetFont(const wxFont
& font
)
178 { Attributes().SetFont(font
); }
181 long GetMask() const { return m_mask
; }
182 long GetId() const { return m_itemId
; }
183 int GetColumn() const { return m_col
; }
184 long GetState() const { return m_state
& m_stateMask
; }
185 const wxString
& GetText() const { return m_text
; }
186 int GetImage() const { return m_image
; }
187 long GetData() const { return m_data
; }
189 int GetWidth() const { return m_width
; }
190 wxListColumnFormat
GetAlign() const { return (wxListColumnFormat
)m_format
; }
192 wxListItemAttr
*GetAttributes() const { return m_attr
; }
193 bool HasAttributes() const { return m_attr
!= NULL
; }
195 wxColour
GetTextColour() const
196 { return HasAttributes() ? m_attr
->GetTextColour() : wxNullColour
; }
197 wxColour
GetBackgroundColour() const
198 { return HasAttributes() ? m_attr
->GetBackgroundColour()
200 wxFont
GetFont() const
201 { return HasAttributes() ? m_attr
->GetFont() : wxNullFont
; }
203 // this conversion is necessary to make old code using GetItem() to
205 operator long() const { return m_itemId
; }
207 // these members are public for compatibility
209 long m_mask
; // Indicates what fields are valid
210 long m_itemId
; // The zero-based item position
211 int m_col
; // Zero-based column, if in report mode
212 long m_state
; // The state of the item
213 long m_stateMask
;// Which flags of m_state are valid (uses same flags)
214 wxString m_text
; // The label/header text
215 int m_image
; // The zero-based index into an image list
216 long m_data
; // App-defined data
219 int m_format
; // left, right, centre
220 int m_width
; // width of column
223 // creates m_attr if we don't have it yet
224 wxListItemAttr
& Attributes()
227 m_attr
= new wxListItemAttr
;
232 wxListItemAttr
*m_attr
; // optional pointer to the items style
235 DECLARE_DYNAMIC_CLASS(wxListItem
)
238 // ----------------------------------------------------------------------------
239 // include the wxListCtrl class declaration
240 // ----------------------------------------------------------------------------
242 #if defined(__WXMSW__)
244 #include "wx/generic/listctrl.h"
246 #include "wx/msw/listctrl.h"
248 #elif defined(__WXMOTIF__)
249 #include "wx/generic/listctrl.h"
250 #elif defined(__WXGTK__)
251 #include "wx/generic/listctrl.h"
252 #elif defined(__WXQT__)
253 #include "wx/generic/listctrl.h"
254 #elif defined(__WXMAC__)
255 #include "wx/generic/listctrl.h"
256 #elif defined(__WXPM__)
257 #include "wx/generic/listctrl.h"
258 #elif defined(__WXSTUBS__)
259 #include "wx/generic/listctrl.h"
262 // ----------------------------------------------------------------------------
263 // wxListEvent - the event class for the wxListCtrl notifications
264 // ----------------------------------------------------------------------------
266 class WXDLLEXPORT wxListEvent
: public wxNotifyEvent
269 wxListEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0);
280 int GetCode() const { return m_code
; }
281 long GetIndex() const { return m_itemIndex
; }
282 long GetOldIndex() const { return m_oldItemIndex
; }
283 long GetOldItem() const { return m_oldItemIndex
; }
284 int GetColumn() const { return m_col
; }
285 bool Cancelled() const { return m_cancelled
; }
286 wxPoint
GetPoint() const { return m_pointDrag
; }
287 const wxString
& GetLabel() const { return m_item
.m_text
; }
288 const wxString
& GetText() const { return m_item
.m_text
; }
289 int GetImage() const { return m_item
.m_image
; }
290 long GetData() const { return m_item
.m_data
; }
291 long GetMask() const { return m_item
.m_mask
; }
292 const wxListItem
& GetItem() const { return m_item
; }
294 void CopyObject(wxObject
& object_dest
) const;
297 DECLARE_DYNAMIC_CLASS(wxListEvent
)
300 // ----------------------------------------------------------------------------
301 // wxListCtrl event macros
302 // ----------------------------------------------------------------------------
304 BEGIN_DECLARE_EVENT_TYPES()
305 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
, 700)
306 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
, 701)
307 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
, 702)
308 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
, 703)
309 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
, 704)
310 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, 705)
311 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
, 706)
312 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
, 707)
313 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
, 708)
314 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
, 709)
315 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
, 710)
316 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
, 711)
317 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
, 712)
318 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
, 713)
319 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
, 714)
320 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
, 715)
321 END_DECLARE_EVENT_TYPES()
323 typedef void (wxEvtHandler::*wxListEventFunction
)(wxListEvent
&);
325 #define EVT_LIST_BEGIN_DRAG(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
326 #define EVT_LIST_BEGIN_RDRAG(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
327 #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 ),
328 #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 ),
329 #define EVT_LIST_DELETE_ITEM(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_DELETE_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
330 #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 ),
331 #define EVT_LIST_GET_INFO(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_GET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
332 #define EVT_LIST_SET_INFO(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_SET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
333 #define EVT_LIST_ITEM_SELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_SELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
334 #define EVT_LIST_ITEM_DESELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_DESELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
335 #define EVT_LIST_KEY_DOWN(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
336 #define EVT_LIST_INSERT_ITEM(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_INSERT_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
337 #define EVT_LIST_COL_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_COL_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
338 #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 ),
339 #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 ),
340 #define EVT_LIST_ITEM_ACTIVATED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL ),
343 // _WX_LISTCTRL_H_BASE_