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