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