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