1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/osx/listctrl.h
3 // Purpose: wxListCtrl class
4 // Author: Stefan Csomor
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_LISTCTRL_H_
12 #define _WX_LISTCTRL_H_
15 #include "wx/generic/listctrl.h"
17 #define wxMAC_ALWAYS_USE_GENERIC_LISTCTRL wxT("mac.listctrl.always_use_generic")
19 class wxMacDataBrowserListCtrlControl
;
20 class wxListCtrlTextCtrlWrapper
;
21 class wxListCtrlRenameTimer
;
23 WX_DECLARE_EXPORTED_LIST(wxListItem
, wxColumnList
);
25 class WXDLLIMPEXP_CORE wxListCtrl
: public wxListCtrlBase
27 DECLARE_DYNAMIC_CLASS(wxListCtrl
)
33 wxListCtrl() { Init(); }
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
)
45 Create(parent
, id
, pos
, size
, style
, validator
, name
);
48 virtual ~wxListCtrl();
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
);
59 ////////////////////////////////////////////////////////////////////////////
61 // Gets information about this column
62 bool GetColumn(int col
, wxListItem
& item
) const;
64 // Sets information about this column
65 bool SetColumn(int col
, const wxListItem
& item
) ;
67 // Gets the column width
68 int GetColumnWidth(int col
) const;
70 // Sets the column width
71 bool SetColumnWidth(int col
, int width
) ;
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;
79 // Gets the edit control for editing labels.
80 wxTextCtrl
* GetEditControl() const;
82 // Gets information about the item
83 bool GetItem(wxListItem
& info
) const ;
85 // Sets information about the item
86 bool SetItem(wxListItem
& info
) ;
88 // Sets a string field at a particular column
89 long SetItem(long index
, int col
, const wxString
& label
, int imageId
= -1);
91 // Gets the item state
92 int GetItemState(long item
, long stateMask
) const ;
94 // Sets the item state
95 bool SetItemState(long item
, long state
, long stateMask
) ;
97 void AssignImageList(wxImageList
*imageList
, int which
);
99 // Sets the item image
100 bool SetItemImage(long item
, int image
, int selImage
= -1) ;
101 bool SetItemColumnImage(long item
, long column
, int image
);
103 // Gets the item text
104 wxString
GetItemText(long item
, int col
= 0) const ;
106 // Sets the item text
107 void SetItemText(long item
, const wxString
& str
) ;
109 void SetItemTextColour(long item
, const wxColour
& colour
) ;
110 wxColour
GetItemTextColour(long item
) const;
112 void SetItemBackgroundColour(long item
, const wxColour
& colour
) ;
113 wxColour
GetItemBackgroundColour(long item
) const;
115 void SetItemFont( long item
, const wxFont
&f
);
116 wxFont
GetItemFont( long item
) const;
118 // Gets the item data
119 long GetItemData(long item
) const ;
121 // Sets the item data
122 bool SetItemPtrData(long item
, wxUIntPtr data
);
123 bool SetItemData(long item
, long data
) { return SetItemPtrData(item
, data
); }
125 // Gets the item rectangle
126 bool GetItemRect(long item
, wxRect
& rect
, int code
= wxLIST_RECT_BOUNDS
) const ;
128 // Gets the item rectangle of a subitem
129 bool GetSubItemRect( long item
, long subItem
, wxRect
& rect
, int code
= wxLIST_RECT_BOUNDS
) const;
131 // Gets the item position
132 bool GetItemPosition(long item
, wxPoint
& pos
) const ;
134 // Sets the item position
135 bool SetItemPosition(long item
, const wxPoint
& pos
) ;
137 // Gets the number of items in the list control
138 int GetItemCount() const;
140 // Gets the number of columns in the list control
141 int GetColumnCount() const;
143 void SetItemSpacing( int spacing
, bool isSmall
= false );
144 wxSize
GetItemSpacing() const;
146 // Gets the number of selected items in the list control
147 int GetSelectedItemCount() const;
149 wxRect
GetViewRect() const;
151 // Gets the text colour of the listview
152 wxColour
GetTextColour() const;
154 // Sets the text colour of the listview
155 void SetTextColour(const wxColour
& col
);
157 // Gets the index of the topmost visible item when in
158 // list or report view
159 long GetTopItem() const ;
161 // Add or remove a single window style
162 void SetSingleStyle(long style
, bool add
= true) ;
164 // Set the whole window style
165 void SetWindowStyleFlag(long style
) ;
167 // Searches for an item, starting from 'item'.
168 // item can be -1 to find the first item that matches the
170 // Returns the item or -1 if unsuccessful.
171 long GetNextItem(long item
, int geometry
= wxLIST_NEXT_ALL
, int state
= wxLIST_STATE_DONTCARE
) const ;
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;
179 // Gets one of the three image lists
180 wxImageList
*GetImageList(int which
) const ;
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
) ;
192 ////////////////////////////////////////////////////////////////////////////
194 // Arranges the items
195 bool Arrange(int flag
= wxLIST_ALIGN_DEFAULT
);
198 bool DeleteItem(long item
);
201 bool DeleteAllItems() ;
204 bool DeleteColumn(int col
);
206 // Deletes all columns
207 bool DeleteAllColumns();
209 // Clears items, and columns if there are any.
213 wxTextCtrl
* EditLabel(long item
, wxClassInfo
* textControlClass
= wxCLASSINFO(wxTextCtrl
));
215 // End label editing, optionally cancelling the edit
216 bool EndEditLabel(bool cancel
);
218 // Ensures this item is visible
219 bool EnsureVisible(long item
) ;
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);
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
);
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
);
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;
238 // Inserts an item, returning the index of the new item if successful,
240 // TOD: Should also have some further convenience functions
241 // which don't require setting a wxListItem object
242 long InsertItem(wxListItem
& info
);
244 // Insert a string item
245 long InsertItem(long index
, const wxString
& label
);
247 // Insert an image item
248 long InsertItem(long index
, int imageIndex
);
250 // Insert an image/string item
251 long InsertItem(long index
, const wxString
& label
, int imageIndex
);
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
);
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.
270 // data is arbitrary data to be passed to the sort function.
271 bool SortItems(wxListCtrlCompare fn
, wxIntPtr data
);
273 wxMacDataBrowserListCtrlControl
* GetListPeer() const;
275 // these functions are only used for virtual list view controls, i.e. the
276 // ones with wxLC_VIRTUAL style
278 void SetItemCount(long count
);
279 void RefreshItem(long item
);
280 void RefreshItems(long itemFrom
, long itemTo
);
282 // return the text for the given column of the given item
283 virtual wxString
OnGetItemText(long item
, long column
) const;
285 // return the icon for the given item. In report view, OnGetItemImage will
286 // only be called for the first column. See OnGetItemColumnImage for
288 virtual int OnGetItemImage(long item
) const;
290 // return the icon for the given item and column.
291 virtual int OnGetItemColumnImage(long item
, long column
) const;
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);
301 void Command(wxCommandEvent
& event
) { ProcessCommand(event
); }
303 wxListCtrlCompare
GetCompareFunc() { return m_compareFunc
; }
304 wxIntPtr
GetCompareFuncData() { return m_compareFuncData
; }
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;
313 virtual void Freeze ();
314 virtual void Thaw ();
315 virtual void Update ();
317 // functions for editing/timer
318 void OnRenameTimer();
319 bool OnRenameAccept(long itemEdit
, const wxString
& value
);
320 void OnRenameCancelled(long itemEdit
);
322 void ChangeCurrent(long current
);
323 void ResetCurrent() { ChangeCurrent((long)-1); }
324 bool HasCurrent() const { return m_current
!= (long)-1; }
326 void OnLeftDown(wxMouseEvent
& event
);
327 void OnDblClick(wxMouseEvent
& event
);
329 void FinishEditing(wxTextCtrl
*text
)
332 m_textctrlWrapper
= NULL
;
336 virtual int GetScrollPos(int orient
) const;
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
);
344 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
345 virtual wxDropTarget
* GetDropTarget() const;
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
; }
354 virtual wxVisualAttributes
GetDefaultAttributes() const
356 return GetClassDefaultAttributes(GetWindowVariant());
359 static wxVisualAttributes
360 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
363 // Implement base class pure virtual methods.
364 long DoInsertColumn(long col
, const wxListItem
& info
);
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
);
372 wxListCtrlTextCtrlWrapper
*m_textctrlWrapper
;
373 wxListCtrlRenameTimer
*m_renameTimer
;
374 // common part of all ctors
377 wxGenericListCtrl
* m_genericImpl
; // allow use of the generic impl.
378 wxMacDataBrowserListCtrlControl
* m_dbImpl
;
379 void* m_macListCtrlEventHandler
;
381 wxListCtrlCompare m_compareFunc
;
382 wxIntPtr m_compareFuncData
;
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)
389 wxColumnList m_colsInfo
; // for storing info about each column
390 wxColour m_textColor
;
393 // keep track of whether or not we should delete the image list ourselves.
394 bool m_ownsImageListNormal
,
395 m_ownsImageListSmall
,
396 m_ownsImageListState
;
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
402 int m_count
; // for virtual lists, store item count
405 int CalcColumnAutoWidth(int col
) const;