#include #include #include #include "Utilities.h" #include "math.h" typedef short double *psdouble, **ppsdouble; OSErr dimimgr(Pimgdr m, int y, int x){ int i; m->y = y; m->x = x; if (!(m->e = (ppsdouble) NewPtr(sizeof(psdouble) * (long)y))) return memFullErr; for (i=0; ie[i] = (psdouble)NewPtr(sizeof(short double) * (long)x))){ m->y = i; freeimgr(m); return memFullErr; } } return noErr; } void freeimgr(Pimgdr m){ int y,i; y = m->y; for (i=0; ie[i]); DisposPtr((Ptr)m->e); } int GetDialogItem(DialogPtr TheDialog, int item){ short ItemType; Rect ItemBox; Handle ItemHdl; Str255 str; GetDItem(TheDialog, item, &ItemType, &ItemHdl, &ItemBox); return GetCtlValue((ControlHandle)ItemHdl); } void SetDialogItem(DialogPtr TheDialog, int item, int n){ short ItemType; Rect ItemBox; Handle ItemHdl; Str255 str; GetDItem(TheDialog, item, &ItemType, &ItemHdl, &ItemBox); SetCtlValue((ControlHandle)ItemHdl, n); } void SetDNum(DialogPtr TheDialog, int item, int n){ short ItemType; Rect ItemBox; Handle ItemHdl; Str255 str; GetDItem(TheDialog, item, &ItemType, &ItemHdl, &ItemBox); NumToString(n,str); SetIText(ItemHdl, str); } void SetDReal(DialogPtr TheDialog, int item, double n, int fwidth){ short ItemType; Rect ItemBox; Handle ItemHdl; Str255 str; GetDItem(TheDialog, item, &ItemType, &ItemHdl, &ItemBox); Real2String(n,1, fwidth, str); SetIText(ItemHdl, str); } double GetDReal(DialogPtr TheDialog, int item){ Str255 str; Rect r; short itemType; Handle Text; GetDItem (TheDialog, item, &itemType, &Text, &r); GetIText (Text, str); return String2Real(str); } int GetDNum(DialogPtr TheDialog, int item){ long n; Str255 str; Rect r; short itemType; Handle Text; GetDItem (TheDialog, item, &itemType, &Text, &r); GetIText (Text, str); StringToNum(str,&n); return n; } void SetDString(DialogPtr TheDialog, int item, Str255 str){ short ItemType; Rect ItemBox; Handle ItemHdl; GetDItem(TheDialog, item, &ItemType, &ItemHdl, &ItemBox); SetIText(ItemHdl, str); } void GetDString(DialogPtr TheDialog, int item, Str255 str){ Rect r; short itemType; Handle Text; GetDItem (TheDialog, item, &itemType, &Text, &r); GetIText (Text, str); } double String2Real(Str255 str){ PtoCstr(str); return atof((char *)str); } void Real2String(double val, int width, int fwidth, Str255 str)/* ignoring width for now */ { char fs[] = "%6.2f"; /* fwidth =-1 => make up a sensible value for fwidth 0 2 or 4 */ if ( fwidth < 0 ) { if ( val < 1.0 ) fwidth = 4; else if ( (int)val == val ) fwidth = 0; else fwidth = 2; } fs[1] = '0'+width; fs[3] = '0'+fwidth; sprintf((char *)str,fs,val); CtoPstr((char *)str); }