1 /////////////////////////////////////////////////////////////////////////////
2 // Name: include/wx/scrolwin.h
3 // Purpose: wxScrolledWindow, wxScrolledControl and wxScrollHelper
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2000 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_SCROLWIN_H_BASE_
13 #define _WX_SCROLWIN_H_BASE_
15 #include "wx/window.h"
17 class WXDLLEXPORT wxScrollHelperEvtHandler
;
18 class WXDLLEXPORT wxTimer
;
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__)
27 class WXDLLEXPORT wxScrollHelper
31 wxScrollHelper(wxWindow
*winToScroll
= (wxWindow
*)NULL
);
32 void SetWindow(wxWindow
*winToScroll
);
33 virtual ~wxScrollHelper();
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 );
41 // scroll to the given (in logical coords) position
42 virtual void Scroll(int x
, int y
);
44 // get/set the page size for this orientation (wxVERTICAL/wxHORIZONTAL)
45 int GetScrollPageSize(int orient
) const;
46 void SetScrollPageSize(int orient
, int pageSize
);
48 // Set the x, y scrolling increments.
49 void SetScrollRate( int xstep
, int ystep
);
51 // get the size of one logical unit in physical ones
52 virtual void GetScrollPixelsPerUnit(int *pixelsPerUnitX
,
53 int *pixelsPerUnitY
) const;
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
);
63 virtual void GetViewStart(int *x
, int *y
) const;
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
; }
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
76 DoCalcScrolledPosition(pt
.x
, pt
.y
, &p2
.x
, &p2
.y
);
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
85 DoCalcUnscrolledPosition(pt
.x
, pt
.y
, &p2
.x
, &p2
.y
);
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;
92 // Adjust the scrollbars
93 virtual void AdjustScrollbars(void);
95 // Calculate scroll increment
96 virtual int CalcScrollInc(wxScrollWinEvent
& event
);
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;
105 void SetTargetRect(const wxRect
& rect
) { m_rectToScroll
= rect
; }
106 wxRect
GetTargetRect() const { return m_rectToScroll
; }
108 // Override this function to draw the graphic (or just process EVT_PAINT)
109 virtual void OnDraw(wxDC
& WXUNUSED(dc
)) { }
111 // change the DC origin according to the scroll position.
112 virtual void DoPrepareDC(wxDC
& dc
);
114 // are we generating the autoscroll events?
115 bool IsAutoScrolling() const { return m_timerAutoScroll
!= NULL
; }
117 // stop generating the scroll events when mouse is held outside the window
118 void StopAutoScrolling();
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
125 // the base class version just returns true
126 virtual bool SendAutoScrollEvents(wxScrollWinEvent
& event
) const;
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
);
136 void HandleOnMouseWheel(wxMouseEvent
& event
);
137 #endif // wxUSE_MOUSEWHEEL
139 // FIXME: this is needed for now for wxPlot compilation, should be removed
141 void OnScroll(wxScrollWinEvent
& event
) { HandleOnScroll(event
); }
143 #if WXWIN_COMPATIBILITY_2_2
144 // Compatibility only, don't use
145 void ViewStart(int *x
, int *y
) const { GetViewStart( x
, y
); }
146 #endif // WXWIN_COMPATIBILITY_2_2
149 // get pointer to our scroll rect if we use it or NULL
150 const wxRect
*GetScrollRect() const
152 return m_rectToScroll
.width
!= 0 ? &m_rectToScroll
: NULL
;
155 // get the size of the target window
156 wxSize
GetTargetSize() const
158 return m_rectToScroll
.width
!= 0 ? m_rectToScroll
.GetSize()
159 : m_targetWindow
->GetClientSize();
162 void GetTargetSize(int *w
, int *h
)
164 wxSize size
= GetTargetSize();
171 // change just the target window (unlike SetWindow which changes m_win as
173 void DoSetTargetWindow(wxWindow
*target
);
175 // delete the event handler we installed
176 void DeleteEvtHandler();
181 wxRect m_rectToScroll
;
183 wxTimer
*m_timerAutoScroll
;
185 int m_xScrollPixelsPerLine
;
186 int m_yScrollPixelsPerLine
;
187 int m_xScrollPosition
;
188 int m_yScrollPosition
;
191 int m_xScrollLinesPerPage
;
192 int m_yScrollLinesPerPage
;
194 bool m_xScrollingEnabled
;
195 bool m_yScrollingEnabled
;
202 #endif // wxUSE_MOUSEWHEEL
204 wxScrollHelperEvtHandler
*m_handler
;
206 DECLARE_NO_COPY_CLASS(wxScrollHelper
)
211 // ----------------------------------------------------------------------------
212 // wxScrolledWindow: a wxWindow which knows how to scroll
213 // ----------------------------------------------------------------------------
215 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
216 #include "wx/gtk/scrolwin.h"
218 #include "wx/generic/scrolwin.h"
220 class WXDLLEXPORT wxScrolledWindow
: public wxGenericScrolledWindow
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
)
235 DECLARE_DYNAMIC_CLASS_NO_COPY(wxScrolledWindow
)
238 #define wxSCROLLED_WINDOW_IS_GENERIC 1
242 // _WX_SCROLWIN_H_BASE_