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
, bool pushEventHandler
= FALSE
);
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
120 // FIXME: this is needed for now for wxPlot compilation, should be removed
122 void OnScroll(wxScrollWinEvent
& event
) { HandleOnScroll(event
); }
125 // get pointer to our scroll rect if we use it or NULL
126 const wxRect
*GetRect() const
128 return m_rectToScroll
.width
!= 0 ? &m_rectToScroll
: NULL
;
131 // get the size of the target window
132 wxSize
GetTargetSize() const
134 return m_rectToScroll
.width
!= 0 ? m_rectToScroll
.GetSize()
135 : m_targetWindow
->GetClientSize();
138 void GetTargetSize(int *w
, int *h
)
140 wxSize size
= GetTargetSize();
147 // change just the target window (unlike SetWindow which changes m_win as
149 void DoSetTargetWindow(wxWindow
*target
, bool pushEventHandler
= FALSE
);
151 // delete the event handler we installed
152 void DeleteEvtHandler();
157 wxRect m_rectToScroll
;
159 wxTimer
*m_timerAutoScroll
;
161 int m_xScrollPixelsPerLine
;
162 int m_yScrollPixelsPerLine
;
163 int m_xScrollPosition
;
164 int m_yScrollPosition
;
167 int m_xScrollLinesPerPage
;
168 int m_yScrollLinesPerPage
;
170 bool m_xScrollingEnabled
;
171 bool m_yScrollingEnabled
;
178 #endif // wxUSE_MOUSEWHEEL
180 wxScrollHelperEvtHandler
*m_handler
;
183 // ----------------------------------------------------------------------------
184 // wxScrolledWindow: a wxWindow which knows how to scroll
185 // ----------------------------------------------------------------------------
187 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
188 #include "wx/gtk/scrolwin.h"
190 #include "wx/generic/scrolwin.h"
192 class WXDLLEXPORT wxScrolledWindow
: public wxGenericScrolledWindow
195 wxScrolledWindow() { }
196 wxScrolledWindow(wxWindow
*parent
,
198 const wxPoint
& pos
= wxDefaultPosition
,
199 const wxSize
& size
= wxDefaultSize
,
200 long style
= wxScrolledWindowStyle
,
201 const wxString
& name
= wxPanelNameStr
)
202 : wxGenericScrolledWindow(parent
, id
, pos
, size
, style
, name
)
207 DECLARE_CLASS(wxScrolledWindow
)
210 #define wxSCROLLED_WINDOW_IS_GENERIC 1
214 // _WX_SCROLWIN_H_BASE_