1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/listctrl.h
3 // Purpose: Generic list control
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling and Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef __LISTCTRLH_G__
12 #define __LISTCTRLH_G__
14 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
15 #pragma interface "listctrl.h"
19 #include "wx/object.h"
21 #include "wx/imaglist.h"
23 #include "wx/generic/imaglist.h"
26 #include "wx/control.h"
28 #include "wx/dcclient.h"
29 #include "wx/scrolwin.h"
30 #include "wx/settings.h"
31 #include "wx/listbase.h"
33 #if wxUSE_DRAG_AND_DROP
34 class WXDLLEXPORT wxDropTarget
;
37 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
41 class WXDLLEXPORT wxListItem
;
42 class WXDLLEXPORT wxListEvent
;
44 #if !defined(__WXMSW__) || defined(__WXUNIVERSAL__)
45 class WXDLLEXPORT wxListCtrl
;
46 #define wxImageListType wxImageList
48 #define wxImageListType wxGenericImageList
51 //-----------------------------------------------------------------------------
53 //-----------------------------------------------------------------------------
55 class WXDLLEXPORT wxListHeaderData
;
56 class WXDLLEXPORT wxListItemData
;
57 class WXDLLEXPORT wxListLineData
;
59 class WXDLLEXPORT wxListHeaderWindow
;
60 class WXDLLEXPORT wxListMainWindow
;
62 class WXDLLEXPORT wxListRenameTimer
;
63 class WXDLLEXPORT wxListTextCtrl
;
65 //-----------------------------------------------------------------------------
67 //-----------------------------------------------------------------------------
69 class WXDLLEXPORT wxGenericListCtrl
: public wxControl
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
)
81 Create(parent
, winid
, pos
, size
, style
, validator
, name
);
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
);
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;
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 #if wxABI_VERSION >= 20602
122 void SetItemFont( long item
, const wxFont
&f
);
123 wxFont
GetItemFont( long item
) const;
125 int GetSelectedItemCount() const;
126 wxColour
GetTextColour() const;
127 void SetTextColour(const wxColour
& col
);
128 long GetTopItem() const;
130 void SetSingleStyle( long style
, bool add
= true ) ;
131 void SetWindowStyleFlag( long style
);
132 void RecreateWindow() {}
133 long GetNextItem( long item
, int geometry
= wxLIST_NEXT_ALL
, int state
= wxLIST_STATE_DONTCARE
) const;
134 wxImageListType
*GetImageList( int which
) const;
135 void SetImageList( wxImageListType
*imageList
, int which
);
136 void AssignImageList( wxImageListType
*imageList
, int which
);
137 bool Arrange( int flag
= wxLIST_ALIGN_DEFAULT
); // always wxLIST_ALIGN_LEFT in wxGLC
140 bool DeleteItem( long item
);
141 bool DeleteAllItems();
142 bool DeleteAllColumns();
143 bool DeleteColumn( int col
);
145 void SetItemCount(long count
);
147 void EditLabel( long item
) { Edit(item
); }
148 void Edit( long item
);
150 bool EnsureVisible( long item
);
151 long FindItem( long start
, const wxString
& str
, bool partial
= false );
152 long FindItem( long start
, wxUIntPtr data
);
153 long FindItem( long start
, const wxPoint
& pt
, int direction
); // not supported in wxGLC
154 long HitTest( const wxPoint
& point
, int& flags
);
155 long InsertItem(wxListItem
& info
);
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
);
160 long InsertColumn( long col
, const wxString
& heading
,
161 int format
= wxLIST_FORMAT_LEFT
, int width
= -1 );
162 bool ScrollList( int dx
, int dy
);
163 bool SortItems( wxListCtrlCompare fn
, long data
);
164 bool Update( long item
);
166 // are we in report mode?
167 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
169 // are we in virtual report mode?
170 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
172 // do we have a header window?
173 bool HasHeader() const
174 { return InReportView() && !HasFlag(wxLC_NO_HEADER
); }
176 // refresh items selectively (only useful for virtual list controls)
177 void RefreshItem(long item
);
178 void RefreshItems(long itemFrom
, long itemTo
);
180 // obsolete, don't use
181 wxDEPRECATED( int GetItemSpacing( bool isSmall
) const );
184 virtual wxVisualAttributes
GetDefaultAttributes() const
186 return GetClassDefaultAttributes(GetWindowVariant());
189 static wxVisualAttributes
190 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
192 // implementation only from now on
193 // -------------------------------
195 void OnInternalIdle( );
196 void OnSize( wxSizeEvent
&event
);
198 // We have to hand down a few functions
199 virtual void Refresh(bool eraseBackground
= true,
200 const wxRect
*rect
= NULL
);
202 virtual void Freeze();
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
);
212 #if wxUSE_DRAG_AND_DROP
213 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
214 virtual wxDropTarget
*GetDropTarget() const;
217 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
219 virtual bool ShouldInheritColours() const { return false; }
220 virtual void SetFocus();
222 virtual wxSize
DoGetBestSize() const;
227 wxImageListType
*m_imageListNormal
;
228 wxImageListType
*m_imageListSmall
;
229 wxImageListType
*m_imageListState
; // what's that ?
230 bool m_ownsImageListNormal
,
231 m_ownsImageListSmall
,
232 m_ownsImageListState
;
233 wxListHeaderWindow
*m_headerWin
;
234 wxListMainWindow
*m_mainWin
;
235 wxCoord m_headerHeight
;
238 // return the text for the given column of the given item
239 virtual wxString
OnGetItemText(long item
, long column
) const;
241 // return the icon for the given item
242 virtual int OnGetItemImage(long item
) const;
244 // return the attribute for the item (may return NULL if none)
245 virtual wxListItemAttr
*OnGetItemAttr(long item
) const;
247 // it calls our OnGetXXX() functions
248 friend class WXDLLEXPORT wxListMainWindow
;
251 // Virtual function hiding supression
252 virtual void Update() { wxWindow::Update(); }
254 // create the header window
255 void CreateHeaderWindow();
257 // calculate and set height of the header
258 void CalculateAndSetHeaderHeight();
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
);
264 DECLARE_EVENT_TABLE()
265 DECLARE_DYNAMIC_CLASS(wxGenericListCtrl
)
268 #if !defined(__WXMSW__) || defined(__WXUNIVERSAL__)
270 * wxListCtrl has to be a real class or we have problems with
271 * the run-time information.
274 class WXDLLEXPORT wxListCtrl
: public wxGenericListCtrl
276 DECLARE_DYNAMIC_CLASS(wxListCtrl
)
281 wxListCtrl(wxWindow
*parent
, wxWindowID winid
= wxID_ANY
,
282 const wxPoint
& pos
= wxDefaultPosition
,
283 const wxSize
& size
= wxDefaultSize
,
284 long style
= wxLC_ICON
,
285 const wxValidator
&validator
= wxDefaultValidator
,
286 const wxString
&name
= wxListCtrlNameStr
)
287 : wxGenericListCtrl(parent
, winid
, pos
, size
, style
, validator
, name
)
291 #endif // !__WXMSW__ || __WXUNIVERSAL__
293 #endif // __LISTCTRLH_G__