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 >
Wrap
C/C++ Source or Header
|
2000-11-12
|
3KB
|
106 lines
// ---------------------------------------------------------------------------
// PalmUtils.c
// Contains generic PalmOS code snippets
//
// Project: WAPUniverse for PalmOS
// Copyright ⌐ 1999-2000 Filip Onkelinx
//
// http://www.wapuniverse.com/
// filip@onkelinx.com
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
//
// $Workfile: PalmUtils.c $
// $Author: wapuniverse $
// $Date: 2000/11/11 20:51:09 $
// $Revision: 1.4 $
//
// $Header: /cvsroot/wapuniverse/wapuniverse/src/PalmUtils.c,v 1.4 2000/11/11 20:51:09 wapuniverse Exp $
//
// -------------------------------------------------------------------------------
#include <PalmOS.h>
void *GetObjectPtr (UInt16 objectID)
{
FormPtr frm = FrmGetActiveForm ();
return(FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, objectID)));
}
void SetFieldFromStr(const Char *srcP , UInt16 fieldIndex)
{
FieldPtr fldP;
FormPtr frm = FrmGetActiveForm ();
MemHandle txtH;
MemHandle oldTxtH;
fldP = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, fieldIndex));
ErrNonFatalDisplayIf (!fldP, "missing field");
oldTxtH = (MemHandle) FldGetTextHandle (fldP);
// get some space in which to stash the string
txtH = MemHandleNew (StrLen (srcP) + 1);
ErrFatalDisplayIf (!txtH, "MemHandleNew Failed");
StrCopy (MemHandleLock (txtH), srcP);
// unlock the string MemHandle
MemHandleUnlock (txtH);
FldSetTextHandle (fldP, (MemHandle) txtH);
FldDrawField (fldP);
// free the MemHandle AFTER we call FldSetTextHandle.
if (oldTxtH)
MemHandleFree (oldTxtH);
}
// draw strings at top of rectangle r, but don't overwrite
// right-edge of r
void DrawCharsToFitWidth (char* s, RectanglePtr r, char c)
{
char t[40];
Int16 stringLength = StrLen (s) + 1;
Int16 pixelWidth = r->extent.x;
Boolean truncate;
t[0] = c;
StrCopy (&t[1], s);
// FntCharsInWidth will update stringLength to the
// maximum without exceeding the width
FntCharsInWidth (t, &pixelWidth, &stringLength, &truncate);
WinDrawChars (t, stringLength, r->topLeft.x, r->topLeft.y);
}
FieldPtr GetFocusObjectPtr (void)
{
FormPtr frm;
UInt16 focus;
// get a poInt16er to tha active form and the index of the form object with
// focus
frm = FrmGetActiveForm ();
focus = FrmGetFocus (frm);
// if no object has the focus return NULL poInt16er
if (focus == noFocus)
return(NULL);
// return a poInt16er to the object with focus
return(FrmGetObjectPtr (frm, focus));
}