]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/listctrl.h
added ping location for IRIX
[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 __LISTCTRLH_G__
12 #define __LISTCTRLH_G__
13
14 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
15 #pragma interface "listctrl.h"
16 #endif
17
18 #include "wx/defs.h"
19 #include "wx/object.h"
20 #ifdef __WXMAC__
21 #include "wx/imaglist.h"
22 #else
23 #include "wx/generic/imaglist.h"
24 #endif
25
26 #include "wx/control.h"
27 #include "wx/timer.h"
28 #include "wx/dcclient.h"
29 #include "wx/scrolwin.h"
30 #include "wx/settings.h"
31 #include "wx/listbase.h"
32
33 #if wxUSE_DRAG_AND_DROP
34 class WXDLLEXPORT wxDropTarget;
35 #endif
36
37 //-----------------------------------------------------------------------------
38 // classes
39 //-----------------------------------------------------------------------------
40
41 class WXDLLEXPORT wxListItem;
42 class WXDLLEXPORT wxListEvent;
43
44 #if !defined(__WXMSW__) || defined(__WXUNIVERSAL__)
45 class WXDLLEXPORT wxListCtrl;
46 #define wxImageListType wxImageList
47 #else
48 #define wxImageListType wxGenericImageList
49 #endif
50
51 //-----------------------------------------------------------------------------
52 // internal classes
53 //-----------------------------------------------------------------------------
54
55 class WXDLLEXPORT wxListHeaderData;
56 class WXDLLEXPORT wxListItemData;
57 class WXDLLEXPORT wxListLineData;
58
59 class WXDLLEXPORT wxListHeaderWindow;
60 class WXDLLEXPORT wxListMainWindow;
61
62 class WXDLLEXPORT wxListRenameTimer;
63 class WXDLLEXPORT wxListTextCtrl;
64
65 //-----------------------------------------------------------------------------
66 // wxListCtrl
67 //-----------------------------------------------------------------------------
68
69 class WXDLLEXPORT wxGenericListCtrl: public wxControl
70 {
71 public:
72 wxGenericListCtrl();
73 wxGenericListCtrl( wxWindow *parent,
74 wxWindowID winid = wxID_ANY,
75 const wxPoint &pos = wxDefaultPosition,
76 const wxSize &size = wxDefaultSize,
77 long style = wxLC_ICON,
78 const wxValidator& validator = wxDefaultValidator,
79 const wxString &name = wxListCtrlNameStr)
80 {
81 Create(parent, winid, pos, size, style, validator, name);
82 }
83 ~wxGenericListCtrl();
84
85 bool Create( wxWindow *parent,
86 wxWindowID winid = wxID_ANY,
87 const wxPoint &pos = wxDefaultPosition,
88 const wxSize &size = wxDefaultSize,
89 long style = wxLC_ICON,
90 const wxValidator& validator = wxDefaultValidator,
91 const wxString &name = wxListCtrlNameStr);
92
93 bool GetColumn( int col, wxListItem& item ) const;
94 bool SetColumn( int col, wxListItem& item );
95 int GetColumnWidth( int col ) const;
96 bool SetColumnWidth( int col, int width);
97 int GetCountPerPage() const; // not the same in wxGLC as in Windows, I think
98 wxRect GetViewRect() const;
99
100 bool GetItem( wxListItem& info ) const;
101 bool SetItem( wxListItem& info ) ;
102 long SetItem( long index, int col, const wxString& label, int imageId = -1 );
103 int GetItemState( long item, long stateMask ) const;
104 bool SetItemState( long item, long state, long stateMask);
105 bool SetItemImage( long item, int image, int selImage = -1 );
106 wxString GetItemText( long item ) const;
107 void SetItemText( long item, const wxString& str );
108 wxUIntPtr GetItemData( long item ) const;
109 bool SetItemData( long item, long data );
110 bool GetItemRect( long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS ) const;
111 bool GetItemPosition( long item, wxPoint& pos ) const;
112 bool SetItemPosition( long item, const wxPoint& pos ); // not supported in wxGLC
113 int GetItemCount() const;
114 int GetColumnCount() const;
115 void SetItemSpacing( int spacing, bool isSmall = false );
116 wxSize GetItemSpacing() const;
117 void SetItemTextColour( long item, const wxColour& col);
118 wxColour GetItemTextColour( long item ) const;
119 void SetItemBackgroundColour( long item, const wxColour &col);
120 wxColour GetItemBackgroundColour( long item ) const;
121 #if wxABI_VERSION >= 20602
122 void SetItemFont( long item, const wxFont &f);
123 wxFont GetItemFont( long item ) const;
124 #endif
125 int GetSelectedItemCount() const;
126 wxColour GetTextColour() const;
127 void SetTextColour(const wxColour& col);
128 long GetTopItem() const;
129
130 void SetSingleStyle( long style, bool add = true ) ;
131 void SetWindowStyleFlag( long style );
132 void RecreateWindow() {}
133 long GetNextItem( long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE ) const;
134 wxImageListType *GetImageList( int which ) const;
135 void SetImageList( wxImageListType *imageList, int which );
136 void AssignImageList( wxImageListType *imageList, int which );
137 bool Arrange( int flag = wxLIST_ALIGN_DEFAULT ); // always wxLIST_ALIGN_LEFT in wxGLC
138
139 void ClearAll();
140 bool DeleteItem( long item );
141 bool DeleteAllItems();
142 bool DeleteAllColumns();
143 bool DeleteColumn( int col );
144
145 void SetItemCount(long count);
146
147 void EditLabel( long item ) { Edit(item); }
148 void Edit( long item );
149
150 bool EnsureVisible( long item );
151 long FindItem( long start, const wxString& str, bool partial = false );
152 long FindItem( long start, wxUIntPtr data );
153 long FindItem( long start, const wxPoint& pt, int direction ); // not supported in wxGLC
154 long HitTest( const wxPoint& point, int& flags);
155 long InsertItem(wxListItem& info);
156 long InsertItem( long index, const wxString& label );
157 long InsertItem( long index, int imageIndex );
158 long InsertItem( long index, const wxString& label, int imageIndex );
159 long InsertColumn( long col, wxListItem& info );
160 long InsertColumn( long col, const wxString& heading,
161 int format = wxLIST_FORMAT_LEFT, int width = -1 );
162 bool ScrollList( int dx, int dy );
163 bool SortItems( wxListCtrlCompare fn, long data );
164 bool Update( long item );
165
166 // are we in report mode?
167 bool InReportView() const { return HasFlag(wxLC_REPORT); }
168
169 // are we in virtual report mode?
170 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL); }
171
172 // do we have a header window?
173 bool HasHeader() const
174 { return InReportView() && !HasFlag(wxLC_NO_HEADER); }
175
176 // refresh items selectively (only useful for virtual list controls)
177 void RefreshItem(long item);
178 void RefreshItems(long itemFrom, long itemTo);
179
180 // obsolete, don't use
181 wxDEPRECATED( int GetItemSpacing( bool isSmall ) const );
182
183
184 virtual wxVisualAttributes GetDefaultAttributes() const
185 {
186 return GetClassDefaultAttributes(GetWindowVariant());
187 }
188
189 static wxVisualAttributes
190 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
191
192 // implementation only from now on
193 // -------------------------------
194
195 void OnInternalIdle( );
196 void OnSize( wxSizeEvent &event );
197
198 // We have to hand down a few functions
199 virtual void Refresh(bool eraseBackground = true,
200 const wxRect *rect = NULL);
201
202 virtual void Freeze();
203 virtual void Thaw();
204
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 );
211
212 #if wxUSE_DRAG_AND_DROP
213 virtual void SetDropTarget( wxDropTarget *dropTarget );
214 virtual wxDropTarget *GetDropTarget() const;
215 #endif
216
217 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
218
219 virtual bool ShouldInheritColours() const { return false; }
220 virtual void SetFocus();
221
222 virtual wxSize DoGetBestSize() const;
223
224 // implementation
225 // --------------
226
227 wxImageListType *m_imageListNormal;
228 wxImageListType *m_imageListSmall;
229 wxImageListType *m_imageListState; // what's that ?
230 bool m_ownsImageListNormal,
231 m_ownsImageListSmall,
232 m_ownsImageListState;
233 wxListHeaderWindow *m_headerWin;
234 wxListMainWindow *m_mainWin;
235 wxCoord m_headerHeight;
236
237 protected:
238 // return the text for the given column of the given item
239 virtual wxString OnGetItemText(long item, long column) const;
240
241 // return the icon for the given item
242 virtual int OnGetItemImage(long item) const;
243
244 // return the attribute for the item (may return NULL if none)
245 virtual wxListItemAttr *OnGetItemAttr(long item) const;
246
247 // it calls our OnGetXXX() functions
248 friend class WXDLLEXPORT wxListMainWindow;
249
250 private:
251 // Virtual function hiding supression
252 virtual void Update() { wxWindow::Update(); }
253
254 // create the header window
255 void CreateHeaderWindow();
256
257 // calculate and set height of the header
258 void CalculateAndSetHeaderHeight();
259
260 // reposition the header and the main window in the report view depending
261 // on whether it should be shown or not
262 void ResizeReportView(bool showHeader);
263
264 DECLARE_EVENT_TABLE()
265 DECLARE_DYNAMIC_CLASS(wxGenericListCtrl)
266 };
267
268 #if !defined(__WXMSW__) || defined(__WXUNIVERSAL__)
269 /*
270 * wxListCtrl has to be a real class or we have problems with
271 * the run-time information.
272 */
273
274 class WXDLLEXPORT wxListCtrl: public wxGenericListCtrl
275 {
276 DECLARE_DYNAMIC_CLASS(wxListCtrl)
277
278 public:
279 wxListCtrl() {}
280
281 wxListCtrl(wxWindow *parent, wxWindowID winid = wxID_ANY,
282 const wxPoint& pos = wxDefaultPosition,
283 const wxSize& size = wxDefaultSize,
284 long style = wxLC_ICON,
285 const wxValidator &validator = wxDefaultValidator,
286 const wxString &name = wxListCtrlNameStr)
287 : wxGenericListCtrl(parent, winid, pos, size, style, validator, name)
288 {
289 }
290 };
291 #endif // !__WXMSW__ || __WXUNIVERSAL__
292
293 #endif // __LISTCTRLH_G__