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"
28 #include "wx/textctrl.h"
30 #if wxUSE_DRAG_AND_DROP
31 class WXDLLEXPORT wxDropTarget
;
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
38 class WXDLLEXPORT wxListItem
;
39 class WXDLLEXPORT wxListEvent
;
41 #if !defined(__WXMSW__) || defined(__WXUNIVERSAL__)
42 class WXDLLEXPORT wxListCtrl
;
43 #define wxImageListType wxImageList
45 #define wxImageListType wxGenericImageList
48 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------
52 class WXDLLEXPORT wxListHeaderData
;
53 class WXDLLEXPORT wxListItemData
;
54 class WXDLLEXPORT wxListLineData
;
56 class WXDLLEXPORT wxListHeaderWindow
;
57 class WXDLLEXPORT wxListMainWindow
;
59 class WXDLLEXPORT wxListRenameTimer
;
60 class WXDLLEXPORT wxListTextCtrl
;
62 //-----------------------------------------------------------------------------
64 //-----------------------------------------------------------------------------
66 class WXDLLEXPORT wxGenericListCtrl
: public wxControl
70 wxGenericListCtrl( 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
= wxListCtrlNameStr
)
78 Create(parent
, winid
, pos
, size
, style
, validator
, name
);
82 bool Create( wxWindow
*parent
,
83 wxWindowID winid
= wxID_ANY
,
84 const wxPoint
&pos
= wxDefaultPosition
,
85 const wxSize
&size
= wxDefaultSize
,
86 long style
= wxLC_ICON
,
87 const wxValidator
& validator
= wxDefaultValidator
,
88 const wxString
&name
= wxListCtrlNameStr
);
90 bool GetColumn( int col
, wxListItem
& item
) const;
91 bool SetColumn( int col
, wxListItem
& item
);
92 int GetColumnWidth( int col
) const;
93 bool SetColumnWidth( int col
, int width
);
94 int GetCountPerPage() const; // not the same in wxGLC as in Windows, I think
95 wxRect
GetViewRect() const;
97 bool GetItem( wxListItem
& info
) const;
98 bool SetItem( wxListItem
& info
) ;
99 long SetItem( long index
, int col
, const wxString
& label
, int imageId
= -1 );
100 int GetItemState( long item
, long stateMask
) const;
101 bool SetItemState( long item
, long state
, long stateMask
);
102 bool SetItemImage( long item
, int image
, int selImage
= -1 );
103 bool SetItemColumnImage( long item
, long column
, int image
);
104 wxString
GetItemText( long item
) const;
105 void SetItemText( long item
, const wxString
& str
);
106 wxUIntPtr
GetItemData( long item
) const;
107 bool SetItemData( long item
, long data
);
108 bool GetItemRect( long item
, wxRect
& rect
, int code
= wxLIST_RECT_BOUNDS
) const;
109 bool GetItemPosition( long item
, wxPoint
& pos
) const;
110 bool SetItemPosition( long item
, const wxPoint
& pos
); // not supported in wxGLC
111 int GetItemCount() const;
112 int GetColumnCount() const;
113 void SetItemSpacing( int spacing
, bool isSmall
= false );
114 wxSize
GetItemSpacing() const;
115 void SetItemTextColour( long item
, const wxColour
& col
);
116 wxColour
GetItemTextColour( long item
) const;
117 void SetItemBackgroundColour( long item
, const wxColour
&col
);
118 wxColour
GetItemBackgroundColour( long item
) const;
119 void SetItemFont( long item
, const wxFont
&f
);
120 wxFont
GetItemFont( long item
) const;
121 int GetSelectedItemCount() const;
122 wxColour
GetTextColour() const;
123 void SetTextColour(const wxColour
& col
);
124 long GetTopItem() const;
126 void SetSingleStyle( long style
, bool add
= true ) ;
127 void SetWindowStyleFlag( long style
);
128 void RecreateWindow() {}
129 long GetNextItem( long item
, int geometry
= wxLIST_NEXT_ALL
, int state
= wxLIST_STATE_DONTCARE
) const;
130 wxImageListType
*GetImageList( int which
) const;
131 void SetImageList( wxImageListType
*imageList
, int which
);
132 void AssignImageList( wxImageListType
*imageList
, int which
);
133 bool Arrange( int flag
= wxLIST_ALIGN_DEFAULT
); // always wxLIST_ALIGN_LEFT in wxGLC
136 bool DeleteItem( long item
);
137 bool DeleteAllItems();
138 bool DeleteAllColumns();
139 bool DeleteColumn( int col
);
141 void SetItemCount(long count
);
143 wxTextCtrl
*EditLabel(long item
,
144 wxClassInfo
* textControlClass
= CLASSINFO(wxTextCtrl
));
145 wxTextCtrl
* GetEditControl() const;
146 void Edit( long item
) { EditLabel(item
); }
148 bool EnsureVisible( long item
);
149 long FindItem( long start
, const wxString
& str
, bool partial
= false );
150 long FindItem( long start
, wxUIntPtr data
);
151 long FindItem( long start
, const wxPoint
& pt
, int direction
); // not supported in wxGLC
152 long HitTest( const wxPoint
& point
, int& flags
);
153 long InsertItem(wxListItem
& info
);
154 long InsertItem( long index
, const wxString
& label
);
155 long InsertItem( long index
, int imageIndex
);
156 long InsertItem( long index
, const wxString
& label
, int imageIndex
);
157 long InsertColumn( long col
, wxListItem
& info
);
158 long InsertColumn( long col
, const wxString
& heading
,
159 int format
= wxLIST_FORMAT_LEFT
, int width
= -1 );
160 bool ScrollList( int dx
, int dy
);
161 bool SortItems( wxListCtrlCompare fn
, long data
);
162 bool Update( long item
);
163 // Must provide overload to avoid hiding it (and warnings about it)
164 virtual void Update() { wxControl::Update(); }
166 // are we in report mode?
167 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
169 // are we in virtual report mode?
170 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
172 // do we have a header window?
173 bool HasHeader() const
174 { return InReportView() && !HasFlag(wxLC_NO_HEADER
); }
176 // refresh items selectively (only useful for virtual list controls)
177 void RefreshItem(long item
);
178 void RefreshItems(long itemFrom
, long itemTo
);
180 // obsolete, don't use
181 wxDEPRECATED( int GetItemSpacing( bool isSmall
) const );
184 virtual wxVisualAttributes
GetDefaultAttributes() const
186 return GetClassDefaultAttributes(GetWindowVariant());
189 static wxVisualAttributes
190 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
192 // implementation only from now on
193 // -------------------------------
195 void OnInternalIdle( );
196 void OnSize( wxSizeEvent
&event
);
198 // We have to hand down a few functions
199 virtual void Refresh(bool eraseBackground
= true,
200 const wxRect
*rect
= NULL
);
202 virtual void Freeze();
205 virtual bool SetBackgroundColour( const wxColour
&colour
);
206 virtual bool SetForegroundColour( const wxColour
&colour
);
207 virtual wxColour
GetBackgroundColour() const;
208 virtual wxColour
GetForegroundColour() const;
209 virtual bool SetFont( const wxFont
&font
);
210 virtual bool SetCursor( const wxCursor
&cursor
);
212 #if wxUSE_DRAG_AND_DROP
213 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
214 virtual wxDropTarget
*GetDropTarget() const;
217 virtual bool ShouldInheritColours() const { return false; }
218 virtual void SetFocus();
223 wxImageListType
*m_imageListNormal
;
224 wxImageListType
*m_imageListSmall
;
225 wxImageListType
*m_imageListState
; // what's that ?
226 bool m_ownsImageListNormal
,
227 m_ownsImageListSmall
,
228 m_ownsImageListState
;
229 wxListHeaderWindow
*m_headerWin
;
230 wxListMainWindow
*m_mainWin
;
231 wxCoord m_headerHeight
;
234 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
236 // take into account the coordinates difference between the container
237 // window and the list control window itself here
238 virtual void DoClientToScreen( int *x
, int *y
) const;
239 virtual void DoScreenToClient( int *x
, int *y
) const;
241 virtual wxSize
DoGetBestSize() const;
243 // return the text for the given column of the given item
244 virtual wxString
OnGetItemText(long item
, long column
) const;
246 // return the icon for the given item. In report view, OnGetItemImage will
247 // only be called for the first column. See OnGetItemColumnImage for
249 virtual int OnGetItemImage(long item
) const;
251 // return the icon for the given item and column.
252 virtual int OnGetItemColumnImage(long item
, long column
) const;
254 // return the attribute for the item (may return NULL if none)
255 virtual wxListItemAttr
*OnGetItemAttr(long item
) const;
257 // it calls our OnGetXXX() functions
258 friend class WXDLLEXPORT wxListMainWindow
;
261 // create the header window
262 void CreateHeaderWindow();
264 // calculate and set height of the header
265 void CalculateAndSetHeaderHeight();
267 // reposition the header and the main window in the report view depending
268 // on whether it should be shown or not
269 void ResizeReportView(bool showHeader
);
271 DECLARE_EVENT_TABLE()
272 DECLARE_DYNAMIC_CLASS(wxGenericListCtrl
)
275 #if !defined(__WXMSW__) || defined(__WXUNIVERSAL__)
277 * wxListCtrl has to be a real class or we have problems with
278 * the run-time information.
281 class WXDLLEXPORT wxListCtrl
: public wxGenericListCtrl
283 DECLARE_DYNAMIC_CLASS(wxListCtrl
)
288 wxListCtrl(wxWindow
*parent
, wxWindowID winid
= wxID_ANY
,
289 const wxPoint
& pos
= wxDefaultPosition
,
290 const wxSize
& size
= wxDefaultSize
,
291 long style
= wxLC_ICON
,
292 const wxValidator
&validator
= wxDefaultValidator
,
293 const wxString
&name
= wxListCtrlNameStr
)
294 : wxGenericListCtrl(parent
, winid
, pos
, size
, style
, validator
, name
)
298 #endif // !__WXMSW__ || __WXUNIVERSAL__
300 #endif // __LISTCTRLH_G__