您的位置:首页 > 大数据 > 人工智能

symbian 符合控件 滚动条How to Create a Scrollable Container

2010-06-10 18:03 501 查看
 

Contents

 [hide]
1 Need for a scrollable container

2 Creating the scrollable container

3 ConstructL function of CParentContainer & CChildContainer

4 Performing the layout of Containers

5 Scrolling Calculation

6 OfferKeyEventL

Need for a scrollable container

Now a days many controls are present in a single view making the visibility of the control an point to argue on due to the limited screen dimensions. One way to overcome the problem is by placing all the controls over the container and when you want to bring the particular control in the view you can just move all the controls by the offset value upwards and downwards But doing this is tedious and might be difficult to maintain in the future and not a good logic . The other way around is to use the property of CCoeControl to move entirely up and down along with its contents( moving the entire container up and down ) instead of moving all the controls. Below is the way to do it.

Note :- for simplicity functions related to scrolling are only implemented.

Creating the scrollable container

You need to create two compound controls CParentContainer & CChildContainer.

class CParentContainer:public CCoeControl
{
public:
TKeyResponse OfferKeyEventL(const TKeyEvent &aKeyEvent,TEventCode aType);

public:
RPointerArray<CCoeControl> iParentArray;
CChildContainer* iChildContainer;

};

class CChildContainer:public CCoeControl
{
public:
TKeyResponse OfferKeyEventL(const TKeyEvent &aKeyEvent,TEventCode aType);

public:
RPointerArray<CCoeControl> iChildArray;
CParentContainer* iParent
};

ConstructL function of CParentContainer & CChildContainer

/*
* @ param aRect  :-  Rect  passed for the application
*/
void CParentContainer  :: ConstructL(TRect &aRect)
{
CreateWindowL();
iChildContainer = CChildContainer::NewL( aRect);
iParentArray.Append(iChildContainer);
ActivateL();

}

/*
* @param  aRect  :-  Rect   with in which all  controls  should be shown
*/

void  CChildContainer::ConstructL(TRect & aRect,CParentContainer& aParent)
{
iParent = aParent;
// Create  1st  control
iChildArray.Append(iControl1);
// Create  2st  control
iChildArray.Append(iControl2);
// Create  nth  control
iChildArray.Append(iControln);

}

Performing the layout of Containers

void CParentContainer ::SetLayout()
{
SetExtent(Rect().iTl,Rect().Size());
iChildContainer-> SetLayout(Rect(),Rect().Width());

}

void CChildContainer::SetLayout(TPoint aPoint, TInt aWidth)
{

TInt newHeight = 0;

newHeight = iControl1.Size().iHeight + iControl2.Size().iHeight +....
.....+ iControln.Size().iHeight

// set the extent of  the container to the new height
SetExtent(aPoint, TSize(aWidth, newHeight));

}

Scrolling Calculation

/** Scroll the page up and down */
void CChildContainer :: ScrollTheContainer(TScrollDirection aDirection, TInt aMovePixels)
{
/** Get the current position */
TPoint iPosition  = Position();
/** If user press Up Key */
if(aDirection == EPageMovementUp)
{
/** move the container upward by adding aMovePixels to
Container Y co-ordinate */
}
/** if user press down key */
else if(aDirection == EPageMovementDown)
{
/** move the container downward by subtracting aMovePixels to
Container Y co-ordinate */
}
/** Set the position */
SetPosition(iPosition);

}

TBool CChildContainer :: UpMovementPossible()
{
if(Position().iY >= iParent.Rect().iTl.iY)
return EFalse;
else
return ETrue;
}

TBool CChildContainer:: DownMovementPossible()
{
if(Rect().Height() + Position().iY < iParent.Rect().iBr.iY )
return EFalse;
else
return ETrue;
}

OfferKeyEventL

TKeyResponse CChildContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
if(aType != EEventKey)
{
return EKeyWasNotConsumed;
}
switch (aKeyEvent.iScanCode)
{

case EStdKeyUpArrow :
{

if(!UpMovementPossible())
{
return EKeyWasNotConsumed;
}
else
{
TInt move_pixels = iParent.Rect().Height()* 0.10;
ScrollTheContainer(EPageMovementUp, move_pixels);
return EKeyWasConsumed;
}
break;
}

case EStdKeyDownArrow :
{

if(!DownMovementPossible())
{
return EKeyWasNotConsumed;
}
else
{
TInt move_pixels = iParent.Rect().Height()* 0.12;
ScrollTheContainer(EPageMovementDown, move_pixels);
return EKeyWasConsumed;
}
break;
}

};
return EKeyWasNotConsumed;
}

/* Offer KeyEventL of Parent Container*/
TKeyResponse CParentContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent,TEventCode aType )
{
TKeyResponse keyRes = EKeyWasNotConsumed;
if(aType != EEventKey)
{
return EKeyWasNotConsumed;
}

keyRes = iChildContainer->OfferKeyEventL(aKeyEvent,aType);
return keyRes;

// nothing to do here

}


Related Wiki Articles

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息