]> git.saurik.com Git - wxWidgets.git/blame - include/wx/univ/scrolbar.h
more synonyms for UCS-2/4
[wxWidgets.git] / include / wx / univ / scrolbar.h
CommitLineData
1e6feb95
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/univ/scrolbar.h
3// Purpose: wxScrollBar for wxUniversal
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 20.08.00
7// RCS-ID: $Id$
442b35b5 8// Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
65571936 9// Licence: wxWindows licence
1e6feb95
VZ
10///////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_UNIV_SCROLBAR_H_
13#define _WX_UNIV_SCROLBAR_H_
14
12028905 15#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
a3870b2f 16 #pragma interface "univscrolbar.h"
1e6feb95
VZ
17#endif
18
19class WXDLLEXPORT wxScrollTimer;
20
21#include "wx/univ/scrarrow.h"
b5435dcc 22#include "wx/renderer.h"
1e6feb95
VZ
23
24// ----------------------------------------------------------------------------
25// the actions supported by this control
26// ----------------------------------------------------------------------------
27
28// scroll the bar
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
35
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")
40
41// ----------------------------------------------------------------------------
42// wxScrollBar
43// ----------------------------------------------------------------------------
44
45class WXDLLEXPORT wxScrollBar : public wxScrollBarBase,
46 public wxControlWithArrows
47{
48public:
49 // scrollbar elements: they correspond to wxHT_SCROLLBAR_XXX constants but
50 // start from 0 which allows to use them as array indices
51 enum Element
52 {
53 Element_Arrow_Line_1,
54 Element_Arrow_Line_2,
55 Element_Arrow_Page_1,
56 Element_Arrow_Page_2,
57 Element_Thumb,
58 Element_Bar_1,
59 Element_Bar_2,
60 Element_Max
61 };
62
63 wxScrollBar();
64 wxScrollBar(wxWindow *parent,
65 wxWindowID id,
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);
71
72 bool Create(wxWindow *parent,
73 wxWindowID id,
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);
79
80 virtual ~wxScrollBar();
81
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;
87
88 virtual void SetThumbPosition(int thumbPos);
89 virtual void SetScrollbar(int position, int thumbSize,
90 int range, int pageSize,
a290fa5a 91 bool refresh = true);
1e6feb95
VZ
92
93 // wxScrollBar actions
94 void ScrollToStart();
95 void ScrollToEnd();
94fa33a0
VS
96 bool ScrollLines(int nLines);
97 bool ScrollPages(int nPages);
1e6feb95
VZ
98
99 virtual bool PerformAction(const wxControlAction& action,
100 long numArg = 0,
101 const wxString& strArg = wxEmptyString);
102
f809133f
RR
103 // The scrollbars around a normal window should not
104 // receive the focus.
105 virtual bool AcceptsFocus() const;
106
1e6feb95
VZ
107 // wxScrollBar sub elements state (combination of wxCONTROL_XXX)
108 void SetState(Element which, int flags);
109 int GetState(Element which) const;
110
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;
119
120 // for wxControlRenderer::DrawScrollbar() only
121 const wxScrollArrows& GetArrows() const { return m_arrows; }
122
e39af974
JS
123 // idle processing
124 virtual void OnInternalIdle();
125
1e6feb95
VZ
126protected:
127 virtual wxSize DoGetBestClientSize() const;
128 virtual void DoDraw(wxControlRenderer *renderer);
129 virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
130
a290fa5a 131 // forces update of thumb's visual appearence (does nothing if m_dirty=false)
21c3670f 132 void UpdateThumb();
1e6feb95
VZ
133
134 // SetThumbPosition() helper
135 void DoSetThumb(int thumbPos);
136
137 // common part of all ctors
138 void Init();
139
c7beb048
VZ
140 // is this scrollbar attached to a window or a standalone control?
141 bool IsStandalone() const;
142
1e6feb95
VZ
143private:
144 // total range of the scrollbar in logical units
145 int m_range;
146
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)
150 int m_thumbSize,
151 m_thumbPos,
152 m_thumbPosOld;
153
154 // the page size, i.e. the number of lines by which to scroll when page
155 // up/down action is performed
156 int m_pageSize;
157
158 // the state of the sub elements
159 int m_elementsState[Element_Max];
160
161 // the dirty flag: if set, scrollbar must be updated
162 bool m_dirty;
163
164 // the object handling the arrows
165 wxScrollArrows m_arrows;
166
167 DECLARE_EVENT_TABLE()
168 DECLARE_DYNAMIC_CLASS(wxScrollBar)
169};
170
171// ----------------------------------------------------------------------------
172// common scrollbar input handler: it manages clicks on the standard scrollbar
173// elements (line arrows, bar, thumb)
174// ----------------------------------------------------------------------------
175
176class WXDLLEXPORT wxStdScrollBarInputHandler : public wxStdInputHandler
177{
178public:
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);
183
23645bfa 184 virtual bool HandleKey(wxInputConsumer *consumer,
1e6feb95
VZ
185 const wxKeyEvent& event,
186 bool pressed);
23645bfa 187 virtual bool HandleMouse(wxInputConsumer *consumer,
1e6feb95 188 const wxMouseEvent& event);
23645bfa 189 virtual bool HandleMouseMove(wxInputConsumer *consumer, const wxMouseEvent& event);
1e6feb95
VZ
190
191 virtual ~wxStdScrollBarInputHandler();
192
193 // this method is called by wxScrollBarTimer only and may be overridden
194 //
a290fa5a 195 // return true to continue scrolling, false to stop the timer
1e6feb95
VZ
196 virtual bool OnScrollTimer(wxScrollBar *scrollbar,
197 const wxControlAction& action);
198
199protected:
200 // the methods which must be overridden in the derived class
201
a290fa5a 202 // return true if the mouse button can be used to activate scrollbar, false
1e6feb95
VZ
203 // if not (only left mouse button can do it under Windows, any button under
204 // GTK+)
205 virtual bool IsAllowedButton(int button) = 0;
206
207 // set or clear the specified flag on the scrollbar element corresponding
208 // to m_htLast
209 void SetElementState(wxScrollBar *scrollbar, int flag, bool doIt);
210
211 // [un]highlight the scrollbar element corresponding to m_htLast
212 virtual void Highlight(wxScrollBar *scrollbar, bool doIt)
213 { SetElementState(scrollbar, wxCONTROL_CURRENT, doIt); }
214
215 // [un]press the scrollbar element corresponding to m_htLast
216 virtual void Press(wxScrollBar *scrollbar, bool doIt)
217 { SetElementState(scrollbar, wxCONTROL_PRESSED, doIt); }
218
219 // stop scrolling because we reached the end point
220 void StopScrolling(wxScrollBar *scrollbar);
221
222 // get the mouse coordinates in the scrollbar direction from the event
223 wxCoord GetMouseCoord(const wxScrollBar *scrollbar,
224 const wxMouseEvent& event) const;
225
226 // generate a "thumb move" action for this mouse event
227 void HandleThumbMove(wxScrollBar *scrollbar, const wxMouseEvent& event);
228
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;
232 bool m_winHasMouse;
233 int m_btnCapture; // the mouse button which has captured mouse
234
235 // the position where we started scrolling by page
236 wxPoint m_ptStartScrolling;
237
238 // one of wxHT_SCROLLBAR_XXX value: where has the mouse been last time?
239 wxHitTest m_htLast;
240
241 // the renderer (we use it only for hit testing)
242 wxRenderer *m_renderer;
243
244 // the offset of the top/left of the scrollbar relative to the mouse to
245 // keep during the thumb drag
246 int m_ofsMouse;
247
248 // the timer for generating scroll events when the mouse stays pressed on
249 // a scrollbar
250 wxScrollTimer *m_timerScroll;
251};
252
253#endif // _WX_UNIV_SCROLBAR_H_
254