1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/univ/scrolbar.h
3 // Purpose: wxScrollBar for wxUniversal
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_UNIV_SCROLBAR_H_
12 #define _WX_UNIV_SCROLBAR_H_
14 class WXDLLIMPEXP_FWD_CORE wxScrollTimer
;
16 #include "wx/univ/scrarrow.h"
17 #include "wx/renderer.h"
19 // ----------------------------------------------------------------------------
20 // the actions supported by this control
21 // ----------------------------------------------------------------------------
24 #define wxACTION_SCROLL_START wxT("start") // to the beginning
25 #define wxACTION_SCROLL_END wxT("end") // to the end
26 #define wxACTION_SCROLL_LINE_UP wxT("lineup") // one line up/left
27 #define wxACTION_SCROLL_PAGE_UP wxT("pageup") // one page up/left
28 #define wxACTION_SCROLL_LINE_DOWN wxT("linedown") // one line down/right
29 #define wxACTION_SCROLL_PAGE_DOWN wxT("pagedown") // one page down/right
31 // the scrollbar thumb may be dragged
32 #define wxACTION_SCROLL_THUMB_DRAG wxT("thumbdrag")
33 #define wxACTION_SCROLL_THUMB_MOVE wxT("thumbmove")
34 #define wxACTION_SCROLL_THUMB_RELEASE wxT("thumbrelease")
36 // ----------------------------------------------------------------------------
38 // ----------------------------------------------------------------------------
40 class WXDLLIMPEXP_CORE wxScrollBar
: public wxScrollBarBase
,
41 public wxControlWithArrows
44 // scrollbar elements: they correspond to wxHT_SCROLLBAR_XXX constants but
45 // start from 0 which allows to use them as array indices
59 wxScrollBar(wxWindow
*parent
,
61 const wxPoint
& pos
= wxDefaultPosition
,
62 const wxSize
& size
= wxDefaultSize
,
63 long style
= wxSB_HORIZONTAL
,
64 const wxValidator
& validator
= wxDefaultValidator
,
65 const wxString
& name
= wxScrollBarNameStr
);
67 bool Create(wxWindow
*parent
,
69 const wxPoint
& pos
= wxDefaultPosition
,
70 const wxSize
& size
= wxDefaultSize
,
71 long style
= wxSB_HORIZONTAL
,
72 const wxValidator
& validator
= wxDefaultValidator
,
73 const wxString
& name
= wxScrollBarNameStr
);
75 virtual ~wxScrollBar();
77 // implement base class pure virtuals
78 virtual int GetThumbPosition() const;
79 virtual int GetThumbSize() const;
80 virtual int GetPageSize() const;
81 virtual int GetRange() const;
83 virtual void SetThumbPosition(int thumbPos
);
84 virtual void SetScrollbar(int position
, int thumbSize
,
85 int range
, int pageSize
,
88 // wxScrollBar actions
91 bool ScrollLines(int nLines
);
92 bool ScrollPages(int nPages
);
94 virtual bool PerformAction(const wxControlAction
& action
,
96 const wxString
& strArg
= wxEmptyString
);
98 static wxInputHandler
*GetStdInputHandler(wxInputHandler
*handlerDef
);
99 virtual wxInputHandler
*DoGetStdInputHandler(wxInputHandler
*handlerDef
)
101 return GetStdInputHandler(handlerDef
);
104 // scrollbars around a normal window should not receive the focus
105 virtual bool AcceptsFocus() const;
107 // wxScrollBar sub elements state (combination of wxCONTROL_XXX)
108 void SetState(Element which
, int flags
);
109 int GetState(Element which
) const;
111 // implement wxControlWithArrows methods
112 virtual wxRenderer
*GetRenderer() const { return m_renderer
; }
113 virtual wxWindow
*GetWindow() { return this; }
114 virtual bool IsVertical() const { return wxScrollBarBase::IsVertical(); }
115 virtual int GetArrowState(wxScrollArrows::Arrow arrow
) const;
116 virtual void SetArrowFlag(wxScrollArrows::Arrow arrow
, int flag
, bool set
);
117 virtual bool OnArrow(wxScrollArrows::Arrow arrow
);
118 virtual wxScrollArrows::Arrow
HitTestArrow(const wxPoint
& pt
) const;
120 // for wxControlRenderer::DrawScrollbar() only
121 const wxScrollArrows
& GetArrows() const { return m_arrows
; }
123 // returns one of wxHT_SCROLLBAR_XXX constants
124 wxHitTest
HitTestBar(const wxPoint
& pt
) const;
127 virtual void OnInternalIdle();
130 virtual wxSize
DoGetBestClientSize() const;
131 virtual void DoDraw(wxControlRenderer
*renderer
);
132 virtual wxBorder
GetDefaultBorder() const { return wxBORDER_NONE
; }
134 // forces update of thumb's visual appearence (does nothing if m_dirty=false)
137 // SetThumbPosition() helper
138 void DoSetThumb(int thumbPos
);
140 // common part of all ctors
143 // is this scrollbar attached to a window or a standalone control?
144 bool IsStandalone() const;
146 // scrollbar geometry methods:
148 // gets the bounding box for a scrollbar element for the given (by default
149 // - current) thumb position
150 wxRect
GetScrollbarRect(wxScrollBar::Element elem
, int thumbPos
= -1) const;
152 // returns the size of the scrollbar shaft excluding the arrows
153 wxCoord
GetScrollbarSize() const;
155 // translate the scrollbar position (in logical units) into physical
156 // coordinate (in pixels) and the other way round
157 wxCoord
ScrollbarToPixel(int thumbPos
= -1);
158 int PixelToScrollbar(wxCoord coord
);
160 // return the starting and ending positions, in pixels, of the thumb of a
161 // scrollbar with the given logical position, thumb size and range and the
162 // given physical length
163 static void GetScrollBarThumbSize(wxCoord length
,
171 // total range of the scrollbar in logical units
174 // the current and previous (after last refresh - this is used for
175 // repainting optimisation) size of the thumb in logical units (from 0 to
176 // m_range) and its position (from 0 to m_range - m_thumbSize)
181 // the page size, i.e. the number of lines by which to scroll when page
182 // up/down action is performed
185 // the state of the sub elements
186 int m_elementsState
[Element_Max
];
188 // the dirty flag: if set, scrollbar must be updated
191 // the object handling the arrows
192 wxScrollArrows m_arrows
;
194 friend WXDLLIMPEXP_CORE
class wxControlRenderer
; // for geometry methods
195 friend class wxStdScrollBarInputHandler
; // for geometry methods
197 DECLARE_EVENT_TABLE()
198 DECLARE_DYNAMIC_CLASS(wxScrollBar
)
201 // ----------------------------------------------------------------------------
202 // Standard scrollbar input handler which can be used as a base class
203 // ----------------------------------------------------------------------------
205 class WXDLLIMPEXP_CORE wxStdScrollBarInputHandler
: public wxStdInputHandler
208 // constructor takes a renderer (used for scrollbar hit testing) and the
209 // base handler to which all unhandled events are forwarded
210 wxStdScrollBarInputHandler(wxRenderer
*renderer
,
211 wxInputHandler
*inphand
);
213 virtual bool HandleKey(wxInputConsumer
*consumer
,
214 const wxKeyEvent
& event
,
216 virtual bool HandleMouse(wxInputConsumer
*consumer
,
217 const wxMouseEvent
& event
);
218 virtual bool HandleMouseMove(wxInputConsumer
*consumer
, const wxMouseEvent
& event
);
220 virtual ~wxStdScrollBarInputHandler();
222 // this method is called by wxScrollBarTimer only and may be overridden
224 // return true to continue scrolling, false to stop the timer
225 virtual bool OnScrollTimer(wxScrollBar
*scrollbar
,
226 const wxControlAction
& action
);
229 // return true if the mouse button can be used to activate scrollbar, false
230 // if not (any button under GTK+ unlike left button only which is default)
231 virtual bool IsAllowedButton(int button
) const
232 { return button
== wxMOUSE_BTN_LEFT
; }
234 // set or clear the specified flag on the scrollbar element corresponding
236 void SetElementState(wxScrollBar
*scrollbar
, int flag
, bool doIt
);
238 // [un]highlight the scrollbar element corresponding to m_htLast
239 virtual void Highlight(wxScrollBar
*scrollbar
, bool doIt
)
240 { SetElementState(scrollbar
, wxCONTROL_CURRENT
, doIt
); }
242 // [un]press the scrollbar element corresponding to m_htLast
243 virtual void Press(wxScrollBar
*scrollbar
, bool doIt
)
244 { SetElementState(scrollbar
, wxCONTROL_PRESSED
, doIt
); }
246 // stop scrolling because we reached the end point
247 void StopScrolling(wxScrollBar
*scrollbar
);
249 // get the mouse coordinates in the scrollbar direction from the event
250 wxCoord
GetMouseCoord(const wxScrollBar
*scrollbar
,
251 const wxMouseEvent
& event
) const;
253 // generate a "thumb move" action for this mouse event
254 void HandleThumbMove(wxScrollBar
*scrollbar
, const wxMouseEvent
& event
);
257 // the window (scrollbar) which has capture or NULL and the flag telling if
258 // the mouse is inside the element which captured it or not
259 wxWindow
*m_winCapture
;
261 int m_btnCapture
; // the mouse button which has captured mouse
263 // the position where we started scrolling by page
264 wxPoint m_ptStartScrolling
;
266 // one of wxHT_SCROLLBAR_XXX value: where has the mouse been last time?
269 // the renderer (we use it only for hit testing)
270 wxRenderer
*m_renderer
;
272 // the offset of the top/left of the scrollbar relative to the mouse to
273 // keep during the thumb drag
276 // the timer for generating scroll events when the mouse stays pressed on
278 wxScrollTimer
*m_timerScroll
;
281 #endif // _WX_UNIV_SCROLBAR_H_