1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/os2/listctrl.h
3 // Purpose: wxListCtrl class
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_LISTCTRL_H_
13 #define _WX_LISTCTRL_H_
17 #include "wx/control.h"
20 #include "wx/textctrl.h"
23 class WXDLLIMPEXP_FWD_CORE wxImageList
;
25 typedef int (wxCALLBACK
*wxListCtrlCompare
)(long lItem1
, long lItem2
, long lSortData
);
27 class WXDLLIMPEXP_CORE wxListCtrl
: public wxControl
30 wxListCtrl() { Init(); }
31 wxListCtrl( wxWindow
* pParent
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
)
49 virtual ~wxListCtrl();
51 bool Create( wxWindow
* pParent
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
62 ////////////////////////////////////////////////////////////////////////////
66 // Set the control colours
68 bool SetForegroundColour(const wxColour
& rCol
);
69 bool SetBackgroundColour(const wxColour
& rCol
);
72 // Information about this column
74 bool GetColumn( int nCol
77 bool SetColumn( int nCol
84 int GetColumnWidth(int nCol
) const;
85 bool SetColumnWidth( int nCol
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)
95 int GetCountPerPage(void) const;
97 wxRect
GetViewRect() const;
99 // Gets the edit control for editing labels.
101 wxTextCtrl
* GetEditControl(void) const;
104 // Information about the item
106 bool GetItem(wxListItem
& rInfo
) const;
107 bool SetItem(wxListItem
& rInfo
);
110 // Sets a string field at a particular column
112 long SetItem( long lIndex
114 ,const wxString
& rsLabel
121 int GetItemState( long lItem
124 bool SetItemState( long lItem
130 // Sets the item image
132 bool SetItemImage( long lItem
136 bool SetItemColumnImage( long lItem
144 wxString
GetItemText(long lItem
) const;
145 void SetItemText( long lItem
146 ,const wxString
& rsStr
152 long GetItemData(long lItem
) const;
153 bool SetItemPtrData(long item
, wxUIntPtr data
);
154 bool SetItemData(long item
, long data
) { return SetItemPtrData(item
, data
); }
157 // Gets the item rectangle
159 bool GetItemRect( long lItem
161 ,int nCode
= wxLIST_RECT_BOUNDS
167 bool GetItemPosition( long lItem
170 bool SetItemPosition( long lItem
175 // Gets the number of items in the list control
177 int GetItemCount(void) const;
180 // Gets the number of columns in the list control
182 inline int GetColumnCount(void) const { return m_nColCount
; }
185 // Retrieves the spacing between icons in pixels.
186 // If bIsSmall is true, gets the spacing for the small icon
187 // view, otherwise the large icon view.
189 int GetItemSpacing(bool bIsSmall
) const;
192 // Foreground colour of an item.
194 wxColour
GetItemTextColour(long lItem
) const;
195 void SetItemTextColour( long lItem
196 ,const wxColour
& rCol
200 // Background colour of an item.
202 wxColour
GetItemBackgroundColour(long lItem
) const;
203 void SetItemBackgroundColour( long lItem
204 ,const wxColour
& rCol
208 // Gets the number of selected items in the list control
210 int GetSelectedItemCount(void) const;
213 // Text colour of the listview
215 wxColour
GetTextColour(void) const;
216 void SetTextColour(const wxColour
& rCol
);
219 // Gets the index of the topmost visible item when in
220 // list or report view
222 long GetTopItem(void) const;
225 // Add or remove a single window style
226 void SetSingleStyle( long lStyle
231 // Set the whole window style
233 void SetWindowStyleFlag(long lStyle
);
236 // Searches for an item, starting from 'item'.
237 // item can be -1 to find the first item that matches the
239 // Returns the item or -1 if unsuccessful.
240 long GetNextItem( long lItem
241 ,int nGeometry
= wxLIST_NEXT_ALL
242 ,int lState
= wxLIST_STATE_DONTCARE
246 // Gets one of the three image lists
248 wxImageList
* GetImageList(int nWhich
) const;
251 // Sets the image list
253 void SetImageList( wxImageList
* pImageList
256 void AssignImageList( wxImageList
* pImageList
261 // Returns true if it is a virtual list control
263 inline bool IsVirtual() const { return (GetWindowStyle() & wxLC_VIRTUAL
) != 0; }
266 // Refresh items selectively (only useful for virtual list controls)
268 void RefreshItem(long lItem
);
269 void RefreshItems( long lItemFrom
275 ////////////////////////////////////////////////////////////////////////////
279 // Arranges the items
281 bool Arrange(int nFlag
= wxLIST_ALIGN_DEFAULT
);
286 bool DeleteItem(long lItem
);
290 bool DeleteAllItems(void);
295 bool DeleteColumn(int nCol
);
298 // Deletes all columns
300 bool DeleteAllColumns(void);
303 // Clears items, and columns if there are any.
310 wxTextCtrl
* EditLabel( long lItem
311 ,wxClassInfo
* pTextControlClass
= CLASSINFO(wxTextCtrl
)
315 // End label editing, optionally cancelling the edit
317 bool EndEditLabel(bool bCancel
);
320 // Ensures this item is visible
322 bool EnsureVisible(long lItem
);
325 // Find an item whose label matches this string, starting from the item after 'start'
326 // or the beginning if 'start' is -1.
328 long FindItem( long lStart
329 ,const wxString
& rsStr
330 ,bool bPartial
= false
334 // Find an item whose data matches this data, starting from the item after 'start'
335 // or the beginning if 'start' is -1.
337 long FindItem( long lStart
342 // Find an item nearest this position in the specified direction, starting from
343 // the item after 'start' or the beginning if 'start' is -1.
345 long FindItem( long lStart
346 ,const wxPoint
& rPoint
351 // Determines which item (if any) is at the specified point,
352 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
354 long HitTest( const wxPoint
& rPoint
359 // Inserts an item, returning the index of the new item if successful,
362 long InsertItem(wxListItem
& rInfo
);
365 // Insert a string item
367 long InsertItem( long lIndex
368 ,const wxString
& rsLabel
372 // Insert an image item
374 long InsertItem( long lIndex
379 // Insert an image/string item
381 long InsertItem( long lIndex
382 ,const wxString
& rsLabel
387 // For list view mode (only), inserts a column.
389 long InsertColumn( long lCol
393 long InsertColumn( long lCol
394 ,const wxString
& rsHeading
395 ,int nFormat
= wxLIST_FORMAT_LEFT
400 // set the number of items in a virtual list control
402 void SetItemCount(long lCount
);
405 // Scrolls the list control. If in icon, small icon or report view mode,
406 // x specifies the number of pixels to scroll. If in list view mode, x
407 // specifies the number of columns to scroll.
408 // If in icon, small icon or list view mode, y specifies the number of pixels
409 // to scroll. If in report view mode, y specifies the number of lines to scroll.
411 bool ScrollList( int nDx
418 // fn is a function which takes 3 long arguments: item1, item2, data.
419 // item1 is the long data associated with a first item (NOT the index).
420 // item2 is the long data associated with a second item (NOT the index).
421 // data is the same value as passed to SortItems.
422 // The return value is a negative number if the first item should precede the second
423 // item, a positive number of the second item should precede the first,
424 // or zero if the two items are equivalent.
426 // data is arbitrary data to be passed to the sort function.
428 bool SortItems( wxListCtrlCompare fn
436 virtual bool OS2Command( WXUINT uParam
440 // Bring the control in sync with current m_windowStyle value
442 void UpdateStyle(void);
445 // Implementation: converts wxWidgets style to MSW style.
446 // Can be a single style flag or a bit list.
447 // oldStyle is 'normalised' so that it doesn't contain
448 // conflicting styles.
450 long ConvertToOS2Style( long& lOldStyle
453 long ConvertArrangeToOS2Style(long lStyle
);
454 long ConvertViewToOS2Style(long lStyle
);
456 virtual MRESULT
OS2WindowProc( WXUINT uMsg
462 ////////////////////////////////////////////////////////////////////////////
463 // Necessary for drawing hrules and vrules, if specified
464 void OnPaint(wxPaintEvent
& rEvent
);
468 // common part of all ctors
473 // Free memory taken by all internal data
475 void FreeAllInternalData(void);
477 wxTextCtrl
* m_pTextCtrl
; // The control used for editing a label
478 wxImageList
* m_pImageListNormal
; // The image list for normal icons
479 wxImageList
* m_pImageListSmall
; // The image list for small icons
480 wxImageList
* m_pImageListState
; // The image list state icons (not implemented yet)
481 bool m_bOwnsImageListNormal
;
482 bool m_bOwnsImageListSmall
;
483 bool m_bOwnsImageListState
;
484 long m_lBaseStyle
; // Basic PM style flags, for recreation purposes
485 int m_nColCount
; // PM doesn't have GetColumnCount so must
486 // keep track of inserted/deleted columns
489 // true if we have any internal data (user data & attributes)
491 bool m_bAnyInternalData
;
494 // true if we have any items with custom attributes
499 // These functions are only used for virtual list view controls, i.e. the
500 // ones with wxLC_VIRTUAL style
502 // return the text for the given column of the given item
504 virtual wxString
OnGetItemText( long lItem
509 // Return the icon for the given item. In report view, OnGetItemImage will
510 // only be called for the first column. See OnGetItemColumnImage for
513 virtual int OnGetItemImage(long lItem
) const;
516 // Return the icon for the given item and column
518 virtual int OnGetItemColumnImage(long lItem
, long lColumn
) const;
521 // Return the attribute for the item (may return NULL if none)
523 virtual wxListItemAttr
* OnGetItemAttr(long lItem
) const;
526 bool DoCreateControl( int nX
532 DECLARE_DYNAMIC_CLASS(wxListCtrl
)
533 DECLARE_EVENT_TABLE()
534 wxDECLARE_NO_COPY_CLASS(wxListCtrl
);
535 }; // end of CLASS wxListCtrl
537 #endif // wxUSE_LISTCTRL
539 #endif // _WX_LISTCTRL_H_