]> git.saurik.com Git - wxWidgets.git/blob - include/wx/scrolwin.h
Now uses GetFileAttributes for wxPathExists and wxFileExists under Windows,
[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 wxScrollHelperEvtHandler;
18 class WXDLLEXPORT wxTimer;
19
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 // ----------------------------------------------------------------------------
25
26 class WXDLLEXPORT wxScrollHelper
27 {
28 public:
29 // ctor and dtor
30 wxScrollHelper(wxWindow *winToScroll = (wxWindow *)NULL);
31 void SetWindow(wxWindow *winToScroll);
32 virtual ~wxScrollHelper();
33
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 );
39
40 // scroll to the given (in logical coords) position
41 virtual void Scroll(int x, int y);
42
43 // get/set the page size for this orientation (wxVERTICAL/wxHORIZONTAL)
44 int GetScrollPageSize(int orient) const;
45 void SetScrollPageSize(int orient, int pageSize);
46
47 // get the size of one logical unit in physical ones
48 virtual void GetScrollPixelsPerUnit(int *pixelsPerUnitX,
49 int *pixelsPerUnitY) const;
50
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);
57
58 // Get the view start
59 virtual void GetViewStart(int *x, int *y) const;
60
61 // Actual size in pixels when scrolling is taken into account
62 virtual void GetVirtualSize(int *x, int *y) const;
63
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; }
68
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;
72
73 // Adjust the scrollbars
74 virtual void AdjustScrollbars(void);
75
76 // Calculate scroll increment
77 virtual int CalcScrollInc(wxScrollWinEvent& event);
78
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;
85
86 void SetTargetRect(const wxRect& rect) { m_rectToScroll = rect; }
87 wxRect GetTargetRect() const { return m_rectToScroll; }
88
89 // Override this function to draw the graphic (or just process EVT_PAINT)
90 virtual void OnDraw(wxDC& WXUNUSED(dc)) { }
91
92 // change the DC origin according to the scroll position.
93 virtual void DoPrepareDC(wxDC& dc);
94
95 // are we generating the autoscroll events?
96 bool IsAutoScrolling() const { return m_timerAutoScroll != NULL; }
97
98 // stop generating the scroll events when mouse is held outside the window
99 void StopAutoScrolling();
100
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
105 //
106 // the base class version just returns TRUE
107 virtual bool SendAutoScrollEvents(wxScrollWinEvent& event) const;
108
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);
116 #if wxUSE_MOUSEWHEEL
117 void HandleOnMouseWheel(wxMouseEvent& event);
118 #endif // wxUSE_MOUSEWHEEL
119
120 protected:
121 // get pointer to our scroll rect if we use it or NULL
122 const wxRect *GetRect() const
123 {
124 return m_rectToScroll.width != 0 ? &m_rectToScroll : NULL;
125 }
126
127 // get the size of the target window
128 wxSize GetTargetSize() const
129 {
130 return m_rectToScroll.width != 0 ? m_rectToScroll.GetSize()
131 : m_targetWindow->GetClientSize();
132 }
133
134 void GetTargetSize(int *w, int *h)
135 {
136 wxSize size = GetTargetSize();
137 if ( w )
138 *w = size.x;
139 if ( h )
140 *h = size.y;
141 }
142
143 // change just the target window (unlike SetWindow which changes m_win as
144 // well)
145 void DoSetTargetWindow(wxWindow *target);
146
147 // delete the event handler we installed
148 void DeleteEvtHandler();
149
150 wxWindow *m_win,
151 *m_targetWindow;
152
153 wxRect m_rectToScroll;
154
155 wxTimer *m_timerAutoScroll;
156
157 int m_xScrollPixelsPerLine;
158 int m_yScrollPixelsPerLine;
159 int m_xScrollPosition;
160 int m_yScrollPosition;
161 int m_xScrollLines;
162 int m_yScrollLines;
163 int m_xScrollLinesPerPage;
164 int m_yScrollLinesPerPage;
165
166 bool m_xScrollingEnabled;
167 bool m_yScrollingEnabled;
168
169 double m_scaleX;
170 double m_scaleY;
171
172 #if wxUSE_MOUSEWHEEL
173 int m_wheelRotation;
174 #endif // wxUSE_MOUSEWHEEL
175
176 wxScrollHelperEvtHandler *m_handler;
177 };
178
179 // ----------------------------------------------------------------------------
180 // wxScrolledWindow: a wxWindow which knows how to scroll
181 // ----------------------------------------------------------------------------
182
183 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
184 #include "wx/gtk/scrolwin.h"
185 #else // !wxGTK
186 #include "wx/generic/scrolwin.h"
187
188 class WXDLLEXPORT wxScrolledWindow : public wxGenericScrolledWindow
189 {
190 public:
191 wxScrolledWindow() { }
192 wxScrolledWindow(wxWindow *parent,
193 wxWindowID id = -1,
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)
199 {
200 }
201
202 private:
203 DECLARE_CLASS(wxScrolledWindow)
204 };
205
206 #define wxSCROLLED_WINDOW_IS_GENERIC 1
207 #endif
208
209 #endif
210 // _WX_SCROLWIN_H_BASE_