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