1 ///////////////////////////////////////////////////////////////////////////// 2 // Name: wx/generic/listctrl.h 3 // Purpose: Generic list control 4 // Author: Robert Roebling 5 // Created: 01/02/97 6 // Copyright: (c) 1998 Robert Roebling and Julian Smart 7 // Licence: wxWindows licence 8 ///////////////////////////////////////////////////////////////////////////// 9 10 #ifndef _WX_GENERIC_LISTCTRL_H_ 11 #define _WX_GENERIC_LISTCTRL_H_ 12 13 #include "wx/containr.h" 14 #include "wx/scrolwin.h" 15 #include "wx/textctrl.h" 16 17 #if wxUSE_DRAG_AND_DROP 18 class WXDLLIMPEXP_FWD_CORE wxDropTarget; 19 #endif 20 21 //----------------------------------------------------------------------------- 22 // internal classes 23 //----------------------------------------------------------------------------- 24 25 class WXDLLIMPEXP_FWD_CORE wxListHeaderWindow; 26 class WXDLLIMPEXP_FWD_CORE wxListMainWindow; 27 28 //----------------------------------------------------------------------------- 29 // wxListCtrl 30 //----------------------------------------------------------------------------- 31 32 class WXDLLIMPEXP_CORE wxGenericListCtrl: public wxNavigationEnabled<wxListCtrlBase>, 33 public wxScrollHelper 34 { 35 public: 36 wxGenericListCtrl()37 wxGenericListCtrl() : wxScrollHelper(this) 38 { 39 Init(); 40 } 41 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) wxScrollHelper(this)49 : wxScrollHelper(this) 50 { 51 Create(parent, winid, pos, size, style, validator, name); 52 } 53 54 virtual ~wxGenericListCtrl(); 55 56 void Init(); 57 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); 65 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; 72 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); SetItemData(long item,long 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; 103 104 void SetSingleStyle( long style, bool add = true ) ; 105 void SetWindowStyleFlag( long style ); RecreateWindow()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 112 113 void ClearAll(); 114 bool DeleteItem( long item ); 115 bool DeleteAllItems(); 116 bool DeleteAllColumns(); 117 bool DeleteColumn( int col ); 118 119 void SetItemCount(long count); 120 121 wxTextCtrl *EditLabel(long item, 122 wxClassInfo* textControlClass = wxCLASSINFO(wxTextCtrl)); 123 124 // End label editing, optionally cancelling the edit 125 #if wxABI_VERSION >= 30002 126 bool EndEditLabel(bool cancel); 127 #endif 128 129 wxTextCtrl* GetEditControl() const; Edit(long item)130 void Edit( long item ) { EditLabel(item); } 131 132 bool EnsureVisible( long item ); 133 long FindItem( long start, const wxString& str, bool partial = false ); 134 long FindItem( long start, wxUIntPtr data ); 135 long FindItem( long start, const wxPoint& pt, int direction ); // not supported in wxGLC 136 long HitTest( const wxPoint& point, int& flags, long *pSubItem = NULL ) const; 137 long InsertItem(wxListItem& info); 138 long InsertItem( long index, const wxString& label ); 139 long InsertItem( long index, int imageIndex ); 140 long InsertItem( long index, const wxString& label, int imageIndex ); 141 bool ScrollList( int dx, int dy ); 142 bool SortItems( wxListCtrlCompare fn, wxIntPtr data ); 143 144 // do we have a header window? HasHeader()145 bool HasHeader() const 146 { return InReportView() && !HasFlag(wxLC_NO_HEADER); } 147 148 // refresh items selectively (only useful for virtual list controls) 149 void RefreshItem(long item); 150 void RefreshItems(long itemFrom, long itemTo); 151 152 virtual void EnableBellOnNoMatch(bool on = true); 153 154 #if WXWIN_COMPATIBILITY_2_6 155 // obsolete, don't use 156 wxDEPRECATED( int GetItemSpacing( bool isSmall ) const ); 157 #endif // WXWIN_COMPATIBILITY_2_6 158 159 160 // overridden base class virtuals 161 // ------------------------------ 162 GetDefaultAttributes()163 virtual wxVisualAttributes GetDefaultAttributes() const 164 { 165 return GetClassDefaultAttributes(GetWindowVariant()); 166 } 167 168 static wxVisualAttributes 169 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); 170 171 virtual void Update(); 172 173 174 // implementation only from now on 175 // ------------------------------- 176 177 // generic version extension, don't use in portable code 178 bool Update( long item ); 179 180 void OnInternalIdle( ); 181 182 // We have to hand down a few functions 183 virtual void Refresh(bool eraseBackground = true, 184 const wxRect *rect = NULL); 185 186 virtual bool SetBackgroundColour( const wxColour &colour ); 187 virtual bool SetForegroundColour( const wxColour &colour ); 188 virtual wxColour GetBackgroundColour() const; 189 virtual wxColour GetForegroundColour() const; 190 virtual bool SetFont( const wxFont &font ); 191 virtual bool SetCursor( const wxCursor &cursor ); 192 193 #if wxUSE_DRAG_AND_DROP 194 virtual void SetDropTarget( wxDropTarget *dropTarget ); 195 virtual wxDropTarget *GetDropTarget() const; 196 #endif 197 ShouldInheritColours()198 virtual bool ShouldInheritColours() const { return false; } 199 200 // implementation 201 // -------------- 202 203 wxImageList *m_imageListNormal; 204 wxImageList *m_imageListSmall; 205 wxImageList *m_imageListState; // what's that ? 206 bool m_ownsImageListNormal, 207 m_ownsImageListSmall, 208 m_ownsImageListState; 209 wxListHeaderWindow *m_headerWin; 210 wxListMainWindow *m_mainWin; 211 212 protected: 213 // Implement base class pure virtual methods. 214 long DoInsertColumn(long col, const wxListItem& info); 215 216 217 virtual bool DoPopupMenu( wxMenu *menu, int x, int y ); 218 219 virtual wxSize DoGetBestClientSize() const; 220 221 // return the text for the given column of the given item 222 virtual wxString OnGetItemText(long item, long column) const; 223 224 // return the icon for the given item. In report view, OnGetItemImage will 225 // only be called for the first column. See OnGetItemColumnImage for 226 // details. 227 virtual int OnGetItemImage(long item) const; 228 229 // return the icon for the given item and column. 230 virtual int OnGetItemColumnImage(long item, long column) const; 231 232 // it calls our OnGetXXX() functions 233 friend class WXDLLIMPEXP_FWD_CORE wxListMainWindow; 234 235 virtual wxBorder GetDefaultBorder() const; 236 237 virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size); 238 239 private: 240 void CreateOrDestroyHeaderWindowAsNeeded(); 241 void OnScroll( wxScrollWinEvent& event ); 242 void OnSize( wxSizeEvent &event ); 243 244 // we need to return a special WM_GETDLGCODE value to process just the 245 // arrows but let the other navigation characters through 246 #if defined(__WXMSW__) && !defined(__WXWINCE__) && !defined(__WXUNIVERSAL__) 247 virtual WXLRESULT 248 MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); 249 #endif // __WXMSW__ 250 251 WX_FORWARD_TO_SCROLL_HELPER() 252 253 DECLARE_EVENT_TABLE() 254 DECLARE_DYNAMIC_CLASS(wxGenericListCtrl) 255 }; 256 257 #if (!defined(__WXMSW__) || defined(__WXUNIVERSAL__)) && (!(defined(__WXMAC__) && wxOSX_USE_CARBON) || defined(__WXUNIVERSAL__ )) 258 /* 259 * wxListCtrl has to be a real class or we have problems with 260 * the run-time information. 261 */ 262 263 class WXDLLIMPEXP_CORE wxListCtrl: public wxGenericListCtrl 264 { DECLARE_DYNAMIC_CLASS(wxListCtrl)265 DECLARE_DYNAMIC_CLASS(wxListCtrl) 266 267 public: 268 wxListCtrl() {} 269 270 wxListCtrl(wxWindow *parent, wxWindowID winid = wxID_ANY, 271 const wxPoint& pos = wxDefaultPosition, 272 const wxSize& size = wxDefaultSize, 273 long style = wxLC_ICON, 274 const wxValidator &validator = wxDefaultValidator, 275 const wxString &name = wxListCtrlNameStr) wxGenericListCtrl(parent,winid,pos,size,style,validator,name)276 : wxGenericListCtrl(parent, winid, pos, size, style, validator, name) 277 { 278 } 279 280 }; 281 #endif // !__WXMSW__ || __WXUNIVERSAL__ 282 283 #endif // _WX_GENERIC_LISTCTRL_H_ 284