]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/listctrl.h
Added wxDataViewCustomCell.
[wxWidgets.git] / include / wx / generic / listctrl.h
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
bdc72a22 2// Name: wx/generic/listctrl.h
c801d85f
KB
3// Purpose: Generic list control
4// Author: Robert Roebling
5// Created: 01/02/97
52f2ad08 6// RCS-ID: $Id$
371a5b4e 7// Copyright: (c) 1998 Robert Roebling and Julian Smart
65571936 8// Licence: wxWindows licence
c801d85f
KB
9/////////////////////////////////////////////////////////////////////////////
10
11#ifndef __LISTCTRLH_G__
12#define __LISTCTRLH_G__
13
c801d85f
KB
14#include "wx/defs.h"
15#include "wx/object.h"
ca135148
SC
16#ifdef __WXMAC__
17#include "wx/imaglist.h"
18#else
9cb07953 19#include "wx/generic/imaglist.h"
ca135148 20#endif
9cb07953 21
c801d85f
KB
22#include "wx/control.h"
23#include "wx/timer.h"
24#include "wx/dcclient.h"
25#include "wx/scrolwin.h"
26#include "wx/settings.h"
e81a301c 27#include "wx/listbase.h"
c801d85f 28
1e6d9499
JS
29#if wxUSE_DRAG_AND_DROP
30class WXDLLEXPORT wxDropTarget;
31#endif
32
c801d85f
KB
33//-----------------------------------------------------------------------------
34// classes
35//-----------------------------------------------------------------------------
36
1e6d9499
JS
37class WXDLLEXPORT wxListItem;
38class WXDLLEXPORT wxListEvent;
f9ceab7c 39
3a5bcc4d 40#if !defined(__WXMSW__) || defined(__WXUNIVERSAL__)
1e6d9499 41class WXDLLEXPORT wxListCtrl;
f9ceab7c
JS
42#define wxImageListType wxImageList
43#else
44#define wxImageListType wxGenericImageList
45#endif
c801d85f
KB
46
47//-----------------------------------------------------------------------------
48// internal classes
49//-----------------------------------------------------------------------------
50
1e6d9499
JS
51class WXDLLEXPORT wxListHeaderData;
52class WXDLLEXPORT wxListItemData;
53class WXDLLEXPORT wxListLineData;
c801d85f 54
1e6d9499
JS
55class WXDLLEXPORT wxListHeaderWindow;
56class WXDLLEXPORT wxListMainWindow;
c801d85f 57
1e6d9499 58class WXDLLEXPORT wxListRenameTimer;
e179bd65 59class WXDLLEXPORT wxListTextCtrl;
c801d85f 60
c801d85f
KB
61//-----------------------------------------------------------------------------
62// wxListCtrl
63//-----------------------------------------------------------------------------
64
3cd94a0d 65class WXDLLEXPORT wxGenericListCtrl: public wxControl
c801d85f 66{
b16088bf 67public:
3cd94a0d
JS
68 wxGenericListCtrl();
69 wxGenericListCtrl( wxWindow *parent,
ca65c044 70 wxWindowID winid = wxID_ANY,
674ac8b9
VZ
71 const wxPoint &pos = wxDefaultPosition,
72 const wxSize &size = wxDefaultSize,
73 long style = wxLC_ICON,
74 const wxValidator& validator = wxDefaultValidator,
52f2ad08 75 const wxString &name = wxListCtrlNameStr)
6463b9f5
JS
76 {
77 Create(parent, winid, pos, size, style, validator, name);
78 }
3cd94a0d 79 ~wxGenericListCtrl();
29149a64 80
674ac8b9 81 bool Create( wxWindow *parent,
ca65c044 82 wxWindowID winid = wxID_ANY,
674ac8b9
VZ
83 const wxPoint &pos = wxDefaultPosition,
84 const wxSize &size = wxDefaultSize,
85 long style = wxLC_ICON,
86 const wxValidator& validator = wxDefaultValidator,
52f2ad08 87 const wxString &name = wxListCtrlNameStr);
b16088bf 88
e487524e 89 bool GetColumn( int col, wxListItem& item ) const;
debe6624 90 bool SetColumn( int col, wxListItem& item );
e487524e 91 int GetColumnWidth( int col ) const;
debe6624 92 bool SetColumnWidth( int col, int width);
e179bd65 93 int GetCountPerPage() const; // not the same in wxGLC as in Windows, I think
11ebea16 94 wxRect GetViewRect() const;
b16088bf 95
e487524e 96 bool GetItem( wxListItem& info ) const;
c801d85f 97 bool SetItem( wxListItem& info ) ;
debe6624 98 long SetItem( long index, int col, const wxString& label, int imageId = -1 );
e487524e 99 int GetItemState( long item, long stateMask ) const;
debe6624 100 bool SetItemState( long item, long state, long stateMask);
aba3d35e 101 bool SetItemImage( long item, int image, int selImage = -1 );
e487524e 102 wxString GetItemText( long item ) const;
debe6624 103 void SetItemText( long item, const wxString& str );
81ce36aa 104 wxUIntPtr GetItemData( long item ) const;
debe6624 105 bool SetItemData( long item, long data );
0a240683 106 bool GetItemRect( long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS ) const;
e487524e 107 bool GetItemPosition( long item, wxPoint& pos ) const;
debe6624 108 bool SetItemPosition( long item, const wxPoint& pos ); // not supported in wxGLC
e179bd65
RR
109 int GetItemCount() const;
110 int GetColumnCount() const;
ca65c044 111 void SetItemSpacing( int spacing, bool isSmall = false );
5db8d758 112 wxSize GetItemSpacing() const;
5b98eb2f
RL
113 void SetItemTextColour( long item, const wxColour& col);
114 wxColour GetItemTextColour( long item ) const;
115 void SetItemBackgroundColour( long item, const wxColour &col);
116 wxColour GetItemBackgroundColour( long item ) const;
35c2acd4
MW
117 void SetItemFont( long item, const wxFont &f);
118 wxFont GetItemFont( long item ) const;
e179bd65 119 int GetSelectedItemCount() const;
0530737d
VZ
120 wxColour GetTextColour() const;
121 void SetTextColour(const wxColour& col);
e179bd65 122 long GetTopItem() const;
b16088bf 123
ca65c044 124 void SetSingleStyle( long style, bool add = true ) ;
e179bd65
RR
125 void SetWindowStyleFlag( long style );
126 void RecreateWindow() {}
127 long GetNextItem( long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE ) const;
f9ceab7c
JS
128 wxImageListType *GetImageList( int which ) const;
129 void SetImageList( wxImageListType *imageList, int which );
130 void AssignImageList( wxImageListType *imageList, int which );
debe6624 131 bool Arrange( int flag = wxLIST_ALIGN_DEFAULT ); // always wxLIST_ALIGN_LEFT in wxGLC
57c4d796 132
4f22cf8d 133 void ClearAll();
debe6624 134 bool DeleteItem( long item );
e179bd65
RR
135 bool DeleteAllItems();
136 bool DeleteAllColumns();
debe6624 137 bool DeleteColumn( int col );
57c4d796 138
2c1f73ee
VZ
139 void SetItemCount(long count);
140
26e8da41
VZ
141 wxTextCtrl *EditLabel(long item,
142 wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl));
143 wxTextCtrl* GetEditControl() const;
144 void Edit( long item ) { EditLabel(item); }
57c4d796 145
debe6624 146 bool EnsureVisible( long item );
ca65c044 147 long FindItem( long start, const wxString& str, bool partial = false );
81ce36aa 148 long FindItem( long start, wxUIntPtr data );
e179bd65
RR
149 long FindItem( long start, const wxPoint& pt, int direction ); // not supported in wxGLC
150 long HitTest( const wxPoint& point, int& flags);
c801d85f 151 long InsertItem(wxListItem& info);
e179bd65
RR
152 long InsertItem( long index, const wxString& label );
153 long InsertItem( long index, int imageIndex );
154 long InsertItem( long index, const wxString& label, int imageIndex );
155 long InsertColumn( long col, wxListItem& info );
2f1e3c46
VZ
156 long InsertColumn( long col, const wxString& heading,
157 int format = wxLIST_FORMAT_LEFT, int width = -1 );
e179bd65
RR
158 bool ScrollList( int dx, int dy );
159 bool SortItems( wxListCtrlCompare fn, long data );
160 bool Update( long item );
6f02a879
VZ
161 // Must provide overload to avoid hiding it (and warnings about it)
162 virtual void Update() { wxControl::Update(); }
29149a64 163
b5d43d1d
VZ
164 // are we in report mode?
165 bool InReportView() const { return HasFlag(wxLC_REPORT); }
166
167 // are we in virtual report mode?
168 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL); }
169
170 // do we have a header window?
171 bool HasHeader() const
172 { return InReportView() && !HasFlag(wxLC_NO_HEADER); }
2c1f73ee 173
1a6cb56f
VZ
174 // refresh items selectively (only useful for virtual list controls)
175 void RefreshItem(long item);
176 void RefreshItems(long itemFrom, long itemTo);
177
5db8d758
VZ
178 // obsolete, don't use
179 wxDEPRECATED( int GetItemSpacing( bool isSmall ) const );
180
181
35d4c967
RD
182 virtual wxVisualAttributes GetDefaultAttributes() const
183 {
184 return GetClassDefaultAttributes(GetWindowVariant());
185 }
186
187 static wxVisualAttributes
188 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
189
1a6cb56f
VZ
190 // implementation only from now on
191 // -------------------------------
192
5180055b 193 void OnInternalIdle( );
b16088bf 194 void OnSize( wxSizeEvent &event );
57c4d796 195
77e7a1dc 196 // We have to hand down a few functions
ca65c044 197 virtual void Refresh(bool eraseBackground = true,
2f1e3c46 198 const wxRect *rect = NULL);
57c4d796 199
c5c528fc
VZ
200 virtual void Freeze();
201 virtual void Thaw();
202
203 virtual bool SetBackgroundColour( const wxColour &colour );
204 virtual bool SetForegroundColour( const wxColour &colour );
205 virtual wxColour GetBackgroundColour() const;
206 virtual wxColour GetForegroundColour() const;
207 virtual bool SetFont( const wxFont &font );
208 virtual bool SetCursor( const wxCursor &cursor );
57c4d796 209
1e6d9499 210#if wxUSE_DRAG_AND_DROP
c5c528fc
VZ
211 virtual void SetDropTarget( wxDropTarget *dropTarget );
212 virtual wxDropTarget *GetDropTarget() const;
1e6d9499
JS
213#endif
214
d4864e97 215 virtual bool ShouldInheritColours() const { return false; }
c5c528fc 216 virtual void SetFocus();
c801d85f 217
b16088bf
RR
218 // implementation
219 // --------------
57c4d796 220
f9ceab7c
JS
221 wxImageListType *m_imageListNormal;
222 wxImageListType *m_imageListSmall;
223 wxImageListType *m_imageListState; // what's that ?
29149a64 224 bool m_ownsImageListNormal,
2e12c11a
VS
225 m_ownsImageListSmall,
226 m_ownsImageListState;
c801d85f
KB
227 wxListHeaderWindow *m_headerWin;
228 wxListMainWindow *m_mainWin;
f8252483 229 wxCoord m_headerHeight;
a3622daa 230
2c1f73ee 231protected:
6f02a879
VZ
232 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
233
7447bdd7
VZ
234 // take into account the coordinates difference between the container
235 // window and the list control window itself here
236 virtual void DoClientToScreen( int *x, int *y ) const;
237 virtual void DoScreenToClient( int *x, int *y ) const;
238
6f02a879
VZ
239 virtual wxSize DoGetBestSize() const;
240
2c1f73ee
VZ
241 // return the text for the given column of the given item
242 virtual wxString OnGetItemText(long item, long column) const;
243
208458a7
RD
244 // return the icon for the given item. In report view, OnGetItemImage will
245 // only be called for the first column. See OnGetItemColumnImage for
246 // details.
2c1f73ee
VZ
247 virtual int OnGetItemImage(long item) const;
248
208458a7
RD
249 // return the icon for the given item and column.
250 virtual int OnGetItemColumnImage(long item, long column) const;
251
6c02c329
VZ
252 // return the attribute for the item (may return NULL if none)
253 virtual wxListItemAttr *OnGetItemAttr(long item) const;
254
2c1f73ee 255 // it calls our OnGetXXX() functions
ad08ef44 256 friend class WXDLLEXPORT wxListMainWindow;
2c1f73ee 257
b16088bf 258private:
cf1dfa6b
VZ
259 // create the header window
260 void CreateHeaderWindow();
261
f8252483
JS
262 // calculate and set height of the header
263 void CalculateAndSetHeaderHeight();
264
c0f8674c
VZ
265 // reposition the header and the main window in the report view depending
266 // on whether it should be shown or not
267 void ResizeReportView(bool showHeader);
268
b16088bf 269 DECLARE_EVENT_TABLE()
6b99f53e 270 DECLARE_DYNAMIC_CLASS(wxGenericListCtrl)
c801d85f
KB
271};
272
3a5bcc4d 273#if !defined(__WXMSW__) || defined(__WXUNIVERSAL__)
b31989e2
JS
274/*
275 * wxListCtrl has to be a real class or we have problems with
276 * the run-time information.
277 */
c801d85f 278
b31989e2
JS
279class WXDLLEXPORT wxListCtrl: public wxGenericListCtrl
280{
281 DECLARE_DYNAMIC_CLASS(wxListCtrl)
282
283public:
6463b9f5 284 wxListCtrl() {}
b31989e2 285
ca65c044 286 wxListCtrl(wxWindow *parent, wxWindowID winid = wxID_ANY,
b31989e2
JS
287 const wxPoint& pos = wxDefaultPosition,
288 const wxSize& size = wxDefaultSize,
289 long style = wxLC_ICON,
290 const wxValidator &validator = wxDefaultValidator,
52f2ad08 291 const wxString &name = wxListCtrlNameStr)
6463b9f5
JS
292 : wxGenericListCtrl(parent, winid, pos, size, style, validator, name)
293 {
294 }
b31989e2 295};
3a5bcc4d 296#endif // !__WXMSW__ || __WXUNIVERSAL__
5b98eb2f 297
b31989e2 298#endif // __LISTCTRLH_G__