Scrollbar events in 5th edition

本文介绍了一个自定义控件中滚动条的方向和移动跨度的实现方法。通过Symbian C++编程,详细展示了如何创建滚动条、定义滚动条大小,并处理滚动事件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

This article demonstrates how to get the scrollbar direction and movement spans.

Header:

 

class CMyControl: public CCoeControl, public MEikScrollBarObserver
{
     public:// Constructors and destructor
        ~CMyControl();
        static CMyControl* NewL(TRect aRect);
        static CMyControl* NewLC(TRect aRect);
 
     private:
         CMyControl();
         void ConstructL(TRect aRect);
         void Draw( const TRect& aRect ) const;
         virtual void HandlePointerEventL(const TPointerEvent& aPointerEvent);
         TInt CountComponentControls() const;
         CCoeControl* ComponentControl( TInt aIndex ) const;
         void CreateScrollBar();
 
     private:///MEikScrollBarObserver
         void HandleScrollEventL(CEikScrollBar*  aScrollBar,TEikScrollEvent aEventType );
 
     protected:
         void SizeChanged();
 
 
     private:
        CEikScrollBarFrame* iSBFrame;
        TInt                iScrollSpan;
        TInt                iScrollPos;
TBool iIsScrollDown;
 
};

 

Cpp: 

 

// Implementation of scroll bar in custom control along with number of movement by scrollbar in one Drag.
// ScrollBar in symbian c++ ("Symbian c++").
 
void CMyControl::CreateScrollBar()
{
         iScrollPos=-1;// initial scroll pos is -1 as 0 specify the first span/drag.
         iScrollSpan=1;// scrollbar moves by one item at a time
         iSBFrame=new ( ELeave ) CEikScrollBarFrame( this,this);   
         iSBFrame
->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,CEikScrollBarFrame::EOn); 
         iSBFrame
->CreateDoubleSpanScrollBarsL(ETrue, EFalse);// create scrollbar
         iSBFrame->SetTypeOfVScrollBar(CEikScrollBarFrame::EDoubleSpan);//type of scrollbar
}
 
void CMyControl::SizeChanged()
{
        
// Here you are required to define the size of your scrollbar//
          TInt listStatusPaneHeight=60;
          TEikScrollBarFrameLayout layout;
          TEikScrollBarModel       myModel;
          TEikScrollBarModel       myModel2;
          myModel.iThumbSpan=1;
          myModel.iScrollSpan =iScrollSpan;   
          layout.
iTilingMode=TEikScrollBarFrameLayout::EInclusiveRectConstant;           
          TRect fullRect
=TRect(TPoint(Rect().iTl.iX,Rect().iTl.iY+listStatusPaneHeight),TSize(Rect().Size().iWidth,Rect ().Size().iHeight-listStatusPaneHeight));
          TRect inclRect = fullRect;
          if(iSBFrame)
      {
            TBool stat = iSBFrame->TileL(&myModel2, &myModel, fullRect, inclRect, layout);
        iSBFrame->DrawScrollBarsNow();
          }
    }
 
 
 
void CMyControl::HandleScrollEventL(CEikScrollBar*  aScrollBar,TEikScrollEvent aEventType )
        {
        switch(aEventType)
           {
             case EEikScrollThumbDragVert:
                 {
                   CEikScrollBar* sb=  iSBFrame->VerticalScrollBar();// get an object of your scroll bar
                   TInt pos=sb->ThumbPosition();/// it will provide new position of scrollbar
                  if(iScrollPos<pos)
                   {
                     iScrollPos=pos;/// moving down number of scroll span
                     iIsScrollDown=ETrue;
                   }
                  else
                   {
                     iScrollPos=pos;/// moving down number of scroll span
                     iIsScrollDown=EFalse;
                   }
                  DrawNow();
                  break;
                }
             case EEikScrollThumbReleaseVert:
                  break;
             default:
                  break;
            }
        }

Usage: 

// get an object of your scroll bar type 
CEikScrollBar* sb = iSBFrame->VerticalScrollBar();
 
// it starts with 0 depicting your first scroll, every time you scroll your thumb position changes
// with number of scroll movement in one drag.
TInt pos=sb->ThumbPosition();
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值