]> git.saurik.com Git - wxWidgets.git/blame - include/wx/listbase.h
due to a typo in #if condition, validation was disabled for wizard pages -- fixed now
[wxWidgets.git] / include / wx / listbase.h
CommitLineData
e81a301c
JS
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$
77ffb593 8// Copyright: (c) wxWidgets team
65571936 9// Licence: wxWindows licence
e81a301c
JS
10///////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_LISTBASE_H_BASE_
13#define _WX_LISTBASE_H_BASE_
14
12028905 15#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
e81a301c
JS
16// #pragma interface "listctrlbase.h"
17#endif
18
2ecf902b
WS
19#include "wx/defs.h"
20
e81a301c
JS
21#if wxUSE_LISTCTRL
22
87f086bc 23#include "wx/colour.h"
ec64c745 24#include "wx/font.h"
87f086bc
VZ
25#include "wx/gdicmn.h"
26
27#include "wx/event.h"
ec64c745 28
e81a301c
JS
29// ----------------------------------------------------------------------------
30// types
31// ----------------------------------------------------------------------------
32
33// type of compare function for wxListCtrl sort operation
34typedef int (wxCALLBACK *wxListCtrlCompare)(long item1, long item2, long sortData);
35
36// ----------------------------------------------------------------------------
37// wxListCtrl constants
38// ----------------------------------------------------------------------------
39
40// style flags
41#define wxLC_VRULES 0x0001
42#define wxLC_HRULES 0x0002
43
44#define wxLC_ICON 0x0004
45#define wxLC_SMALL_ICON 0x0008
46#define wxLC_LIST 0x0010
47#define wxLC_REPORT 0x0020
48
49#define wxLC_ALIGN_TOP 0x0040
50#define wxLC_ALIGN_LEFT 0x0080
51#define wxLC_AUTOARRANGE 0x0100
52#define wxLC_VIRTUAL 0x0200
53#define wxLC_EDIT_LABELS 0x0400
54#define wxLC_NO_HEADER 0x0800
55#define wxLC_NO_SORT_HEADER 0x1000
56#define wxLC_SINGLE_SEL 0x2000
57#define wxLC_SORT_ASCENDING 0x4000
58#define wxLC_SORT_DESCENDING 0x8000
59
60#define wxLC_MASK_TYPE (wxLC_ICON | wxLC_SMALL_ICON | wxLC_LIST | wxLC_REPORT)
61#define wxLC_MASK_ALIGN (wxLC_ALIGN_TOP | wxLC_ALIGN_LEFT)
62#define wxLC_MASK_SORT (wxLC_SORT_ASCENDING | wxLC_SORT_DESCENDING)
63
64// for compatibility only
65#define wxLC_USER_TEXT wxLC_VIRTUAL
66
67// Omitted because
68// (a) too much detail
69// (b) not enough style flags
70// (c) not implemented anyhow in the generic version
71//
72// #define wxLC_NO_SCROLL
73// #define wxLC_NO_LABEL_WRAP
74// #define wxLC_OWNERDRAW_FIXED
75// #define wxLC_SHOW_SEL_ALWAYS
76
77// Mask flags to tell app/GUI what fields of wxListItem are valid
78#define wxLIST_MASK_STATE 0x0001
79#define wxLIST_MASK_TEXT 0x0002
80#define wxLIST_MASK_IMAGE 0x0004
81#define wxLIST_MASK_DATA 0x0008
82#define wxLIST_SET_ITEM 0x0010
83#define wxLIST_MASK_WIDTH 0x0020
84#define wxLIST_MASK_FORMAT 0x0040
85
86// State flags for indicating the state of an item
87#define wxLIST_STATE_DONTCARE 0x0000
88#define wxLIST_STATE_DROPHILITED 0x0001 // MSW only
89#define wxLIST_STATE_FOCUSED 0x0002
90#define wxLIST_STATE_SELECTED 0x0004
91#define wxLIST_STATE_CUT 0x0008 // MSW only
c220541d
DW
92#define wxLIST_STATE_DISABLED 0x0010 // OS2 only
93#define wxLIST_STATE_FILTERED 0x0020 // OS2 only
94#define wxLIST_STATE_INUSE 0x0040 // OS2 only
95#define wxLIST_STATE_PICKED 0x0080 // OS2 only
96#define wxLIST_STATE_SOURCE 0x0100 // OS2 only
e81a301c
JS
97
98// Hit test flags, used in HitTest
99#define wxLIST_HITTEST_ABOVE 0x0001 // Above the client area.
100#define wxLIST_HITTEST_BELOW 0x0002 // Below the client area.
101#define wxLIST_HITTEST_NOWHERE 0x0004 // In the client area but below the last item.
102#define wxLIST_HITTEST_ONITEMICON 0x0020 // On the bitmap associated with an item.
103#define wxLIST_HITTEST_ONITEMLABEL 0x0080 // On the label (string) associated with an item.
104#define wxLIST_HITTEST_ONITEMRIGHT 0x0100 // In the area to the right of an item.
105#define wxLIST_HITTEST_ONITEMSTATEICON 0x0200 // On the state icon for a tree view item that is in a user-defined state.
106#define wxLIST_HITTEST_TOLEFT 0x0400 // To the left of the client area.
107#define wxLIST_HITTEST_TORIGHT 0x0800 // To the right of the client area.
108
109#define wxLIST_HITTEST_ONITEM (wxLIST_HITTEST_ONITEMICON | wxLIST_HITTEST_ONITEMLABEL | wxLIST_HITTEST_ONITEMSTATEICON)
110
111// Flags for GetNextItem (MSW only except wxLIST_NEXT_ALL)
112enum
113{
114 wxLIST_NEXT_ABOVE, // Searches for an item above the specified item
115 wxLIST_NEXT_ALL, // Searches for subsequent item by index
116 wxLIST_NEXT_BELOW, // Searches for an item below the specified item
117 wxLIST_NEXT_LEFT, // Searches for an item to the left of the specified item
118 wxLIST_NEXT_RIGHT // Searches for an item to the right of the specified item
119};
120
121// Alignment flags for Arrange (MSW only except wxLIST_ALIGN_LEFT)
122enum
123{
124 wxLIST_ALIGN_DEFAULT,
125 wxLIST_ALIGN_LEFT,
126 wxLIST_ALIGN_TOP,
127 wxLIST_ALIGN_SNAP_TO_GRID
128};
129
130// Column format (MSW only except wxLIST_FORMAT_LEFT)
131enum wxListColumnFormat
132{
133 wxLIST_FORMAT_LEFT,
134 wxLIST_FORMAT_RIGHT,
135 wxLIST_FORMAT_CENTRE,
136 wxLIST_FORMAT_CENTER = wxLIST_FORMAT_CENTRE
137};
138
139// Autosize values for SetColumnWidth
140enum
141{
142 wxLIST_AUTOSIZE = -1,
143 wxLIST_AUTOSIZE_USEHEADER = -2 // partly supported by generic version
144};
145
146// Flag values for GetItemRect
147enum
148{
149 wxLIST_RECT_BOUNDS,
150 wxLIST_RECT_ICON,
151 wxLIST_RECT_LABEL
152};
153
154// Flag values for FindItem (MSW only)
155enum
156{
157 wxLIST_FIND_UP,
158 wxLIST_FIND_DOWN,
159 wxLIST_FIND_LEFT,
160 wxLIST_FIND_RIGHT
161};
162
163// ----------------------------------------------------------------------------
164// wxListItemAttr: a structure containing the visual attributes of an item
165// ----------------------------------------------------------------------------
166
167class WXDLLEXPORT wxListItemAttr
168{
169public:
170 // ctors
171 wxListItemAttr() { }
172 wxListItemAttr(const wxColour& colText,
173 const wxColour& colBack,
174 const wxFont& font)
175 : m_colText(colText), m_colBack(colBack), m_font(font) { }
176
177 // setters
178 void SetTextColour(const wxColour& colText) { m_colText = colText; }
179 void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; }
180 void SetFont(const wxFont& font) { m_font = font; }
181
182 // accessors
183 bool HasTextColour() const { return m_colText.Ok(); }
184 bool HasBackgroundColour() const { return m_colBack.Ok(); }
185 bool HasFont() const { return m_font.Ok(); }
186
187 const wxColour& GetTextColour() const { return m_colText; }
188 const wxColour& GetBackgroundColour() const { return m_colBack; }
189 const wxFont& GetFont() const { return m_font; }
190
191private:
192 wxColour m_colText,
193 m_colBack;
194 wxFont m_font;
195};
196
197// ----------------------------------------------------------------------------
198// wxListItem: the item or column info, used to exchange data with wxListCtrl
199// ----------------------------------------------------------------------------
200
201class WXDLLEXPORT wxListItem : public wxObject
202{
203public:
204 wxListItem() { Init(); m_attr = NULL; }
205 wxListItem(const wxListItem& item)
206 : wxObject(),
207 m_mask(item.m_mask),
208 m_itemId(item.m_itemId),
209 m_col(item.m_col),
210 m_state(item.m_state),
211 m_stateMask(item.m_stateMask),
212 m_text(item.m_text),
213 m_image(item.m_image),
214 m_data(item.m_data),
215 m_format(item.m_format),
216 m_width(item.m_width),
217 m_attr(NULL)
218 {
219 // copy list item attributes
220 if( item.HasAttributes() )
221 m_attr = new wxListItemAttr(*item.GetAttributes());
222 }
223 virtual ~wxListItem() { delete m_attr; }
224
225 // resetting
226 void Clear() { Init(); m_text.clear(); ClearAttributes(); }
227 void ClearAttributes() { if ( m_attr ) { delete m_attr; m_attr = NULL; } }
228
229 // setters
6770762d
VZ
230 void SetMask(long mask)
231 { m_mask = mask; }
232 void SetId(long id)
233 { m_itemId = id; }
234 void SetColumn(int col)
235 { m_col = col; }
236 void SetState(long state)
237 { m_mask |= wxLIST_MASK_STATE; m_state = state; m_stateMask |= state; }
238 void SetStateMask(long stateMask)
239 { m_stateMask = stateMask; }
240 void SetText(const wxString& text)
241 { m_mask |= wxLIST_MASK_TEXT; m_text = text; }
242 void SetImage(int image)
243 { m_mask |= wxLIST_MASK_IMAGE; m_image = image; }
244 void SetData(long data)
245 { m_mask |= wxLIST_MASK_DATA; m_data = data; }
246 void SetData(void *data)
0d01dd51 247 { m_mask |= wxLIST_MASK_DATA; m_data = wxPtrToUInt(data); }
6770762d
VZ
248
249 void SetWidth(int width)
250 { m_mask |= wxLIST_MASK_WIDTH; m_width = width; }
251 void SetAlign(wxListColumnFormat align)
252 { m_mask |= wxLIST_MASK_FORMAT; m_format = align; }
e81a301c
JS
253
254 void SetTextColour(const wxColour& colText)
255 { Attributes().SetTextColour(colText); }
256 void SetBackgroundColour(const wxColour& colBack)
257 { Attributes().SetBackgroundColour(colBack); }
258 void SetFont(const wxFont& font)
259 { Attributes().SetFont(font); }
260
261 // accessors
262 long GetMask() const { return m_mask; }
263 long GetId() const { return m_itemId; }
264 int GetColumn() const { return m_col; }
265 long GetState() const { return m_state & m_stateMask; }
266 const wxString& GetText() const { return m_text; }
267 int GetImage() const { return m_image; }
0d01dd51 268 wxUIntPtr GetData() const { return m_data; }
e81a301c
JS
269
270 int GetWidth() const { return m_width; }
271 wxListColumnFormat GetAlign() const { return (wxListColumnFormat)m_format; }
272
273 wxListItemAttr *GetAttributes() const { return m_attr; }
274 bool HasAttributes() const { return m_attr != NULL; }
275
276 wxColour GetTextColour() const
277 { return HasAttributes() ? m_attr->GetTextColour() : wxNullColour; }
278 wxColour GetBackgroundColour() const
279 { return HasAttributes() ? m_attr->GetBackgroundColour()
280 : wxNullColour; }
281 wxFont GetFont() const
282 { return HasAttributes() ? m_attr->GetFont() : wxNullFont; }
283
284 // this conversion is necessary to make old code using GetItem() to
285 // compile
286 operator long() const { return m_itemId; }
287
288 // these members are public for compatibility
289
290 long m_mask; // Indicates what fields are valid
291 long m_itemId; // The zero-based item position
292 int m_col; // Zero-based column, if in report mode
293 long m_state; // The state of the item
294 long m_stateMask;// Which flags of m_state are valid (uses same flags)
295 wxString m_text; // The label/header text
296 int m_image; // The zero-based index into an image list
0d01dd51 297 wxUIntPtr m_data; // App-defined data
e81a301c
JS
298
299 // For columns only
300 int m_format; // left, right, centre
301 int m_width; // width of column
302
c220541d
DW
303#ifdef __WXPM__
304 int m_miniImage; // handle to the mini image for OS/2
305#endif
306
e81a301c
JS
307protected:
308 // creates m_attr if we don't have it yet
309 wxListItemAttr& Attributes()
310 {
311 if ( !m_attr )
312 m_attr = new wxListItemAttr;
313
314 return *m_attr;
315 }
316
317 void Init()
318 {
319 m_mask = 0;
320 m_itemId = 0;
321 m_col = 0;
322 m_state = 0;
323 m_stateMask = 0;
324 m_image = 0;
325 m_data = 0;
326
327 m_format = wxLIST_FORMAT_CENTRE;
328 m_width = 0;
329 }
330
331 wxListItemAttr *m_attr; // optional pointer to the items style
332
333private:
334 // VZ: this is strange, we have a copy ctor but not operator=(), why?
335 wxListItem& operator=(const wxListItem& item);
336
337 DECLARE_DYNAMIC_CLASS(wxListItem)
338};
339
340// ----------------------------------------------------------------------------
341// wxListEvent - the event class for the wxListCtrl notifications
342// ----------------------------------------------------------------------------
343
344class WXDLLEXPORT wxListEvent : public wxNotifyEvent
345{
346public:
921176c5
DE
347 wxListEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
348 : wxNotifyEvent(commandType, winid)
e81a301c
JS
349 , m_code(0)
350 , m_oldItemIndex(0)
351 , m_itemIndex(0)
352 , m_col(0)
353 , m_pointDrag()
354 , m_item()
d2ed74b9 355 , m_editCancelled(false)
e81a301c
JS
356 { }
357
358 wxListEvent(const wxListEvent& event)
359 : wxNotifyEvent(event)
360 , m_code(event.m_code)
361 , m_oldItemIndex(event.m_oldItemIndex)
362 , m_itemIndex(event.m_itemIndex)
363 , m_col(event.m_col)
364 , m_pointDrag(event.m_pointDrag)
365 , m_item(event.m_item)
d2ed74b9 366 , m_editCancelled(event.m_editCancelled)
e81a301c
JS
367 { }
368
369 int GetKeyCode() const { return m_code; }
370 long GetIndex() const { return m_itemIndex; }
371 int GetColumn() const { return m_col; }
372 wxPoint GetPoint() const { return m_pointDrag; }
373 const wxString& GetLabel() const { return m_item.m_text; }
374 const wxString& GetText() const { return m_item.m_text; }
375 int GetImage() const { return m_item.m_image; }
106d80ad 376 long GetData() const { return wx_static_cast(long, m_item.m_data); }
e81a301c
JS
377 long GetMask() const { return m_item.m_mask; }
378 const wxListItem& GetItem() const { return m_item; }
379
380 // for wxEVT_COMMAND_LIST_CACHE_HINT only
381 long GetCacheFrom() const { return m_oldItemIndex; }
382 long GetCacheTo() const { return m_itemIndex; }
383
d2ed74b9
VZ
384 // was label editing canceled? (for wxEVT_COMMAND_LIST_END_LABEL_EDIT only)
385 bool IsEditCancelled() const { return m_editCancelled; }
386 void SetEditCanceled(bool editCancelled) { m_editCancelled = editCancelled; }
387
e81a301c
JS
388#if WXWIN_COMPATIBILITY_2_2
389 // these methods don't do anything at all
390 long GetOldIndex() const { return 0; }
391 long GetOldItem() const { return 0; }
392
393 // this one is superseded by GetKeyCode()
394 int GetCode() const { return GetKeyCode(); }
395#endif // WXWIN_COMPATIBILITY_2_2
396
397 virtual wxEvent *Clone() const { return new wxListEvent(*this); }
398
399//protected: -- not for backwards compatibility
400 int m_code;
401 long m_oldItemIndex; // only for wxEVT_COMMAND_LIST_CACHE_HINT
402 long m_itemIndex;
403 int m_col;
404 wxPoint m_pointDrag;
405
406 wxListItem m_item;
407
d2ed74b9
VZ
408protected:
409 bool m_editCancelled;
410
e81a301c 411private:
fc7a2a60 412 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxListEvent)
e81a301c
JS
413};
414
415// ----------------------------------------------------------------------------
416// wxListCtrl event macros
417// ----------------------------------------------------------------------------
418
419BEGIN_DECLARE_EVENT_TYPES()
420 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG, 700)
421 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG, 701)
422 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, 702)
423 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT, 703)
424 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM, 704)
425 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, 705)
c3627a00 426#if WXWIN_COMPATIBILITY_2_4
e81a301c
JS
427 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO, 706)
428 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO, 707)
c3627a00 429#endif
e81a301c
JS
430 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED, 708)
431 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED, 709)
432 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN, 710)
433 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM, 711)
434 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK, 712)
435 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, 713)
436 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK, 714)
437 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED, 715)
438 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT, 716)
439 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK, 717)
440 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG, 718)
441 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING, 719)
442 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG, 720)
443 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED, 721)
444END_DECLARE_EVENT_TYPES()
445
446typedef void (wxEvtHandler::*wxListEventFunction)(wxListEvent&);
447
7fa03f04 448#define wxListEventHandler(func) \
8bc3ec1f 449 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxListEventFunction, &func)
7fa03f04
VZ
450
451#define wx__DECLARE_LISTEVT(evt, id, fn) \
452 wx__DECLARE_EVT1(wxEVT_COMMAND_LIST_ ## evt, id, wxListEventHandler(fn))
453
454#define EVT_LIST_BEGIN_DRAG(id, fn) wx__DECLARE_LISTEVT(BEGIN_DRAG, id, fn)
455#define EVT_LIST_BEGIN_RDRAG(id, fn) wx__DECLARE_LISTEVT(BEGIN_RDRAG, id, fn)
456#define EVT_LIST_BEGIN_LABEL_EDIT(id, fn) wx__DECLARE_LISTEVT(BEGIN_LABEL_EDIT, id, fn)
457#define EVT_LIST_END_LABEL_EDIT(id, fn) wx__DECLARE_LISTEVT(END_LABEL_EDIT, id, fn)
458#define EVT_LIST_DELETE_ITEM(id, fn) wx__DECLARE_LISTEVT(DELETE_ITEM, id, fn)
459#define EVT_LIST_DELETE_ALL_ITEMS(id, fn) wx__DECLARE_LISTEVT(DELETE_ALL_ITEMS, id, fn)
460#define EVT_LIST_KEY_DOWN(id, fn) wx__DECLARE_LISTEVT(KEY_DOWN, id, fn)
461#define EVT_LIST_INSERT_ITEM(id, fn) wx__DECLARE_LISTEVT(INSERT_ITEM, id, fn)
462
463#define EVT_LIST_COL_CLICK(id, fn) wx__DECLARE_LISTEVT(COL_CLICK, id, fn)
464#define EVT_LIST_COL_RIGHT_CLICK(id, fn) wx__DECLARE_LISTEVT(COL_RIGHT_CLICK, id, fn)
465#define EVT_LIST_COL_BEGIN_DRAG(id, fn) wx__DECLARE_LISTEVT(COL_BEGIN_DRAG, id, fn)
466#define EVT_LIST_COL_DRAGGING(id, fn) wx__DECLARE_LISTEVT(COL_DRAGGING, id, fn)
467#define EVT_LIST_COL_END_DRAG(id, fn) wx__DECLARE_LISTEVT(COL_END_DRAG, id, fn)
468
469#define EVT_LIST_ITEM_SELECTED(id, fn) wx__DECLARE_LISTEVT(ITEM_SELECTED, id, fn)
470#define EVT_LIST_ITEM_DESELECTED(id, fn) wx__DECLARE_LISTEVT(ITEM_DESELECTED, id, fn)
471#define EVT_LIST_ITEM_RIGHT_CLICK(id, fn) wx__DECLARE_LISTEVT(ITEM_RIGHT_CLICK, id, fn)
472#define EVT_LIST_ITEM_MIDDLE_CLICK(id, fn) wx__DECLARE_LISTEVT(ITEM_MIDDLE_CLICK, id, fn)
473#define EVT_LIST_ITEM_ACTIVATED(id, fn) wx__DECLARE_LISTEVT(ITEM_ACTIVATED, id, fn)
474#define EVT_LIST_ITEM_FOCUSED(id, fn) wx__DECLARE_LISTEVT(ITEM_FOCUSED, id, fn)
475
476#define EVT_LIST_CACHE_HINT(id, fn) wx__DECLARE_LISTEVT(CACHE_HINT, id, fn)
477
478
c3627a00 479#if WXWIN_COMPATIBILITY_2_4
7fa03f04
VZ
480#define EVT_LIST_GET_INFO(id, fn) wx__DECLARE_LISTEVT(GET_INFO, id, fn)
481#define EVT_LIST_SET_INFO(id, fn) wx__DECLARE_LISTEVT(SET_INFO, id, fn)
c3627a00 482#endif
e81a301c
JS
483
484#endif // wxUSE_LISTCTRL
485
486#endif
487 // _WX_LISTCTRL_H_BASE_