Example 10-3. Scrollbar compute scroll procedure example (continued)
xv_set(sb, SCROLLBAR_VIEW_LENGTH, last_plus_one - first,
0);
*offset = first;
return (XV_OK);
}
In this example, the textsw package keeps track of the object size based on the number of
characters in the view. When the user scrolls, the object length will most probably change, so
the textsw package uses its own compute scroll procecure to calculate a new object length
and offset each time there is a scroll request. This is needed for cases when the user scrolls
backwards and data is still coming into the textsw, so the object length grows (the propor-
tional indicator shrinks).
10.4.2.1 Indicating scrollbar motion
The attribute
SCROLLBAR_MOTION provides the scrolling motion that resulted during a
scrollbar_request event. This attribute is get only. Possible valid motions returned are:
ABSOLUTE
POINT_TO_MIN (from here_to_top on menu)
PAGE_FORWARD
LINE_FORWARD
MIN_TO_POINT (from top_to_here on menu)
PAGE_BACKWARD
LINE_BACKWARD
TO_END
TO_START
PAGE_ALIGNED
10.4.3 Providing a Scrollbar Normalize Procedure
The scrollbar package provides for a special offset routine that may be used to adjust the new
scroll position before the scrollbar package scrolls to the starting location computed by the
scrollbar compute procedure. This special offset routine, called the normalize procedure,
allows you to perform a scroll adjustment when, for example, the new scroll position would
split an object in the view. By default, no normalize procedure is specified and the scrollbar
package scrolls to the starting location computed by the compute procedure, as shown in the
previous section. Use
SCROLLBAR_NORMALIZE_PROC
to name a normalize procedure used to
adjust the offset.
The function set with SCROLLBAR_NORMALIZE_PROC should return vstart. The function takes
the offset given by the compute_proc and adjusts it. The scrollbar package will then
scroll to this offset into the object. The form of the normalize scroll routine is:
void
my_scrollbar_normalize_proc(sb, voffset, motion, vstart)
Scrollbar sb;
long unsigned offset;
268 XView Programming Manual
Scroll_motion motion;
long unsigned *vstart; /* new offset, this is the new view start*/
See the following example:
Example 10-4. Scrollbar normalize procedure example
panel_normalize_scroll(sb, offset, motion, vs)
Scrollbar sb;
long unsigned offset;
Scroll_motion motion;
long unsigned *vs; /* new offset == new viewstart */
{
line_ht = (int) xv_get(sb, SCROLLBAR_PIXELS_PER_UNIT);
/* If everything in the panel is in view, then dont scroll. */
if ((int) xv_get(sb, SCROLLBAR_OBJECT_LENGTH) <=
(int) xv_get(sb, SCROLLBAR_VIEW_LENGTH))
return (*vs = offset);
switch (motion) {
case SCROLLBAR_ABSOLUTE:
case SCROLLBAR_LINE_FORWARD:
case SCROLLBAR_TO_START:
align_to_max = TRUE;
scrolling_up = TRUE;
break;
case SCROLLBAR_PAGE_FORWARD:
case SCROLLBAR_TO_END:
align_to_max = TRUE;
scrolling_up = TRUE;
break;
case SCROLLBAR_POINT_TO_MIN:
align_to_max = TRUE;
scrolling_up = TRUE;
break;
case SCROLLBAR_MIN_TO_POINT:
align_to_max = TRUE;
scrolling_up = FALSE;
break;
case SCROLLBAR_PAGE_BACKWARD:
case SCROLLBAR_LINE_BACKWARD:
align_to_max = FALSE;
scrolling_up = FALSE;
break;
}
*vs = offset;
return (XV_OK);
}
Scrollbars
Scrollbars 269
The panel package uses this to ensure panel items are aligned properly and partial items are
not visible. The scrollbar package calls scrollbar_compute_scroll_proc and
scrollbar_normalize_proc in that order whenever any scrolling is done.
10.5 Scrollbar Package Summary
The procedures and macros in the SCROLLBAR package are listed in the next two tables.
Table 10-1 lists the procedure for the SCROLLBAR package. Table 10-2 lists the attributes in
the SCROLLBAR package. This information is described fully in the XView Reference Man-
ual.
Table 10-1. Scrollbar Procedures
scrollbar_paint()
scrollbar_default_compute_scroll_proc()
Table 10-2. Scrollbar Attributes
SCROLLBAR_DIRECTION SCROLLBAR_PAGE_LENGTH
SCROLLBAR_LAST_VIEW_START SCROLLBAR_PIXELS_PER_UNIT
SCROLLBAR_MENU SCROLLBAR_SPLITTABLE
SCROLLBAR_NOTIFY_CLIENT SCROLLBAR_VIEW_LENGTH
SCROLLBAR_OBJECT_LENGTH SCROLLBAR_VIEW_START
SCROLLBAR_MOTION
270 XView Programming Manual
This page intentionally left blank
to preserve original page counts.
This page intentionally left blank
to preserve original page counts.

Get Volume 7A: XView Programming Manual now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.