]>
Commit | Line | Data |
---|---|---|
8cf73271 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: listctrl.h | |
3 | // Purpose: wxListCtrl class | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 1998-01-01 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Stefan Csomor | |
65571936 | 9 | // Licence: wxWindows licence |
8cf73271 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_LISTCTRL_H_ | |
13 | #define _WX_LISTCTRL_H_ | |
14 | ||
e2bc1d69 | 15 | #include "wx/generic/listctrl.h" |
8cf73271 | 16 | |
e2bc1d69 | 17 | class wxMacDataBrowserListCtrlControl; |
b19f2e4e | 18 | class wxMacListControl; |
8cf73271 | 19 | |
8cf73271 SC |
20 | class WXDLLEXPORT wxListCtrl: public wxControl |
21 | { | |
22 | DECLARE_DYNAMIC_CLASS(wxListCtrl) | |
23 | public: | |
24 | /* | |
25 | * Public interface | |
26 | */ | |
27 | ||
e2bc1d69 KO |
28 | wxListCtrl() { Init(); } |
29 | ||
30 | wxListCtrl(wxWindow *parent, | |
31 | wxWindowID id = wxID_ANY, | |
32 | const wxPoint& pos = wxDefaultPosition, | |
33 | const wxSize& size = wxDefaultSize, | |
34 | long style = wxLC_ICON, | |
35 | const wxValidator& validator = wxDefaultValidator, | |
36 | const wxString& name = wxListCtrlNameStr) | |
37 | { | |
38 | Init(); | |
8cf73271 | 39 | |
e2bc1d69 KO |
40 | Create(parent, id, pos, size, style, validator, name); |
41 | } | |
8cf73271 | 42 | |
e2bc1d69 | 43 | virtual ~wxListCtrl(); |
8cf73271 | 44 | |
e2bc1d69 KO |
45 | bool Create(wxWindow *parent, |
46 | wxWindowID id = wxID_ANY, | |
47 | const wxPoint& pos = wxDefaultPosition, | |
48 | const wxSize& size = wxDefaultSize, | |
49 | long style = wxLC_ICON, | |
50 | const wxValidator& validator = wxDefaultValidator, | |
51 | const wxString& name = wxListCtrlNameStr); | |
8cf73271 SC |
52 | |
53 | // Attributes | |
54 | //////////////////////////////////////////////////////////////////////////// | |
55 | ||
56 | // Gets information about this column | |
57 | bool GetColumn(int col, wxListItem& item) const; | |
58 | ||
59 | // Sets information about this column | |
e2bc1d69 | 60 | // TODO: NOT const to be compatible with wxGenericListCtrl API |
8cf73271 SC |
61 | bool SetColumn(int col, wxListItem& item) ; |
62 | ||
63 | // Gets the column width | |
64 | int GetColumnWidth(int col) const; | |
65 | ||
66 | // Sets the column width | |
67 | bool SetColumnWidth(int col, int width) ; | |
68 | ||
69 | // Gets the number of items that can fit vertically in the | |
70 | // visible area of the list control (list or report view) | |
71 | // or the total number of items in the list control (icon | |
72 | // or small icon view) | |
73 | int GetCountPerPage() const; | |
74 | ||
75 | // Gets the edit control for editing labels. | |
76 | wxTextCtrl* GetEditControl() const; | |
77 | ||
78 | // Gets information about the item | |
79 | bool GetItem(wxListItem& info) const ; | |
80 | ||
81 | // Sets information about the item | |
82 | bool SetItem(wxListItem& info) ; | |
83 | ||
84 | // Sets a string field at a particular column | |
85 | long SetItem(long index, int col, const wxString& label, int imageId = -1); | |
86 | ||
87 | // Gets the item state | |
88 | int GetItemState(long item, long stateMask) const ; | |
89 | ||
90 | // Sets the item state | |
91 | bool SetItemState(long item, long state, long stateMask) ; | |
92 | ||
e2bc1d69 KO |
93 | void AssignImageList(wxImageList *imageList, int which); |
94 | ||
8cf73271 | 95 | // Sets the item image |
e2bc1d69 | 96 | bool SetItemImage(long item, int image, int selImage = -1) ; |
06db67bc | 97 | bool SetItemColumnImage(long item, long column, int image); |
8cf73271 SC |
98 | |
99 | // Gets the item text | |
100 | wxString GetItemText(long item) const ; | |
101 | ||
102 | // Sets the item text | |
103 | void SetItemText(long item, const wxString& str) ; | |
e2bc1d69 KO |
104 | |
105 | void SetItemTextColour(long item, const wxColour& colour) ; | |
106 | wxColour GetItemTextColour(long item) const; | |
107 | ||
108 | void SetItemBackgroundColour(long item, const wxColour& colour) ; | |
109 | wxColour GetItemBackgroundColour(long item) const; | |
110 | ||
111 | void SetItemFont( long item, const wxFont &f); | |
112 | wxFont GetItemFont( long item ) const; | |
8cf73271 SC |
113 | |
114 | // Gets the item data | |
115 | long GetItemData(long item) const ; | |
116 | ||
117 | // Sets the item data | |
118 | bool SetItemData(long item, long data) ; | |
119 | ||
120 | // Gets the item rectangle | |
121 | bool GetItemRect(long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS) const ; | |
122 | ||
123 | // Gets the item position | |
124 | bool GetItemPosition(long item, wxPoint& pos) const ; | |
125 | ||
126 | // Sets the item position | |
127 | bool SetItemPosition(long item, const wxPoint& pos) ; | |
128 | ||
129 | // Gets the number of items in the list control | |
130 | int GetItemCount() const; | |
131 | ||
132 | // Gets the number of columns in the list control | |
133 | int GetColumnCount() const; | |
134 | ||
72bc14da | 135 | void SetItemSpacing( int spacing, bool isSmall = false ); |
e2bc1d69 | 136 | wxSize GetItemSpacing() const; |
8cf73271 SC |
137 | |
138 | // Gets the number of selected items in the list control | |
139 | int GetSelectedItemCount() const; | |
e2bc1d69 KO |
140 | |
141 | wxRect GetViewRect() const; | |
8cf73271 SC |
142 | |
143 | // Gets the text colour of the listview | |
144 | wxColour GetTextColour() const; | |
145 | ||
146 | // Sets the text colour of the listview | |
147 | void SetTextColour(const wxColour& col); | |
148 | ||
149 | // Gets the index of the topmost visible item when in | |
150 | // list or report view | |
151 | long GetTopItem() const ; | |
152 | ||
72bc14da RD |
153 | // are we in report mode? |
154 | bool InReportView() const { return HasFlag(wxLC_REPORT); } | |
155 | ||
e2bc1d69 KO |
156 | bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL); } |
157 | ||
8cf73271 | 158 | // Add or remove a single window style |
52f2ad08 | 159 | void SetSingleStyle(long style, bool add = true) ; |
8cf73271 SC |
160 | |
161 | // Set the whole window style | |
162 | void SetWindowStyleFlag(long style) ; | |
163 | ||
164 | // Searches for an item, starting from 'item'. | |
165 | // item can be -1 to find the first item that matches the | |
166 | // specified flags. | |
167 | // Returns the item or -1 if unsuccessful. | |
168 | long GetNextItem(long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE) const ; | |
169 | ||
77ffb593 | 170 | // Implementation: converts wxWidgets style to MSW style. |
8cf73271 SC |
171 | // Can be a single style flag or a bit list. |
172 | // oldStyle is 'normalised' so that it doesn't contain | |
173 | // conflicting styles. | |
174 | long ConvertToMSWStyle(long& oldStyle, long style) const; | |
175 | ||
176 | // Gets one of the three image lists | |
177 | wxImageList *GetImageList(int which) const ; | |
178 | ||
179 | // Sets the image list | |
180 | // N.B. There's a quirk in the Win95 list view implementation. | |
181 | // If in wxLC_LIST mode, it'll *still* display images by the labels if | |
182 | // there's a small-icon image list set for the control - even though you | |
183 | // haven't specified wxLIST_MASK_IMAGE when inserting. | |
184 | // So you have to set a NULL small-icon image list to be sure that | |
185 | // the wxLC_LIST mode works without icons. Of course, you may want icons... | |
186 | void SetImageList(wxImageList *imageList, int which) ; | |
187 | ||
188 | // Operations | |
189 | //////////////////////////////////////////////////////////////////////////// | |
190 | ||
191 | // Arranges the items | |
192 | bool Arrange(int flag = wxLIST_ALIGN_DEFAULT); | |
193 | ||
194 | // Deletes an item | |
195 | bool DeleteItem(long item); | |
196 | ||
197 | // Deletes all items | |
198 | bool DeleteAllItems() ; | |
199 | ||
200 | // Deletes a column | |
201 | bool DeleteColumn(int col); | |
202 | ||
203 | // Deletes all columns | |
204 | bool DeleteAllColumns(); | |
205 | ||
206 | // Clears items, and columns if there are any. | |
207 | void ClearAll(); | |
208 | ||
209 | // Edit the label | |
210 | wxTextCtrl* EditLabel(long item, wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl)); | |
211 | ||
212 | // End label editing, optionally cancelling the edit | |
213 | bool EndEditLabel(bool cancel); | |
214 | ||
215 | // Ensures this item is visible | |
216 | bool EnsureVisible(long item) ; | |
217 | ||
218 | // Find an item whose label matches this string, starting from the item after 'start' | |
219 | // or the beginning if 'start' is -1. | |
52f2ad08 | 220 | long FindItem(long start, const wxString& str, bool partial = false); |
8cf73271 SC |
221 | |
222 | // Find an item whose data matches this data, starting from the item after 'start' | |
223 | // or the beginning if 'start' is -1. | |
224 | long FindItem(long start, long data); | |
225 | ||
226 | // Find an item nearest this position in the specified direction, starting from | |
227 | // the item after 'start' or the beginning if 'start' is -1. | |
228 | long FindItem(long start, const wxPoint& pt, int direction); | |
229 | ||
230 | // Determines which item (if any) is at the specified point, | |
231 | // giving details in 'flags' (see wxLIST_HITTEST_... flags above) | |
e2bc1d69 KO |
232 | // Request the subitem number as well at the given coordinate. |
233 | long HitTest(const wxPoint& point, int& flags, long* ptrSubItem = NULL) const; | |
8cf73271 SC |
234 | |
235 | // Inserts an item, returning the index of the new item if successful, | |
236 | // -1 otherwise. | |
237 | // TOD: Should also have some further convenience functions | |
238 | // which don't require setting a wxListItem object | |
239 | long InsertItem(wxListItem& info); | |
240 | ||
241 | // Insert a string item | |
242 | long InsertItem(long index, const wxString& label); | |
243 | ||
244 | // Insert an image item | |
245 | long InsertItem(long index, int imageIndex); | |
246 | ||
247 | // Insert an image/string item | |
248 | long InsertItem(long index, const wxString& label, int imageIndex); | |
249 | ||
250 | // For list view mode (only), inserts a column. | |
251 | long InsertColumn(long col, wxListItem& info); | |
252 | ||
253 | long InsertColumn(long col, const wxString& heading, int format = wxLIST_FORMAT_LEFT, | |
254 | int width = -1); | |
255 | ||
256 | // Scrolls the list control. If in icon, small icon or report view mode, | |
257 | // x specifies the number of pixels to scroll. If in list view mode, x | |
258 | // specifies the number of columns to scroll. | |
259 | // If in icon, small icon or list view mode, y specifies the number of pixels | |
260 | // to scroll. If in report view mode, y specifies the number of lines to scroll. | |
261 | bool ScrollList(int dx, int dy); | |
262 | ||
263 | // Sort items. | |
264 | ||
265 | // fn is a function which takes 3 long arguments: item1, item2, data. | |
266 | // item1 is the long data associated with a first item (NOT the index). | |
267 | // item2 is the long data associated with a second item (NOT the index). | |
268 | // data is the same value as passed to SortItems. | |
269 | // The return value is a negative number if the first item should precede the second | |
270 | // item, a positive number of the second item should precede the first, | |
271 | // or zero if the two items are equivalent. | |
272 | ||
273 | // data is arbitrary data to be passed to the sort function. | |
274 | bool SortItems(wxListCtrlCompare fn, long data); | |
275 | ||
e2bc1d69 KO |
276 | wxMacListControl* GetPeer() const; |
277 | ||
278 | // these functions are only used for virtual list view controls, i.e. the | |
279 | // ones with wxLC_VIRTUAL style | |
280 | ||
281 | void SetItemCount(long count); | |
282 | void RefreshItem(long item); | |
283 | void RefreshItems(long itemFrom, long itemTo); | |
284 | ||
285 | // return the text for the given column of the given item | |
286 | virtual wxString OnGetItemText(long item, long column) const; | |
287 | ||
288 | // return the icon for the given item. In report view, OnGetItemImage will | |
289 | // only be called for the first column. See OnGetItemColumnImage for | |
290 | // details. | |
291 | virtual int OnGetItemImage(long item) const; | |
292 | ||
293 | // return the icon for the given item and column. | |
294 | virtual int OnGetItemColumnImage(long item, long column) const; | |
295 | ||
296 | // return the attribute for the item (may return NULL if none) | |
297 | virtual wxListItemAttr *OnGetItemAttr(long item) const; | |
298 | ||
8cf73271 SC |
299 | /* Why should we need this function? Leave for now. |
300 | * We might need it because item data may have changed, | |
301 | * but the display needs refreshing (in string callback mode) | |
302 | // Updates an item. If the list control has the wxLI_AUTO_ARRANGE style, | |
303 | // the items will be rearranged. | |
304 | bool Update(long item); | |
305 | */ | |
306 | ||
307 | void Command(wxCommandEvent& event) { ProcessCommand(event); }; | |
308 | ||
3fd864a1 KO |
309 | wxListCtrlCompare GetCompareFunc() { return m_compareFunc; }; |
310 | long GetCompareFuncData() { return m_compareFuncData; }; | |
311 | ||
54eb75b5 RD |
312 | |
313 | // public overrides needed for pimpl approach | |
314 | virtual bool SetFont(const wxFont& font); | |
315 | virtual bool SetForegroundColour(const wxColour& colour); | |
316 | virtual bool SetBackgroundColour(const wxColour& colour); | |
317 | ||
8cf73271 | 318 | protected: |
54eb75b5 | 319 | // protected overrides needed for pimpl approach |
e2bc1d69 | 320 | virtual void DoSetSize(int x, int y, |
54eb75b5 RD |
321 | int width, int height, |
322 | int sizeFlags = wxSIZE_AUTO); | |
e2bc1d69 KO |
323 | |
324 | // common part of all ctors | |
325 | void Init(); | |
326 | ||
327 | wxGenericListCtrl* m_genericImpl; // allow use of the generic impl. | |
328 | wxMacDataBrowserListCtrlControl* m_dbImpl; | |
8c0c4196 | 329 | void* /*EventHandlerRef*/ m_macListCtrlEventHandler; |
3fd864a1 KO |
330 | wxListCtrlCompare m_compareFunc; |
331 | long m_compareFuncData; | |
332 | ||
8cf73271 SC |
333 | wxTextCtrl* m_textCtrl; // The control used for editing a label |
334 | wxImageList * m_imageListNormal; // The image list for normal icons | |
335 | wxImageList * m_imageListSmall; // The image list for small icons | |
336 | wxImageList * m_imageListState; // The image list state icons (not implemented yet) | |
e2bc1d69 KO |
337 | |
338 | // keep track of whether or not we should delete the image list ourselves. | |
339 | bool m_ownsImageListNormal, | |
340 | m_ownsImageListSmall, | |
341 | m_ownsImageListState; | |
8cf73271 SC |
342 | |
343 | long m_baseStyle; // Basic Windows style flags, for recreation purposes | |
344 | wxStringList m_stringPool; // Pool of 3 strings to satisfy Windows callback | |
345 | // requirements | |
346 | int m_colCount; // Windows doesn't have GetColumnCount so must | |
347 | // keep track of inserted/deleted columns | |
348 | ||
e2bc1d69 | 349 | int m_count; // for virtual lists, store item count |
8cf73271 SC |
350 | }; |
351 | ||
8cf73271 SC |
352 | #endif |
353 | // _WX_LISTCTRL_H_ |