]> git.saurik.com Git - wxWidgets.git/blob - include/wx/scrolwin.h
added more files (unchanged) from wxUniv branch
[wxWidgets.git] / include / wx / scrolwin.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: include/wx/scrolwin.h
3 // Purpose: wxScrolledWindow, wxScrolledControl and wxScrollHelper
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 30.08.00
7 // RCS-ID: $Id$
8 // Copyright: (c) 2000 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_SCROLWIN_H_BASE_
13 #define _WX_SCROLWIN_H_BASE_
14
15 #include "wx/window.h"
16
17 class WXDLLEXPORT wxTimer;
18
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 // ----------------------------------------------------------------------------
24
25 class WXDLLEXPORT wxScrollHelper
26 {
27 public:
28 // ctor and dtor
29 wxScrollHelper(wxWindow *winToScroll = (wxWindow *)NULL);
30 void SetWindow(wxWindow *winToScroll);
31 virtual ~wxScrollHelper();
32
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 );
38
39 // scroll to the given (in logical coords) position
40 virtual void Scroll(int x, int y);
41
42 // get/set the page size for this orientation (wxVERTICAL/wxHORIZONTAL)
43 int GetScrollPageSize(int orient) const;
44 void SetScrollPageSize(int orient, int pageSize);
45
46 // get the size of one logical unit in physical ones
47 virtual void GetScrollPixelsPerUnit(int *pixelsPerUnitX,
48 int *pixelsPerUnitY) const;
49
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);
56
57 // Get the view start
58 virtual void GetViewStart(int *x, int *y) const;
59
60 // Actual size in pixels when scrolling is taken into account
61 virtual void GetVirtualSize(int *x, int *y) const;
62
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; }
67
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;
71
72 // Adjust the scrollbars
73 virtual void AdjustScrollbars(void);
74
75 // Calculate scroll increment
76 virtual int CalcScrollInc(wxScrollWinEvent& event);
77
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;
84
85 void SetTargetRect(const wxRect& rect) { m_rectToScroll = rect; }
86 wxRect GetTargetRect() const { return m_rectToScroll; }
87
88 // Override this function to draw the graphic (or just process EVT_PAINT)
89 virtual void OnDraw(wxDC& WXUNUSED(dc)) { }
90
91 // change the DC origin according to the scroll position.
92 virtual void DoPrepareDC(wxDC& dc);
93
94 // are we generating the autoscroll events?
95 bool IsAutoScrolling() const { return m_timerAutoScroll != NULL; }
96
97 // stop generating the scroll events when mouse is held outside the window
98 void StopAutoScrolling();
99
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
104 //
105 // the base class version just returns TRUE
106 virtual bool SendAutoScrollEvents(wxScrollWinEvent& event) const;
107
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);
115 void HandleOnMouseWheel(wxMouseEvent& event);
116
117 protected:
118 // get pointer to our scroll rect if we use it or NULL
119 const wxRect *GetRect() const
120 {
121 return m_rectToScroll.width != 0 ? &m_rectToScroll : NULL;
122 }
123
124 // get the size of the target window
125 wxSize GetTargetSize() const
126 {
127 return m_rectToScroll.width != 0 ? m_rectToScroll.GetSize()
128 : m_targetWindow->GetClientSize();
129 }
130
131 void GetTargetSize(int *w, int *h)
132 {
133 wxSize size = GetTargetSize();
134 if ( w )
135 *w = size.x;
136 if ( h )
137 *h = size.y;
138 }
139
140 wxWindow *m_win,
141 *m_targetWindow;
142
143 wxRect m_rectToScroll;
144
145 wxTimer *m_timerAutoScroll;
146
147 int m_xScrollPixelsPerLine;
148 int m_yScrollPixelsPerLine;
149 int m_xScrollPosition;
150 int m_yScrollPosition;
151 int m_xScrollLines;
152 int m_yScrollLines;
153 int m_xScrollLinesPerPage;
154 int m_yScrollLinesPerPage;
155
156 bool m_xScrollingEnabled;
157 bool m_yScrollingEnabled;
158
159 double m_scaleX;
160 double m_scaleY;
161 };
162
163 // ----------------------------------------------------------------------------
164 // wxScrolledWindow: a wxWindow which knows how to scroll
165 // ----------------------------------------------------------------------------
166
167 #ifdef __WXGTK__
168 #include "wx/gtk/scrolwin.h"
169 #else // !wxGTK
170 #include "wx/generic/scrolwin.h"
171
172 class WXDLLEXPORT wxScrolledWindow : public wxGenericScrolledWindow
173 {
174 public:
175 wxScrolledWindow() { }
176 wxScrolledWindow(wxWindow *parent,
177 wxWindowID id = -1,
178 const wxPoint& pos = wxDefaultPosition,
179 const wxSize& size = wxDefaultSize,
180 long style = wxScrolledWindowStyle,
181 const wxString& name = wxPanelNameStr)
182 : wxGenericScrolledWindow(parent, id, pos, size, style, name)
183 {
184 }
185
186 private:
187 DECLARE_CLASS(wxScrolledWindow)
188 };
189
190 #define wxSCROLLED_WINDOW_IS_GENERIC 1
191 #endif
192
193 #endif
194 // _WX_SCROLWIN_H_BASE_