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