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 int GetSelectedItemCount() const;
122 wxColour
GetTextColour() const;
123 void SetTextColour(const wxColour
& col
);
124 long GetTopItem() const;
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
136 bool DeleteItem( long item
);
137 bool DeleteAllItems();
138 bool DeleteAllColumns();
139 bool DeleteColumn( int col
);
141 void SetItemCount(long count
);
143 void EditLabel( long item
) { Edit(item
); }
144 void Edit( long item
);
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
);
162 // are we in report mode?
163 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
165 // are we in virtual report mode?
166 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
168 // do we have a header window?
169 bool HasHeader() const
170 { return InReportView() && !HasFlag(wxLC_NO_HEADER
); }
172 // refresh items selectively (only useful for virtual list controls)
173 void RefreshItem(long item
);
174 void RefreshItems(long itemFrom
, long itemTo
);
176 // obsolete, don't use
177 wxDEPRECATED( int GetItemSpacing( bool isSmall
) const );
180 virtual wxVisualAttributes
GetDefaultAttributes() const
182 return GetClassDefaultAttributes(GetWindowVariant());
185 static wxVisualAttributes
186 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
188 // implementation only from now on
189 // -------------------------------
191 void OnInternalIdle( );
192 void OnSize( wxSizeEvent
&event
);
194 // We have to hand down a few functions
195 virtual void Refresh(bool eraseBackground
= true,
196 const wxRect
*rect
= NULL
);
198 virtual void Freeze();
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
);
208 #if wxUSE_DRAG_AND_DROP
209 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
210 virtual wxDropTarget
*GetDropTarget() const;
213 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
215 virtual bool ShouldInheritColours() const { return false; }
216 virtual void SetFocus();
218 virtual wxSize
DoGetBestSize() const;
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
;
234 // return the text for the given column of the given item
235 virtual wxString
OnGetItemText(long item
, long column
) const;
237 // return the icon for the given item
238 virtual int OnGetItemImage(long item
) const;
240 // return the attribute for the item (may return NULL if none)
241 virtual wxListItemAttr
*OnGetItemAttr(long item
) const;
243 // it calls our OnGetXXX() functions
244 friend class WXDLLEXPORT wxListMainWindow
;
247 // Virtual function hiding supression
248 virtual void Update() { wxWindow::Update(); }
250 // create the header window
251 void CreateHeaderWindow();
253 // calculate and set height of the header
254 void CalculateAndSetHeaderHeight();
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
);
260 DECLARE_EVENT_TABLE()
261 DECLARE_DYNAMIC_CLASS(wxGenericListCtrl
)
264 #if !defined(__WXMSW__) || defined(__WXUNIVERSAL__)
266 * wxListCtrl has to be a real class or we have problems with
267 * the run-time information.
270 class WXDLLEXPORT wxListCtrl
: public wxGenericListCtrl
272 DECLARE_DYNAMIC_CLASS(wxListCtrl
)
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
)
287 #endif // !__WXMSW__ || __WXUNIVERSAL__
289 #endif // __LISTCTRLH_G__