Scrollbar widget

Application Header file <Xraw/Scrollbar.h>
Class Header file <Xraw/ScrollbarP.h>
Class scrollbarWidgetClass
Class Name Scrollbar
Superclass Simple --> Core

Table of Contents


    The Scrollbar widget is a rectangular area containing a slide region and a thumb (also known as a slide bar). A Scrollbar can be used alone, as a value generator, or it can be used within a composite widget (for example, a Viewport). A Scrollbar can be oriented either vertically or horizontally.

    When a Scrollbar is created, it is drawn with the thumb in a contrasting color. The thumb is normally used to scroll client data and to give visual feedback on the percentage of the client data that is visible.

    Each pointer button invokes a specific action. That is, given either a vertical or horizontal orientation, the pointer button actions will scroll or return data as appropriate for that orientation. Pointer buttons 1 and 3 do not move the thumb automatically. Instead, they return the pixel position of the cursor on the scroll region. When pointer button 2 is clicked, the thumb moves to the current pointer position. When pointer button 2 is held down and the pointer is moved, the thumb follows the pointer.

    The pointer cursor in the scroll region changes depending on the current action. When no pointer button is pressed, the cursor appears as a double-headed arrow that points in the direction that scrolling can occur. When pointer button 1 or 3 is pressed, the cursor appears as a single-headed arrow that points in the logical direction that the client will move the data. When pointer button 2 is pressed, the cursor appears as an arrow that points to the thumb.

    While scrolling is in progress, the application receives notification through callback procedures. For both discrete scrolling actions, the callback returns the Scrollbar widget, the client_data, and the pixel position of the pointer when the button was released. For continuous scrolling, the callback routine returns the scroll bar widget, the client data, and the current relative position of the thumb. When the thumb is moved using pointer button 2, the callback procedure is invoked continuously. When either button 1 or 3 is pressed, the callback procedure is invoked only when the button is released and the client callback procedure is responsible for moving the thumb.


New Resources

Name Class Type Notes Default Value
increment Increment Dimension CSG 10
length Length Dimension CSG 1
minimumThumb MinimumThumb Dimension CSG 7
orientation Orientation Orientation CSG XtorientVertical
page_increment Increment Dimension CSG 20
repeatDelay RepeatDelay Int CSG 150
shown Shown Float CSG 0.0
stripeColor StripeColor Pixel CSG Dinamic
thumbColor ThumbColor Pixel CSG Dinamic
thickness Thickness Dimension CSG 10
topOfThumb TopOfThumb Float CSG 0.0
 
Callback resources
jumpProc Callback XtCallbackList C NULL
incrementProc Callback XtCallbackList C NULL
decrementProc Callback XtCallbackList C NULL
pageIncrementProc Callback XtCallbackList C NULL
pageDecrementProc Callback XtCallbackList C NULL
valueChangedProc Callback XtCallbackList C NULL
dragProc Callback XtCallbackList C NULL
toTopProc Callback XtCallbackList C NULL
toBottomProc Callback XtCallbackList C NULL
thumbProc Callback XtCallbackList C NULL
scrollProc Callback XtCallbackList C NULL
length The height of a vertical scrollbar or the width of a horizontal scrollbar.
minimumThumb The smallest size, in pixels, to which the thumb can shrink.
orientation The orientation is the direction that the thumb will be allowed to move. This value can be either XtorientVertical or XtorientHorizontal.
shown This is the size of the thumb, expressed as a percentage (0.0 - 1.0) of the length of the scrollbar.
thickness The width of a vertical scrollbar or the height of a horizontal scrollbar.
topOfThumb The location of the top of the thumb, as a percentage (0.0 - 1.0) of the length of the scrollbar. This resource was called top in previous versions of the Athena widget set. The name collided with the a Form widget constraint resource, and had to be changed.

Callback resources

jumpProc All functions on this callback list are called when the NotifyThumb action is invoked.
scrollProc All functions on this callback list may be called when the NotifyScroll action is invoked. See the Scrollbar Actions section for details.

Inherited Resources

Simple class resources
Name Class Type Notes Default Value
bottomShadowPixel BottomShadowPixel Pixel CSG Dinamic
bottomShadowPixmap BottomShadowPixmap Pixmap CSG UnspecifiedPixmap
cursor Cursor Cursor CSG None
cursorName CursorName String C NULL
highlightPixel highlightPixel Pixel CSG Dinamic
highlightPixmap highlightPixmap Pixmap CSG UnspecifiedPixmap
highlightThickness HighlightThickness Dimension CSG 2
insensitiveBorder Insensitive Pixmap CSG None**GreyPixmap
foreground Foreground Pixel CSG XtDefaultForeground
shadowWidth ShadowWidth Dimension CSG 0
topShadowPixmap TopShadowPixmap Pixmap CSG UnspecifiedPixmap
topShadowPixel TopShadowPixel Pixel CSG Dinamic
userData UserData XtPointer CSG NULL
 
Core class resources
Name Class Type Notes Default Value
accelerators Accelerators XtAccelerators CSG NULL
ancestorSensitive AncestorSensitive Boolean G True
background Background Pixel CSG XtDefaultBackground
backgroundPixmap Pixmap Pixmap CSG XtUnspecifiedPixmap
borderColor BorderColor Pixel CSG XtDefaultForeground
borderPixmap Pixmap Pixmap CSG XtUnspecifiedPixmap
borderWidth BorderWidth Dimension CSG 0
colormap Colormap Colormap CG Parent's Colormap
depth Depth int CG Parent's Depth
destroyCallback Callback XtCallbackList C NULL
height Height Dimension CSG Dinamic
initialResourcesPersistent InitialResourcesPersistent Boolean C True
mappedWhenManaged MappedWhenManaged Boolean CSG True
screen Screen Screen CG Parent's Screen
sensitive Sensitive Boolean CSG True
translations Translations XtTranslations CSG NULL
width Width Dimension CSG Dinamic
x Position Position CSG 0
y Position Position CSG 0


Scrollbar Actions

The actions supported by the Scrollbar widget are:
StartScroll() This must be the first action to begin a new movement.
NotifyScroll() This executes the scrollProc callbacks and passes the position of the pointer.
EndScroll() This must be the last action after a movement is complete.
MoveThumb() Repositions the Scrollbar's thumb to the current pointer location. It executes the valueChangedProc callbacks with reason XawSB_VALUE_CHANGED and the thumbProc and jumpProc callbacks for backward compatibility with the Athena.
NotifyThumb() This is the same as MoveThumb(). It is used just for backward compatibility with the Athena.
PageDownOrRight(value) If the value is Right and the Scrollbar widget is horizontal or if the value is Down and the Scrollbar widget is vertical, then it increases topOfThumb by one pages.
PageUpOrLeft(value) If the value is Left and the Scrollbar widget is horizontal or if the value is Up and the Scrollbar widget is vertical, then it reduces topOfThumb by one pages.

The default bindings for Scrollbar are:

     <Btn1Down>:     StartScroll()                 
     <Btn2Down>:     StartScroll() NotifyThumb()   
     <Btn3Down>:     StartScroll()                 
     <Btn1Motion>:   Moved()                       
     <Btn2Motion>:   NotifyThumb()                 
     <BtnUp>:        NotifyScroll() EndScroll()    
     Ctrl<Key>Right: PageDownOrRight(Right)      
     Ctrl<Key>Left:  PageUpOrLeft(Left)          
     Ctrl<Key>Down:  PageDownOrRight(Down)       
     Ctrl<Key>Up:    PageUpOrLeft(Up)            
     Meta<Key>Right: ToBottom(Right)             
     Meta<Key>Left:  ToTop(Left)                 
     Meta<Key>Down:  ToBottom(Down)              
     Meta<Key>Up:    ToTop(Up)                   
     <Key>Right:     IncrementDownOrRight(Right) 
     <Key>Left:      IncrementUpOrLeft(Left)     
     <Key>Down:      IncrementDownOrRight(Down)  
     <Key>Up:        IncrementUpOrLeft(Up)

Scrollbar Callbacks

There are two callback lists provided by the Scrollbar widget. The procedural interface for these functions is described here.

The calling interface to the scrollProc callback procedure is:



void ScrollProc(scrollbar, client_data, position)
	Widget scrollbar;
	XtPointer client_data;
	XtPointer position;        /* int */
scrollbar Specifies the Scrollbar widget.
client_data Specifies the client data.
position Specifies a pixel position in integer form.

The scrollProc callback is used for incremental scrolling and is called by the NotifyScroll action. The position argument is a signed quantity and should be cast to an int when used. Using the default button bindings, button 1 returns a positive value, and button 3 returns a negative value. In both cases, the magnitude of the value is the distance of the pointer in pixels from the top (or left) of the Scrollbar. The value will never be greater than the length of the Scrollbar.

The calling interface to the jumpProc callback procedure is:



void JumpProc(scrollbar, client_data, percent)
	Widget scrollbar;
	XtPointer client_data;
	XtPointer percent_ptr; /* float* */
scrollbar Specifies the ID of the scroll bar widget.
client_data Specifies the client data.
percent_ptr Specifies the floating point position of the thumb (0.0 - 1.0).

The jumpProc callback is used to implement smooth scrolling and is called by the NotifyThumb action. Percent_ptr must be cast to a pointer to float before use; i.e.

	float percent = *(float*)percent_ptr;

With the default button bindings, button 2 moves the thumb interactively, and the jumpProc is called on each new position of the pointer, while the pointer button remains down. The value specified by percent_ptr is the current location of the thumb (from the top or left of the Scrollbar) expressed as a percentage of the length of the Scrollbar.


Convenience routines

To set the position and length of a Scrollbar thumb, use XawScrollbarSetThumb.


void XawScrollbarSetThumb(w, top, shown)
	Widget w;
	float top;
	float shown;
w Specifies the Scrollbar widget.
top Specifies the position of the top of the thumb as a fraction of the length of the Scrollbar.
shown Specifies the length of the thumb as a fraction of the total length of the Scrollbar.

XawScrollbarThumb moves the visible thumb to a new position (0.0 - 1.0) and length (0.0 - 1.0). Either the top or shown arguments can be specified as -1.0, in which case the current value is left unchanged. Values greater than 1.0 are truncated to 1.0.

If called from jumpProc, XawScrollbarSetThumb has no effect.


Setting Float Resources

The shown and topOfThumb resources are of type float. These resources can be difficult to get into an argument list. The reason is that C performs an automatic cast of the float value to an integer value, usually truncating the important information. The following code fragment is one portable method of getting a float into an argument list.


  top = 0.5;
  if (sizeof(float) > sizeof(XtArgVal)) {
  /*
   * If a float is larger than an XtArgVal then pass this 
   * resource value by reference.
   */
       XtSetArg(args[0], XtNshown, &top);
  }
  else {
  /*
   * Convince C not to perform an automatic conversion, which
   * would truncate 0.5 to 0. 
   */
       XtArgVal * l_top = (XtArgVal *) ⊤
       XtSetArg(args[0], XtNshown, *l_top);
  }


[Xraw home]       [Xraw widget class hierarchy]


Vladimir T. Romanovski
romsky@hp1.oea.ihep.su