]> git.saurik.com Git - wxWidgets.git/blob - include/wx/scrolwin.h
added default style wxFRAME_TOOL_WINDOW to creation
[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 // FIXME: this is needed for now for wxPlot compilation, should be removed
121 // once it is fixed!
122 void OnScroll(wxScrollWinEvent& event) { HandleOnScroll(event); }
123
124 protected:
125 // get pointer to our scroll rect if we use it or NULL
126 const wxRect *GetRect() const
127 {
128 return m_rectToScroll.width != 0 ? &m_rectToScroll : NULL;
129 }
130
131 // get the size of the target window
132 wxSize GetTargetSize() const
133 {
134 return m_rectToScroll.width != 0 ? m_rectToScroll.GetSize()
135 : m_targetWindow->GetClientSize();
136 }
137
138 void GetTargetSize(int *w, int *h)
139 {
140 wxSize size = GetTargetSize();
141 if ( w )
142 *w = size.x;
143 if ( h )
144 *h = size.y;
145 }
146
147 // change just the target window (unlike SetWindow which changes m_win as
148 // well)
149 void DoSetTargetWindow(wxWindow *target);
150
151 // delete the event handler we installed
152 void DeleteEvtHandler();
153
154 wxWindow *m_win,
155 *m_targetWindow;
156
157 wxRect m_rectToScroll;
158
159 wxTimer *m_timerAutoScroll;
160
161 int m_xScrollPixelsPerLine;
162 int m_yScrollPixelsPerLine;
163 int m_xScrollPosition;
164 int m_yScrollPosition;
165 int m_xScrollLines;
166 int m_yScrollLines;
167 int m_xScrollLinesPerPage;
168 int m_yScrollLinesPerPage;
169
170 bool m_xScrollingEnabled;
171 bool m_yScrollingEnabled;
172
173 double m_scaleX;
174 double m_scaleY;
175
176 #if wxUSE_MOUSEWHEEL
177 int m_wheelRotation;
178 #endif // wxUSE_MOUSEWHEEL
179
180 wxScrollHelperEvtHandler *m_handler;
181 };
182
183 // ----------------------------------------------------------------------------
184 // wxScrolledWindow: a wxWindow which knows how to scroll
185 // ----------------------------------------------------------------------------
186
187 #if defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
188 #include "wx/gtk/scrolwin.h"
189 #else // !wxGTK
190 #include "wx/generic/scrolwin.h"
191
192 class WXDLLEXPORT wxScrolledWindow : public wxGenericScrolledWindow
193 {
194 public:
195 wxScrolledWindow() { }
196 wxScrolledWindow(wxWindow *parent,
197 wxWindowID id = -1,
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)
203 {
204 }
205
206 private:
207 DECLARE_CLASS(wxScrolledWindow)
208 };
209
210 #define wxSCROLLED_WINDOW_IS_GENERIC 1
211 #endif
212
213 #endif
214 // _WX_SCROLWIN_H_BASE_