You could also use a field. You have to handle some field events, but it is
quite doable. I have multiple scrollable fields in my app, so have
developed some utility routines that I use. Check them out:
/***************************************************************************
***
** Function: NoteViewHandleEvent
** Description: Main event handler for note view dialog box
** Parameters: event
** pointer to event to be handled
** Returns: True if we handled it, False if it should go to someone
** more capable than I.
****************************************************************************
**/
Boolean NoteViewHandleEvent(
EventPtr event)
{
FieldPtr fld;
UInt16 formId;
FormPtr frm;
Boolean handled;
UInt16 index;
UInt16 pos;
handled = False;
switch (event->eType)
{
// handle your events here...
case frmOpenEvent:
frm = FrmGetActiveForm();
// other form open processing here...
WsUpdateScrollBarField(NoteField, NoteScrollBar);
handled = True;
break; // end form open
} // end switch
// if not yet handled, check for field scrolling
if (!handled)
handled = WsHandleFieldScrolling(
event,
NoteField,
NoteScrollBar);
return handled;
} // end NoteViewHandleEvent
/***************************************************************************
***
** Function: WsHandleFieldScrolling
** Description: handles events for fields with scroll bars
** These are field changed, key down, and
scroll repeat.
** Parameters: event, fldId, barId
** Returns: whether handled
****************************************************************************
**/
Boolean WsHandleFieldScrolling(
EventPtr event,
UInt16 fldId,
UInt16 barId)
{
Boolean handled;
handled = False;
switch (event->eType)
{
case fldChangedEvent:
{
WsUpdateScrollBarField(fldId, barId);
handled = True;
} break; // end field changed
case keyDownEvent:
{
if (event->data.keyDown.chr == pageUpChr)
{
WsPageScrollField(winUp, fldId, barId);
handled = True;
}
else if (event->data.keyDown.chr == pageDownChr)
{
WsPageScrollField(winDown, fldId, barId);
handled = True;
}
} break; // end key down
case sclRepeatEvent:
{
WsScrollField(
event->data.sclRepeat.newValue -
event->data.sclRepeat.value,
fldId, barId);
} break; // end scroll repeat
} // end switch on event type
return handled;
} // end WsHandleFieldScrolling
/***************************************************************************
***
** Function: WsPageScrollField
** Description: scrolls a field and updates an assoicated scroll bar.
** Parameters: lines, barId, fldId
****************************************************************************
**/
void WsPageScrollField(
WinDirectionType direction,
UInt16 fldId,
UInt16 barId)
{
ScrollBarPtr bar;
FieldPtr fld;
FormPtr frm;
UInt16 index;
UInt16 linesToScroll;
Int16 min;
Int16 max;
Int16 pageSize;
Int16 value;
frm = FrmGetActiveForm();
index = FrmGetObjectIndex(frm, fldId);
fld = FrmGetObjectPtr(frm, index);
if (FldScrollable(fld, direction))
{
linesToScroll = FldGetVisibleLines(fld) - 1;
FldScrollField(fld, linesToScroll, direction);
// Update the scroll bar.
index = FrmGetObjectIndex(frm, barId);
bar = FrmGetObjectPtr(frm, index);
SclGetScrollBar(bar, &value, &min, &max, &pageSize);
if (direction == winUp)
value -= (Int16)linesToScroll;
else
value += (Int16)linesToScroll;
SclSetScrollBar(bar, value, min, max, pageSize);
}
} // end WsPageScrollField
/***************************************************************************
***
** Function: WsScrollField
** Description: scrolls a field and updates an assoicated scroll bar.
** Parameters: lines, barId, fldId
****************************************************************************
**/
void WsScrollField(
Int16 lines,
UInt16 fldId,
UInt16 barId)
{
ScrollBarPtr bar;
UInt16 blankLines;
FieldPtr fld;
FormPtr frm;
UInt16 index;
Int16 min;
Int16 max;
Int16 pageSize;
Int16 value;
frm = FrmGetActiveForm();
index = FrmGetObjectIndex(frm, fldId);
fld = FrmGetObjectPtr(frm, index);
if (lines < 0)
{
blankLines = FldGetNumberOfBlankLines(fld);
FldScrollField(fld, (UInt16)-lines, winUp);
// If there were blank lines visible at the end of the field
// then we need to update the scroll bar.
if (blankLines)
{
// Update the scroll bar.
index = FrmGetObjectIndex(frm, barId);
bar = FrmGetObjectPtr(frm, index);
SclGetScrollBar(bar, &value, &min, &max, &pageSize);
if (blankLines > -lines)
max += lines;
else
max -= (Int16)blankLines;
SclSetScrollBar(bar, value, min, max, pageSize);
}
}
else if (lines > 0)
FldScrollField(fld, (UInt16)lines, winDown);
} // end WsScrollField
/***************************************************************************
***
** Function: WsUpdateScrollBarField
** Description: updates a scroll bar and field combination.
** Parameters: lines, barId, fldId
****************************************************************************
**/
void WsUpdateScrollBarField(
UInt16 fldId,
UInt16 barId)
{
ScrollBarPtr bar;
UInt16 fieldHeight;
FieldPtr fld;
FormPtr frm;
UInt16 index;
UInt16 scrollPos;
UInt16 textHeight;
Int16 maxValue;
frm = FrmGetActiveForm();
index = FrmGetObjectIndex(frm, fldId);
fld = FrmGetObjectPtr(frm, index);
index = FrmGetObjectIndex(frm, barId);
bar = FrmGetObjectPtr(frm, index);
FldGetScrollValues(fld, &scrollPos, &textHeight, &fieldHeight);
if (textHeight > fieldHeight)
maxValue = (Int16)(textHeight - fieldHeight);
else if (scrollPos)
maxValue = (Int16)scrollPos;
else
maxValue = 0;
SclSetScrollBar(
bar,
(Int16)scrollPos,
0,
maxValue,
(Int16)(fieldHeight - 1));
} // end WsUpdateScrollBarField
-----Original Message-----
From: Dave Lippincott [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, October 23, 2001 6:52 AM
To: Palm Developer Forum
Subject: Re: Scrollbar example.
a list or table would be better. I'd use a table but lists are easier.
----- Original Message -----
From: "WebMaster - MantroTech" <[EMAIL PROTECTED]>
Newsgroups: palm-dev-forum
To: "Palm Developer Forum" <[EMAIL PROTECTED]>
Sent: Monday, October 22, 2001 8:14 PM
Subject: Scrollbar example.
> Hi All.
> I need to display text on form which exceeds one screen in height, so
I
> guess I need to implement a scroll bar. On top of the screen there is a
logo
> which shouldn't be scrolled but rest of the text needs to be scrollable.
> Currently I am displaying Text by using labels, should I use another
> resource for the same and how should I use scrollbars with the same?
> Will appreciate any help.
>
> regards
>
>
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/tech/support/forums/
>
--
For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/tech/support/forums/
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/