]> git.saurik.com Git - wxWidgets.git/blame - include/wx/scrolwin.h
Made wxBORDER_THEME the same as wxBORDER_DEFAULT
[wxWidgets.git] / include / wx / scrolwin.h
CommitLineData
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
2cd354c9 15#include "wx/panel.h"
1e6feb95 16
b5dbe15d
VS
17class WXDLLIMPEXP_FWD_CORE wxScrollHelperEvtHandler;
18class WXDLLIMPEXP_FWD_CORE wxTimer;
1e6feb95 19
d32e78bd
VZ
20// default scrolled window style: scroll in both directions
21#define wxScrolledWindowStyle (wxHSCROLL | wxVSCROLL)
22
1e6feb95 23// ----------------------------------------------------------------------------
d32e78bd
VZ
24// The hierarchy of scrolling classes is a bit complicated because we want to
25// put as much functionality as possible in a mix-in class not deriving from
26// wxWindow so that other classes could derive from the same base class on all
27// platforms irrespectively of whether they are native controls (and hence
28// don't use our scrolling) or not.
29//
30// So we have
31//
32// wxScrollHelper
33// |
34// |
35// \|/
36// wxWindow wxScrollHelperNative
37// | \ / /
38// | \ / /
39// | _| |_ /
40// | wxScrolledWindow /
41// | /
42// \|/ /
43// wxControl /
44// \ /
45// \ /
46// _| |_
47// wxScrolledControl
48//
1e6feb95
VZ
49// ----------------------------------------------------------------------------
50
51class WXDLLEXPORT wxScrollHelper
fa3541bd
JS
52{
53public:
d32e78bd
VZ
54 // ctor must be given the associated window
55 wxScrollHelper(wxWindow *winToScroll);
1e6feb95
VZ
56 virtual ~wxScrollHelper();
57
58 // configure the scrolling
59 virtual void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
60 int noUnitsX, int noUnitsY,
61 int xPos = 0, int yPos = 0,
d775fa82 62 bool noRefresh = false );
1e6feb95
VZ
63
64 // scroll to the given (in logical coords) position
65 virtual void Scroll(int x, int y);
66
67 // get/set the page size for this orientation (wxVERTICAL/wxHORIZONTAL)
68 int GetScrollPageSize(int orient) const;
69 void SetScrollPageSize(int orient, int pageSize);
70
5713b349
RR
71 // get the number of lines the window can scroll,
72 // returns 0 if no scrollbars are there.
73 int GetScrollLines( int orient ) const;
74
566d84a7
RL
75 // Set the x, y scrolling increments.
76 void SetScrollRate( int xstep, int ystep );
77
1e6feb95
VZ
78 // get the size of one logical unit in physical ones
79 virtual void GetScrollPixelsPerUnit(int *pixelsPerUnitX,
80 int *pixelsPerUnitY) const;
81
d775fa82 82 // Enable/disable Windows scrolling in either direction. If true, wxWidgets
1e6feb95 83 // scrolls the canvas and only a bit of the canvas is invalidated; no
d775fa82 84 // Clear() is necessary. If false, the whole canvas is invalidated and a
1e6feb95
VZ
85 // Clear() is necessary. Disable for when the scroll increment is used to
86 // actually scroll a non-constant distance
87 virtual void EnableScrolling(bool x_scrolling, bool y_scrolling);
88
89 // Get the view start
90 virtual void GetViewStart(int *x, int *y) const;
91
1e6feb95
VZ
92 // Set the scale factor, used in PrepareDC
93 void SetScale(double xs, double ys) { m_scaleX = xs; m_scaleY = ys; }
94 double GetScaleX() const { return m_scaleX; }
95 double GetScaleY() const { return m_scaleY; }
96
97 // translate between scrolled and unscrolled coordinates
8c2f3797
VS
98 void CalcScrolledPosition(int x, int y, int *xx, int *yy) const
99 { DoCalcScrolledPosition(x, y, xx, yy); }
100 wxPoint CalcScrolledPosition(const wxPoint& pt) const
101 {
102 wxPoint p2;
103 DoCalcScrolledPosition(pt.x, pt.y, &p2.x, &p2.y);
104 return p2;
105 }
106
107 void CalcUnscrolledPosition(int x, int y, int *xx, int *yy) const
108 { DoCalcUnscrolledPosition(x, y, xx, yy); }
109 wxPoint CalcUnscrolledPosition(const wxPoint& pt) const
110 {
111 wxPoint p2;
112 DoCalcUnscrolledPosition(pt.x, pt.y, &p2.x, &p2.y);
113 return p2;
114 }
0d6d6051 115
8c2f3797
VS
116 virtual void DoCalcScrolledPosition(int x, int y, int *xx, int *yy) const;
117 virtual void DoCalcUnscrolledPosition(int x, int y, int *xx, int *yy) const;
1e6feb95
VZ
118
119 // Adjust the scrollbars
120 virtual void AdjustScrollbars(void);
121
122 // Calculate scroll increment
123 virtual int CalcScrollInc(wxScrollWinEvent& event);
124
125 // Normally the wxScrolledWindow will scroll itself, but in some rare
126 // occasions you might want it to scroll [part of] another window (e.g. a
127 // child of it in order to scroll only a portion the area between the
128 // scrollbars (spreadsheet: only cell area will move).
af4088f1 129 virtual void SetTargetWindow(wxWindow *target);
1e6feb95
VZ
130 virtual wxWindow *GetTargetWindow() const;
131
132 void SetTargetRect(const wxRect& rect) { m_rectToScroll = rect; }
133 wxRect GetTargetRect() const { return m_rectToScroll; }
134
135 // Override this function to draw the graphic (or just process EVT_PAINT)
136 virtual void OnDraw(wxDC& WXUNUSED(dc)) { }
137
138 // change the DC origin according to the scroll position.
139 virtual void DoPrepareDC(wxDC& dc);
140
141 // are we generating the autoscroll events?
142 bool IsAutoScrolling() const { return m_timerAutoScroll != NULL; }
143
144 // stop generating the scroll events when mouse is held outside the window
145 void StopAutoScrolling();
146
147 // this method can be overridden in a derived class to forbid sending the
148 // auto scroll events - note that unlike StopAutoScrolling() it doesn't
149 // stop the timer, so it will be called repeatedly and will typically
150 // return different values depending on the current mouse position
151 //
d775fa82 152 // the base class version just returns true
1e6feb95
VZ
153 virtual bool SendAutoScrollEvents(wxScrollWinEvent& event) const;
154
155 // the methods to be called from the window event handlers
156 void HandleOnScroll(wxScrollWinEvent& event);
157 void HandleOnSize(wxSizeEvent& event);
158 void HandleOnPaint(wxPaintEvent& event);
159 void HandleOnChar(wxKeyEvent& event);
160 void HandleOnMouseEnter(wxMouseEvent& event);
161 void HandleOnMouseLeave(wxMouseEvent& event);
e421922f 162#if wxUSE_MOUSEWHEEL
1e6feb95 163 void HandleOnMouseWheel(wxMouseEvent& event);
e421922f 164#endif // wxUSE_MOUSEWHEEL
1e6feb95 165
2ec0173d
VZ
166 // FIXME: this is needed for now for wxPlot compilation, should be removed
167 // once it is fixed!
168 void OnScroll(wxScrollWinEvent& event) { HandleOnScroll(event); }
169
1e6feb95
VZ
170protected:
171 // get pointer to our scroll rect if we use it or NULL
d5d58a93 172 const wxRect *GetScrollRect() const
1e6feb95
VZ
173 {
174 return m_rectToScroll.width != 0 ? &m_rectToScroll : NULL;
175 }
176
177 // get the size of the target window
178 wxSize GetTargetSize() const
fa3541bd 179 {
1e6feb95
VZ
180 return m_rectToScroll.width != 0 ? m_rectToScroll.GetSize()
181 : m_targetWindow->GetClientSize();
fa3541bd 182 }
1e6feb95 183
2d6dd9c0 184 void GetTargetSize(int *w, int *h) const
1e6feb95
VZ
185 {
186 wxSize size = GetTargetSize();
187 if ( w )
188 *w = size.x;
189 if ( h )
190 *h = size.y;
191 }
192
d32e78bd
VZ
193 // implementations of various wxWindow virtual methods which should be
194 // forwarded to us (this can be done by WX_FORWARD_TO_SCROLL_HELPER())
195 bool ScrollLayout();
196 void ScrollDoSetVirtualSize(int x, int y);
197 wxSize ScrollGetBestVirtualSize() const;
198 wxSize ScrollGetWindowSizeForVirtualSize(const wxSize& size) const;
199
349efbaa
VZ
200 // change just the target window (unlike SetWindow which changes m_win as
201 // well)
af4088f1 202 void DoSetTargetWindow(wxWindow *target);
349efbaa
VZ
203
204 // delete the event handler we installed
205 void DeleteEvtHandler();
206
d32e78bd 207
39ae1f13
WS
208 double m_scaleX;
209 double m_scaleY;
210
1e6feb95
VZ
211 wxWindow *m_win,
212 *m_targetWindow;
213
214 wxRect m_rectToScroll;
215
216 wxTimer *m_timerAutoScroll;
217
218 int m_xScrollPixelsPerLine;
219 int m_yScrollPixelsPerLine;
220 int m_xScrollPosition;
221 int m_yScrollPosition;
222 int m_xScrollLines;
223 int m_yScrollLines;
224 int m_xScrollLinesPerPage;
225 int m_yScrollLinesPerPage;
226
227 bool m_xScrollingEnabled;
228 bool m_yScrollingEnabled;
229
e421922f
VZ
230#if wxUSE_MOUSEWHEEL
231 int m_wheelRotation;
232#endif // wxUSE_MOUSEWHEEL
349efbaa
VZ
233
234 wxScrollHelperEvtHandler *m_handler;
22f3361e
VZ
235
236 DECLARE_NO_COPY_CLASS(wxScrollHelper)
fa3541bd 237};
1e6feb95 238
d32e78bd
VZ
239// this macro can be used in a wxScrollHelper-derived class to forward wxWindow
240// methods to corresponding wxScrollHelper methods
241#define WX_FORWARD_TO_SCROLL_HELPER() \
8b64a7e2 242public: \
d32e78bd
VZ
243 virtual void PrepareDC(wxDC& dc) { DoPrepareDC(dc); } \
244 virtual bool Layout() { return ScrollLayout(); } \
245 virtual void DoSetVirtualSize(int x, int y) \
246 { ScrollDoSetVirtualSize(x, y); } \
247 virtual wxSize GetBestVirtualSize() const \
248 { return ScrollGetBestVirtualSize(); } \
6f02a879 249protected: \
d32e78bd
VZ
250 virtual wxSize GetWindowSizeForVirtualSize(const wxSize& size) const \
251 { return ScrollGetWindowSizeForVirtualSize(size); }
252
253// include the declaration of wxScrollHelperNative if needed
1be7a35c 254#if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__)
d32e78bd 255 #include "wx/gtk/scrolwin.h"
1be7a35c
MR
256#elif defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
257 #include "wx/gtk1/scrolwin.h"
d32e78bd
VZ
258#else
259 typedef wxScrollHelper wxScrollHelperNative;
adfea104
JS
260#endif
261
1e6feb95
VZ
262// ----------------------------------------------------------------------------
263// wxScrolledWindow: a wxWindow which knows how to scroll
264// ----------------------------------------------------------------------------
265
d32e78bd
VZ
266class WXDLLEXPORT wxScrolledWindow : public wxPanel,
267 public wxScrollHelperNative
268{
269public:
270 wxScrolledWindow() : wxScrollHelperNative(this) { }
271 wxScrolledWindow(wxWindow *parent,
272 wxWindowID winid = wxID_ANY,
273 const wxPoint& pos = wxDefaultPosition,
274 const wxSize& size = wxDefaultSize,
275 long style = wxScrolledWindowStyle,
276 const wxString& name = wxPanelNameStr)
277 : wxScrollHelperNative(this)
1e6feb95 278 {
d32e78bd
VZ
279 Create(parent, winid, pos, size, style, name);
280 }
c801d85f 281
d32e78bd
VZ
282 virtual ~wxScrolledWindow();
283
284 bool Create(wxWindow *parent,
285 wxWindowID winid,
286 const wxPoint& pos = wxDefaultPosition,
287 const wxSize& size = wxDefaultSize,
288 long style = wxScrolledWindowStyle,
289 const wxString& name = wxPanelNameStr);
290
6f02a879
VZ
291 // we need to return a special WM_GETDLGCODE value to process just the
292 // arrows but let the other navigation characters through
293#ifdef __WXMSW__
294 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
295#endif // __WXMSW__
296
d32e78bd
VZ
297 WX_FORWARD_TO_SCROLL_HELPER()
298
299protected:
300 // this is needed for wxEVT_PAINT processing hack described in
301 // wxScrollHelperEvtHandler::ProcessEvent()
302 void OnPaint(wxPaintEvent& event);
303
d32e78bd
VZ
304private:
305 DECLARE_DYNAMIC_CLASS_NO_COPY(wxScrolledWindow)
306 DECLARE_EVENT_TABLE()
307};
308
309#endif // _WX_SCROLWIN_H_BASE_
566d84a7 310