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"
16 #include "wx/imaglist.h"
18 #include "wx/control.h"
20 #include "wx/dcclient.h"
21 #include "wx/scrolwin.h"
22 #include "wx/settings.h"
23 #include "wx/listctrl.h"
24 #include "wx/textctrl.h"
26 #if wxUSE_DRAG_AND_DROP
27 class WXDLLEXPORT wxDropTarget
;
30 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
34 extern WXDLLEXPORT_DATA(const wxChar
) wxGenericListCtrlNameStr
[];
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
40 class WXDLLEXPORT wxListHeaderData
;
41 class WXDLLEXPORT wxListItemData
;
43 class WXDLLEXPORT wxListHeaderWindow
;
44 class WXDLLEXPORT wxListMainWindow
;
46 class WXDLLEXPORT wxListRenameTimer
;
47 class WXDLLEXPORT wxListTextCtrl
;
49 //-----------------------------------------------------------------------------
51 //-----------------------------------------------------------------------------
53 class WXDLLEXPORT wxGenericListCtrl
: public wxControl
58 wxGenericListCtrl( wxWindow
*parent
,
59 wxWindowID winid
= wxID_ANY
,
60 const wxPoint
&pos
= wxDefaultPosition
,
61 const wxSize
&size
= wxDefaultSize
,
62 long style
= wxLC_ICON
,
63 const wxValidator
& validator
= wxDefaultValidator
,
64 const wxString
&name
= wxGenericListCtrlNameStr
)
66 Create(parent
, winid
, pos
, size
, style
, validator
, name
);
68 virtual ~wxGenericListCtrl();
70 bool Create( wxWindow
*parent
,
71 wxWindowID winid
= wxID_ANY
,
72 const wxPoint
&pos
= wxDefaultPosition
,
73 const wxSize
&size
= wxDefaultSize
,
74 long style
= wxLC_ICON
,
75 const wxValidator
& validator
= wxDefaultValidator
,
76 const wxString
&name
= wxGenericListCtrlNameStr
);
78 bool GetColumn( int col
, wxListItem
& item
) const;
79 bool SetColumn( int col
, wxListItem
& item
);
80 int GetColumnWidth( int col
) const;
81 bool SetColumnWidth( int col
, int width
);
82 int GetCountPerPage() const; // not the same in wxGLC as in Windows, I think
83 wxRect
GetViewRect() const;
85 bool GetItem( wxListItem
& info
) const;
86 bool SetItem( wxListItem
& info
) ;
87 long SetItem( long index
, int col
, const wxString
& label
, int imageId
= -1 );
88 int GetItemState( long item
, long stateMask
) const;
89 bool SetItemState( long item
, long state
, long stateMask
);
90 bool SetItemImage( long item
, int image
, int selImage
= -1 );
91 bool SetItemColumnImage( long item
, long column
, int image
);
92 wxString
GetItemText( long item
) const;
93 void SetItemText( long item
, const wxString
& str
);
94 wxUIntPtr
GetItemData( long item
) const;
95 bool SetItemData( long item
, long data
);
96 bool GetItemRect( long item
, wxRect
& rect
, int code
= wxLIST_RECT_BOUNDS
) const;
97 bool GetItemPosition( long item
, wxPoint
& pos
) const;
98 bool SetItemPosition( long item
, const wxPoint
& pos
); // not supported in wxGLC
99 int GetItemCount() const;
100 int GetColumnCount() const;
101 void SetItemSpacing( int spacing
, bool isSmall
= false );
102 wxSize
GetItemSpacing() const;
103 void SetItemTextColour( long item
, const wxColour
& col
);
104 wxColour
GetItemTextColour( long item
) const;
105 void SetItemBackgroundColour( long item
, const wxColour
&col
);
106 wxColour
GetItemBackgroundColour( long item
) const;
107 void SetItemFont( long item
, const wxFont
&f
);
108 wxFont
GetItemFont( long item
) const;
109 int GetSelectedItemCount() const;
110 wxColour
GetTextColour() const;
111 void SetTextColour(const wxColour
& col
);
112 long GetTopItem() const;
114 void SetSingleStyle( long style
, bool add
= true ) ;
115 void SetWindowStyleFlag( long style
);
116 void RecreateWindow() {}
117 long GetNextItem( long item
, int geometry
= wxLIST_NEXT_ALL
, int state
= wxLIST_STATE_DONTCARE
) const;
118 wxImageList
*GetImageList( int which
) const;
119 void SetImageList( wxImageList
*imageList
, int which
);
120 void AssignImageList( wxImageList
*imageList
, int which
);
121 bool Arrange( int flag
= wxLIST_ALIGN_DEFAULT
); // always wxLIST_ALIGN_LEFT in wxGLC
124 bool DeleteItem( long item
);
125 bool DeleteAllItems();
126 bool DeleteAllColumns();
127 bool DeleteColumn( int col
);
129 void SetItemCount(long count
);
131 wxTextCtrl
*EditLabel(long item
,
132 wxClassInfo
* textControlClass
= CLASSINFO(wxTextCtrl
));
133 wxTextCtrl
* GetEditControl() const;
134 void Edit( long item
) { EditLabel(item
); }
136 bool EnsureVisible( long item
);
137 long FindItem( long start
, const wxString
& str
, bool partial
= false );
138 long FindItem( long start
, wxUIntPtr data
);
139 long FindItem( long start
, const wxPoint
& pt
, int direction
); // not supported in wxGLC
140 long HitTest( const wxPoint
& point
, int& flags
, long *pSubItem
= NULL
) const;
141 long InsertItem(wxListItem
& info
);
142 long InsertItem( long index
, const wxString
& label
);
143 long InsertItem( long index
, int imageIndex
);
144 long InsertItem( long index
, const wxString
& label
, int imageIndex
);
145 long InsertColumn( long col
, wxListItem
& info
);
146 long InsertColumn( long col
, const wxString
& heading
,
147 int format
= wxLIST_FORMAT_LEFT
, int width
= -1 );
148 bool ScrollList( int dx
, int dy
);
149 bool SortItems( wxListCtrlCompare fn
, long data
);
150 bool Update( long item
);
151 // Must provide overload to avoid hiding it (and warnings about it)
152 virtual void Update() { wxControl::Update(); }
154 // are we in report mode?
155 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
157 // are we in virtual report mode?
158 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
160 // do we have a header window?
161 bool HasHeader() const
162 { return InReportView() && !HasFlag(wxLC_NO_HEADER
); }
164 // refresh items selectively (only useful for virtual list controls)
165 void RefreshItem(long item
);
166 void RefreshItems(long itemFrom
, long itemTo
);
168 #if WXWIN_COMPATIBILITY_2_6
169 // obsolete, don't use
170 wxDEPRECATED( int GetItemSpacing( bool isSmall
) const );
171 #endif // WXWIN_COMPATIBILITY_2_6
173 virtual wxVisualAttributes
GetDefaultAttributes() const
175 return GetClassDefaultAttributes(GetWindowVariant());
178 static wxVisualAttributes
179 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
181 // implementation only from now on
182 // -------------------------------
184 void OnInternalIdle( );
185 void OnSize( wxSizeEvent
&event
);
187 // We have to hand down a few functions
188 virtual void Refresh(bool eraseBackground
= true,
189 const wxRect
*rect
= NULL
);
191 virtual void Freeze();
194 virtual bool SetBackgroundColour( const wxColour
&colour
);
195 virtual bool SetForegroundColour( const wxColour
&colour
);
196 virtual wxColour
GetBackgroundColour() const;
197 virtual wxColour
GetForegroundColour() const;
198 virtual bool SetFont( const wxFont
&font
);
199 virtual bool SetCursor( const wxCursor
&cursor
);
201 #if wxUSE_DRAG_AND_DROP
202 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
203 virtual wxDropTarget
*GetDropTarget() const;
206 virtual bool ShouldInheritColours() const { return false; }
207 virtual void SetFocus();
212 wxImageList
*m_imageListNormal
;
213 wxImageList
*m_imageListSmall
;
214 wxImageList
*m_imageListState
; // what's that ?
215 bool m_ownsImageListNormal
,
216 m_ownsImageListSmall
,
217 m_ownsImageListState
;
218 wxListHeaderWindow
*m_headerWin
;
219 wxListMainWindow
*m_mainWin
;
220 wxCoord m_headerHeight
;
223 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
225 // take into account the coordinates difference between the container
226 // window and the list control window itself here
227 virtual void DoClientToScreen( int *x
, int *y
) const;
228 virtual void DoScreenToClient( int *x
, int *y
) const;
230 virtual wxSize
DoGetBestSize() const;
232 // return the text for the given column of the given item
233 virtual wxString
OnGetItemText(long item
, long column
) const;
235 // return the icon for the given item. In report view, OnGetItemImage will
236 // only be called for the first column. See OnGetItemColumnImage for
238 virtual int OnGetItemImage(long item
) const;
240 // return the icon for the given item and column.
241 virtual int OnGetItemColumnImage(long item
, long column
) const;
243 // return the attribute for the item (may return NULL if none)
244 virtual wxListItemAttr
*OnGetItemAttr(long item
) const;
246 // it calls our OnGetXXX() functions
247 friend class WXDLLEXPORT wxListMainWindow
;
250 // create the header window
251 void CreateHeaderWindow();
253 // calculate and set height of the header
254 void CalculateAndSetHeaderHeight();
256 // reposition the header and the main window in the report view depending
257 // on whether it should be shown or not
258 void ResizeReportView(bool showHeader
);
260 DECLARE_EVENT_TABLE()
261 DECLARE_DYNAMIC_CLASS(wxGenericListCtrl
)
264 #if (!defined(__WXMSW__) || defined(__WXUNIVERSAL__)) && !defined(__WXMAC__)
266 * wxListCtrl has to be a real class or we have problems with
267 * the run-time information.
270 class WXDLLEXPORT wxListCtrl
: public wxGenericListCtrl
272 DECLARE_DYNAMIC_CLASS(wxListCtrl
)
277 wxListCtrl(wxWindow
*parent
, wxWindowID winid
= wxID_ANY
,
278 const wxPoint
& pos
= wxDefaultPosition
,
279 const wxSize
& size
= wxDefaultSize
,
280 long style
= wxLC_ICON
,
281 const wxValidator
&validator
= wxDefaultValidator
,
282 const wxString
&name
= wxListCtrlNameStr
)
283 : wxGenericListCtrl(parent
, winid
, pos
, size
, style
, validator
, name
)
288 #endif // !__WXMSW__ || __WXUNIVERSAL__
290 #endif // __LISTCTRLH_G__