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