home *** CD-ROM | disk | FTP | other *** search
/ Palm Utilities / Palm_Utilities_CD-ROM_2001_2001.iso / files / internet misc / GetTLE 1.0 / GetTLE.exe / Src / Util.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-07  |  2.5 KB  |  78 lines

  1. /*
  2.     GetTLE - Util.c - two routines to make fields less complicated
  3.     Copyright ⌐2000 Andreas Schneider
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18. */
  19.  
  20. #include <PalmOS.h>
  21. #include "Util.h"
  22.  
  23. // Set the text of a field to the text given by NewHandle
  24. // also free the OldHandle (if any)
  25. extern FieldPtr SetFormFieldTextFromHandle(FormPtr Form,UInt16 FieldID, MemHandle NewHandle)
  26. {
  27.     MemHandle    OldHandle;
  28.     FieldPtr    Field;
  29.     
  30.     // get the field and it's text VoidHand.
  31.     Field = FrmGetObjectPtr(Form, FrmGetObjectIndex(Form, FieldID));
  32.     if (Field)
  33.     {
  34.       // remember the old handle - we might have to free it later
  35.       OldHandle = (MemHandle) FldGetTextHandle(Field);
  36.       // set the field's text to the new text
  37.       FldSetTextHandle(Field, (MemHandle) NewHandle);
  38.       // redraw the field to make the change visible
  39.       FldDrawField(Field);
  40.       // now that the field has the new handle we should free the old one
  41.       if (OldHandle)
  42.       {
  43.           MemHandleFree(OldHandle);
  44.       }
  45.     }
  46.     return Field;
  47. }
  48.  
  49. // even more coveniant: just pass the text - the Handle stuff
  50. // is handled by this routine - this one needs the FormPtr
  51. extern FieldPtr SetFormFieldTextFromString(FormPtr Form,UInt16 FieldID, Char *String)
  52. {
  53.     MemHandle NewHandle;
  54.     FieldPtr Field=NULL;
  55.     
  56.     // allocate memory for a copy of the string plus trailing \0
  57.     NewHandle = MemHandleNew(StrLen(String) + 1);
  58.     if (NewHandle)
  59.     {    
  60.       // lock the handle and copy the string to it
  61.       StrCopy(MemHandleLock(NewHandle), String);
  62.       // unlock the handle
  63.       MemHandleUnlock(NewHandle);
  64.       // set the field text using the above routine
  65.       Field = SetFormFieldTextFromHandle(Form,FieldID,NewHandle);
  66.   }
  67.   return Field;
  68. }
  69.  
  70.  
  71. // we might not want to specify the Form
  72. extern FieldPtr SetFieldTextFromString(UInt16 FieldID,Char *String)
  73. {
  74.   FieldPtr Field;
  75.   
  76.   Field=SetFormFieldTextFromString(FrmGetActiveForm(),FieldID,String);
  77.   return Field;
  78. }