]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/listctrl.h
activating DrawRectangle optimization
[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 _WX_GENERIC_LISTCTRL_H_
12 #define _WX_GENERIC_LISTCTRL_H_
13
14 #include "wx/containr.h"
15 #include "wx/scrolwin.h"
16 #include "wx/textctrl.h"
17
18 #if wxUSE_DRAG_AND_DROP
19 class WXDLLIMPEXP_FWD_CORE wxDropTarget;
20 #endif
21
22 //-----------------------------------------------------------------------------
23 // internal classes
24 //-----------------------------------------------------------------------------
25
26 class WXDLLIMPEXP_FWD_CORE wxListHeaderWindow;
27 class WXDLLIMPEXP_FWD_CORE wxListMainWindow;
28
29 //-----------------------------------------------------------------------------
30 // wxListCtrl
31 //-----------------------------------------------------------------------------
32
33 class WXDLLIMPEXP_CORE wxGenericListCtrl: public wxNavigationEnabled<wxListCtrlBase>,
34 public wxScrollHelper
35 {
36 public:
37
38 wxGenericListCtrl() : wxScrollHelper(this)
39 {
40 Init();
41 }
42
43 wxGenericListCtrl( wxWindow *parent,
44 wxWindowID winid = wxID_ANY,
45 const wxPoint &pos = wxDefaultPosition,
46 const wxSize &size = wxDefaultSize,
47 long style = wxLC_ICON,
48 const wxValidator& validator = wxDefaultValidator,
49 const wxString &name = wxListCtrlNameStr)
50 : wxScrollHelper(this)
51 {
52 Create(parent, winid, pos, size, style, validator, name);
53 }
54
55 virtual ~wxGenericListCtrl();
56
57 void Init();
58
59 bool Create( wxWindow *parent,
60 wxWindowID winid = wxID_ANY,
61 const wxPoint &pos = wxDefaultPosition,
62 const wxSize &size = wxDefaultSize,
63 long style = wxLC_ICON,
64 const wxValidator& validator = wxDefaultValidator,
65 const wxString &name = wxListCtrlNameStr);
66
67 bool GetColumn( int col, wxListItem& item ) const;
68 bool SetColumn( int col, const wxListItem& item );
69 int GetColumnWidth( int col ) const;
70 bool SetColumnWidth( int col, int width);
71 int GetCountPerPage() const; // not the same in wxGLC as in Windows, I think
72 wxRect GetViewRect() const;
73
74 bool GetItem( wxListItem& info ) const;
75 bool SetItem( wxListItem& info ) ;
76 long SetItem( long index, int col, const wxString& label, int imageId = -1 );
77 int GetItemState( long item, long stateMask ) const;
78 bool SetItemState( long item, long state, long stateMask);
79 bool SetItemImage( long item, int image, int selImage = -1 );
80 bool SetItemColumnImage( long item, long column, int image );
81 wxString GetItemText( long item, int col = 0 ) const;
82 void SetItemText( long item, const wxString& str );
83 wxUIntPtr GetItemData( long item ) const;
84 bool SetItemPtrData(long item, wxUIntPtr data);
85 bool SetItemData(long item, long data) { return SetItemPtrData(item, data); }
86 bool GetItemRect( long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS ) const;
87 bool GetSubItemRect( long item, long subItem, wxRect& rect, int code = wxLIST_RECT_BOUNDS ) const;
88 bool GetItemPosition( long item, wxPoint& pos ) const;
89 bool SetItemPosition( long item, const wxPoint& pos ); // not supported in wxGLC
90 int GetItemCount() const;
91 int GetColumnCount() const;
92 void SetItemSpacing( int spacing, bool isSmall = false );
93 wxSize GetItemSpacing() const;
94 void SetItemTextColour( long item, const wxColour& col);
95 wxColour GetItemTextColour( long item ) const;
96 void SetItemBackgroundColour( long item, const wxColour &col);
97 wxColour GetItemBackgroundColour( long item ) const;
98 void SetItemFont( long item, const wxFont &f);
99 wxFont GetItemFont( long item ) const;
100 int GetSelectedItemCount() const;
101 wxColour GetTextColour() const;
102 void SetTextColour(const wxColour& col);
103 long GetTopItem() const;
104
105 void SetSingleStyle( long style, bool add = true ) ;
106 void SetWindowStyleFlag( long style );
107 void RecreateWindow() {}
108 long GetNextItem( long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE ) const;
109 wxImageList *GetImageList( int which ) const;
110 void SetImageList( wxImageList *imageList, int which );
111 void AssignImageList( wxImageList *imageList, int which );
112 bool Arrange( int flag = wxLIST_ALIGN_DEFAULT ); // always wxLIST_ALIGN_LEFT in wxGLC
113
114 void ClearAll();
115 bool DeleteItem( long item );
116 bool DeleteAllItems();
117 bool DeleteAllColumns();
118 bool DeleteColumn( int col );
119
120 void SetItemCount(long count);
121
122 wxTextCtrl *EditLabel(long item,
123 wxClassInfo* textControlClass = wxCLASSINFO(wxTextCtrl));
124 wxTextCtrl* GetEditControl() const;
125 void Edit( long item ) { EditLabel(item); }
126
127 bool EnsureVisible( long item );
128 long FindItem( long start, const wxString& str, bool partial = false );
129 long FindItem( long start, wxUIntPtr data );
130 long FindItem( long start, const wxPoint& pt, int direction ); // not supported in wxGLC
131 long HitTest( const wxPoint& point, int& flags, long *pSubItem = NULL ) const;
132 long InsertItem(wxListItem& info);
133 long InsertItem( long index, const wxString& label );
134 long InsertItem( long index, int imageIndex );
135 long InsertItem( long index, const wxString& label, int imageIndex );
136 bool ScrollList( int dx, int dy );
137 bool SortItems( wxListCtrlCompare fn, wxIntPtr data );
138
139 // do we have a header window?
140 bool HasHeader() const
141 { return InReportView() && !HasFlag(wxLC_NO_HEADER); }
142
143 // refresh items selectively (only useful for virtual list controls)
144 void RefreshItem(long item);
145 void RefreshItems(long itemFrom, long itemTo);
146
147 virtual void EnableBellOnNoMatch(bool on = true);
148
149 #if WXWIN_COMPATIBILITY_2_6
150 // obsolete, don't use
151 wxDEPRECATED( int GetItemSpacing( bool isSmall ) const );
152 #endif // WXWIN_COMPATIBILITY_2_6
153
154
155 // overridden base class virtuals
156 // ------------------------------
157
158 virtual wxVisualAttributes GetDefaultAttributes() const
159 {
160 return GetClassDefaultAttributes(GetWindowVariant());
161 }
162
163 static wxVisualAttributes
164 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
165
166 virtual void Update();
167
168
169 // implementation only from now on
170 // -------------------------------
171
172 // generic version extension, don't use in portable code
173 bool Update( long item );
174
175 void OnInternalIdle( );
176
177 // We have to hand down a few functions
178 virtual void Refresh(bool eraseBackground = true,
179 const wxRect *rect = NULL);
180
181 virtual bool SetBackgroundColour( const wxColour &colour );
182 virtual bool SetForegroundColour( const wxColour &colour );
183 virtual wxColour GetBackgroundColour() const;
184 virtual wxColour GetForegroundColour() const;
185 virtual bool SetFont( const wxFont &font );
186 virtual bool SetCursor( const wxCursor &cursor );
187
188 #if wxUSE_DRAG_AND_DROP
189 virtual void SetDropTarget( wxDropTarget *dropTarget );
190 virtual wxDropTarget *GetDropTarget() const;
191 #endif
192
193 virtual bool ShouldInheritColours() const { return false; }
194
195 // implementation
196 // --------------
197
198 wxImageList *m_imageListNormal;
199 wxImageList *m_imageListSmall;
200 wxImageList *m_imageListState; // what's that ?
201 bool m_ownsImageListNormal,
202 m_ownsImageListSmall,
203 m_ownsImageListState;
204 wxListHeaderWindow *m_headerWin;
205 wxListMainWindow *m_mainWin;
206
207 protected:
208 // Implement base class pure virtual methods.
209 long DoInsertColumn(long col, const wxListItem& info);
210
211
212 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
213
214 // take into account the coordinates difference between the container
215 // window and the list control window itself here
216 virtual void DoClientToScreen( int *x, int *y ) const;
217 virtual void DoScreenToClient( int *x, int *y ) const;
218
219 virtual wxSize DoGetBestClientSize() const;
220
221 // return the text for the given column of the given item
222 virtual wxString OnGetItemText(long item, long column) const;
223
224 // return the icon for the given item. In report view, OnGetItemImage will
225 // only be called for the first column. See OnGetItemColumnImage for
226 // details.
227 virtual int OnGetItemImage(long item) const;
228
229 // return the icon for the given item and column.
230 virtual int OnGetItemColumnImage(long item, long column) const;
231
232 // return the attribute for the item (may return NULL if none)
233 virtual wxListItemAttr *OnGetItemAttr(long item) const;
234
235 // it calls our OnGetXXX() functions
236 friend class WXDLLIMPEXP_FWD_CORE wxListMainWindow;
237
238 virtual wxBorder GetDefaultBorder() const;
239
240 virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size);
241
242 private:
243 void CreateOrDestroyHeaderWindowAsNeeded();
244 void OnScroll( wxScrollWinEvent& event );
245 void OnSize( wxSizeEvent &event );
246
247 // we need to return a special WM_GETDLGCODE value to process just the
248 // arrows but let the other navigation characters through
249 #if defined(__WXMSW__) && !defined(__WXWINCE__) && !defined(__WXUNIVERSAL__)
250 virtual WXLRESULT
251 MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
252 #endif // __WXMSW__
253
254 WX_FORWARD_TO_SCROLL_HELPER()
255
256 DECLARE_EVENT_TABLE()
257 DECLARE_DYNAMIC_CLASS(wxGenericListCtrl)
258 };
259
260 #if (!defined(__WXMSW__) || defined(__WXUNIVERSAL__)) && (!(defined(__WXMAC__) && wxOSX_USE_CARBON) || defined(__WXUNIVERSAL__ ))
261 /*
262 * wxListCtrl has to be a real class or we have problems with
263 * the run-time information.
264 */
265
266 class WXDLLIMPEXP_CORE wxListCtrl: public wxGenericListCtrl
267 {
268 DECLARE_DYNAMIC_CLASS(wxListCtrl)
269
270 public:
271 wxListCtrl() {}
272
273 wxListCtrl(wxWindow *parent, wxWindowID winid = wxID_ANY,
274 const wxPoint& pos = wxDefaultPosition,
275 const wxSize& size = wxDefaultSize,
276 long style = wxLC_ICON,
277 const wxValidator &validator = wxDefaultValidator,
278 const wxString &name = wxListCtrlNameStr)
279 : wxGenericListCtrl(parent, winid, pos, size, style, validator, name)
280 {
281 }
282
283 };
284 #endif // !__WXMSW__ || __WXUNIVERSAL__
285
286 #endif // _WX_GENERIC_LISTCTRL_H_