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