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_CORE wxImageList
;
18 #if wxUSE_DRAG_AND_DROP
19 class WXDLLEXPORT wxDropTarget
;
22 // ----------------------------------------------------------------------------
24 // ----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
31 class WXDLLEXPORT wxListHeaderWindow
;
32 class WXDLLEXPORT wxListMainWindow
;
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
38 class WXDLLEXPORT 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 GetItemPosition( long item
, wxPoint
& pos
) const;
84 bool SetItemPosition( long item
, const wxPoint
& pos
); // not supported in wxGLC
85 int GetItemCount() const;
86 int GetColumnCount() const;
87 void SetItemSpacing( int spacing
, bool isSmall
= false );
88 wxSize
GetItemSpacing() const;
89 void SetItemTextColour( long item
, const wxColour
& col
);
90 wxColour
GetItemTextColour( long item
) const;
91 void SetItemBackgroundColour( long item
, const wxColour
&col
);
92 wxColour
GetItemBackgroundColour( long item
) const;
93 void SetItemFont( long item
, const wxFont
&f
);
94 wxFont
GetItemFont( long item
) const;
95 int GetSelectedItemCount() const;
96 wxColour
GetTextColour() const;
97 void SetTextColour(const wxColour
& col
);
98 long GetTopItem() const;
100 void SetSingleStyle( long style
, bool add
= true ) ;
101 void SetWindowStyleFlag( long style
);
102 void RecreateWindow() {}
103 long GetNextItem( long item
, int geometry
= wxLIST_NEXT_ALL
, int state
= wxLIST_STATE_DONTCARE
) const;
104 wxImageList
*GetImageList( int which
) const;
105 void SetImageList( wxImageList
*imageList
, int which
);
106 void AssignImageList( wxImageList
*imageList
, int which
);
107 bool Arrange( int flag
= wxLIST_ALIGN_DEFAULT
); // always wxLIST_ALIGN_LEFT in wxGLC
110 bool DeleteItem( long item
);
111 bool DeleteAllItems();
112 bool DeleteAllColumns();
113 bool DeleteColumn( int col
);
115 void SetItemCount(long count
);
117 wxTextCtrl
*EditLabel(long item
,
118 wxClassInfo
* textControlClass
= CLASSINFO(wxTextCtrl
));
119 wxTextCtrl
* GetEditControl() const;
120 void Edit( long item
) { EditLabel(item
); }
122 bool EnsureVisible( long item
);
123 long FindItem( long start
, const wxString
& str
, bool partial
= false );
124 long FindItem( long start
, wxUIntPtr data
);
125 long FindItem( long start
, const wxPoint
& pt
, int direction
); // not supported in wxGLC
126 long HitTest( const wxPoint
& point
, int& flags
, long *pSubItem
= NULL
) const;
127 long InsertItem(wxListItem
& info
);
128 long InsertItem( long index
, const wxString
& label
);
129 long InsertItem( long index
, int imageIndex
);
130 long InsertItem( long index
, const wxString
& label
, int imageIndex
);
131 long InsertColumn( long col
, wxListItem
& info
);
132 long InsertColumn( long col
, const wxString
& heading
,
133 int format
= wxLIST_FORMAT_LEFT
, int width
= -1 );
134 bool ScrollList( int dx
, int dy
);
135 bool SortItems( wxListCtrlCompare fn
, long data
);
136 bool Update( long item
);
137 // Must provide overload to avoid hiding it (and warnings about it)
138 virtual void Update() { wxControl::Update(); }
140 // are we in report mode?
141 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
143 // are we in virtual report mode?
144 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
146 // do we have a header window?
147 bool HasHeader() const
148 { return InReportView() && !HasFlag(wxLC_NO_HEADER
); }
150 // refresh items selectively (only useful for virtual list controls)
151 void RefreshItem(long item
);
152 void RefreshItems(long itemFrom
, long itemTo
);
154 #if WXWIN_COMPATIBILITY_2_6
155 // obsolete, don't use
156 wxDEPRECATED( int GetItemSpacing( bool isSmall
) const );
157 #endif // WXWIN_COMPATIBILITY_2_6
159 virtual wxVisualAttributes
GetDefaultAttributes() const
161 return GetClassDefaultAttributes(GetWindowVariant());
164 static wxVisualAttributes
165 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
167 // implementation only from now on
168 // -------------------------------
170 void OnInternalIdle( );
171 void OnSize( wxSizeEvent
&event
);
173 // We have to hand down a few functions
174 virtual void Refresh(bool eraseBackground
= true,
175 const wxRect
*rect
= NULL
);
177 virtual void Freeze();
180 virtual bool SetBackgroundColour( const wxColour
&colour
);
181 virtual bool SetForegroundColour( const wxColour
&colour
);
182 virtual wxColour
GetBackgroundColour() const;
183 virtual wxColour
GetForegroundColour() const;
184 virtual bool SetFont( const wxFont
&font
);
185 virtual bool SetCursor( const wxCursor
&cursor
);
187 virtual int GetScrollPos(int orient
) const;
188 virtual void SetScrollPos(int orient
, int pos
, bool refresh
= true);
190 #if wxUSE_DRAG_AND_DROP
191 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
192 virtual wxDropTarget
*GetDropTarget() const;
195 virtual bool ShouldInheritColours() const { return false; }
196 virtual void SetFocus();
201 wxImageList
*m_imageListNormal
;
202 wxImageList
*m_imageListSmall
;
203 wxImageList
*m_imageListState
; // what's that ?
204 bool m_ownsImageListNormal
,
205 m_ownsImageListSmall
,
206 m_ownsImageListState
;
207 wxListHeaderWindow
*m_headerWin
;
208 wxListMainWindow
*m_mainWin
;
209 wxCoord m_headerHeight
;
212 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
214 // take into account the coordinates difference between the container
215 // window and the list control window itself here
216 virtual void DoClientToScreen( int *x
, int *y
) const;
217 virtual void DoScreenToClient( int *x
, int *y
) const;
219 virtual wxSize
DoGetBestSize() const;
221 // return the text for the given column of the given item
222 virtual wxString
OnGetItemText(long item
, long column
) const;
224 // return the icon for the given item. In report view, OnGetItemImage will
225 // only be called for the first column. See OnGetItemColumnImage for
227 virtual int OnGetItemImage(long item
) const;
229 // return the icon for the given item and column.
230 virtual int OnGetItemColumnImage(long item
, long column
) const;
232 // return the attribute for the item (may return NULL if none)
233 virtual wxListItemAttr
*OnGetItemAttr(long item
) const;
235 // it calls our OnGetXXX() functions
236 friend class WXDLLEXPORT wxListMainWindow
;
239 // create the header window
240 void CreateHeaderWindow();
242 // calculate and set height of the header
243 void CalculateAndSetHeaderHeight();
245 // reposition the header and the main window in the report view depending
246 // on whether it should be shown or not
247 void ResizeReportView(bool showHeader
);
249 DECLARE_EVENT_TABLE()
250 DECLARE_DYNAMIC_CLASS(wxGenericListCtrl
)
253 #if (!defined(__WXMSW__) || defined(__WXUNIVERSAL__)) && !defined(__WXMAC__)
255 * wxListCtrl has to be a real class or we have problems with
256 * the run-time information.
259 class WXDLLEXPORT wxListCtrl
: public wxGenericListCtrl
261 DECLARE_DYNAMIC_CLASS(wxListCtrl
)
266 wxListCtrl(wxWindow
*parent
, wxWindowID winid
= wxID_ANY
,
267 const wxPoint
& pos
= wxDefaultPosition
,
268 const wxSize
& size
= wxDefaultSize
,
269 long style
= wxLC_ICON
,
270 const wxValidator
&validator
= wxDefaultValidator
,
271 const wxString
&name
= wxListCtrlNameStr
)
272 : wxGenericListCtrl(parent
, winid
, pos
, size
, style
, validator
, name
)
277 #endif // !__WXMSW__ || __WXUNIVERSAL__
279 #endif // _WX_GENERIC_LISTCTRL_H_