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 license
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_UNIV_SCROLBAR_H_
13 #define _WX_UNIV_SCROLBAR_H_
16 #pragma interface "univscrolbar.h"
19 class WXDLLEXPORT wxScrollTimer
;
21 #include "wx/univ/scrarrow.h"
23 // ----------------------------------------------------------------------------
24 // the actions supported by this control
25 // ----------------------------------------------------------------------------
28 #define wxACTION_SCROLL_START _T("start") // to the beginning
29 #define wxACTION_SCROLL_END _T("end") // to the end
30 #define wxACTION_SCROLL_LINE_UP _T("lineup") // one line up/left
31 #define wxACTION_SCROLL_PAGE_UP _T("pageup") // one page up/left
32 #define wxACTION_SCROLL_LINE_DOWN _T("linedown") // one line down/right
33 #define wxACTION_SCROLL_PAGE_DOWN _T("pagedown") // one page down/right
35 // the scrollbar thumb may be dragged
36 #define wxACTION_SCROLL_THUMB_DRAG _T("thumbdrag")
37 #define wxACTION_SCROLL_THUMB_MOVE _T("thumbmove")
38 #define wxACTION_SCROLL_THUMB_RELEASE _T("thumbrelease")
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
44 class WXDLLEXPORT wxScrollBar
: public wxScrollBarBase
,
45 public wxControlWithArrows
48 // scrollbar elements: they correspond to wxHT_SCROLLBAR_XXX constants but
49 // start from 0 which allows to use them as array indices
63 wxScrollBar(wxWindow
*parent
,
65 const wxPoint
& pos
= wxDefaultPosition
,
66 const wxSize
& size
= wxDefaultSize
,
67 long style
= wxSB_HORIZONTAL
,
68 const wxValidator
& validator
= wxDefaultValidator
,
69 const wxString
& name
= wxScrollBarNameStr
);
71 bool Create(wxWindow
*parent
,
73 const wxPoint
& pos
= wxDefaultPosition
,
74 const wxSize
& size
= wxDefaultSize
,
75 long style
= wxSB_HORIZONTAL
,
76 const wxValidator
& validator
= wxDefaultValidator
,
77 const wxString
& name
= wxScrollBarNameStr
);
79 virtual ~wxScrollBar();
81 // implement base class pure virtuals
82 virtual int GetThumbPosition() const;
83 virtual int GetThumbSize() const;
84 virtual int GetPageSize() const;
85 virtual int GetRange() const;
87 virtual void SetThumbPosition(int thumbPos
);
88 virtual void SetScrollbar(int position
, int thumbSize
,
89 int range
, int pageSize
,
92 // wxScrollBar actions
95 bool ScrollLines(int nLines
);
96 bool ScrollPages(int nPages
);
98 virtual bool PerformAction(const wxControlAction
& action
,
100 const wxString
& strArg
= wxEmptyString
);
102 // wxScrollBar sub elements state (combination of wxCONTROL_XXX)
103 void SetState(Element which
, int flags
);
104 int GetState(Element which
) const;
106 // implement wxControlWithArrows methods
107 virtual wxRenderer
*GetRenderer() const { return m_renderer
; }
108 virtual wxWindow
*GetWindow() { return this; }
109 virtual bool IsVertical() const { return wxScrollBarBase::IsVertical(); }
110 virtual int GetArrowState(wxScrollArrows::Arrow arrow
) const;
111 virtual void SetArrowFlag(wxScrollArrows::Arrow arrow
, int flag
, bool set
);
112 virtual bool OnArrow(wxScrollArrows::Arrow arrow
);
113 virtual wxScrollArrows::Arrow
HitTest(const wxPoint
& pt
) const;
115 // for wxControlRenderer::DrawScrollbar() only
116 const wxScrollArrows
& GetArrows() const { return m_arrows
; }
119 virtual wxSize
DoGetBestClientSize() const;
120 virtual void DoDraw(wxControlRenderer
*renderer
);
121 virtual wxBorder
GetDefaultBorder() const { return wxBORDER_NONE
; }
124 void OnIdle(wxIdleEvent
& event
);
126 // forces update of thumb's visual appearence (does nothing if m_dirty=FALSE)
129 // SetThumbPosition() helper
130 void DoSetThumb(int thumbPos
);
132 // common part of all ctors
136 // total range of the scrollbar in logical units
139 // the current and previous (after last refresh - this is used for
140 // repainting optimisation) size of the thumb in logical units (from 0 to
141 // m_range) and its position (from 0 to m_range - m_thumbSize)
146 // the page size, i.e. the number of lines by which to scroll when page
147 // up/down action is performed
150 // the state of the sub elements
151 int m_elementsState
[Element_Max
];
153 // the dirty flag: if set, scrollbar must be updated
156 // the object handling the arrows
157 wxScrollArrows m_arrows
;
159 DECLARE_EVENT_TABLE()
160 DECLARE_DYNAMIC_CLASS(wxScrollBar
)
163 // ----------------------------------------------------------------------------
164 // common scrollbar input handler: it manages clicks on the standard scrollbar
165 // elements (line arrows, bar, thumb)
166 // ----------------------------------------------------------------------------
168 class WXDLLEXPORT wxStdScrollBarInputHandler
: public wxStdInputHandler
171 // constructor takes a renderer (used for scrollbar hit testing) and the
172 // base handler to which all unhandled events are forwarded
173 wxStdScrollBarInputHandler(wxRenderer
*renderer
,
174 wxInputHandler
*inphand
);
176 virtual bool HandleKey(wxInputConsumer
*consumer
,
177 const wxKeyEvent
& event
,
179 virtual bool HandleMouse(wxInputConsumer
*consumer
,
180 const wxMouseEvent
& event
);
181 virtual bool HandleMouseMove(wxInputConsumer
*consumer
, const wxMouseEvent
& event
);
183 virtual ~wxStdScrollBarInputHandler();
185 // this method is called by wxScrollBarTimer only and may be overridden
187 // return TRUE to continue scrolling, FALSE to stop the timer
188 virtual bool OnScrollTimer(wxScrollBar
*scrollbar
,
189 const wxControlAction
& action
);
192 // the methods which must be overridden in the derived class
194 // return TRUE if the mouse button can be used to activate scrollbar, FALSE
195 // if not (only left mouse button can do it under Windows, any button under
197 virtual bool IsAllowedButton(int button
) = 0;
199 // set or clear the specified flag on the scrollbar element corresponding
201 void SetElementState(wxScrollBar
*scrollbar
, int flag
, bool doIt
);
203 // [un]highlight the scrollbar element corresponding to m_htLast
204 virtual void Highlight(wxScrollBar
*scrollbar
, bool doIt
)
205 { SetElementState(scrollbar
, wxCONTROL_CURRENT
, doIt
); }
207 // [un]press the scrollbar element corresponding to m_htLast
208 virtual void Press(wxScrollBar
*scrollbar
, bool doIt
)
209 { SetElementState(scrollbar
, wxCONTROL_PRESSED
, doIt
); }
211 // stop scrolling because we reached the end point
212 void StopScrolling(wxScrollBar
*scrollbar
);
214 // get the mouse coordinates in the scrollbar direction from the event
215 wxCoord
GetMouseCoord(const wxScrollBar
*scrollbar
,
216 const wxMouseEvent
& event
) const;
218 // generate a "thumb move" action for this mouse event
219 void HandleThumbMove(wxScrollBar
*scrollbar
, const wxMouseEvent
& event
);
221 // the window (scrollbar) which has capture or NULL and the flag telling if
222 // the mouse is inside the element which captured it or not
223 wxWindow
*m_winCapture
;
225 int m_btnCapture
; // the mouse button which has captured mouse
227 // the position where we started scrolling by page
228 wxPoint m_ptStartScrolling
;
230 // one of wxHT_SCROLLBAR_XXX value: where has the mouse been last time?
233 // the renderer (we use it only for hit testing)
234 wxRenderer
*m_renderer
;
236 // the offset of the top/left of the scrollbar relative to the mouse to
237 // keep during the thumb drag
240 // the timer for generating scroll events when the mouse stays pressed on
242 wxScrollTimer
*m_timerScroll
;
245 #endif // _WX_UNIV_SCROLBAR_H_