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