1 // This file is part of VSTGUI. It is subject to the license terms 2 // in the LICENSE file found in the top-level directory of this 3 // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE 4 5 #ifndef __cdatabrowser__ 6 #define __cdatabrowser__ 7 8 #include "vstguifwd.h" 9 #include "cscrollview.h" 10 #include "cfont.h" 11 #include "ccolor.h" 12 #include "cstring.h" 13 #include <vector> 14 15 namespace VSTGUI { 16 17 // forward private internal views 18 class CDataBrowserView; 19 class CDataBrowserHeader; 20 21 //----------------------------------------------------------------------------- 22 // CDataBrowser Declaration 23 //! @brief DataBrowser view 24 /// @ingroup controls 25 //----------------------------------------------------------------------------------------------- 26 class CDataBrowser : public CScrollView 27 { 28 protected: 29 enum 30 { 31 kDrawRowLinesFlag = kLastScrollViewStyleFlag, 32 kDrawColumnLinesFlag, 33 kDrawHeaderFlag, 34 kMultiSelectionStyleFlag 35 }; 36 37 public: 38 CDataBrowser (const CRect& size, IDataBrowserDelegate* db, int32_t style = 0, CCoord scrollbarWidth = 16, CBitmap* pBackground = nullptr); 39 40 enum CDataBrowserStyle 41 { 42 // see CScrollView for more styles 43 kDrawRowLines = 1 << kDrawRowLinesFlag, 44 kDrawColumnLines = 1 << kDrawColumnLinesFlag, 45 kDrawHeader = 1 << kDrawHeaderFlag, 46 kMultiSelectionStyle = 1 << kMultiSelectionStyleFlag 47 }; 48 49 enum 50 { 51 kNoSelection = -1 52 }; 53 54 /// @brief CDataBrowser Cell position description 55 struct Cell { 56 int32_t row {-1}; 57 int32_t column {-1}; 58 59 Cell () = default; CellCell60 Cell (int32_t row, int32_t column) : row (row), column (column) {} isValidCell61 bool isValid () const { return row > -1 && column > -1; } 62 }; 63 64 using Selection = std::vector<int32_t>; 65 66 //----------------------------------------------------------------------------- 67 /// @name CDataBrowser Methods 68 //----------------------------------------------------------------------------- 69 //@{ 70 /** trigger recalculation, call if numRows or numColumns changed */ 71 virtual void recalculateLayout (bool rememberSelection = false); 72 /** invalidates an individual cell */ 73 virtual void invalidate (const Cell& cell); 74 /** invalidates a complete row */ 75 virtual void invalidateRow (int32_t row); 76 /** scrolls the scrollview so that row is visible */ 77 virtual void makeRowVisible (int32_t row); 78 79 /** get bounds of a cell */ 80 virtual CRect getCellBounds (const Cell& cell); 81 /** get the cell at position where */ 82 virtual Cell getCellAt (const CPoint& where) const; 83 84 /** get first selected row */ 85 virtual int32_t getSelectedRow () const; 86 /** set the exclusive selected row */ 87 virtual void setSelectedRow (int32_t row, bool makeVisible = false); 88 89 /** get all selected rows */ getSelection()90 const Selection& getSelection () const { return selection; } 91 /** add row to selection */ 92 virtual void selectRow (int32_t row); 93 /** remove row from selection */ 94 virtual void unselectRow (int32_t row); 95 /** empty selection */ 96 virtual void unselectAll (); 97 98 /** starts a text edit for a cell */ 99 virtual void beginTextEdit (const Cell& cell, UTF8StringPtr initialText); 100 101 /** get delegate object */ getDelegate()102 IDataBrowserDelegate* getDelegate () const { return db; } 103 //@} 104 105 void setAutosizeFlags (int32_t flags) override; 106 void setViewSize (const CRect& size, bool invalid) override; 107 void setWantsFocus (bool state) override; 108 109 int32_t onKeyDown (VstKeyCode& keyCode) override; 110 CMouseEventResult onMouseDown (CPoint& where, const CButtonState& buttons) override; 111 protected: 112 ~CDataBrowser () noexcept override; 113 void valueChanged (CControl *pControl) override; 114 CMessageResult notify (CBaseObject* sender, IdStringPtr message) override; 115 bool attached (CView *parent) override; 116 bool removed (CView* parent) override; 117 bool wantsFocus () const override; 118 119 void recalculateSubViews () override; 120 void validateSelection (); 121 122 IDataBrowserDelegate* db; 123 CDataBrowserView* dbView; 124 CDataBrowserHeader* dbHeader; 125 CViewContainer* dbHeaderContainer; 126 Selection selection; 127 }; 128 129 //----------------------------------------------------------------------------- 130 } // VSTGUI 131 132 #endif 133