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 // ----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
39 class WXDLLEXPORT wxListHeaderData
;
40 class WXDLLEXPORT wxListItemData
;
42 class WXDLLEXPORT wxListHeaderWindow
;
43 class WXDLLEXPORT wxListMainWindow
;
45 class WXDLLEXPORT wxListRenameTimer
;
46 class WXDLLEXPORT wxListTextCtrl
;
48 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------
52 class WXDLLEXPORT wxGenericListCtrl
: public wxControl
57 wxGenericListCtrl( wxWindow
*parent
,
58 wxWindowID winid
= wxID_ANY
,
59 const wxPoint
&pos
= wxDefaultPosition
,
60 const wxSize
&size
= wxDefaultSize
,
61 long style
= wxLC_ICON
,
62 const wxValidator
& validator
= wxDefaultValidator
,
63 const wxString
&name
= wxListCtrlNameStr
)
65 Create(parent
, winid
, pos
, size
, style
, validator
, name
);
67 virtual ~wxGenericListCtrl();
69 bool Create( 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 bool GetColumn( int col
, wxListItem
& item
) const;
78 bool SetColumn( int col
, wxListItem
& item
);
79 int GetColumnWidth( int col
) const;
80 bool SetColumnWidth( int col
, int width
);
81 int GetCountPerPage() const; // not the same in wxGLC as in Windows, I think
82 wxRect
GetViewRect() const;
84 bool GetItem( wxListItem
& info
) const;
85 bool SetItem( wxListItem
& info
) ;
86 long SetItem( long index
, int col
, const wxString
& label
, int imageId
= -1 );
87 int GetItemState( long item
, long stateMask
) const;
88 bool SetItemState( long item
, long state
, long stateMask
);
89 bool SetItemImage( long item
, int image
, int selImage
= -1 );
90 bool SetItemColumnImage( long item
, long column
, int image
);
91 wxString
GetItemText( long item
) const;
92 void SetItemText( long item
, const wxString
& str
);
93 wxUIntPtr
GetItemData( long item
) const;
94 bool SetItemData( long item
, long data
);
95 bool GetItemRect( long item
, wxRect
& rect
, int code
= wxLIST_RECT_BOUNDS
) const;
96 bool GetItemPosition( long item
, wxPoint
& pos
) const;
97 bool SetItemPosition( long item
, const wxPoint
& pos
); // not supported in wxGLC
98 int GetItemCount() const;
99 int GetColumnCount() const;
100 void SetItemSpacing( int spacing
, bool isSmall
= false );
101 wxSize
GetItemSpacing() const;
102 void SetItemTextColour( long item
, const wxColour
& col
);
103 wxColour
GetItemTextColour( long item
) const;
104 void SetItemBackgroundColour( long item
, const wxColour
&col
);
105 wxColour
GetItemBackgroundColour( long item
) const;
106 void SetItemFont( long item
, const wxFont
&f
);
107 wxFont
GetItemFont( long item
) const;
108 int GetSelectedItemCount() const;
109 wxColour
GetTextColour() const;
110 void SetTextColour(const wxColour
& col
);
111 long GetTopItem() const;
113 void SetSingleStyle( long style
, bool add
= true ) ;
114 void SetWindowStyleFlag( long style
);
115 void RecreateWindow() {}
116 long GetNextItem( long item
, int geometry
= wxLIST_NEXT_ALL
, int state
= wxLIST_STATE_DONTCARE
) const;
117 wxImageList
*GetImageList( int which
) const;
118 void SetImageList( wxImageList
*imageList
, int which
);
119 void AssignImageList( wxImageList
*imageList
, int which
);
120 bool Arrange( int flag
= wxLIST_ALIGN_DEFAULT
); // always wxLIST_ALIGN_LEFT in wxGLC
123 bool DeleteItem( long item
);
124 bool DeleteAllItems();
125 bool DeleteAllColumns();
126 bool DeleteColumn( int col
);
128 void SetItemCount(long count
);
130 wxTextCtrl
*EditLabel(long item
,
131 wxClassInfo
* textControlClass
= CLASSINFO(wxTextCtrl
));
132 wxTextCtrl
* GetEditControl() const;
133 void Edit( long item
) { EditLabel(item
); }
135 bool EnsureVisible( long item
);
136 long FindItem( long start
, const wxString
& str
, bool partial
= false );
137 long FindItem( long start
, wxUIntPtr data
);
138 long FindItem( long start
, const wxPoint
& pt
, int direction
); // not supported in wxGLC
139 long HitTest( const wxPoint
& point
, int& flags
, long *pSubItem
= NULL
) const;
140 long InsertItem(wxListItem
& info
);
141 long InsertItem( long index
, const wxString
& label
);
142 long InsertItem( long index
, int imageIndex
);
143 long InsertItem( long index
, const wxString
& label
, int imageIndex
);
144 long InsertColumn( long col
, wxListItem
& info
);
145 long InsertColumn( long col
, const wxString
& heading
,
146 int format
= wxLIST_FORMAT_LEFT
, int width
= -1 );
147 bool ScrollList( int dx
, int dy
);
148 bool SortItems( wxListCtrlCompare fn
, long data
);
149 bool Update( long item
);
150 // Must provide overload to avoid hiding it (and warnings about it)
151 virtual void Update() { wxControl::Update(); }
153 // are we in report mode?
154 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
156 // are we in virtual report mode?
157 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
159 // do we have a header window?
160 bool HasHeader() const
161 { return InReportView() && !HasFlag(wxLC_NO_HEADER
); }
163 // refresh items selectively (only useful for virtual list controls)
164 void RefreshItem(long item
);
165 void RefreshItems(long itemFrom
, long itemTo
);
167 #if WXWIN_COMPATIBILITY_2_6
168 // obsolete, don't use
169 wxDEPRECATED( int GetItemSpacing( bool isSmall
) const );
170 #endif // WXWIN_COMPATIBILITY_2_6
172 virtual wxVisualAttributes
GetDefaultAttributes() const
174 return GetClassDefaultAttributes(GetWindowVariant());
177 static wxVisualAttributes
178 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
180 // implementation only from now on
181 // -------------------------------
183 void OnInternalIdle( );
184 void OnSize( wxSizeEvent
&event
);
186 // We have to hand down a few functions
187 virtual void Refresh(bool eraseBackground
= true,
188 const wxRect
*rect
= NULL
);
190 virtual void Freeze();
193 virtual bool SetBackgroundColour( const wxColour
&colour
);
194 virtual bool SetForegroundColour( const wxColour
&colour
);
195 virtual wxColour
GetBackgroundColour() const;
196 virtual wxColour
GetForegroundColour() const;
197 virtual bool SetFont( const wxFont
&font
);
198 virtual bool SetCursor( const wxCursor
&cursor
);
200 #if wxUSE_DRAG_AND_DROP
201 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
202 virtual wxDropTarget
*GetDropTarget() const;
205 virtual bool ShouldInheritColours() const { return false; }
206 virtual void SetFocus();
211 wxImageList
*m_imageListNormal
;
212 wxImageList
*m_imageListSmall
;
213 wxImageList
*m_imageListState
; // what's that ?
214 bool m_ownsImageListNormal
,
215 m_ownsImageListSmall
,
216 m_ownsImageListState
;
217 wxListHeaderWindow
*m_headerWin
;
218 wxListMainWindow
*m_mainWin
;
219 wxCoord m_headerHeight
;
222 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
224 // take into account the coordinates difference between the container
225 // window and the list control window itself here
226 virtual void DoClientToScreen( int *x
, int *y
) const;
227 virtual void DoScreenToClient( int *x
, int *y
) const;
229 virtual wxSize
DoGetBestSize() const;
231 // return the text for the given column of the given item
232 virtual wxString
OnGetItemText(long item
, long column
) const;
234 // return the icon for the given item. In report view, OnGetItemImage will
235 // only be called for the first column. See OnGetItemColumnImage for
237 virtual int OnGetItemImage(long item
) const;
239 // return the icon for the given item and column.
240 virtual int OnGetItemColumnImage(long item
, long column
) const;
242 // return the attribute for the item (may return NULL if none)
243 virtual wxListItemAttr
*OnGetItemAttr(long item
) const;
245 // it calls our OnGetXXX() functions
246 friend class WXDLLEXPORT wxListMainWindow
;
249 // create the header window
250 void CreateHeaderWindow();
252 // calculate and set height of the header
253 void CalculateAndSetHeaderHeight();
255 // reposition the header and the main window in the report view depending
256 // on whether it should be shown or not
257 void ResizeReportView(bool showHeader
);
259 DECLARE_EVENT_TABLE()
260 DECLARE_DYNAMIC_CLASS(wxGenericListCtrl
)
263 #if (!defined(__WXMSW__) || defined(__WXUNIVERSAL__)) && !defined(__WXMAC__)
265 * wxListCtrl has to be a real class or we have problems with
266 * the run-time information.
269 class WXDLLEXPORT wxListCtrl
: public wxGenericListCtrl
271 DECLARE_DYNAMIC_CLASS(wxListCtrl
)
276 wxListCtrl(wxWindow
*parent
, wxWindowID winid
= wxID_ANY
,
277 const wxPoint
& pos
= wxDefaultPosition
,
278 const wxSize
& size
= wxDefaultSize
,
279 long style
= wxLC_ICON
,
280 const wxValidator
&validator
= wxDefaultValidator
,
281 const wxString
&name
= wxListCtrlNameStr
)
282 : wxGenericListCtrl(parent
, winid
, pos
, size
, style
, validator
, name
)
287 #endif // !__WXMSW__ || __WXUNIVERSAL__
289 #endif // __LISTCTRLH_G__