]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: include/wx/scrolwin.h | |
3 | // Purpose: wxScrolledWindow, wxScrolledControl and wxScrollHelper | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 30.08.00 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 2000 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_SCROLWIN_H_BASE_ | |
13 | #define _WX_SCROLWIN_H_BASE_ | |
14 | ||
15 | #include "wx/window.h" | |
16 | ||
17 | class WXDLLEXPORT wxScrollHelperEvtHandler; | |
18 | class WXDLLEXPORT wxTimer; | |
19 | ||
20 | // ---------------------------------------------------------------------------- | |
21 | // wxScrollHelper: this class implements the scrolling logic which is used by | |
22 | // wxScrolledWindow and wxScrolledControl. It is a mix-in: just derive from it | |
23 | // to implement scrolling in your class. | |
24 | // ---------------------------------------------------------------------------- | |
25 | ||
26 | class WXDLLEXPORT wxScrollHelper | |
27 | { | |
28 | public: | |
29 | // ctor and dtor | |
30 | wxScrollHelper(wxWindow *winToScroll = (wxWindow *)NULL); | |
31 | void SetWindow(wxWindow *winToScroll); | |
32 | virtual ~wxScrollHelper(); | |
33 | ||
34 | // configure the scrolling | |
35 | virtual void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY, | |
36 | int noUnitsX, int noUnitsY, | |
37 | int xPos = 0, int yPos = 0, | |
38 | bool noRefresh = FALSE ); | |
39 | ||
40 | // scroll to the given (in logical coords) position | |
41 | virtual void Scroll(int x, int y); | |
42 | ||
43 | // get/set the page size for this orientation (wxVERTICAL/wxHORIZONTAL) | |
44 | int GetScrollPageSize(int orient) const; | |
45 | void SetScrollPageSize(int orient, int pageSize); | |
46 | ||
47 | // Set the x, y scrolling increments. | |
48 | void SetScrollRate( int xstep, int ystep ); | |
49 | ||
50 | // get the size of one logical unit in physical ones | |
51 | virtual void GetScrollPixelsPerUnit(int *pixelsPerUnitX, | |
52 | int *pixelsPerUnitY) const; | |
53 | ||
54 | // Enable/disable Windows scrolling in either direction. If TRUE, wxWindows | |
55 | // scrolls the canvas and only a bit of the canvas is invalidated; no | |
56 | // Clear() is necessary. If FALSE, the whole canvas is invalidated and a | |
57 | // Clear() is necessary. Disable for when the scroll increment is used to | |
58 | // actually scroll a non-constant distance | |
59 | virtual void EnableScrolling(bool x_scrolling, bool y_scrolling); | |
60 | ||
61 | // Get the view start | |
62 | virtual void GetViewStart(int *x, int *y) const; | |
63 | ||
64 | // Set the scale factor, used in PrepareDC | |
65 | void SetScale(double xs, double ys) { m_scaleX = xs; m_scaleY = ys; } | |
66 | double GetScaleX() const { return m_scaleX; } | |
67 | double GetScaleY() const { return m_scaleY; } | |
68 | ||
69 | // translate between scrolled and unscrolled coordinates | |
70 | void CalcScrolledPosition(int x, int y, int *xx, int *yy) const | |
71 | { DoCalcScrolledPosition(x, y, xx, yy); } | |
72 | wxPoint CalcScrolledPosition(const wxPoint& pt) const | |
73 | { | |
74 | wxPoint p2; | |
75 | DoCalcScrolledPosition(pt.x, pt.y, &p2.x, &p2.y); | |
76 | return p2; | |
77 | } | |
78 | ||
79 | void CalcUnscrolledPosition(int x, int y, int *xx, int *yy) const | |
80 | { DoCalcUnscrolledPosition(x, y, xx, yy); } | |
81 | wxPoint CalcUnscrolledPosition(const wxPoint& pt) const | |
82 | { | |
83 | wxPoint p2; | |
84 | DoCalcUnscrolledPosition(pt.x, pt.y, &p2.x, &p2.y); | |
85 | return p2; | |
86 | } | |
87 | ||
88 | virtual void DoCalcScrolledPosition(int x, int y, int *xx, int *yy) const; | |
89 | virtual void DoCalcUnscrolledPosition(int x, int y, int *xx, int *yy) const; | |
90 | ||
91 | // Adjust the scrollbars | |
92 | virtual void AdjustScrollbars(void); | |
93 | ||
94 | // Calculate scroll increment | |
95 | virtual int CalcScrollInc(wxScrollWinEvent& event); | |
96 | ||
97 | // Normally the wxScrolledWindow will scroll itself, but in some rare | |
98 | // occasions you might want it to scroll [part of] another window (e.g. a | |
99 | // child of it in order to scroll only a portion the area between the | |
100 | // scrollbars (spreadsheet: only cell area will move). | |
101 | virtual void SetTargetWindow(wxWindow *target); | |
102 | virtual wxWindow *GetTargetWindow() const; | |
103 | ||
104 | void SetTargetRect(const wxRect& rect) { m_rectToScroll = rect; } | |
105 | wxRect GetTargetRect() const { return m_rectToScroll; } | |
106 | ||
107 | // Override this function to draw the graphic (or just process EVT_PAINT) | |
108 | virtual void OnDraw(wxDC& WXUNUSED(dc)) { } | |
109 | ||
110 | // change the DC origin according to the scroll position. | |
111 | virtual void DoPrepareDC(wxDC& dc); | |
112 | ||
113 | // are we generating the autoscroll events? | |
114 | bool IsAutoScrolling() const { return m_timerAutoScroll != NULL; } | |
115 | ||
116 | // stop generating the scroll events when mouse is held outside the window | |
117 | void StopAutoScrolling(); | |
118 | ||
119 | // this method can be overridden in a derived class to forbid sending the | |
120 | // auto scroll events - note that unlike StopAutoScrolling() it doesn't | |
121 | // stop the timer, so it will be called repeatedly and will typically | |
122 | // return different values depending on the current mouse position | |
123 | // | |
124 | // the base class version just returns TRUE | |
125 | virtual bool SendAutoScrollEvents(wxScrollWinEvent& event) const; | |
126 | ||
127 | // the methods to be called from the window event handlers | |
128 | void HandleOnScroll(wxScrollWinEvent& event); | |
129 | void HandleOnSize(wxSizeEvent& event); | |
130 | void HandleOnPaint(wxPaintEvent& event); | |
131 | void HandleOnChar(wxKeyEvent& event); | |
132 | void HandleOnMouseEnter(wxMouseEvent& event); | |
133 | void HandleOnMouseLeave(wxMouseEvent& event); | |
134 | #if wxUSE_MOUSEWHEEL | |
135 | void HandleOnMouseWheel(wxMouseEvent& event); | |
136 | #endif // wxUSE_MOUSEWHEEL | |
137 | ||
138 | // FIXME: this is needed for now for wxPlot compilation, should be removed | |
139 | // once it is fixed! | |
140 | void OnScroll(wxScrollWinEvent& event) { HandleOnScroll(event); } | |
141 | ||
142 | #if WXWIN_COMPATIBILITY_2_2 | |
143 | // Compatibility only, don't use | |
144 | void ViewStart(int *x, int *y) const { GetViewStart( x, y ); } | |
145 | #endif // WXWIN_COMPATIBILITY_2_2 | |
146 | ||
147 | protected: | |
148 | // get pointer to our scroll rect if we use it or NULL | |
149 | const wxRect *GetRect() const | |
150 | { | |
151 | return m_rectToScroll.width != 0 ? &m_rectToScroll : NULL; | |
152 | } | |
153 | ||
154 | // get the size of the target window | |
155 | wxSize GetTargetSize() const | |
156 | { | |
157 | return m_rectToScroll.width != 0 ? m_rectToScroll.GetSize() | |
158 | : m_targetWindow->GetClientSize(); | |
159 | } | |
160 | ||
161 | void GetTargetSize(int *w, int *h) | |
162 | { | |
163 | wxSize size = GetTargetSize(); | |
164 | if ( w ) | |
165 | *w = size.x; | |
166 | if ( h ) | |
167 | *h = size.y; | |
168 | } | |
169 | ||
170 | // change just the target window (unlike SetWindow which changes m_win as | |
171 | // well) | |
172 | void DoSetTargetWindow(wxWindow *target); | |
173 | ||
174 | // delete the event handler we installed | |
175 | void DeleteEvtHandler(); | |
176 | ||
177 | wxWindow *m_win, | |
178 | *m_targetWindow; | |
179 | ||
180 | wxRect m_rectToScroll; | |
181 | ||
182 | wxTimer *m_timerAutoScroll; | |
183 | ||
184 | int m_xScrollPixelsPerLine; | |
185 | int m_yScrollPixelsPerLine; | |
186 | int m_xScrollPosition; | |
187 | int m_yScrollPosition; | |
188 | int m_xScrollLines; | |
189 | int m_yScrollLines; | |
190 | int m_xScrollLinesPerPage; | |
191 | int m_yScrollLinesPerPage; | |
192 | ||
193 | bool m_xScrollingEnabled; | |
194 | bool m_yScrollingEnabled; | |
195 | ||
196 | double m_scaleX; | |
197 | double m_scaleY; | |
198 | ||
199 | #if wxUSE_MOUSEWHEEL | |
200 | int m_wheelRotation; | |
201 | #endif // wxUSE_MOUSEWHEEL | |
202 | ||
203 | wxScrollHelperEvtHandler *m_handler; | |
204 | }; | |
205 | ||
206 | // ---------------------------------------------------------------------------- | |
207 | // wxScrolledWindow: a wxWindow which knows how to scroll | |
208 | // ---------------------------------------------------------------------------- | |
209 | ||
210 | #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__) | |
211 | #include "wx/gtk/scrolwin.h" | |
212 | #else // !wxGTK | |
213 | #include "wx/generic/scrolwin.h" | |
214 | ||
215 | class WXDLLEXPORT wxScrolledWindow : public wxGenericScrolledWindow | |
216 | { | |
217 | public: | |
218 | wxScrolledWindow() { } | |
219 | wxScrolledWindow(wxWindow *parent, | |
220 | wxWindowID id = -1, | |
221 | const wxPoint& pos = wxDefaultPosition, | |
222 | const wxSize& size = wxDefaultSize, | |
223 | long style = wxScrolledWindowStyle, | |
224 | const wxString& name = wxPanelNameStr) | |
225 | : wxGenericScrolledWindow(parent, id, pos, size, style, name) | |
226 | { | |
227 | } | |
228 | ||
229 | private: | |
230 | DECLARE_CLASS(wxScrolledWindow) | |
231 | }; | |
232 | ||
233 | #define wxSCROLLED_WINDOW_IS_GENERIC 1 | |
234 | #endif | |
235 | ||
236 | #endif | |
237 | // _WX_SCROLWIN_H_BASE_ | |
238 | ||
239 | // vi:sts=4:sw=4:et |