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 wxTimer
;
19 // ----------------------------------------------------------------------------
20 // wxScrollHelper: this class implements the scrolling logic which is used by
21 // wxScrolledWindow and wxScrolledControl. It is a mix-in: just derive from it
22 // to implement scrolling in your class.
23 // ----------------------------------------------------------------------------
25 class WXDLLEXPORT wxScrollHelper
29 wxScrollHelper(wxWindow
*winToScroll
= (wxWindow
*)NULL
);
30 void SetWindow(wxWindow
*winToScroll
);
31 virtual ~wxScrollHelper();
33 // configure the scrolling
34 virtual void SetScrollbars(int pixelsPerUnitX
, int pixelsPerUnitY
,
35 int noUnitsX
, int noUnitsY
,
36 int xPos
= 0, int yPos
= 0,
37 bool noRefresh
= FALSE
);
39 // scroll to the given (in logical coords) position
40 virtual void Scroll(int x
, int y
);
42 // get/set the page size for this orientation (wxVERTICAL/wxHORIZONTAL)
43 int GetScrollPageSize(int orient
) const;
44 void SetScrollPageSize(int orient
, int pageSize
);
46 // get the size of one logical unit in physical ones
47 virtual void GetScrollPixelsPerUnit(int *pixelsPerUnitX
,
48 int *pixelsPerUnitY
) const;
50 // Enable/disable Windows scrolling in either direction. If TRUE, wxWindows
51 // scrolls the canvas and only a bit of the canvas is invalidated; no
52 // Clear() is necessary. If FALSE, the whole canvas is invalidated and a
53 // Clear() is necessary. Disable for when the scroll increment is used to
54 // actually scroll a non-constant distance
55 virtual void EnableScrolling(bool x_scrolling
, bool y_scrolling
);
58 virtual void GetViewStart(int *x
, int *y
) const;
60 // Actual size in pixels when scrolling is taken into account
61 virtual void GetVirtualSize(int *x
, int *y
) const;
63 // Set the scale factor, used in PrepareDC
64 void SetScale(double xs
, double ys
) { m_scaleX
= xs
; m_scaleY
= ys
; }
65 double GetScaleX() const { return m_scaleX
; }
66 double GetScaleY() const { return m_scaleY
; }
68 // translate between scrolled and unscrolled coordinates
69 virtual void CalcScrolledPosition(int x
, int y
, int *xx
, int *yy
) const;
70 virtual void CalcUnscrolledPosition(int x
, int y
, int *xx
, int *yy
) const;
72 // Adjust the scrollbars
73 virtual void AdjustScrollbars(void);
75 // Calculate scroll increment
76 virtual int CalcScrollInc(wxScrollWinEvent
& event
);
78 // Normally the wxScrolledWindow will scroll itself, but in some rare
79 // occasions you might want it to scroll [part of] another window (e.g. a
80 // child of it in order to scroll only a portion the area between the
81 // scrollbars (spreadsheet: only cell area will move).
82 virtual void SetTargetWindow(wxWindow
*target
);
83 virtual wxWindow
*GetTargetWindow() const;
85 void SetTargetRect(const wxRect
& rect
) { m_rectToScroll
= rect
; }
86 wxRect
GetTargetRect() const { return m_rectToScroll
; }
88 // Override this function to draw the graphic (or just process EVT_PAINT)
89 virtual void OnDraw(wxDC
& WXUNUSED(dc
)) { }
91 // change the DC origin according to the scroll position.
92 virtual void DoPrepareDC(wxDC
& dc
);
94 // are we generating the autoscroll events?
95 bool IsAutoScrolling() const { return m_timerAutoScroll
!= NULL
; }
97 // stop generating the scroll events when mouse is held outside the window
98 void StopAutoScrolling();
100 // this method can be overridden in a derived class to forbid sending the
101 // auto scroll events - note that unlike StopAutoScrolling() it doesn't
102 // stop the timer, so it will be called repeatedly and will typically
103 // return different values depending on the current mouse position
105 // the base class version just returns TRUE
106 virtual bool SendAutoScrollEvents(wxScrollWinEvent
& event
) const;
108 // the methods to be called from the window event handlers
109 void HandleOnScroll(wxScrollWinEvent
& event
);
110 void HandleOnSize(wxSizeEvent
& event
);
111 void HandleOnPaint(wxPaintEvent
& event
);
112 void HandleOnChar(wxKeyEvent
& event
);
113 void HandleOnMouseEnter(wxMouseEvent
& event
);
114 void HandleOnMouseLeave(wxMouseEvent
& event
);
116 void HandleOnMouseWheel(wxMouseEvent
& event
);
117 #endif // wxUSE_MOUSEWHEEL
120 // get pointer to our scroll rect if we use it or NULL
121 const wxRect
*GetRect() const
123 return m_rectToScroll
.width
!= 0 ? &m_rectToScroll
: NULL
;
126 // get the size of the target window
127 wxSize
GetTargetSize() const
129 return m_rectToScroll
.width
!= 0 ? m_rectToScroll
.GetSize()
130 : m_targetWindow
->GetClientSize();
133 void GetTargetSize(int *w
, int *h
)
135 wxSize size
= GetTargetSize();
145 wxRect m_rectToScroll
;
147 wxTimer
*m_timerAutoScroll
;
149 int m_xScrollPixelsPerLine
;
150 int m_yScrollPixelsPerLine
;
151 int m_xScrollPosition
;
152 int m_yScrollPosition
;
155 int m_xScrollLinesPerPage
;
156 int m_yScrollLinesPerPage
;
158 bool m_xScrollingEnabled
;
159 bool m_yScrollingEnabled
;
166 #endif // wxUSE_MOUSEWHEEL
169 // ----------------------------------------------------------------------------
170 // wxScrolledWindow: a wxWindow which knows how to scroll
171 // ----------------------------------------------------------------------------
174 #include "wx/gtk/scrolwin.h"
176 #include "wx/generic/scrolwin.h"
178 class WXDLLEXPORT wxScrolledWindow
: public wxGenericScrolledWindow
181 wxScrolledWindow() { }
182 wxScrolledWindow(wxWindow
*parent
,
184 const wxPoint
& pos
= wxDefaultPosition
,
185 const wxSize
& size
= wxDefaultSize
,
186 long style
= wxScrolledWindowStyle
,
187 const wxString
& name
= wxPanelNameStr
)
188 : wxGenericScrolledWindow(parent
, id
, pos
, size
, style
, name
)
193 DECLARE_CLASS(wxScrolledWindow
)
196 #define wxSCROLLED_WINDOW_IS_GENERIC 1
200 // _WX_SCROLWIN_H_BASE_