]> git.saurik.com Git - wxWidgets.git/blame - include/wx/listctrl.h
Further wxUniv fixes
[wxWidgets.git] / include / wx / listctrl.h
CommitLineData
bdc72a22
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/listctrl.h
3// Purpose: wxListCtrl class
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 04.12.99
7// RCS-ID: $Id$
8// Copyright: (c) wxWindows team
9// Licence: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11
34138703
JS
12#ifndef _WX_LISTCTRL_H_BASE_
13#define _WX_LISTCTRL_H_BASE_
c801d85f 14
510fc784
RR
15#ifdef __GNUG__
16 #pragma interface "listctrlbase.h"
17#endif
18
1e6feb95
VZ
19#if wxUSE_LISTCTRL
20
bdc72a22
VZ
21// ----------------------------------------------------------------------------
22// types
23// ----------------------------------------------------------------------------
24
25// type of compare function for wxListCtrl sort operation
26typedef int (wxCALLBACK *wxListCtrlCompare)(long item1, long item2, long sortData);
27
28// ----------------------------------------------------------------------------
29// wxListCtrl constants
30// ----------------------------------------------------------------------------
31
32// Mask flags to tell app/GUI what fields of wxListItem are valid
33#define wxLIST_MASK_STATE 0x0001
34#define wxLIST_MASK_TEXT 0x0002
35#define wxLIST_MASK_IMAGE 0x0004
36#define wxLIST_MASK_DATA 0x0008
37#define wxLIST_SET_ITEM 0x0010
38#define wxLIST_MASK_WIDTH 0x0020
39#define wxLIST_MASK_FORMAT 0x0040
40
41// State flags for indicating the state of an item
42#define wxLIST_STATE_DONTCARE 0x0000
43#define wxLIST_STATE_DROPHILITED 0x0001 // MSW only
44#define wxLIST_STATE_FOCUSED 0x0002
45#define wxLIST_STATE_SELECTED 0x0004
46#define wxLIST_STATE_CUT 0x0008 // MSW only
47
48// Hit test flags, used in HitTest
49#define wxLIST_HITTEST_ABOVE 0x0001 // Above the client area.
50#define wxLIST_HITTEST_BELOW 0x0002 // Below the client area.
51#define wxLIST_HITTEST_NOWHERE 0x0004 // In the client area but below the last item.
52#define wxLIST_HITTEST_ONITEMICON 0x0020 // On the bitmap associated with an item.
53#define wxLIST_HITTEST_ONITEMLABEL 0x0080 // On the label (string) associated with an item.
54#define wxLIST_HITTEST_ONITEMRIGHT 0x0100 // In the area to the right of an item.
55#define wxLIST_HITTEST_ONITEMSTATEICON 0x0200 // On the state icon for a tree view item that is in a user-defined state.
56#define wxLIST_HITTEST_TOLEFT 0x0400 // To the left of the client area.
57#define wxLIST_HITTEST_TORIGHT 0x0800 // To the right of the client area.
58
59#define wxLIST_HITTEST_ONITEM (wxLIST_HITTEST_ONITEMICON | wxLIST_HITTEST_ONITEMLABEL | wxLIST_HITTEST_ONITEMSTATEICON)
60
61// Flags for GetNextItem (MSW only except wxLIST_NEXT_ALL)
62enum
63{
64 wxLIST_NEXT_ABOVE, // Searches for an item above the specified item
65 wxLIST_NEXT_ALL, // Searches for subsequent item by index
66 wxLIST_NEXT_BELOW, // Searches for an item below the specified item
67 wxLIST_NEXT_LEFT, // Searches for an item to the left of the specified item
43543d98 68 wxLIST_NEXT_RIGHT // Searches for an item to the right of the specified item
bdc72a22
VZ
69};
70
71// Alignment flags for Arrange (MSW only except wxLIST_ALIGN_LEFT)
72enum
73{
74 wxLIST_ALIGN_DEFAULT,
75 wxLIST_ALIGN_LEFT,
76 wxLIST_ALIGN_TOP,
77 wxLIST_ALIGN_SNAP_TO_GRID
78};
79
80// Column format (MSW only except wxLIST_FORMAT_LEFT)
81enum wxListColumnFormat
82{
83 wxLIST_FORMAT_LEFT,
84 wxLIST_FORMAT_RIGHT,
85 wxLIST_FORMAT_CENTRE,
86 wxLIST_FORMAT_CENTER = wxLIST_FORMAT_CENTRE
87};
88
89// Autosize values for SetColumnWidth
90enum
91{
92 wxLIST_AUTOSIZE = -1,
93 wxLIST_AUTOSIZE_USEHEADER = -2 // partly supported by generic version
94};
95
96// Flag values for GetItemRect
97enum
98{
99 wxLIST_RECT_BOUNDS,
100 wxLIST_RECT_ICON,
101 wxLIST_RECT_LABEL
102};
103
104// Flag values for FindItem (MSW only)
105enum
106{
107 wxLIST_FIND_UP,
108 wxLIST_FIND_DOWN,
109 wxLIST_FIND_LEFT,
110 wxLIST_FIND_RIGHT
111};
112
113// ----------------------------------------------------------------------------
114// wxListItemAttr: a structure containing the visual attributes of an item
115// ----------------------------------------------------------------------------
116
117class WXDLLEXPORT wxListItemAttr
118{
119public:
120 // ctors
121 wxListItemAttr() { }
122 wxListItemAttr(const wxColour& colText,
123 const wxColour& colBack,
124 const wxFont& font)
125 : m_colText(colText), m_colBack(colBack), m_font(font) { }
126
127 // setters
128 void SetTextColour(const wxColour& colText) { m_colText = colText; }
129 void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; }
130 void SetFont(const wxFont& font) { m_font = font; }
131
132 // accessors
d62228a6
VZ
133 bool HasTextColour() const { return m_colText.Ok(); }
134 bool HasBackgroundColour() const { return m_colBack.Ok(); }
135 bool HasFont() const { return m_font.Ok(); }
136
bdc72a22
VZ
137 const wxColour& GetTextColour() const { return m_colText; }
138 const wxColour& GetBackgroundColour() const { return m_colBack; }
139 const wxFont& GetFont() const { return m_font; }
140
141private:
142 wxColour m_colText,
143 m_colBack;
144 wxFont m_font;
145};
146
147// ----------------------------------------------------------------------------
148// wxListItem: the item or column info, used to exchange data with wxListCtrl
149// ----------------------------------------------------------------------------
150
151class WXDLLEXPORT wxListItem : public wxObject
152{
153public:
154 wxListItem();
d62228a6 155 ~wxListItem() { delete m_attr; }
bdc72a22 156
9b00bb16
RR
157 // resetting
158 void Clear();
159 void ClearAttributes();
160
bdc72a22
VZ
161 // setters
162 void SetMask(long mask) { m_mask = mask; }
163 void SetId(long id) { m_itemId = id; }
164 void SetColumn(int col) { m_col = col; }
165 void SetState(long state) { m_state = state; m_stateMask |= state; }
166 void SetStateMask(long stateMask) { m_stateMask = stateMask; }
167 void SetText(const wxString& text) { m_text = text; }
168 void SetImage(int image) { m_image = image; }
169 void SetData(long data) { m_data = data; }
170 void SetData(void *data) { m_data = (long)data; }
171
172 void SetWidth(int width) { m_width = width; }
173 void SetAlign(wxListColumnFormat align) { m_format = align; }
174
175 void SetTextColour(const wxColour& colText)
176 { Attributes().SetTextColour(colText); }
177 void SetBackgroundColour(const wxColour& colBack)
178 { Attributes().SetBackgroundColour(colBack); }
179 void SetFont(const wxFont& font)
180 { Attributes().SetFont(font); }
181
182 // accessors
183 long GetMask() const { return m_mask; }
184 long GetId() const { return m_itemId; }
185 int GetColumn() const { return m_col; }
186 long GetState() const { return m_state & m_stateMask; }
187 const wxString& GetText() const { return m_text; }
188 int GetImage() const { return m_image; }
189 long GetData() const { return m_data; }
190
191 int GetWidth() const { return m_width; }
192 wxListColumnFormat GetAlign() const { return (wxListColumnFormat)m_format; }
193
194 wxListItemAttr *GetAttributes() const { return m_attr; }
195 bool HasAttributes() const { return m_attr != NULL; }
196
13111b2a 197 wxColour GetTextColour() const
bdc72a22 198 { return HasAttributes() ? m_attr->GetTextColour() : wxNullColour; }
13111b2a 199 wxColour GetBackgroundColour() const
bdc72a22
VZ
200 { return HasAttributes() ? m_attr->GetBackgroundColour()
201 : wxNullColour; }
13111b2a 202 wxFont GetFont() const
bdc72a22
VZ
203 { return HasAttributes() ? m_attr->GetFont() : wxNullFont; }
204
cff5ce9e
VZ
205 // this conversion is necessary to make old code using GetItem() to
206 // compile
207 operator long() const { return m_itemId; }
208
bdc72a22
VZ
209 // these members are public for compatibility
210
211 long m_mask; // Indicates what fields are valid
212 long m_itemId; // The zero-based item position
213 int m_col; // Zero-based column, if in report mode
214 long m_state; // The state of the item
215 long m_stateMask;// Which flags of m_state are valid (uses same flags)
216 wxString m_text; // The label/header text
217 int m_image; // The zero-based index into an image list
218 long m_data; // App-defined data
219
220 // For columns only
221 int m_format; // left, right, centre
222 int m_width; // width of column
223
224protected:
225 // creates m_attr if we don't have it yet
226 wxListItemAttr& Attributes()
227 {
228 if ( !m_attr )
229 m_attr = new wxListItemAttr;
230
231 return *m_attr;
232 }
233
234 wxListItemAttr *m_attr; // optional pointer to the items style
235
236private:
237 DECLARE_DYNAMIC_CLASS(wxListItem)
238};
239
240// ----------------------------------------------------------------------------
241// include the wxListCtrl class declaration
242// ----------------------------------------------------------------------------
243
2049ba38 244#if defined(__WXMSW__)
bdc72a22
VZ
245 #ifdef __WIN16__
246 #include "wx/generic/listctrl.h"
247 #else
248 #include "wx/msw/listctrl.h"
249 #endif
2049ba38 250#elif defined(__WXMOTIF__)
bdc72a22 251 #include "wx/generic/listctrl.h"
2049ba38 252#elif defined(__WXGTK__)
bdc72a22 253 #include "wx/generic/listctrl.h"
b4e76e0d 254#elif defined(__WXQT__)
bdc72a22 255 #include "wx/generic/listctrl.h"
34138703 256#elif defined(__WXMAC__)
bdc72a22 257 #include "wx/generic/listctrl.h"
1777b9bb 258#elif defined(__WXPM__)
bdc72a22 259 #include "wx/generic/listctrl.h"
34138703 260#elif defined(__WXSTUBS__)
bdc72a22 261 #include "wx/generic/listctrl.h"
c801d85f
KB
262#endif
263
86f975a8
VZ
264// ----------------------------------------------------------------------------
265// wxListEvent - the event class for the wxListCtrl notifications
266// ----------------------------------------------------------------------------
267
268class WXDLLEXPORT wxListEvent : public wxNotifyEvent
269{
270public:
271 wxListEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
272
273 int m_code;
274 long m_itemIndex;
275 long m_oldItemIndex;
276 int m_col;
277 bool m_cancelled;
278 wxPoint m_pointDrag;
279
280 wxListItem m_item;
cdf1e714 281
225fe9d6
VZ
282 int GetCode() const { return m_code; }
283 long GetIndex() const { return m_itemIndex; }
284 long GetOldIndex() const { return m_oldItemIndex; }
285 long GetOldItem() const { return m_oldItemIndex; }
286 int GetColumn() const { return m_col; }
287 bool Cancelled() const { return m_cancelled; }
288 wxPoint GetPoint() const { return m_pointDrag; }
289 const wxString& GetLabel() const { return m_item.m_text; }
290 const wxString& GetText() const { return m_item.m_text; }
291 int GetImage() const { return m_item.m_image; }
292 long GetData() const { return m_item.m_data; }
293 long GetMask() const { return m_item.m_mask; }
294 const wxListItem& GetItem() const { return m_item; }
86f975a8 295
e4c730e9 296 void CopyObject(wxObject& object_dest) const;
e4c730e9 297
86f975a8
VZ
298private:
299 DECLARE_DYNAMIC_CLASS(wxListEvent)
300};
301
2e4df4bf
VZ
302// ----------------------------------------------------------------------------
303// wxListCtrl event macros
304// ----------------------------------------------------------------------------
305
306BEGIN_DECLARE_EVENT_TYPES()
307 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG, 700)
308 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG, 701)
309 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, 702)
310 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT, 703)
311 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM, 704)
312 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, 705)
313 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO, 706)
314 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO, 707)
315 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED, 708)
316 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED, 709)
317 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN, 710)
318 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM, 711)
319 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK, 712)
320 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, 713)
321 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, 714)
322 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED, 715)
323END_DECLARE_EVENT_TYPES()
324
86f975a8
VZ
325typedef void (wxEvtHandler::*wxListEventFunction)(wxListEvent&);
326
2e4df4bf
VZ
327#define EVT_LIST_BEGIN_DRAG(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
328#define EVT_LIST_BEGIN_RDRAG(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
329#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 ),
330#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 ),
331#define EVT_LIST_DELETE_ITEM(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_DELETE_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
332#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 ),
333#define EVT_LIST_GET_INFO(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_GET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
334#define EVT_LIST_SET_INFO(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_SET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
335#define EVT_LIST_ITEM_SELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_SELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
336#define EVT_LIST_ITEM_DESELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_DESELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
337#define EVT_LIST_KEY_DOWN(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
338#define EVT_LIST_INSERT_ITEM(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_INSERT_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
339#define EVT_LIST_COL_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_COL_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL ),
340#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 ),
341#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 ),
342#define EVT_LIST_ITEM_ACTIVATED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_LIST_ITEM_ACTIVATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL ),
86f975a8 343
1e6feb95
VZ
344#endif // wxUSE_LISTCTRL
345
c801d85f 346#endif
34138703 347 // _WX_LISTCTRL_H_BASE_