]> git.saurik.com Git - wxWidgets.git/blame - include/wx/scrolwin.h
corrected GetBestSize() implementation: take all items, not just the currently visibl...
[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
1e6feb95
VZ
15#include "wx/window.h"
16
349efbaa 17class WXDLLEXPORT wxScrollHelperEvtHandler;
1e6feb95
VZ
18class 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
27class WXDLLEXPORT wxScrollHelper
fa3541bd
JS
28{
29public:
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
1e6feb95
VZ
143protected:
144 // get pointer to our scroll rect if we use it or NULL
d5d58a93 145 const wxRect *GetScrollRect() const
1e6feb95
VZ
146 {
147 return m_rectToScroll.width != 0 ? &m_rectToScroll : NULL;
148 }
149
150 // get the size of the target window
151 wxSize GetTargetSize() const
fa3541bd 152 {
1e6feb95
VZ
153 return m_rectToScroll.width != 0 ? m_rectToScroll.GetSize()
154 : m_targetWindow->GetClientSize();
fa3541bd 155 }
1e6feb95
VZ
156
157 void GetTargetSize(int *w, int *h)
158 {
159 wxSize size = GetTargetSize();
160 if ( w )
161 *w = size.x;
162 if ( h )
163 *h = size.y;
164 }
165
349efbaa
VZ
166 // change just the target window (unlike SetWindow which changes m_win as
167 // well)
af4088f1 168 void DoSetTargetWindow(wxWindow *target);
349efbaa
VZ
169
170 // delete the event handler we installed
171 void DeleteEvtHandler();
172
39ae1f13
WS
173 double m_scaleX;
174 double m_scaleY;
175
1e6feb95
VZ
176 wxWindow *m_win,
177 *m_targetWindow;
178
179 wxRect m_rectToScroll;
180
181 wxTimer *m_timerAutoScroll;
182
183 int m_xScrollPixelsPerLine;
184 int m_yScrollPixelsPerLine;
185 int m_xScrollPosition;
186 int m_yScrollPosition;
187 int m_xScrollLines;
188 int m_yScrollLines;
189 int m_xScrollLinesPerPage;
190 int m_yScrollLinesPerPage;
191
192 bool m_xScrollingEnabled;
193 bool m_yScrollingEnabled;
194
e421922f
VZ
195#if wxUSE_MOUSEWHEEL
196 int m_wheelRotation;
197#endif // wxUSE_MOUSEWHEEL
349efbaa
VZ
198
199 wxScrollHelperEvtHandler *m_handler;
22f3361e
VZ
200
201 DECLARE_NO_COPY_CLASS(wxScrollHelper)
fa3541bd 202};
1e6feb95 203
adfea104
JS
204#endif
205
1e6feb95
VZ
206// ----------------------------------------------------------------------------
207// wxScrolledWindow: a wxWindow which knows how to scroll
208// ----------------------------------------------------------------------------
209
3379ed37 210#if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
1e6feb95
VZ
211 #include "wx/gtk/scrolwin.h"
212#else // !wxGTK
213 #include "wx/generic/scrolwin.h"
214
215 class WXDLLEXPORT wxScrolledWindow : public wxGenericScrolledWindow
216 {
217 public:
6463b9f5 218 wxScrolledWindow() { }
1e6feb95 219 wxScrolledWindow(wxWindow *parent,
d775fa82 220 wxWindowID winid = wxID_ANY,
1e6feb95
VZ
221 const wxPoint& pos = wxDefaultPosition,
222 const wxSize& size = wxDefaultSize,
223 long style = wxScrolledWindowStyle,
6463b9f5
JS
224 const wxString& name = wxPanelNameStr)
225 : wxGenericScrolledWindow(parent, winid, pos, size, style, name)
226 {
227 }
1e6feb95
VZ
228
229 private:
fc7a2a60 230 DECLARE_DYNAMIC_CLASS_NO_COPY(wxScrolledWindow)
1e6feb95
VZ
231 };
232
233 #define wxSCROLLED_WINDOW_IS_GENERIC 1
30954328 234#endif
c801d85f
KB
235
236#endif
34138703 237 // _WX_SCROLWIN_H_BASE_
566d84a7 238