1 /* 2 * Part of WCM Commander 3 * https://github.com/corporateshark/WCMCommander 4 * wcm@linderdaum.com 5 */ 6 7 #pragma once 8 9 #include "swl/swl.h" 10 11 template <typename ContainerItemType> 12 class iContainerListWin: public VListWin 13 { 14 public: iContainerListWin(Win * parent,std::vector<ContainerItemType> * Items)15 iContainerListWin( Win* parent, std::vector<ContainerItemType>* Items ) 16 : VListWin( Win::WT_CHILD, WH_TABFOCUS | WH_CLICKFOCUS, 0, parent, VListWin::SINGLE_SELECT, VListWin::BORDER_3D, 0 ) 17 , m_ItemList( Items ) 18 { 19 wal::GC gc( this ); 20 gc.Set( GetFont() ); 21 cpoint ts = gc.GetTextExtents( ABCString ); 22 //int fontW = ( ts.x / ABCStringLen ); 23 int fontH = ts.y + 2; 24 25 this->SetItemSize( ( fontH > 16 ? fontH : 16 ) + 1, 100 ); 26 27 SetCount( m_ItemList->size() ); 28 SetCurrent( 0 ); 29 30 LSize ls; 31 ls.x.maximal = 10000; 32 ls.x.ideal = 500; 33 ls.x.minimal = 300; 34 35 ls.y.maximal = 10000; 36 ls.y.ideal = 300; 37 ls.y.minimal = 200; 38 39 SetLSize( ls ); 40 } ~iContainerListWin()41 virtual ~iContainerListWin() {}; 42 GetCurrentData()43 const ContainerItemType* GetCurrentData( ) const 44 { 45 int n = GetCurrent( ); 46 47 if ( n < 0 || n >= ( int )m_ItemList->size() ) { return nullptr; } 48 49 return &( m_ItemList->at( n ) ); 50 } 51 GetCurrentData()52 ContainerItemType* GetCurrentData( ) 53 { 54 int n = GetCurrent( ); 55 56 if ( n < 0 || n >= ( int )m_ItemList->size() ) { return nullptr; } 57 58 return &( m_ItemList->at( n ) ); 59 } 60 Ins(const ContainerItemType & p)61 void Ins( const ContainerItemType& p ) 62 { 63 m_ItemList->push_back( p ); 64 SetCount( m_ItemList->size( ) ); 65 SetCurrent( ( int )m_ItemList->size() - 1 ); 66 CalcScroll(); 67 Invalidate(); 68 } 69 Del()70 void Del() 71 { 72 int n = GetCurrent(); 73 74 if ( n < 0 || n >= ( int )m_ItemList->size( ) ) { return; } 75 76 m_ItemList->erase( m_ItemList->begin( ) + n ); 77 78 SetCount( m_ItemList->size( ) ); 79 CalcScroll(); 80 Invalidate(); 81 } 82 Rename(const ContainerItemType & p)83 void Rename( const ContainerItemType& p ) 84 { 85 int n = GetCurrent(); 86 87 if ( n < 0 || n >= ( int )m_ItemList->size( ) ) { return; } 88 89 m_ItemList->at( n ) = p; 90 CalcScroll(); 91 Invalidate(); 92 } 93 94 virtual void DrawItem( wal::GC& gc, int n, crect rect ) = 0; 95 96 protected: 97 std::vector<ContainerItemType>* m_ItemList; 98 }; 99