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 _WX_GENERIC_LISTCTRL_H_
12 #define _WX_GENERIC_LISTCTRL_H_
14 #include "wx/scrolwin.h"
15 #include "wx/textctrl.h"
17 #if wxUSE_DRAG_AND_DROP
18 class WXDLLIMPEXP_FWD_CORE wxDropTarget
;
21 //-----------------------------------------------------------------------------
23 //-----------------------------------------------------------------------------
25 class WXDLLIMPEXP_FWD_CORE wxListHeaderWindow
;
26 class WXDLLIMPEXP_FWD_CORE wxListMainWindow
;
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
32 class WXDLLIMPEXP_CORE wxGenericListCtrl
: public wxListCtrlBase
,
37 wxGenericListCtrl() : wxScrollHelper(this)
42 wxGenericListCtrl( wxWindow
*parent
,
43 wxWindowID winid
= wxID_ANY
,
44 const wxPoint
&pos
= wxDefaultPosition
,
45 const wxSize
&size
= wxDefaultSize
,
46 long style
= wxLC_ICON
,
47 const wxValidator
& validator
= wxDefaultValidator
,
48 const wxString
&name
= wxListCtrlNameStr
)
49 : wxScrollHelper(this)
51 Create(parent
, winid
, pos
, size
, style
, validator
, name
);
54 virtual ~wxGenericListCtrl();
58 bool Create( wxWindow
*parent
,
59 wxWindowID winid
= wxID_ANY
,
60 const wxPoint
&pos
= wxDefaultPosition
,
61 const wxSize
&size
= wxDefaultSize
,
62 long style
= wxLC_ICON
,
63 const wxValidator
& validator
= wxDefaultValidator
,
64 const wxString
&name
= wxListCtrlNameStr
);
66 bool GetColumn( int col
, wxListItem
& item
) const;
67 bool SetColumn( int col
, const wxListItem
& item
);
68 int GetColumnWidth( int col
) const;
69 bool SetColumnWidth( int col
, int width
);
70 int GetCountPerPage() const; // not the same in wxGLC as in Windows, I think
71 wxRect
GetViewRect() const;
73 bool GetItem( wxListItem
& info
) const;
74 bool SetItem( wxListItem
& info
) ;
75 long SetItem( long index
, int col
, const wxString
& label
, int imageId
= -1 );
76 int GetItemState( long item
, long stateMask
) const;
77 bool SetItemState( long item
, long state
, long stateMask
);
78 bool SetItemImage( long item
, int image
, int selImage
= -1 );
79 bool SetItemColumnImage( long item
, long column
, int image
);
80 wxString
GetItemText( long item
, int col
= 0 ) const;
81 void SetItemText( long item
, const wxString
& str
);
82 wxUIntPtr
GetItemData( long item
) const;
83 bool SetItemPtrData(long item
, wxUIntPtr data
);
84 bool SetItemData(long item
, long data
) { return SetItemPtrData(item
, data
); }
85 bool GetItemRect( long item
, wxRect
& rect
, int code
= wxLIST_RECT_BOUNDS
) const;
86 bool GetSubItemRect( long item
, long subItem
, wxRect
& rect
, int code
= wxLIST_RECT_BOUNDS
) const;
87 bool GetItemPosition( long item
, wxPoint
& pos
) const;
88 bool SetItemPosition( long item
, const wxPoint
& pos
); // not supported in wxGLC
89 int GetItemCount() const;
90 int GetColumnCount() const;
91 void SetItemSpacing( int spacing
, bool isSmall
= false );
92 wxSize
GetItemSpacing() const;
93 void SetItemTextColour( long item
, const wxColour
& col
);
94 wxColour
GetItemTextColour( long item
) const;
95 void SetItemBackgroundColour( long item
, const wxColour
&col
);
96 wxColour
GetItemBackgroundColour( long item
) const;
97 void SetItemFont( long item
, const wxFont
&f
);
98 wxFont
GetItemFont( long item
) const;
99 int GetSelectedItemCount() const;
100 wxColour
GetTextColour() const;
101 void SetTextColour(const wxColour
& col
);
102 long GetTopItem() const;
104 void SetSingleStyle( long style
, bool add
= true ) ;
105 void SetWindowStyleFlag( long style
);
106 void RecreateWindow() {}
107 long GetNextItem( long item
, int geometry
= wxLIST_NEXT_ALL
, int state
= wxLIST_STATE_DONTCARE
) const;
108 wxImageList
*GetImageList( int which
) const;
109 void SetImageList( wxImageList
*imageList
, int which
);
110 void AssignImageList( wxImageList
*imageList
, int which
);
111 bool Arrange( int flag
= wxLIST_ALIGN_DEFAULT
); // always wxLIST_ALIGN_LEFT in wxGLC
114 bool DeleteItem( long item
);
115 bool DeleteAllItems();
116 bool DeleteAllColumns();
117 bool DeleteColumn( int col
);
119 void SetItemCount(long count
);
121 wxTextCtrl
*EditLabel(long item
,
122 wxClassInfo
* textControlClass
= wxCLASSINFO(wxTextCtrl
));
123 wxTextCtrl
* GetEditControl() const;
124 void Edit( long item
) { EditLabel(item
); }
126 bool EnsureVisible( long item
);
127 long FindItem( long start
, const wxString
& str
, bool partial
= false );
128 long FindItem( long start
, wxUIntPtr data
);
129 long FindItem( long start
, const wxPoint
& pt
, int direction
); // not supported in wxGLC
130 long HitTest( const wxPoint
& point
, int& flags
, long *pSubItem
= NULL
) const;
131 long InsertItem(wxListItem
& info
);
132 long InsertItem( long index
, const wxString
& label
);
133 long InsertItem( long index
, int imageIndex
);
134 long InsertItem( long index
, const wxString
& label
, int imageIndex
);
135 bool ScrollList( int dx
, int dy
);
136 bool SortItems( wxListCtrlCompare fn
, wxIntPtr data
);
138 // do we have a header window?
139 bool HasHeader() const
140 { return InReportView() && !HasFlag(wxLC_NO_HEADER
); }
142 // refresh items selectively (only useful for virtual list controls)
143 void RefreshItem(long item
);
144 void RefreshItems(long itemFrom
, long itemTo
);
146 #if WXWIN_COMPATIBILITY_2_6
147 // obsolete, don't use
148 wxDEPRECATED( int GetItemSpacing( bool isSmall
) const );
149 #endif // WXWIN_COMPATIBILITY_2_6
152 // overridden base class virtuals
153 // ------------------------------
155 virtual wxVisualAttributes
GetDefaultAttributes() const
157 return GetClassDefaultAttributes(GetWindowVariant());
160 static wxVisualAttributes
161 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
163 virtual void Update();
166 // implementation only from now on
167 // -------------------------------
169 // generic version extension, don't use in portable code
170 bool Update( long item
);
172 void OnInternalIdle( );
174 // We have to hand down a few functions
175 virtual void Refresh(bool eraseBackground
= true,
176 const wxRect
*rect
= NULL
);
178 virtual bool SetBackgroundColour( const wxColour
&colour
);
179 virtual bool SetForegroundColour( const wxColour
&colour
);
180 virtual wxColour
GetBackgroundColour() const;
181 virtual wxColour
GetForegroundColour() const;
182 virtual bool SetFont( const wxFont
&font
);
183 virtual bool SetCursor( const wxCursor
&cursor
);
185 #if wxUSE_DRAG_AND_DROP
186 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
187 virtual wxDropTarget
*GetDropTarget() const;
190 virtual bool ShouldInheritColours() const { return false; }
191 virtual void SetFocus();
196 wxImageList
*m_imageListNormal
;
197 wxImageList
*m_imageListSmall
;
198 wxImageList
*m_imageListState
; // what's that ?
199 bool m_ownsImageListNormal
,
200 m_ownsImageListSmall
,
201 m_ownsImageListState
;
202 wxListHeaderWindow
*m_headerWin
;
203 wxListMainWindow
*m_mainWin
;
206 // Implement base class pure virtual methods.
207 long DoInsertColumn(long col
, const wxListItem
& info
);
210 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
212 // take into account the coordinates difference between the container
213 // window and the list control window itself here
214 virtual void DoClientToScreen( int *x
, int *y
) const;
215 virtual void DoScreenToClient( int *x
, int *y
) const;
217 virtual wxSize
DoGetBestClientSize() const;
219 // return the text for the given column of the given item
220 virtual wxString
OnGetItemText(long item
, long column
) const;
222 // return the icon for the given item. In report view, OnGetItemImage will
223 // only be called for the first column. See OnGetItemColumnImage for
225 virtual int OnGetItemImage(long item
) const;
227 // return the icon for the given item and column.
228 virtual int OnGetItemColumnImage(long item
, long column
) const;
230 // return the attribute for the item (may return NULL if none)
231 virtual wxListItemAttr
*OnGetItemAttr(long item
) const;
233 // it calls our OnGetXXX() functions
234 friend class WXDLLIMPEXP_FWD_CORE wxListMainWindow
;
236 virtual wxBorder
GetDefaultBorder() const;
238 virtual wxSize
GetSizeAvailableForScrollTarget(const wxSize
& size
);
241 void CreateOrDestroyHeaderWindowAsNeeded();
242 void OnScroll( wxScrollWinEvent
& event
);
243 void OnSize( wxSizeEvent
&event
);
245 // we need to return a special WM_GETDLGCODE value to process just the
246 // arrows but let the other navigation characters through
247 #if defined(__WXMSW__) && !defined(__WXWINCE__) && !defined(__WXUNIVERSAL__)
249 MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
252 WX_FORWARD_TO_SCROLL_HELPER()
254 DECLARE_EVENT_TABLE()
255 DECLARE_DYNAMIC_CLASS(wxGenericListCtrl
)
258 #if (!defined(__WXMSW__) || defined(__WXUNIVERSAL__)) && (!(defined(__WXMAC__) && wxOSX_USE_CARBON) || defined(__WXUNIVERSAL__ ))
260 * wxListCtrl has to be a real class or we have problems with
261 * the run-time information.
264 class WXDLLIMPEXP_CORE wxListCtrl
: public wxGenericListCtrl
266 DECLARE_DYNAMIC_CLASS(wxListCtrl
)
271 wxListCtrl(wxWindow
*parent
, wxWindowID winid
= wxID_ANY
,
272 const wxPoint
& pos
= wxDefaultPosition
,
273 const wxSize
& size
= wxDefaultSize
,
274 long style
= wxLC_ICON
,
275 const wxValidator
&validator
= wxDefaultValidator
,
276 const wxString
&name
= wxListCtrlNameStr
)
277 : wxGenericListCtrl(parent
, winid
, pos
, size
, style
, validator
, name
)
282 #endif // !__WXMSW__ || __WXUNIVERSAL__
284 #endif // _WX_GENERIC_LISTCTRL_H_