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
); }
144 // get pointer to our scroll rect if we use it or NULL
145 const wxRect
*GetScrollRect() const
147 return m_rectToScroll
.width
!= 0 ? &m_rectToScroll
: NULL
;
150 // get the size of the target window
151 wxSize
GetTargetSize() const
153 return m_rectToScroll
.width
!= 0 ? m_rectToScroll
.GetSize()
154 : m_targetWindow
->GetClientSize();
157 void GetTargetSize(int *w
, int *h
)
159 wxSize size
= GetTargetSize();
166 // change just the target window (unlike SetWindow which changes m_win as
168 void DoSetTargetWindow(wxWindow
*target
);
170 // delete the event handler we installed
171 void DeleteEvtHandler();
179 wxRect m_rectToScroll
;
181 wxTimer
*m_timerAutoScroll
;
183 int m_xScrollPixelsPerLine
;
184 int m_yScrollPixelsPerLine
;
185 int m_xScrollPosition
;
186 int m_yScrollPosition
;
189 int m_xScrollLinesPerPage
;
190 int m_yScrollLinesPerPage
;
192 bool m_xScrollingEnabled
;
193 bool m_yScrollingEnabled
;
197 #endif // wxUSE_MOUSEWHEEL
199 wxScrollHelperEvtHandler
*m_handler
;
201 DECLARE_NO_COPY_CLASS(wxScrollHelper
)
206 // ----------------------------------------------------------------------------
207 // wxScrolledWindow: a wxWindow which knows how to scroll
208 // ----------------------------------------------------------------------------
210 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
211 #include "wx/gtk/scrolwin.h"
213 #include "wx/generic/scrolwin.h"
215 class WXDLLEXPORT wxScrolledWindow
: public wxGenericScrolledWindow
218 wxScrolledWindow() { }
219 wxScrolledWindow(wxWindow
*parent
,
220 wxWindowID winid
= wxID_ANY
,
221 const wxPoint
& pos
= wxDefaultPosition
,
222 const wxSize
& size
= wxDefaultSize
,
223 long style
= wxScrolledWindowStyle
,
224 const wxString
& name
= wxPanelNameStr
)
225 : wxGenericScrolledWindow(parent
, winid
, pos
, size
, style
, name
)
230 DECLARE_DYNAMIC_CLASS_NO_COPY(wxScrolledWindow
)
233 #define wxSCROLLED_WINDOW_IS_GENERIC 1
237 // _WX_SCROLWIN_H_BASE_