home *** CD-ROM | disk | FTP | other *** search
/ linuxmafia.com 2016 / linuxmafia.com.tar / linuxmafia.com / pub / palmos / wapuniverse-src-0.3.5.build9.tar.gz / wapuniverse-src-0.3.5.build9.tar / wapuniverse-0.3.5.build9 / formBrowser.c < prev    next >
C/C++ Source or Header  |  2000-11-12  |  34KB  |  1,342 lines

  1. // ---------------------------------------------------------------------------
  2. // FormBrowser.c
  3. // Contains PalmOS specific code, for Browser form
  4. // 
  5. // Project: WAPUniverse for PalmOS
  6. // Copyright ⌐ 1999-2000 Filip Onkelinx
  7. //
  8. // http://www.wapuniverse.com/
  9. // filip@onkelinx.com
  10. //
  11. // This program is free software; you can redistribute it and/or
  12. // modify it under the terms of the GNU General Public License
  13. // as published by the Free Software Foundation; either version 2
  14. // of the License, or (at your option) any later version.
  15. //
  16. // This program is distributed in the hope that it will be useful,
  17. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. // GNU General Public License for more details.
  20. //
  21. // You should have received a copy of the GNU General Public License
  22. // along with this program; if not, write to the Free Software 
  23. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
  24. //
  25. // 
  26. // $Workfile: formBrowser.c $  
  27. // $Author: wapuniverse $  
  28. // $Date: 2000/11/11 20:51:09 $     
  29. // $Revision: 1.21 $
  30. // 
  31. // $Header: /cvsroot/wapuniverse/wapuniverse/src/formBrowser.c,v 1.21 2000/11/11 20:51:09 wapuniverse Exp $
  32. // 
  33. // -------------------------------------------------------------------------------
  34. #include    <PalmOS.h>
  35. #include    <SysEvtMgr.h>
  36. #include     "WAPUniverse.h"
  37. #include    "PalmUtils.h"
  38. #include    "build.h"
  39. #include     "../res/WAPUniverse_res.h"
  40. #include    "formUrlList.h"
  41. #include    "formConnectionList.h"
  42. #include    "formEditConnection.h"
  43. #include    "formEditUrl.h"
  44. #include    "dbConn.h"
  45. #include    "frmScroll.h"
  46. #include     <NetMgr.h>
  47. #include     "wml.h"
  48. #include    "history.h"
  49. #include    "formBrowser.h"
  50. #include    "MenuHnd.h"
  51. #include     "dbOffline.h"
  52. #ifdef __GNUC__
  53. #include "callbacks.h"
  54. #endif
  55.  
  56. #define LINEHEIGHT      12
  57.  
  58.  
  59. static Boolean browserPenUpEvt(EventPtr event, GlobalsType *g);
  60. void palmDrawChars(char *str, Int16 textLen, Int16 x, Int16 y, GlobalsType *g);
  61. Boolean selectInitList (SelectPtr slct, GlobalsType *g);
  62. static void scrollUpdate(GlobalsType *g);
  63.  
  64.  
  65. void MyErrorFunc (char* error, char* additional)
  66. {
  67.  
  68.     FrmCustomAlert (alError, error, additional ? additional : "", NULL);
  69. }
  70.  
  71. static void updateScreen(GlobalsType *g)
  72. {
  73.     WinHandle   tmpDrawWin;
  74.     RectangleType rect={{0, 0}, {153, 132}};
  75.  
  76.     tmpDrawWin = WinGetDrawWindow();
  77.     WinCopyRectangle(g->DrawWin,tmpDrawWin,&rect,0,LINEHEIGHT,winPaint);
  78. }
  79.  
  80. void setVar(Char *name, Char *value, GlobalsType *g)
  81. {
  82.   VarPtr tmp;
  83.   
  84.       tmp= g->Var;
  85.     while(tmp != NULL)
  86.     {
  87.         
  88.         if (StrCompare(name,tmp->name)==0)
  89.         {
  90.             if(tmp->value)
  91.                 Free(tmp->value);
  92.             tmp->value = Malloc(StrLen(value)+1);
  93.             ErrFatalDisplayIf (!tmp->value, "Malloc Failed");
  94.             StrCopy(tmp->value,value);                
  95.             return;            
  96.         }
  97.         tmp = tmp->next;
  98.     }
  99. }
  100.  
  101.  
  102. Boolean selectInitList (SelectPtr slct, GlobalsType *g)
  103. {
  104.   ListPtr         optionslstPtr;
  105.   UInt16          nrOptions;
  106.   UInt16          offset=0;
  107.   FormPtr         frm;
  108.   Char            *txt;
  109.   Char               *options;
  110.   Err             error;
  111.   MemHandle          optionsHandle,optionsListArrayH;          
  112.   OptionPtr       tmp;
  113.   WinHandle         prevDrawWin;
  114.   RectangleType   rect;
  115.   
  116.   nrOptions = 0;
  117.   optionsHandle = MemHandleNew (2);
  118.   options = MemHandleLock (optionsHandle);
  119.   *options = 0;
  120.   tmp = slct->options;
  121.   while(tmp != NULL)
  122.   { 
  123.       if(tmp->txt != NULL){
  124.           MemHandleUnlock (optionsHandle);
  125.           error = MemHandleResize (optionsHandle,StrLen(tmp->txt)+
  126.                                offset + 2);
  127.           options = MemHandleLock (optionsHandle);
  128.           StrCopy(options+offset,tmp->txt);
  129.           offset += (StrLen(tmp->txt)+1);
  130.             nrOptions++;
  131.       }
  132.       tmp=tmp->next;
  133.   }
  134.   *(options+offset)=0;
  135.   if (nrOptions == 0)
  136.     {
  137.       MemHandleUnlock (optionsHandle);
  138.       MemHandleFree (optionsHandle);
  139.       return(false);
  140.     }
  141.   optionsListArrayH = SysFormPointerArrayToStrings (options, nrOptions);
  142.   frm = FrmGetActiveForm();
  143.   optionslstPtr = (ListPtr) (FrmGetObjectPtr (frm, (FrmGetObjectIndex
  144.                                                         (frm, listOption))));
  145.   LstSetListChoices (optionslstPtr, MemHandleLock
  146.                      (optionsListArrayH), nrOptions);
  147.   LstSetHeight (optionslstPtr, nrOptions);
  148. //  LstSetSelection(optionslstPtr,0); // current connection 
  149.   LstPopupList(optionslstPtr);
  150.   txt = LstGetSelectionText(optionslstPtr,
  151.                           LstGetSelection(optionslstPtr));
  152.   if (txt){
  153.     prevDrawWin = WinGetDrawWindow();
  154.      WinSetDrawWindow(g->DrawWin);
  155.     rect.topLeft.x = slct->x1+16;
  156.     rect.extent.x = 144-slct->x1 ;
  157.     rect.topLeft.y = slct->y1-LINEHEIGHT;
  158.     rect.extent.y = LINEHEIGHT ;
  159.     WinEraseRectangle(&rect,0);
  160.     WinDrawChars(txt, StrLen(txt), slct->x1+18, slct->y1-LINEHEIGHT);
  161.     WinSetDrawWindow(prevDrawWin);
  162.     scrollUpdate(g);
  163.      if(slct->name){
  164.         //value = getVar(slct->name);
  165.         tmp = slct->options;
  166.         while(tmp != NULL)
  167.         {
  168.             if (StrCompare(txt,tmp->txt)==0)
  169.                 setVar(slct->name,tmp->value,g);
  170.             tmp=tmp->next;
  171.         }
  172.     }
  173.   }
  174.   MemHandleUnlock (optionsHandle);
  175.   MemHandleFree (optionsHandle);
  176.   return(true);   
  177. }
  178.  
  179. void deactivateInputFld(GlobalsType *g){
  180.   FieldPtr      fldP;
  181.   FormPtr       frm;
  182.   Char             *txt;
  183.   InputPtr        tmp;
  184.       
  185.     if(g->InputFldActive) // if there is an active input field, dactivate it 
  186.     {                
  187.         frm = FrmGetActiveForm ();
  188.           fldP = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm,fldInput));
  189.           ErrNonFatalDisplayIf (!fldP, "missing field");
  190.           txt = FldGetTextPtr (fldP);
  191.         tmp = g->InputFldActive;
  192.         setVar(tmp->name,txt,g);
  193.         g->InputFldActive=NULL;
  194.         FrmHideObject(FrmGetActiveForm(),FrmGetObjectIndex(frm,fldInput));
  195.         palmDrawChars(txt, StrLen(txt), tmp->x1, tmp->y1-(g->ScrollY)-LINEHEIGHT,g);
  196.     }                
  197.  
  198. }
  199.  
  200. void setHyperLinkUrl(Char *prefix, Char *url, GlobalsType *g)
  201. {
  202.     ErrFatalDisplayIf (!g->HyperLinks, "!gHyperLinks");
  203.     ErrFatalDisplayIf (!url, "No URL");
  204.     g->HyperLinks->url = Malloc(StrLen(url)+StrLen(prefix)+1);
  205.     ErrFatalDisplayIf (!g->HyperLinks->url, "Malloc Failed");
  206.     StrCopy(g->HyperLinks->url,prefix);
  207.     StrCopy(g->HyperLinks->url+StrLen(prefix),url);
  208. }
  209.  
  210. int addHyperLink(Int16 x1, Int16 y1, GlobalsType *g)
  211. {
  212.   HyperLinkPtr tmp;
  213.  
  214.     tmp = Malloc (sizeof(HyperLinkType));
  215.     ErrFatalDisplayIf (!tmp, "Malloc Failed");
  216.     tmp->x1=x1;
  217.     tmp->y1=y1;
  218.     tmp->next = g->HyperLinks;
  219.     tmp->url=NULL;
  220.     g->HyperLinks = tmp;
  221.             
  222. return(0);
  223. }
  224.  
  225. int addVar(Char *name, GlobalsType *g)
  226. {
  227.   VarPtr tmp;
  228.  
  229.     tmp = Malloc (sizeof(VarType));
  230.     ErrFatalDisplayIf (!tmp, "Malloc Failed");
  231.     tmp->value=NULL;
  232.     tmp->name = Malloc(StrLen(name)+1);
  233.     ErrFatalDisplayIf (!tmp->name, "Malloc Failed");
  234.     StrCopy(tmp->name,name);
  235.     tmp->next = g->Var;
  236.     g->Var = tmp;
  237.             
  238. return(0);
  239. }
  240.  
  241. Char *getVar(Char *name, GlobalsType *g)
  242. {
  243.   VarPtr tmp;
  244.   
  245.       tmp= g->Var;
  246.     while(tmp != NULL)
  247.     {
  248.         
  249.         if (StrCompare(name,tmp->name)==0)
  250.         {
  251.             if(tmp->value)
  252.                 return(tmp->value);
  253.             else
  254.                 return("");
  255.         }
  256.         tmp = tmp->next;
  257.     }
  258.     return("");
  259. }
  260.  
  261. void setHyperLinkEnd(Int16 x2, Int16 y2, GlobalsType *g)
  262. {
  263.  if(!g->HyperLinks)
  264.      return;
  265.  g->HyperLinks->x2 = x2;
  266.  g->HyperLinks->y2 = y2; 
  267. }
  268.  
  269. char *escaped(Char *str)
  270. {
  271.  // TODO : escaped string
  272.  return(str);
  273. }
  274.  
  275. char *unescaped(Char *str)
  276. {
  277.  // TODO : unescaped string
  278.  return(str);
  279. }
  280.  
  281. unsigned char *expandVar(unsigned char *instr, GlobalsType *g)
  282. {
  283. int i,start,exttype,newlen,len;
  284. unsigned char *name,*value,*str,*newstr,c;
  285.  
  286.   len = StrLen(instr);
  287.   str = Malloc(len+1);       
  288.   ErrFatalDisplayIf (!newstr, "Malloc expandVar");
  289.   StrCopy(str,instr);
  290.   i = 0;
  291.   while(i<len)
  292.   {
  293.     c = str[i];
  294.       if ((c==EXT_T_0) || (c==EXT_T_1) || (c==EXT_T_2)) 
  295.     {
  296.       exttype= c;
  297.       start = i+1;
  298.     }
  299.     if (c==END)
  300.     {
  301.        name=&(str[start]);
  302.        str[i]=0;
  303.        value = getVar(name,g);
  304.        if(exttype==EXT_T_0)
  305.          value = escaped(value);
  306.        if(exttype==EXT_T_1)
  307.          value = unescaped(value);      
  308.        newlen = len - (StrLen(name)+2) + StrLen(value) + 1;
  309.        newstr = Malloc(newlen);       
  310.        ErrFatalDisplayIf (!newstr, "Malloc expandVar");
  311.        StrNCopy(newstr,str,start-1);
  312.        StrNCopy(newstr+start-1,value,StrLen(value));
  313.        StrNCopy(newstr+start-1+StrLen(value),&(str[i+1]),len-i);
  314.        newstr[newlen-1]=0;    
  315.        Free(str);
  316.        str = newstr;
  317.          len = StrLen(str);
  318.        i=0;
  319.     }else{
  320.        i++;
  321.     }
  322.   }
  323.   return(str);
  324. }
  325.  
  326. void followLink(unsigned char *str, GlobalsType *g)
  327. {
  328.   CardPtr      tmpCrd;
  329.   Char *urlStr;
  330.  
  331.   urlStr = expandVar(str,g);
  332.   if (urlStr[0]=='#'){
  333.     g->state = BS_NEW_CARD;
  334.     tmpCrd = g->wmldck.card;
  335.     while(tmpCrd){
  336.         if(StrCompare(tmpCrd->card_id, &urlStr[1])==0){
  337.             g->CardOffset = tmpCrd->offset;
  338.             Free(urlStr);
  339.             return;
  340.         }
  341.         tmpCrd = tmpCrd->next;
  342.     }
  343.       DisplayError("Card Not Found!");
  344.     Free(urlStr);
  345.     return;
  346.   }else{
  347.     if(g->Url)
  348.         Free(g->Url);
  349.     g->Url=Malloc(MAX_URL_LEN+1);
  350.     ErrFatalDisplayIf (!g->Url, "Malloc gUrl");
  351.     wapCreateUrlStr(urlStr,g->Url,g);
  352.     historyPush(g->Url,g);
  353.     Free(urlStr);
  354.     browserReloadEvt(g);
  355.     return;
  356.   }  
  357. }
  358.  
  359.  
  360. Boolean checkHyperLink(Int16 x, Int16 y, GlobalsType *g)
  361. {
  362.   HyperLinkPtr tmp;
  363.   
  364.       tmp= g->HyperLinks;
  365.     while(tmp != NULL)
  366.     {
  367.         if ((y>tmp->y1)&&(y<tmp->y2)&&
  368.                 (x>tmp->x1)&&(x<tmp->x2))
  369.         {
  370.             deactivateInputFld(g);
  371.             followLink(tmp->url,g);
  372.             return(true);            
  373.         }
  374.         tmp = tmp->next;
  375.     }
  376.     return(false);
  377. }
  378.  
  379. Boolean checkInput(Int16 x, Int16 y, GlobalsType *g)
  380. {
  381.   InputPtr tmp;
  382.   ControlPtr ctl;
  383.   RectangleType rect;
  384.       
  385.       tmp= g->Input;
  386.     while(tmp != NULL)
  387.     {
  388.         if ((y>tmp->y1)&&(y<tmp->y2)&&
  389.                 (x>tmp->x1)&&(x<tmp->x2))
  390.         {
  391.             if (g->InputFldActive == tmp)
  392.                 return(true);
  393.             if (g->InputFldActive)
  394.                 deactivateInputFld(g);                
  395.              rect.topLeft.x = tmp->x1;
  396.             rect.extent.x = 56 ;
  397.             rect.topLeft.y = tmp->y1-(g->ScrollY);
  398.             rect.extent.y = 14 ;
  399.               ctl = GetObjectPtr (fldInput);
  400.             FldSetBounds((FieldPtr)ctl,&rect);
  401.             g->InputFldActive=tmp;
  402.             SetFieldFromStr(getVar(tmp->name,g) , fldInput);
  403.               FrmShowObject(FrmGetActiveForm(),FrmGetObjectIndex(FrmGetActiveForm(),fldInput));
  404.             return(true);            
  405.         }
  406.         tmp = tmp->next;
  407.     }
  408.     return(false);
  409. }
  410.  
  411. int disposeHyperLinks(GlobalsType *g)
  412. {
  413.   HyperLinkPtr tmp;
  414.  
  415.     while(g->HyperLinks != NULL){
  416.         tmp = g->HyperLinks;
  417.         g->HyperLinks = g->HyperLinks->next;
  418.         if(tmp->url)
  419.             Free(tmp->url);
  420.         Free(tmp);
  421.     }        
  422.       return(0);
  423. }
  424.  
  425. int disposeVar(GlobalsType *g)
  426. {
  427.   VarPtr tmp;
  428.  
  429.     while(g->Var != NULL){
  430.         tmp = g->Var;
  431.         g->Var = g->Var->next;
  432.         if(tmp->name)
  433.             Free(tmp->name);
  434.         if(tmp->value)
  435.             Free(tmp->value);
  436.         Free(tmp);
  437.     }        
  438.       return(0);
  439. }
  440.  
  441. int disposeOptions(OptionPtr options, GlobalsType *g)
  442. {
  443.   OptionPtr tmp;
  444.  
  445.     while(options != NULL){
  446.         tmp = options;
  447.         options = options->next;
  448.         if(tmp->value)
  449.             Free(tmp->value);
  450.         if(tmp->txt)
  451.             Free(tmp->txt);
  452.         Free(tmp);
  453.     }        
  454.       return(0);
  455. }
  456.  
  457. int disposeSelect(GlobalsType *g)
  458. {
  459.   SelectPtr tmp;
  460.  
  461.     while(g->Select != NULL){
  462.         tmp = g->Select;
  463.         g->Select = g->Select->next;
  464.         if(tmp->name)
  465.             Free(tmp->name);
  466.         disposeOptions(tmp->options,g);
  467.         Free(tmp);
  468.     }        
  469.       return(0);
  470. }
  471.  
  472.  
  473. Boolean checkSelect(Int16 x, Int16 y, GlobalsType *g)
  474. {
  475.   SelectPtr tmp;
  476.   ControlPtr ctl;
  477.       
  478.       tmp= g->Select;
  479.     while(tmp != NULL)
  480.     {
  481.         if ((y>tmp->y1)&&(y<tmp->y2)&&
  482.                 (x>tmp->x1)&&(x<tmp->x2))
  483.         {
  484.             deactivateInputFld(g);
  485.               ctl = GetObjectPtr (listOption);
  486.             LstSetPosition((ListPtr)ctl,tmp->x1,tmp->y1-g->ScrollY);
  487.             return(selectInitList(tmp,g));
  488.         }
  489.         tmp = tmp->next;
  490.     }
  491.     return(false);
  492. }
  493.  
  494.  
  495. int disposeInput(GlobalsType *g)
  496. {
  497.   InputPtr tmp;
  498.  
  499.     while(g->Input != NULL){
  500.         tmp = g->Input;
  501.         g->Input = g->Input->next;
  502.         if(tmp->name)
  503.             Free(tmp->name);
  504.         Free(tmp);
  505.     }        
  506.       return(0);
  507. }
  508.  
  509. void palmprintln(GlobalsType *g)
  510. {
  511.     g->y+=LINEHEIGHT;
  512.     g->x=0;
  513. }
  514.  
  515. static void scrollUpdate( GlobalsType *g)
  516. {
  517.     WinHandle   tmpDrawWin;
  518.     RectangleType rect={{0, 0}, {153, 132}};
  519.  
  520.     rect.topLeft.y = g->ScrollY;
  521.     tmpDrawWin = WinGetDrawWindow();
  522.     WinCopyRectangle(g->DrawWin,tmpDrawWin,&rect,0,LINEHEIGHT,winPaint);
  523.     SclSetScrollBar(GetObjectPtr(scrollBarBrowser),(g->ScrollY/10),0,(g->DrawHeight/10)-13,13);
  524.  
  525. }
  526.  
  527. static void scrollUp(GlobalsType *g)
  528. {
  529.  
  530.     g->ScrollY-=120;
  531.     if (g->ScrollY < 0)
  532.         g->ScrollY = 0;
  533.  
  534.     scrollUpdate(g);
  535. }
  536.  
  537. static void scrollDown(GlobalsType *g)
  538. {
  539.  
  540.     g->ScrollY+=120;
  541.     if (g->ScrollY > (g->DrawHeight-132))
  542.         g->ScrollY = (g->DrawHeight-132);
  543.  
  544.     scrollUpdate(g);
  545. }
  546.  
  547. static Int16 WrapPos(char *str, Int16 width)
  548. {
  549.     Int16 i,wp;
  550.     char c;
  551.         
  552.     i=0;
  553.     wp=-1;
  554.     while ( (c=str[i++]) != 0) {
  555.         if (i == width ) {
  556.             return(wp);
  557.         }
  558.         if (c==' ') {
  559.             wp=i;
  560.         }
  561.     }
  562.     return(wp);
  563.  
  564. }
  565.  
  566. void palmResizeWindow(Int16 space, GlobalsType *g)
  567. {
  568.     WinHandle       tmpDrawWin;
  569.     RectangleType     rect={{0, 0}, {153, 0}};
  570.     Err             error;
  571.     WinHandle        prevDrawWin;
  572.  
  573.     prevDrawWin = WinGetDrawWindow();
  574.     if ( (g->y) > (g->DrawHeight-space)) { // resize offscreen window
  575.         rect.extent.y = g->DrawHeight;
  576.         g->DrawHeight+=50;
  577.         tmpDrawWin = WinCreateOffscreenWindow(153,g->DrawHeight,screenFormat,&error);
  578.         // copy window contents 
  579.         WinSetDrawWindow(tmpDrawWin);
  580.         WinEraseWindow();
  581.         WinSetDrawWindow(prevDrawWin);
  582.         WinCopyRectangle(g->DrawWin,tmpDrawWin,&rect,0,0,winPaint);
  583.         WinDeleteWindow(g->DrawWin,false);
  584.         g->DrawWin = tmpDrawWin;
  585.         SclSetScrollBar(GetObjectPtr(scrollBarBrowser),0,0,(g->DrawHeight/10)-13,13);
  586.     }
  587. }
  588.  
  589. void palmDrawImage(WSPPDU *wsppdu, GlobalsType *g)
  590. {
  591.  Int16            xpos,ypos;
  592.  UInt16         width, height;
  593.  UInt16         rowBytes,wbmpRowBytes;
  594.  BitmapType     *bmp= NULL;
  595.  unsigned char  *tmpPtr= NULL;
  596.  WinHandle       prevDrawWin;
  597.  
  598.     width = wsppdu->data[2];
  599.     height = wsppdu->data[3];
  600.     rowBytes =  (((width+15) >> 4) << 1); // palm bmp even word boundary !!
  601.     wbmpRowBytes = ((width+7) >> 3) ; // wbmp is byte boundary
  602.     bmp = MemPtrNew (sizeof(BitmapType)+(rowBytes*height));    
  603.     ErrFatalDisplayIf (!bmp, "Malloc Failed");
  604.     MemSet(bmp,sizeof(BitmapType)+(rowBytes*height),0);
  605.     bmp->width = width;
  606.     bmp->height = height;
  607.     bmp->rowBytes = rowBytes;
  608.     bmp->pixelSize = 1;
  609.     bmp->version = 1;
  610.     tmpPtr = (unsigned char *) (bmp + 1);
  611.     for (ypos=0;ypos<height;ypos++){
  612.       for (xpos=0;xpos<wbmpRowBytes;xpos++){
  613.         *(tmpPtr+xpos+(ypos*rowBytes))=(wsppdu->data[4+xpos+(ypos*wbmpRowBytes)]) ^ 0xFF ; // wbmp is inversed 
  614.         }
  615.     }
  616.     prevDrawWin = WinGetDrawWindow();
  617.     palmResizeWindow(height,g); // resize window buffer if needed 
  618.     WinSetDrawWindow(g->DrawWin);
  619.     WinDrawBitmap(bmp,(160-width)/2,g->y);
  620.     WinSetDrawWindow(prevDrawWin);
  621.     updateScreen(g);
  622.     g->y+=height;
  623.     if (bmp) {
  624.         Free(bmp);
  625.     }
  626. }
  627.  
  628. static void    drawTrigger(Int16 x, Int16 y)
  629. // Draw the trigger symbol. I was surprised there is no special character in 
  630. // the symbol charset for this, so I had to 'draw it by hand'
  631. {
  632. Int16 i;
  633.     
  634.     for(i=7; i>0; i-=2){  
  635.         WinDrawLine(x,y,x+i,y);
  636.         x++; y++;
  637.     }
  638. }
  639.  
  640. void palmHyperLink(Boolean ison, Char *prefix, Char *url, GlobalsType *g)
  641. {
  642.   if (ison)
  643.   {
  644.     WinSetUnderlineMode(grayUnderline); // one of noUnderline, grayUnderline, solidUnderline.
  645.     addHyperLink(g->x, g->y+g->ScrollY+LINEHEIGHT,g); // add hyperlink entry, set start x,y
  646.       if(url) // if url given, set url
  647.         setHyperLinkUrl(prefix, url,g); 
  648.   }
  649.   else
  650.   {
  651.     WinSetUnderlineMode(noUnderline);
  652.     setHyperLinkEnd(g->x, g->y+g->ScrollY+24,g); 
  653.     if(url) // if url given, set url
  654.         setHyperLinkUrl(prefix, url,g);
  655.   }
  656. }
  657.  
  658. void palmWmlInputType(Boolean pwdType, GlobalsType *g)
  659. {
  660.     if(g->Input)
  661.         g->Input->passwordType= pwdType;
  662. }        
  663.  
  664. void palmWmlInputValue(Char *value, GlobalsType *g)
  665. {
  666.     if(g->Input){
  667.         setVar(g->Input->name,value,g);
  668.         palmDrawChars(value, StrLen(value), g->Input->x1, g->Input->y1-LINEHEIGHT,g);
  669.     }
  670. }        
  671.  
  672. void palmWmlInput(Char *fieldName, GlobalsType *g)
  673. {
  674.  WinHandle       prevDrawWin;
  675.  RectangleType     rect;
  676.  InputPtr tmp;
  677.  
  678.     if ( g->x> 100)
  679.         palmprintln(g);    
  680.     tmp = Malloc (sizeof(InputType));
  681.     ErrFatalDisplayIf (!tmp, "Malloc Failed");
  682.     tmp->name = Malloc(StrLen(fieldName)+1);
  683.     ErrFatalDisplayIf (!tmp->name, "Malloc Failed");
  684.     StrCopy(tmp->name,fieldName);
  685.     addVar(fieldName,g);
  686.     tmp->x1=g->x+3;
  687.     tmp->y1=(g->y)+(g->ScrollY)+LINEHEIGHT;
  688.      rect.topLeft.x = g->x+3;
  689.     rect.extent.x = 56 ;
  690.     tmp->x2= tmp->x1 + rect.extent.x;
  691.     rect.topLeft.y = g->y+g->ScrollY;
  692.     rect.extent.y = LINEHEIGHT-1 ;
  693.     tmp->y2= tmp->y1 + LINEHEIGHT-1 ;
  694.     tmp->next = g->Input;
  695.     g->Input = tmp;
  696.  
  697.     prevDrawWin = WinGetDrawWindow();
  698.     WinSetDrawWindow(g->DrawWin);
  699.     WinDrawGrayRectangleFrame(simpleFrame,&rect); // simpleFrame/rectangleFrame
  700.     WinSetDrawWindow(prevDrawWin);
  701.     updateScreen(g);
  702.     palmprintln(g);    
  703.     
  704. }
  705.  
  706. void palmWmlSelectOptionTxt(Char *txt, GlobalsType *g)
  707. {
  708.  OptionPtr tmp;
  709.  
  710.     tmp = g->Select->options;
  711.     if(tmp != NULL){
  712.         while(tmp->next != NULL){
  713.             tmp = tmp->next;
  714.         }
  715.         tmp->txt = Malloc(StrLen(txt)+1);
  716.         ErrFatalDisplayIf (!tmp->txt, "Malloc Failed");
  717.         StrCopy(tmp->txt,txt);
  718.     }
  719.         
  720. }
  721.  
  722. void palmWmlSelect(Char *name, GlobalsType *g)
  723. {
  724.  SelectPtr         tmp;
  725.  
  726.     if ( g->x> 100)
  727.         palmprintln(g);    
  728.     tmp = Malloc (sizeof(SelectType));
  729.     ErrFatalDisplayIf (!tmp, "Malloc Failed");
  730.     tmp->name = Malloc(StrLen(name)+1);
  731.     ErrFatalDisplayIf (!tmp->name, "Malloc Failed");
  732.     StrCopy(tmp->name,name);
  733.     addVar(name,g);
  734.     tmp->x1=g->x;
  735.     tmp->y1=g->y+g->ScrollY+LINEHEIGHT;
  736.     tmp->x2= tmp->x1 + 10;
  737.     tmp->y2= tmp->y1 + LINEHEIGHT-1;
  738.     tmp->next = g->Select;
  739.     tmp->options = NULL;
  740.     g->Select = tmp;
  741.  
  742. }
  743.  
  744. void palmWmlSelectValue(Char *ivalue, GlobalsType *g)
  745. {
  746.     if(g->Select){
  747.         setVar(g->Select->name,ivalue,g);
  748.     }
  749. }
  750.  
  751. void palmWmlSelectOption(Char *value, GlobalsType *g)
  752. {
  753.  OptionPtr tmp,nw;
  754.  
  755.     if(g->Select){
  756.         nw = Malloc (sizeof(OptionType));
  757.         ErrFatalDisplayIf (!nw, "Malloc Failed");
  758.         nw->value = Malloc(StrLen(value)+1);
  759.         ErrFatalDisplayIf (!nw->value, "Malloc Failed");
  760.         StrCopy(nw->value,value);
  761.         nw->txt = NULL;
  762.         nw->next = NULL;
  763.         tmp = g->Select->options;
  764.         if(tmp == NULL){
  765.             g->Select->options = nw;
  766.         }else{
  767.             while(tmp->next != NULL){
  768.                 tmp = tmp->next;
  769.             }
  770.             tmp->next = nw;
  771.         }
  772.     }
  773. }
  774.  
  775. void selectDrawText(SelectPtr slct, GlobalsType *g)
  776. {
  777.  Char    *txt,*value;
  778.  OptionPtr tmp;
  779.  
  780.  if(slct){
  781.      if(slct->name){
  782.         value = getVar(slct->name,g);
  783.         tmp = slct->options;
  784.         txt=NULL;
  785.         while(tmp != NULL)
  786.         {
  787.             if (StrCompare(value,tmp->value)==0)
  788.                 txt=tmp->txt;
  789.             tmp=tmp->next;
  790.         }
  791.         if (txt)
  792.             WinDrawChars(txt, StrLen(txt), slct->x1+18, slct->y1+g->ScrollY-LINEHEIGHT);
  793.     }        
  794.  }
  795. }
  796.  
  797.  
  798. void palmWmlSelectEnd(GlobalsType *g)
  799. {
  800.  WinHandle  prevDrawWin;
  801.  
  802.  prevDrawWin = WinGetDrawWindow();
  803.  WinSetDrawWindow(g->DrawWin);
  804.  drawTrigger(g->x+3,g->y+g->ScrollY+4);
  805.  selectDrawText(g->Select,g);
  806.  palmprintln(g);    
  807.  WinSetDrawWindow(prevDrawWin);
  808.  updateScreen(g);
  809. }
  810.  
  811. void palmUnderline(Boolean ison)
  812. {
  813. if (ison)
  814.     WinSetUnderlineMode(solidUnderline); // one of noUnderline, grayUnderline, solidUnderline.
  815. else
  816.     WinSetUnderlineMode(noUnderline);
  817. }
  818.  
  819. void palmBold(Boolean ison)
  820. {
  821. if (ison)
  822.     FntSetFont(boldFont);
  823. else
  824.     FntSetFont(stdFont);
  825. }
  826.  
  827. void palmDrawChars(char *str, Int16 textLen, Int16 x, Int16 y, GlobalsType *g)
  828. {
  829.     WinHandle    prevDrawWin;
  830.  
  831.     prevDrawWin = WinGetDrawWindow();
  832.     palmResizeWindow(LINEHEIGHT,g); // resize window buffer if needed
  833.     WinSetDrawWindow(g->DrawWin);
  834.     WinDrawChars(str,textLen,x,y);
  835.     WinSetDrawWindow(prevDrawWin);
  836.     updateScreen(g);
  837. }
  838.  
  839. void palmprintf(char *str, GlobalsType *g)
  840. {
  841.     Int16         textLen, width, wp;
  842.     Boolean     fits;
  843.  
  844.     width = 152-g->x;
  845.     textLen = StrLen(str);
  846.     FntCharsInWidth(str, &width, &textLen, &fits);
  847.     while (!fits) {
  848.         // check if there is a space-char so we we can wrap
  849.         wp= WrapPos(str,textLen);
  850.         if (wp == -1 ) {  // no space-character in string, try if newline would help
  851.             width = 152;
  852.             textLen = StrLen(str);
  853.             FntCharsInWidth(str, &width, &textLen, &fits);
  854.             if (!fits) { // the string still does not fit after a newline, check again for space-char
  855.                 wp= WrapPos(str,textLen);
  856.                 if (wp == -1) { // we'll need to cut ...
  857.                     width = 152-g->x;
  858.                     FntCharsInWidth(str, &width, &textLen, &fits);
  859.                     palmDrawChars(str,textLen,g->x,g->y,g);
  860.                     g->x+=FntCharsWidth(str,textLen);
  861.                     str=str+textLen;                        
  862.                 } else { // there is a space-char at position 'wp'
  863.                     palmprintln(g);
  864.                     palmDrawChars(str,wp,g->x,g->y,g);
  865.                     g->x+=FntCharsWidth(str,wp);
  866.                     str=str+wp;
  867.                 }
  868.             } else { // the complete string fits after a newline. 
  869.                 palmprintln(g);
  870.                 palmDrawChars(str,textLen,g->x,g->y,g);
  871.                 g->x+=FntCharsWidth(str,textLen);
  872.                 if (g->y<160) { // visible part, so update real screen
  873.                     updateScreen(g);
  874.                 }
  875.                 return;
  876.             }
  877.         } else { // there is a space-char at position 'wp'
  878.             palmDrawChars(str,wp,g->x,g->y,g);
  879.             g->x+=FntCharsWidth(str,wp);
  880.             str=str+wp;
  881.         }
  882.         width = 152-g->x;
  883.         textLen = StrLen(str);
  884.         FntCharsInWidth(str, &width, &textLen, &fits);                
  885.     }
  886.     palmDrawChars(str,textLen,g->x,g->y,g);
  887.     g->x+=FntCharsWidth(str,textLen);
  888.     if (g->y<160) { // visible part, so update real screen
  889.         updateScreen(g);
  890.     }
  891. }
  892.  
  893. void palmsrcprintf(char *str, GlobalsType *g)
  894. {
  895.     Char * srcPtr;
  896.     UInt32   sz;
  897.  
  898.     sz = MemHandleSize(g->srcHandle);
  899.     srcPtr = MemHandleLock(g->srcHandle);
  900.     if ( sz <= (StrLen(srcPtr)+StrLen(str))) { // We need to resize
  901.         MemHandleUnlock(g->srcHandle);
  902.         if (MemHandleResize(g->srcHandle,sz+250) == 0) {
  903.             sz+=250;
  904.             srcPtr = MemHandleLock(g->srcHandle);
  905.         } else {
  906.             DisplayError("Resize Failed");
  907.             return; 
  908.         }
  909.     }
  910.     StrCat(srcPtr,str);
  911.     MemHandleUnlock(g->srcHandle);
  912.  
  913. }
  914.  
  915. Err OpenNetwork(GlobalsType *g)
  916. {
  917.     Err             error;
  918. //    UInt16          InterfaceError;
  919.  
  920.     if (g->NetLibOpen==true)
  921.         return(0);
  922.     if (SysLibFind ("Net.lib", &AppNetRefnum) == 0) {
  923.         error = NetLibOpen (AppNetRefnum, &errno);
  924.         if (errno != 0) {
  925.             MyErrorFunc("NetLibOpen",WspHostErrStr());
  926.             NetLibClose (AppNetRefnum, true);
  927.         } else if (error == 0 || error == netErrAlreadyOpen) {
  928.             g->NetLibOpen= true;
  929.             return(0);
  930.         }
  931.         return(error);
  932.     } else {
  933.         DisplayError ("PANIC: NO NETLIB FOUND!");   
  934.         return(-1);
  935.     }
  936. }
  937.  
  938.  
  939. void showProgress(GlobalsType *g)
  940. {
  941.     BitmapPtr resP=0;
  942.  
  943.     resP=MemHandleLock(g->resBmpPrgrs[g->progress]);
  944.     WinDrawBitmap (resP, 44, 147);
  945.     MemPtrUnlock(resP);
  946.     g->progress= ((g->progress)+1)%4;
  947. }
  948.  
  949. Boolean runBrowserState(GlobalsType *g)
  950. {
  951.     static UInt32            maxTimer;
  952.     static Int16            len;
  953.     WinHandle               prevDrawWin;
  954.     static RectangleType     r = {{0, 10}, {153, 135}};
  955.  
  956.     if (g->state==BS_IDLE) {
  957.         return(true);
  958.     }
  959.     // Update progres indicator
  960.     showProgress(g);
  961.     switch (g->state) {
  962. // 
  963.     case BS_GET_URL:
  964.         FrmSetTitle(FrmGetActiveForm(),"Requesting URL");
  965.         g->sock = wapGetUrl (&(g->conn),g->Url,true,g);
  966.         g->state = BS_GET_REPLY;
  967.         FrmSetTitle(FrmGetActiveForm(),"Waiting for reply");
  968.         maxTimer = TimGetTicks() + (REPLY_TIMEOUT * SysTicksPerSecond());
  969.         break;
  970.     case BS_GET_REPLY:
  971.         len = WspGetReply(g->sock,g->inBuf,DEF_RECEIVE_BUF,maxTimer,g);
  972.         break;
  973.     case BS_WSP_DECODE:
  974.         FrmSetTitle(FrmGetActiveForm(),"Decoding data");
  975.         if (WspDecode(g->inBuf,len, &(g->wsppdu) ) == 0) {
  976.             g->state = BS_WBXML_PARSE;
  977.         } else {
  978.             g->state = BS_IDLE;
  979.         }
  980.         break;
  981.     case BS_WBXML_PARSE:        
  982.         g->wmldck.card=NULL;
  983.         FrmSetTitle(FrmGetActiveForm(),"Parsing data");
  984.         wbxml_parse(&(g->wsppdu), ACTION_PARSE, &(g->wmldck), 0,g);
  985.         if(g->wmldck.card)  // if there is a first card defined, show it
  986.             g->CardOffset = g->wmldck.card->offset;
  987.         else
  988.             g->CardOffset = 0;
  989.         g->state= BS_RENDER;
  990.         break;
  991.     case BS_NEW_CARD:
  992.         g->x=0;g->y=0;
  993.         g->ScrollY=0;
  994.         disposeHyperLinks(g);
  995.         disposeVar(g);
  996.         disposeInput(g);
  997.         disposeSelect(g);
  998.         prevDrawWin = WinGetDrawWindow();
  999.         WinSetDrawWindow(g->DrawWin);
  1000.             WinEraseWindow();
  1001.         WinSetDrawWindow(prevDrawWin);
  1002.         WinEraseRectangle(&r,0);
  1003.         scrollUpdate(g);
  1004.         //OpenNetwork();
  1005.         g->state= BS_RENDER;
  1006.         break;
  1007.     case BS_RENDER:
  1008.         FrmSetTitle(FrmGetActiveForm(),"Rendering data");
  1009.         g->wmldck.ontimerUrl=NULL;
  1010.         g->wmldck.timerVal=-1;
  1011.         wbxml_parse(&(g->wsppdu), ACTION_RENDER, &(g->wmldck), g->CardOffset,g);
  1012.         updateScreen(g);
  1013.         if(g->wmldck.timerVal != -1){
  1014.             g->state = BS_ONTIMER;
  1015.             maxTimer = TimGetTicks() + ( g->wmldck.timerVal * SysTicksPerSecond() );
  1016.         }else{
  1017.             g->state = BS_IDLE;
  1018.         }
  1019.         g->progress= 0;
  1020.         showProgress(g);
  1021.         break;    
  1022.     case BS_ONTIMER:
  1023.         if (maxTimer < TimGetTicks())
  1024.             followLink(g->wmldck.ontimerUrl,g); 
  1025.         break;
  1026.         
  1027.     default:
  1028.     }
  1029.     return true;
  1030. }
  1031.  
  1032. static void frmOpenEvent_OH(GlobalsType *g)
  1033. {
  1034.     Err             error;
  1035.     WinHandle       prevDrawWin;
  1036.  
  1037.     g->resBmpPrgrs[0]=DmGetResource(bitmapRsc, bmpProgress1);
  1038.     g->resBmpPrgrs[1]=DmGetResource(bitmapRsc, bmpProgress2);
  1039.     g->resBmpPrgrs[2]=DmGetResource(bitmapRsc, bmpProgress3);
  1040.     g->resBmpPrgrs[3]=DmGetResource(bitmapRsc, bmpProgress4);
  1041.     g->progress=0;
  1042.     g->srcHandle=0;
  1043.     g->sock = -1;
  1044.     g->inBuf = NULL;
  1045.     g->HyperLinks = NULL;
  1046.     g->Var = NULL;
  1047.     g->Input = NULL;
  1048.     g->Select = NULL;
  1049.     g->Url = NULL;
  1050.     g->InputFldActive=NULL;
  1051.     dbUrlReadCurrentUrl(g);
  1052.     FrmDrawForm(FrmGetActiveForm());
  1053.     prevDrawWin = WinGetDrawWindow();
  1054.     g->DrawWin = WinCreateOffscreenWindow(153,150,screenFormat,&error);
  1055.     g->DrawHeight=132;
  1056.     g->ScrollY=0;
  1057.     WinSetDrawWindow(g->DrawWin);
  1058.     WinEraseWindow();
  1059.     WinSetDrawWindow(prevDrawWin);
  1060.     SclSetScrollBar(GetObjectPtr(scrollBarBrowser),0,0,0,13);
  1061.     g->x=0;g->y=0;
  1062.     g->state = BS_IDLE;
  1063.     g->wsppdu.data= NULL;
  1064.  
  1065.     g->inBuf=Malloc(DEF_RECEIVE_BUF+1);   
  1066.     ErrFatalDisplayIf (!g->inBuf, "Malloc");
  1067.     
  1068.     dbConnGetConnection(g->DbUrlCurrentURL.connection,&(g->conn),g);
  1069.     g->Url=Malloc(StrLen(g->DbUrlCurrentURL.urlstr)+1);
  1070.     ErrFatalDisplayIf (!g->Url, "Malloc gUrl");
  1071.     StrCopy(g->Url,g->DbUrlCurrentURL.urlstr);  
  1072.     historyPush(g->Url,g);
  1073.     if(StrNCaselessCompare(g->Url,"MTCH:",5)==0)
  1074.     {
  1075.         g->state = BS_GET_OFFLINE;
  1076.     }else
  1077.     {
  1078.         error = OpenNetwork(g);
  1079.         if (error == 0) {
  1080.             g->state = BS_GET_URL;
  1081.         }
  1082.     } 
  1083. }
  1084.  
  1085.  
  1086. Boolean browserReloadEvt(GlobalsType *g)
  1087. {
  1088.     Err             error;
  1089.     WinHandle       prevDrawWin;
  1090.     RectangleType r = {{0, 10}, {153, 135}};
  1091.  
  1092.     g->x=0;g->y=0;
  1093.     g->ScrollY=0;
  1094.  
  1095.     g->InputFldActive=NULL;
  1096.     WspFreePdu(&(g->wsppdu));
  1097.     disposeHyperLinks(g);
  1098.     disposeVar(g);
  1099.     disposeInput(g);
  1100.     disposeSelect(g);
  1101.     wbxml_free_wmldck(&(g->wmldck));
  1102. // 
  1103.         error = OpenNetwork(g);
  1104.         if (error == 0) {
  1105.             g->state = BS_GET_URL;
  1106.         }
  1107. // 
  1108.     prevDrawWin = WinGetDrawWindow();
  1109.     WinSetDrawWindow(g->DrawWin);
  1110.     WinEraseWindow();
  1111.     WinSetDrawWindow(prevDrawWin);
  1112.     WinEraseRectangle(&r,0);
  1113.     scrollUpdate(g);
  1114.     return(true);   
  1115. }
  1116.  
  1117. Boolean browserSrcEvt(GlobalsType *g)
  1118. {
  1119.     WMLDeck         wmldck;
  1120.  
  1121.     if (g->wsppdu.data==NULL) {
  1122.         MyErrorFunc ("No page loaded", "View Source");
  1123.         return(true);
  1124.     }
  1125.     g->srcHandle = MemHandleNew(20);
  1126.     if (g->srcHandle<=0) {
  1127.         MyErrorFunc ("MemHandleNew Failed", "ButtonSrc_OH");
  1128.         return(true);
  1129.     }
  1130.     MemSet(MemHandleLock(g->srcHandle),20,0);
  1131.     MemHandleUnlock(g->srcHandle);
  1132.     wmldck.card=NULL;
  1133.     wbxml_parse(&(g->wsppdu), ACTION_SRC, &wmldck,0,g );
  1134.     wbxml_free_wmldck(&wmldck);
  1135.     ScrollFrm("WML Source",g->srcHandle);
  1136.     MemHandleFree(g->srcHandle);
  1137.     g->srcHandle=0;
  1138.     return(true);   
  1139. }
  1140.  
  1141. static void frmCloseEvent_OH(GlobalsType *g)
  1142. {
  1143.  
  1144.     // close socket if needed              
  1145.     if (g->sock >= 0)
  1146.         close (g->sock);
  1147.     if(g->NetLibOpen==true)
  1148.         NetLibClose (AppNetRefnum, false);
  1149.        g->NetLibOpen=false;
  1150.     if (g->inBuf != NULL) {
  1151.         Free(g->inBuf);
  1152.         g->inBuf = NULL;
  1153.     }
  1154.     if (g->Url != NULL) {
  1155.         Free(g->Url);
  1156.         g->Url = NULL;
  1157.     }
  1158.     WinDeleteWindow(g->DrawWin,false);
  1159.     g->DrawWin = NULL;
  1160.     WspFreePdu(&(g->wsppdu));
  1161.     disposeHyperLinks(g);
  1162.     disposeVar(g);
  1163.     disposeInput(g);
  1164.     disposeSelect(g);
  1165.     wbxml_free_wmldck(&(g->wmldck));
  1166.     DmReleaseResource(g->resBmpPrgrs[0]);
  1167.     DmReleaseResource(g->resBmpPrgrs[1]);
  1168.     DmReleaseResource(g->resBmpPrgrs[2]);
  1169.     DmReleaseResource(g->resBmpPrgrs[3]);
  1170. }
  1171.  
  1172.  
  1173. /**----------------------------------**/
  1174. /** Form Event Handler for FormBrowser**/
  1175. /**----------------------------------**/
  1176.  
  1177. /****************************************************/
  1178. /* 
  1179.    Function: Boolean FormBrowser_EH(EventPtr event);
  1180.    Description: Main Form Event Handler for FormBrowser
  1181.  */
  1182. /****************************************************/
  1183.  
  1184.  
  1185. /* Form Event Handler */
  1186. Boolean ehFormBrowser(EventPtr event)
  1187. {
  1188.     Boolean handled = false;
  1189.       GlobalsType *g;
  1190.  
  1191.  
  1192. #ifdef __GNUC__
  1193.     CALLBACK_PROLOGUE
  1194. #endif
  1195.     FtrGet(wuAppType, ftrGlobals, (UInt32 *)&g);
  1196.     switch (event->eType) {
  1197.     
  1198.     case ctlSelectEvent:
  1199.         if (event->data.ctlSelect.controlID == buttonBack) {
  1200.             deactivateInputFld(g);
  1201.             handled = browserBackEvt(g);
  1202.         }
  1203.         break;
  1204.  
  1205.     case frmOpenEvent:
  1206.         frmOpenEvent_OH(g);
  1207.         break;
  1208.  
  1209.     case frmCloseEvent:
  1210.         frmCloseEvent_OH(g);
  1211.         break;
  1212.  
  1213.     case nilEvent:
  1214.         handled = runBrowserState(g);
  1215.         break;
  1216.  
  1217.     case sclRepeatEvent:
  1218.         deactivateInputFld(g);
  1219.         g->ScrollY = event->data.sclRepeat.newValue*10;
  1220.         scrollUpdate(g);
  1221.         break;
  1222.  
  1223.     case keyDownEvent:
  1224.         switch (event->data.keyDown.chr) {
  1225.         case pageUpChr:
  1226.             deactivateInputFld(g);
  1227.             scrollUp(g);
  1228.             break;
  1229.  
  1230.         case pageDownChr:
  1231.             deactivateInputFld(g);
  1232.             scrollDown (g);
  1233.             break;
  1234.         }
  1235.         break;
  1236.  
  1237.     case penUpEvent: // leave this one at the end of the switch !!
  1238.         handled = browserPenUpEvt(event,g);
  1239.         break;
  1240.  
  1241.     case menuEvent:
  1242.         deactivateInputFld(g);
  1243.         handled = mhMenuView(event->data.menu.itemID,g);
  1244.           break;
  1245.         
  1246.     default:
  1247.         break;        
  1248.  
  1249.     }
  1250. #ifdef __GNUC__
  1251.     CALLBACK_EPILOGUE
  1252. #endif
  1253.     return handled;
  1254. }
  1255.  
  1256.  
  1257. /* Item Handler Functions Here */
  1258.  
  1259. /**--------------------------------------**/
  1260. /** Form Object Handler Functions for FormBrowser **/
  1261. /**--------------------------------------**/
  1262.  
  1263.  
  1264.  
  1265. /****************************************************/
  1266. /* 
  1267.    Function: Boolean ButtonURLs_OH(EventPtr event);
  1268.    Description: Button Object Handler for the FormBrowser Form
  1269.  */
  1270. /****************************************************/
  1271.  
  1272. static Boolean browserPenUpEvt(EventPtr event, GlobalsType *g)
  1273. {
  1274. Int16 xpos,ypos;
  1275.  
  1276.     xpos = event->screenX;
  1277.     ypos = event->screenY;
  1278.     if((xpos > 153) || (ypos > 144))
  1279.         return(false);
  1280.     // user clicked in the browser area, check if he clicked an hyperlink
  1281.     ypos += g->ScrollY;
  1282.     // let's see if we have a link under this xpos/ypos position
  1283.     if (!checkSelect(xpos,ypos,g)){
  1284.         if(!checkInput(xpos,ypos,g)){
  1285.             return(checkHyperLink(xpos, ypos,g));
  1286.         }
  1287.     }
  1288.     return(true);
  1289. }
  1290.  
  1291. Boolean browserStopEvt(GlobalsType *g)
  1292. {
  1293.     g->progress= 0;
  1294.     showProgress(g);
  1295.     g->state = BS_IDLE;
  1296.     FrmSetTitle(FrmGetActiveForm(),"WAPUniverse");
  1297.     return(true);
  1298. }
  1299.  
  1300.             
  1301. /****************************************************/
  1302. /* 
  1303.    Function: Boolean ButtonURLs_OH(EventPtr event);
  1304.    Description: Button Object Handler for the FormBrowser Form
  1305.  */
  1306. /****************************************************/
  1307.  
  1308. Boolean browserURLsEvt(GlobalsType *g)
  1309. {
  1310.     SwitchForm(frmUrlList,g);
  1311.     return(true);   
  1312. }
  1313.  
  1314.  
  1315. /****************************************************/
  1316. /* 
  1317.    Function: Boolean ButtonBack_OH(EventPtr event);
  1318.    Description: Button Object Handler for the FormBrowser Form
  1319.  */
  1320. /****************************************************/
  1321.  
  1322. Boolean browserBackEvt(GlobalsType *g)
  1323. {
  1324.  
  1325. Char *tmpUrl;
  1326.  
  1327.     tmpUrl = historyPop(g);
  1328.     if (!tmpUrl)
  1329.         return(true);
  1330.     if(g->Url)
  1331.         Free(g->Url);
  1332.     g->Url=Malloc(MAX_URL_LEN+1);
  1333.     ErrFatalDisplayIf (!g->Url, "Malloc");
  1334.     wapCreateUrlStr(tmpUrl,g->Url,g);
  1335.     free(tmpUrl);
  1336.     browserReloadEvt(g);
  1337.     return(true);   
  1338. }
  1339.  
  1340.  
  1341.  
  1342.