1 /////////////////////////////////////////////////////////////////////////////
2 // Name: include/wx/vscroll.h
3 // Purpose: wxVScrolledWindow: generalization of wxScrolledWindow
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_VSCROLL_H_
13 #define _WX_VSCROLL_H_
15 #include "wx/panel.h" // base class
17 // ----------------------------------------------------------------------------
19 // ----------------------------------------------------------------------------
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).
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.
35 class WXDLLEXPORT wxVScrolledWindow
: public wxPanel
38 // constructors and such
39 // ---------------------
41 // default ctor, you must call Create() later
42 wxVScrolledWindow() { Init(); }
44 // normal ctor, no need to call Create() after this one
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
,
53 const wxString
& name
= wxPanelNameStr
)
57 (void)Create(parent
, id
, pos
, size
, style
, name
);
60 // same as the previous ctor but returns status code: true if ok
62 // just as with the ctor above, wxVSCROLL style is always used, there is no
64 bool Create(wxWindow
*parent
,
65 wxWindowID id
= wxID_ANY
,
66 const wxPoint
& pos
= wxDefaultPosition
,
67 const wxSize
& size
= wxDefaultSize
,
69 const wxString
& name
= wxPanelNameStr
)
71 return wxPanel::Create(parent
, id
, pos
, size
, style
| wxVSCROLL
, name
);
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
);
83 // scroll to the specified line: it will become the first visible line in
86 // return true if we scrolled the window, false if nothing was done
87 bool ScrollToLine(size_t line
);
89 // scroll by the specified number of lines/pages
90 virtual bool ScrollLines(int lines
);
91 virtual bool ScrollPages(int pages
);
93 // redraw the specified line
94 void RefreshLine(size_t line
);
96 // redraw all lines in the specified range (inclusive)
97 void RefreshLines(size_t from
, size_t to
);
99 // return the item at the specified (in physical coordinates) position or.
101 // wxNOT_FOUND if none, i.e. if it is below the last item
102 int HitTest(wxCoord x
, wxCoord y
) const;
103 int HitTest(const wxPoint
& pt
) const { return HitTest(pt
.x
, pt
.y
); }
105 // recalculate all our parameters and redisplay all lines
106 virtual void RefreshAll();
112 // get the number of lines this window contains (previously set by
114 size_t GetLineCount() const { return m_lineMax
; }
116 // get the first currently visible line
117 size_t GetFirstVisibleLine() const { return m_lineFirst
; }
119 // get the last currently visible line
120 size_t GetLastVisibleLine() const { return m_lineFirst
+ m_nVisible
- 1; }
122 // is this line currently visible?
123 bool IsVisible(size_t line
) const
124 { return line
>= m_lineFirst
&& line
<= GetLastVisibleLine(); }
128 // this function must be overridden in the derived class and it should
129 // return the height of the given line in pixels
130 virtual wxCoord
OnGetLineHeight(size_t n
) const = 0;
132 // this function doesn't have to be overridden but it may be useful to do
133 // it if calculating the lines heights is a relatively expensive operation
134 // as it gives the user code a possibility to calculate several of them at
137 // OnGetLinesHint() is normally called just before OnGetLineHeight() but you
138 // shouldn't rely on the latter being called for all lines in the interval
139 // specified here. It is also possible that OnGetLineHeight() will be
140 // called for the lines outside of this interval, so this is really just a
141 // hint, not a promise.
143 // finally note that lineMin is inclusive, while lineMax is exclusive, as
145 virtual void OnGetLinesHint(size_t lineMin
, size_t lineMax
) const { }
148 // the event handlers
149 void OnSize(wxSizeEvent
& event
);
150 void OnScroll(wxScrollWinEvent
& event
);
152 // find the index of the line we need to show at the top of the window such
153 // that the last (fully or partially) visible line is the given one
154 size_t FindFirstFromBottom(size_t lineLast
, bool fullyVisible
= false);
156 // get the total height of the lines between lineMin (inclusive) and
157 // lineMax (exclusive)
158 wxCoord
GetLinesHeight(size_t lineMin
, size_t lineMax
) const;
160 // update the thumb size shown by the scrollbar
161 void UpdateScrollbar();
164 // common part of all ctors
168 // the total number of (logical) lines
171 // the total (estimated) height
172 wxCoord m_heightTotal
;
174 // the first currently visible line
177 // the number of currently visible lines (including the last, possibly only
178 // partly, visible one)
182 DECLARE_EVENT_TABLE()
185 #endif // _WX_VSCROLL_H_