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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "univscrolbar.h"
19 class WXDLLEXPORT wxScrollTimer
;
21 #include "wx/univ/scrarrow.h"
22 #include "wx/renderer.h"
24 // ----------------------------------------------------------------------------
25 // the actions supported by this control
26 // ----------------------------------------------------------------------------
29 #define wxACTION_SCROLL_START _T("start") // to the beginning
30 #define wxACTION_SCROLL_END _T("end") // to the end
31 #define wxACTION_SCROLL_LINE_UP _T("lineup") // one line up/left
32 #define wxACTION_SCROLL_PAGE_UP _T("pageup") // one page up/left
33 #define wxACTION_SCROLL_LINE_DOWN _T("linedown") // one line down/right
34 #define wxACTION_SCROLL_PAGE_DOWN _T("pagedown") // one page down/right
36 // the scrollbar thumb may be dragged
37 #define wxACTION_SCROLL_THUMB_DRAG _T("thumbdrag")
38 #define wxACTION_SCROLL_THUMB_MOVE _T("thumbmove")
39 #define wxACTION_SCROLL_THUMB_RELEASE _T("thumbrelease")
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
45 class WXDLLEXPORT wxScrollBar
: public wxScrollBarBase
,
46 public wxControlWithArrows
49 // scrollbar elements: they correspond to wxHT_SCROLLBAR_XXX constants but
50 // start from 0 which allows to use them as array indices
64 wxScrollBar(wxWindow
*parent
,
66 const wxPoint
& pos
= wxDefaultPosition
,
67 const wxSize
& size
= wxDefaultSize
,
68 long style
= wxSB_HORIZONTAL
,
69 const wxValidator
& validator
= wxDefaultValidator
,
70 const wxString
& name
= wxScrollBarNameStr
);
72 bool Create(wxWindow
*parent
,
74 const wxPoint
& pos
= wxDefaultPosition
,
75 const wxSize
& size
= wxDefaultSize
,
76 long style
= wxSB_HORIZONTAL
,
77 const wxValidator
& validator
= wxDefaultValidator
,
78 const wxString
& name
= wxScrollBarNameStr
);
80 virtual ~wxScrollBar();
82 // implement base class pure virtuals
83 virtual int GetThumbPosition() const;
84 virtual int GetThumbSize() const;
85 virtual int GetPageSize() const;
86 virtual int GetRange() const;
88 virtual void SetThumbPosition(int thumbPos
);
89 virtual void SetScrollbar(int position
, int thumbSize
,
90 int range
, int pageSize
,
93 // wxScrollBar actions
96 bool ScrollLines(int nLines
);
97 bool ScrollPages(int nPages
);
99 virtual bool PerformAction(const wxControlAction
& action
,
101 const wxString
& strArg
= wxEmptyString
);
103 // The scrollbars around a normal window should not
104 // 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
HitTest(const wxPoint
& pt
) const;
120 // for wxControlRenderer::DrawScrollbar() only
121 const wxScrollArrows
& GetArrows() const { return m_arrows
; }
124 virtual void OnInternalIdle();
127 virtual wxSize
DoGetBestClientSize() const;
128 virtual void DoDraw(wxControlRenderer
*renderer
);
129 virtual wxBorder
GetDefaultBorder() const { return wxBORDER_NONE
; }
131 // forces update of thumb's visual appearence (does nothing if m_dirty=FALSE)
134 // SetThumbPosition() helper
135 void DoSetThumb(int thumbPos
);
137 // common part of all ctors
140 // is this scrollbar attached to a window or a standalone control?
141 bool IsStandalone() const;
144 // total range of the scrollbar in logical units
147 // the current and previous (after last refresh - this is used for
148 // repainting optimisation) size of the thumb in logical units (from 0 to
149 // m_range) and its position (from 0 to m_range - m_thumbSize)
154 // the page size, i.e. the number of lines by which to scroll when page
155 // up/down action is performed
158 // the state of the sub elements
159 int m_elementsState
[Element_Max
];
161 // the dirty flag: if set, scrollbar must be updated
164 // the object handling the arrows
165 wxScrollArrows m_arrows
;
167 DECLARE_EVENT_TABLE()
168 DECLARE_DYNAMIC_CLASS(wxScrollBar
)
171 // ----------------------------------------------------------------------------
172 // common scrollbar input handler: it manages clicks on the standard scrollbar
173 // elements (line arrows, bar, thumb)
174 // ----------------------------------------------------------------------------
176 class WXDLLEXPORT wxStdScrollBarInputHandler
: public wxStdInputHandler
179 // constructor takes a renderer (used for scrollbar hit testing) and the
180 // base handler to which all unhandled events are forwarded
181 wxStdScrollBarInputHandler(wxRenderer
*renderer
,
182 wxInputHandler
*inphand
);
184 virtual bool HandleKey(wxInputConsumer
*consumer
,
185 const wxKeyEvent
& event
,
187 virtual bool HandleMouse(wxInputConsumer
*consumer
,
188 const wxMouseEvent
& event
);
189 virtual bool HandleMouseMove(wxInputConsumer
*consumer
, const wxMouseEvent
& event
);
191 virtual ~wxStdScrollBarInputHandler();
193 // this method is called by wxScrollBarTimer only and may be overridden
195 // return TRUE to continue scrolling, FALSE to stop the timer
196 virtual bool OnScrollTimer(wxScrollBar
*scrollbar
,
197 const wxControlAction
& action
);
200 // the methods which must be overridden in the derived class
202 // return TRUE if the mouse button can be used to activate scrollbar, FALSE
203 // if not (only left mouse button can do it under Windows, any button under
205 virtual bool IsAllowedButton(int button
) = 0;
207 // set or clear the specified flag on the scrollbar element corresponding
209 void SetElementState(wxScrollBar
*scrollbar
, int flag
, bool doIt
);
211 // [un]highlight the scrollbar element corresponding to m_htLast
212 virtual void Highlight(wxScrollBar
*scrollbar
, bool doIt
)
213 { SetElementState(scrollbar
, wxCONTROL_CURRENT
, doIt
); }
215 // [un]press the scrollbar element corresponding to m_htLast
216 virtual void Press(wxScrollBar
*scrollbar
, bool doIt
)
217 { SetElementState(scrollbar
, wxCONTROL_PRESSED
, doIt
); }
219 // stop scrolling because we reached the end point
220 void StopScrolling(wxScrollBar
*scrollbar
);
222 // get the mouse coordinates in the scrollbar direction from the event
223 wxCoord
GetMouseCoord(const wxScrollBar
*scrollbar
,
224 const wxMouseEvent
& event
) const;
226 // generate a "thumb move" action for this mouse event
227 void HandleThumbMove(wxScrollBar
*scrollbar
, const wxMouseEvent
& event
);
229 // the window (scrollbar) which has capture or NULL and the flag telling if
230 // the mouse is inside the element which captured it or not
231 wxWindow
*m_winCapture
;
233 int m_btnCapture
; // the mouse button which has captured mouse
235 // the position where we started scrolling by page
236 wxPoint m_ptStartScrolling
;
238 // one of wxHT_SCROLLBAR_XXX value: where has the mouse been last time?
241 // the renderer (we use it only for hit testing)
242 wxRenderer
*m_renderer
;
244 // the offset of the top/left of the scrollbar relative to the mouse to
245 // keep during the thumb drag
248 // the timer for generating scroll events when the mouse stays pressed on
250 wxScrollTimer
*m_timerScroll
;
253 #endif // _WX_UNIV_SCROLBAR_H_