1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        wx/generic/listctrl.h
3 // Purpose:     Generic list control
4 // Author:      Robert Roebling
5 // Created:     01/02/97
6 // RCS-ID:      $Id: listctrl.h 62158 2009-09-26 17:47:23Z JS $
7 // Copyright:   (c) 1998 Robert Roebling and Julian Smart
8 // Licence:     wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10 
11 #ifndef _WX_GENERIC_LISTCTRL_H_
12 #define _WX_GENERIC_LISTCTRL_H_
13 
14 #include "wx/textctrl.h"
15 
16 class WXDLLIMPEXP_CORE wxImageList;
17 
18 #if wxUSE_DRAG_AND_DROP
19 class WXDLLEXPORT wxDropTarget;
20 #endif
21 
22 // ----------------------------------------------------------------------------
23 // constants
24 // ----------------------------------------------------------------------------
25 
26 
27 //-----------------------------------------------------------------------------
28 // internal classes
29 //-----------------------------------------------------------------------------
30 
31 class WXDLLEXPORT wxListHeaderWindow;
32 class WXDLLEXPORT wxListMainWindow;
33 
34 //-----------------------------------------------------------------------------
35 // wxListCtrl
36 //-----------------------------------------------------------------------------
37 
38 class WXDLLEXPORT wxGenericListCtrl: public wxControl
39 {
40 public:
41 
42     wxGenericListCtrl();
43     wxGenericListCtrl( wxWindow *parent,
44                 wxWindowID winid = wxID_ANY,
45                 const wxPoint &pos = wxDefaultPosition,
46                 const wxSize &size = wxDefaultSize,
47                 long style = wxLC_ICON,
48                 const wxValidator& validator = wxDefaultValidator,
49                 const wxString &name = wxListCtrlNameStr)
50     {
51         Create(parent, winid, pos, size, style, validator, name);
52     }
53     virtual ~wxGenericListCtrl();
54 
55     bool Create( wxWindow *parent,
56                  wxWindowID winid = wxID_ANY,
57                  const wxPoint &pos = wxDefaultPosition,
58                  const wxSize &size = wxDefaultSize,
59                  long style = wxLC_ICON,
60                  const wxValidator& validator = wxDefaultValidator,
61                  const wxString &name = wxListCtrlNameStr);
62 
63     bool GetColumn( int col, wxListItem& item ) const;
64     bool SetColumn( int col, wxListItem& item );
65     int GetColumnWidth( int col ) const;
66     bool SetColumnWidth( int col, int width);
67     int GetCountPerPage() const; // not the same in wxGLC as in Windows, I think
68     wxRect GetViewRect() const;
69 
70     bool GetItem( wxListItem& info ) const;
71     bool SetItem( wxListItem& info ) ;
72     long SetItem( long index, int col, const wxString& label, int imageId = -1 );
73     int  GetItemState( long item, long stateMask ) const;
74     bool SetItemState( long item, long state, long stateMask);
75     bool SetItemImage( long item, int image, int selImage = -1 );
76     bool SetItemColumnImage( long item, long column, int image );
77     wxString GetItemText( long item ) const;
78     void SetItemText( long item, const wxString& str );
79     wxUIntPtr GetItemData( long item ) const;
80 #if wxABI_VERSION >= 20804
81     bool SetItemPtrData(long item, wxUIntPtr data);
82 #endif // wxABI 2.8.4+
83     bool SetItemData(long item, long data);
84     bool GetItemRect( long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS ) const;
85     bool GetItemPosition( long item, wxPoint& pos ) const;
86     bool SetItemPosition( long item, const wxPoint& pos ); // not supported in wxGLC
87     int GetItemCount() const;
88     int GetColumnCount() const;
89     void SetItemSpacing( int spacing, bool isSmall = false );
90     wxSize GetItemSpacing() const;
91     void SetItemTextColour( long item, const wxColour& col);
92     wxColour GetItemTextColour( long item ) const;
93     void SetItemBackgroundColour( long item, const wxColour &col);
94     wxColour GetItemBackgroundColour( long item ) const;
95     void SetItemFont( long item, const wxFont &f);
96     wxFont GetItemFont( long item ) const;
97     int GetSelectedItemCount() const;
98     wxColour GetTextColour() const;
99     void SetTextColour(const wxColour& col);
100     long GetTopItem() const;
101 
102     void SetSingleStyle( long style, bool add = true ) ;
103     void SetWindowStyleFlag( long style );
RecreateWindow()104     void RecreateWindow() {}
105     long GetNextItem( long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE ) const;
106     wxImageList *GetImageList( int which ) const;
107     void SetImageList( wxImageList *imageList, int which );
108     void AssignImageList( wxImageList *imageList, int which );
109     bool Arrange( int flag = wxLIST_ALIGN_DEFAULT ); // always wxLIST_ALIGN_LEFT in wxGLC
110 
111     void ClearAll();
112     bool DeleteItem( long item );
113     bool DeleteAllItems();
114     bool DeleteAllColumns();
115     bool DeleteColumn( int col );
116 
117     void SetItemCount(long count);
118 
119     wxTextCtrl *EditLabel(long item,
120                           wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl));
121     wxTextCtrl* GetEditControl() const;
Edit(long item)122     void Edit( long item ) { EditLabel(item); }
123 
124     bool EnsureVisible( long item );
125     long FindItem( long start, const wxString& str, bool partial = false );
126     long FindItem( long start, wxUIntPtr data );
127     long FindItem( long start, const wxPoint& pt, int direction ); // not supported in wxGLC
128     long HitTest( const wxPoint& point, int& flags, long *pSubItem = NULL ) const;
129     long InsertItem(wxListItem& info);
130     long InsertItem( long index, const wxString& label );
131     long InsertItem( long index, int imageIndex );
132     long InsertItem( long index, const wxString& label, int imageIndex );
133     long InsertColumn( long col, wxListItem& info );
134     long InsertColumn( long col, const wxString& heading,
135                        int format = wxLIST_FORMAT_LEFT, int width = -1 );
136     bool ScrollList( int dx, int dy );
137     bool SortItems( wxListCtrlCompare fn, long data );
138     bool Update( long item );
139     virtual void Update();
140 
141     // are we in report mode?
InReportView()142     bool InReportView() const { return HasFlag(wxLC_REPORT); }
143 
144     // are we in virtual report mode?
IsVirtual()145     bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL); }
146 
147     // do we have a header window?
HasHeader()148     bool HasHeader() const
149         { return InReportView() && !HasFlag(wxLC_NO_HEADER); }
150 
151     // refresh items selectively (only useful for virtual list controls)
152     void RefreshItem(long item);
153     void RefreshItems(long itemFrom, long itemTo);
154 
155 #if WXWIN_COMPATIBILITY_2_6
156     // obsolete, don't use
157     wxDEPRECATED( int GetItemSpacing( bool isSmall ) const );
158 #endif // WXWIN_COMPATIBILITY_2_6
159 
GetDefaultAttributes()160     virtual wxVisualAttributes GetDefaultAttributes() const
161     {
162         return GetClassDefaultAttributes(GetWindowVariant());
163     }
164 
165     static wxVisualAttributes
166     GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
167 
168     // implementation only from now on
169     // -------------------------------
170 
171     void OnInternalIdle( );
172     void OnSize( wxSizeEvent &event );
173 
174     // We have to hand down a few functions
175     virtual void Refresh(bool eraseBackground = true,
176                          const wxRect *rect = NULL);
177 
178     virtual void Freeze();
179     virtual void Thaw();
180 
181     virtual bool SetBackgroundColour( const wxColour &colour );
182     virtual bool SetForegroundColour( const wxColour &colour );
183     virtual wxColour GetBackgroundColour() const;
184     virtual wxColour GetForegroundColour() const;
185     virtual bool SetFont( const wxFont &font );
186     virtual bool SetCursor( const wxCursor &cursor );
187 
188     virtual int GetScrollPos(int orient) const;
189     virtual void SetScrollPos(int orient, int pos, bool refresh = true);
190 
191 #if wxUSE_DRAG_AND_DROP
192     virtual void SetDropTarget( wxDropTarget *dropTarget );
193     virtual wxDropTarget *GetDropTarget() const;
194 #endif
195 
ShouldInheritColours()196     virtual bool ShouldInheritColours() const { return false; }
197     virtual void SetFocus();
198 
199     // implementation
200     // --------------
201 
202     wxImageList         *m_imageListNormal;
203     wxImageList         *m_imageListSmall;
204     wxImageList         *m_imageListState;  // what's that ?
205     bool                 m_ownsImageListNormal,
206                          m_ownsImageListSmall,
207                          m_ownsImageListState;
208     wxListHeaderWindow  *m_headerWin;
209     wxListMainWindow    *m_mainWin;
210     wxCoord              m_headerHeight;
211 
212 protected:
213     virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
214 
215     // take into account the coordinates difference between the container
216     // window and the list control window itself here
217     virtual void DoClientToScreen( int *x, int *y ) const;
218     virtual void DoScreenToClient( int *x, int *y ) const;
219 
220     virtual wxSize DoGetBestSize() const;
221 
222     // return the text for the given column of the given item
223     virtual wxString OnGetItemText(long item, long column) const;
224 
225     // return the icon for the given item. In report view, OnGetItemImage will
226     // only be called for the first column. See OnGetItemColumnImage for
227     // details.
228     virtual int OnGetItemImage(long item) const;
229 
230     // return the icon for the given item and column.
231     virtual int OnGetItemColumnImage(long item, long column) const;
232 
233     // return the attribute for the item (may return NULL if none)
234     virtual wxListItemAttr *OnGetItemAttr(long item) const;
235 
236     // it calls our OnGetXXX() functions
237     friend class WXDLLEXPORT wxListMainWindow;
238 
239 private:
240     // create the header window
241     void CreateHeaderWindow();
242 
243     // calculate and set height of the header
244     void CalculateAndSetHeaderHeight();
245 
246     // reposition the header and the main window in the report view depending
247     // on whether it should be shown or not
248     void ResizeReportView(bool showHeader);
249 
250     DECLARE_EVENT_TABLE()
251     DECLARE_DYNAMIC_CLASS(wxGenericListCtrl)
252 };
253 
254 #if (!defined(__WXMSW__) || defined(__WXUNIVERSAL__)) && (!defined(__WXMAC__) || defined(__WXUNIVERSAL__))
255 /*
256  * wxListCtrl has to be a real class or we have problems with
257  * the run-time information.
258  */
259 
260 class WXDLLEXPORT wxListCtrl: public wxGenericListCtrl
261 {
DECLARE_DYNAMIC_CLASS(wxListCtrl)262     DECLARE_DYNAMIC_CLASS(wxListCtrl)
263 
264 public:
265     wxListCtrl() {}
266 
267     wxListCtrl(wxWindow *parent, wxWindowID winid = wxID_ANY,
268                const wxPoint& pos = wxDefaultPosition,
269                const wxSize& size = wxDefaultSize,
270                long style = wxLC_ICON,
271                const wxValidator &validator = wxDefaultValidator,
272                const wxString &name = wxListCtrlNameStr)
wxGenericListCtrl(parent,winid,pos,size,style,validator,name)273     : wxGenericListCtrl(parent, winid, pos, size, style, validator, name)
274     {
275     }
276 
277 };
278 #endif // !__WXMSW__ || __WXUNIVERSAL__
279 
280 #endif // _WX_GENERIC_LISTCTRL_H_
281