]> git.saurik.com Git - wxWidgets.git/blob - include/wx/os2/listctrl.h
fix SetUserData() to delete the correct pointer
[wxWidgets.git] / include / wx / os2 / listctrl.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/os2/listctrl.h
3 // Purpose: wxListCtrl class
4 // Author:
5 // Modified by:
6 // Created:
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_LISTCTRL_H_
13 #define _WX_LISTCTRL_H_
14
15 #if wxUSE_LISTCTRL
16
17 #include "wx/control.h"
18 #include "wx/event.h"
19 #include "wx/hash.h"
20 #include "wx/textctrl.h"
21
22
23 class WXDLLEXPORT wxImageList;
24
25 typedef int (wxCALLBACK *wxListCtrlCompare)(long lItem1, long lItem2, long lSortData);
26
27 class WXDLLEXPORT wxListCtrl: public wxControl
28 {
29 public:
30 wxListCtrl() { Init(); }
31 wxListCtrl( wxWindow* pParent
32 ,wxWindowID vId = -1
33 ,const wxPoint& rPos = wxDefaultPosition
34 ,const wxSize& rSize = wxDefaultSize
35 ,long lStyle = wxLC_ICON
36 ,const wxValidator& rValidator = wxDefaultValidator
37 ,const wxString& rsName = wxListCtrlNameStr)
38 {
39 Init();
40 Create( pParent
41 ,vId
42 ,rPos
43 ,rSize
44 ,lStyle
45 ,rValidator
46 ,rsName
47 );
48 }
49 virtual ~wxListCtrl();
50
51 bool Create( wxWindow* pParent
52 ,wxWindowID vId = -1
53 ,const wxPoint& rPos = wxDefaultPosition
54 ,const wxSize& rSize = wxDefaultSize
55 ,long lStyle = wxLC_ICON
56 ,const wxValidator& rValidator = wxDefaultValidator
57 ,const wxString& rsName = wxListCtrlNameStr
58 );
59
60
61 // Attributes
62 ////////////////////////////////////////////////////////////////////////////
63 //
64
65 //
66 // Set the control colours
67 //
68 bool SetForegroundColour(const wxColour& rCol);
69 bool SetBackgroundColour(const wxColour& rCol);
70
71 //
72 // Information about this column
73 //
74 bool GetColumn( int nCol
75 ,wxListItem& rItem
76 ) const;
77 bool SetColumn( int nCol
78 ,wxListItem& rItem
79 );
80
81 //
82 // Column width
83 //
84 int GetColumnWidth(int nCol) const;
85 bool SetColumnWidth( int nCol
86 ,int nWidth
87 );
88
89 //
90 // Gets the number of items that can fit vertically in the
91 // visible area of the list control (list or report view)
92 // or the total number of items in the list control (icon
93 // or small icon view)
94 //
95 int GetCountPerPage(void) const;
96
97 wxRect GetViewRect() const;
98 //
99 // Gets the edit control for editing labels.
100 //
101 wxTextCtrl* GetEditControl(void) const;
102
103 //
104 // Information about the item
105 //
106 bool GetItem(wxListItem& rInfo) const;
107 bool SetItem(wxListItem& rInfo);
108
109 //
110 // Sets a string field at a particular column
111 //
112 long SetItem( long lIndex
113 ,int nCol
114 ,const wxString& rsLabel
115 ,int nImageId = -1
116 );
117
118 //
119 // Item state
120 //
121 int GetItemState( long lItem
122 ,long lStateMask
123 ) const;
124 bool SetItemState( long lItem
125 ,long lState
126 ,long lStateMask
127 );
128
129 //
130 // Sets the item image
131 //
132 bool SetItemImage( long lItem
133 ,int nImage
134 ,int lSelImage
135 );
136
137 //
138 // Item text
139 //
140 wxString GetItemText(long lItem) const;
141 void SetItemText( long lItem
142 ,const wxString& rsStr
143 );
144
145 //
146 // Item data
147 //
148 long GetItemData(long lItem) const;
149 bool SetItemData( long lItem
150 ,long lData
151 );
152
153 //
154 // Gets the item rectangle
155 //
156 bool GetItemRect( long lItem
157 ,wxRect& rRect
158 ,int nCode = wxLIST_RECT_BOUNDS
159 ) const;
160
161 //
162 // Item position
163 //
164 bool GetItemPosition( long lItem
165 ,wxPoint& rPos
166 ) const;
167 bool SetItemPosition( long lItem
168 ,const wxPoint& rPos
169 );
170
171 //
172 // Gets the number of items in the list control
173 //
174 int GetItemCount(void) const;
175
176 //
177 // Gets the number of columns in the list control
178 //
179 inline int GetColumnCount(void) const { return m_nColCount; }
180
181 //
182 // Retrieves the spacing between icons in pixels.
183 // If bIsSmall is true, gets the spacing for the small icon
184 // view, otherwise the large icon view.
185 //
186 int GetItemSpacing(bool bIsSmall) const;
187
188 //
189 // Foreground colour of an item.
190 //
191 wxColour GetItemTextColour(long lItem) const;
192 void SetItemTextColour( long lItem
193 ,const wxColour& rCol
194 );
195
196 //
197 // Background colour of an item.
198 //
199 wxColour GetItemBackgroundColour(long lItem ) const;
200 void SetItemBackgroundColour( long lItem
201 ,const wxColour& rCol
202 );
203
204 //
205 // Gets the number of selected items in the list control
206 //
207 int GetSelectedItemCount(void) const;
208
209 //
210 // Text colour of the listview
211 //
212 wxColour GetTextColour(void) const;
213 void SetTextColour(const wxColour& rCol);
214
215 //
216 // Gets the index of the topmost visible item when in
217 // list or report view
218 //
219 long GetTopItem(void) const;
220
221 //
222 // Add or remove a single window style
223 void SetSingleStyle( long lStyle
224 ,bool bAdd = true
225 );
226
227 //
228 // Set the whole window style
229 //
230 void SetWindowStyleFlag(long lStyle);
231
232 //
233 // Searches for an item, starting from 'item'.
234 // item can be -1 to find the first item that matches the
235 // specified flags.
236 // Returns the item or -1 if unsuccessful.
237 long GetNextItem( long lItem
238 ,int nGeometry = wxLIST_NEXT_ALL
239 ,int lState = wxLIST_STATE_DONTCARE
240 ) const;
241
242 //
243 // Gets one of the three image lists
244 //
245 wxImageList* GetImageList(int nWhich) const;
246
247 //
248 // Sets the image list
249 //
250 void SetImageList( wxImageList* pImageList
251 ,int nWhich
252 );
253 void AssignImageList( wxImageList* pImageList
254 ,int nWhich
255 );
256
257 //
258 // Returns true if it is a virtual list control
259 //
260 inline bool IsVirtual() const { return (GetWindowStyle() & wxLC_VIRTUAL) != 0; }
261
262 //
263 // Refresh items selectively (only useful for virtual list controls)
264 //
265 void RefreshItem(long lItem);
266 void RefreshItems( long lItemFrom
267 ,long lItemTo
268 );
269
270 //
271 // Operations
272 ////////////////////////////////////////////////////////////////////////////
273 //
274
275 //
276 // Arranges the items
277 //
278 bool Arrange(int nFlag = wxLIST_ALIGN_DEFAULT);
279
280 //
281 // Deletes an item
282 //
283 bool DeleteItem(long lItem);
284
285 //
286 // Deletes all items
287 bool DeleteAllItems(void);
288
289 //
290 // Deletes a column
291 //
292 bool DeleteColumn(int nCol);
293
294 //
295 // Deletes all columns
296 //
297 bool DeleteAllColumns(void);
298
299 //
300 // Clears items, and columns if there are any.
301 //
302 void ClearAll(void);
303
304 //
305 // Edit the label
306 //
307 wxTextCtrl* EditLabel( long lItem
308 ,wxClassInfo* pTextControlClass = CLASSINFO(wxTextCtrl)
309 );
310
311 //
312 // End label editing, optionally cancelling the edit
313 //
314 bool EndEditLabel(bool bCancel);
315
316 //
317 // Ensures this item is visible
318 //
319 bool EnsureVisible(long lItem);
320
321 //
322 // Find an item whose label matches this string, starting from the item after 'start'
323 // or the beginning if 'start' is -1.
324 //
325 long FindItem( long lStart
326 ,const wxString& rsStr
327 ,bool bPartial = false
328 );
329
330 //
331 // Find an item whose data matches this data, starting from the item after 'start'
332 // or the beginning if 'start' is -1.
333 //
334 long FindItem( long lStart
335 ,long lData
336 );
337
338 //
339 // Find an item nearest this position in the specified direction, starting from
340 // the item after 'start' or the beginning if 'start' is -1.
341 //
342 long FindItem( long lStart
343 ,const wxPoint& rPoint
344 ,int lDirection
345 );
346
347 //
348 // Determines which item (if any) is at the specified point,
349 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
350 //
351 long HitTest( const wxPoint& rPoint
352 ,int& rFlags
353 );
354
355 //
356 // Inserts an item, returning the index of the new item if successful,
357 // -1 otherwise.
358 //
359 long InsertItem(wxListItem& rInfo);
360
361 //
362 // Insert a string item
363 //
364 long InsertItem( long lIndex
365 ,const wxString& rsLabel
366 );
367
368 //
369 // Insert an image item
370 //
371 long InsertItem( long lIndex
372 ,int nImageIndex
373 );
374
375 //
376 // Insert an image/string item
377 //
378 long InsertItem( long lIndex
379 ,const wxString& rsLabel
380 ,int nImageIndex
381 );
382
383 //
384 // For list view mode (only), inserts a column.
385 //
386 long InsertColumn( long lCol
387 ,wxListItem& rInfo
388 );
389
390 long InsertColumn( long lCol
391 ,const wxString& rsHeading
392 ,int nFormat = wxLIST_FORMAT_LEFT
393 ,int lWidth = -1
394 );
395
396 //
397 // set the number of items in a virtual list control
398 //
399 void SetItemCount(long lCount);
400
401 //
402 // Scrolls the list control. If in icon, small icon or report view mode,
403 // x specifies the number of pixels to scroll. If in list view mode, x
404 // specifies the number of columns to scroll.
405 // If in icon, small icon or list view mode, y specifies the number of pixels
406 // to scroll. If in report view mode, y specifies the number of lines to scroll.
407 //
408 bool ScrollList( int nDx
409 ,int nDy
410 );
411
412 // Sort items.
413
414 //
415 // fn is a function which takes 3 long arguments: item1, item2, data.
416 // item1 is the long data associated with a first item (NOT the index).
417 // item2 is the long data associated with a second item (NOT the index).
418 // data is the same value as passed to SortItems.
419 // The return value is a negative number if the first item should precede the second
420 // item, a positive number of the second item should precede the first,
421 // or zero if the two items are equivalent.
422 //
423 // data is arbitrary data to be passed to the sort function.
424 //
425 bool SortItems( wxListCtrlCompare fn
426 ,long lData
427 );
428
429 //
430 // IMPLEMENTATION
431 // --------------
432 //
433 virtual bool OS2Command( WXUINT uParam
434 ,WXWORD wId
435 );
436 //
437 // Bring the control in sync with current m_windowStyle value
438 //
439 void UpdateStyle(void);
440
441 //
442 // Implementation: converts wxWidgets style to MSW style.
443 // Can be a single style flag or a bit list.
444 // oldStyle is 'normalised' so that it doesn't contain
445 // conflicting styles.
446 //
447 long ConvertToOS2Style( long& lOldStyle
448 ,long lStyle
449 ) const;
450 long ConvertArrangeToOS2Style(long lStyle);
451 long ConvertViewToOS2Style(long lStyle);
452
453 virtual MRESULT OS2WindowProc( WXUINT uMsg
454 ,WXWPARAM wParam
455 ,WXLPARAM lParam
456 );
457
458 // Event handlers
459 ////////////////////////////////////////////////////////////////////////////
460 // Necessary for drawing hrules and vrules, if specified
461 void OnPaint(wxPaintEvent& rEvent);
462
463 protected:
464 //
465 // common part of all ctors
466 //
467 void Init(void);
468
469 //
470 // Free memory taken by all internal data
471 //
472 void FreeAllInternalData(void);
473
474 wxTextCtrl* m_pTextCtrl; // The control used for editing a label
475 wxImageList* m_pImageListNormal; // The image list for normal icons
476 wxImageList* m_pImageListSmall; // The image list for small icons
477 wxImageList* m_pImageListState; // The image list state icons (not implemented yet)
478 bool m_bOwnsImageListNormal;
479 bool m_bOwnsImageListSmall;
480 bool m_bOwnsImageListState;
481 long m_lBaseStyle; // Basic PM style flags, for recreation purposes
482 int m_nColCount; // PM doesn't have GetColumnCount so must
483 // keep track of inserted/deleted columns
484
485 //
486 // true if we have any internal data (user data & attributes)
487 //
488 bool m_bAnyInternalData;
489
490 //
491 // true if we have any items with custom attributes
492 //
493 bool m_bHasAnyAttr;
494
495 //
496 // These functions are only used for virtual list view controls, i.e. the
497 // ones with wxLC_VIRTUAL style
498 //
499 // return the text for the given column of the given item
500 //
501 virtual wxString OnGetItemText( long lItem
502 ,long lColumn
503 ) const;
504
505 //
506 // Return the icon for the given item
507 //
508 virtual int OnGetItemImage(long lItem) const;
509
510 //
511 // Return the attribute for the item (may return NULL if none)
512 //
513 virtual wxListItemAttr* OnGetItemAttr(long lItem) const;
514
515 private:
516 bool DoCreateControl( int nX
517 ,int nY
518 ,int nWidth
519 ,int nHeight
520 );
521
522 DECLARE_DYNAMIC_CLASS(wxListCtrl)
523 DECLARE_EVENT_TABLE()
524 DECLARE_NO_COPY_CLASS(wxListCtrl)
525 }; // end of CLASS wxListCtrl
526
527 #endif // wxUSE_LISTCTRL
528
529 #endif // _WX_LISTCTRL_H_
530