1 ///////////////////////////////////////////////////////////////////////////// 2 // Name: wx/generic/dataview.h 3 // Purpose: wxDataViewCtrl generic implementation header 4 // Author: Robert Roebling 5 // Id: $Id: dataview.h 53135 2008-04-12 02:31:04Z VZ $ 6 // Copyright: (c) 1998 Robert Roebling 7 // Licence: wxWindows licence 8 ///////////////////////////////////////////////////////////////////////////// 9 10 #ifndef __GENERICDATAVIEWCTRLH__ 11 #define __GENERICDATAVIEWCTRLH__ 12 13 #include "wx/defs.h" 14 #include "wx/object.h" 15 #include "wx/list.h" 16 #include "wx/control.h" 17 #include "wx/scrolwin.h" 18 #include "wx/icon.h" 19 20 // --------------------------------------------------------- 21 // classes 22 // --------------------------------------------------------- 23 24 class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl; 25 class WXDLLIMPEXP_FWD_ADV wxDataViewMainWindow; 26 class WXDLLIMPEXP_FWD_ADV wxDataViewHeaderWindow; 27 28 // --------------------------------------------------------- 29 // wxDataViewRenderer 30 // --------------------------------------------------------- 31 32 class WXDLLIMPEXP_ADV wxDataViewRenderer: public wxDataViewRendererBase 33 { 34 public: 35 wxDataViewRenderer( const wxString &varianttype, wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT ); 36 virtual ~wxDataViewRenderer(); 37 38 virtual bool Render( wxRect cell, wxDC *dc, int state ) = 0; 39 virtual wxSize GetSize() = 0; 40 Activate(wxRect WXUNUSED (cell),wxDataViewListModel * WXUNUSED (model),unsigned int WXUNUSED (col),unsigned int WXUNUSED (row))41 virtual bool Activate( wxRect WXUNUSED(cell), 42 wxDataViewListModel *WXUNUSED(model), 43 unsigned int WXUNUSED(col), 44 unsigned int WXUNUSED(row) ) 45 { return false; } 46 LeftClick(wxPoint WXUNUSED (cursor),wxRect WXUNUSED (cell),wxDataViewListModel * WXUNUSED (model),unsigned int WXUNUSED (col),unsigned int WXUNUSED (row))47 virtual bool LeftClick( wxPoint WXUNUSED(cursor), 48 wxRect WXUNUSED(cell), 49 wxDataViewListModel *WXUNUSED(model), 50 unsigned int WXUNUSED(col), 51 unsigned int WXUNUSED(row) ) 52 { return false; } RightClick(wxPoint WXUNUSED (cursor),wxRect WXUNUSED (cell),wxDataViewListModel * WXUNUSED (model),unsigned int WXUNUSED (col),unsigned int WXUNUSED (row))53 virtual bool RightClick( wxPoint WXUNUSED(cursor), 54 wxRect WXUNUSED(cell), 55 wxDataViewListModel *WXUNUSED(model), 56 unsigned int WXUNUSED(col), 57 unsigned int WXUNUSED(row) ) 58 { return false; } StartDrag(wxPoint WXUNUSED (cursor),wxRect WXUNUSED (cell),wxDataViewListModel * WXUNUSED (model),unsigned int WXUNUSED (col),unsigned int WXUNUSED (row))59 virtual bool StartDrag( wxPoint WXUNUSED(cursor), 60 wxRect WXUNUSED(cell), 61 wxDataViewListModel *WXUNUSED(model), 62 unsigned int WXUNUSED(col), 63 unsigned int WXUNUSED(row) ) 64 { return false; } 65 66 // Create DC on request 67 virtual wxDC *GetDC(); 68 69 private: 70 wxDC *m_dc; 71 72 protected: 73 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer) 74 }; 75 76 // --------------------------------------------------------- 77 // wxDataViewCustomRenderer 78 // --------------------------------------------------------- 79 80 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewRenderer 81 { 82 public: 83 wxDataViewCustomRenderer( const wxString &varianttype = wxT("string"), 84 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT ); 85 86 protected: 87 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer) 88 }; 89 90 // --------------------------------------------------------- 91 // wxDataViewTextRenderer 92 // --------------------------------------------------------- 93 94 class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewCustomRenderer 95 { 96 public: 97 wxDataViewTextRenderer( const wxString &varianttype = wxT("string"), 98 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT ); 99 100 bool SetValue( const wxVariant &value ); 101 bool GetValue( wxVariant &value ); 102 103 bool Render( wxRect cell, wxDC *dc, int state ); 104 wxSize GetSize(); 105 106 private: 107 wxString m_text; 108 109 protected: 110 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer) 111 }; 112 113 // --------------------------------------------------------- 114 // wxDataViewBitmapRenderer 115 // --------------------------------------------------------- 116 117 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewCustomRenderer 118 { 119 public: 120 wxDataViewBitmapRenderer( const wxString &varianttype = wxT("wxBitmap"), 121 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT ); 122 123 bool SetValue( const wxVariant &value ); 124 bool GetValue( wxVariant &value ); 125 126 bool Render( wxRect cell, wxDC *dc, int state ); 127 wxSize GetSize(); 128 129 private: 130 wxIcon m_icon; 131 wxBitmap m_bitmap; 132 133 protected: 134 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer) 135 }; 136 137 // --------------------------------------------------------- 138 // wxDataViewToggleRenderer 139 // --------------------------------------------------------- 140 141 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewCustomRenderer 142 { 143 public: 144 wxDataViewToggleRenderer( const wxString &varianttype = wxT("bool"), 145 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT ); 146 147 bool SetValue( const wxVariant &value ); 148 bool GetValue( wxVariant &value ); 149 150 bool Render( wxRect cell, wxDC *dc, int state ); 151 bool Activate( wxRect cell, wxDataViewListModel *model, unsigned int col, unsigned int row ); 152 wxSize GetSize(); 153 154 private: 155 bool m_toggle; 156 157 protected: 158 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer) 159 }; 160 161 // --------------------------------------------------------- 162 // wxDataViewProgressRenderer 163 // --------------------------------------------------------- 164 165 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer 166 { 167 public: 168 wxDataViewProgressRenderer( const wxString &label = wxEmptyString, 169 const wxString &varianttype = wxT("long"), 170 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT ); 171 virtual ~wxDataViewProgressRenderer(); 172 173 bool SetValue( const wxVariant &value ); 174 175 virtual bool Render( wxRect cell, wxDC *dc, int state ); 176 virtual wxSize GetSize(); 177 178 private: 179 wxString m_label; 180 int m_value; 181 182 protected: 183 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer) 184 }; 185 186 // --------------------------------------------------------- 187 // wxDataViewDateRenderer 188 // --------------------------------------------------------- 189 190 class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer 191 { 192 public: 193 wxDataViewDateRenderer( const wxString &varianttype = wxT("datetime"), 194 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE ); 195 196 bool SetValue( const wxVariant &value ); 197 198 virtual bool Render( wxRect cell, wxDC *dc, int state ); 199 virtual wxSize GetSize(); 200 virtual bool Activate( wxRect cell, 201 wxDataViewListModel *model, unsigned int col, unsigned int row ); 202 203 private: 204 wxDateTime m_date; 205 206 protected: 207 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer) 208 }; 209 210 // --------------------------------------------------------- 211 // wxDataViewColumn 212 // --------------------------------------------------------- 213 214 class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase 215 { 216 public: 217 wxDataViewColumn( const wxString &title, wxDataViewRenderer *renderer, unsigned int model_column, 218 int width = 80, int flags = wxDATAVIEW_COL_RESIZABLE ); 219 wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *renderer, unsigned int model_column, 220 int width = 80, int flags = wxDATAVIEW_COL_RESIZABLE ); 221 virtual ~wxDataViewColumn(); 222 223 virtual void SetTitle( const wxString &title ); 224 virtual void SetBitmap( const wxBitmap &bitmap ); 225 226 virtual void SetAlignment( wxAlignment align ); 227 228 virtual void SetSortable( bool sortable ); 229 virtual bool GetSortable(); 230 virtual void SetSortOrder( bool ascending ); 231 virtual bool IsSortOrderAscending(); 232 233 virtual int GetWidth(); 234 235 private: 236 int m_width; 237 int m_fixedWidth; 238 239 protected: 240 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn) 241 }; 242 243 // --------------------------------------------------------- 244 // wxDataViewCtrl 245 // --------------------------------------------------------- 246 247 class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase, 248 public wxScrollHelperNative 249 { 250 public: wxDataViewCtrl()251 wxDataViewCtrl() : wxScrollHelperNative(this) 252 { 253 Init(); 254 } 255 256 wxDataViewCtrl( wxWindow *parent, wxWindowID id, 257 const wxPoint& pos = wxDefaultPosition, 258 const wxSize& size = wxDefaultSize, long style = 0, 259 const wxValidator& validator = wxDefaultValidator ) wxScrollHelperNative(this)260 : wxScrollHelperNative(this) 261 { 262 Create(parent, id, pos, size, style, validator ); 263 } 264 265 virtual ~wxDataViewCtrl(); 266 267 void Init(); 268 269 bool Create(wxWindow *parent, wxWindowID id, 270 const wxPoint& pos = wxDefaultPosition, 271 const wxSize& size = wxDefaultSize, long style = 0, 272 const wxValidator& validator = wxDefaultValidator ); 273 274 virtual bool AssociateModel( wxDataViewListModel *model ); 275 virtual bool AppendColumn( wxDataViewColumn *col ); 276 277 virtual void SetSelection( int row ); // -1 for unselect 278 virtual void SetSelectionRange( unsigned int from, unsigned int to ); 279 virtual void SetSelections( const wxArrayInt& aSelections); 280 virtual void Unselect( unsigned int row ); 281 282 virtual bool IsSelected( unsigned int row ) const; 283 virtual int GetSelection() const; 284 virtual int GetSelections(wxArrayInt& aSelections) const; 285 286 private: 287 friend class wxDataViewMainWindow; 288 friend class wxDataViewHeaderWindow; 289 wxDataViewListModelNotifier *m_notifier; 290 wxDataViewMainWindow *m_clientArea; 291 wxDataViewHeaderWindow *m_headerArea; 292 293 private: 294 void OnSize( wxSizeEvent &event ); 295 296 // we need to return a special WM_GETDLGCODE value to process just the 297 // arrows but let the other navigation characters through 298 #ifdef __WXMSW__ 299 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); 300 #endif // __WXMSW__ 301 302 WX_FORWARD_TO_SCROLL_HELPER() 303 304 private: 305 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl) 306 DECLARE_NO_COPY_CLASS(wxDataViewCtrl) 307 DECLARE_EVENT_TABLE() 308 }; 309 310 311 #endif // __GENERICDATAVIEWCTRLH__ 312