]> git.saurik.com Git - wxWidgets.git/blame - include/wx/listctrl.h
1. wxFileDialog patch for multiple selection applied (with some small changes),
[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
bdc72a22
VZ
15// ----------------------------------------------------------------------------
16// types
17// ----------------------------------------------------------------------------
18
19// type of compare function for wxListCtrl sort operation
20typedef int (wxCALLBACK *wxListCtrlCompare)(long item1, long item2, long sortData);
21
22// ----------------------------------------------------------------------------
23// wxListCtrl constants
24// ----------------------------------------------------------------------------
25
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
34
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
41
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.
52
53#define wxLIST_HITTEST_ONITEM (wxLIST_HITTEST_ONITEMICON | wxLIST_HITTEST_ONITEMLABEL | wxLIST_HITTEST_ONITEMSTATEICON)
54
55// Flags for GetNextItem (MSW only except wxLIST_NEXT_ALL)
56enum
57{
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
43543d98 62 wxLIST_NEXT_RIGHT // Searches for an item to the right of the specified item
bdc72a22
VZ
63};
64
65// Alignment flags for Arrange (MSW only except wxLIST_ALIGN_LEFT)
66enum
67{
68 wxLIST_ALIGN_DEFAULT,
69 wxLIST_ALIGN_LEFT,
70 wxLIST_ALIGN_TOP,
71 wxLIST_ALIGN_SNAP_TO_GRID
72};
73
74// Column format (MSW only except wxLIST_FORMAT_LEFT)
75enum wxListColumnFormat
76{
77 wxLIST_FORMAT_LEFT,
78 wxLIST_FORMAT_RIGHT,
79 wxLIST_FORMAT_CENTRE,
80 wxLIST_FORMAT_CENTER = wxLIST_FORMAT_CENTRE
81};
82
83// Autosize values for SetColumnWidth
84enum
85{
86 wxLIST_AUTOSIZE = -1,
87 wxLIST_AUTOSIZE_USEHEADER = -2 // partly supported by generic version
88};
89
90// Flag values for GetItemRect
91enum
92{
93 wxLIST_RECT_BOUNDS,
94 wxLIST_RECT_ICON,
95 wxLIST_RECT_LABEL
96};
97
98// Flag values for FindItem (MSW only)
99enum
100{
101 wxLIST_FIND_UP,
102 wxLIST_FIND_DOWN,
103 wxLIST_FIND_LEFT,
104 wxLIST_FIND_RIGHT
105};
106
107// ----------------------------------------------------------------------------
108// wxListItemAttr: a structure containing the visual attributes of an item
109// ----------------------------------------------------------------------------
110
111class WXDLLEXPORT wxListItemAttr
112{
113public:
114 // ctors
115 wxListItemAttr() { }
116 wxListItemAttr(const wxColour& colText,
117 const wxColour& colBack,
118 const wxFont& font)
119 : m_colText(colText), m_colBack(colBack), m_font(font) { }
120
121 // setters
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; }
125
126 // accessors
d62228a6
VZ
127 bool HasTextColour() const { return m_colText.Ok(); }
128 bool HasBackgroundColour() const { return m_colBack.Ok(); }
129 bool HasFont() const { return m_font.Ok(); }
130
bdc72a22
VZ
131 const wxColour& GetTextColour() const { return m_colText; }
132 const wxColour& GetBackgroundColour() const { return m_colBack; }
133 const wxFont& GetFont() const { return m_font; }
134
135private:
136 wxColour m_colText,
137 m_colBack;
138 wxFont m_font;
139};
140
141// ----------------------------------------------------------------------------
142// wxListItem: the item or column info, used to exchange data with wxListCtrl
143// ----------------------------------------------------------------------------
144
145class WXDLLEXPORT wxListItem : public wxObject
146{
147public:
148 wxListItem();
d62228a6 149 ~wxListItem() { delete m_attr; }
bdc72a22
VZ
150
151 // setters
152 void SetMask(long mask) { m_mask = mask; }
153 void SetId(long id) { m_itemId = id; }
154 void SetColumn(int col) { m_col = col; }
155 void SetState(long state) { m_state = state; m_stateMask |= state; }
156 void SetStateMask(long stateMask) { m_stateMask = stateMask; }
157 void SetText(const wxString& text) { m_text = text; }
158 void SetImage(int image) { m_image = image; }
159 void SetData(long data) { m_data = data; }
160 void SetData(void *data) { m_data = (long)data; }
161
162 void SetWidth(int width) { m_width = width; }
163 void SetAlign(wxListColumnFormat align) { m_format = align; }
164
165 void SetTextColour(const wxColour& colText)
166 { Attributes().SetTextColour(colText); }
167 void SetBackgroundColour(const wxColour& colBack)
168 { Attributes().SetBackgroundColour(colBack); }
169 void SetFont(const wxFont& font)
170 { Attributes().SetFont(font); }
171
172 // accessors
173 long GetMask() const { return m_mask; }
174 long GetId() const { return m_itemId; }
175 int GetColumn() const { return m_col; }
176 long GetState() const { return m_state & m_stateMask; }
177 const wxString& GetText() const { return m_text; }
178 int GetImage() const { return m_image; }
179 long GetData() const { return m_data; }
180
181 int GetWidth() const { return m_width; }
182 wxListColumnFormat GetAlign() const { return (wxListColumnFormat)m_format; }
183
184 wxListItemAttr *GetAttributes() const { return m_attr; }
185 bool HasAttributes() const { return m_attr != NULL; }
186
187 const wxColour& GetTextColour() const
188 { return HasAttributes() ? m_attr->GetTextColour() : wxNullColour; }
189 const wxColour& GetBackgroundColour() const
190 { return HasAttributes() ? m_attr->GetBackgroundColour()
191 : wxNullColour; }
192 const wxFont& GetFont() const
193 { return HasAttributes() ? m_attr->GetFont() : wxNullFont; }
194
195 // these members are public for compatibility
196
197 long m_mask; // Indicates what fields are valid
198 long m_itemId; // The zero-based item position
199 int m_col; // Zero-based column, if in report mode
200 long m_state; // The state of the item
201 long m_stateMask;// Which flags of m_state are valid (uses same flags)
202 wxString m_text; // The label/header text
203 int m_image; // The zero-based index into an image list
204 long m_data; // App-defined data
205
206 // For columns only
207 int m_format; // left, right, centre
208 int m_width; // width of column
209
210protected:
211 // creates m_attr if we don't have it yet
212 wxListItemAttr& Attributes()
213 {
214 if ( !m_attr )
215 m_attr = new wxListItemAttr;
216
217 return *m_attr;
218 }
219
220 wxListItemAttr *m_attr; // optional pointer to the items style
221
222private:
223 DECLARE_DYNAMIC_CLASS(wxListItem)
224};
225
226// ----------------------------------------------------------------------------
227// include the wxListCtrl class declaration
228// ----------------------------------------------------------------------------
229
2049ba38 230#if defined(__WXMSW__)
bdc72a22
VZ
231 #ifdef __WIN16__
232 #include "wx/generic/listctrl.h"
233 #else
234 #include "wx/msw/listctrl.h"
235 #endif
2049ba38 236#elif defined(__WXMOTIF__)
bdc72a22 237 #include "wx/generic/listctrl.h"
2049ba38 238#elif defined(__WXGTK__)
bdc72a22 239 #include "wx/generic/listctrl.h"
b4e76e0d 240#elif defined(__WXQT__)
bdc72a22 241 #include "wx/generic/listctrl.h"
34138703 242#elif defined(__WXMAC__)
bdc72a22 243 #include "wx/generic/listctrl.h"
1777b9bb 244#elif defined(__WXPM__)
bdc72a22 245 #include "wx/generic/listctrl.h"
34138703 246#elif defined(__WXSTUBS__)
bdc72a22 247 #include "wx/generic/listctrl.h"
c801d85f
KB
248#endif
249
86f975a8
VZ
250// ----------------------------------------------------------------------------
251// wxListEvent - the event class for the wxListCtrl notifications
252// ----------------------------------------------------------------------------
253
254class WXDLLEXPORT wxListEvent : public wxNotifyEvent
255{
256public:
257 wxListEvent(wxEventType commandType = wxEVT_NULL, int id = 0);
258
259 int m_code;
260 long m_itemIndex;
261 long m_oldItemIndex;
262 int m_col;
263 bool m_cancelled;
264 wxPoint m_pointDrag;
265
266 wxListItem m_item;
cdf1e714 267
0b855868
RR
268 inline int GetCode() { return m_code; }
269 inline long GetIndex() { return m_itemIndex; }
270 inline long GetOldIndex() { return m_oldItemIndex; }
271 inline long GetItem() { return m_itemIndex; }
272 inline long GetOldItem() { return m_oldItemIndex; }
273 inline int GetColumn() { return m_col; }
274 inline bool Cancelled() { return m_cancelled; }
275 inline wxPoint GetPoint() { return m_pointDrag; }
276 inline const wxString &GetLabel() const { return m_item.m_text; }
277 inline const wxString &GetText() const { return m_item.m_text; }
278 inline int GetImage() { return m_item.m_image; }
279 inline long GetData() { return m_item.m_data; }
280 inline long GetMask() { return m_item.m_mask; }
281 inline const wxListItem &GetItem() const { return m_item; }
86f975a8 282
e4c730e9
RR
283#ifndef __WXMSW__
284 void CopyObject(wxObject& object_dest) const;
285#endif
286
86f975a8
VZ
287private:
288 DECLARE_DYNAMIC_CLASS(wxListEvent)
289};
290
291typedef void (wxEvtHandler::*wxListEventFunction)(wxListEvent&);
292
293#define EVT_LIST_BEGIN_DRAG(id, fn) { wxEVT_COMMAND_LIST_BEGIN_DRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL },
294#define EVT_LIST_BEGIN_RDRAG(id, fn) { wxEVT_COMMAND_LIST_BEGIN_RDRAG, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL },
295#define EVT_LIST_BEGIN_LABEL_EDIT(id, fn) { wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL },
296#define EVT_LIST_END_LABEL_EDIT(id, fn) { wxEVT_COMMAND_LIST_END_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL },
297#define EVT_LIST_DELETE_ITEM(id, fn) { wxEVT_COMMAND_LIST_DELETE_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL },
298#define EVT_LIST_DELETE_ALL_ITEMS(id, fn) { wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL },
299#define EVT_LIST_GET_INFO(id, fn) { wxEVT_COMMAND_LIST_GET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL },
300#define EVT_LIST_SET_INFO(id, fn) { wxEVT_COMMAND_LIST_SET_INFO, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL },
301#define EVT_LIST_ITEM_SELECTED(id, fn) { wxEVT_COMMAND_LIST_ITEM_SELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL },
302#define EVT_LIST_ITEM_DESELECTED(id, fn) { wxEVT_COMMAND_LIST_ITEM_DESELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL },
303#define EVT_LIST_KEY_DOWN(id, fn) { wxEVT_COMMAND_LIST_KEY_DOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL },
304#define EVT_LIST_INSERT_ITEM(id, fn) { wxEVT_COMMAND_LIST_INSERT_ITEM, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL },
305#define EVT_LIST_COL_CLICK(id, fn) { wxEVT_COMMAND_LIST_COL_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, NULL },
4debf135
UC
306#define EVT_LIST_ITEM_RIGHT_CLICK(id, fn) { wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL },
307#define EVT_LIST_ITEM_MIDDLE_CLICK(id, fn) { wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL },
86f975a8
VZ
308#define EVT_LIST_ITEM_ACTIVATED(id, fn) { wxEVT_COMMAND_LIST_ITEM_ACTIVATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction) & fn, (wxObject *) NULL },
309
c801d85f 310#endif
34138703 311 // _WX_LISTCTRL_H_BASE_