]> git.saurik.com Git - wxWidgets.git/blob - include/wx/scrolwin.h
layout improvement on mac
[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
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 protected:
143 // get pointer to our scroll rect if we use it or NULL
144 const wxRect *GetRect() const
145 {
146 return m_rectToScroll.width != 0 ? &m_rectToScroll : NULL;
147 }
148
149 // get the size of the target window
150 wxSize GetTargetSize() const
151 {
152 return m_rectToScroll.width != 0 ? m_rectToScroll.GetSize()
153 : m_targetWindow->GetClientSize();
154 }
155
156 void GetTargetSize(int *w, int *h)
157 {
158 wxSize size = GetTargetSize();
159 if ( w )
160 *w = size.x;
161 if ( h )
162 *h = size.y;
163 }
164
165 // change just the target window (unlike SetWindow which changes m_win as
166 // well)
167 void DoSetTargetWindow(wxWindow *target);
168
169 // delete the event handler we installed
170 void DeleteEvtHandler();
171
172 wxWindow *m_win,
173 *m_targetWindow;
174
175 wxRect m_rectToScroll;
176
177 wxTimer *m_timerAutoScroll;
178
179 int m_xScrollPixelsPerLine;
180 int m_yScrollPixelsPerLine;
181 int m_xScrollPosition;
182 int m_yScrollPosition;
183 int m_xScrollLines;
184 int m_yScrollLines;
185 int m_xScrollLinesPerPage;
186 int m_yScrollLinesPerPage;
187
188 bool m_xScrollingEnabled;
189 bool m_yScrollingEnabled;
190
191 double m_scaleX;
192 double m_scaleY;
193
194 #if wxUSE_MOUSEWHEEL
195 int m_wheelRotation;
196 #endif // wxUSE_MOUSEWHEEL
197
198 wxScrollHelperEvtHandler *m_handler;
199 };
200
201 // ----------------------------------------------------------------------------
202 // wxScrolledWindow: a wxWindow which knows how to scroll
203 // ----------------------------------------------------------------------------
204
205 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
206 #include "wx/gtk/scrolwin.h"
207 #else // !wxGTK
208 #include "wx/generic/scrolwin.h"
209
210 class WXDLLEXPORT wxScrolledWindow : public wxGenericScrolledWindow
211 {
212 public:
213 wxScrolledWindow() { }
214 wxScrolledWindow(wxWindow *parent,
215 wxWindowID id = -1,
216 const wxPoint& pos = wxDefaultPosition,
217 const wxSize& size = wxDefaultSize,
218 long style = wxScrolledWindowStyle,
219 const wxString& name = wxPanelNameStr)
220 : wxGenericScrolledWindow(parent, id, pos, size, style, name)
221 {
222 }
223
224 private:
225 DECLARE_CLASS(wxScrolledWindow)
226 };
227
228 #define wxSCROLLED_WINDOW_IS_GENERIC 1
229 #endif
230
231 #endif
232 // _WX_SCROLWIN_H_BASE_
233
234 // vi:sts=4:sw=4:et