]> git.saurik.com Git - wxWidgets.git/blob - include/wx/scrolwin.h
0.1.6-1
[wxWidgets.git] / include / wx / scrolwin.h
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 #if !defined(__WXGTK__) || defined(__WXUNIVERSAL__)
26
27 class WXDLLEXPORT wxScrollHelper
28 {
29 public:
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,
39 bool noRefresh = false );
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
48 // Set the x, y scrolling increments.
49 void SetScrollRate( int xstep, int ystep );
50
51 // get the size of one logical unit in physical ones
52 virtual void GetScrollPixelsPerUnit(int *pixelsPerUnitX,
53 int *pixelsPerUnitY) const;
54
55 // Enable/disable Windows scrolling in either direction. If true, wxWidgets
56 // scrolls the canvas and only a bit of the canvas is invalidated; no
57 // Clear() is necessary. If false, the whole canvas is invalidated and a
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
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
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 }
88
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;
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).
102 virtual void SetTargetWindow(wxWindow *target);
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 //
125 // the base class version just returns true
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);
135 #if wxUSE_MOUSEWHEEL
136 void HandleOnMouseWheel(wxMouseEvent& event);
137 #endif // wxUSE_MOUSEWHEEL
138
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
143 #if WXWIN_COMPATIBILITY_2_2
144 // Compatibility only, don't use
145 wxDEPRECATED( void ViewStart(int *x, int *y) const );
146 #endif // WXWIN_COMPATIBILITY_2_2
147
148 protected:
149 // get pointer to our scroll rect if we use it or NULL
150 const wxRect *GetScrollRect() const
151 {
152 return m_rectToScroll.width != 0 ? &m_rectToScroll : NULL;
153 }
154
155 // get the size of the target window
156 wxSize GetTargetSize() const
157 {
158 return m_rectToScroll.width != 0 ? m_rectToScroll.GetSize()
159 : m_targetWindow->GetClientSize();
160 }
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
171 // change just the target window (unlike SetWindow which changes m_win as
172 // well)
173 void DoSetTargetWindow(wxWindow *target);
174
175 // delete the event handler we installed
176 void DeleteEvtHandler();
177
178 double m_scaleX;
179 double m_scaleY;
180
181 wxWindow *m_win,
182 *m_targetWindow;
183
184 wxRect m_rectToScroll;
185
186 wxTimer *m_timerAutoScroll;
187
188 int m_xScrollPixelsPerLine;
189 int m_yScrollPixelsPerLine;
190 int m_xScrollPosition;
191 int m_yScrollPosition;
192 int m_xScrollLines;
193 int m_yScrollLines;
194 int m_xScrollLinesPerPage;
195 int m_yScrollLinesPerPage;
196
197 bool m_xScrollingEnabled;
198 bool m_yScrollingEnabled;
199
200 #if wxUSE_MOUSEWHEEL
201 int m_wheelRotation;
202 #endif // wxUSE_MOUSEWHEEL
203
204 wxScrollHelperEvtHandler *m_handler;
205
206 DECLARE_NO_COPY_CLASS(wxScrollHelper)
207 };
208
209 #endif
210
211 // ----------------------------------------------------------------------------
212 // wxScrolledWindow: a wxWindow which knows how to scroll
213 // ----------------------------------------------------------------------------
214
215 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
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:
223 wxScrolledWindow() { }
224 wxScrolledWindow(wxWindow *parent,
225 wxWindowID winid = wxID_ANY,
226 const wxPoint& pos = wxDefaultPosition,
227 const wxSize& size = wxDefaultSize,
228 long style = wxScrolledWindowStyle,
229 const wxString& name = wxPanelNameStr)
230 : wxGenericScrolledWindow(parent, winid, pos, size, style, name)
231 {
232 }
233
234 private:
235 DECLARE_DYNAMIC_CLASS_NO_COPY(wxScrolledWindow)
236 };
237
238 #define wxSCROLLED_WINDOW_IS_GENERIC 1
239 #endif
240
241 #endif
242 // _WX_SCROLWIN_H_BASE_
243