1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/os2/listctrl.h
3 // Purpose: wxListCtrl class
7 // Copyright: (c) wxWidgets team
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_LISTCTRL_H_
12 #define _WX_LISTCTRL_H_
16 #include "wx/control.h"
19 #include "wx/textctrl.h"
22 class WXDLLIMPEXP_FWD_CORE wxImageList
;
24 typedef int (wxCALLBACK
*wxListCtrlCompare
)(long lItem1
, long lItem2
, long lSortData
);
26 class WXDLLIMPEXP_CORE wxListCtrl
: public wxControl
29 wxListCtrl() { Init(); }
30 wxListCtrl( wxWindow
* pParent
32 ,const wxPoint
& rPos
= wxDefaultPosition
33 ,const wxSize
& rSize
= wxDefaultSize
34 ,long lStyle
= wxLC_ICON
35 ,const wxValidator
& rValidator
= wxDefaultValidator
36 ,const wxString
& rsName
= wxListCtrlNameStr
)
48 virtual ~wxListCtrl();
50 bool Create( wxWindow
* pParent
52 ,const wxPoint
& rPos
= wxDefaultPosition
53 ,const wxSize
& rSize
= wxDefaultSize
54 ,long lStyle
= wxLC_ICON
55 ,const wxValidator
& rValidator
= wxDefaultValidator
56 ,const wxString
& rsName
= wxListCtrlNameStr
61 ////////////////////////////////////////////////////////////////////////////
65 // Set the control colours
67 bool SetForegroundColour(const wxColour
& rCol
);
68 bool SetBackgroundColour(const wxColour
& rCol
);
71 // Information about this column
73 bool GetColumn( int nCol
76 bool SetColumn( int nCol
83 int GetColumnWidth(int nCol
) const;
84 bool SetColumnWidth( int nCol
89 // Gets the number of items that can fit vertically in the
90 // visible area of the list control (list or report view)
91 // or the total number of items in the list control (icon
92 // or small icon view)
94 int GetCountPerPage(void) const;
96 wxRect
GetViewRect() const;
98 // Gets the edit control for editing labels.
100 wxTextCtrl
* GetEditControl(void) const;
103 // Information about the item
105 bool GetItem(wxListItem
& rInfo
) const;
106 bool SetItem(wxListItem
& rInfo
);
109 // Sets a string field at a particular column
111 long SetItem( long lIndex
113 ,const wxString
& rsLabel
120 int GetItemState( long lItem
123 bool SetItemState( long lItem
129 // Sets the item image
131 bool SetItemImage( long lItem
135 bool SetItemColumnImage( long lItem
143 wxString
GetItemText(long lItem
) const;
144 void SetItemText( long lItem
145 ,const wxString
& rsStr
151 long GetItemData(long lItem
) const;
152 bool SetItemPtrData(long item
, wxUIntPtr data
);
153 bool SetItemData(long item
, long data
) { return SetItemPtrData(item
, data
); }
156 // Gets the item rectangle
158 bool GetItemRect( long lItem
160 ,int nCode
= wxLIST_RECT_BOUNDS
166 bool GetItemPosition( long lItem
169 bool SetItemPosition( long lItem
174 // Gets the number of items in the list control
176 int GetItemCount(void) const;
179 // Gets the number of columns in the list control
181 inline int GetColumnCount(void) const { return m_nColCount
; }
184 // Retrieves the spacing between icons in pixels.
185 // If bIsSmall is true, gets the spacing for the small icon
186 // view, otherwise the large icon view.
188 int GetItemSpacing(bool bIsSmall
) const;
191 // Foreground colour of an item.
193 wxColour
GetItemTextColour(long lItem
) const;
194 void SetItemTextColour( long lItem
195 ,const wxColour
& rCol
199 // Background colour of an item.
201 wxColour
GetItemBackgroundColour(long lItem
) const;
202 void SetItemBackgroundColour( long lItem
203 ,const wxColour
& rCol
207 // Gets the number of selected items in the list control
209 int GetSelectedItemCount(void) const;
212 // Text colour of the listview
214 wxColour
GetTextColour(void) const;
215 void SetTextColour(const wxColour
& rCol
);
218 // Gets the index of the topmost visible item when in
219 // list or report view
221 long GetTopItem(void) const;
224 // Add or remove a single window style
225 void SetSingleStyle( long lStyle
230 // Set the whole window style
232 void SetWindowStyleFlag(long lStyle
);
235 // Searches for an item, starting from 'item'.
236 // item can be -1 to find the first item that matches the
238 // Returns the item or -1 if unsuccessful.
239 long GetNextItem( long lItem
240 ,int nGeometry
= wxLIST_NEXT_ALL
241 ,int lState
= wxLIST_STATE_DONTCARE
245 // Gets one of the three image lists
247 wxImageList
* GetImageList(int nWhich
) const;
250 // Sets the image list
252 void SetImageList( wxImageList
* pImageList
255 void AssignImageList( wxImageList
* pImageList
260 // Returns true if it is a virtual list control
262 inline bool IsVirtual() const { return (GetWindowStyle() & wxLC_VIRTUAL
) != 0; }
265 // Refresh items selectively (only useful for virtual list controls)
267 void RefreshItem(long lItem
);
268 void RefreshItems( long lItemFrom
274 ////////////////////////////////////////////////////////////////////////////
278 // Arranges the items
280 bool Arrange(int nFlag
= wxLIST_ALIGN_DEFAULT
);
285 bool DeleteItem(long lItem
);
289 bool DeleteAllItems(void);
294 bool DeleteColumn(int nCol
);
297 // Deletes all columns
299 bool DeleteAllColumns(void);
302 // Clears items, and columns if there are any.
309 wxTextCtrl
* EditLabel( long lItem
310 ,wxClassInfo
* pTextControlClass
= wxCLASSINFO(wxTextCtrl
)
314 // End label editing, optionally cancelling the edit
316 bool EndEditLabel(bool bCancel
);
319 // Ensures this item is visible
321 bool EnsureVisible(long lItem
);
324 // Find an item whose label matches this string, starting from the item after 'start'
325 // or the beginning if 'start' is -1.
327 long FindItem( long lStart
328 ,const wxString
& rsStr
329 ,bool bPartial
= false
333 // Find an item whose data matches this data, starting from the item after 'start'
334 // or the beginning if 'start' is -1.
336 long FindItem( long lStart
341 // Find an item nearest this position in the specified direction, starting from
342 // the item after 'start' or the beginning if 'start' is -1.
344 long FindItem( long lStart
345 ,const wxPoint
& rPoint
350 // Determines which item (if any) is at the specified point,
351 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
353 long HitTest( const wxPoint
& rPoint
358 // Inserts an item, returning the index of the new item if successful,
361 long InsertItem(wxListItem
& rInfo
);
364 // Insert a string item
366 long InsertItem( long lIndex
367 ,const wxString
& rsLabel
371 // Insert an image item
373 long InsertItem( long lIndex
378 // Insert an image/string item
380 long InsertItem( long lIndex
381 ,const wxString
& rsLabel
386 // For list view mode (only), inserts a column.
388 long InsertColumn( long lCol
392 long InsertColumn( long lCol
393 ,const wxString
& rsHeading
394 ,int nFormat
= wxLIST_FORMAT_LEFT
399 // set the number of items in a virtual list control
401 void SetItemCount(long lCount
);
404 // Scrolls the list control. If in icon, small icon or report view mode,
405 // x specifies the number of pixels to scroll. If in list view mode, x
406 // specifies the number of columns to scroll.
407 // If in icon, small icon or list view mode, y specifies the number of pixels
408 // to scroll. If in report view mode, y specifies the number of lines to scroll.
410 bool ScrollList( int nDx
417 // fn is a function which takes 3 long arguments: item1, item2, data.
418 // item1 is the long data associated with a first item (NOT the index).
419 // item2 is the long data associated with a second item (NOT the index).
420 // data is the same value as passed to SortItems.
421 // The return value is a negative number if the first item should precede the second
422 // item, a positive number of the second item should precede the first,
423 // or zero if the two items are equivalent.
425 // data is arbitrary data to be passed to the sort function.
427 bool SortItems( wxListCtrlCompare fn
435 virtual bool OS2Command( WXUINT uParam
439 // Bring the control in sync with current m_windowStyle value
441 void UpdateStyle(void);
444 // Implementation: converts wxWidgets style to MSW style.
445 // Can be a single style flag or a bit list.
446 // oldStyle is 'normalised' so that it doesn't contain
447 // conflicting styles.
449 long ConvertToOS2Style( long& lOldStyle
452 long ConvertArrangeToOS2Style(long lStyle
);
453 long ConvertViewToOS2Style(long lStyle
);
455 virtual MRESULT
OS2WindowProc( WXUINT uMsg
461 ////////////////////////////////////////////////////////////////////////////
462 // Necessary for drawing hrules and vrules, if specified
463 void OnPaint(wxPaintEvent
& rEvent
);
467 // common part of all ctors
472 // Free memory taken by all internal data
474 void FreeAllInternalData(void);
476 wxTextCtrl
* m_pTextCtrl
; // The control used for editing a label
477 wxImageList
* m_pImageListNormal
; // The image list for normal icons
478 wxImageList
* m_pImageListSmall
; // The image list for small icons
479 wxImageList
* m_pImageListState
; // The image list state icons (not implemented yet)
480 bool m_bOwnsImageListNormal
;
481 bool m_bOwnsImageListSmall
;
482 bool m_bOwnsImageListState
;
483 long m_lBaseStyle
; // Basic PM style flags, for recreation purposes
484 int m_nColCount
; // PM doesn't have GetColumnCount so must
485 // keep track of inserted/deleted columns
488 // true if we have any internal data (user data & attributes)
490 bool m_bAnyInternalData
;
493 // true if we have any items with custom attributes
498 // These functions are only used for virtual list view controls, i.e. the
499 // ones with wxLC_VIRTUAL style
501 // return the text for the given column of the given item
503 virtual wxString
OnGetItemText( long lItem
508 // Return the icon for the given item. In report view, OnGetItemImage will
509 // only be called for the first column. See OnGetItemColumnImage for
512 virtual int OnGetItemImage(long lItem
) const;
515 // Return the icon for the given item and column
517 virtual int OnGetItemColumnImage(long lItem
, long lColumn
) const;
520 // Return the attribute for the item (may return NULL if none)
522 virtual wxListItemAttr
* OnGetItemAttr(long lItem
) const;
525 bool DoCreateControl( int nX
531 DECLARE_DYNAMIC_CLASS(wxListCtrl
)
532 DECLARE_EVENT_TABLE()
533 wxDECLARE_NO_COPY_CLASS(wxListCtrl
);
534 }; // end of CLASS wxListCtrl
536 #endif // wxUSE_LISTCTRL
538 #endif // _WX_LISTCTRL_H_