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