]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/listctrl.h
listctrl header cleanup
[wxWidgets.git] / include / wx / generic / listctrl.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/listctrl.h
3 // Purpose: Generic list control
4 // Author: Robert Roebling
5 // Created: 01/02/97
6 // RCS-ID: $Id$
7 // Copyright: (c) 1998 Robert Roebling and Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_GENERIC_LISTCTRL_H_
12 #define _WX_GENERIC_LISTCTRL_H_
13
14 #include "wx/textctrl.h"
15
16 class WXDLLIMPEXP_CORE wxImageList;
17
18 #if wxUSE_DRAG_AND_DROP
19 class WXDLLEXPORT wxDropTarget;
20 #endif
21
22 // ----------------------------------------------------------------------------
23 // constants
24 // ----------------------------------------------------------------------------
25
26
27 //-----------------------------------------------------------------------------
28 // internal classes
29 //-----------------------------------------------------------------------------
30
31 class WXDLLEXPORT wxListHeaderWindow;
32 class WXDLLEXPORT wxListMainWindow;
33
34 //-----------------------------------------------------------------------------
35 // wxListCtrl
36 //-----------------------------------------------------------------------------
37
38 class WXDLLEXPORT wxGenericListCtrl: public wxControl
39 {
40 public:
41
42 wxGenericListCtrl();
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)
50 {
51 Create(parent, winid, pos, size, style, validator, name);
52 }
53 virtual ~wxGenericListCtrl();
54
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);
62
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;
69
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 SetItemData( long item, long data );
81 bool GetItemRect( long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS ) const;
82 bool GetItemPosition( long item, wxPoint& pos ) const;
83 bool SetItemPosition( long item, const wxPoint& pos ); // not supported in wxGLC
84 int GetItemCount() const;
85 int GetColumnCount() const;
86 void SetItemSpacing( int spacing, bool isSmall = false );
87 wxSize GetItemSpacing() const;
88 void SetItemTextColour( long item, const wxColour& col);
89 wxColour GetItemTextColour( long item ) const;
90 void SetItemBackgroundColour( long item, const wxColour &col);
91 wxColour GetItemBackgroundColour( long item ) const;
92 void SetItemFont( long item, const wxFont &f);
93 wxFont GetItemFont( long item ) const;
94 int GetSelectedItemCount() const;
95 wxColour GetTextColour() const;
96 void SetTextColour(const wxColour& col);
97 long GetTopItem() const;
98
99 void SetSingleStyle( long style, bool add = true ) ;
100 void SetWindowStyleFlag( long style );
101 void RecreateWindow() {}
102 long GetNextItem( long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE ) const;
103 wxImageList *GetImageList( int which ) const;
104 void SetImageList( wxImageList *imageList, int which );
105 void AssignImageList( wxImageList *imageList, int which );
106 bool Arrange( int flag = wxLIST_ALIGN_DEFAULT ); // always wxLIST_ALIGN_LEFT in wxGLC
107
108 void ClearAll();
109 bool DeleteItem( long item );
110 bool DeleteAllItems();
111 bool DeleteAllColumns();
112 bool DeleteColumn( int col );
113
114 void SetItemCount(long count);
115
116 wxTextCtrl *EditLabel(long item,
117 wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl));
118 wxTextCtrl* GetEditControl() const;
119 void Edit( long item ) { EditLabel(item); }
120
121 bool EnsureVisible( long item );
122 long FindItem( long start, const wxString& str, bool partial = false );
123 long FindItem( long start, wxUIntPtr data );
124 long FindItem( long start, const wxPoint& pt, int direction ); // not supported in wxGLC
125 long HitTest( const wxPoint& point, int& flags, long *pSubItem = NULL ) const;
126 long InsertItem(wxListItem& info);
127 long InsertItem( long index, const wxString& label );
128 long InsertItem( long index, int imageIndex );
129 long InsertItem( long index, const wxString& label, int imageIndex );
130 long InsertColumn( long col, wxListItem& info );
131 long InsertColumn( long col, const wxString& heading,
132 int format = wxLIST_FORMAT_LEFT, int width = -1 );
133 bool ScrollList( int dx, int dy );
134 bool SortItems( wxListCtrlCompare fn, long data );
135 bool Update( long item );
136 // Must provide overload to avoid hiding it (and warnings about it)
137 virtual void Update() { wxControl::Update(); }
138
139 // are we in report mode?
140 bool InReportView() const { return HasFlag(wxLC_REPORT); }
141
142 // are we in virtual report mode?
143 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL); }
144
145 // do we have a header window?
146 bool HasHeader() const
147 { return InReportView() && !HasFlag(wxLC_NO_HEADER); }
148
149 // refresh items selectively (only useful for virtual list controls)
150 void RefreshItem(long item);
151 void RefreshItems(long itemFrom, long itemTo);
152
153 #if WXWIN_COMPATIBILITY_2_6
154 // obsolete, don't use
155 wxDEPRECATED( int GetItemSpacing( bool isSmall ) const );
156 #endif // WXWIN_COMPATIBILITY_2_6
157
158 virtual wxVisualAttributes GetDefaultAttributes() const
159 {
160 return GetClassDefaultAttributes(GetWindowVariant());
161 }
162
163 static wxVisualAttributes
164 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
165
166 // implementation only from now on
167 // -------------------------------
168
169 void OnInternalIdle( );
170 void OnSize( wxSizeEvent &event );
171
172 // We have to hand down a few functions
173 virtual void Refresh(bool eraseBackground = true,
174 const wxRect *rect = NULL);
175
176 virtual void Freeze();
177 virtual void Thaw();
178
179 virtual bool SetBackgroundColour( const wxColour &colour );
180 virtual bool SetForegroundColour( const wxColour &colour );
181 virtual wxColour GetBackgroundColour() const;
182 virtual wxColour GetForegroundColour() const;
183 virtual bool SetFont( const wxFont &font );
184 virtual bool SetCursor( const wxCursor &cursor );
185
186 #if wxUSE_DRAG_AND_DROP
187 virtual void SetDropTarget( wxDropTarget *dropTarget );
188 virtual wxDropTarget *GetDropTarget() const;
189 #endif
190
191 virtual bool ShouldInheritColours() const { return false; }
192 virtual void SetFocus();
193
194 // implementation
195 // --------------
196
197 wxImageList *m_imageListNormal;
198 wxImageList *m_imageListSmall;
199 wxImageList *m_imageListState; // what's that ?
200 bool m_ownsImageListNormal,
201 m_ownsImageListSmall,
202 m_ownsImageListState;
203 wxListHeaderWindow *m_headerWin;
204 wxListMainWindow *m_mainWin;
205 wxCoord m_headerHeight;
206
207 protected:
208 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
209
210 // take into account the coordinates difference between the container
211 // window and the list control window itself here
212 virtual void DoClientToScreen( int *x, int *y ) const;
213 virtual void DoScreenToClient( int *x, int *y ) const;
214
215 virtual wxSize DoGetBestSize() const;
216
217 // return the text for the given column of the given item
218 virtual wxString OnGetItemText(long item, long column) const;
219
220 // return the icon for the given item. In report view, OnGetItemImage will
221 // only be called for the first column. See OnGetItemColumnImage for
222 // details.
223 virtual int OnGetItemImage(long item) const;
224
225 // return the icon for the given item and column.
226 virtual int OnGetItemColumnImage(long item, long column) const;
227
228 // return the attribute for the item (may return NULL if none)
229 virtual wxListItemAttr *OnGetItemAttr(long item) const;
230
231 // it calls our OnGetXXX() functions
232 friend class WXDLLEXPORT wxListMainWindow;
233
234 private:
235 // create the header window
236 void CreateHeaderWindow();
237
238 // calculate and set height of the header
239 void CalculateAndSetHeaderHeight();
240
241 // reposition the header and the main window in the report view depending
242 // on whether it should be shown or not
243 void ResizeReportView(bool showHeader);
244
245 DECLARE_EVENT_TABLE()
246 DECLARE_DYNAMIC_CLASS(wxGenericListCtrl)
247 };
248
249 #if (!defined(__WXMSW__) || defined(__WXUNIVERSAL__)) && !defined(__WXMAC__)
250 /*
251 * wxListCtrl has to be a real class or we have problems with
252 * the run-time information.
253 */
254
255 class WXDLLEXPORT wxListCtrl: public wxGenericListCtrl
256 {
257 DECLARE_DYNAMIC_CLASS(wxListCtrl)
258
259 public:
260 wxListCtrl() {}
261
262 wxListCtrl(wxWindow *parent, wxWindowID winid = wxID_ANY,
263 const wxPoint& pos = wxDefaultPosition,
264 const wxSize& size = wxDefaultSize,
265 long style = wxLC_ICON,
266 const wxValidator &validator = wxDefaultValidator,
267 const wxString &name = wxListCtrlNameStr)
268 : wxGenericListCtrl(parent, winid, pos, size, style, validator, name)
269 {
270 }
271
272 };
273 #endif // !__WXMSW__ || __WXUNIVERSAL__
274
275 #endif // _WX_GENERIC_LISTCTRL_H_