]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
bdc72a22 | 2 | // Name: wx/generic/listctrl.h |
c801d85f KB |
3 | // Purpose: Generic list control |
4 | // Author: Robert Roebling | |
5 | // Created: 01/02/97 | |
6 | // Id: | |
371a5b4e | 7 | // Copyright: (c) 1998 Robert Roebling and Julian Smart |
bdc72a22 | 8 | // Licence: wxWindows licence |
c801d85f KB |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
11 | #ifndef __LISTCTRLH_G__ | |
12 | #define __LISTCTRLH_G__ | |
13 | ||
12028905 | 14 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
0d3820b3 | 15 | #pragma interface "listctrl.h" |
c801d85f KB |
16 | #endif |
17 | ||
18 | #include "wx/defs.h" | |
19 | #include "wx/object.h" | |
9cb07953 | 20 | #include "wx/generic/imaglist.h" |
9cb07953 | 21 | |
c801d85f KB |
22 | #include "wx/control.h" |
23 | #include "wx/timer.h" | |
24 | #include "wx/dcclient.h" | |
25 | #include "wx/scrolwin.h" | |
26 | #include "wx/settings.h" | |
e81a301c | 27 | #include "wx/listbase.h" |
c801d85f | 28 | |
1e6d9499 JS |
29 | #if wxUSE_DRAG_AND_DROP |
30 | class WXDLLEXPORT wxDropTarget; | |
31 | #endif | |
32 | ||
c801d85f KB |
33 | //----------------------------------------------------------------------------- |
34 | // classes | |
35 | //----------------------------------------------------------------------------- | |
36 | ||
1e6d9499 JS |
37 | class WXDLLEXPORT wxListItem; |
38 | class WXDLLEXPORT wxListEvent; | |
f9ceab7c JS |
39 | |
40 | #if !defined(__WXMSW__) || defined(__WIN16__) || defined(__WXUNIVERSAL__) | |
1e6d9499 | 41 | class WXDLLEXPORT wxListCtrl; |
f9ceab7c JS |
42 | #define wxImageListType wxImageList |
43 | #else | |
44 | #define wxImageListType wxGenericImageList | |
45 | #endif | |
c801d85f KB |
46 | |
47 | //----------------------------------------------------------------------------- | |
48 | // internal classes | |
49 | //----------------------------------------------------------------------------- | |
50 | ||
1e6d9499 JS |
51 | class WXDLLEXPORT wxListHeaderData; |
52 | class WXDLLEXPORT wxListItemData; | |
53 | class WXDLLEXPORT wxListLineData; | |
c801d85f | 54 | |
1e6d9499 JS |
55 | class WXDLLEXPORT wxListHeaderWindow; |
56 | class WXDLLEXPORT wxListMainWindow; | |
c801d85f | 57 | |
1e6d9499 | 58 | class WXDLLEXPORT wxListRenameTimer; |
e179bd65 | 59 | class WXDLLEXPORT wxListTextCtrl; |
c801d85f | 60 | |
c801d85f KB |
61 | //----------------------------------------------------------------------------- |
62 | // wxListCtrl | |
63 | //----------------------------------------------------------------------------- | |
64 | ||
3cd94a0d | 65 | class WXDLLEXPORT wxGenericListCtrl: public wxControl |
c801d85f | 66 | { |
b16088bf | 67 | public: |
3cd94a0d JS |
68 | wxGenericListCtrl(); |
69 | wxGenericListCtrl( wxWindow *parent, | |
921176c5 | 70 | wxWindowID winid = -1, |
674ac8b9 VZ |
71 | const wxPoint &pos = wxDefaultPosition, |
72 | const wxSize &size = wxDefaultSize, | |
73 | long style = wxLC_ICON, | |
74 | const wxValidator& validator = wxDefaultValidator, | |
6463b9f5 JS |
75 | const wxString &name = wxT("listctrl") ) |
76 | { | |
77 | Create(parent, winid, pos, size, style, validator, name); | |
78 | } | |
3cd94a0d | 79 | ~wxGenericListCtrl(); |
29149a64 | 80 | |
674ac8b9 | 81 | bool Create( wxWindow *parent, |
921176c5 | 82 | wxWindowID winid = -1, |
674ac8b9 VZ |
83 | const wxPoint &pos = wxDefaultPosition, |
84 | const wxSize &size = wxDefaultSize, | |
85 | long style = wxLC_ICON, | |
86 | const wxValidator& validator = wxDefaultValidator, | |
2b5f62a0 | 87 | const wxString &name = wxT("listctrl") ); |
b16088bf | 88 | |
e487524e | 89 | bool GetColumn( int col, wxListItem& item ) const; |
debe6624 | 90 | bool SetColumn( int col, wxListItem& item ); |
e487524e | 91 | int GetColumnWidth( int col ) const; |
debe6624 | 92 | bool SetColumnWidth( int col, int width); |
e179bd65 | 93 | int GetCountPerPage() const; // not the same in wxGLC as in Windows, I think |
11ebea16 | 94 | wxRect GetViewRect() const; |
b16088bf | 95 | |
e487524e | 96 | bool GetItem( wxListItem& info ) const; |
c801d85f | 97 | bool SetItem( wxListItem& info ) ; |
debe6624 | 98 | long SetItem( long index, int col, const wxString& label, int imageId = -1 ); |
e487524e | 99 | int GetItemState( long item, long stateMask ) const; |
debe6624 JS |
100 | bool SetItemState( long item, long state, long stateMask); |
101 | bool SetItemImage( long item, int image, int selImage); | |
e487524e | 102 | wxString GetItemText( long item ) const; |
debe6624 | 103 | void SetItemText( long item, const wxString& str ); |
e487524e | 104 | long GetItemData( long item ) const; |
debe6624 | 105 | bool SetItemData( long item, long data ); |
0a240683 | 106 | bool GetItemRect( long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS ) const; |
e487524e | 107 | bool GetItemPosition( long item, wxPoint& pos ) const; |
debe6624 | 108 | bool SetItemPosition( long item, const wxPoint& pos ); // not supported in wxGLC |
e179bd65 RR |
109 | int GetItemCount() const; |
110 | int GetColumnCount() const; | |
33d0b396 | 111 | void SetItemSpacing( int spacing, bool isSmall = FALSE ); |
5db8d758 | 112 | wxSize GetItemSpacing() const; |
5b98eb2f RL |
113 | void SetItemTextColour( long item, const wxColour& col); |
114 | wxColour GetItemTextColour( long item ) const; | |
115 | void SetItemBackgroundColour( long item, const wxColour &col); | |
116 | wxColour GetItemBackgroundColour( long item ) const; | |
e179bd65 | 117 | int GetSelectedItemCount() const; |
0530737d VZ |
118 | wxColour GetTextColour() const; |
119 | void SetTextColour(const wxColour& col); | |
e179bd65 | 120 | long GetTopItem() const; |
b16088bf | 121 | |
debe6624 | 122 | void SetSingleStyle( long style, bool add = TRUE ) ; |
e179bd65 RR |
123 | void SetWindowStyleFlag( long style ); |
124 | void RecreateWindow() {} | |
125 | long GetNextItem( long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE ) const; | |
f9ceab7c JS |
126 | wxImageListType *GetImageList( int which ) const; |
127 | void SetImageList( wxImageListType *imageList, int which ); | |
128 | void AssignImageList( wxImageListType *imageList, int which ); | |
debe6624 | 129 | bool Arrange( int flag = wxLIST_ALIGN_DEFAULT ); // always wxLIST_ALIGN_LEFT in wxGLC |
57c4d796 | 130 | |
4f22cf8d | 131 | void ClearAll(); |
debe6624 | 132 | bool DeleteItem( long item ); |
e179bd65 RR |
133 | bool DeleteAllItems(); |
134 | bool DeleteAllColumns(); | |
debe6624 | 135 | bool DeleteColumn( int col ); |
57c4d796 | 136 | |
2c1f73ee VZ |
137 | void SetItemCount(long count); |
138 | ||
e179bd65 RR |
139 | void EditLabel( long item ) { Edit(item); } |
140 | void Edit( long item ); | |
57c4d796 | 141 | |
debe6624 | 142 | bool EnsureVisible( long item ); |
e179bd65 RR |
143 | long FindItem( long start, const wxString& str, bool partial = FALSE ); |
144 | long FindItem( long start, long data ); | |
145 | long FindItem( long start, const wxPoint& pt, int direction ); // not supported in wxGLC | |
146 | long HitTest( const wxPoint& point, int& flags); | |
c801d85f | 147 | long InsertItem(wxListItem& info); |
e179bd65 RR |
148 | long InsertItem( long index, const wxString& label ); |
149 | long InsertItem( long index, int imageIndex ); | |
150 | long InsertItem( long index, const wxString& label, int imageIndex ); | |
151 | long InsertColumn( long col, wxListItem& info ); | |
2f1e3c46 VZ |
152 | long InsertColumn( long col, const wxString& heading, |
153 | int format = wxLIST_FORMAT_LEFT, int width = -1 ); | |
e179bd65 RR |
154 | bool ScrollList( int dx, int dy ); |
155 | bool SortItems( wxListCtrlCompare fn, long data ); | |
156 | bool Update( long item ); | |
29149a64 | 157 | |
b5d43d1d VZ |
158 | // are we in report mode? |
159 | bool InReportView() const { return HasFlag(wxLC_REPORT); } | |
160 | ||
161 | // are we in virtual report mode? | |
162 | bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL); } | |
163 | ||
164 | // do we have a header window? | |
165 | bool HasHeader() const | |
166 | { return InReportView() && !HasFlag(wxLC_NO_HEADER); } | |
2c1f73ee | 167 | |
1a6cb56f VZ |
168 | // refresh items selectively (only useful for virtual list controls) |
169 | void RefreshItem(long item); | |
170 | void RefreshItems(long itemFrom, long itemTo); | |
171 | ||
5db8d758 VZ |
172 | // obsolete, don't use |
173 | wxDEPRECATED( int GetItemSpacing( bool isSmall ) const ); | |
174 | ||
175 | ||
1a6cb56f VZ |
176 | // implementation only from now on |
177 | // ------------------------------- | |
178 | ||
5180055b | 179 | void OnInternalIdle( ); |
b16088bf | 180 | void OnSize( wxSizeEvent &event ); |
57c4d796 | 181 | |
77e7a1dc | 182 | // We have to hand down a few functions |
2f1e3c46 VZ |
183 | virtual void Refresh(bool eraseBackground = TRUE, |
184 | const wxRect *rect = NULL); | |
57c4d796 | 185 | |
c5c528fc VZ |
186 | virtual void Freeze(); |
187 | virtual void Thaw(); | |
188 | ||
189 | virtual bool SetBackgroundColour( const wxColour &colour ); | |
190 | virtual bool SetForegroundColour( const wxColour &colour ); | |
191 | virtual wxColour GetBackgroundColour() const; | |
192 | virtual wxColour GetForegroundColour() const; | |
193 | virtual bool SetFont( const wxFont &font ); | |
194 | virtual bool SetCursor( const wxCursor &cursor ); | |
57c4d796 | 195 | |
1e6d9499 | 196 | #if wxUSE_DRAG_AND_DROP |
c5c528fc VZ |
197 | virtual void SetDropTarget( wxDropTarget *dropTarget ); |
198 | virtual wxDropTarget *GetDropTarget() const; | |
1e6d9499 JS |
199 | #endif |
200 | ||
c5c528fc VZ |
201 | virtual bool DoPopupMenu( wxMenu *menu, int x, int y ); |
202 | ||
d4864e97 | 203 | virtual bool ShouldInheritColours() const { return false; } |
c5c528fc | 204 | virtual void SetFocus(); |
c801d85f | 205 | |
b16088bf RR |
206 | // implementation |
207 | // -------------- | |
57c4d796 | 208 | |
f9ceab7c JS |
209 | wxImageListType *m_imageListNormal; |
210 | wxImageListType *m_imageListSmall; | |
211 | wxImageListType *m_imageListState; // what's that ? | |
29149a64 | 212 | bool m_ownsImageListNormal, |
2e12c11a VS |
213 | m_ownsImageListSmall, |
214 | m_ownsImageListState; | |
c801d85f KB |
215 | wxListHeaderWindow *m_headerWin; |
216 | wxListMainWindow *m_mainWin; | |
f8252483 | 217 | wxCoord m_headerHeight; |
a3622daa | 218 | |
2c1f73ee VZ |
219 | protected: |
220 | // return the text for the given column of the given item | |
221 | virtual wxString OnGetItemText(long item, long column) const; | |
222 | ||
223 | // return the icon for the given item | |
224 | virtual int OnGetItemImage(long item) const; | |
225 | ||
6c02c329 VZ |
226 | // return the attribute for the item (may return NULL if none) |
227 | virtual wxListItemAttr *OnGetItemAttr(long item) const; | |
228 | ||
2c1f73ee | 229 | // it calls our OnGetXXX() functions |
ad08ef44 | 230 | friend class WXDLLEXPORT wxListMainWindow; |
2c1f73ee | 231 | |
b16088bf | 232 | private: |
210a651b | 233 | // Virtual function hiding supression |
8ac7c509 | 234 | virtual void Update() { wxWindow::Update(); } |
210a651b | 235 | |
cf1dfa6b VZ |
236 | // create the header window |
237 | void CreateHeaderWindow(); | |
238 | ||
f8252483 JS |
239 | // calculate and set height of the header |
240 | void CalculateAndSetHeaderHeight(); | |
241 | ||
c0f8674c VZ |
242 | // reposition the header and the main window in the report view depending |
243 | // on whether it should be shown or not | |
244 | void ResizeReportView(bool showHeader); | |
245 | ||
b16088bf | 246 | DECLARE_EVENT_TABLE() |
3cd94a0d | 247 | DECLARE_DYNAMIC_CLASS(wxGenericListCtrl); |
c801d85f KB |
248 | }; |
249 | ||
b31989e2 JS |
250 | #if !defined(__WXMSW__) || defined(__WIN16__) || defined(__WXUNIVERSAL__) |
251 | /* | |
252 | * wxListCtrl has to be a real class or we have problems with | |
253 | * the run-time information. | |
254 | */ | |
c801d85f | 255 | |
b31989e2 JS |
256 | class WXDLLEXPORT wxListCtrl: public wxGenericListCtrl |
257 | { | |
258 | DECLARE_DYNAMIC_CLASS(wxListCtrl) | |
259 | ||
260 | public: | |
6463b9f5 | 261 | wxListCtrl() {} |
b31989e2 | 262 | |
921176c5 | 263 | wxListCtrl(wxWindow *parent, wxWindowID winid = -1, |
b31989e2 JS |
264 | const wxPoint& pos = wxDefaultPosition, |
265 | const wxSize& size = wxDefaultSize, | |
266 | long style = wxLC_ICON, | |
267 | const wxValidator &validator = wxDefaultValidator, | |
6463b9f5 JS |
268 | const wxString &name = wxT("listctrl") ) |
269 | : wxGenericListCtrl(parent, winid, pos, size, style, validator, name) | |
270 | { | |
271 | } | |
b31989e2 JS |
272 | }; |
273 | #endif // !__WXMSW__ || __WIN16__ || __WXUNIVERSAL__ | |
5b98eb2f | 274 | |
b31989e2 | 275 | #endif // __LISTCTRLH_G__ |