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 class WXDLLIMPEXP_FWD_CORE wxImageList
;
19 #if wxUSE_DRAG_AND_DROP
20 class WXDLLIMPEXP_FWD_CORE wxDropTarget
;
23 // ----------------------------------------------------------------------------
25 // ----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
32 class WXDLLIMPEXP_FWD_CORE wxListHeaderWindow
;
33 class WXDLLIMPEXP_FWD_CORE wxListMainWindow
;
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
39 class WXDLLIMPEXP_CORE wxGenericListCtrl
: public wxControl
,
44 wxGenericListCtrl() : wxScrollHelper(this)
49 wxGenericListCtrl( wxWindow
*parent
,
50 wxWindowID winid
= wxID_ANY
,
51 const wxPoint
&pos
= wxDefaultPosition
,
52 const wxSize
&size
= wxDefaultSize
,
53 long style
= wxLC_ICON
,
54 const wxValidator
& validator
= wxDefaultValidator
,
55 const wxString
&name
= wxListCtrlNameStr
)
56 : wxScrollHelper(this)
58 Create(parent
, winid
, pos
, size
, style
, validator
, name
);
61 virtual ~wxGenericListCtrl();
65 bool Create( wxWindow
*parent
,
66 wxWindowID winid
= wxID_ANY
,
67 const wxPoint
&pos
= wxDefaultPosition
,
68 const wxSize
&size
= wxDefaultSize
,
69 long style
= wxLC_ICON
,
70 const wxValidator
& validator
= wxDefaultValidator
,
71 const wxString
&name
= wxListCtrlNameStr
);
73 bool GetColumn( int col
, wxListItem
& item
) const;
74 bool SetColumn( int col
, wxListItem
& item
);
75 int GetColumnWidth( int col
) const;
76 bool SetColumnWidth( int col
, int width
);
77 int GetCountPerPage() const; // not the same in wxGLC as in Windows, I think
78 wxRect
GetViewRect() const;
80 bool GetItem( wxListItem
& info
) const;
81 bool SetItem( wxListItem
& info
) ;
82 long SetItem( long index
, int col
, const wxString
& label
, int imageId
= -1 );
83 int GetItemState( long item
, long stateMask
) const;
84 bool SetItemState( long item
, long state
, long stateMask
);
85 bool SetItemImage( long item
, int image
, int selImage
= -1 );
86 bool SetItemColumnImage( long item
, long column
, int image
);
87 wxString
GetItemText( long item
) const;
88 void SetItemText( long item
, const wxString
& str
);
89 wxUIntPtr
GetItemData( long item
) const;
90 bool SetItemPtrData(long item
, wxUIntPtr data
);
91 bool SetItemData(long item
, long data
) { return SetItemPtrData(item
, data
); }
92 bool GetItemRect( long item
, wxRect
& rect
, int code
= wxLIST_RECT_BOUNDS
) const;
93 bool GetSubItemRect( long item
, long subItem
, wxRect
& rect
, int code
= wxLIST_RECT_BOUNDS
) const;
94 bool GetItemPosition( long item
, wxPoint
& pos
) const;
95 bool SetItemPosition( long item
, const wxPoint
& pos
); // not supported in wxGLC
96 int GetItemCount() const;
97 int GetColumnCount() const;
98 void SetItemSpacing( int spacing
, bool isSmall
= false );
99 wxSize
GetItemSpacing() const;
100 void SetItemTextColour( long item
, const wxColour
& col
);
101 wxColour
GetItemTextColour( long item
) const;
102 void SetItemBackgroundColour( long item
, const wxColour
&col
);
103 wxColour
GetItemBackgroundColour( long item
) const;
104 void SetItemFont( long item
, const wxFont
&f
);
105 wxFont
GetItemFont( long item
) const;
106 int GetSelectedItemCount() const;
107 wxColour
GetTextColour() const;
108 void SetTextColour(const wxColour
& col
);
109 long GetTopItem() const;
111 void SetSingleStyle( long style
, bool add
= true ) ;
112 void SetWindowStyleFlag( long style
);
113 void RecreateWindow() {}
114 long GetNextItem( long item
, int geometry
= wxLIST_NEXT_ALL
, int state
= wxLIST_STATE_DONTCARE
) const;
115 wxImageList
*GetImageList( int which
) const;
116 void SetImageList( wxImageList
*imageList
, int which
);
117 void AssignImageList( wxImageList
*imageList
, int which
);
118 bool Arrange( int flag
= wxLIST_ALIGN_DEFAULT
); // always wxLIST_ALIGN_LEFT in wxGLC
121 bool DeleteItem( long item
);
122 bool DeleteAllItems();
123 bool DeleteAllColumns();
124 bool DeleteColumn( int col
);
126 void SetItemCount(long count
);
128 wxTextCtrl
*EditLabel(long item
,
129 wxClassInfo
* textControlClass
= CLASSINFO(wxTextCtrl
));
130 wxTextCtrl
* GetEditControl() const;
131 void Edit( long item
) { EditLabel(item
); }
133 bool EnsureVisible( long item
);
134 long FindItem( long start
, const wxString
& str
, bool partial
= false );
135 long FindItem( long start
, wxUIntPtr data
);
136 long FindItem( long start
, const wxPoint
& pt
, int direction
); // not supported in wxGLC
137 long HitTest( const wxPoint
& point
, int& flags
, long *pSubItem
= NULL
) const;
138 long InsertItem(wxListItem
& info
);
139 long InsertItem( long index
, const wxString
& label
);
140 long InsertItem( long index
, int imageIndex
);
141 long InsertItem( long index
, const wxString
& label
, int imageIndex
);
142 long InsertColumn( long col
, wxListItem
& info
);
143 long InsertColumn( long col
, const wxString
& heading
,
144 int format
= wxLIST_FORMAT_LEFT
, int width
= -1 );
145 bool ScrollList( int dx
, int dy
);
146 bool SortItems( wxListCtrlCompare fn
, long data
);
147 bool Update( long item
);
148 // Must provide overload to avoid hiding it (and warnings about it)
149 virtual void Update() { wxControl::Update(); }
151 // are we in report mode?
152 bool InReportView() const { return HasFlag(wxLC_REPORT
); }
154 // are we in virtual report mode?
155 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); }
157 // do we have a header window?
158 bool HasHeader() const
159 { return InReportView() && !HasFlag(wxLC_NO_HEADER
); }
161 // refresh items selectively (only useful for virtual list controls)
162 void RefreshItem(long item
);
163 void RefreshItems(long itemFrom
, long itemTo
);
165 #if WXWIN_COMPATIBILITY_2_6
166 // obsolete, don't use
167 wxDEPRECATED( int GetItemSpacing( bool isSmall
) const );
168 #endif // WXWIN_COMPATIBILITY_2_6
170 virtual wxVisualAttributes
GetDefaultAttributes() const
172 return GetClassDefaultAttributes(GetWindowVariant());
175 static wxVisualAttributes
176 GetClassDefaultAttributes(wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
);
178 // implementation only from now on
179 // -------------------------------
181 void OnInternalIdle( );
183 // We have to hand down a few functions
184 virtual void Refresh(bool eraseBackground
= true,
185 const wxRect
*rect
= NULL
);
187 virtual bool SetBackgroundColour( const wxColour
&colour
);
188 virtual bool SetForegroundColour( const wxColour
&colour
);
189 virtual wxColour
GetBackgroundColour() const;
190 virtual wxColour
GetForegroundColour() const;
191 virtual bool SetFont( const wxFont
&font
);
192 virtual bool SetCursor( const wxCursor
&cursor
);
194 #if wxUSE_DRAG_AND_DROP
195 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
196 virtual wxDropTarget
*GetDropTarget() const;
199 virtual bool ShouldInheritColours() const { return false; }
200 virtual void SetFocus();
205 wxImageList
*m_imageListNormal
;
206 wxImageList
*m_imageListSmall
;
207 wxImageList
*m_imageListState
; // what's that ?
208 bool m_ownsImageListNormal
,
209 m_ownsImageListSmall
,
210 m_ownsImageListState
;
211 wxListHeaderWindow
*m_headerWin
;
212 wxListMainWindow
*m_mainWin
;
213 wxCoord m_headerHeight
;
216 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
218 // take into account the coordinates difference between the container
219 // window and the list control window itself here
220 virtual void DoClientToScreen( int *x
, int *y
) const;
221 virtual void DoScreenToClient( int *x
, int *y
) const;
223 virtual wxSize
DoGetBestSize() const;
225 // return the text for the given column of the given item
226 virtual wxString
OnGetItemText(long item
, long column
) const;
228 // return the icon for the given item. In report view, OnGetItemImage will
229 // only be called for the first column. See OnGetItemColumnImage for
231 virtual int OnGetItemImage(long item
) const;
233 // return the icon for the given item and column.
234 virtual int OnGetItemColumnImage(long item
, long column
) const;
236 // return the attribute for the item (may return NULL if none)
237 virtual wxListItemAttr
*OnGetItemAttr(long item
) const;
239 // it calls our OnGetXXX() functions
240 friend class WXDLLIMPEXP_FWD_CORE wxListMainWindow
;
242 virtual wxBorder
GetDefaultBorder() const;
245 void CreateOrDestroyHeaderWindowAsNeeded();
246 void OnScroll( wxScrollWinEvent
& event
);
247 void OnSize( wxSizeEvent
&event
);
248 virtual wxSize
GetSizeAvailableForScrollTarget(const wxSize
& size
);
250 // we need to return a special WM_GETDLGCODE value to process just the
251 // arrows but let the other navigation characters through
253 virtual WXLRESULT
MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
256 WX_FORWARD_TO_SCROLL_HELPER()
258 DECLARE_EVENT_TABLE()
259 DECLARE_DYNAMIC_CLASS(wxGenericListCtrl
)
262 #if (!defined(__WXMSW__) || defined(__WXUNIVERSAL__)) && (!(defined(__WXMAC__) && wxOSX_USE_CARBON) || defined(__WXUNIVERSAL__ ))
264 * wxListCtrl has to be a real class or we have problems with
265 * the run-time information.
268 class WXDLLIMPEXP_CORE wxListCtrl
: public wxGenericListCtrl
270 DECLARE_DYNAMIC_CLASS(wxListCtrl
)
275 wxListCtrl(wxWindow
*parent
, wxWindowID winid
= wxID_ANY
,
276 const wxPoint
& pos
= wxDefaultPosition
,
277 const wxSize
& size
= wxDefaultSize
,
278 long style
= wxLC_ICON
,
279 const wxValidator
&validator
= wxDefaultValidator
,
280 const wxString
&name
= wxListCtrlNameStr
)
281 : wxGenericListCtrl(parent
, winid
, pos
, size
, style
, validator
, name
)
286 #endif // !__WXMSW__ || __WXUNIVERSAL__
288 #endif // _WX_GENERIC_LISTCTRL_H_