]> git.saurik.com Git - wxWidgets.git/blame - include/wx/vscroll.h
fixed virtual function hiding for LoadBitmap()
[wxWidgets.git] / include / wx / vscroll.h
CommitLineData
cf7d6329
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: include/wx/vscroll.h
3// Purpose: wxVScrolledWindow: generalization of wxScrolledWindow
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 30.05.03
7// RCS-ID: $Id$
77ffb593 8// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
65571936 9// Licence: wxWindows licence
cf7d6329
VZ
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_VSCROLL_H_
13#define _WX_VSCROLL_H_
14
12028905 15#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
687dcff3
VS
16#pragma interface "vscroll.h"
17#endif
18
cf7d6329
VZ
19#include "wx/panel.h" // base class
20
21// ----------------------------------------------------------------------------
22// wxVScrolledWindow
23// ----------------------------------------------------------------------------
24
25/*
26 In the name of this class, "V" may stand for "variable" because it can be
27 used for scrolling lines of variable heights; "virtual" because it is not
28 necessary to know the heights of all lines in advance -- only those which
29 are shown on the screen need to be measured; or, even, "vertical" because
30 this class only supports scrolling in one direction currently (this could
31 and probably will change in the future however).
32
33 In any case, this is a generalization of the wxScrolledWindow class which
34 can be only used when all lines have the same height. It lacks some other
35 wxScrolledWindow features however, notably it currently lacks support for
36 horizontal scrolling; it can't scroll another window nor only a rectangle
37 of the window and not its entire client area.
38 */
af9fe887 39class WXDLLEXPORT wxVScrolledWindow : public wxPanel
cf7d6329
VZ
40{
41public:
42 // constructors and such
43 // ---------------------
44
45 // default ctor, you must call Create() later
46 wxVScrolledWindow() { Init(); }
47
48 // normal ctor, no need to call Create() after this one
49 //
50 // note that wxVSCROLL is always automatically added to our style, there is
51 // no need to specify it explicitly
52 wxVScrolledWindow(wxWindow *parent,
53 wxWindowID id = wxID_ANY,
54 const wxPoint& pos = wxDefaultPosition,
55 const wxSize& size = wxDefaultSize,
56 long style = 0,
57 const wxString& name = wxPanelNameStr)
58 {
59 Init();
60
61 (void)Create(parent, id, pos, size, style, name);
62 }
63
64 // same as the previous ctor but returns status code: true if ok
65 //
66 // just as with the ctor above, wxVSCROLL style is always used, there is no
67 // need to specify it
68 bool Create(wxWindow *parent,
ceb71775 69 wxWindowID id = wxID_ANY,
cf7d6329
VZ
70 const wxPoint& pos = wxDefaultPosition,
71 const wxSize& size = wxDefaultSize,
72 long style = 0,
73 const wxString& name = wxPanelNameStr)
74 {
75 return wxPanel::Create(parent, id, pos, size, style | wxVSCROLL, name);
76 }
77
78
79 // operations
80 // ----------
81
82 // set the number of lines the window contains: the derived class must
83 // provide the heights for all lines with indices up to the one given here
84 // in its OnGetLineHeight()
85 void SetLineCount(size_t count);
86
87 // scroll to the specified line: it will become the first visible line in
88 // the window
89 //
90 // return true if we scrolled the window, false if nothing was done
91 bool ScrollToLine(size_t line);
92
93 // scroll by the specified number of lines/pages
94 virtual bool ScrollLines(int lines);
95 virtual bool ScrollPages(int pages);
96
e0c6027b 97 // redraw the specified line
d62b93c4 98 virtual void RefreshLine(size_t line);
e0c6027b 99
ae0f0223 100 // redraw all lines in the specified range (inclusive)
d62b93c4 101 virtual void RefreshLines(size_t from, size_t to);
ae0f0223 102
ceb71775
VZ
103 // return the item at the specified (in physical coordinates) position or.
104
e0c6027b
VZ
105 // wxNOT_FOUND if none, i.e. if it is below the last item
106 int HitTest(wxCoord x, wxCoord y) const;
107 int HitTest(const wxPoint& pt) const { return HitTest(pt.x, pt.y); }
108
8b053348
VZ
109 // recalculate all our parameters and redisplay all lines
110 virtual void RefreshAll();
111
cf7d6329
VZ
112
113 // accessors
114 // ---------
115
116 // get the number of lines this window contains (previously set by
117 // SetLineCount())
118 size_t GetLineCount() const { return m_lineMax; }
119
120 // get the first currently visible line
dd932cbe 121 size_t GetVisibleBegin() const { return m_lineFirst; }
cf7d6329 122
dd932cbe
VZ
123 // get the first currently visible line
124 size_t GetVisibleEnd() const { return m_lineFirst + m_nVisible; }
cf7d6329 125
e0c6027b
VZ
126 // is this line currently visible?
127 bool IsVisible(size_t line) const
dd932cbe
VZ
128 { return line >= GetVisibleBegin() && line < GetVisibleEnd(); }
129
130
131 // this is the same as GetVisibleBegin(), exists to match
132 // GetLastVisibleLine() and for backwards compatibility only
133 size_t GetFirstVisibleLine() const { return m_lineFirst; }
134
135 // get the last currently visible line
136 //
137 // this function is unsafe as it returns (size_t)-1 (i.e. a huge positive
138 // number) if the control is empty, use GetVisibleEnd() instead, this one
139 // is kept for backwards compatibility
140 size_t GetLastVisibleLine() const { return GetVisibleEnd() - 1; }
e0c6027b 141
cf7d6329 142
e0c6027b 143protected:
cf7d6329
VZ
144 // this function must be overridden in the derived class and it should
145 // return the height of the given line in pixels
146 virtual wxCoord OnGetLineHeight(size_t n) const = 0;
147
148 // this function doesn't have to be overridden but it may be useful to do
149 // it if calculating the lines heights is a relatively expensive operation
150 // as it gives the user code a possibility to calculate several of them at
151 // once
152 //
153 // OnGetLinesHint() is normally called just before OnGetLineHeight() but you
154 // shouldn't rely on the latter being called for all lines in the interval
155 // specified here. It is also possible that OnGetLineHeight() will be
156 // called for the lines outside of this interval, so this is really just a
157 // hint, not a promise.
158 //
159 // finally note that lineMin is inclusive, while lineMax is exclusive, as
160 // usual
27d0dcd0
VZ
161 virtual void OnGetLinesHint(size_t WXUNUSED(lineMin),
162 size_t WXUNUSED(lineMax)) const { }
cf7d6329 163
1e0af0bc
VZ
164 // when the number of lines changes, we try to estimate the total height
165 // of all lines which is a rather expensive operation in terms of lines
166 // access, so if the user code may estimate the average height
167 // better/faster than we do, it should override this function to implement
168 // its own logic
169 //
170 // this function should return the best guess for the total height it may
171 // make
172 virtual wxCoord EstimateTotalHeight() const;
173
e0c6027b 174
cf7d6329
VZ
175 // the event handlers
176 void OnSize(wxSizeEvent& event);
177 void OnScroll(wxScrollWinEvent& event);
4719e58d
RD
178#if wxUSE_MOUSEWHEEL
179 void OnMouseWheel(wxMouseEvent& event);
180#endif
cf7d6329
VZ
181
182 // find the index of the line we need to show at the top of the window such
0b49ccf8
VZ
183 // that the last (fully or partially) visible line is the given one
184 size_t FindFirstFromBottom(size_t lineLast, bool fullyVisible = false);
cf7d6329
VZ
185
186 // get the total height of the lines between lineMin (inclusive) and
187 // lineMax (exclusive)
188 wxCoord GetLinesHeight(size_t lineMin, size_t lineMax) const;
189
190 // update the thumb size shown by the scrollbar
191 void UpdateScrollbar();
192
193private:
194 // common part of all ctors
195 void Init();
196
197
198 // the total number of (logical) lines
199 size_t m_lineMax;
200
201 // the total (estimated) height
202 wxCoord m_heightTotal;
203
204 // the first currently visible line
205 size_t m_lineFirst;
206
207 // the number of currently visible lines (including the last, possibly only
208 // partly, visible one)
209 size_t m_nVisible;
210
4719e58d
RD
211 // accumulated mouse wheel rotation
212#if wxUSE_MOUSEWHEEL
213 int m_sumWheelRotation;
214#endif
cf7d6329
VZ
215
216 DECLARE_EVENT_TABLE()
27d0dcd0 217 DECLARE_NO_COPY_CLASS(wxVScrolledWindow)
0c8392ca 218 DECLARE_ABSTRACT_CLASS(wxVScrolledWindow)
cf7d6329
VZ
219};
220
221#endif // _WX_VSCROLL_H_
222