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, wxWindows
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
); }
143 // get pointer to our scroll rect if we use it or NULL
144 const wxRect
*GetRect() const
146 return m_rectToScroll
.width
!= 0 ? &m_rectToScroll
: NULL
;
149 // get the size of the target window
150 wxSize
GetTargetSize() const
152 return m_rectToScroll
.width
!= 0 ? m_rectToScroll
.GetSize()
153 : m_targetWindow
->GetClientSize();
156 void GetTargetSize(int *w
, int *h
)
158 wxSize size
= GetTargetSize();
165 // change just the target window (unlike SetWindow which changes m_win as
167 void DoSetTargetWindow(wxWindow
*target
);
169 // delete the event handler we installed
170 void DeleteEvtHandler();
175 wxRect m_rectToScroll
;
177 wxTimer
*m_timerAutoScroll
;
179 int m_xScrollPixelsPerLine
;
180 int m_yScrollPixelsPerLine
;
181 int m_xScrollPosition
;
182 int m_yScrollPosition
;
185 int m_xScrollLinesPerPage
;
186 int m_yScrollLinesPerPage
;
188 bool m_xScrollingEnabled
;
189 bool m_yScrollingEnabled
;
196 #endif // wxUSE_MOUSEWHEEL
198 wxScrollHelperEvtHandler
*m_handler
;
201 // ----------------------------------------------------------------------------
202 // wxScrolledWindow: a wxWindow which knows how to scroll
203 // ----------------------------------------------------------------------------
205 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
206 #include "wx/gtk/scrolwin.h"
208 #include "wx/generic/scrolwin.h"
210 class WXDLLEXPORT wxScrolledWindow
: public wxGenericScrolledWindow
213 wxScrolledWindow() { }
214 wxScrolledWindow(wxWindow
*parent
,
216 const wxPoint
& pos
= wxDefaultPosition
,
217 const wxSize
& size
= wxDefaultSize
,
218 long style
= wxScrolledWindowStyle
,
219 const wxString
& name
= wxPanelNameStr
)
220 : wxGenericScrolledWindow(parent
, id
, pos
, size
, style
, name
)
225 DECLARE_CLASS(wxScrolledWindow
)
228 #define wxSCROLLED_WINDOW_IS_GENERIC 1
232 // _WX_SCROLWIN_H_BASE_