Hi - I read in the archives about the discussion people had about dynamic
scrollbars a while back, and I do NOT want to reignite the debate;
however, I do have one of these "Zen" UIs that are in the vast minority,
and need to find a solution.  

Specifically, I am working on what can best be described as a
multi-windowed microbrowser; I know I will have one main window (and in
the past, I used the make-a-static-form-with-a-hidden-scrollbar trick).  
But I may need to make a completely arbitrary number of other windows,
some little dialog boxes, but some larger windows which may need to
scroll.  There's really no way I can do this statically (unless I can load
and set bounds on a single form resource multiple times, which I don't
believe is possible?).

I don't care about support beyond the here and now (Palm OS 3.5-4.1), and
although I really hope OS 5 provides some way of addressing this, I am
willing to rewrite whatever code I write today as a gadget or something
when OS 5 comes along.  But I want to be able to FrmNewForm a form, and
then manually edit the object list to add my scrollbar object.  Here's the
code:

    // attach a scrollbar.

    ScrollBarType * sclBar = (ScrollBarType
*)MemPtrNew(sizeof(ScrollBarType));
    MemSet(sclBar,MemPtrSize((MemPtr)sclBar),0);

        // initialize scrollbar, etc.

-snip-

    // add the scrollbar to the form's object list.  

    mainForm = FrmGetFormPtr(ID);

    MemHandle memH =
MemHandleNew(sizeof(FormObjListType)*(FrmGetNumberOfObjects(mainForm)+1));
    FormObjListType * newObjects = (FormObjListType *)MemHandleLock(memH);
    MemSet(newObjects,MemPtrSize((MemPtr)newObjects),0);

MEMMOVE(newObjects,mainForm->objects,sizeof(FormObjListType)*(FrmGetNumberOfObjects(mainForm)));

    FormObjListType folt = newObjects[FrmGetNumberOfObjects(mainForm)];

    folt.objectType = frmScrollBarObj;
    folt.object.scrollBar = sclBar;
  
    // THIS ACCESSES INTERNALS

    mainForm->objects = newObjects;
    mainForm->numObjects++;

    // DONE ACCESSING INTERNALS
    
    MemHandleUnlock(memH);

    FrmDrawForm(mainForm);

---


Aside from the fact that you're not supposed to do this, can anybody tell
me what I'm missing?  When I try this, I usually just get a crash when I
next try to add a dynamic UI object to my form, which makes sense, I
guess.  I think I need to know:

-whether using MemHandleNew is the right way to allocate a movable chunk
that the Form knows how to deal with when it next needs to add memory,

-whether the dynamic heap is even the right place to allocate the Form's
object list, and

-whether there's just a better way to do this in general.

There's an outside chance that I could fake this by generating speculative
resources at compile time, and I'm going to look into that too.  But
honestly, no matter how dirty it is, a dynamic solution would be better
for me right now.  Does anybody have experience doing this?  Thanks...

-Dan


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to