OWLNext    7.0
Borland's Object Windows Library for the modern age
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
scrollba.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1991, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Implementation of class TScrollBar. This defines the basic behavior of all
7/// scrollbar controls.
8//----------------------------------------------------------------------------
9#include <owl/pch.h>
10#include <owl/scrollba.h>
11#include <owl/uimetric.h>
12
13namespace owl {
14
16
17DEFINE_RESPONSE_TABLE1(TScrollBar, TControl)
21
22//
23/// Constructs and initializes a TScrollBar object with the given parent window
24/// (parent), a control ID (id), a position (x, y), and a width and height (w, h).
25/// Invokes the TControl constructor with similar parameters. If isHScrollBar is
26/// true, the constructor adds SBS_HORZ to the window style. If it is false, the
27/// constructor adds SBS_VERT. If the supplied height for a horizontal scroll bar or
28/// the supplied width for a vertical scroll bar is 0, a standard system metric value is used.
29/// LineMagnitude is initialized to 1 and PageMagnitude is set to 10.
30//
32 int id,
33 int x, int y, int w, int h,
34 bool isHScrollBar,
35 TModule* module)
36:
37 TControl(parent, id, nullptr, x, y, w, h, module)
38{
39 LineMagnitude = 1;
40 PageMagnitude = 10;
41
42 if (isHScrollBar) {
43 Attr.Style |= SBS_HORZ;
44
45 if (Attr.H == 0)
46 Attr.H = TUIMetric::CyHScroll;
47 }
48 else {
49 Attr.Style |= SBS_VERT;
50
51 if (Attr.W == 0)
52 Attr.W = TUIMetric::CxVScroll;
53 }
54}
55
56//
57/// Constructs a TScrollBar object to be associated with a scroll bar control of a
58/// TDialog object. Invokes the TControl constructor with identical parameters.
59/// The resourceId parameter must correspond to a scroll bar resource that you
60/// define.
61///
62/// The LineMagnitude is set to 1 by default.
63/// The PageMagnitude is set to 10 by default.
64//
66 int resourceId,
67 TModule* module)
68:
69 TControl(parent, resourceId, module)
70{
71 LineMagnitude = 1;
72 PageMagnitude = 10;
73}
74
75//
76/// Constructs a scroll bar object to encapsulate (alias) an existing control.
77//
79:
80 TControl(hWnd, module),
81 LineMagnitude(1)
82{
84 ZeroMemory(&info, sizeof info);
85 info.cbSize = sizeof info;
86 info.fMask = SIF_PAGE;
88 PageMagnitude = info.nPage;
89}
90
91//
92/// Transfers scroll-bar data to or from the transfer buffer pointed to by buffer,
93/// which is expected to point to a TScrollBarData structure.
94/// Data is transferred to or from the transfer buffer if tdGetData or tdSetData is
95/// supplied as the direction.
96/// Transfer always returns the size of the transfer data (the size of the
97/// TScrollBarData structure). To retrieve the size of this data without
98/// transferring data, pass tdSizeData as the direction.
99//
100uint
102{
103 if (!buffer && direction != tdSizeData) return 0;
105
106 if (direction == tdGetData) {
107 GetRange(scrollBuff->LowValue, scrollBuff->HighValue);
108 scrollBuff->Position = GetPosition();
109 }
110 else if (direction == tdSetData) {
111 SetRange(scrollBuff->LowValue, scrollBuff->HighValue);
112 SetPosition(scrollBuff->Position);
113 }
114
115 return sizeof(TScrollBarData);
116}
117
118//
119/// Returns the name of TScrollBar's registration class, "SCROLLBAR".
120//
122{
123 return TWindowClassName{_T("SCROLLBAR")};
124}
125
126//
127/// Sets the scroll bar's range to 0, 100. To redefine this range, call SetRange.
128//
129void
135
136//
137/// Sets scrollbar info
138//
139void
145
146//
147/// Retrieves the scroll info.
148//
149void
155
156//
157/// Returns the scroll bar's current thumb position.
158//
159int
161{
164 ZeroMemory(&info, sizeof info);
165 info.cbSize = sizeof info;
166 info.fMask = SIF_POS;
168 return info.nPos;
169}
170
171//
172/// Moves the thumb to the position specified in thumbPos. If thumbPos is outside
173/// the present range of the scroll bar, the thumb is moved to the closest position
174/// within range.
175//
176void
178{
180 int minValue, maxValue;
182
183 // Constrain "thumbPos" to be in the range "minValue .. maxValue"
184 //
185 if (thumbPos > maxValue)
187
188 else if (thumbPos < minValue)
190
191 if (thumbPos != GetPosition()) {
193 ZeroMemory(&info, sizeof info);
194 info.cbSize = sizeof info;
195 info.fMask = SIF_POS;
196 info.nPos = thumbPos;
198 }
199}
200
201//
202/// Returns the current delta to move the thumb when page up/page down is received.
203//
204int
206{
207 return PageMagnitude;
208}
209
210//
211/// Sets the delta to move the thumb when page up/page down is received.
212//
213void
215{
216 PageMagnitude = pagemagnitude;
219 ZeroMemory(&info, sizeof info);
220 info.cbSize = sizeof info;
221 info.fMask = SIF_PAGE;
222 info.nPage = pagemagnitude;
224}
225
226//
227/// Returns the end values of the present range of scroll bar thumb positions in minValue and maxValue.
228//
229void
231{
234 ZeroMemory(&info, sizeof info);
235 info.cbSize = sizeof info;
236 info.fMask = SIF_RANGE;
238 minValue = info.nMin;
239 maxValue = info.nMax;
240}
241
242//
243/// Sets the scroll bar to the range between min and max.
244//
245void
247{
250 ZeroMemory(&info, sizeof info);
251 info.cbSize = sizeof info;
252 info.fMask = SIF_RANGE;
253 info.nMin = minValue;
254 info.nMax = maxValue;
256}
257
258
259//
260/// Calls SetPosition to change the scroll bar's thumb position by the value
261/// supplied in delta. A positive delta moves the thumb down or right. A negative
262/// delta value moves the thumb up or left. DeltaPos returns the new thumb position.
263//
264int
266{
267 if (delta != 0)
269
270 return GetPosition();
271}
272
273//
274/// Calls SetPosition to move the thumb up or left (by LineMagnitude units).
275/// SBLineUp is called to respond to a click on the top or left arrow of the scroll
276/// bar.
277//
278void
280{
281 DeltaPos(-LineMagnitude);
282}
283
284//
285/// Calls SetPosition to move the thumb down or right (by LineMagnitude units).
286/// SBLineDown is called to respond to a click on the bottom or right arrow of the
287/// scroll bar.
288//
289void
291{
292 DeltaPos(LineMagnitude);
293}
294
295//
296/// Calls SetPosition to move the thumb up or left (by PageMagnitude units).
297/// SBPageUp is called to respond to a click in the top or left scrolling area of
298/// the scroll bar.
299//
300void
302{
303 DeltaPos(-PageMagnitude);
304}
305
306//
307/// Calls SetPosition to move the thumb down or right (by PageMagnitude units).
308/// SBPageDown is called to respond to a click in the bottom or right scrolling area
309/// of the scroll bar.
310//
311void
313{
314 DeltaPos(PageMagnitude);
315}
316
317//
318/// Calls SetPosition to move the thumb. SBThumbPosition is called to respond when
319/// the thumb is set to a new position.
320//
321void
326
327//
328/// Calls SetPosition to move the thumb as it is being dragged to a new position.
329//
330void
335
336//
337/// Calls SetPosition to move the thumb to the top or right of the scroll bar. SBTop
338/// is called to respond to the thumb's being dragged to the top or rightmost
339/// position on the scroll bar.
340//
341void
348
349//
350/// Calls SetPosition to move the thumb to the bottom or right of the scroll bar.
351/// SBBottom is called to respond to the thumb's being dragged to the bottom or
352/// rightmost position of the scroll bar.
353//
354void
361
362//
363/// User released the mouse after scrolling.
364//
365void
369
370//
371/// Response table handler that calls the virtual function (SBBottom, SBLineDown and
372/// so on) in response to messages sent by TWindow::DispatchScroll.
373//
374void
376{
377 // Note that the passed 'thumbPos' only contains 16-bit position data.
378 // See MSDN (http://msdn.microsoft.com/en-us/library/windows/desktop/bb787575.aspx).
379 // We call GetScrollPos or GetScrollTrackPos as appropriate to try to get 32-bit data.
380 // Also see [bugs:#227](http://sourceforge.net/p/owlnext/bugs/227).
381 //
382 switch (scrollCode) {
383 case SB_LINEDOWN: SBLineDown(); break;
384 case SB_LINEUP: SBLineUp(); break;
385 case SB_PAGEDOWN: SBPageDown(); break;
386 case SB_PAGEUP: SBPageUp(); break;
387 case SB_TOP: SBTop(); break;
388 case SB_BOTTOM: SBBottom(); break;
389 case SB_THUMBPOSITION:
390 {
391 int thumbPos32 = GetScrollPos(SB_CTL); // May fail and return 0.
392 int p = (thumbPos32 != 0) ? thumbPos32 : thumbPos;
394 break;
395 }
396 case SB_THUMBTRACK:
397 {
398 int thumbPos32 = GetScrollTrackPos(SB_CTL); // May fail and return 0.
399 int p = (thumbPos32 != 0) ? thumbPos32 : thumbPos;
400 SBThumbTrack(p);
401 break;
402 }
404 }
405}
406
407//
408/// Response table handler that calls the virtual function (SBBottom, SBLineDown and
409/// so on) in response to messages sent by TWindow::DispatchScroll.
410//
411void
413{
414 // Simply forward to EvHScroll, since the code is identical.
415 //
417}
418
420
421#if OWL_PERSISTENT_STREAMS
422
423//
424// Reads an instance of TScrollBar from the passed ipstream.
425//
426void*
427TScrollBar::Streamer::Read(ipstream& is, uint32 /*version*/) const
428{
429 ReadBaseObject((TControl*)GetObject(), is);
430 is >> GetObject()->LineMagnitude
431 >> GetObject()->PageMagnitude;
432 return GetObject();
433}
434
435//
436// Writes the TScrollBar to the passed opstream.
437//
438void
439TScrollBar::Streamer::Write(opstream& os) const
440{
441 WriteBaseObject((TControl*)GetObject(), os);
442 os << GetObject()->LineMagnitude
443 << GetObject()->PageMagnitude;
444}
445
446#endif
447
448} // OWL namespace
449/* ========================================================================== */
450
#define PRECONDITION(condition)
Definition checks.h:227
TControl unifies its derived control classes, such as TScrollBar, TControlGadget, and TButton.
Definition control.h:38
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
TScrollBar objects represent standalone vertical and horizontal scroll bar controls.
Definition scrollba.h:41
void SetPageMagnitude(int pagemagnitude)
Sets the delta to move the thumb when page up/page down is received.
Definition scrollba.cpp:214
virtual void SBLineUp()
Calls SetPosition to move the thumb up or left (by LineMagnitude units).
Definition scrollba.cpp:279
int GetPageMagnitude() const
Returns the current delta to move the thumb when page up/page down is received.
Definition scrollba.cpp:205
virtual void SetScrollInfo(SCROLLINFO *info, bool redraw=true)
Sets scrollbar info.
Definition scrollba.cpp:140
virtual void SBLineDown()
Calls SetPosition to move the thumb down or right (by LineMagnitude units).
Definition scrollba.cpp:290
void Transfer(TScrollBarData &data, TTransferDirection direction)
Safe overload.
Definition scrollba.h:88
virtual void SetPosition(int thumbPos, bool redraw=true)
Moves the thumb to the position specified in thumbPos.
Definition scrollba.cpp:177
auto GetWindowClassName() -> TWindowClassName override
Returns the name of TScrollBar's registration class, "SCROLLBAR".
Definition scrollba.cpp:121
TScrollBar(TWindow *parent, int id, int x, int y, int w, int h, bool isHScrollBar, TModule *module=0)
Constructs and initializes a TScrollBar object with the given parent window (parent),...
Definition scrollba.cpp:31
virtual void SBBottom()
Calls SetPosition to move the thumb to the bottom or right of the scroll bar.
Definition scrollba.cpp:355
virtual void SBThumbPosition(int thumbPos)
Calls SetPosition to move the thumb.
Definition scrollba.cpp:322
void SetupWindow() override
Sets the scroll bar's range to 0, 100. To redefine this range, call SetRange.
Definition scrollba.cpp:130
virtual void SBThumbTrack(int thumbPos)
Calls SetPosition to move the thumb as it is being dragged to a new position.
Definition scrollba.cpp:331
virtual void SBEndScroll()
User released the mouse after scrolling.
Definition scrollba.cpp:366
virtual void GetRange(int &minValue, int &maxValue) const
Returns the end values of the present range of scroll bar thumb positions in minValue and maxValue.
Definition scrollba.cpp:230
virtual int GetPosition() const
Returns the scroll bar's current thumb position.
Definition scrollba.cpp:160
virtual void GetScrollInfo(SCROLLINFO *info) const
Retrieves the scroll info.
Definition scrollba.cpp:150
virtual void SBPageDown()
Calls SetPosition to move the thumb down or right (by PageMagnitude units).
Definition scrollba.cpp:312
virtual void SBTop()
Calls SetPosition to move the thumb to the top or right of the scroll bar.
Definition scrollba.cpp:342
virtual void SetRange(int minValue, int maxValue, bool redraw=true)
Sets the scroll bar to the range between min and max.
Definition scrollba.cpp:246
virtual int DeltaPos(int delta)
Calls SetPosition to change the scroll bar's thumb position by the value supplied in delta.
Definition scrollba.cpp:265
void EvHScroll(uint scrollCode, uint thumbPos, HWND hWndCtl)
Response table handler that calls the virtual function (SBBottom, SBLineDown and so on) in response t...
Definition scrollba.cpp:375
void EvVScroll(uint scrollCode, uint thumbPos, HWND hWndCtl)
Response table handler that calls the virtual function (SBBottom, SBLineDown and so on) in response t...
Definition scrollba.cpp:412
virtual void SBPageUp()
Calls SetPosition to move the thumb up or left (by PageMagnitude units).
Definition scrollba.cpp:301
static const TUIMetric CyHScroll
Definition uimetric.h:37
static const TUIMetric CxVScroll
Definition uimetric.h:36
Type-safe encapsulation of a Windows class name, a union between ATOM and LPCTSTR.
Definition module.h:47
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
int GetScrollTrackPos(int bar) const
Returns the thumb track position in the scroll bar.
Definition window.cpp:4104
int GetScrollPos(int bar) const
Returns the thumb position in the scroll bar.
Definition window.cpp:4080
virtual void SetupWindow()
Performs setup following creation of an associated MS-Windows window.
Definition window.cpp:2575
HWND THandle
TWindow encapsulates an HWND.
Definition window.h:418
HWND GetHandle() const
Returns the handle of the window.
Definition window.h:2020
ipstream, a specialized input stream derivative of pstream, is the base class for reading (extracting...
Definition objstrm.h:391
#define _T(x)
Definition cygwin.h:51
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
Definition eventhan.h:492
void ReadBaseObject(Base *base, ipstream &in)
Definition objstrm.h:1159
#define IMPLEMENT_STREAMABLE1(cls, base1)
Definition objstrm.h:1725
void WriteBaseObject(Base *base, opstream &out)
Definition objstrm.h:1150
TTransferDirection
The TTransferDirection enum describes the constants that the transfer function uses to determine how ...
Definition window.h:92
@ tdSizeData
Return the size of data transferred by the class.
Definition window.h:95
@ tdSetData
Set data from the buffer into the window.
Definition window.h:94
@ tdGetData
Get data from the window into the buffer.
Definition window.h:93
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
EV_WM_HSCROLL
Definition notetab.cpp:55
unsigned long uint32
Definition number.h:34
OWL_DIAGINFO
Definition animctrl.cpp:14
END_RESPONSE_TABLE
Definition button.cpp:26
EV_WM_VSCROLL
Definition scrollba.cpp:18
unsigned int uint
Definition number.h:25
Definition of class TScrollBar.
The TScrollBarData structure contains integer values that represent a range of thumb positions on the...
Definition scrollba.h:148
Definition of TUIMetric, a UI metrics provider class.