]> git.saurik.com Git - wxWidgets.git/blob - include/wx/scrolwin.h
mac fixes
[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 #if wxUSE_MOUSEWHEEL
116 void HandleOnMouseWheel(wxMouseEvent& event);
117 #endif // wxUSE_MOUSEWHEEL
118
119 protected:
120 // get pointer to our scroll rect if we use it or NULL
121 const wxRect *GetRect() const
122 {
123 return m_rectToScroll.width != 0 ? &m_rectToScroll : NULL;
124 }
125
126 // get the size of the target window
127 wxSize GetTargetSize() const
128 {
129 return m_rectToScroll.width != 0 ? m_rectToScroll.GetSize()
130 : m_targetWindow->GetClientSize();
131 }
132
133 void GetTargetSize(int *w, int *h)
134 {
135 wxSize size = GetTargetSize();
136 if ( w )
137 *w = size.x;
138 if ( h )
139 *h = size.y;
140 }
141
142 wxWindow *m_win,
143 *m_targetWindow;
144
145 wxRect m_rectToScroll;
146
147 wxTimer *m_timerAutoScroll;
148
149 int m_xScrollPixelsPerLine;
150 int m_yScrollPixelsPerLine;
151 int m_xScrollPosition;
152 int m_yScrollPosition;
153 int m_xScrollLines;
154 int m_yScrollLines;
155 int m_xScrollLinesPerPage;
156 int m_yScrollLinesPerPage;
157
158 bool m_xScrollingEnabled;
159 bool m_yScrollingEnabled;
160
161 double m_scaleX;
162 double m_scaleY;
163
164 #if wxUSE_MOUSEWHEEL
165 int m_wheelRotation;
166 #endif // wxUSE_MOUSEWHEEL
167 };
168
169 // ----------------------------------------------------------------------------
170 // wxScrolledWindow: a wxWindow which knows how to scroll
171 // ----------------------------------------------------------------------------
172
173 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
174 #include "wx/gtk/scrolwin.h"
175 #else // !wxGTK
176 #include "wx/generic/scrolwin.h"
177
178 class WXDLLEXPORT wxScrolledWindow : public wxGenericScrolledWindow
179 {
180 public:
181 wxScrolledWindow() { }
182 wxScrolledWindow(wxWindow *parent,
183 wxWindowID id = -1,
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)
189 {
190 }
191
192 private:
193 DECLARE_CLASS(wxScrolledWindow)
194 };
195
196 #define wxSCROLLED_WINDOW_IS_GENERIC 1
197 #endif
198
199 #endif
200 // _WX_SCROLWIN_H_BASE_