]> git.saurik.com Git - wxWidgets.git/blame - include/wx/vscroll.h
Addition at simple wxObject*, support into wxVariant.
[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$
8// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_VSCROLL_H_
13#define _WX_VSCROLL_H_
14
15#include "wx/panel.h" // base class
16
17// ----------------------------------------------------------------------------
18// wxVScrolledWindow
19// ----------------------------------------------------------------------------
20
21/*
22 In the name of this class, "V" may stand for "variable" because it can be
23 used for scrolling lines of variable heights; "virtual" because it is not
24 necessary to know the heights of all lines in advance -- only those which
25 are shown on the screen need to be measured; or, even, "vertical" because
26 this class only supports scrolling in one direction currently (this could
27 and probably will change in the future however).
28
29 In any case, this is a generalization of the wxScrolledWindow class which
30 can be only used when all lines have the same height. It lacks some other
31 wxScrolledWindow features however, notably it currently lacks support for
32 horizontal scrolling; it can't scroll another window nor only a rectangle
33 of the window and not its entire client area.
34 */
af9fe887 35class WXDLLEXPORT wxVScrolledWindow : public wxPanel
cf7d6329
VZ
36{
37public:
38 // constructors and such
39 // ---------------------
40
41 // default ctor, you must call Create() later
42 wxVScrolledWindow() { Init(); }
43
44 // normal ctor, no need to call Create() after this one
45 //
46 // note that wxVSCROLL is always automatically added to our style, there is
47 // no need to specify it explicitly
48 wxVScrolledWindow(wxWindow *parent,
49 wxWindowID id = wxID_ANY,
50 const wxPoint& pos = wxDefaultPosition,
51 const wxSize& size = wxDefaultSize,
52 long style = 0,
53 const wxString& name = wxPanelNameStr)
54 {
55 Init();
56
57 (void)Create(parent, id, pos, size, style, name);
58 }
59
60 // same as the previous ctor but returns status code: true if ok
61 //
62 // just as with the ctor above, wxVSCROLL style is always used, there is no
63 // need to specify it
64 bool Create(wxWindow *parent,
65 wxWindowID id,
66 const wxPoint& pos = wxDefaultPosition,
67 const wxSize& size = wxDefaultSize,
68 long style = 0,
69 const wxString& name = wxPanelNameStr)
70 {
71 return wxPanel::Create(parent, id, pos, size, style | wxVSCROLL, name);
72 }
73
74
75 // operations
76 // ----------
77
78 // set the number of lines the window contains: the derived class must
79 // provide the heights for all lines with indices up to the one given here
80 // in its OnGetLineHeight()
81 void SetLineCount(size_t count);
82
83 // scroll to the specified line: it will become the first visible line in
84 // the window
85 //
86 // return true if we scrolled the window, false if nothing was done
87 bool ScrollToLine(size_t line);
88
89 // scroll by the specified number of lines/pages
90 virtual bool ScrollLines(int lines);
91 virtual bool ScrollPages(int pages);
92
e0c6027b
VZ
93 // redraw the specified line
94 void RefreshLine(size_t line);
95
96 // return the item at the specified (in physical coordinates) position or
97 // wxNOT_FOUND if none, i.e. if it is below the last item
98 int HitTest(wxCoord x, wxCoord y) const;
99 int HitTest(const wxPoint& pt) const { return HitTest(pt.x, pt.y); }
100
cf7d6329
VZ
101
102 // accessors
103 // ---------
104
105 // get the number of lines this window contains (previously set by
106 // SetLineCount())
107 size_t GetLineCount() const { return m_lineMax; }
108
109 // get the first currently visible line
110 size_t GetFirstVisibleLine() const { return m_lineFirst; }
111
112 // get the last currently visible line
113 size_t GetLastVisibleLine() const { return m_lineFirst + m_nVisible - 1; }
114
e0c6027b
VZ
115 // is this line currently visible?
116 bool IsVisible(size_t line) const
117 { return line >= m_lineFirst && line <= GetLastVisibleLine(); }
118
cf7d6329 119
e0c6027b 120protected:
cf7d6329
VZ
121 // this function must be overridden in the derived class and it should
122 // return the height of the given line in pixels
123 virtual wxCoord OnGetLineHeight(size_t n) const = 0;
124
125 // this function doesn't have to be overridden but it may be useful to do
126 // it if calculating the lines heights is a relatively expensive operation
127 // as it gives the user code a possibility to calculate several of them at
128 // once
129 //
130 // OnGetLinesHint() is normally called just before OnGetLineHeight() but you
131 // shouldn't rely on the latter being called for all lines in the interval
132 // specified here. It is also possible that OnGetLineHeight() will be
133 // called for the lines outside of this interval, so this is really just a
134 // hint, not a promise.
135 //
136 // finally note that lineMin is inclusive, while lineMax is exclusive, as
137 // usual
138 virtual void OnGetLinesHint(size_t lineMin, size_t lineMax) const { }
139
e0c6027b 140
cf7d6329
VZ
141 // the event handlers
142 void OnSize(wxSizeEvent& event);
143 void OnScroll(wxScrollWinEvent& event);
144
145 // find the index of the line we need to show at the top of the window such
146 // that the last line shown is the given one
147 size_t FindFirstFromBottom(size_t lineLast);
148
149 // get the total height of the lines between lineMin (inclusive) and
150 // lineMax (exclusive)
151 wxCoord GetLinesHeight(size_t lineMin, size_t lineMax) const;
152
153 // update the thumb size shown by the scrollbar
154 void UpdateScrollbar();
155
156private:
157 // common part of all ctors
158 void Init();
159
160
161 // the total number of (logical) lines
162 size_t m_lineMax;
163
164 // the total (estimated) height
165 wxCoord m_heightTotal;
166
167 // the first currently visible line
168 size_t m_lineFirst;
169
170 // the number of currently visible lines (including the last, possibly only
171 // partly, visible one)
172 size_t m_nVisible;
173
174
175 DECLARE_EVENT_TABLE()
176};
177
178#endif // _WX_VSCROLL_H_
179