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