//--------------------------------------------------------------------------- #include #pragma hdrstop #include "TableViewUnit.h" //--------------------------------------------------------------------------- #pragma package(smart_init) //--------------------------------------------------------------------------- #define CelOFF 1 #define HgtERROR 0 //--------------------------------------------------------------------------- __fastcall TTableView::TTableView(TComponent* Owner) : TScrollView(Owner) { OnChangeSBPos = DoChgPos; OnChangeSize = DoChgSize; OnHgtTitle = DoHgtTitle; OnHgtBottom = DoHgtBottom; FIndFocus = NOSET; FIndSel = NOSET; FCount = 0; FHgtSmall = NOSET; m_Title = NULL; m_Bottom = NULL; OnMouseWheel = DoMouseWheel; } //--------------------------------------------------------------------------- __fastcall TTableView::~TTableView() { DoTableInit(); } //--------------------------------------------------------------------------- bool __fastcall TTableView::ReloadData(int iCellIndex, SBS iSBS, int iTopline) { bool bRet = true; DoTableInit(); if( FOnTitle ) { //set title m_Title = (TPanelDB *)FOnTitle(this); if( m_Title ) m_Title->Parent = this; } if( FOnBottom ) { //set Bottom m_Bottom = (TPanelDB *)FOnBottom(this); if( m_Bottom ) m_Bottom->Parent = this; } if( FOnCellHgt && FOnMDNum && FOnMDCell ) { m_DBNum = FOnMDNum(this); //set data num if( m_DBNum<=0 ) bRet = false; if( bRet ) { for( int index=0; indexm_VCHGT[i] ) iSmlHgt = m_VCHGT[i]; } int iSmlHgtTmp = iSmlHgt; if(iSmlHgt>nHeight) iSmlHgtTmp = iSmlHgt = (iSmlHgt-nHeight)%nHeight; if( (HgtSmall!=NOSET) && (HgtSmall=nHeight ) { iCellShowNum = nHeight/iSmlHgt; m_PosPage = nHeight/iSmlHgtTmp; bSBOK = true; } } } //get sb info m_PosTotal = iPosNumTotal; //no sb will show if(iCellShowHgt needs cell //merge if(m_UIOff-Offset<0) { bMerge = true; if(m_UIOff!=0){ iCellChgNum = Offset - m_UIOff; }else{ iCellChgNum = Offset; } m_IndTop -= iCellChgNum; m_UIOff = 0; //--------------when just show between needs cell }else{ bMerge = false; iCellChgNum = 0; m_UIOff -= Offset; } } break; case CELLS_Down: { //--------------when just show > needs cell //merge if(m_UIOff+Offset>m_UIOffMerge || m_UIOff==1) { bMerge = true; if(m_UIOff> save the change cells's source index if(iCelInd> iCellTop if( m_IndBeg-m_UIOffMerge<=iIndTop+iCelInd && iIndTop+iCelInd=GetCellBom() ) bVisible = false; return bVisible; } //--------------------------------------------------------------------------- int __fastcall TTableView::getContentHeight() { int nHeight = Height; if( m_Title ) nHeight -= m_Title->Height; if( m_Bottom ) nHeight -= m_Bottom->Height; return nHeight; } //--------------------------------------------------------------------------- TStateBtn* __fastcall TTableView::GetCellAds(int iCellIndex) { TStateBtn *rowCellTmp = NULL; int index = 0; BTNLST::iterator lst_FCell; for( lst_FCell = (m_LstBtn).begin(); lst_FCell != (m_LstBtn).end(); lst_FCell++) { if(m_IndTop+index == iCellIndex){ rowCellTmp = *lst_FCell; break; } index++; } return rowCellTmp; } //--------------------------------------------------------------------------- int __fastcall TTableView::GetCellHgt(int iCellIndex) { if( 0<=iCellIndex && iCellIndex<=m_DBNum-1 ) return m_VCHGT[iCellIndex]; return 0; } //--------------------------------------------------------------------------- int __fastcall TTableView::GetCellBeg() { return m_IndBeg; } //--------------------------------------------------------------------------- int __fastcall TTableView::GetCellBom() { int nHeight = m_RtContent.Height(); int indBeg = m_IndBeg; int iCurTop = m_HgtOver; int index = 0; for( ; index=nHeight ) break; } return indBeg+index+1; } //--------------------------------------------------------------------------- int __fastcall TTableView::GetCellNum() { return m_DBNum; } //--------------------------------------------------------------------------- void __fastcall TTableView::SetCellInd(int iCellIndex) { if( iCellIndex<0 || iCellIndex>m_DBNum-1) return; int iTopLine = 0; if( iCellIndex!=0 ) iTopLine = m_VCPOS[iCellIndex-1]; SetSBPos(SBS_POS, iTopLine); } //--------------------------------------------------------------------------- void __fastcall TTableView::SetSBPos(SBS iSBS, int iTopline) { short ScrollCode = iSBS; if(iSBS==SBS_TOP){ iTopline = 0; }else if(iSBS==SBS_BOTTOM){ iTopline = m_PosTotal-m_PosPage; } DoChgPos(this, ScrollCode, iTopline); SetSB(m_PosTotal, m_PosPage, m_PosBegin); } //--------------------------------------------------------------------------- void __fastcall TTableView::DoChgPos(TObject *Sender, short ScrollCode, int iTopLine) { if( iTopLine<0 ) { iTopLine = 0; } else if(iTopLine>m_PosTotal-m_PosPage ) { iTopLine = m_PosTotal-m_PosPage; } if( m_bTop && (ScrollCode==SB_LINEUP||ScrollCode==SB_PAGEUP ) ){ if(FOnMDTop) FOnMDTop(this); return; } else if( m_bBom && (ScrollCode==SB_LINEDOWN||ScrollCode==SB_PAGEDOWN ) ){ if(FOnMDBottom) FOnMDBottom(this); return; } else if( iTopLine<0 || iTopLine>m_PosTotal ) return; m_bTop = (0==iTopLine)?true:false; m_bBom = (m_PosTotal-m_PosPage==iTopLine)?true:false; //get CELLS CELLS eCELLS; if(abs(m_PosBegin-iTopLine)>=m_PosPage+2) eCELLS = CELLS_Page; else if(m_PosBeginiTopLine) eCELLS = CELLS_Up; //get new m_IndBeg int iIndChange, iPosCur, iPosPre; iIndChange = iPosCur = iPosPre = 0; int front, end, mid; front = 0; end = m_VCPOS.size()-1; mid = (front+end)/2; VCINT::iterator vc_FPos = (m_VCPOS).begin(); iPosCur = *(vc_FPos+mid); if(mid==0) iPosPre = 0; else iPosPre = *(vc_FPos+mid-1); while( front<=end ) { if(iPosPre<=iTopLine && iTopLineiTopLine) end = mid; mid = (front+end)/2; iPosCur = *(vc_FPos+mid); if(mid==0) iPosPre = 0; else iPosPre = *(vc_FPos+mid-1); } //get new m_IndBeg to it's pre index >> m_HgtOver int iPosBeginNum = 0; if( iIndChange != 0 ) iPosBeginNum = *(m_VCPOS.begin()+iIndChange-1); int iABS = abs(iPosBeginNum-iTopLine); m_HgtOver = -iABS*m_HgtSmall; if( iIndChange!=m_IndBeg ) { //change m_IndBeg int indBeginTmp = m_IndBeg; m_IndBeg = iIndChange; DoLstChg( eCELLS, abs(indBeginTmp-iIndChange) ); }else { //change m_IndBeg over hegiht Paint(); } m_PosBegin = iTopLine; } //--------------------------------------------------------------------------- int __fastcall TTableView::DoHgtTitle(TObject *Sender) { if( m_Title) return m_Title->Height; return 0; } //--------------------------------------------------------------------------- int __fastcall TTableView::DoHgtBottom(TObject *Sender) { if( m_Bottom) return m_Bottom->Height; return 0; } //--------------------------------------------------------------------------- void __fastcall TTableView::DoPaintLst(TCanvas *pCanvas) { int iTop, iLeft, iWidth, iHeight; iTop = m_HgtTop + m_HgtOver + m_RtContent.Top; iLeft = m_RtContent.Left; iWidth = m_RtContent.Width(); int iIndex = 0; for(BTNLST::iterator lstBtn=m_LstBtn.begin(); lstBtn!=m_LstBtn.end(); lstBtn++) { if(m_IndTop+iIndex>m_VCHGT.size()-1) { break; } iHeight = m_VCHGT[m_IndTop+iIndex]; (*lstBtn)->SetBounds( iLeft, iTop, iWidth, iHeight ); (*lstBtn)->Paint(pCanvas); iTop += iHeight; iIndex++; } } //---------------------------------------------------------------------------