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