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