]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/listctrl.h
add missing wxUSE_DRAG_AND_DROP checks
[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_FWD_CORE wxImageList;
17
18 #if wxUSE_DRAG_AND_DROP
19 class WXDLLIMPEXP_FWD_CORE wxDropTarget;
20 #endif
21
22 // ----------------------------------------------------------------------------
23 // constants
24 // ----------------------------------------------------------------------------
25
26
27 //-----------------------------------------------------------------------------
28 // internal classes
29 //-----------------------------------------------------------------------------
30
31 class WXDLLIMPEXP_FWD_CORE wxListHeaderWindow;
32 class WXDLLIMPEXP_FWD_CORE wxListMainWindow;
33
34 //-----------------------------------------------------------------------------
35 // wxListCtrl
36 //-----------------------------------------------------------------------------
37
38 class WXDLLIMPEXP_CORE wxGenericListCtrl: public wxControl,
39 public wxScrollHelper
40 {
41 public:
42
43 wxGenericListCtrl() : wxScrollHelper(this)
44 {
45 Init();
46 }
47
48 wxGenericListCtrl( wxWindow *parent,
49 wxWindowID winid = wxID_ANY,
50 const wxPoint &pos = wxDefaultPosition,
51 const wxSize &size = wxDefaultSize,
52 long style = wxLC_ICON,
53 const wxValidator& validator = wxDefaultValidator,
54 const wxString &name = wxListCtrlNameStr)
55 : wxScrollHelper(this)
56 {
57 Create(parent, winid, pos, size, style, validator, name);
58 }
59
60 virtual ~wxGenericListCtrl();
61
62 void Init();
63
64 bool Create( wxWindow *parent,
65 wxWindowID winid = wxID_ANY,
66 const wxPoint &pos = wxDefaultPosition,
67 const wxSize &size = wxDefaultSize,
68 long style = wxLC_ICON,
69 const wxValidator& validator = wxDefaultValidator,
70 const wxString &name = wxListCtrlNameStr);
71
72 bool GetColumn( int col, wxListItem& item ) const;
73 bool SetColumn( int col, wxListItem& item );
74 int GetColumnWidth( int col ) const;
75 bool SetColumnWidth( int col, int width);
76 int GetCountPerPage() const; // not the same in wxGLC as in Windows, I think
77 wxRect GetViewRect() const;
78
79 bool GetItem( wxListItem& info ) const;
80 bool SetItem( wxListItem& info ) ;
81 long SetItem( long index, int col, const wxString& label, int imageId = -1 );
82 int GetItemState( long item, long stateMask ) const;
83 bool SetItemState( long item, long state, long stateMask);
84 bool SetItemImage( long item, int image, int selImage = -1 );
85 bool SetItemColumnImage( long item, long column, int image );
86 wxString GetItemText( long item ) const;
87 void SetItemText( long item, const wxString& str );
88 wxUIntPtr GetItemData( long item ) const;
89 bool SetItemPtrData(long item, wxUIntPtr data);
90 bool SetItemData(long item, long data) { return SetItemPtrData(item, data); }
91 bool GetItemRect( long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS ) const;
92 bool GetSubItemRect( long item, long subItem, wxRect& rect, int code = wxLIST_RECT_BOUNDS ) const;
93 bool GetItemPosition( long item, wxPoint& pos ) const;
94 bool SetItemPosition( long item, const wxPoint& pos ); // not supported in wxGLC
95 int GetItemCount() const;
96 int GetColumnCount() const;
97 void SetItemSpacing( int spacing, bool isSmall = false );
98 wxSize GetItemSpacing() const;
99 void SetItemTextColour( long item, const wxColour& col);
100 wxColour GetItemTextColour( long item ) const;
101 void SetItemBackgroundColour( long item, const wxColour &col);
102 wxColour GetItemBackgroundColour( long item ) const;
103 void SetItemFont( long item, const wxFont &f);
104 wxFont GetItemFont( long item ) const;
105 int GetSelectedItemCount() const;
106 wxColour GetTextColour() const;
107 void SetTextColour(const wxColour& col);
108 long GetTopItem() const;
109
110 void SetSingleStyle( long style, bool add = true ) ;
111 void SetWindowStyleFlag( long style );
112 void RecreateWindow() {}
113 long GetNextItem( long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE ) const;
114 wxImageList *GetImageList( int which ) const;
115 void SetImageList( wxImageList *imageList, int which );
116 void AssignImageList( wxImageList *imageList, int which );
117 bool Arrange( int flag = wxLIST_ALIGN_DEFAULT ); // always wxLIST_ALIGN_LEFT in wxGLC
118
119 void ClearAll();
120 bool DeleteItem( long item );
121 bool DeleteAllItems();
122 bool DeleteAllColumns();
123 bool DeleteColumn( int col );
124
125 void SetItemCount(long count);
126
127 wxTextCtrl *EditLabel(long item,
128 wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl));
129 wxTextCtrl* GetEditControl() const;
130 void Edit( long item ) { EditLabel(item); }
131
132 bool EnsureVisible( long item );
133 long FindItem( long start, const wxString& str, bool partial = false );
134 long FindItem( long start, wxUIntPtr data );
135 long FindItem( long start, const wxPoint& pt, int direction ); // not supported in wxGLC
136 long HitTest( const wxPoint& point, int& flags, long *pSubItem = NULL ) const;
137 long InsertItem(wxListItem& info);
138 long InsertItem( long index, const wxString& label );
139 long InsertItem( long index, int imageIndex );
140 long InsertItem( long index, const wxString& label, int imageIndex );
141 long InsertColumn( long col, wxListItem& info );
142 long InsertColumn( long col, const wxString& heading,
143 int format = wxLIST_FORMAT_LEFT, int width = -1 );
144 bool ScrollList( int dx, int dy );
145 bool SortItems( wxListCtrlCompare fn, long data );
146 bool Update( long item );
147 // Must provide overload to avoid hiding it (and warnings about it)
148 virtual void Update() { wxControl::Update(); }
149
150 // are we in report mode?
151 bool InReportView() const { return HasFlag(wxLC_REPORT); }
152
153 // are we in virtual report mode?
154 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL); }
155
156 // do we have a header window?
157 bool HasHeader() const
158 { return InReportView() && !HasFlag(wxLC_NO_HEADER); }
159
160 // refresh items selectively (only useful for virtual list controls)
161 void RefreshItem(long item);
162 void RefreshItems(long itemFrom, long itemTo);
163
164 #if WXWIN_COMPATIBILITY_2_6
165 // obsolete, don't use
166 wxDEPRECATED( int GetItemSpacing( bool isSmall ) const );
167 #endif // WXWIN_COMPATIBILITY_2_6
168
169 virtual wxVisualAttributes GetDefaultAttributes() const
170 {
171 return GetClassDefaultAttributes(GetWindowVariant());
172 }
173
174 static wxVisualAttributes
175 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
176
177 // implementation only from now on
178 // -------------------------------
179
180 void OnInternalIdle( );
181
182 // We have to hand down a few functions
183 virtual void Refresh(bool eraseBackground = true,
184 const wxRect *rect = NULL);
185
186 virtual bool SetBackgroundColour( const wxColour &colour );
187 virtual bool SetForegroundColour( const wxColour &colour );
188 virtual wxColour GetBackgroundColour() const;
189 virtual wxColour GetForegroundColour() const;
190 virtual bool SetFont( const wxFont &font );
191 virtual bool SetCursor( const wxCursor &cursor );
192
193 #if wxUSE_DRAG_AND_DROP
194 virtual void SetDropTarget( wxDropTarget *dropTarget );
195 virtual wxDropTarget *GetDropTarget() const;
196 #endif
197
198 virtual bool ShouldInheritColours() const { return false; }
199 virtual void SetFocus();
200
201 // implementation
202 // --------------
203
204 wxImageList *m_imageListNormal;
205 wxImageList *m_imageListSmall;
206 wxImageList *m_imageListState; // what's that ?
207 bool m_ownsImageListNormal,
208 m_ownsImageListSmall,
209 m_ownsImageListState;
210 wxListHeaderWindow *m_headerWin;
211 wxListMainWindow *m_mainWin;
212 wxCoord m_headerHeight;
213
214 protected:
215 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
216
217 // take into account the coordinates difference between the container
218 // window and the list control window itself here
219 virtual void DoClientToScreen( int *x, int *y ) const;
220 virtual void DoScreenToClient( int *x, int *y ) const;
221
222 virtual wxSize DoGetBestSize() const;
223
224 // return the text for the given column of the given item
225 virtual wxString OnGetItemText(long item, long column) const;
226
227 // return the icon for the given item. In report view, OnGetItemImage will
228 // only be called for the first column. See OnGetItemColumnImage for
229 // details.
230 virtual int OnGetItemImage(long item) const;
231
232 // return the icon for the given item and column.
233 virtual int OnGetItemColumnImage(long item, long column) const;
234
235 // return the attribute for the item (may return NULL if none)
236 virtual wxListItemAttr *OnGetItemAttr(long item) const;
237
238 // it calls our OnGetXXX() functions
239 friend class WXDLLIMPEXP_FWD_CORE wxListMainWindow;
240
241 virtual wxBorder GetDefaultBorder() const;
242
243 private:
244 void CreateOrDestroyHeaderWindowAsNeeded();
245 void OnScroll( wxScrollWinEvent& event );
246 void OnSize( wxSizeEvent &event );
247 virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size);
248
249 // we need to return a special WM_GETDLGCODE value to process just the
250 // arrows but let the other navigation characters through
251 #ifdef __WXMSW__
252 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
253 #endif // __WXMSW__
254
255 WX_FORWARD_TO_SCROLL_HELPER()
256
257 DECLARE_EVENT_TABLE()
258 DECLARE_DYNAMIC_CLASS(wxGenericListCtrl)
259 };
260
261 #if (!defined(__WXMSW__) || defined(__WXUNIVERSAL__)) && (!(defined(__WXMAC__) && wxOSX_USE_CARBON) || defined(__WXUNIVERSAL__ ))
262 /*
263 * wxListCtrl has to be a real class or we have problems with
264 * the run-time information.
265 */
266
267 class WXDLLIMPEXP_CORE wxListCtrl: public wxGenericListCtrl
268 {
269 DECLARE_DYNAMIC_CLASS(wxListCtrl)
270
271 public:
272 wxListCtrl() {}
273
274 wxListCtrl(wxWindow *parent, wxWindowID winid = wxID_ANY,
275 const wxPoint& pos = wxDefaultPosition,
276 const wxSize& size = wxDefaultSize,
277 long style = wxLC_ICON,
278 const wxValidator &validator = wxDefaultValidator,
279 const wxString &name = wxListCtrlNameStr)
280 : wxGenericListCtrl(parent, winid, pos, size, style, validator, name)
281 {
282 }
283
284 };
285 #endif // !__WXMSW__ || __WXUNIVERSAL__
286
287 #endif // _WX_GENERIC_LISTCTRL_H_