Scrollbar events in 5th edition

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();
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章