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 //----------------------------------------------------------------------------- 
  27 class WXDLLIMPEXP_FWD_CORE wxListHeaderWindow
; 
  28 class WXDLLIMPEXP_FWD_CORE wxListMainWindow
; 
  30 //----------------------------------------------------------------------------- 
  32 //----------------------------------------------------------------------------- 
  34 class WXDLLIMPEXP_CORE wxGenericListCtrl
: public wxControl
, 
  39     wxGenericListCtrl() : wxScrollHelper(this) 
  44     wxGenericListCtrl( wxWindow 
*parent
, 
  45                 wxWindowID winid 
= wxID_ANY
, 
  46                 const wxPoint 
&pos 
= wxDefaultPosition
, 
  47                 const wxSize 
&size 
= wxDefaultSize
, 
  48                 long style 
= wxLC_ICON
, 
  49                 const wxValidator
& validator 
= wxDefaultValidator
, 
  50                 const wxString 
&name 
= wxListCtrlNameStr
) 
  51             : wxScrollHelper(this) 
  53         Create(parent
, winid
, pos
, size
, style
, validator
, name
); 
  56     virtual ~wxGenericListCtrl(); 
  60     bool Create( wxWindow 
*parent
, 
  61                  wxWindowID winid 
= wxID_ANY
, 
  62                  const wxPoint 
&pos 
= wxDefaultPosition
, 
  63                  const wxSize 
&size 
= wxDefaultSize
, 
  64                  long style 
= wxLC_ICON
, 
  65                  const wxValidator
& validator 
= wxDefaultValidator
, 
  66                  const wxString 
&name 
= wxListCtrlNameStr
); 
  68     bool GetColumn( int col
, wxListItem
& item 
) const; 
  69     bool SetColumn( int col
, wxListItem
& item 
); 
  70     int GetColumnWidth( int col 
) const; 
  71     bool SetColumnWidth( int col
, int width
); 
  72     int GetCountPerPage() const; // not the same in wxGLC as in Windows, I think 
  73     wxRect 
GetViewRect() const; 
  75     bool GetItem( wxListItem
& info 
) const; 
  76     bool SetItem( wxListItem
& info 
) ; 
  77     long SetItem( long index
, int col
, const wxString
& label
, int imageId 
= -1 ); 
  78     int  GetItemState( long item
, long stateMask 
) const; 
  79     bool SetItemState( long item
, long state
, long stateMask
); 
  80     bool SetItemImage( long item
, int image
, int selImage 
= -1 ); 
  81     bool SetItemColumnImage( long item
, long column
, int image 
); 
  82     wxString 
GetItemText( long item
, int col 
= 0 ) const; 
  83     void SetItemText( long item
, const wxString
& str 
); 
  84     wxUIntPtr 
GetItemData( long item 
) const; 
  85     bool SetItemPtrData(long item
, wxUIntPtr data
); 
  86     bool SetItemData(long item
, long data
) { return SetItemPtrData(item
, data
); } 
  87     bool GetItemRect( long item
, wxRect
& rect
, int code 
= wxLIST_RECT_BOUNDS 
) const; 
  88     bool GetSubItemRect( long item
, long subItem
, wxRect
& rect
, int code 
= wxLIST_RECT_BOUNDS 
) const; 
  89     bool GetItemPosition( long item
, wxPoint
& pos 
) const; 
  90     bool SetItemPosition( long item
, const wxPoint
& pos 
); // not supported in wxGLC 
  91     int GetItemCount() const; 
  92     int GetColumnCount() const; 
  93     void SetItemSpacing( int spacing
, bool isSmall 
= false ); 
  94     wxSize 
GetItemSpacing() const; 
  95     void SetItemTextColour( long item
, const wxColour
& col
); 
  96     wxColour 
GetItemTextColour( long item 
) const; 
  97     void SetItemBackgroundColour( long item
, const wxColour 
&col
); 
  98     wxColour 
GetItemBackgroundColour( long item 
) const; 
  99     void SetItemFont( long item
, const wxFont 
&f
); 
 100     wxFont 
GetItemFont( long item 
) const; 
 101     int GetSelectedItemCount() const; 
 102     wxColour 
GetTextColour() const; 
 103     void SetTextColour(const wxColour
& col
); 
 104     long GetTopItem() const; 
 106     void SetSingleStyle( long style
, bool add 
= true ) ; 
 107     void SetWindowStyleFlag( long style 
); 
 108     void RecreateWindow() {} 
 109     long GetNextItem( long item
, int geometry 
= wxLIST_NEXT_ALL
, int state 
= wxLIST_STATE_DONTCARE 
) const; 
 110     wxImageList 
*GetImageList( int which 
) const; 
 111     void SetImageList( wxImageList 
*imageList
, int which 
); 
 112     void AssignImageList( wxImageList 
*imageList
, int which 
); 
 113     bool Arrange( int flag 
= wxLIST_ALIGN_DEFAULT 
); // always wxLIST_ALIGN_LEFT in wxGLC 
 116     bool DeleteItem( long item 
); 
 117     bool DeleteAllItems(); 
 118     bool DeleteAllColumns(); 
 119     bool DeleteColumn( int col 
); 
 121     void SetItemCount(long count
); 
 123     wxTextCtrl 
*EditLabel(long item
, 
 124                           wxClassInfo
* textControlClass 
= wxCLASSINFO(wxTextCtrl
)); 
 125     wxTextCtrl
* GetEditControl() const; 
 126     void Edit( long item 
) { EditLabel(item
); } 
 128     bool EnsureVisible( long item 
); 
 129     long FindItem( long start
, const wxString
& str
, bool partial 
= false ); 
 130     long FindItem( long start
, wxUIntPtr data 
); 
 131     long FindItem( long start
, const wxPoint
& pt
, int direction 
); // not supported in wxGLC 
 132     long HitTest( const wxPoint
& point
, int& flags
, long *pSubItem 
= NULL 
) const; 
 133     long InsertItem(wxListItem
& info
); 
 134     long InsertItem( long index
, const wxString
& label 
); 
 135     long InsertItem( long index
, int imageIndex 
); 
 136     long InsertItem( long index
, const wxString
& label
, int imageIndex 
); 
 137     long InsertColumn( long col
, wxListItem
& info 
); 
 138     long InsertColumn( long col
, const wxString
& heading
, 
 139                        int format 
= wxLIST_FORMAT_LEFT
, int width 
= -1 ); 
 140     bool ScrollList( int dx
, int dy 
); 
 141     bool SortItems( wxListCtrlCompare fn
, wxIntPtr data 
); 
 143     // are we in report mode? 
 144     bool InReportView() const { return HasFlag(wxLC_REPORT
); } 
 146     // are we in virtual report mode? 
 147     bool IsVirtual() const { return HasFlag(wxLC_VIRTUAL
); } 
 149     // do we have a header window? 
 150     bool HasHeader() const 
 151         { return InReportView() && !HasFlag(wxLC_NO_HEADER
); } 
 153     // refresh items selectively (only useful for virtual list controls) 
 154     void RefreshItem(long item
); 
 155     void RefreshItems(long itemFrom
, long itemTo
); 
 157 #if WXWIN_COMPATIBILITY_2_6 
 158     // obsolete, don't use 
 159     wxDEPRECATED( int GetItemSpacing( bool isSmall 
) const ); 
 160 #endif // WXWIN_COMPATIBILITY_2_6 
 163     // overridden base class virtuals 
 164     // ------------------------------ 
 166     virtual wxVisualAttributes 
GetDefaultAttributes() const 
 168         return GetClassDefaultAttributes(GetWindowVariant()); 
 171     static wxVisualAttributes
 
 172     GetClassDefaultAttributes(wxWindowVariant variant 
= wxWINDOW_VARIANT_NORMAL
); 
 174     virtual void Update(); 
 177     // implementation only from now on 
 178     // ------------------------------- 
 180     // generic version extension, don't use in portable code 
 181     bool Update( long item 
); 
 183     void OnInternalIdle( ); 
 185     // We have to hand down a few functions 
 186     virtual void Refresh(bool eraseBackground 
= true, 
 187                          const wxRect 
*rect 
= NULL
); 
 189     virtual bool SetBackgroundColour( const wxColour 
&colour 
); 
 190     virtual bool SetForegroundColour( const wxColour 
&colour 
); 
 191     virtual wxColour 
GetBackgroundColour() const; 
 192     virtual wxColour 
GetForegroundColour() const; 
 193     virtual bool SetFont( const wxFont 
&font 
); 
 194     virtual bool SetCursor( const wxCursor 
&cursor 
); 
 196 #if wxUSE_DRAG_AND_DROP 
 197     virtual void SetDropTarget( wxDropTarget 
*dropTarget 
); 
 198     virtual wxDropTarget 
*GetDropTarget() const; 
 201     virtual bool ShouldInheritColours() const { return false; } 
 202     virtual void SetFocus(); 
 207     wxImageList         
*m_imageListNormal
; 
 208     wxImageList         
*m_imageListSmall
; 
 209     wxImageList         
*m_imageListState
;  // what's that ? 
 210     bool                 m_ownsImageListNormal
, 
 211                          m_ownsImageListSmall
, 
 212                          m_ownsImageListState
; 
 213     wxListHeaderWindow  
*m_headerWin
; 
 214     wxListMainWindow    
*m_mainWin
; 
 217     virtual bool DoPopupMenu( wxMenu 
*menu
, int x
, int y 
); 
 219     // take into account the coordinates difference between the container 
 220     // window and the list control window itself here 
 221     virtual void DoClientToScreen( int *x
, int *y 
) const; 
 222     virtual void DoScreenToClient( int *x
, int *y 
) const; 
 224     virtual wxSize 
DoGetBestClientSize() const; 
 226     // return the text for the given column of the given item 
 227     virtual wxString 
OnGetItemText(long item
, long column
) const; 
 229     // return the icon for the given item. In report view, OnGetItemImage will 
 230     // only be called for the first column. See OnGetItemColumnImage for 
 232     virtual int OnGetItemImage(long item
) const; 
 234     // return the icon for the given item and column. 
 235     virtual int OnGetItemColumnImage(long item
, long column
) const; 
 237     // return the attribute for the item (may return NULL if none) 
 238     virtual wxListItemAttr 
*OnGetItemAttr(long item
) const; 
 240     // it calls our OnGetXXX() functions 
 241     friend class WXDLLIMPEXP_FWD_CORE wxListMainWindow
; 
 243     virtual wxBorder 
GetDefaultBorder() const; 
 245     virtual wxSize 
GetSizeAvailableForScrollTarget(const wxSize
& size
); 
 248     void CreateOrDestroyHeaderWindowAsNeeded(); 
 249     void OnScroll( wxScrollWinEvent
& event 
); 
 250     void OnSize( wxSizeEvent 
&event 
); 
 252     // we need to return a special WM_GETDLGCODE value to process just the 
 253     // arrows but let the other navigation characters through 
 254 #if defined(__WXMSW__) && !defined(__WXWINCE__) && !defined(__WXUNIVERSAL__) 
 256     MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
); 
 259     WX_FORWARD_TO_SCROLL_HELPER() 
 261     DECLARE_EVENT_TABLE() 
 262     DECLARE_DYNAMIC_CLASS(wxGenericListCtrl
) 
 265 #if (!defined(__WXMSW__) || defined(__WXUNIVERSAL__)) && (!(defined(__WXMAC__) && wxOSX_USE_CARBON) || defined(__WXUNIVERSAL__ )) 
 267  * wxListCtrl has to be a real class or we have problems with 
 268  * the run-time information. 
 271 class WXDLLIMPEXP_CORE wxListCtrl
: public wxGenericListCtrl
 
 273     DECLARE_DYNAMIC_CLASS(wxListCtrl
) 
 278     wxListCtrl(wxWindow 
*parent
, wxWindowID winid 
= wxID_ANY
, 
 279                const wxPoint
& pos 
= wxDefaultPosition
, 
 280                const wxSize
& size 
= wxDefaultSize
, 
 281                long style 
= wxLC_ICON
, 
 282                const wxValidator 
&validator 
= wxDefaultValidator
, 
 283                const wxString 
&name 
= wxListCtrlNameStr
) 
 284     : wxGenericListCtrl(parent
, winid
, pos
, size
, style
, validator
, name
) 
 289 #endif // !__WXMSW__ || __WXUNIVERSAL__ 
 291 #endif // _WX_GENERIC_LISTCTRL_H_