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 // get the size of one logical unit in physical ones
48 virtual void GetScrollPixelsPerUnit(int *pixelsPerUnitX
,
49 int *pixelsPerUnitY
) const;
51 // Enable/disable Windows scrolling in either direction. If TRUE, wxWindows
52 // scrolls the canvas and only a bit of the canvas is invalidated; no
53 // Clear() is necessary. If FALSE, the whole canvas is invalidated and a
54 // Clear() is necessary. Disable for when the scroll increment is used to
55 // actually scroll a non-constant distance
56 virtual void EnableScrolling(bool x_scrolling
, bool y_scrolling
);
59 virtual void GetViewStart(int *x
, int *y
) const;
61 // Actual size in pixels when scrolling is taken into account
62 virtual void GetVirtualSize(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 virtual void CalcScrolledPosition(int x
, int y
, int *xx
, int *yy
) const;
71 virtual void CalcUnscrolledPosition(int x
, int y
, int *xx
, int *yy
) const;
73 // Adjust the scrollbars
74 virtual void AdjustScrollbars(void);
76 // Calculate scroll increment
77 virtual int CalcScrollInc(wxScrollWinEvent
& event
);
79 // Normally the wxScrolledWindow will scroll itself, but in some rare
80 // occasions you might want it to scroll [part of] another window (e.g. a
81 // child of it in order to scroll only a portion the area between the
82 // scrollbars (spreadsheet: only cell area will move).
83 virtual void SetTargetWindow(wxWindow
*target
);
84 virtual wxWindow
*GetTargetWindow() const;
86 void SetTargetRect(const wxRect
& rect
) { m_rectToScroll
= rect
; }
87 wxRect
GetTargetRect() const { return m_rectToScroll
; }
89 // Override this function to draw the graphic (or just process EVT_PAINT)
90 virtual void OnDraw(wxDC
& WXUNUSED(dc
)) { }
92 // change the DC origin according to the scroll position.
93 virtual void DoPrepareDC(wxDC
& dc
);
95 // are we generating the autoscroll events?
96 bool IsAutoScrolling() const { return m_timerAutoScroll
!= NULL
; }
98 // stop generating the scroll events when mouse is held outside the window
99 void StopAutoScrolling();
101 // this method can be overridden in a derived class to forbid sending the
102 // auto scroll events - note that unlike StopAutoScrolling() it doesn't
103 // stop the timer, so it will be called repeatedly and will typically
104 // return different values depending on the current mouse position
106 // the base class version just returns TRUE
107 virtual bool SendAutoScrollEvents(wxScrollWinEvent
& event
) const;
109 // the methods to be called from the window event handlers
110 void HandleOnScroll(wxScrollWinEvent
& event
);
111 void HandleOnSize(wxSizeEvent
& event
);
112 void HandleOnPaint(wxPaintEvent
& event
);
113 void HandleOnChar(wxKeyEvent
& event
);
114 void HandleOnMouseEnter(wxMouseEvent
& event
);
115 void HandleOnMouseLeave(wxMouseEvent
& event
);
117 void HandleOnMouseWheel(wxMouseEvent
& event
);
118 #endif // wxUSE_MOUSEWHEEL
121 // get pointer to our scroll rect if we use it or NULL
122 const wxRect
*GetRect() const
124 return m_rectToScroll
.width
!= 0 ? &m_rectToScroll
: NULL
;
127 // get the size of the target window
128 wxSize
GetTargetSize() const
130 return m_rectToScroll
.width
!= 0 ? m_rectToScroll
.GetSize()
131 : m_targetWindow
->GetClientSize();
134 void GetTargetSize(int *w
, int *h
)
136 wxSize size
= GetTargetSize();
143 // change just the target window (unlike SetWindow which changes m_win as
145 void DoSetTargetWindow(wxWindow
*target
);
147 // delete the event handler we installed
148 void DeleteEvtHandler();
153 wxRect m_rectToScroll
;
155 wxTimer
*m_timerAutoScroll
;
157 int m_xScrollPixelsPerLine
;
158 int m_yScrollPixelsPerLine
;
159 int m_xScrollPosition
;
160 int m_yScrollPosition
;
163 int m_xScrollLinesPerPage
;
164 int m_yScrollLinesPerPage
;
166 bool m_xScrollingEnabled
;
167 bool m_yScrollingEnabled
;
174 #endif // wxUSE_MOUSEWHEEL
176 wxScrollHelperEvtHandler
*m_handler
;
179 // ----------------------------------------------------------------------------
180 // wxScrolledWindow: a wxWindow which knows how to scroll
181 // ----------------------------------------------------------------------------
183 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
184 #include "wx/gtk/scrolwin.h"
186 #include "wx/generic/scrolwin.h"
188 class WXDLLEXPORT wxScrolledWindow
: public wxGenericScrolledWindow
191 wxScrolledWindow() { }
192 wxScrolledWindow(wxWindow
*parent
,
194 const wxPoint
& pos
= wxDefaultPosition
,
195 const wxSize
& size
= wxDefaultSize
,
196 long style
= wxScrolledWindowStyle
,
197 const wxString
& name
= wxPanelNameStr
)
198 : wxGenericScrolledWindow(parent
, id
, pos
, size
, style
, name
)
203 DECLARE_CLASS(wxScrolledWindow
)
206 #define wxSCROLLED_WINDOW_IS_GENERIC 1
210 // _WX_SCROLWIN_H_BASE_