]>
Commit | Line | Data |
---|---|---|
1e6feb95 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/univ/scrthumb.h | |
3 | // Purpose: wxScrollThumb class | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 12.02.01 | |
7 | // RCS-ID: $Id$ | |
442b35b5 | 8 | // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com) |
65571936 | 9 | // Licence: wxWindows licence |
1e6feb95 VZ |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_UNIV_SCRTHUMB_H_ | |
13 | #define _WX_UNIV_SCRTHUMB_H_ | |
14 | ||
1e6feb95 VZ |
15 | // ---------------------------------------------------------------------------- |
16 | // wxScrollThumb is not a control but just a class containing the common | |
17 | // functionality of scroll thumb such as used by scrollbars, sliders and maybe | |
18 | // other (user) controls | |
19 | // | |
20 | // This class is similar to wxScrollThumb. | |
21 | // ---------------------------------------------------------------------------- | |
22 | ||
23 | class WXDLLEXPORT wxControlWithThumb; | |
24 | class WXDLLEXPORT wxMouseEvent; | |
25 | class WXDLLEXPORT wxRect; | |
26 | class WXDLLEXPORT wxScrollTimer; | |
27 | ||
28 | #include "wx/timer.h" | |
29 | ||
30 | // ---------------------------------------------------------------------------- | |
31 | // wxScrollThumb: an abstraction of scrollbar thumb | |
32 | // ---------------------------------------------------------------------------- | |
33 | ||
34 | class WXDLLEXPORT wxScrollThumb | |
35 | { | |
36 | public: | |
37 | enum Shaft | |
38 | { | |
39 | Shaft_None = -1, | |
40 | Shaft_Above, // or to the left of the thumb | |
41 | Shaft_Below, // or to the right of the thumb | |
42 | Shaft_Thumb, // on the thumb | |
43 | Shaft_Max | |
44 | }; | |
45 | ||
46 | // ctor requires a back pointer to wxControlWithThumb | |
47 | wxScrollThumb(wxControlWithThumb *control); | |
48 | ||
49 | // process a mouse click: will capture the mouse if the button was pressed | |
50 | // on either the thumb (start dragging it then) or the shaft (start | |
51 | // scrolling) | |
52 | bool HandleMouse(const wxMouseEvent& event) const; | |
53 | ||
54 | // process a mouse move | |
55 | bool HandleMouseMove(const wxMouseEvent& event) const; | |
56 | ||
57 | // dtor | |
58 | ~wxScrollThumb(); | |
59 | ||
60 | private: | |
61 | // do we have the mouse capture? | |
62 | bool HasCapture() const { return m_captureData != NULL; } | |
63 | ||
64 | // get the coord of this event in the direction we're interested in (y for | |
65 | // vertical shaft or x for horizontal ones) | |
66 | wxCoord GetMouseCoord(const wxMouseEvent& event) const; | |
67 | ||
68 | // get the position of the thumb corresponding to the current mouse | |
69 | // position (can only be called while we're dragging the thumb!) | |
70 | int GetThumbPos(const wxMouseEvent& event) const; | |
71 | ||
72 | // the main control | |
73 | wxControlWithThumb *m_control; | |
74 | ||
75 | // the part of it where the mouse currently is | |
76 | Shaft m_shaftPart; | |
77 | ||
78 | // the data for the mouse capture | |
79 | struct WXDLLEXPORT wxScrollThumbCaptureData *m_captureData; | |
80 | }; | |
81 | ||
82 | // ---------------------------------------------------------------------------- | |
83 | // wxControlWithThumb: interface implemented by controls using wxScrollThumb | |
84 | // ---------------------------------------------------------------------------- | |
85 | ||
86 | class WXDLLEXPORT wxControlWithThumb | |
87 | { | |
88 | public: | |
23ff76d5 WS |
89 | virtual ~wxControlWithThumb() {} |
90 | ||
1e6feb95 VZ |
91 | // simple accessors |
92 | // ---------------- | |
93 | ||
94 | // get the controls window (used for mouse capturing) | |
95 | virtual wxWindow *GetWindow() = 0; | |
96 | ||
97 | // get the orientation of the shaft (vertical or horizontal) | |
98 | virtual bool IsVertical() const = 0; | |
99 | ||
100 | // geometry functions | |
101 | // ------------------ | |
102 | ||
103 | // hit testing: return part of the shaft the point is in (or Shaft_None) | |
104 | virtual wxScrollThumb::Shaft HitTest(const wxPoint& pt) const = 0; | |
105 | ||
106 | // get the current position in pixels of the thumb | |
107 | virtual wxCoord ThumbPosToPixel() const = 0; | |
108 | ||
109 | // transform from pixel offset to the thumb logical position | |
110 | virtual int PixelToThumbPos(wxCoord x) const = 0; | |
111 | ||
112 | // callbacks | |
113 | // --------- | |
114 | ||
115 | // set or clear the specified flag in the arrow state: this function is | |
116 | // responsible for refreshing the control | |
117 | virtual void SetShaftPartState(wxScrollThumb::Shaft shaftPart, | |
118 | int flag, | |
a290fa5a | 119 | bool set = true) = 0; |
1e6feb95 VZ |
120 | |
121 | // called when the user starts dragging the thumb | |
122 | virtual void OnThumbDragStart(int pos) = 0; | |
123 | ||
124 | // called while the user drags the thumb | |
125 | virtual void OnThumbDrag(int pos) = 0; | |
126 | ||
127 | // called when the user stops dragging the thumb | |
128 | virtual void OnThumbDragEnd(int pos) = 0; | |
129 | ||
130 | // called before starting to call OnPageScroll() - gives the control the | |
131 | // possibility to remember its current state | |
132 | virtual void OnPageScrollStart() = 0; | |
133 | ||
134 | // called while the user keeps the mouse pressed above/below the thumb, | |
a290fa5a | 135 | // return true to continue scrollign and false to stop it (e.g. because the |
1e6feb95 VZ |
136 | // scrollbar has reached the top/bottom) |
137 | virtual bool OnPageScroll(int pageInc) = 0; | |
138 | }; | |
139 | ||
140 | #endif // _WX_UNIV_SCRTHUMB_H_ |