symbian 符合控件 滚动条How to Create a Scrollable Container
2010-06-10 18:03
501 查看
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
相关文章推荐
- [android]How to implement an not editable scrollable EditText?(如何实现一个不可编辑的带滚动条的EditText?) .
- How to Interactively Create a Docker Container
- How to create a Symbian application icon (SVG)
- how to sign an assembly with a strong name & how to create a pair key怎样通过强名给程序集签名以及如何创建钥匙对?
- How to Create a Automated Task that Runs at a Set Time in Windows 7
- How to Create an Reusable Components for Your Project
- How to use ComboBox Control in VC++ - 在VC中如何使用 ComboBox 控件
- How to create physical standby database with 11g RMAN DUPLICATE FROM ACTIVE DATABASE [ID 747250.1]
- 如何在SharePoint 2013 创建Power pivot 库(How to create a PowerPivot Gallery )及错误解决方法
- you have to know about how to create user defined control.
- How To Create An ASM Diskgroup Using XML code Thru ASMCMD?
- How To Create A Mole Whacking Game with Cocos2D: Part 1/2
- How to create a resizeable dialog box with scroll bars in Visual C++
- How to create a pure Swift module
- How To Create Your Own Personal Document Viewer (Like Scribd or Google Books)
- [转]POI : How to Create and Use User Defined Functions
- How to Create a SharePoint 2010 Project Without SharePoint Server
- how to create pooled table or cluster table
- STL template&Container--how to change normal function into generic function.
- How to Create a Microsoft .NET Compact Framework-based Image Button