📄 uulistboxview.cpp
字号:
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Jabber
* Copyright (C) 2004 Xie Tian Lu http://sabber.jabberstudio.org/
*/
#include <w32std.h>
#include "UUListBoxView.h"
#include "UUListBoxModel.h"
#include "UUListItemDrawer.h"
#include "UUListItem.h"
CUUListBoxView::CUUListBoxView()
: iCurItemExpanded( EFalse )
{
}
CUUListBoxView::~CUUListBoxView()
{
delete iCTimer;
}
void CUUListBoxView::ConstructL(MListBoxModel* aListBoxModel, CListItemDrawer* aItemDrawer, CWsScreenDevice* aScreen, RWindowGroup* aGroupWin, RWindow* aWsWindow, const TRect& aDisplayArea, TInt aItemHeight)
{
CListBoxView::ConstructL( aListBoxModel, aItemDrawer, aScreen, aGroupWin, aWsWindow, aDisplayArea, aItemHeight );
iModel = aListBoxModel;
ConstructTimerL();
}
void CUUListBoxView::MoveCursorL(TCursorMovement aCursorMovement, TSelectionMode /* aSelectionMode */)
{
CUUListBoxModel* model = ( CUUListBoxModel* )iModel;
int totalNum = model->NumberOfItems();
int curItem = CurrentItemIndex();
switch ( aCursorMovement ) {
case ECursorNextItem:
curItem++;
break;
case ECursorPreviousItem:
curItem--;
break;
}
iCurrentItemIndex = curItem;
if ( iCurrentItemIndex < 0 )
iCurrentItemIndex = 0;
else if ( iCurrentItemIndex > totalNum - 1 )
iCurrentItemIndex = totalNum - 1;
CUUListItemDrawer* drawer = ( CUUListItemDrawer* )iItemDrawer;
if ( model->NeedShowIndex() )
drawer->ShowCurItemIndex( ETrue );
ShrinkCurrentItem();
iCTimer->Queue();
int topItem = CalcNewTopItemIndexSoItemIsVisible( curItem );
if ( topItem != iTopItemIndex )
SetTopItemIndex( topItem );
DrawItemRange( iTopItemIndex, iBottomItemIndex );
}
void CUUListBoxView::Draw(const TRect* /*aClipRect*/) const
{
//if ( ( ( CUUListBoxModel* )iModel )->ItemNumChanged() )
// AdjustItemIndice();
DrawItemRange( iTopItemIndex, iBottomItemIndex );
}
TInt CUUListBoxView::CalcNewTopItemIndexSoItemIsVisible(TInt aItemIndex) const
{
TInt idx = iTopItemIndex;
if ( aItemIndex > iBottomItemIndex ) {
idx = iTopItemIndex + aItemIndex - iBottomItemIndex;
} else if ( aItemIndex < iTopItemIndex ) {
if ( aItemIndex == iCurrentItemIndex )
idx = aItemIndex;
}
return idx;
}
void CUUListBoxView::CalcBottomItemIndex()
{
AdjustItemIndice();
}
void CUUListBoxView::DrawItemRange(TInt aStartItemIndex, TInt aEndItemIndex) const
{
TRect rect = ViewRect();
rect.iBr.iY += 2;
iItemDrawer->ClearRect( rect );
for ( int i = aStartItemIndex; i <= aEndItemIndex; i++ ) {
if ( i != iCurrentItemIndex )
DrawItem( i );
}
DrawItem( iCurrentItemIndex );
}
void CUUListBoxView::CalCurrentItemHeight()
{
CUUListItemDrawer* drawer = ( CUUListItemDrawer* )iItemDrawer;
drawer->ShowCurItemIndex( EFalse );
ExpandCurrentItem();
DrawItemRange( iTopItemIndex, iBottomItemIndex );
}
void CUUListBoxView::ExpandCurrentItem()
{
CUUListBoxModel* model = ( CUUListBoxModel* )iModel;
if ( iCurItemExpanded )
return;
if (((CUUListBoxModel *)iModel)->iItemNum)
{
iCurItemExtraHeight = model->GetItemAt(iCurrentItemIndex)->ViewLineNum();
if ( iCurItemExtraHeight > 0 )
iCurItemExpanded = ETrue;
if ( iCurItemExtraHeight > 2 )
iCurItemExtraHeight = 2;
iCurItemExtraHeight*=iItemHeight;
iCurItemHeight = iCurItemExtraHeight + iItemHeight;
CUUListItemDrawer* drawer = ( CUUListItemDrawer* )iItemDrawer;
drawer->SetCurItemExtraHeight( iCurItemExtraHeight );
AdjustItemIndice();
}
}
void CUUListBoxView::SetCurItemExpanded(TBool State)
{
iCurItemExpanded=State;
}
void CUUListBoxView::SetCurrentItemIndex(TInt Index)
{
iCurrentItemIndex=Index;
}
void CUUListBoxView::ShrinkCurrentItem()
{
if ( !iCurItemExpanded )
return;
iCurItemExpanded = EFalse;
iCurItemExtraHeight = 0;
iCurItemHeight = iCurItemExtraHeight + iItemHeight;
CUUListItemDrawer* drawer = ( CUUListItemDrawer* )iItemDrawer;
drawer->SetCurItemExtraHeight( iCurItemExtraHeight );
AdjustItemIndice();
}
TInt CUUListBoxView::NumberOfItemsFitInViewRect()
{
int h = iViewRect.Height() - iCurItemExtraHeight;
return h / iItemHeight;
}
TInt CUUListBoxView::CurrentItemIndex()
{
return iCurrentItemIndex;
}
void CUUListBoxView::AdjustItemIndice()
{
int totalNum = iModel->NumberOfItems();
if ( totalNum <= 0 )
return;
if ( iCurrentItemIndex < 0 )
iCurrentItemIndex = 0;
if ( iCurrentItemIndex > totalNum - 1 )
iCurrentItemIndex = totalNum - 1;
if ( iTopItemIndex < 0 )
iTopItemIndex = 0;
if ( iTopItemIndex > iCurrentItemIndex )
iTopItemIndex = iCurrentItemIndex;
if ( iBottomItemIndex < iCurrentItemIndex )
iBottomItemIndex = iCurrentItemIndex;
if ( iBottomItemIndex > totalNum - 1 )
iBottomItemIndex = totalNum - 1;
int curNum = iBottomItemIndex - iTopItemIndex + 1;
int posNum = NumberOfItemsFitInViewRect();
while ( curNum > posNum ) {
if ( iBottomItemIndex > iCurrentItemIndex ) {
iBottomItemIndex--;
} else if ( iTopItemIndex < iCurrentItemIndex ) {
iTopItemIndex++;
}
curNum--;
}
while ( curNum < posNum ) {
if ( iBottomItemIndex < totalNum - 1 )
iBottomItemIndex++;
else if ( iTopItemIndex > 0 )
iTopItemIndex--;
curNum++;
if ( curNum >= totalNum )
break;
}
CUUListItemDrawer* drawer = ( CUUListItemDrawer* )iItemDrawer;
drawer->SetItemIndice( iCurrentItemIndex, iTopItemIndex, iBottomItemIndex );
}
void CUUListBoxView::OnTimer( CUserTimer* /*aTimer*/ )
{
CalCurrentItemHeight();
}
const TInt KTimerInterval = 800000;
void CUUListBoxView::ConstructTimerL()
{
iCTimer = CUserTimer::NewL( KTimerInterval, this );
}
TInt CUUListBoxView::ItemHeight()
{
return iItemHeight;
}
CUUListItemDrawer* CUUListBoxView::ItemDrawer()
{
return (CUUListItemDrawer *)iItemDrawer;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -