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 WXDLLIMPEXP_FWD_CORE 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 wxT("start") // to the beginning
26 #define wxACTION_SCROLL_END wxT("end") // to the end
27 #define wxACTION_SCROLL_LINE_UP wxT("lineup") // one line up/left
28 #define wxACTION_SCROLL_PAGE_UP wxT("pageup") // one page up/left
29 #define wxACTION_SCROLL_LINE_DOWN wxT("linedown") // one line down/right
30 #define wxACTION_SCROLL_PAGE_DOWN wxT("pagedown") // one page down/right
32 // the scrollbar thumb may be dragged
33 #define wxACTION_SCROLL_THUMB_DRAG wxT("thumbdrag")
34 #define wxACTION_SCROLL_THUMB_MOVE wxT("thumbmove")
35 #define wxACTION_SCROLL_THUMB_RELEASE wxT("thumbrelease")
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 class WXDLLIMPEXP_CORE 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 static wxInputHandler
*GetStdInputHandler(wxInputHandler
*handlerDef
);
100 virtual wxInputHandler
*DoGetStdInputHandler(wxInputHandler
*handlerDef
)
102 return GetStdInputHandler(handlerDef
);
105 // scrollbars around a normal window should not receive the focus
106 virtual bool AcceptsFocus() const;
108 // wxScrollBar sub elements state (combination of wxCONTROL_XXX)
109 void SetState(Element which
, int flags
);
110 int GetState(Element which
) const;
112 // implement wxControlWithArrows methods
113 virtual wxRenderer
*GetRenderer() const { return m_renderer
; }
114 virtual wxWindow
*GetWindow() { return this; }
115 virtual bool IsVertical() const { return wxScrollBarBase::IsVertical(); }
116 virtual int GetArrowState(wxScrollArrows::Arrow arrow
) const;
117 virtual void SetArrowFlag(wxScrollArrows::Arrow arrow
, int flag
, bool set
);
118 virtual bool OnArrow(wxScrollArrows::Arrow arrow
);
119 virtual wxScrollArrows::Arrow
HitTestArrow(const wxPoint
& pt
) const;
121 // for wxControlRenderer::DrawScrollbar() only
122 const wxScrollArrows
& GetArrows() const { return m_arrows
; }
124 // returns one of wxHT_SCROLLBAR_XXX constants
125 wxHitTest
HitTestBar(const wxPoint
& pt
) const;
128 virtual void OnInternalIdle();
131 virtual wxSize
DoGetBestClientSize() const;
132 virtual void DoDraw(wxControlRenderer
*renderer
);
133 virtual wxBorder
GetDefaultBorder() const { return wxBORDER_NONE
; }
135 // forces update of thumb's visual appearence (does nothing if m_dirty=false)
138 // SetThumbPosition() helper
139 void DoSetThumb(int thumbPos
);
141 // common part of all ctors
144 // is this scrollbar attached to a window or a standalone control?
145 bool IsStandalone() const;
147 // scrollbar geometry methods:
149 // gets the bounding box for a scrollbar element for the given (by default
150 // - current) thumb position
151 wxRect
GetScrollbarRect(wxScrollBar::Element elem
, int thumbPos
= -1) const;
153 // returns the size of the scrollbar shaft excluding the arrows
154 wxCoord
GetScrollbarSize() const;
156 // translate the scrollbar position (in logical units) into physical
157 // coordinate (in pixels) and the other way round
158 wxCoord
ScrollbarToPixel(int thumbPos
= -1);
159 int PixelToScrollbar(wxCoord coord
);
161 // return the starting and ending positions, in pixels, of the thumb of a
162 // scrollbar with the given logical position, thumb size and range and the
163 // given physical length
164 static void GetScrollBarThumbSize(wxCoord length
,
172 // total range of the scrollbar in logical units
175 // the current and previous (after last refresh - this is used for
176 // repainting optimisation) size of the thumb in logical units (from 0 to
177 // m_range) and its position (from 0 to m_range - m_thumbSize)
182 // the page size, i.e. the number of lines by which to scroll when page
183 // up/down action is performed
186 // the state of the sub elements
187 int m_elementsState
[Element_Max
];
189 // the dirty flag: if set, scrollbar must be updated
192 // the object handling the arrows
193 wxScrollArrows m_arrows
;
195 friend WXDLLIMPEXP_CORE
class wxControlRenderer
; // for geometry methods
196 friend class wxStdScrollBarInputHandler
; // for geometry methods
198 DECLARE_EVENT_TABLE()
199 DECLARE_DYNAMIC_CLASS(wxScrollBar
)
202 // ----------------------------------------------------------------------------
203 // Standard scrollbar input handler which can be used as a base class
204 // ----------------------------------------------------------------------------
206 class WXDLLIMPEXP_CORE wxStdScrollBarInputHandler
: public wxStdInputHandler
209 // constructor takes a renderer (used for scrollbar hit testing) and the
210 // base handler to which all unhandled events are forwarded
211 wxStdScrollBarInputHandler(wxRenderer
*renderer
,
212 wxInputHandler
*inphand
);
214 virtual bool HandleKey(wxInputConsumer
*consumer
,
215 const wxKeyEvent
& event
,
217 virtual bool HandleMouse(wxInputConsumer
*consumer
,
218 const wxMouseEvent
& event
);
219 virtual bool HandleMouseMove(wxInputConsumer
*consumer
, const wxMouseEvent
& event
);
221 virtual ~wxStdScrollBarInputHandler();
223 // this method is called by wxScrollBarTimer only and may be overridden
225 // return true to continue scrolling, false to stop the timer
226 virtual bool OnScrollTimer(wxScrollBar
*scrollbar
,
227 const wxControlAction
& action
);
230 // return true if the mouse button can be used to activate scrollbar, false
231 // if not (any button under GTK+ unlike left button only which is default)
232 virtual bool IsAllowedButton(int button
) const
233 { return button
== wxMOUSE_BTN_LEFT
; }
235 // set or clear the specified flag on the scrollbar element corresponding
237 void SetElementState(wxScrollBar
*scrollbar
, int flag
, bool doIt
);
239 // [un]highlight the scrollbar element corresponding to m_htLast
240 virtual void Highlight(wxScrollBar
*scrollbar
, bool doIt
)
241 { SetElementState(scrollbar
, wxCONTROL_CURRENT
, doIt
); }
243 // [un]press the scrollbar element corresponding to m_htLast
244 virtual void Press(wxScrollBar
*scrollbar
, bool doIt
)
245 { SetElementState(scrollbar
, wxCONTROL_PRESSED
, doIt
); }
247 // stop scrolling because we reached the end point
248 void StopScrolling(wxScrollBar
*scrollbar
);
250 // get the mouse coordinates in the scrollbar direction from the event
251 wxCoord
GetMouseCoord(const wxScrollBar
*scrollbar
,
252 const wxMouseEvent
& event
) const;
254 // generate a "thumb move" action for this mouse event
255 void HandleThumbMove(wxScrollBar
*scrollbar
, const wxMouseEvent
& event
);
258 // the window (scrollbar) which has capture or NULL and the flag telling if
259 // the mouse is inside the element which captured it or not
260 wxWindow
*m_winCapture
;
262 int m_btnCapture
; // the mouse button which has captured mouse
264 // the position where we started scrolling by page
265 wxPoint m_ptStartScrolling
;
267 // one of wxHT_SCROLLBAR_XXX value: where has the mouse been last time?
270 // the renderer (we use it only for hit testing)
271 wxRenderer
*m_renderer
;
273 // the offset of the top/left of the scrollbar relative to the mouse to
274 // keep during the thumb drag
277 // the timer for generating scroll events when the mouse stays pressed on
279 wxScrollTimer
*m_timerScroll
;
282 #endif // _WX_UNIV_SCROLBAR_H_