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