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 / PalmUtils.c < prev    next >
C/C++ Source or Header  |  2000-11-12  |  3KB  |  106 lines

  1. // ---------------------------------------------------------------------------
  2. // PalmUtils.c
  3. // Contains generic PalmOS code snippets
  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: PalmUtils.c $  
  27. // $Author: wapuniverse $  
  28. // $Date: 2000/11/11 20:51:09 $     
  29. // $Revision: 1.4 $
  30. // 
  31. // $Header: /cvsroot/wapuniverse/wapuniverse/src/PalmUtils.c,v 1.4 2000/11/11 20:51:09 wapuniverse Exp $
  32. // 
  33. // -------------------------------------------------------------------------------
  34. #include    <PalmOS.h>
  35.  
  36. void *GetObjectPtr (UInt16 objectID)
  37. {
  38.     FormPtr         frm = FrmGetActiveForm ();
  39.     return(FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, objectID)));
  40. }
  41.  
  42. void SetFieldFromStr(const Char *srcP , UInt16 fieldIndex)
  43. {
  44.   FieldPtr        fldP;
  45.   FormPtr         frm = FrmGetActiveForm ();
  46.   MemHandle       txtH;
  47.   MemHandle       oldTxtH;
  48.  
  49.   fldP = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, fieldIndex));
  50.   ErrNonFatalDisplayIf (!fldP, "missing field");
  51.   oldTxtH = (MemHandle) FldGetTextHandle (fldP);
  52.   // get some space in which to stash the string
  53.   txtH = MemHandleNew (StrLen (srcP) + 1);
  54.   ErrFatalDisplayIf (!txtH, "MemHandleNew Failed");
  55.   StrCopy (MemHandleLock (txtH), srcP);
  56.   // unlock the string MemHandle 
  57.   MemHandleUnlock (txtH);
  58.   FldSetTextHandle (fldP, (MemHandle) txtH);
  59.   FldDrawField (fldP);
  60.   // free the MemHandle AFTER we call FldSetTextHandle.
  61.   if (oldTxtH)
  62.     MemHandleFree (oldTxtH);
  63.  
  64. }
  65.  
  66. // draw strings at top of rectangle r, but don't overwrite
  67. // right-edge of r
  68. void DrawCharsToFitWidth (char* s, RectanglePtr r, char c)
  69. {
  70.     char            t[40];
  71.     Int16          stringLength = StrLen (s) + 1;
  72.     Int16          pixelWidth = r->extent.x;
  73.     Boolean         truncate;
  74.  
  75.     t[0] = c;
  76.     StrCopy (&t[1], s);
  77.     // FntCharsInWidth will update stringLength to the 
  78.     // maximum without exceeding the width
  79.     FntCharsInWidth (t, &pixelWidth, &stringLength, &truncate);
  80.     WinDrawChars (t, stringLength, r->topLeft.x, r->topLeft.y);
  81. }
  82.  
  83.  
  84.  
  85. FieldPtr GetFocusObjectPtr (void)
  86. {
  87.     FormPtr         frm;
  88.     UInt16            focus;
  89.  
  90.     // get a poInt16er to tha active form and the index of the form object with
  91.     // focus
  92.     frm = FrmGetActiveForm ();
  93.     focus = FrmGetFocus (frm);
  94.  
  95.     // if no object has the focus return NULL poInt16er
  96.     if (focus == noFocus)
  97.         return(NULL);
  98.  
  99.     // return a poInt16er to the object with focus
  100.     return(FrmGetObjectPtr (frm, focus));
  101. }
  102.  
  103.  
  104.  
  105.  
  106.