I am having one of those nights where I can't seem to lock down the problem
I am having.
Maybe someone can point that obvious error (hopefully).
I've used this code (parts from Memopad example and parts from elsewhere) in
a previous project; it worked fine there. When I dropped
the code into a new project -- it just doesn't work.
- Form Loads (works)
- String resources attached to Field and displays on form (works)
- scrollbars update with content. (works)
- Scrolling (no work... sigh)
- I have Field Scrollbar attached property set in the resource.
a funny side effect is that the scroll bars update in weird ways (after
scrolling up and down a few times) -- then they disappear right off the
form.
I've included the three scrolling/field functions along with my
FormHandleEvent for the form in question.
I keep on looking at this; then comparing to my other project. I can't find
the difference in how they are used and what makes one work over the other.
The only real difference between the programs are that the original working
example in an expanded application (Using CallbackThunk). I wouldn't think
that
it would effect the scrollbars...
going crazy..
Maybe its something I didn't do in the resource file that I have
forgotten...
--Wolfgang
PS : These fields are non editable as well.
-----------------------Source------------------------------------
/************************************************************************
* FUNCTION: PageScroll
* DESCRIPTION: Will Scroll our help text in a up or down direction.
Hardwired to a particular field/scrollbar combo.
* PARAMETERS: winUp/winDown,Field ID, ScrollbarID
* RETURNS: Zilcho..
*************************************************************************/
static void PageScroll (WinDirectionType direction,Int16 fieldID,Int16
barID)
{
Int16 value;
Int16 min;
Int16 max;
Int16 pageSize;
Int16 linesToScroll;
FieldPtr fld;
ScrollBarPtr bar;
FormPtr formP;
formP = FrmGetActiveForm();
fld = (FieldPtr) FrmGetObjectPtr(formP, fieldID);
if (FldScrollable (fld, direction))
{
linesToScroll = FldGetVisibleLines (fld) - 1;
FldScrollField (fld, -linesToScroll, direction);
// Update the scroll bar.
bar = (ScrollBarPtr) FrmGetObjectPtr(formP, barID);
SclGetScrollBar (bar, &value, &min, &max, &pageSize);
if (direction == winUp)
value -= linesToScroll;
else
value += linesToScroll;
SclSetScrollBar (bar, value, min, max, pageSize);
return;
}
FldGrabFocus (fld);
}
/***********************************************************************
* FUNCTION: FieldScroll
* DESCRIPTION: P13. Scrolls a field a line at a time.
* PARAMETERS: linesToScroll - number of lines to scroll,
* negative numbers are used to scroll up
***********************************************************************/
static void FieldScroll (Int16 linesToScroll,Int16 fieldID,Int16 barID)
{
Int16 blankLines;
Int16 min;
Int16 max;
Int16 value;
Int16 pageSize;
FieldPtr fld;
ScrollBarPtr bar;
FormPtr formP;
formP = FrmGetActiveForm();
fld = (FieldPtr) FrmGetObjectPtr(formP, fieldID);
if (linesToScroll < 0)
{
blankLines = FldGetNumberOfBlankLines (fld);
FldScrollField (fld, -linesToScroll, 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.
bar = (ScrollBarPtr) FrmGetObjectPtr(formP, barID);
SclGetScrollBar (bar, &value, &min, &max, &pageSize);
if (blankLines > -linesToScroll)
max += linesToScroll;
else
max -= blankLines;
SclSetScrollBar (bar, value, min, max, pageSize);
}
}
else (linesToScroll > 0)
FldScrollField (fld, linesToScroll, winDown);
}
/************************************************************************
* FUNCTION: UpdateScrollBar
* DESCRIPTION: Refreshes the scroll bars' settings after the field it repre
senting changes shape or size.
* PARAMETERS: fieldID ,ScrollbarID
* RETURNS: none
*************************************************************************/
static void UpdateScrollBar (Int16 fieldID,Int16 barID)
{
UInt16 scrollPos;
UInt16 textHeight;
UInt16 fieldHeight;
UInt16 maxValue;
FieldAttrType attr;
FieldPtr fld;
ScrollBarPtr bar;
FormPtr formP;
formP = FrmGetActiveForm();
fld = (FieldPtr) FrmGetObjectPtr(formP, fieldID);
bar = (ScrollBarPtr) FrmGetObjectPtr(formP, barID);
FldGetScrollValues (fld, &scrollPos, &textHeight, &fieldHeight);
if (textHeight > fieldHeight)
maxValue = textHeight - fieldHeight;
else if (scrollPos)
maxValue = scrollPos;
else
maxValue = 0;
FldGetAttributes (fld, &attr);
attr.hasScrollBar = true;
SclSetScrollBar (bar, scrollPos, 0, maxValue, fieldHeight-1);
}
/************************************************************************
* FUNCTION: PresentationFormHandleEvent
* DESCRIPTION: handles events for the presentation form
* PARAMETERS: EventType
* RETURNS: none
*************************************************************************/
static Boolean PresentationFormHandleEvent(EventType * eventP)
{
Boolean handled = false;
FormType * formP;
Int16 fieldID;
FieldPtr fieldPointer;
MemHandle MemHandleString;
formP = FrmGetActiveForm();
switch (eventP->eType)
{
case keyDownEvent:
if (eventP->data.keyDown.chr == pageUpChr)
{
PageScroll (winUp,FrmGetObjectIndex (formP,
PresentationQuestion_textField),FrmGetObjectIndex (formP,
PresentationScrollerScrollBar));
handled = true;
}
else if(eventP->data.keyDown.chr == pageDownChr)
{
PageScroll (winDown,FrmGetObjectIndex (formP,
PresentationQuestion_textField),FrmGetObjectIndex (formP,
PresentationScrollerScrollBar));
handled = true;
}
case ctlSelectEvent:
return PresentationFormDoButton(eventP->data.menu.itemID);
case sclRepeatEvent: // Scrollbar action (arrows and handle move)
FieldScroll (eventP->data.sclRepeat.newValue -
eventP->data.sclRepeat.value,FrmGetObjectIndex (formP,
PresentationQuestion_textField),FrmGetObjectIndex (formP,
PresentationScrollerScrollBar));
break;
case frmOpenEvent:
formP = FrmGetActiveForm();
PresentationFormInit(formP);
FrmDrawForm(formP);
MemHandleString = DmGet1Resource('tSTR', Presentation1String);
formP = FrmGetActiveForm();
fieldID=FrmGetObjectIndex (formP,
PresentationQuestion_textField);
fieldPointer = (FieldPtr) FrmGetObjectPtr(formP, fieldID);
FldSetTextHandle (fieldPointer, MemHandleString);
UpdateScrollBar(FrmGetObjectIndex (formP,
PresentationQuestion_textField),FrmGetObjectIndex (formP,
PresentationScrollerScrollBar));
DmReleaseResource(MemHandleString);
FrmDrawForm(formP);
FldSetTextHandle (fieldPointer, NULL);
handled = true;
break;
case frmUpdateEvent:
break;
default:
break;
}
return handled;
}
----------------------------------------------------------------------------
------------------
Wolfgang Bochar
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/