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