]> git.saurik.com Git - wxWidgets.git/blame - include/wx/mac/carbon/listctrl.h
Fix for non-PCH builds.
[wxWidgets.git] / include / wx / mac / carbon / listctrl.h
CommitLineData
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 17class wxMacDataBrowserListCtrlControl;
b19f2e4e 18class wxMacListControl;
7ac21a67
KO
19class wxListCtrlTextCtrlWrapper;
20class wxListCtrlRenameTimer;
8cf73271 21
e9a0cc4b
KO
22WX_DECLARE_EXPORTED_LIST(wxListItem, wxColumnList);
23
8cf73271
SC
24class WXDLLEXPORT wxListCtrl: public wxControl
25{
26 DECLARE_DYNAMIC_CLASS(wxListCtrl)
27 public:
28 /*
29 * Public interface
30 */
31
e2bc1d69
KO
32 wxListCtrl() { Init(); }
33
34 wxListCtrl(wxWindow *parent,
35 wxWindowID id = wxID_ANY,
36 const wxPoint& pos = wxDefaultPosition,
37 const wxSize& size = wxDefaultSize,
38 long style = wxLC_ICON,
39 const wxValidator& validator = wxDefaultValidator,
40 const wxString& name = wxListCtrlNameStr)
41 {
42 Init();
8cf73271 43
e2bc1d69
KO
44 Create(parent, id, pos, size, style, validator, name);
45 }
8cf73271 46
e2bc1d69 47 virtual ~wxListCtrl();
8cf73271 48
e2bc1d69
KO
49 bool Create(wxWindow *parent,
50 wxWindowID id = wxID_ANY,
51 const wxPoint& pos = wxDefaultPosition,
52 const wxSize& size = wxDefaultSize,
53 long style = wxLC_ICON,
54 const wxValidator& validator = wxDefaultValidator,
55 const wxString& name = wxListCtrlNameStr);
8cf73271
SC
56
57 // Attributes
58 ////////////////////////////////////////////////////////////////////////////
59
60 // Gets information about this column
61 bool GetColumn(int col, wxListItem& item) const;
62
63 // Sets information about this column
e2bc1d69 64 // TODO: NOT const to be compatible with wxGenericListCtrl API
8cf73271
SC
65 bool SetColumn(int col, 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
e2bc1d69
KO
97 void AssignImageList(wxImageList *imageList, int which);
98
8cf73271 99 // Sets the item image
e2bc1d69 100 bool SetItemImage(long item, int image, int selImage = -1) ;
06db67bc 101 bool SetItemColumnImage(long item, long column, int image);
8cf73271
SC
102
103 // Gets the item text
104 wxString GetItemText(long item) const ;
105
106 // Sets the item text
107 void SetItemText(long item, const wxString& str) ;
e2bc1d69
KO
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;
8cf73271
SC
117
118 // Gets the item data
119 long GetItemData(long item) const ;
120
121 // Sets the item data
122 bool SetItemData(long item, long data) ;
123
124 // Gets the item rectangle
125 bool GetItemRect(long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS) const ;
126
127 // Gets the item position
128 bool GetItemPosition(long item, wxPoint& pos) const ;
129
130 // Sets the item position
131 bool SetItemPosition(long item, const wxPoint& pos) ;
132
133 // Gets the number of items in the list control
134 int GetItemCount() const;
135
136 // Gets the number of columns in the list control
137 int GetColumnCount() const;
138
72bc14da 139 void SetItemSpacing( int spacing, bool isSmall = false );
e2bc1d69 140 wxSize GetItemSpacing() const;
8cf73271
SC
141
142 // Gets the number of selected items in the list control
143 int GetSelectedItemCount() const;
e2bc1d69
KO
144
145 wxRect GetViewRect() const;
8cf73271
SC
146
147 // Gets the text colour of the listview
148 wxColour GetTextColour() const;
149
150 // Sets the text colour of the listview
151 void SetTextColour(const wxColour& col);
152
153 // Gets the index of the topmost visible item when in
154 // list or report view
155 long GetTopItem() const ;
156
72bc14da
RD
157 // are we in report mode?
158 bool InReportView() const { return HasFlag(wxLC_REPORT); }
159
e2bc1d69
KO
160 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL); }
161
8cf73271 162 // Add or remove a single window style
52f2ad08 163 void SetSingleStyle(long style, bool add = true) ;
8cf73271
SC
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
77ffb593 174 // Implementation: converts wxWidgets style to MSW style.
8cf73271
SC
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
214 wxTextCtrl* EditLabel(long item, wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl));
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.
52f2ad08 224 long FindItem(long start, const wxString& str, bool partial = false);
8cf73271
SC
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)
e2bc1d69
KO
236 // Request the subitem number as well at the given coordinate.
237 long HitTest(const wxPoint& point, int& flags, long* ptrSubItem = NULL) const;
8cf73271
SC
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
254 // For list view mode (only), inserts a column.
255 long InsertColumn(long col, wxListItem& info);
256
257 long InsertColumn(long col, const wxString& heading, int format = wxLIST_FORMAT_LEFT,
258 int width = -1);
259
260 // Scrolls the list control. If in icon, small icon or report view mode,
261 // x specifies the number of pixels to scroll. If in list view mode, x
262 // specifies the number of columns to scroll.
263 // If in icon, small icon or list view mode, y specifies the number of pixels
264 // to scroll. If in report view mode, y specifies the number of lines to scroll.
265 bool ScrollList(int dx, int dy);
266
267 // Sort items.
268
269 // fn is a function which takes 3 long arguments: item1, item2, data.
270 // item1 is the long data associated with a first item (NOT the index).
271 // item2 is the long data associated with a second item (NOT the index).
272 // data is the same value as passed to SortItems.
273 // The return value is a negative number if the first item should precede the second
274 // item, a positive number of the second item should precede the first,
275 // or zero if the two items are equivalent.
276
277 // data is arbitrary data to be passed to the sort function.
278 bool SortItems(wxListCtrlCompare fn, long data);
279
e2bc1d69
KO
280 wxMacListControl* GetPeer() const;
281
282 // these functions are only used for virtual list view controls, i.e. the
283 // ones with wxLC_VIRTUAL style
284
285 void SetItemCount(long count);
286 void RefreshItem(long item);
287 void RefreshItems(long itemFrom, long itemTo);
288
289 // return the text for the given column of the given item
290 virtual wxString OnGetItemText(long item, long column) const;
291
292 // return the icon for the given item. In report view, OnGetItemImage will
293 // only be called for the first column. See OnGetItemColumnImage for
294 // details.
295 virtual int OnGetItemImage(long item) const;
296
297 // return the icon for the given item and column.
298 virtual int OnGetItemColumnImage(long item, long column) const;
299
300 // return the attribute for the item (may return NULL if none)
301 virtual wxListItemAttr *OnGetItemAttr(long item) const;
302
8cf73271
SC
303/* Why should we need this function? Leave for now.
304 * We might need it because item data may have changed,
305 * but the display needs refreshing (in string callback mode)
306 // Updates an item. If the list control has the wxLI_AUTO_ARRANGE style,
307 // the items will be rearranged.
308 bool Update(long item);
309*/
310
311 void Command(wxCommandEvent& event) { ProcessCommand(event); };
312
3fd864a1
KO
313 wxListCtrlCompare GetCompareFunc() { return m_compareFunc; };
314 long GetCompareFuncData() { return m_compareFuncData; };
315
54eb75b5
RD
316
317 // public overrides needed for pimpl approach
318 virtual bool SetFont(const wxFont& font);
319 virtual bool SetForegroundColour(const wxColour& colour);
320 virtual bool SetBackgroundColour(const wxColour& colour);
e9a0cc4b
KO
321 virtual wxColour GetBackgroundColour();
322
7ac21a67
KO
323 // functions for editing/timer
324 void OnRenameTimer();
325 bool OnRenameAccept(long itemEdit, const wxString& value);
326 void OnRenameCancelled(long itemEdit);
327
328 void ChangeCurrent(long current);
329 void ResetCurrent() { ChangeCurrent((long)-1); }
330 bool HasCurrent() const { return m_current != (long)-1; }
331
332 void OnLeftDown(wxMouseEvent& event);
333 void OnDblClick(wxMouseEvent& event);
334
335 void FinishEditing(wxTextCtrl *text)
336 {
337 delete text;
338 m_textctrlWrapper = NULL;
339 SetFocus();
340 }
341
02095058
KO
342 virtual int GetScrollPos(int orient) const;
343
bc63f2c9
KO
344 virtual void SetFocus();
345
02095058
KO
346 virtual void SetDropTarget( wxDropTarget *dropTarget );
347 virtual wxDropTarget* GetDropTarget() const;
348
e9a0cc4b
KO
349 // with CG, we need to get the context from an kEventControlDraw event
350 // unfortunately, the DataBrowser callbacks don't provide the context
351 // and we need it, so we need to set/remove it before and after draw
352 // events so we can access it in the callbacks.
353 void MacSetDrawingContext(void* context) { m_cgContext = context; }
354 void* MacGetDrawingContext() { return m_cgContext; }
54eb75b5 355
8cf73271 356protected:
02095058 357
54eb75b5 358 // protected overrides needed for pimpl approach
e2bc1d69 359 virtual void DoSetSize(int x, int y,
54eb75b5
RD
360 int width, int height,
361 int sizeFlags = wxSIZE_AUTO);
e2bc1d69 362
a6c82d64
KO
363 virtual wxSize DoGetBestSize() const;
364
7ac21a67
KO
365 long m_current;
366 wxListCtrlTextCtrlWrapper *m_textctrlWrapper;
367 wxListCtrlRenameTimer *m_renameTimer;
e2bc1d69
KO
368 // common part of all ctors
369 void Init();
370
371 wxGenericListCtrl* m_genericImpl; // allow use of the generic impl.
372 wxMacDataBrowserListCtrlControl* m_dbImpl;
e9a0cc4b
KO
373 void* m_macListCtrlEventHandler;
374 void* m_cgContext;
3fd864a1
KO
375 wxListCtrlCompare m_compareFunc;
376 long m_compareFuncData;
377
8cf73271
SC
378 wxTextCtrl* m_textCtrl; // The control used for editing a label
379 wxImageList * m_imageListNormal; // The image list for normal icons
380 wxImageList * m_imageListSmall; // The image list for small icons
381 wxImageList * m_imageListState; // The image list state icons (not implemented yet)
e2bc1d69 382
e9a0cc4b
KO
383 wxColumnList m_colsInfo; // for storing info about each column
384 wxColour m_textColor;
385 wxColour m_bgColor;
386
e2bc1d69
KO
387 // keep track of whether or not we should delete the image list ourselves.
388 bool m_ownsImageListNormal,
389 m_ownsImageListSmall,
390 m_ownsImageListState;
8cf73271
SC
391
392 long m_baseStyle; // Basic Windows style flags, for recreation purposes
393 wxStringList m_stringPool; // Pool of 3 strings to satisfy Windows callback
394 // requirements
395 int m_colCount; // Windows doesn't have GetColumnCount so must
396 // keep track of inserted/deleted columns
397
e2bc1d69 398 int m_count; // for virtual lists, store item count
7ac21a67
KO
399
400private:
401 DECLARE_EVENT_TABLE()
8cf73271
SC
402};
403
8cf73271
SC
404#endif
405 // _WX_LISTCTRL_H_