Scrollbar events in 5th edition

來源:互聯網
上載者:User

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.