]>
Commit | Line | Data |
---|---|---|
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 | int GetSelectedItemCount() const; | |
122 | wxColour GetTextColour() const; | |
123 | void SetTextColour(const wxColour& col); | |
124 | long GetTopItem() const; | |
125 | ||
126 | void SetSingleStyle( long style, bool add = true ) ; | |
127 | void SetWindowStyleFlag( long style ); | |
128 | void RecreateWindow() {} | |
129 | long GetNextItem( long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE ) const; | |
130 | wxImageListType *GetImageList( int which ) const; | |
131 | void SetImageList( wxImageListType *imageList, int which ); | |
132 | void AssignImageList( wxImageListType *imageList, int which ); | |
133 | bool Arrange( int flag = wxLIST_ALIGN_DEFAULT ); // always wxLIST_ALIGN_LEFT in wxGLC | |
134 | ||
135 | void ClearAll(); | |
136 | bool DeleteItem( long item ); | |
137 | bool DeleteAllItems(); | |
138 | bool DeleteAllColumns(); | |
139 | bool DeleteColumn( int col ); | |
140 | ||
141 | void SetItemCount(long count); | |
142 | ||
143 | void EditLabel( long item ) { Edit(item); } | |
144 | void Edit( long item ); | |
145 | ||
146 | bool EnsureVisible( long item ); | |
147 | long FindItem( long start, const wxString& str, bool partial = false ); | |
148 | long FindItem( long start, wxUIntPtr data ); | |
149 | long FindItem( long start, const wxPoint& pt, int direction ); // not supported in wxGLC | |
150 | long HitTest( const wxPoint& point, int& flags); | |
151 | long InsertItem(wxListItem& info); | |
152 | long InsertItem( long index, const wxString& label ); | |
153 | long InsertItem( long index, int imageIndex ); | |
154 | long InsertItem( long index, const wxString& label, int imageIndex ); | |
155 | long InsertColumn( long col, wxListItem& info ); | |
156 | long InsertColumn( long col, const wxString& heading, | |
157 | int format = wxLIST_FORMAT_LEFT, int width = -1 ); | |
158 | bool ScrollList( int dx, int dy ); | |
159 | bool SortItems( wxListCtrlCompare fn, long data ); | |
160 | bool Update( long item ); | |
161 | ||
162 | // are we in report mode? | |
163 | bool InReportView() const { return HasFlag(wxLC_REPORT); } | |
164 | ||
165 | // are we in virtual report mode? | |
166 | bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL); } | |
167 | ||
168 | // do we have a header window? | |
169 | bool HasHeader() const | |
170 | { return InReportView() && !HasFlag(wxLC_NO_HEADER); } | |
171 | ||
172 | // refresh items selectively (only useful for virtual list controls) | |
173 | void RefreshItem(long item); | |
174 | void RefreshItems(long itemFrom, long itemTo); | |
175 | ||
176 | // obsolete, don't use | |
177 | wxDEPRECATED( int GetItemSpacing( bool isSmall ) const ); | |
178 | ||
179 | ||
180 | virtual wxVisualAttributes GetDefaultAttributes() const | |
181 | { | |
182 | return GetClassDefaultAttributes(GetWindowVariant()); | |
183 | } | |
184 | ||
185 | static wxVisualAttributes | |
186 | GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); | |
187 | ||
188 | // implementation only from now on | |
189 | // ------------------------------- | |
190 | ||
191 | void OnInternalIdle( ); | |
192 | void OnSize( wxSizeEvent &event ); | |
193 | ||
194 | // We have to hand down a few functions | |
195 | virtual void Refresh(bool eraseBackground = true, | |
196 | const wxRect *rect = NULL); | |
197 | ||
198 | virtual void Freeze(); | |
199 | virtual void Thaw(); | |
200 | ||
201 | virtual bool SetBackgroundColour( const wxColour &colour ); | |
202 | virtual bool SetForegroundColour( const wxColour &colour ); | |
203 | virtual wxColour GetBackgroundColour() const; | |
204 | virtual wxColour GetForegroundColour() const; | |
205 | virtual bool SetFont( const wxFont &font ); | |
206 | virtual bool SetCursor( const wxCursor &cursor ); | |
207 | ||
208 | #if wxUSE_DRAG_AND_DROP | |
209 | virtual void SetDropTarget( wxDropTarget *dropTarget ); | |
210 | virtual wxDropTarget *GetDropTarget() const; | |
211 | #endif | |
212 | ||
213 | virtual bool DoPopupMenu( wxMenu *menu, int x, int y ); | |
214 | ||
215 | virtual bool ShouldInheritColours() const { return false; } | |
216 | virtual void SetFocus(); | |
217 | ||
218 | virtual wxSize DoGetBestSize() const; | |
219 | ||
220 | // implementation | |
221 | // -------------- | |
222 | ||
223 | wxImageListType *m_imageListNormal; | |
224 | wxImageListType *m_imageListSmall; | |
225 | wxImageListType *m_imageListState; // what's that ? | |
226 | bool m_ownsImageListNormal, | |
227 | m_ownsImageListSmall, | |
228 | m_ownsImageListState; | |
229 | wxListHeaderWindow *m_headerWin; | |
230 | wxListMainWindow *m_mainWin; | |
231 | wxCoord m_headerHeight; | |
232 | ||
233 | protected: | |
234 | // return the text for the given column of the given item | |
235 | virtual wxString OnGetItemText(long item, long column) const; | |
236 | ||
237 | // return the icon for the given item | |
238 | virtual int OnGetItemImage(long item) const; | |
239 | ||
240 | // return the attribute for the item (may return NULL if none) | |
241 | virtual wxListItemAttr *OnGetItemAttr(long item) const; | |
242 | ||
243 | // it calls our OnGetXXX() functions | |
244 | friend class WXDLLEXPORT wxListMainWindow; | |
245 | ||
246 | private: | |
247 | // Virtual function hiding supression | |
248 | virtual void Update() { wxWindow::Update(); } | |
249 | ||
250 | // create the header window | |
251 | void CreateHeaderWindow(); | |
252 | ||
253 | // calculate and set height of the header | |
254 | void CalculateAndSetHeaderHeight(); | |
255 | ||
256 | // reposition the header and the main window in the report view depending | |
257 | // on whether it should be shown or not | |
258 | void ResizeReportView(bool showHeader); | |
259 | ||
260 | DECLARE_EVENT_TABLE() | |
261 | DECLARE_DYNAMIC_CLASS(wxGenericListCtrl) | |
262 | }; | |
263 | ||
264 | #if !defined(__WXMSW__) || defined(__WXUNIVERSAL__) | |
265 | /* | |
266 | * wxListCtrl has to be a real class or we have problems with | |
267 | * the run-time information. | |
268 | */ | |
269 | ||
270 | class WXDLLEXPORT wxListCtrl: public wxGenericListCtrl | |
271 | { | |
272 | DECLARE_DYNAMIC_CLASS(wxListCtrl) | |
273 | ||
274 | public: | |
275 | wxListCtrl() {} | |
276 | ||
277 | wxListCtrl(wxWindow *parent, wxWindowID winid = wxID_ANY, | |
278 | const wxPoint& pos = wxDefaultPosition, | |
279 | const wxSize& size = wxDefaultSize, | |
280 | long style = wxLC_ICON, | |
281 | const wxValidator &validator = wxDefaultValidator, | |
282 | const wxString &name = wxListCtrlNameStr) | |
283 | : wxGenericListCtrl(parent, winid, pos, size, style, validator, name) | |
284 | { | |
285 | } | |
286 | }; | |
287 | #endif // !__WXMSW__ || __WXUNIVERSAL__ | |
288 | ||
289 | #endif // __LISTCTRLH_G__ |