1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/listctrl.h
3 // Purpose: Generic list control
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling and Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef __LISTCTRLH_G__
12 #define __LISTCTRLH_G__
15 #include "wx/object.h"
17 #include "wx/imaglist.h"
19 #include "wx/generic/imaglist.h"
22 #include "wx/control.h"
24 #include "wx/dcclient.h"
25 #include "wx/scrolwin.h"
26 #include "wx/settings.h"
27 #include "wx/listbase.h"
29 #if wxUSE_DRAG_AND_DROP
30 class WXDLLEXPORT wxDropTarget
;
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
37 class WXDLLEXPORT wxListItem
;
38 class WXDLLEXPORT wxListEvent
;
40 #if !defined(__WXMSW__) || defined(__WXUNIVERSAL__)
41 class WXDLLEXPORT wxListCtrl
;
42 #define wxImageListType wxImageList
44 #define wxImageListType wxGenericImageList
47 //-----------------------------------------------------------------------------
49 //-----------------------------------------------------------------------------
51 class WXDLLEXPORT wxListHeaderData
;
52 class WXDLLEXPORT wxListItemData
;
53 class WXDLLEXPORT wxListLineData
;
55 class WXDLLEXPORT wxListHeaderWindow
;
56 class WXDLLEXPORT wxListMainWindow
;
58 class WXDLLEXPORT wxListRenameTimer
;
59 class WXDLLEXPORT wxListTextCtrl
;
61 //-----------------------------------------------------------------------------
63 //-----------------------------------------------------------------------------
65 class WXDLLEXPORT wxGenericListCtrl
: public wxControl
69 wxGenericListCtrl( wxWindow
*parent
,
70 wxWindowID winid
= wxID_ANY
,
71 const wxPoint
&pos
= wxDefaultPosition
,
72 const wxSize
&size
= wxDefaultSize
,
73 long style
= wxLC_ICON
,
74 const wxValidator
& validator
= wxDefaultValidator
,
75 const wxString
&name
= wxListCtrlNameStr
)
77 Create(parent
, winid
, pos
, size
, style
, validator
, name
);
81 bool Create( wxWindow
*parent
,
82 wxWindowID winid
= wxID_ANY
,
83 const wxPoint
&pos
= wxDefaultPosition
,
84 const wxSize
&size
= wxDefaultSize
,
85 long style
= wxLC_ICON
,
86 const wxValidator
& validator
= wxDefaultValidator
,
87 const wxString
&name
= wxListCtrlNameStr
);
89 bool GetColumn( int col
, wxListItem
& item
) const;
90 bool SetColumn( int col
, wxListItem
& item
);
91 int GetColumnWidth( int col
) const;
92 bool SetColumnWidth( int col
, int width
);
93 int GetCountPerPage() const; // not the same in wxGLC as in Windows, I think
94 wxRect
GetViewRect() const;
96 bool GetItem( wxListItem
& info
) const;
97 bool SetItem( wxListItem
& info
) ;
98 long SetItem( long index
, int col
, const wxString
& label
, int imageId
= -1 );
99 int GetItemState( long item
, long stateMask
) const;
100 bool SetItemState( long item
, long state
, long stateMask
);
101 bool SetItemImage( long item
, int image
, int selImage
= -1 );
102 wxString
GetItemText( long item
) const;
103 void SetItemText( long item
, const wxString
& str
);
104 wxUIntPtr
GetItemData( long item
) const;
105 bool SetItemData( long item
, long data
);
106 bool GetItemRect( long item
, wxRect
& rect
, int code
= wxLIST_RECT_BOUNDS
) const;
107 bool GetItemPosition( long item
, wxPoint
& pos
) const;
108 bool SetItemPosition( long item
, const wxPoint
& pos
); // not supported in wxGLC
109 int GetItemCount() const;
110 int GetColumnCount() const;
111 void SetItemSpacing( int spacing
, bool isSmall
= false );
112 wxSize
GetItemSpacing() const;
113 void SetItemTextColour( long item
, const wxColour
& col
);
114 wxColour
GetItemTextColour( long item
) const;
115 void SetItemBackgroundColour( long item
, const wxColour
&col
);
116 wxColour
GetItemBackgroundColour( long item
) const;
117 void SetItemFont( long item
, const wxFont
&f
);
118 wxFont
GetItemFont( long item
) const;
119 int GetSelectedItemCount() const;
120 wxColour
GetTextColour() const;
121 void SetTextColour(const wxColour
& col
);
122 long GetTopItem() const;
124 void SetSingleStyle( long style
, bool add
= true ) ;
125 void SetWindowStyleFlag( long style
);
126 void RecreateWindow() {}
127 long GetNextItem( long item
, int geometry
= wxLIST_NEXT_ALL
, int state
= wxLIST_STATE_DONTCARE
) const;
128 wxImageListType
*GetImageList( int which
) const;
129 void SetImageList( wxImageListType
*imageList
, int which
);
130 void AssignImageList( wxImageListType
*imageList
, int which
);
131 bool Arrange( int flag
= wxLIST_ALIGN_DEFAULT
); // always wxLIST_ALIGN_LEFT in wxGLC
134 bool DeleteItem( long item
);
135 bool DeleteAllItems();
136 bool DeleteAllColumns();
137 bool DeleteColumn( int col
);
139 void SetItemCount(long count
);
141 wxTextCtrl
*EditLabel(long item
,
142 wxClassInfo
* textControlClass
= CLASSINFO(wxTextCtrl
));
143 wxTextCtrl
* GetEditControl() const;
144 void Edit( long item
) { EditLabel(item
); }
146 bool EnsureVisible( long item
);
147 long FindItem( long start
, const wxString
& str
, bool partial
= false );
148 long FindItem( long start
, wxUIntPtr data
);
149 long FindItem( long start
, const wxPoint
& pt
, int direction
); // not supported in wxGLC
150 long HitTest( const wxPoint
& point
, int& flags
);
151 long InsertItem(wxListItem
& info
);
152 long InsertItem( long index
, const wxString
& label
);
153 long InsertItem( long index
, int imageIndex
);
154 long InsertItem( long index
, const wxString
& label
, int imageIndex
);
155 long InsertColumn( long col
, wxListItem
& info
);
156 long InsertColumn( long col
, const wxString
& heading
,
157 int format
= wxLIST_FORMAT_LEFT
, int width
= -1 );
158 bool ScrollList( int dx
, int dy
);
159 bool SortItems( wxListCtrlCompare fn
, long data
);
160 bool Update( long item
);
161 // Must provide overload to avoid hiding it (and warnings about it)
162 virtual void Update() { wxControl::Update(); }
164 // are we in report mode?
165 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
167 // are we in virtual report mode?
168 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
170 // do we have a header window?
171 bool HasHeader() const
172 { return InReportView() && !HasFlag(wxLC_NO_HEADER
); }
174 // refresh items selectively (only useful for virtual list controls)
175 void RefreshItem(long item
);
176 void RefreshItems(long itemFrom
, long itemTo
);
178 // obsolete, don't use
179 wxDEPRECATED( int GetItemSpacing( bool isSmall
) const );
182 virtual wxVisualAttributes
GetDefaultAttributes() const
184 return GetClassDefaultAttributes(GetWindowVariant());
187 static wxVisualAttributes
188 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
190 // implementation only from now on
191 // -------------------------------
193 void OnInternalIdle( );
194 void OnSize( wxSizeEvent
&event
);
196 // We have to hand down a few functions
197 virtual void Refresh(bool eraseBackground
= true,
198 const wxRect
*rect
= NULL
);
200 virtual void Freeze();
203 virtual bool SetBackgroundColour( const wxColour
&colour
);
204 virtual bool SetForegroundColour( const wxColour
&colour
);
205 virtual wxColour
GetBackgroundColour() const;
206 virtual wxColour
GetForegroundColour() const;
207 virtual bool SetFont( const wxFont
&font
);
208 virtual bool SetCursor( const wxCursor
&cursor
);
210 #if wxUSE_DRAG_AND_DROP
211 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
212 virtual wxDropTarget
*GetDropTarget() const;
215 virtual bool ShouldInheritColours() const { return false; }
216 virtual void SetFocus();
221 wxImageListType
*m_imageListNormal
;
222 wxImageListType
*m_imageListSmall
;
223 wxImageListType
*m_imageListState
; // what's that ?
224 bool m_ownsImageListNormal
,
225 m_ownsImageListSmall
,
226 m_ownsImageListState
;
227 wxListHeaderWindow
*m_headerWin
;
228 wxListMainWindow
*m_mainWin
;
229 wxCoord m_headerHeight
;
232 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
234 // take into account the coordinates difference between the container
235 // window and the list control window itself here
236 virtual void DoClientToScreen( int *x
, int *y
) const;
237 virtual void DoScreenToClient( int *x
, int *y
) const;
239 virtual wxSize
DoGetBestSize() const;
241 // return the text for the given column of the given item
242 virtual wxString
OnGetItemText(long item
, long column
) const;
244 // return the icon for the given item. In report view, OnGetItemImage will
245 // only be called for the first column. See OnGetItemColumnImage for
247 virtual int OnGetItemImage(long item
) const;
249 // return the icon for the given item and column.
250 virtual int OnGetItemColumnImage(long item
, long column
) const;
252 // return the attribute for the item (may return NULL if none)
253 virtual wxListItemAttr
*OnGetItemAttr(long item
) const;
255 // it calls our OnGetXXX() functions
256 friend class WXDLLEXPORT wxListMainWindow
;
259 // create the header window
260 void CreateHeaderWindow();
262 // calculate and set height of the header
263 void CalculateAndSetHeaderHeight();
265 // reposition the header and the main window in the report view depending
266 // on whether it should be shown or not
267 void ResizeReportView(bool showHeader
);
269 DECLARE_EVENT_TABLE()
270 DECLARE_DYNAMIC_CLASS(wxGenericListCtrl
)
273 #if !defined(__WXMSW__) || defined(__WXUNIVERSAL__)
275 * wxListCtrl has to be a real class or we have problems with
276 * the run-time information.
279 class WXDLLEXPORT wxListCtrl
: public wxGenericListCtrl
281 DECLARE_DYNAMIC_CLASS(wxListCtrl
)
286 wxListCtrl(wxWindow
*parent
, wxWindowID winid
= wxID_ANY
,
287 const wxPoint
& pos
= wxDefaultPosition
,
288 const wxSize
& size
= wxDefaultSize
,
289 long style
= wxLC_ICON
,
290 const wxValidator
&validator
= wxDefaultValidator
,
291 const wxString
&name
= wxListCtrlNameStr
)
292 : wxGenericListCtrl(parent
, winid
, pos
, size
, style
, validator
, name
)
296 #endif // !__WXMSW__ || __WXUNIVERSAL__
298 #endif // __LISTCTRLH_G__