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