I had the same problem. Here's how I associated a multi-line list field with
a vertical scrollbar:

In the code that loads the field, it must update the scroll bar:

        FieldPtr         fP;
        ScrollBarPtr sbP;
        Word vPos;
        Word nLines;
        Word vLines;
        Word max;

...
        
        fP = GetObjectPtr(MainResponseField);
        sbP = GetObjectPtr(MainListScrollBar);

.. (code here sets the field contents and calls FldDrawField)

        // Get the scrolling info from the field
        FldGetScrollValues(fP, &vPos, &nLines, &vLines);

        // Ensure scrollbar works OK when there are less lines of text than
there are in the field
        max = ( nLines > vLines ) ? nLines - vLines : 0;  

        // Set the scrollbar
        SclSetScrollBar(sbP, vPos, 0, max, vLines);

...

Now, in the event handler (AppHandleEvent, in the source generated by CW6)
you need to
handle the scrollbar events and scroll the field. I did this by calling a
common update
function. Note the Boolean variable "handled" which is returned to the
caller. This needs
to be false on the sclRepeatEvent, or the thing won't scroll smoothly:

...

        switch ( eventP->eType )
        {
...
        case sclExitEvent:
                updateListField(eventP->data.sclExit.newValue);
                handled = true;
                break;

        case sclRepeatEvent:
                updateListField(eventP->data.sclRepeat.newValue);
                handled = false;
                break;

...
        }
        return handled;

Here's the esential parts of the update function:

void updateListField(Word newPos)
{
        FieldPtr fldP;
        Word linesToScroll;
        Word pos;
        DirectionType dir;
        Word txtHeight;
        Word fldHeight;
        
        fldP = GetObjectPtr(MainResponseField);
        
        FldGetScrollValues(fldP, &pos, &txtHeight, &fldHeight);
        
        if ( newPos >= pos )
        {
                dir = down;
                linesToScroll = newPos - pos;
        }
        else
        {
                dir = up;
                linesToScroll = pos - newPos;
        }
        
        FldScrollField(fldP, linesToScroll, dir);
}

        
> -----Original Message-----
> From: [EMAIL PROTECTED] [SMTP:[EMAIL PROTECTED]]
> Sent: Thursday, February 17, 2000 9:29 AM
> To:   Palm Developer Forum
> Subject:      hasScrollbar Field Attribute Question ...
> 
> Hi All,
> 
> I have seen the field attribute hasScrollbar and am now playing around
> with
> this flag.
> 
> Unfortunately I can't get this to work and would like to ask for some
> hint's
> on how to use that.
> 
> I have simply set this to true programaticaly expecting a scrollbar to
> appear. Obviously a wrong assumption .
> I placed a scrollbar on the form and am looking for a way to associate the
> scrollbar to the field.
> 
> Am I completely on the wrong track or how would I handle a field with 500
> chars that must be scrollable with a scrollbar.
> 
> Any pointers/advices are greatly appreciated
> Thanks in advance
> Ole
> 

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palm.com/devzone/mailinglists.html

Reply via email to