[ ppcall150 ]


Public Domain By JoeV jov@mountain.net Feb-18-2007
This applet returns the pen x and y position if a pendown event occurred and
the position is within the x,y,w,h parameters sent it. If the pen position is
out of bounds, or if a pendown event hasn't occurred, a null string is returned.
Call the applet from izibasic using the format: R$=CALLPP(150,S$) where:
S$ = "x,y,w,h" where x=xposition, y=yposition, w=xwidth, h=yheight.
R$ = null string if pendown event is out of the x,y,w,h bounds.
R$ = null string if a pendown event has not occurred.
R$ = "x,y" if a pendown event occurred within the x,y,w,h bounds.
Example: R$=callpp$(150,"0,0,160,160) will return any pendown event.
Code Follows:
{$code appl,JVxx,code,150} //required by iziBasic
program ppcall150;

{$i PalmAPI.pas}
type
   iBasFunType=function(S:string):string;  //required by iziBasic
   typeparm=array[1..4] of string;

var
   iBasCallPP:iBasFunType;     //required by iziBasic    

//Other required api calls.
function StrLen(const str:string):uint16;inline(SYSTRAP,$A0C7);

function CallPP(S:string):string;
var
   s1,s2:string;
   x,y,w,h:int16;
   timeo:int32;
   ev:EventType;   
   len,index,parmindex:uint16;
   pstr:typeparm;

begin
{Search thru s to get string parameters passed to applet. The parms are
delimited with commas and then stored in string array pstr[1..4]. A maximum of
4 parms are allowed. Extras are ignored.}
   s1:='';
   pstr1:=;pstr2:=;pstr3:=;pstr4:=;
   parmindex:=1;index:=1;
   len:=strlen(s);
   while index<=len do 
       begin
           if (sindex=',')
           then 
               begin
               pstrparmindex:=s1;    //save parm if comma found
               parmindex:=parmindex+1;
               s1:=''
               end
           else 
               begin
               s1:=s1+sindex;        //else, keep building new parm string
               if index=len
               then
                   begin
                   pstrparmindex:=s1;    //also, save parm if last char
                   parmindex:=parmindex+1
                   end;           
           end;
       if parmindex>4 then index:=len;     //quit if 4 parms are received        
       index:=index+1    
       end;

   x:=stratoi(pstr1);
   y:=stratoi(pstr2);
   w:=stratoi(pstr3);
   h:=stratoi(pstr4);
   EvtGetEvent(ev,0);    
   callpp:='';
   if ev.etype=penDownEvent
   then 
       begin       //check if pen position within x,x+w & y,y+h
       if (ev.screenX<x) or (ev.screenX>(x+w))then ev.screenX:=-1;
       if (ev.screenY<y) or (ev.screenY>(y+h))then ev.screenY:=-1;
       if (ev.screenX<>-1) and (ev.screenY<>-1) 
       then
           begin
           stritoa(s1,ev.screenX);     //return pen position if within bounds
           stritoa(s2,ev.screenY);
           callpp:=s1+','+s2
           end;
       end;

end;

//Main. Required by iziBasic
begin
iBasCallPP:=CallPP;

end.
  pages read