]>
Commit | Line | Data |
---|---|---|
1e6feb95 VZ |
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 | ||
34138703 JS |
12 | #ifndef _WX_SCROLWIN_H_BASE_ |
13 | #define _WX_SCROLWIN_H_BASE_ | |
c801d85f | 14 | |
1e6feb95 VZ |
15 | #include "wx/window.h" |
16 | ||
349efbaa | 17 | class WXDLLEXPORT wxScrollHelperEvtHandler; |
1e6feb95 VZ |
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 | |
fa3541bd JS |
27 | { |
28 | public: | |
1e6feb95 VZ |
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 | ||
566d84a7 RL |
47 | // Set the x, y scrolling increments. |
48 | void SetScrollRate( int xstep, int ystep ); | |
49 | ||
1e6feb95 VZ |
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 | ||
1e6feb95 VZ |
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 | |
8c2f3797 VS |
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 | } | |
0d6d6051 | 87 | |
8c2f3797 VS |
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; | |
1e6feb95 VZ |
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). | |
af4088f1 | 101 | virtual void SetTargetWindow(wxWindow *target); |
1e6feb95 VZ |
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); | |
e421922f | 134 | #if wxUSE_MOUSEWHEEL |
1e6feb95 | 135 | void HandleOnMouseWheel(wxMouseEvent& event); |
e421922f | 136 | #endif // wxUSE_MOUSEWHEEL |
1e6feb95 | 137 | |
2ec0173d VZ |
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 | ||
0d6d6051 VZ |
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 | ||
1e6feb95 VZ |
147 | protected: |
148 | // get pointer to our scroll rect if we use it or NULL | |
d5d58a93 | 149 | const wxRect *GetScrollRect() const |
1e6feb95 VZ |
150 | { |
151 | return m_rectToScroll.width != 0 ? &m_rectToScroll : NULL; | |
152 | } | |
153 | ||
154 | // get the size of the target window | |
155 | wxSize GetTargetSize() const | |
fa3541bd | 156 | { |
1e6feb95 VZ |
157 | return m_rectToScroll.width != 0 ? m_rectToScroll.GetSize() |
158 | : m_targetWindow->GetClientSize(); | |
fa3541bd | 159 | } |
1e6feb95 VZ |
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 | ||
349efbaa VZ |
170 | // change just the target window (unlike SetWindow which changes m_win as |
171 | // well) | |
af4088f1 | 172 | void DoSetTargetWindow(wxWindow *target); |
349efbaa VZ |
173 | |
174 | // delete the event handler we installed | |
175 | void DeleteEvtHandler(); | |
176 | ||
1e6feb95 VZ |
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; | |
e421922f VZ |
198 | |
199 | #if wxUSE_MOUSEWHEEL | |
200 | int m_wheelRotation; | |
201 | #endif // wxUSE_MOUSEWHEEL | |
349efbaa VZ |
202 | |
203 | wxScrollHelperEvtHandler *m_handler; | |
22f3361e VZ |
204 | |
205 | DECLARE_NO_COPY_CLASS(wxScrollHelper) | |
fa3541bd | 206 | }; |
1e6feb95 VZ |
207 | |
208 | // ---------------------------------------------------------------------------- | |
209 | // wxScrolledWindow: a wxWindow which knows how to scroll | |
210 | // ---------------------------------------------------------------------------- | |
211 | ||
3379ed37 | 212 | #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__) |
1e6feb95 VZ |
213 | #include "wx/gtk/scrolwin.h" |
214 | #else // !wxGTK | |
215 | #include "wx/generic/scrolwin.h" | |
216 | ||
217 | class WXDLLEXPORT wxScrolledWindow : public wxGenericScrolledWindow | |
218 | { | |
219 | public: | |
220 | wxScrolledWindow() { } | |
221 | wxScrolledWindow(wxWindow *parent, | |
b935bec2 | 222 | wxWindowID winid = -1, |
1e6feb95 VZ |
223 | const wxPoint& pos = wxDefaultPosition, |
224 | const wxSize& size = wxDefaultSize, | |
225 | long style = wxScrolledWindowStyle, | |
226 | const wxString& name = wxPanelNameStr) | |
b935bec2 | 227 | : wxGenericScrolledWindow(parent, winid, pos, size, style, name) |
1e6feb95 VZ |
228 | { |
229 | } | |
230 | ||
231 | private: | |
fc7a2a60 | 232 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxScrolledWindow) |
1e6feb95 VZ |
233 | }; |
234 | ||
235 | #define wxSCROLLED_WINDOW_IS_GENERIC 1 | |
30954328 | 236 | #endif |
c801d85f KB |
237 | |
238 | #endif | |
34138703 | 239 | // _WX_SCROLWIN_H_BASE_ |
566d84a7 | 240 |