]> git.saurik.com Git - wxWidgets.git/blob - include/wx/listbase.h
added more reserved functions
[wxWidgets.git] / include / wx / listbase.h
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) wxWidgets team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_LISTBASE_H_BASE_
13 #define _WX_LISTBASE_H_BASE_
14
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 // #pragma interface "listctrlbase.h"
17 #endif
18
19 #include "wx/defs.h"
20
21 #if wxUSE_LISTCTRL
22
23 #include "wx/colour.h"
24 #include "wx/font.h"
25 #include "wx/gdicmn.h"
26
27 #include "wx/event.h"
28
29 // ----------------------------------------------------------------------------
30 // types
31 // ----------------------------------------------------------------------------
32
33 // type of compare function for wxListCtrl sort operation
34 typedef 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
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
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)
112 enum
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)
122 enum
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)
131 enum 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
140 enum
141 {
142 wxLIST_AUTOSIZE = -1,
143 wxLIST_AUTOSIZE_USEHEADER = -2 // partly supported by generic version
144 };
145
146 // Flag values for GetItemRect
147 enum
148 {
149 wxLIST_RECT_BOUNDS,
150 wxLIST_RECT_ICON,
151 wxLIST_RECT_LABEL
152 };
153
154 // Flag values for FindItem (MSW only)
155 enum
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
167 class WXDLLEXPORT wxListItemAttr
168 {
169 public:
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
191 private:
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
201 class WXDLLEXPORT wxListItem : public wxObject
202 {
203 public:
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
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)
247 { m_mask |= wxLIST_MASK_DATA; m_data = wxPtrToUInt(data); }
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; }
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; }
268 wxUIntPtr GetData() const { return m_data; }
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
297 wxUIntPtr m_data; // App-defined data
298
299 // For columns only
300 int m_format; // left, right, centre
301 int m_width; // width of column
302
303 #ifdef __WXPM__
304 int m_miniImage; // handle to the mini image for OS/2
305 #endif
306
307 protected:
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
333 private:
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
344 class WXDLLEXPORT wxListEvent : public wxNotifyEvent
345 {
346 public:
347 wxListEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
348 : wxNotifyEvent(commandType, winid)
349 , m_code(0)
350 , m_oldItemIndex(0)
351 , m_itemIndex(0)
352 , m_col(0)
353 , m_pointDrag()
354 , m_item()
355 , m_editCancelled(false)
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)
366 , m_editCancelled(event.m_editCancelled)
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; }
376 long GetData() const { return m_item.m_data; }
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
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
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
408 protected:
409 bool m_editCancelled;
410
411 private:
412 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxListEvent)
413 };
414
415 // ----------------------------------------------------------------------------
416 // wxListCtrl event macros
417 // ----------------------------------------------------------------------------
418
419 BEGIN_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)
426 #if WXWIN_COMPATIBILITY_2_4
427 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO, 706)
428 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO, 707)
429 #endif
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)
444 END_DECLARE_EVENT_TYPES()
445
446 typedef void (wxEvtHandler::*wxListEventFunction)(wxListEvent&);
447
448 #define wxListEventHandler(func) \
449 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxListEventFunction, &func)
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
479 #if WXWIN_COMPATIBILITY_2_4
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)
482 #endif
483
484 #endif // wxUSE_LISTCTRL
485
486 #endif
487 // _WX_LISTCTRL_H_BASE_