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 // ----------------------------------------------------------------------------
26 class WXDLLEXPORT wxScrollHelper
30 wxScrollHelper(wxWindow
*winToScroll
= (wxWindow
*)NULL
);
31 void SetWindow(wxWindow
*winToScroll
);
32 virtual ~wxScrollHelper();
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 );
40 // scroll to the given (in logical coords) position
41 virtual void Scroll(int x
, int y
);
43 // get/set the page size for this orientation (wxVERTICAL/wxHORIZONTAL)
44 int GetScrollPageSize(int orient
) const;
45 void SetScrollPageSize(int orient
, int pageSize
);
47 // Set the x, y scrolling increments.
48 void SetScrollRate( int xstep
, int ystep
);
50 // get the size of one logical unit in physical ones
51 virtual void GetScrollPixelsPerUnit(int *pixelsPerUnitX
,
52 int *pixelsPerUnitY
) const;
54 // Enable/disable Windows scrolling in either direction. If true, wxWidgets
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
);
62 virtual void GetViewStart(int *x
, int *y
) const;
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
; }
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
75 DoCalcScrolledPosition(pt
.x
, pt
.y
, &p2
.x
, &p2
.y
);
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
84 DoCalcUnscrolledPosition(pt
.x
, pt
.y
, &p2
.x
, &p2
.y
);
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;
91 // Adjust the scrollbars
92 virtual void AdjustScrollbars(void);
94 // Calculate scroll increment
95 virtual int CalcScrollInc(wxScrollWinEvent
& event
);
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;
104 void SetTargetRect(const wxRect
& rect
) { m_rectToScroll
= rect
; }
105 wxRect
GetTargetRect() const { return m_rectToScroll
; }
107 // Override this function to draw the graphic (or just process EVT_PAINT)
108 virtual void OnDraw(wxDC
& WXUNUSED(dc
)) { }
110 // change the DC origin according to the scroll position.
111 virtual void DoPrepareDC(wxDC
& dc
);
113 // are we generating the autoscroll events?
114 bool IsAutoScrolling() const { return m_timerAutoScroll
!= NULL
; }
116 // stop generating the scroll events when mouse is held outside the window
117 void StopAutoScrolling();
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
124 // the base class version just returns true
125 virtual bool SendAutoScrollEvents(wxScrollWinEvent
& event
) const;
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
);
135 void HandleOnMouseWheel(wxMouseEvent
& event
);
136 #endif // wxUSE_MOUSEWHEEL
138 // FIXME: this is needed for now for wxPlot compilation, should be removed
140 void OnScroll(wxScrollWinEvent
& event
) { HandleOnScroll(event
); }
142 #if WXWIN_COMPATIBILITY_2_2
143 // Compatibility only, don't use
144 void ViewStart(int *x
, int *y
) const { GetViewStart( x
, y
); }
145 #endif // WXWIN_COMPATIBILITY_2_2
148 // get pointer to our scroll rect if we use it or NULL
149 const wxRect
*GetScrollRect() const
151 return m_rectToScroll
.width
!= 0 ? &m_rectToScroll
: NULL
;
154 // get the size of the target window
155 wxSize
GetTargetSize() const
157 return m_rectToScroll
.width
!= 0 ? m_rectToScroll
.GetSize()
158 : m_targetWindow
->GetClientSize();
161 void GetTargetSize(int *w
, int *h
)
163 wxSize size
= GetTargetSize();
170 // change just the target window (unlike SetWindow which changes m_win as
172 void DoSetTargetWindow(wxWindow
*target
);
174 // delete the event handler we installed
175 void DeleteEvtHandler();
180 wxRect m_rectToScroll
;
182 wxTimer
*m_timerAutoScroll
;
184 int m_xScrollPixelsPerLine
;
185 int m_yScrollPixelsPerLine
;
186 int m_xScrollPosition
;
187 int m_yScrollPosition
;
190 int m_xScrollLinesPerPage
;
191 int m_yScrollLinesPerPage
;
193 bool m_xScrollingEnabled
;
194 bool m_yScrollingEnabled
;
201 #endif // wxUSE_MOUSEWHEEL
203 wxScrollHelperEvtHandler
*m_handler
;
205 DECLARE_NO_COPY_CLASS(wxScrollHelper
)
208 // ----------------------------------------------------------------------------
209 // wxScrolledWindow: a wxWindow which knows how to scroll
210 // ----------------------------------------------------------------------------
212 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
213 #include "wx/gtk/scrolwin.h"
215 #include "wx/generic/scrolwin.h"
217 class WXDLLEXPORT wxScrolledWindow
: public wxGenericScrolledWindow
220 wxScrolledWindow() { }
221 wxScrolledWindow(wxWindow
*parent
,
222 wxWindowID winid
= wxID_ANY
,
223 const wxPoint
& pos
= wxDefaultPosition
,
224 const wxSize
& size
= wxDefaultSize
,
225 long style
= wxScrolledWindowStyle
,
226 const wxString
& name
= wxPanelNameStr
)
227 : wxGenericScrolledWindow(parent
, winid
, pos
, size
, style
, name
)
232 DECLARE_DYNAMIC_CLASS_NO_COPY(wxScrolledWindow
)
235 #define wxSCROLLED_WINDOW_IS_GENERIC 1
239 // _WX_SCROLWIN_H_BASE_