]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/listctrl.h
added wxMOTIF_STR() macro casting away string literal constness for use with Motif...
[wxWidgets.git] / include / wx / generic / listctrl.h
CommitLineData
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
52f2ad08 6// RCS-ID: $Id$
371a5b4e 7// Copyright: (c) 1998 Robert Roebling and Julian Smart
65571936 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"
ca135148
SC
20#ifdef __WXMAC__
21#include "wx/imaglist.h"
22#else
9cb07953 23#include "wx/generic/imaglist.h"
ca135148 24#endif
9cb07953 25
c801d85f
KB
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"
e81a301c 31#include "wx/listbase.h"
c801d85f 32
1e6d9499
JS
33#if wxUSE_DRAG_AND_DROP
34class WXDLLEXPORT wxDropTarget;
35#endif
36
c801d85f
KB
37//-----------------------------------------------------------------------------
38// classes
39//-----------------------------------------------------------------------------
40
1e6d9499
JS
41class WXDLLEXPORT wxListItem;
42class WXDLLEXPORT wxListEvent;
f9ceab7c 43
3a5bcc4d 44#if !defined(__WXMSW__) || defined(__WXUNIVERSAL__)
1e6d9499 45class WXDLLEXPORT wxListCtrl;
f9ceab7c
JS
46#define wxImageListType wxImageList
47#else
48#define wxImageListType wxGenericImageList
49#endif
c801d85f
KB
50
51//-----------------------------------------------------------------------------
52// internal classes
53//-----------------------------------------------------------------------------
54
1e6d9499
JS
55class WXDLLEXPORT wxListHeaderData;
56class WXDLLEXPORT wxListItemData;
57class WXDLLEXPORT wxListLineData;
c801d85f 58
1e6d9499
JS
59class WXDLLEXPORT wxListHeaderWindow;
60class WXDLLEXPORT wxListMainWindow;
c801d85f 61
1e6d9499 62class WXDLLEXPORT wxListRenameTimer;
e179bd65 63class WXDLLEXPORT wxListTextCtrl;
c801d85f 64
c801d85f
KB
65//-----------------------------------------------------------------------------
66// wxListCtrl
67//-----------------------------------------------------------------------------
68
3cd94a0d 69class WXDLLEXPORT wxGenericListCtrl: public wxControl
c801d85f 70{
b16088bf 71public:
3cd94a0d
JS
72 wxGenericListCtrl();
73 wxGenericListCtrl( wxWindow *parent,
ca65c044 74 wxWindowID winid = wxID_ANY,
674ac8b9
VZ
75 const wxPoint &pos = wxDefaultPosition,
76 const wxSize &size = wxDefaultSize,
77 long style = wxLC_ICON,
78 const wxValidator& validator = wxDefaultValidator,
52f2ad08 79 const wxString &name = wxListCtrlNameStr)
6463b9f5
JS
80 {
81 Create(parent, winid, pos, size, style, validator, name);
82 }
3cd94a0d 83 ~wxGenericListCtrl();
29149a64 84
674ac8b9 85 bool Create( wxWindow *parent,
ca65c044 86 wxWindowID winid = wxID_ANY,
674ac8b9
VZ
87 const wxPoint &pos = wxDefaultPosition,
88 const wxSize &size = wxDefaultSize,
89 long style = wxLC_ICON,
90 const wxValidator& validator = wxDefaultValidator,
52f2ad08 91 const wxString &name = wxListCtrlNameStr);
b16088bf 92
e487524e 93 bool GetColumn( int col, wxListItem& item ) const;
debe6624 94 bool SetColumn( int col, wxListItem& item );
e487524e 95 int GetColumnWidth( int col ) const;
debe6624 96 bool SetColumnWidth( int col, int width);
e179bd65 97 int GetCountPerPage() const; // not the same in wxGLC as in Windows, I think
11ebea16 98 wxRect GetViewRect() const;
b16088bf 99
e487524e 100 bool GetItem( wxListItem& info ) const;
c801d85f 101 bool SetItem( wxListItem& info ) ;
debe6624 102 long SetItem( long index, int col, const wxString& label, int imageId = -1 );
e487524e 103 int GetItemState( long item, long stateMask ) const;
debe6624 104 bool SetItemState( long item, long state, long stateMask);
aba3d35e 105 bool SetItemImage( long item, int image, int selImage = -1 );
e487524e 106 wxString GetItemText( long item ) const;
debe6624 107 void SetItemText( long item, const wxString& str );
81ce36aa 108 wxUIntPtr GetItemData( long item ) const;
debe6624 109 bool SetItemData( long item, long data );
0a240683 110 bool GetItemRect( long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS ) const;
e487524e 111 bool GetItemPosition( long item, wxPoint& pos ) const;
debe6624 112 bool SetItemPosition( long item, const wxPoint& pos ); // not supported in wxGLC
e179bd65
RR
113 int GetItemCount() const;
114 int GetColumnCount() const;
ca65c044 115 void SetItemSpacing( int spacing, bool isSmall = false );
5db8d758 116 wxSize GetItemSpacing() const;
5b98eb2f
RL
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;
35c2acd4
MW
121#if wxABI_VERSION >= 20602
122 void SetItemFont( long item, const wxFont &f);
123 wxFont GetItemFont( long item ) const;
124#endif
e179bd65 125 int GetSelectedItemCount() const;
0530737d
VZ
126 wxColour GetTextColour() const;
127 void SetTextColour(const wxColour& col);
e179bd65 128 long GetTopItem() const;
b16088bf 129
ca65c044 130 void SetSingleStyle( long style, bool add = true ) ;
e179bd65
RR
131 void SetWindowStyleFlag( long style );
132 void RecreateWindow() {}
133 long GetNextItem( long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE ) const;
f9ceab7c
JS
134 wxImageListType *GetImageList( int which ) const;
135 void SetImageList( wxImageListType *imageList, int which );
136 void AssignImageList( wxImageListType *imageList, int which );
debe6624 137 bool Arrange( int flag = wxLIST_ALIGN_DEFAULT ); // always wxLIST_ALIGN_LEFT in wxGLC
57c4d796 138
4f22cf8d 139 void ClearAll();
debe6624 140 bool DeleteItem( long item );
e179bd65
RR
141 bool DeleteAllItems();
142 bool DeleteAllColumns();
debe6624 143 bool DeleteColumn( int col );
57c4d796 144
2c1f73ee
VZ
145 void SetItemCount(long count);
146
e179bd65
RR
147 void EditLabel( long item ) { Edit(item); }
148 void Edit( long item );
57c4d796 149
debe6624 150 bool EnsureVisible( long item );
ca65c044 151 long FindItem( long start, const wxString& str, bool partial = false );
81ce36aa 152 long FindItem( long start, wxUIntPtr data );
e179bd65
RR
153 long FindItem( long start, const wxPoint& pt, int direction ); // not supported in wxGLC
154 long HitTest( const wxPoint& point, int& flags);
c801d85f 155 long InsertItem(wxListItem& info);
e179bd65
RR
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 );
2f1e3c46
VZ
160 long InsertColumn( long col, const wxString& heading,
161 int format = wxLIST_FORMAT_LEFT, int width = -1 );
e179bd65
RR
162 bool ScrollList( int dx, int dy );
163 bool SortItems( wxListCtrlCompare fn, long data );
164 bool Update( long item );
29149a64 165
b5d43d1d
VZ
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); }
2c1f73ee 175
1a6cb56f
VZ
176 // refresh items selectively (only useful for virtual list controls)
177 void RefreshItem(long item);
178 void RefreshItems(long itemFrom, long itemTo);
179
5db8d758
VZ
180 // obsolete, don't use
181 wxDEPRECATED( int GetItemSpacing( bool isSmall ) const );
182
183
35d4c967
RD
184 virtual wxVisualAttributes GetDefaultAttributes() const
185 {
186 return GetClassDefaultAttributes(GetWindowVariant());
187 }
188
189 static wxVisualAttributes
190 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
191
1a6cb56f
VZ
192 // implementation only from now on
193 // -------------------------------
194
5180055b 195 void OnInternalIdle( );
b16088bf 196 void OnSize( wxSizeEvent &event );
57c4d796 197
77e7a1dc 198 // We have to hand down a few functions
ca65c044 199 virtual void Refresh(bool eraseBackground = true,
2f1e3c46 200 const wxRect *rect = NULL);
57c4d796 201
c5c528fc
VZ
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 );
57c4d796 211
1e6d9499 212#if wxUSE_DRAG_AND_DROP
c5c528fc
VZ
213 virtual void SetDropTarget( wxDropTarget *dropTarget );
214 virtual wxDropTarget *GetDropTarget() const;
1e6d9499
JS
215#endif
216
c5c528fc
VZ
217 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
218
d4864e97 219 virtual bool ShouldInheritColours() const { return false; }
c5c528fc 220 virtual void SetFocus();
c801d85f 221
3872d96d 222 virtual wxSize DoGetBestSize() const;
52f2ad08 223
b16088bf
RR
224 // implementation
225 // --------------
57c4d796 226
f9ceab7c
JS
227 wxImageListType *m_imageListNormal;
228 wxImageListType *m_imageListSmall;
229 wxImageListType *m_imageListState; // what's that ?
29149a64 230 bool m_ownsImageListNormal,
2e12c11a
VS
231 m_ownsImageListSmall,
232 m_ownsImageListState;
c801d85f
KB
233 wxListHeaderWindow *m_headerWin;
234 wxListMainWindow *m_mainWin;
f8252483 235 wxCoord m_headerHeight;
a3622daa 236
2c1f73ee
VZ
237protected:
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
6c02c329
VZ
244 // return the attribute for the item (may return NULL if none)
245 virtual wxListItemAttr *OnGetItemAttr(long item) const;
246
2c1f73ee 247 // it calls our OnGetXXX() functions
ad08ef44 248 friend class WXDLLEXPORT wxListMainWindow;
2c1f73ee 249
b16088bf 250private:
210a651b 251 // Virtual function hiding supression
8ac7c509 252 virtual void Update() { wxWindow::Update(); }
210a651b 253
cf1dfa6b
VZ
254 // create the header window
255 void CreateHeaderWindow();
256
f8252483
JS
257 // calculate and set height of the header
258 void CalculateAndSetHeaderHeight();
259
c0f8674c
VZ
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
b16088bf 264 DECLARE_EVENT_TABLE()
6b99f53e 265 DECLARE_DYNAMIC_CLASS(wxGenericListCtrl)
c801d85f
KB
266};
267
3a5bcc4d 268#if !defined(__WXMSW__) || defined(__WXUNIVERSAL__)
b31989e2
JS
269/*
270 * wxListCtrl has to be a real class or we have problems with
271 * the run-time information.
272 */
c801d85f 273
b31989e2
JS
274class WXDLLEXPORT wxListCtrl: public wxGenericListCtrl
275{
276 DECLARE_DYNAMIC_CLASS(wxListCtrl)
277
278public:
6463b9f5 279 wxListCtrl() {}
b31989e2 280
ca65c044 281 wxListCtrl(wxWindow *parent, wxWindowID winid = wxID_ANY,
b31989e2
JS
282 const wxPoint& pos = wxDefaultPosition,
283 const wxSize& size = wxDefaultSize,
284 long style = wxLC_ICON,
285 const wxValidator &validator = wxDefaultValidator,
52f2ad08 286 const wxString &name = wxListCtrlNameStr)
6463b9f5
JS
287 : wxGenericListCtrl(parent, winid, pos, size, style, validator, name)
288 {
289 }
b31989e2 290};
3a5bcc4d 291#endif // !__WXMSW__ || __WXUNIVERSAL__
5b98eb2f 292
b31989e2 293#endif // __LISTCTRLH_G__