]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/listctrl.h
test ShowFullScreen() to verify that restoring menu works correctly
[wxWidgets.git] / include / wx / generic / listctrl.h
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$
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/scrolwin.h"
15 #include "wx/textctrl.h"
16
17 class WXDLLIMPEXP_FWD_CORE wxImageList;
18
19 #if wxUSE_DRAG_AND_DROP
20 class WXDLLIMPEXP_FWD_CORE wxDropTarget;
21 #endif
22
23 // ----------------------------------------------------------------------------
24 // constants
25 // ----------------------------------------------------------------------------
26
27
28 //-----------------------------------------------------------------------------
29 // internal classes
30 //-----------------------------------------------------------------------------
31
32 class WXDLLIMPEXP_FWD_CORE wxListHeaderWindow;
33 class WXDLLIMPEXP_FWD_CORE wxListMainWindow;
34
35 //-----------------------------------------------------------------------------
36 // wxListCtrl
37 //-----------------------------------------------------------------------------
38
39 class WXDLLIMPEXP_CORE wxGenericListCtrl: public wxControl,
40 public wxScrollHelper
41 {
42 public:
43
44 wxGenericListCtrl() : wxScrollHelper(this)
45 {
46 Init();
47 }
48
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)
57 {
58 Create(parent, winid, pos, size, style, validator, name);
59 }
60
61 virtual ~wxGenericListCtrl();
62
63 void Init();
64
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);
72
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;
79
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;
110
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
119
120 void ClearAll();
121 bool DeleteItem( long item );
122 bool DeleteAllItems();
123 bool DeleteAllColumns();
124 bool DeleteColumn( int col );
125
126 void SetItemCount(long count);
127
128 wxTextCtrl *EditLabel(long item,
129 wxClassInfo* textControlClass = CLASSINFO(wxTextCtrl));
130 wxTextCtrl* GetEditControl() const;
131 void Edit( long item ) { EditLabel(item); }
132
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(); }
150
151 // are we in report mode?
152 bool InReportView() const { return HasFlag(wxLC_REPORT); }
153
154 // are we in virtual report mode?
155 bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL); }
156
157 // do we have a header window?
158 bool HasHeader() const
159 { return InReportView() && !HasFlag(wxLC_NO_HEADER); }
160
161 // refresh items selectively (only useful for virtual list controls)
162 void RefreshItem(long item);
163 void RefreshItems(long itemFrom, long itemTo);
164
165 #if WXWIN_COMPATIBILITY_2_6
166 // obsolete, don't use
167 wxDEPRECATED( int GetItemSpacing( bool isSmall ) const );
168 #endif // WXWIN_COMPATIBILITY_2_6
169
170 virtual wxVisualAttributes GetDefaultAttributes() const
171 {
172 return GetClassDefaultAttributes(GetWindowVariant());
173 }
174
175 static wxVisualAttributes
176 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
177
178 // implementation only from now on
179 // -------------------------------
180
181 void OnInternalIdle( );
182
183 // We have to hand down a few functions
184 virtual void Refresh(bool eraseBackground = true,
185 const wxRect *rect = NULL);
186
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 );
193
194 #if wxUSE_DRAG_AND_DROP
195 virtual void SetDropTarget( wxDropTarget *dropTarget );
196 virtual wxDropTarget *GetDropTarget() const;
197 #endif
198
199 virtual bool ShouldInheritColours() const { return false; }
200 virtual void SetFocus();
201
202 // implementation
203 // --------------
204
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;
214
215 protected:
216 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
217
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;
222
223 virtual wxSize DoGetBestSize() const;
224
225 // return the text for the given column of the given item
226 virtual wxString OnGetItemText(long item, long column) const;
227
228 // return the icon for the given item. In report view, OnGetItemImage will
229 // only be called for the first column. See OnGetItemColumnImage for
230 // details.
231 virtual int OnGetItemImage(long item) const;
232
233 // return the icon for the given item and column.
234 virtual int OnGetItemColumnImage(long item, long column) const;
235
236 // return the attribute for the item (may return NULL if none)
237 virtual wxListItemAttr *OnGetItemAttr(long item) const;
238
239 // it calls our OnGetXXX() functions
240 friend class WXDLLIMPEXP_FWD_CORE wxListMainWindow;
241
242 virtual wxBorder GetDefaultBorder() const;
243
244 private:
245 void CreateOrDestroyHeaderWindowAsNeeded();
246 void OnScroll( wxScrollWinEvent& event );
247 void OnSize( wxSizeEvent &event );
248 virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size);
249
250 // we need to return a special WM_GETDLGCODE value to process just the
251 // arrows but let the other navigation characters through
252 #ifdef __WXMSW__
253 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
254 #endif // __WXMSW__
255
256 WX_FORWARD_TO_SCROLL_HELPER()
257
258 DECLARE_EVENT_TABLE()
259 DECLARE_DYNAMIC_CLASS(wxGenericListCtrl)
260 };
261
262 #if (!defined(__WXMSW__) || defined(__WXUNIVERSAL__)) && (!(defined(__WXMAC__) && wxOSX_USE_CARBON) || defined(__WXUNIVERSAL__ ))
263 /*
264 * wxListCtrl has to be a real class or we have problems with
265 * the run-time information.
266 */
267
268 class WXDLLIMPEXP_CORE wxListCtrl: public wxGenericListCtrl
269 {
270 DECLARE_DYNAMIC_CLASS(wxListCtrl)
271
272 public:
273 wxListCtrl() {}
274
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)
282 {
283 }
284
285 };
286 #endif // !__WXMSW__ || __WXUNIVERSAL__
287
288 #endif // _WX_GENERIC_LISTCTRL_H_