]> git.saurik.com Git - wxWidgets.git/blob - include/wx/univ/scrolbar.h
put grid string in generic/grid.cpp, not common/datacmn.cpp
[wxWidgets.git] / include / wx / univ / scrolbar.h
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$
8 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_UNIV_SCROLBAR_H_
13 #define _WX_UNIV_SCROLBAR_H_
14
15 class WXDLLEXPORT wxScrollTimer;
16
17 #include "wx/univ/scrarrow.h"
18 #include "wx/renderer.h"
19
20 // ----------------------------------------------------------------------------
21 // the actions supported by this control
22 // ----------------------------------------------------------------------------
23
24 // scroll the bar
25 #define wxACTION_SCROLL_START _T("start") // to the beginning
26 #define wxACTION_SCROLL_END _T("end") // to the end
27 #define wxACTION_SCROLL_LINE_UP _T("lineup") // one line up/left
28 #define wxACTION_SCROLL_PAGE_UP _T("pageup") // one page up/left
29 #define wxACTION_SCROLL_LINE_DOWN _T("linedown") // one line down/right
30 #define wxACTION_SCROLL_PAGE_DOWN _T("pagedown") // one page down/right
31
32 // the scrollbar thumb may be dragged
33 #define wxACTION_SCROLL_THUMB_DRAG _T("thumbdrag")
34 #define wxACTION_SCROLL_THUMB_MOVE _T("thumbmove")
35 #define wxACTION_SCROLL_THUMB_RELEASE _T("thumbrelease")
36
37 // ----------------------------------------------------------------------------
38 // wxScrollBar
39 // ----------------------------------------------------------------------------
40
41 class WXDLLEXPORT wxScrollBar : public wxScrollBarBase,
42 public wxControlWithArrows
43 {
44 public:
45 // scrollbar elements: they correspond to wxHT_SCROLLBAR_XXX constants but
46 // start from 0 which allows to use them as array indices
47 enum Element
48 {
49 Element_Arrow_Line_1,
50 Element_Arrow_Line_2,
51 Element_Arrow_Page_1,
52 Element_Arrow_Page_2,
53 Element_Thumb,
54 Element_Bar_1,
55 Element_Bar_2,
56 Element_Max
57 };
58
59 wxScrollBar();
60 wxScrollBar(wxWindow *parent,
61 wxWindowID id,
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);
67
68 bool Create(wxWindow *parent,
69 wxWindowID id,
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);
75
76 virtual ~wxScrollBar();
77
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;
83
84 virtual void SetThumbPosition(int thumbPos);
85 virtual void SetScrollbar(int position, int thumbSize,
86 int range, int pageSize,
87 bool refresh = true);
88
89 // wxScrollBar actions
90 void ScrollToStart();
91 void ScrollToEnd();
92 bool ScrollLines(int nLines);
93 bool ScrollPages(int nPages);
94
95 virtual bool PerformAction(const wxControlAction& action,
96 long numArg = 0,
97 const wxString& strArg = wxEmptyString);
98
99 static wxInputHandler *GetStdInputHandler(wxInputHandler *handlerDef);
100 virtual wxInputHandler *DoGetStdInputHandler(wxInputHandler *handlerDef)
101 {
102 return GetStdInputHandler(handlerDef);
103 }
104
105 // scrollbars around a normal window should not receive the focus
106 virtual bool AcceptsFocus() const;
107
108 // wxScrollBar sub elements state (combination of wxCONTROL_XXX)
109 void SetState(Element which, int flags);
110 int GetState(Element which) const;
111
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 HitTest(const wxPoint& pt) const;
120
121 // for wxControlRenderer::DrawScrollbar() only
122 const wxScrollArrows& GetArrows() const { return m_arrows; }
123
124 // idle processing
125 virtual void OnInternalIdle();
126
127 protected:
128 virtual wxSize DoGetBestClientSize() const;
129 virtual void DoDraw(wxControlRenderer *renderer);
130 virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
131
132 // forces update of thumb's visual appearence (does nothing if m_dirty=false)
133 void UpdateThumb();
134
135 // SetThumbPosition() helper
136 void DoSetThumb(int thumbPos);
137
138 // common part of all ctors
139 void Init();
140
141 // is this scrollbar attached to a window or a standalone control?
142 bool IsStandalone() const;
143
144 private:
145 // total range of the scrollbar in logical units
146 int m_range;
147
148 // the current and previous (after last refresh - this is used for
149 // repainting optimisation) size of the thumb in logical units (from 0 to
150 // m_range) and its position (from 0 to m_range - m_thumbSize)
151 int m_thumbSize,
152 m_thumbPos,
153 m_thumbPosOld;
154
155 // the page size, i.e. the number of lines by which to scroll when page
156 // up/down action is performed
157 int m_pageSize;
158
159 // the state of the sub elements
160 int m_elementsState[Element_Max];
161
162 // the dirty flag: if set, scrollbar must be updated
163 bool m_dirty;
164
165 // the object handling the arrows
166 wxScrollArrows m_arrows;
167
168 DECLARE_EVENT_TABLE()
169 DECLARE_DYNAMIC_CLASS(wxScrollBar)
170 };
171
172 // ----------------------------------------------------------------------------
173 // Standard scrollbar input handler which can be used as a base class
174 // ----------------------------------------------------------------------------
175
176 class WXDLLEXPORT wxStdScrollBarInputHandler : public wxStdInputHandler
177 {
178 public:
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
184 virtual bool HandleKey(wxInputConsumer *consumer,
185 const wxKeyEvent& event,
186 bool pressed);
187 virtual bool HandleMouse(wxInputConsumer *consumer,
188 const wxMouseEvent& event);
189 virtual bool HandleMouseMove(wxInputConsumer *consumer, const wxMouseEvent& event);
190
191 virtual ~wxStdScrollBarInputHandler();
192
193 // this method is called by wxScrollBarTimer only and may be overridden
194 //
195 // return true to continue scrolling, false to stop the timer
196 virtual bool OnScrollTimer(wxScrollBar *scrollbar,
197 const wxControlAction& action);
198
199 protected:
200 // return true if the mouse button can be used to activate scrollbar, false
201 // if not (any button under GTK+ unlike left button only which is default)
202 virtual bool IsAllowedButton(int button) const
203 { return button == wxMOUSE_BTN_LEFT; }
204
205 // set or clear the specified flag on the scrollbar element corresponding
206 // to m_htLast
207 void SetElementState(wxScrollBar *scrollbar, int flag, bool doIt);
208
209 // [un]highlight the scrollbar element corresponding to m_htLast
210 virtual void Highlight(wxScrollBar *scrollbar, bool doIt)
211 { SetElementState(scrollbar, wxCONTROL_CURRENT, doIt); }
212
213 // [un]press the scrollbar element corresponding to m_htLast
214 virtual void Press(wxScrollBar *scrollbar, bool doIt)
215 { SetElementState(scrollbar, wxCONTROL_PRESSED, doIt); }
216
217 // stop scrolling because we reached the end point
218 void StopScrolling(wxScrollBar *scrollbar);
219
220 // get the mouse coordinates in the scrollbar direction from the event
221 wxCoord GetMouseCoord(const wxScrollBar *scrollbar,
222 const wxMouseEvent& event) const;
223
224 // generate a "thumb move" action for this mouse event
225 void HandleThumbMove(wxScrollBar *scrollbar, const wxMouseEvent& event);
226
227
228 // the window (scrollbar) which has capture or NULL and the flag telling if
229 // the mouse is inside the element which captured it or not
230 wxWindow *m_winCapture;
231 bool m_winHasMouse;
232 int m_btnCapture; // the mouse button which has captured mouse
233
234 // the position where we started scrolling by page
235 wxPoint m_ptStartScrolling;
236
237 // one of wxHT_SCROLLBAR_XXX value: where has the mouse been last time?
238 wxHitTest m_htLast;
239
240 // the renderer (we use it only for hit testing)
241 wxRenderer *m_renderer;
242
243 // the offset of the top/left of the scrollbar relative to the mouse to
244 // keep during the thumb drag
245 int m_ofsMouse;
246
247 // the timer for generating scroll events when the mouse stays pressed on
248 // a scrollbar
249 wxScrollTimer *m_timerScroll;
250 };
251
252 #endif // _WX_UNIV_SCROLBAR_H_
253