]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/listctrl.h
fixes to wxWindowDC flipping+clipping when painting on hidden windows or windows...
[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 #include "wx/defs.h"
15 #include "wx/object.h"
16 #include "wx/imaglist.h"
17
18 #include "wx/control.h"
19 #include "wx/timer.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"
25
26 #if wxUSE_DRAG_AND_DROP
27 class WXDLLEXPORT wxDropTarget;
28 #endif
29
30 // ----------------------------------------------------------------------------
31 // constants
32 // ----------------------------------------------------------------------------
33
34
35 //-----------------------------------------------------------------------------
36 // internal classes
37 //-----------------------------------------------------------------------------
38
39 class WXDLLEXPORT wxListHeaderData;
40 class WXDLLEXPORT wxListItemData;
41
42 class WXDLLEXPORT wxListHeaderWindow;
43 class WXDLLEXPORT wxListMainWindow;
44
45 class WXDLLEXPORT wxListRenameTimer;
46 class WXDLLEXPORT wxListTextCtrl;
47
48 //-----------------------------------------------------------------------------
49 // wxListCtrl
50 //-----------------------------------------------------------------------------
51
52 class WXDLLEXPORT wxGenericListCtrl: public wxControl
53 {
54 public:
55
56 wxGenericListCtrl();
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)
64 {
65 Create(parent, winid, pos, size, style, validator, name);
66 }
67 virtual ~wxGenericListCtrl();
68
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);
76
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;
83
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;
112
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
121
122 void ClearAll();
123 bool DeleteItem( long item );
124 bool DeleteAllItems();
125 bool DeleteAllColumns();
126 bool DeleteColumn( int col );
127
128 void SetItemCount(long count);
129
130 wxTextCtrl *EditLabel(long item,
131 wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl));
132 wxTextCtrl* GetEditControl() const;
133 void Edit( long item ) { EditLabel(item); }
134
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(); }
152
153 // are we in report mode?
154 bool InReportView() const { return HasFlag(wxLC_REPORT); }
155
156 // are we in virtual report mode?
157 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL); }
158
159 // do we have a header window?
160 bool HasHeader() const
161 { return InReportView() && !HasFlag(wxLC_NO_HEADER); }
162
163 // refresh items selectively (only useful for virtual list controls)
164 void RefreshItem(long item);
165 void RefreshItems(long itemFrom, long itemTo);
166
167 #if WXWIN_COMPATIBILITY_2_6
168 // obsolete, don't use
169 wxDEPRECATED( int GetItemSpacing( bool isSmall ) const );
170 #endif // WXWIN_COMPATIBILITY_2_6
171
172 virtual wxVisualAttributes GetDefaultAttributes() const
173 {
174 return GetClassDefaultAttributes(GetWindowVariant());
175 }
176
177 static wxVisualAttributes
178 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
179
180 // implementation only from now on
181 // -------------------------------
182
183 void OnInternalIdle( );
184 void OnSize( wxSizeEvent &event );
185
186 // We have to hand down a few functions
187 virtual void Refresh(bool eraseBackground = true,
188 const wxRect *rect = NULL);
189
190 virtual void Freeze();
191 virtual void Thaw();
192
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 );
199
200 #if wxUSE_DRAG_AND_DROP
201 virtual void SetDropTarget( wxDropTarget *dropTarget );
202 virtual wxDropTarget *GetDropTarget() const;
203 #endif
204
205 virtual bool ShouldInheritColours() const { return false; }
206 virtual void SetFocus();
207
208 // implementation
209 // --------------
210
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;
220
221 protected:
222 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
223
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;
228
229 virtual wxSize DoGetBestSize() const;
230
231 // return the text for the given column of the given item
232 virtual wxString OnGetItemText(long item, long column) const;
233
234 // return the icon for the given item. In report view, OnGetItemImage will
235 // only be called for the first column. See OnGetItemColumnImage for
236 // details.
237 virtual int OnGetItemImage(long item) const;
238
239 // return the icon for the given item and column.
240 virtual int OnGetItemColumnImage(long item, long column) const;
241
242 // return the attribute for the item (may return NULL if none)
243 virtual wxListItemAttr *OnGetItemAttr(long item) const;
244
245 // it calls our OnGetXXX() functions
246 friend class WXDLLEXPORT wxListMainWindow;
247
248 private:
249 // create the header window
250 void CreateHeaderWindow();
251
252 // calculate and set height of the header
253 void CalculateAndSetHeaderHeight();
254
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);
258
259 DECLARE_EVENT_TABLE()
260 DECLARE_DYNAMIC_CLASS(wxGenericListCtrl)
261 };
262
263 #if (!defined(__WXMSW__) || defined(__WXUNIVERSAL__)) && !defined(__WXMAC__)
264 /*
265 * wxListCtrl has to be a real class or we have problems with
266 * the run-time information.
267 */
268
269 class WXDLLEXPORT wxListCtrl: public wxGenericListCtrl
270 {
271 DECLARE_DYNAMIC_CLASS(wxListCtrl)
272
273 public:
274 wxListCtrl() {}
275
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)
283 {
284 }
285
286 };
287 #endif // !__WXMSW__ || __WXUNIVERSAL__
288
289 #endif // __LISTCTRLH_G__