]>
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 | ||
47 | // get the size of one logical unit in physical ones | |
48 | virtual void GetScrollPixelsPerUnit(int *pixelsPerUnitX, | |
49 | int *pixelsPerUnitY) const; | |
50 | ||
51 | // Enable/disable Windows scrolling in either direction. If TRUE, wxWindows | |
52 | // scrolls the canvas and only a bit of the canvas is invalidated; no | |
53 | // Clear() is necessary. If FALSE, the whole canvas is invalidated and a | |
54 | // Clear() is necessary. Disable for when the scroll increment is used to | |
55 | // actually scroll a non-constant distance | |
56 | virtual void EnableScrolling(bool x_scrolling, bool y_scrolling); | |
57 | ||
58 | // Get the view start | |
59 | virtual void GetViewStart(int *x, int *y) const; | |
60 | ||
61 | // Actual size in pixels when scrolling is taken into account | |
62 | virtual void GetVirtualSize(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 | virtual void CalcScrolledPosition(int x, int y, int *xx, int *yy) const; | |
71 | virtual void CalcUnscrolledPosition(int x, int y, int *xx, int *yy) const; | |
72 | ||
73 | // Adjust the scrollbars | |
74 | virtual void AdjustScrollbars(void); | |
75 | ||
76 | // Calculate scroll increment | |
77 | virtual int CalcScrollInc(wxScrollWinEvent& event); | |
78 | ||
79 | // Normally the wxScrolledWindow will scroll itself, but in some rare | |
80 | // occasions you might want it to scroll [part of] another window (e.g. a | |
81 | // child of it in order to scroll only a portion the area between the | |
82 | // scrollbars (spreadsheet: only cell area will move). | |
83 | virtual void SetTargetWindow(wxWindow *target); | |
84 | virtual wxWindow *GetTargetWindow() const; | |
85 | ||
86 | void SetTargetRect(const wxRect& rect) { m_rectToScroll = rect; } | |
87 | wxRect GetTargetRect() const { return m_rectToScroll; } | |
88 | ||
89 | // Override this function to draw the graphic (or just process EVT_PAINT) | |
90 | virtual void OnDraw(wxDC& WXUNUSED(dc)) { } | |
91 | ||
92 | // change the DC origin according to the scroll position. | |
93 | virtual void DoPrepareDC(wxDC& dc); | |
94 | ||
95 | // are we generating the autoscroll events? | |
96 | bool IsAutoScrolling() const { return m_timerAutoScroll != NULL; } | |
97 | ||
98 | // stop generating the scroll events when mouse is held outside the window | |
99 | void StopAutoScrolling(); | |
100 | ||
101 | // this method can be overridden in a derived class to forbid sending the | |
102 | // auto scroll events - note that unlike StopAutoScrolling() it doesn't | |
103 | // stop the timer, so it will be called repeatedly and will typically | |
104 | // return different values depending on the current mouse position | |
105 | // | |
106 | // the base class version just returns TRUE | |
107 | virtual bool SendAutoScrollEvents(wxScrollWinEvent& event) const; | |
108 | ||
109 | // the methods to be called from the window event handlers | |
110 | void HandleOnScroll(wxScrollWinEvent& event); | |
4ed56ed8 | 111 | void OnScroll(wxScrollWinEvent& event) { HandleOnScroll(event); } |
1e6feb95 VZ |
112 | void HandleOnSize(wxSizeEvent& event); |
113 | void HandleOnPaint(wxPaintEvent& event); | |
114 | void HandleOnChar(wxKeyEvent& event); | |
115 | void HandleOnMouseEnter(wxMouseEvent& event); | |
116 | void HandleOnMouseLeave(wxMouseEvent& event); | |
e421922f | 117 | #if wxUSE_MOUSEWHEEL |
1e6feb95 | 118 | void HandleOnMouseWheel(wxMouseEvent& event); |
e421922f | 119 | #endif // wxUSE_MOUSEWHEEL |
1e6feb95 VZ |
120 | |
121 | protected: | |
122 | // get pointer to our scroll rect if we use it or NULL | |
123 | const wxRect *GetRect() const | |
124 | { | |
125 | return m_rectToScroll.width != 0 ? &m_rectToScroll : NULL; | |
126 | } | |
127 | ||
128 | // get the size of the target window | |
129 | wxSize GetTargetSize() const | |
fa3541bd | 130 | { |
1e6feb95 VZ |
131 | return m_rectToScroll.width != 0 ? m_rectToScroll.GetSize() |
132 | : m_targetWindow->GetClientSize(); | |
fa3541bd | 133 | } |
1e6feb95 VZ |
134 | |
135 | void GetTargetSize(int *w, int *h) | |
136 | { | |
137 | wxSize size = GetTargetSize(); | |
138 | if ( w ) | |
139 | *w = size.x; | |
140 | if ( h ) | |
141 | *h = size.y; | |
142 | } | |
143 | ||
349efbaa VZ |
144 | // change just the target window (unlike SetWindow which changes m_win as |
145 | // well) | |
146 | void DoSetTargetWindow(wxWindow *target); | |
147 | ||
148 | // delete the event handler we installed | |
149 | void DeleteEvtHandler(); | |
150 | ||
1e6feb95 VZ |
151 | wxWindow *m_win, |
152 | *m_targetWindow; | |
153 | ||
154 | wxRect m_rectToScroll; | |
155 | ||
156 | wxTimer *m_timerAutoScroll; | |
157 | ||
158 | int m_xScrollPixelsPerLine; | |
159 | int m_yScrollPixelsPerLine; | |
160 | int m_xScrollPosition; | |
161 | int m_yScrollPosition; | |
162 | int m_xScrollLines; | |
163 | int m_yScrollLines; | |
164 | int m_xScrollLinesPerPage; | |
165 | int m_yScrollLinesPerPage; | |
166 | ||
167 | bool m_xScrollingEnabled; | |
168 | bool m_yScrollingEnabled; | |
169 | ||
170 | double m_scaleX; | |
171 | double m_scaleY; | |
e421922f VZ |
172 | |
173 | #if wxUSE_MOUSEWHEEL | |
174 | int m_wheelRotation; | |
175 | #endif // wxUSE_MOUSEWHEEL | |
349efbaa VZ |
176 | |
177 | wxScrollHelperEvtHandler *m_handler; | |
fa3541bd | 178 | }; |
1e6feb95 VZ |
179 | |
180 | // ---------------------------------------------------------------------------- | |
181 | // wxScrolledWindow: a wxWindow which knows how to scroll | |
182 | // ---------------------------------------------------------------------------- | |
183 | ||
3379ed37 | 184 | #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__) |
1e6feb95 VZ |
185 | #include "wx/gtk/scrolwin.h" |
186 | #else // !wxGTK | |
187 | #include "wx/generic/scrolwin.h" | |
188 | ||
189 | class WXDLLEXPORT wxScrolledWindow : public wxGenericScrolledWindow | |
190 | { | |
191 | public: | |
192 | wxScrolledWindow() { } | |
193 | wxScrolledWindow(wxWindow *parent, | |
194 | wxWindowID id = -1, | |
195 | const wxPoint& pos = wxDefaultPosition, | |
196 | const wxSize& size = wxDefaultSize, | |
197 | long style = wxScrolledWindowStyle, | |
198 | const wxString& name = wxPanelNameStr) | |
199 | : wxGenericScrolledWindow(parent, id, pos, size, style, name) | |
200 | { | |
201 | } | |
202 | ||
203 | private: | |
204 | DECLARE_CLASS(wxScrolledWindow) | |
205 | }; | |
206 | ||
207 | #define wxSCROLLED_WINDOW_IS_GENERIC 1 | |
30954328 | 208 | #endif |
c801d85f KB |
209 | |
210 | #endif | |
34138703 | 211 | // _WX_SCROLWIN_H_BASE_ |