]>
Commit | Line | Data |
---|---|---|
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) |
1e6feb95 VZ |
9 | // Licence: wxWindows license |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_UNIV_SCROLBAR_H_ | |
13 | #define _WX_UNIV_SCROLBAR_H_ | |
14 | ||
15 | #ifdef __GNUG__ | |
a3870b2f | 16 | #pragma interface "univscrolbar.h" |
1e6feb95 VZ |
17 | #endif |
18 | ||
19 | class WXDLLEXPORT wxScrollTimer; | |
20 | ||
21 | #include "wx/univ/scrarrow.h" | |
22 | ||
23 | // ---------------------------------------------------------------------------- | |
24 | // the actions supported by this control | |
25 | // ---------------------------------------------------------------------------- | |
26 | ||
27 | // scroll the bar | |
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 | |
34 | ||
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") | |
39 | ||
40 | // ---------------------------------------------------------------------------- | |
41 | // wxScrollBar | |
42 | // ---------------------------------------------------------------------------- | |
43 | ||
44 | class WXDLLEXPORT wxScrollBar : public wxScrollBarBase, | |
45 | public wxControlWithArrows | |
46 | { | |
47 | public: | |
48 | // scrollbar elements: they correspond to wxHT_SCROLLBAR_XXX constants but | |
49 | // start from 0 which allows to use them as array indices | |
50 | enum Element | |
51 | { | |
52 | Element_Arrow_Line_1, | |
53 | Element_Arrow_Line_2, | |
54 | Element_Arrow_Page_1, | |
55 | Element_Arrow_Page_2, | |
56 | Element_Thumb, | |
57 | Element_Bar_1, | |
58 | Element_Bar_2, | |
59 | Element_Max | |
60 | }; | |
61 | ||
62 | wxScrollBar(); | |
63 | wxScrollBar(wxWindow *parent, | |
64 | wxWindowID id, | |
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); | |
70 | ||
71 | bool Create(wxWindow *parent, | |
72 | wxWindowID id, | |
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); | |
78 | ||
79 | virtual ~wxScrollBar(); | |
80 | ||
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; | |
86 | ||
87 | virtual void SetThumbPosition(int thumbPos); | |
88 | virtual void SetScrollbar(int position, int thumbSize, | |
89 | int range, int pageSize, | |
90 | bool refresh = TRUE); | |
91 | ||
92 | // wxScrollBar actions | |
93 | void ScrollToStart(); | |
94 | void ScrollToEnd(); | |
94fa33a0 VS |
95 | bool ScrollLines(int nLines); |
96 | bool ScrollPages(int nPages); | |
1e6feb95 VZ |
97 | |
98 | virtual bool PerformAction(const wxControlAction& action, | |
99 | long numArg = 0, | |
100 | const wxString& strArg = wxEmptyString); | |
101 | ||
f809133f RR |
102 | // The scrollbars around a normal window should not |
103 | // receive the focus. | |
104 | virtual bool AcceptsFocus() const; | |
105 | ||
1e6feb95 VZ |
106 | // wxScrollBar sub elements state (combination of wxCONTROL_XXX) |
107 | void SetState(Element which, int flags); | |
108 | int GetState(Element which) const; | |
109 | ||
110 | // implement wxControlWithArrows methods | |
111 | virtual wxRenderer *GetRenderer() const { return m_renderer; } | |
112 | virtual wxWindow *GetWindow() { return this; } | |
113 | virtual bool IsVertical() const { return wxScrollBarBase::IsVertical(); } | |
114 | virtual int GetArrowState(wxScrollArrows::Arrow arrow) const; | |
115 | virtual void SetArrowFlag(wxScrollArrows::Arrow arrow, int flag, bool set); | |
116 | virtual bool OnArrow(wxScrollArrows::Arrow arrow); | |
117 | virtual wxScrollArrows::Arrow HitTest(const wxPoint& pt) const; | |
118 | ||
119 | // for wxControlRenderer::DrawScrollbar() only | |
120 | const wxScrollArrows& GetArrows() const { return m_arrows; } | |
121 | ||
122 | protected: | |
123 | virtual wxSize DoGetBestClientSize() const; | |
124 | virtual void DoDraw(wxControlRenderer *renderer); | |
125 | virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } | |
126 | ||
127 | // event handlers | |
128 | void OnIdle(wxIdleEvent& event); | |
21c3670f VS |
129 | |
130 | // forces update of thumb's visual appearence (does nothing if m_dirty=FALSE) | |
131 | void UpdateThumb(); | |
1e6feb95 VZ |
132 | |
133 | // SetThumbPosition() helper | |
134 | void DoSetThumb(int thumbPos); | |
135 | ||
136 | // common part of all ctors | |
137 | void Init(); | |
138 | ||
139 | private: | |
140 | // total range of the scrollbar in logical units | |
141 | int m_range; | |
142 | ||
143 | // the current and previous (after last refresh - this is used for | |
144 | // repainting optimisation) size of the thumb in logical units (from 0 to | |
145 | // m_range) and its position (from 0 to m_range - m_thumbSize) | |
146 | int m_thumbSize, | |
147 | m_thumbPos, | |
148 | m_thumbPosOld; | |
149 | ||
150 | // the page size, i.e. the number of lines by which to scroll when page | |
151 | // up/down action is performed | |
152 | int m_pageSize; | |
153 | ||
154 | // the state of the sub elements | |
155 | int m_elementsState[Element_Max]; | |
156 | ||
157 | // the dirty flag: if set, scrollbar must be updated | |
158 | bool m_dirty; | |
159 | ||
160 | // the object handling the arrows | |
161 | wxScrollArrows m_arrows; | |
162 | ||
163 | DECLARE_EVENT_TABLE() | |
164 | DECLARE_DYNAMIC_CLASS(wxScrollBar) | |
165 | }; | |
166 | ||
167 | // ---------------------------------------------------------------------------- | |
168 | // common scrollbar input handler: it manages clicks on the standard scrollbar | |
169 | // elements (line arrows, bar, thumb) | |
170 | // ---------------------------------------------------------------------------- | |
171 | ||
172 | class WXDLLEXPORT wxStdScrollBarInputHandler : public wxStdInputHandler | |
173 | { | |
174 | public: | |
175 | // constructor takes a renderer (used for scrollbar hit testing) and the | |
176 | // base handler to which all unhandled events are forwarded | |
177 | wxStdScrollBarInputHandler(wxRenderer *renderer, | |
178 | wxInputHandler *inphand); | |
179 | ||
23645bfa | 180 | virtual bool HandleKey(wxInputConsumer *consumer, |
1e6feb95 VZ |
181 | const wxKeyEvent& event, |
182 | bool pressed); | |
23645bfa | 183 | virtual bool HandleMouse(wxInputConsumer *consumer, |
1e6feb95 | 184 | const wxMouseEvent& event); |
23645bfa | 185 | virtual bool HandleMouseMove(wxInputConsumer *consumer, const wxMouseEvent& event); |
1e6feb95 VZ |
186 | |
187 | virtual ~wxStdScrollBarInputHandler(); | |
188 | ||
189 | // this method is called by wxScrollBarTimer only and may be overridden | |
190 | // | |
191 | // return TRUE to continue scrolling, FALSE to stop the timer | |
192 | virtual bool OnScrollTimer(wxScrollBar *scrollbar, | |
193 | const wxControlAction& action); | |
194 | ||
195 | protected: | |
196 | // the methods which must be overridden in the derived class | |
197 | ||
198 | // return TRUE if the mouse button can be used to activate scrollbar, FALSE | |
199 | // if not (only left mouse button can do it under Windows, any button under | |
200 | // GTK+) | |
201 | virtual bool IsAllowedButton(int button) = 0; | |
202 | ||
203 | // set or clear the specified flag on the scrollbar element corresponding | |
204 | // to m_htLast | |
205 | void SetElementState(wxScrollBar *scrollbar, int flag, bool doIt); | |
206 | ||
207 | // [un]highlight the scrollbar element corresponding to m_htLast | |
208 | virtual void Highlight(wxScrollBar *scrollbar, bool doIt) | |
209 | { SetElementState(scrollbar, wxCONTROL_CURRENT, doIt); } | |
210 | ||
211 | // [un]press the scrollbar element corresponding to m_htLast | |
212 | virtual void Press(wxScrollBar *scrollbar, bool doIt) | |
213 | { SetElementState(scrollbar, wxCONTROL_PRESSED, doIt); } | |
214 | ||
215 | // stop scrolling because we reached the end point | |
216 | void StopScrolling(wxScrollBar *scrollbar); | |
217 | ||
218 | // get the mouse coordinates in the scrollbar direction from the event | |
219 | wxCoord GetMouseCoord(const wxScrollBar *scrollbar, | |
220 | const wxMouseEvent& event) const; | |
221 | ||
222 | // generate a "thumb move" action for this mouse event | |
223 | void HandleThumbMove(wxScrollBar *scrollbar, const wxMouseEvent& event); | |
224 | ||
225 | // the window (scrollbar) which has capture or NULL and the flag telling if | |
226 | // the mouse is inside the element which captured it or not | |
227 | wxWindow *m_winCapture; | |
228 | bool m_winHasMouse; | |
229 | int m_btnCapture; // the mouse button which has captured mouse | |
230 | ||
231 | // the position where we started scrolling by page | |
232 | wxPoint m_ptStartScrolling; | |
233 | ||
234 | // one of wxHT_SCROLLBAR_XXX value: where has the mouse been last time? | |
235 | wxHitTest m_htLast; | |
236 | ||
237 | // the renderer (we use it only for hit testing) | |
238 | wxRenderer *m_renderer; | |
239 | ||
240 | // the offset of the top/left of the scrollbar relative to the mouse to | |
241 | // keep during the thumb drag | |
242 | int m_ofsMouse; | |
243 | ||
244 | // the timer for generating scroll events when the mouse stays pressed on | |
245 | // a scrollbar | |
246 | wxScrollTimer *m_timerScroll; | |
247 | }; | |
248 | ||
249 | #endif // _WX_UNIV_SCROLBAR_H_ | |
250 |