In my experience, it's easier/safer when implementing unique pen behavior on
a form or even within a gadget to "usurp" the event loop on the
penDownEvent, rather than process penDown, penMove, and penUp in the main
form's event loop and maintain all of that state between events. I
personally find I get in trouble when, inevitably, events come in an order
that I didn't expect and something doesn't get freed or something
not-yet-allocated gets used.

For example, if you look at MemoMain.c in the SDK (the source code to Memo
Pad), on tblEnterEvent, control passes to ListViewSelectMemo(), which
contains a loop that looks a lot like this:

while (1) {
    PenGetPoint (&x, &y, &penDown);
    if (!penDown) break;
    // redraw things on the screen based on pen location
    // and update my internal state
}

Palm does this in several instances in the sample apps and the OS sources.
It'd be interesting to hear from Architect Fedor whether or not this is good
behavior to emulate. It kind of feels "wrong" to take control of the event
loop for the entire duration that the user has the pen down on the screen.
But it sure makes things easier!

Peter

"liuchoi" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
> I would like to let the user to select a particular area in a graph screen
> (The graph screen is now exists). Now I have made a feature that enables
the
> user to "drag" a dotted rectangle using WinDrawGrayRectangleFrame(),
> like the one in windows for selecting icons.
>
> I tried to use WinSaveBits() when penDownEvent occurs to save the whole
> screen and draw the screen back when penMoveEvent occur by
WinRestoreBits().
> However, when I run it in my Palm m515, It complains with a fatal alert:
>
> MemoryMgr.c, Line:4475
> Invalid chunk ptr
>
> and require me to reset. It merely makes my PC hang when I run it in POSE.
:(
> I tried to use WinEraseRectangleFrame() when penMoveEvent occur to erase
> the previous rectangle. It seems works but the graph is spoiled.
>
> The WinRestoreBits() only works when penUpEvent occur. As a result, when
user
> is selecting the graph, the graph will be  spoiled. Fortunately, it can be
> restored back to the original one when the stylus take off from the
screen.
> But I hope to make it looks like the Windows one, that means the dotted
> rectangle won't spoil the background graph. Could anybody teach me how to
> achieve that?
>
> Sorry for my poor English.
>
> Here is what I have written:
>
> switch (eventP->eType) {
>    case penDownEvent:
>      if (RctPtInRectangle(eventP->screenX,eventP->screenY,&gDrawRect)){
>        SavedRegion = WinSaveBits(&wholeScreenRect, &rectErr);
>        gX =eventP->screenX;
>        gY =eventP->screenY;
>        gPenDown =true;
>        handled =true;
>      }
>    break;
>    case penMoveEvent:
>
>      if
(RctPtInRectangle(eventP->screenX,eventP->screenY,&gDrawRect)&&gPenDown){
>        WinEraseRectangleFrame(rectangleFrame, &dottedRect);
>        WinRestoreBits(SavedRegion, 0, 0);  //fatal alert occurs when this
line exists
>        newX =eventP->screenX;
>        newY =eventP->screenY;
>        dottedRect.topLeft.x = gX;
>        dottedRect.topLeft.y = gY;
>        dottedRect.extent.x = newX - gX;
>        dottedRect.extent.y = newY - gY;
>        WinDrawGrayRectangleFrame(rectangleFrame, &dottedRect);
>
>        handled =true;
>      }
>    break;
>    case penUpEvent:
>      if
(RctPtInRectangle(eventP->screenX,eventP->screenY,&gDrawRect)&&gPenDown){
>        newX =eventP->screenX;
>        newY =eventP->screenY;
>        gX =gDrawRect.topLeft.x;
>        gY =gDrawRect.topLeft.y;
>        gPenDown =false;
>        handled =true;
>      }
>    break;
> }
>
>
>



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

Reply via email to