1 /////////////////////////////////////////////////////////////////////////////// 
   2 // Name:        wx/univ/scrolbar.h 
   3 // Purpose:     wxScrollBar for wxUniversal 
   4 // Author:      Vadim Zeitlin 
   8 // Copyright:   (c) 2000 SciTech Software, Inc. (www.scitechsoft.com) 
   9 // Licence:     wxWindows licence 
  10 /////////////////////////////////////////////////////////////////////////////// 
  12 #ifndef _WX_UNIV_SCROLBAR_H_ 
  13 #define _WX_UNIV_SCROLBAR_H_ 
  15 class WXDLLEXPORT wxScrollTimer
; 
  17 #include "wx/univ/scrarrow.h" 
  18 #include "wx/renderer.h" 
  20 // ---------------------------------------------------------------------------- 
  21 // the actions supported by this control 
  22 // ---------------------------------------------------------------------------- 
  25 #define wxACTION_SCROLL_START       _T("start")     // to the beginning 
  26 #define wxACTION_SCROLL_END         _T("end")       // to the end 
  27 #define wxACTION_SCROLL_LINE_UP     _T("lineup")    // one line up/left 
  28 #define wxACTION_SCROLL_PAGE_UP     _T("pageup")    // one page up/left 
  29 #define wxACTION_SCROLL_LINE_DOWN   _T("linedown")  // one line down/right 
  30 #define wxACTION_SCROLL_PAGE_DOWN   _T("pagedown")  // one page down/right 
  32 // the scrollbar thumb may be dragged 
  33 #define wxACTION_SCROLL_THUMB_DRAG      _T("thumbdrag") 
  34 #define wxACTION_SCROLL_THUMB_MOVE      _T("thumbmove") 
  35 #define wxACTION_SCROLL_THUMB_RELEASE   _T("thumbrelease") 
  37 // ---------------------------------------------------------------------------- 
  39 // ---------------------------------------------------------------------------- 
  41 class WXDLLEXPORT wxScrollBar 
: public wxScrollBarBase
, 
  42                                 public wxControlWithArrows
 
  45     // scrollbar elements: they correspond to wxHT_SCROLLBAR_XXX constants but 
  46     // start from 0 which allows to use them as array indices 
  60     wxScrollBar(wxWindow 
*parent
, 
  62                 const wxPoint
& pos 
= wxDefaultPosition
, 
  63                 const wxSize
& size 
= wxDefaultSize
, 
  64                 long style 
= wxSB_HORIZONTAL
, 
  65                 const wxValidator
& validator 
= wxDefaultValidator
, 
  66                 const wxString
& name 
= wxScrollBarNameStr
); 
  68     bool Create(wxWindow 
*parent
, 
  70                 const wxPoint
& pos 
= wxDefaultPosition
, 
  71                 const wxSize
& size 
= wxDefaultSize
, 
  72                 long style 
= wxSB_HORIZONTAL
, 
  73                 const wxValidator
& validator 
= wxDefaultValidator
, 
  74                 const wxString
& name 
= wxScrollBarNameStr
); 
  76     virtual ~wxScrollBar(); 
  78     // implement base class pure virtuals 
  79     virtual int GetThumbPosition() const; 
  80     virtual int GetThumbSize() const; 
  81     virtual int GetPageSize() const; 
  82     virtual int GetRange() const; 
  84     virtual void SetThumbPosition(int thumbPos
); 
  85     virtual void SetScrollbar(int position
, int thumbSize
, 
  86                               int range
, int pageSize
, 
  89     // wxScrollBar actions 
  92     bool ScrollLines(int nLines
); 
  93     bool ScrollPages(int nPages
); 
  95     virtual bool PerformAction(const wxControlAction
& action
, 
  97                                const wxString
& strArg 
= wxEmptyString
); 
  99     // The scrollbars around a normal window should not 
 100     // receive the focus. 
 101     virtual bool AcceptsFocus() const; 
 103     // wxScrollBar sub elements state (combination of wxCONTROL_XXX) 
 104     void SetState(Element which
, int flags
); 
 105     int GetState(Element which
) const; 
 107     // implement wxControlWithArrows methods 
 108     virtual wxRenderer 
*GetRenderer() const { return m_renderer
; } 
 109     virtual wxWindow 
*GetWindow() { return this; } 
 110     virtual bool IsVertical() const { return wxScrollBarBase::IsVertical(); } 
 111     virtual int GetArrowState(wxScrollArrows::Arrow arrow
) const; 
 112     virtual void SetArrowFlag(wxScrollArrows::Arrow arrow
, int flag
, bool set
); 
 113     virtual bool OnArrow(wxScrollArrows::Arrow arrow
); 
 114     virtual wxScrollArrows::Arrow 
HitTest(const wxPoint
& pt
) const; 
 116     // for wxControlRenderer::DrawScrollbar() only 
 117     const wxScrollArrows
& GetArrows() const { return m_arrows
; } 
 120     virtual void OnInternalIdle(); 
 123     virtual wxSize 
DoGetBestClientSize() const; 
 124     virtual void DoDraw(wxControlRenderer 
*renderer
); 
 125     virtual wxBorder 
GetDefaultBorder() const { return wxBORDER_NONE
; } 
 127     // forces update of thumb's visual appearence (does nothing if m_dirty=false) 
 130     // SetThumbPosition() helper 
 131     void DoSetThumb(int thumbPos
); 
 133     // common part of all ctors 
 136     // is this scrollbar attached to a window or a standalone control? 
 137     bool IsStandalone() const; 
 140     // total range of the scrollbar in logical units 
 143     // the current and previous (after last refresh - this is used for 
 144     // repainting optimisation) size of the thumb in logical units (from 0 to 
 145     // m_range) and its position (from 0 to m_range - m_thumbSize) 
 150     // the page size, i.e. the number of lines by which to scroll when page 
 151     // up/down action is performed 
 154     // the state of the sub elements 
 155     int m_elementsState
[Element_Max
]; 
 157     // the dirty flag: if set, scrollbar must be updated 
 160     // the object handling the arrows 
 161     wxScrollArrows m_arrows
; 
 163     DECLARE_EVENT_TABLE() 
 164     DECLARE_DYNAMIC_CLASS(wxScrollBar
) 
 167 // ---------------------------------------------------------------------------- 
 168 // common scrollbar input handler: it manages clicks on the standard scrollbar 
 169 // elements (line arrows, bar, thumb) 
 170 // ---------------------------------------------------------------------------- 
 172 class WXDLLEXPORT wxStdScrollBarInputHandler 
: public wxStdInputHandler
 
 175     // constructor takes a renderer (used for scrollbar hit testing) and the 
 176     // base handler to which all unhandled events are forwarded 
 177     wxStdScrollBarInputHandler(wxRenderer 
*renderer
, 
 178                                wxInputHandler 
*inphand
); 
 180     virtual bool HandleKey(wxInputConsumer 
*consumer
, 
 181                            const wxKeyEvent
& event
, 
 183     virtual bool HandleMouse(wxInputConsumer 
*consumer
, 
 184                              const wxMouseEvent
& event
); 
 185     virtual bool HandleMouseMove(wxInputConsumer 
*consumer
, const wxMouseEvent
& event
); 
 187     virtual ~wxStdScrollBarInputHandler(); 
 189     // this method is called by wxScrollBarTimer only and may be overridden 
 191     // return true to continue scrolling, false to stop the timer 
 192     virtual bool OnScrollTimer(wxScrollBar 
*scrollbar
, 
 193                                const wxControlAction
& action
); 
 196     // the methods which must be overridden in the derived class 
 198     // return true if the mouse button can be used to activate scrollbar, false 
 199     // if not (only left mouse button can do it under Windows, any button under 
 201     virtual bool IsAllowedButton(int button
) = 0; 
 203     // set or clear the specified flag on the scrollbar element corresponding 
 205     void SetElementState(wxScrollBar 
*scrollbar
, int flag
, bool doIt
); 
 207     // [un]highlight the scrollbar element corresponding to m_htLast 
 208     virtual void Highlight(wxScrollBar 
*scrollbar
, bool doIt
) 
 209         { SetElementState(scrollbar
, wxCONTROL_CURRENT
, doIt
); } 
 211     // [un]press the scrollbar element corresponding to m_htLast 
 212     virtual void Press(wxScrollBar 
*scrollbar
, bool doIt
) 
 213         { SetElementState(scrollbar
, wxCONTROL_PRESSED
, doIt
); } 
 215     // stop scrolling because we reached the end point 
 216     void StopScrolling(wxScrollBar 
*scrollbar
); 
 218     // get the mouse coordinates in the scrollbar direction from the event 
 219     wxCoord 
GetMouseCoord(const wxScrollBar 
*scrollbar
, 
 220                           const wxMouseEvent
& event
) const; 
 222     // generate a "thumb move" action for this mouse event 
 223     void HandleThumbMove(wxScrollBar 
*scrollbar
, const wxMouseEvent
& event
); 
 225     // the window (scrollbar) which has capture or NULL and the flag telling if 
 226     // the mouse is inside the element which captured it or not 
 227     wxWindow 
*m_winCapture
; 
 229     int       m_btnCapture
;  // the mouse button which has captured mouse 
 231     // the position where we started scrolling by page 
 232     wxPoint m_ptStartScrolling
; 
 234     // one of wxHT_SCROLLBAR_XXX value: where has the mouse been last time? 
 237     // the renderer (we use it only for hit testing) 
 238     wxRenderer 
*m_renderer
; 
 240     // the offset of the top/left of the scrollbar relative to the mouse to 
 241     // keep during the thumb drag 
 244     // the timer for generating scroll events when the mouse stays pressed on 
 246     wxScrollTimer 
*m_timerScroll
; 
 249 #endif // _WX_UNIV_SCROLBAR_H_