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