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