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