Ejemplo n.º 1
0
static void AudioCDTabInit() {
	ControlType *cck3P;
	FieldType *fld2P, *fld3P;
	ListType *list1P, *list2P;
	MemHandle lengthH, firstTrackH;
	Char *lengthP, *firstTrackP;

	cck3P = (ControlType *)GetObjectPtr(TabAudioCDMP3Checkbox);
	fld2P = (FieldType *)GetObjectPtr(TabAudioCDLengthSecsField);
	fld3P = (FieldType *)GetObjectPtr(TabAudioCDFirstTrackField);
	list1P = (ListType *)GetObjectPtr(TabAudioCDDriverList);
	list2P = (ListType *)GetObjectPtr(TabAudioCDFormatList);

	LstSetSelection(list1P, gameInfoP->musicInfo.sound.drvCD);
	CtlSetLabel((ControlType *)GetObjectPtr(TabAudioCDDriverPopTrigger), LstGetSelectionText(list1P, LstGetSelection(list1P)));

	LstSetSelection(list2P, gameInfoP->musicInfo.sound.frtCD);
	CtlSetLabel((ControlType *)GetObjectPtr(TabAudioCDFormatPopTrigger), LstGetSelectionText(list2P, LstGetSelection(list2P)));

	CtlSetValue(cck3P, gameInfoP->musicInfo.sound.CD);

	lengthH = MemHandleNew(FldGetMaxChars(fld2P)+1);
	lengthP = (Char *)MemHandleLock(lengthH);
	StrIToA(lengthP, gameInfoP->musicInfo.sound.defaultTrackLength);
	MemHandleUnlock(lengthH);
	FldSetTextHandle(fld2P, lengthH);

	firstTrackH = MemHandleNew(FldGetMaxChars(fld3P)+1);
	firstTrackP = (Char *)MemHandleLock(firstTrackH);
	StrIToA(firstTrackP, gameInfoP->musicInfo.sound.firstTrack);
	MemHandleUnlock(firstTrackH);
	FldSetTextHandle(fld3P, firstTrackH);
}
Ejemplo n.º 2
0
/*
** Load the record data (flags, ...) - but not the picture
*/
static void LoadRecordData(void) {
  MemHandle t = NULL;
  MemPtr ptr = NULL;
  UInt16 attr = 0;
  UInt32 highDataOffset = 0;
  Int16 len = 0;

  PRINT("Loading Record Data for %hd", p.dbI);

  /* Clear unmasked flag */
  d.unmaskedCurrentRecord = false;

  /* Open and lock the record */
  t = DmQueryRecord(d.dbR, p.dbI);
  if (!t) abort();
  ptr = MemHandleLock(t);

  /* Is the record private? */
  DmRecordInfo(d.dbR, p.dbI, &attr, NULL, NULL);
  d.record_private = attr & dmRecAttrSecret;

  /* Read the header data */
  MemMove(&d.record, ptr, sizeof(DiddleBugRecordType));

  /* Read the additional alarm info */
  highDataOffset = sketchDataOffset + d.record.sketchLength;

  len = StrLen((Char*)(ptr + highDataOffset)) + 1; /* +1 for null char */
  if (d.record_name) MemHandleFree(d.record_name);
  d.record_name = MemHandleNew(len);
  ASSERT(d.record_name);
  MemMove(MemHandleLock(d.record_name), ptr + highDataOffset, len);
  MemHandleUnlock(d.record_name);

  highDataOffset += len;

  len = StrLen((Char*)(ptr + highDataOffset)) + 1; /* +1 for null char */
  if (d.record_note) MemHandleFree(d.record_note);
  d.record_note = MemHandleNew(len);
  ASSERT(d.record_note);
  MemMove(MemHandleLock(d.record_note), ptr + highDataOffset, len);
  MemHandleUnlock(d.record_note);

  highDataOffset += len;

  /* Clear old data since there may not be an extra-data block yet */
  MemSet(&d.record_sound, sizeof(AlarmSoundInfoType), 0);
  d.record_sound.listIndex = -1; /* default */
  /* Read new extra-data (if it exists and is from a compatible version) */
  if (d.record.extraLength == sizeof(AlarmSoundInfoType))
    MemMove(&d.record_sound, ptr + highDataOffset, d.record.extraLength);

  /* Unlock record */
  MemHandleUnlock(t);
}
Ejemplo n.º 3
0
/*****************************************************************************
* Function: GadgetDrawTime
*
* Description: Show a time in the grid
*****************************************************************************/
void
GadgetDrawTime(TimeType begin, TimeType end, UInt8 day, RGBColorType *color, UInt16 courseID, UInt8 num_times, UInt8 pos)
{
  RectangleType rect;
  RGBColorType prevColor, inverted;

  // Sort out bogus requests, could be more intelligent, maybe later...
  if (day >= gGadgetDaysNum) return;

  // do nothing if Gadget has not yet been GadgetSet
  if (! gForm) return;
  if (! gGadgetID) return;

  GadgetTimeSetRect(&rect, begin, end, day, num_times, pos);


  TNSetForeColorRGB(color, &prevColor);
  WinDrawRectangle(&rect, 0);

  if ( (gPrefs.showTypes || gPrefs.showShortNames) && (rect.extent.y >= FntLineHeight())) {

    RGBColorType oldBack, oldText;

    // Get inverted color
    inverted.r = 255 - color->r;
    inverted.g = 255 - color->g;
    inverted.b = 255 - color->b;

    RctSetRectangle(&rect, rect.topLeft.x+2, rect.topLeft.y, rect.extent.x-4, rect.extent.y);

    TNSetTextColorRGB(&inverted, &oldText);
    TNSetBackColorRGB(color, &oldBack);

    if (gPrefs.showTypes) {
      MemHandle shortName=MemHandleNew(1);;
      CourseTypeGetShortByCourseID(&shortName, courseID);
      TNDrawCharsToFitWidth((Char *)MemHandleLock(shortName), &rect);
      MemHandleUnlock(shortName);
      MemHandleFree(shortName);
    } else if (gPrefs.showShortNames) {
      MemHandle courseName=MemHandleNew(1);
      CourseGetName(courseID, &courseName, false);

      TNDrawCharsToFitWidth((Char *)MemHandleLock(courseName), &rect);

      MemHandleUnlock(courseName);
      MemHandleFree(courseName);
    }

    TNSetBackColorRGB(&oldBack, NULL);
    TNSetTextColorRGB(&oldText, NULL);
  }

  TNSetForeColorRGB(&prevColor, NULL);
}
Ejemplo n.º 4
0
static Boolean
CourseListHandleSelection(void)
{
  MemHandle m, mWebsite, mEmail, old;
  CourseDBRecord c;
  FieldType *fldWebsite, *fldEmail;
  Char *buffer;
  
  m = DmQueryRecord(DatabaseGetRefN(DB_MAIN), gCourseInd[LstGetSelection(GetObjectPtr(LIST_courses))]);
  if (! m)  return true;
  UnpackCourse(&c, MemHandleLock(m));
  fldWebsite = GetObjectPtr(FIELD_cl_website);
  fldEmail = GetObjectPtr(FIELD_cl_email);

  if (StrLen(c.website) == 0) {
    mWebsite = MemHandleNew(4);
    buffer=MemHandleLock(mWebsite);
    MemSet(buffer, 4, 0);
    StrCopy(buffer, "-?-");
  } else {
    mWebsite = MemHandleNew(StrLen(c.website)+1);
    buffer = MemHandleLock(mWebsite);
    MemSet(buffer, StrLen(c.website)+1, 0);
    StrCopy(buffer, c.website);
  }
  MemHandleUnlock(mWebsite);
  old = FldGetTextHandle(fldWebsite);
  FldSetTextHandle(fldWebsite, mWebsite);
  if (old != NULL)  MemHandleFree(old); 
  FldDrawField(fldWebsite);

  if (StrLen(c.teacherEmail) == 0) {
    mEmail = MemHandleNew(4);
    buffer = MemHandleLock(mEmail);
    MemSet(buffer, 4, 0);
    StrCopy(buffer, "-?-");
  } else {
    mEmail = MemHandleNew(StrLen(c.teacherEmail)+1);
    buffer = MemHandleLock(mEmail);
    MemSet(buffer, StrLen(c.teacherEmail)+1, 0);
    StrCopy(buffer, c.teacherEmail);
  }
  MemHandleUnlock(mEmail);
  old = FldGetTextHandle(fldEmail);
  FldSetTextHandle(fldEmail, mEmail);
  if (old != NULL)  MemHandleFree(old); 
  FldDrawField(fldEmail);

  MemHandleUnlock(m);

  return false;
}
Ejemplo n.º 5
0
// Get user name e.g. Julian Smart
bool wxGetUserName(wxChar *buf, int maxSize)
{
    *buf = wxT('\0');

    // buffer allocation
    MemHandle handle = MemHandleNew(maxSize-1);
    if( handle == NULL )
        return false;

    // lock the buffer
    char *id = (char *)MemHandleLock(handle);
    if( id == NULL )
        return false;

    // get user's name
    if( DlkGetSyncInfo(NULL, NULL, NULL, id, NULL, NULL) != errNone )
    {
        MemPtrUnlock(id);
        return false;
    }

    wxStrlcpy(buf, wxSafeConvertMB2WX(id), maxSize);

    // free the buffer
    MemPtrUnlock(id);

    return true;
}
Ejemplo n.º 6
0
void wxControl::SetFieldLabel(const wxString& label)
{
    FieldType* field = (FieldType*)GetObjectPtr();
    if(field==NULL)
        return;

    uint16_t newSize = label.Length() + 1;
    MemHandle strHandle = FldGetTextHandle(field);
    FldSetTextHandle(field, NULL );
    if (strHandle)
    {
        if(MemHandleResize(strHandle, newSize)!=errNone)
            strHandle = 0;
    }
    else
    {
        strHandle = MemHandleNew( newSize );
    }
    if(!strHandle)
        return;

    char* str = (char*) MemHandleLock( strHandle );
    if(str==NULL)
        return;

    strcpy(str, label.c_str());
    MemHandleUnlock(strHandle);
    FldSetTextHandle(field, strHandle);
    FldRecalculateField(field, true);
}
Ejemplo n.º 7
0
static void
ExamDelete(void)
{
  MemHandle mex, m;
  ExamDBRecord *ex;
  UInt16 index=0, pressedButton=0;
  Char *courseName, timeTemp[timeStringLength], dateTemp[longDateStrLength];

  DmFindRecordByID(DatabaseGetRefN(DB_MAIN), gExamsLastSelRowUID, &index);
  mex = DmQueryRecord(DatabaseGetRefN(DB_MAIN), index);
  ex = (ExamDBRecord *)MemHandleLock(mex);

  m=MemHandleNew(1);
  CourseGetName(ex->course, &m, true);
  courseName = MemHandleLock(m);

  DateToAscii(ex->date.month, ex->date.day, ex->date.year+MAC_SHIT_YEAR_CONSTANT, PrefGetPreference(prefLongDateFormat), dateTemp);
  TimeToAscii(ex->begin.hours, ex->begin.minutes, PrefGetPreference(prefTimeFormat), timeTemp);

  pressedButton = FrmCustomAlert(ALERT_ex_dodel, courseName, dateTemp, timeTemp);

  MemHandleUnlock(m);
  MemHandleFree(m);
  MemHandleUnlock(mex);

  if (pressedButton == 0) {
    // OK, the user really wants us to delete the record
    NoteDelete(&index);
    DmRemoveRecord(DatabaseGetRefN(DB_MAIN), index);
    gExamsSelRow=0;
    FrmUpdateForm(FORM_exams, frmRedrawUpdateCode);
  }
}
Ejemplo n.º 8
0
static void
TableDrawData(void *table, Int16 row, Int16 column, RectangleType *bounds)
{
  UInt16 index=TblGetRowID(table, row);
  ExamDBRecord *ex;
  MemHandle mex;
  RGBColorType fore={0x00, 0x00, 0x00, 0x00}, back={0x00, 0xFF, 0xFF, 0xFF};

  if (! TblRowUsable(table, row)) return;
  
  TNSetBackColorRGB(&back, NULL);
  TNSetForeColorRGB(&back, NULL);
  WinDrawRectangle(bounds, 0);

  mex = DmQueryRecord(DatabaseGetRefN(DB_MAIN), index);
  ex = (ExamDBRecord *)MemHandleLock(mex);

  if (column == EXCOL_COURSE) {
    Char *temp;
    MemHandle m=MemHandleNew(1);
    CourseGetName(ex->course, &m, true);
    temp = MemHandleLock(m);

    TNSetForeColorRGB(&fore, NULL);
    TNDrawCharsToFitWidth(temp, bounds);

    MemHandleUnlock(m);
    MemHandleFree(m);
  } else if (column == EXCOL_NOTE) {
    if (ex->note) {
      Char noteSymb[2] = { GADGET_NOTESYMBOL, 0 };
      FontID oldFont = FntSetFont(symbolFont);

      TNDrawCharsToFitWidth(noteSymb, bounds);
      FntSetFont(oldFont);
    }
  } else if (column == EXCOL_DATE) {
    Char dateTemp[dateStringLength];
    DateToAscii(ex->date.month, ex->date.day, ex->date.year+MAC_SHIT_YEAR_CONSTANT, PrefGetPreference(prefDateFormat), dateTemp);
    TNDrawCharsToFitWidth(dateTemp, bounds);
  } else if (column == EXCOL_TIME) {
    Char timeTemp[timeStringLength];
    TimeToAscii(ex->begin.hours, ex->begin.minutes, PrefGetPreference(prefTimeFormat), timeTemp);
    TNDrawCharsToFitWidth(timeTemp, bounds);
  }


  if (ex->flags & EX_FLAG_DONE) {
    RGBColorType red = {0x00, 0xFF, 0x00, 0x00}, old;
    Int16 yCoord=bounds->topLeft.y+(bounds->extent.y / 2);
    TNSetForeColorRGB(&red, &old);
    WinDrawLine(bounds->topLeft.x, yCoord, bounds->topLeft.x+bounds->extent.x, yCoord);
    TNSetForeColorRGB(&old, NULL);
  }

  MemHandleUnlock(mex);
}
/***********************************************************************
 *
 * FUNCTION:    MainFormInit
 *
 * DESCRIPTION: This routine initializes the MainForm form.
 *
 * PARAMETERS:  frm - pointer to the MainForm form.
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *
 *
 ***********************************************************************/
static void MainFormInit(FormPtr frmP)
{
	FieldPtr			fld;
	char *ptr;
   	MemHandle			mh = MemHandleNew (10);
	fld = GetObjectPtr (MainSymbolField);
	ptr = MemHandleLock (mh);
	strcpy(ptr,"IBM");
	FldSetTextHandle (fld, mh);
    MemHandleUnlock(mh);
}
Ejemplo n.º 10
0
Err vfsFileDBGetRecord
    (
    FileRef ref,
    UInt16 recIndex,
    MemHandle *recHP,
    UInt8 *recAttrP,
    UInt32 *uniqueIDP
    )
{
    UInt32 offset;
    UInt32 length;
    MemPtr mp;
    Char* buf;
    file_rec_t axxFileRec;
    Err err;

    if (GetFileProperties (ref,&axxFileRec)!=errNone)
               return dmErrNotRecordDB;

    if (currFileDesc != axxFileRec.fd)
        LoadOffsets(axxFileRec.fd);

    /*Get the record byte position withing the file */
    mp = MemHandleLock(moff);
   ASSERT_MSG("AIM0", mp != 0);

    offset = ((UInt32*)mp)[recIndex * 2];
    length = recIndex < nrec ? ((UInt32*)mp)[recIndex * 2 + 2] : 
                 axxFileRec.size;
    MemHandleUnlock(moff);
    if ( nrec < recIndex) {
        return dmErrIndexOutOfRange;
    }
     length -= offset;
    err=axxPacSeek(LibRef, axxFileRec.fd, offset, SEEK_SET);
    if (err==AXXPAC_ERR_FILE_CLOSED) {
         axxPacFD FileDesc;
        /*This happens when the axxPac has entered into sleep mode */
        FileDesc = axxPacOpen(LibRef, axxFileRec.name,axxFileRec.mode);
        if (FileDesc<0)
              return dmErrNotRecordDB;
        /*The axxPac could have assigned a FileDesc different from before */
        if (FileDesc!=axxFileRec.fd) {
                UpdateFileDesc (ref,FileDesc);
                axxFileRec.fd=FileDesc;
        }
        err=axxPacSeek(LibRef, FileDesc, offset, SEEK_SET);
    }
    *recHP = MemHandleNew(length);
    buf = MemHandleLock(*recHP);
    axxPacRead (LibRef, axxFileRec.fd, buf, length);
    MemHandleUnlock(*recHP);
    return errNone;
}
Ejemplo n.º 11
0
/*****************************************************************************
* Function: DrawCourses
*
* Description: local function to fill the course list
*****************************************************************************/
static void
DrawCourses(ListType *lst)
{
  MemHandle mWebsite, mEmail, old;
  Char *buffer;
  FieldType *fldWebsite, *fldEmail;
  
  gNumCourses=CountCourses();
  gCourseList = (Char **) MemPtrNew(gNumCourses * sizeof(Char *));
  gCourseInd = (UInt16 *) MemPtrNew(gNumCourses * sizeof(UInt16));

  CourseListGen(gCourseList, NULL, gCourseInd, gNumCourses, 0, CLIST_SEARCH_INDEX);
  LstSetListChoices(lst, gCourseList, gNumCourses);
  LstSetSelection(lst, -1);

  
  fldWebsite = GetObjectPtr(FIELD_cl_website);
  fldEmail = GetObjectPtr(FIELD_cl_email);
  
  mWebsite = MemHandleNew(4);
  buffer = MemHandleLock(mWebsite);
  MemSet(buffer, 4, 0);
  StrCopy(buffer, "-?-");
  MemHandleUnlock(mWebsite);

  old = FldGetTextHandle(fldWebsite);
  FldSetTextHandle(fldWebsite, mWebsite);
  if (old != NULL)  MemHandleFree(old); 

  mEmail = MemHandleNew(4);
  buffer = MemHandleLock(mEmail);
  MemSet(buffer, 4, 0);
  StrCopy(buffer, "-?-");
  MemHandleUnlock(mEmail);

  old = FldGetTextHandle(fldEmail);
  FldSetTextHandle(fldEmail, mEmail);
  if (old != NULL)  MemHandleFree(old); 

  
}
Ejemplo n.º 12
0
FF_CM_Class *FF_CM_New(long sizeofCache, int *errCode)
{
	FF_CM_Class *pCmGlobals = NULL;
	tsiMemObject *mem = NULL;
	char *cacheptr = NULL;

	/* Create the memory object that will hold the cache */
	mem = tsi_NewMemhandler( errCode );
	assert( *errCode == 0 );

	if (!*errCode)
	{
		/* Now actually allocate the memory for the cache */
#ifdef PALM
		memH = MemHandleNew((UInt32)sizeofCache);
		if (memH)
			cacheptr = (char *)MemHandleLock(memH);
#else
		cacheptr = (char *)tsi_AllocMem( mem, (size_t)sizeofCache );
#endif
		if (cacheptr)
		{
			/* Using this memory block go and assemble the cache */
			/* initialize pointers, setup data structures, etc.  */

			/* Prototype of CmInitializeCache has been change    */
			/*	  Original: void() (void **, size_t, char*)		 */
			/*	  New     : void*() (size_t, char*)				 */
			/* It seems when GNU compiler inserting static func	 */
			/* into body of caller, position of storing result	 */
			/* are not decided correctly.						 */
			/* DO NOT USE following type of functions			 */
			#if 0
			CmInitializeCache((void **)&pCmGlobals, sizeofCache, cacheptr);
			#endif
			pCmGlobals = CmInitializeCache(sizeofCache, cacheptr);

			/* Save this pointer to the cache context within the global */
			/* cache structure itself -- wild huh?					*/

			pCmGlobals->mem = mem;
			pCmGlobals->BitmapFilter = NULL;
			pCmGlobals->filterParamsPtr = NULL;
		}
		else
		{
			*errCode = T2K_ERR_MEM_MALLOC_FAILED;
		}
	}
    /* Return the self pointer back to the creating application */
	return (pCmGlobals);
}
Ejemplo n.º 13
0
Archivo: helper.c Proyecto: teras/FEdit
void SetFieldFromInt ( UInt16 fieldID, int data ) {
	
	/* Temporary place in heap in order to store the string data */
	MemHandle txtH;
	
	txtH = MemHandleNew ( 10 );
	if ( !txtH) return;

	StrPrintF ( MemHandleLock(txtH), "%i", data);
	SetFieldFromHandle ( fieldID, txtH);
	MemHandleUnlock (txtH);

}
Ejemplo n.º 14
0
/* SetFieldTextFromStr -- Fills a field with a string
 * Args:    
 *     Word     fieldID  -- ID of field to fill, see cwimp.rpc file
 *     CharPtr  strP     -- String to fill ID with
 * Returns:
 *     FieldPtr          -- Ptr to the field set.
 */
FieldPtr SetFieldTextFromStr(Word fieldID, CharPtr strP)
{
  VoidHand txtH;
  
  txtH = MemHandleNew(StrLen(strP) + 1);
  if(!txtH) return NULL;
  
  StrCopy(MemHandleLock(txtH), strP);
  
  // ToDo: SetFieldTextFromHandle should happen *before* unlock
  MemHandleUnlock(txtH);
  
  return SetFieldTextFromHandle(fieldID, txtH);
}
Ejemplo n.º 15
0
/***************************************************************
                   md_malloc
 IN:
 n = size to allocate
 OUT:
 pointer to the locked chunk
 PURPOSE:
 Allocate and lock a moveable chunk of memory.
****************************************************************/
Char * md_malloc(Int n)
{
  VoidHand h;
  VoidPtr p;

  h = MemHandleNew((ULong) n); /* will this cast work??  apparently. */
  if (!h) {
    /* the caller might want to check this and die. */
    return NULL;
  }

  p = MemHandleLock(h);
  MemSet(p, n, 0); /* just to make really sure the memory is zeroed */
  return p;
}
Ejemplo n.º 16
0
Boolean DoRenameFigure(void)
{
    FormPtr prevFrm = FrmGetActiveForm();
    int numFigures = TFigurerecordGetCount();
    if ((currentFigure != noListSelection) && (currentFigure < numFigures)) {
	TFigure_type *t1 = TFigurerecordGet(currentFigure);
	if (t1) {
	    FormPtr frm = FrmInitForm(formRenameFigure);
	    FieldPtr field = (FieldPtr) FrmGetObjectPtr(frm,
							FrmGetObjectIndex
							(frm,
							 fieldFigureName));
	    MemHandle oldhText=FldGetTextHandle(field);
	    MemHandle hText = MemHandleNew(DESCSIZE);
	    char *titleptr = (char *) MemHandleLock(hText);
	    StrNCopy(titleptr, t1->name, DESCSIZE);
	    titleptr[DESCSIZE - 1] = 0;

	    MemPtrUnlock(titleptr);
	    FldSetTextHandle(field, (MemHandle) hText);
	    if (oldhText!=NULL) {
	      MemHandleFree(oldhText);
	    }

	    if (FrmDoDialog(frm) == buttonRFOK) {
		hText = FldGetTextHandle(field);
		titleptr = (char *) MemHandleLock(hText);
		if ((titleptr) && StrLen(titleptr) > 0) {

		    StrNCopy(t1->name, titleptr, DESCSIZE);
		    t1->name[DESCSIZE - 1] = 0;
		    TFigurerecordChange(currentFigure, t1);
		}
		MemPtrUnlock(titleptr);
	    }

	    TFigureFree(t1);
	    if (prevFrm)
		FrmSetActiveForm(prevFrm);
	    FrmDeleteForm(frm);
	}
	return true;
    }

    return false;
}
Ejemplo n.º 17
0
static ZDicFontGlobalsType * PrvMakeGlobals(UInt16 refNum)
{
	ZDicFontGlobalsType * gP = NULL;
	MemHandle gH;
	SysLibTblEntryType * libEntryP;

	/* Get library globals */
	libEntryP = SysLibTblEntry(refNum);
	ErrFatalDisplayIf(libEntryP == NULL, "invalid ZDicFont refNum");

	/* Error check to make sure the globals don't already exist */
	ErrFatalDisplayIf(libEntryP->globalsP, "ZDicFont globals already exist");

	/* Allocate and initialize our library globals. */
	gH = MemHandleNew(sizeof(ZDicFontGlobalsType));
	if ( !gH )
		return( NULL );

	/* Save the handle of our library globals in the system library table  */
	/* entry so we can later retrieve it using SysLibTblEntry(). */
	libEntryP->globalsP = (void*)gH;

	/* Lock our globals (should not fail) */
	gP = PrvLockGlobals(refNum);
	ErrFatalDisplayIf(gP == NULL, "failed to lock ZDicFont globals");

	/* Set the owner of our globals memory chunk to "system" (zero), so it won't get
	 * freed automatically by Memory Manager when the first application to call
	 * ZDicFontOpen exits.  This is important if the library is going to stay open
	 * between apps. */
	MemPtrSetOwner(gP, 0);

	/* Initialize our library globals */
	MemSet(gP, sizeof(ZDicFontGlobalsType), 0);

	/* for convenience and debugging, save ref in globals structure */
	gP->thisLibRefNum = refNum;

	/* initial open count */
	gP->openCount = 0;

	/* return a pointer to our *locked* globals */
	return( gP );
}
Ejemplo n.º 18
0
Archivo: helper.c Proyecto: teras/FEdit
void setFieldFromStr ( UInt16 fieldID, Char * strP ) 
{
	/* Temporary place in heap in order to store the string data */
	MemHandle txtH;

	/* Create new heap space */
	txtH = MemHandleNew ( StrLen (strP) + 1 ) ;
	if ( !txtH )
		return;

	/* Copy string to the heap, in order to be useful */
	StrCopy (MemHandleLock(txtH), strP);	/* Lock the current memory position, in order to accomply the specified task of setting text */
	
	/* Set text of field to the selected  heap data */
	SetFieldFromHandle (fieldID, txtH);
	
	/* Free lock for this (text) item */
	MemHandleUnlock(txtH);
	return;
}
Ejemplo n.º 19
0
static Err PrvCreateClientContext(ZDicFontGlobalsType * gP, UInt32 * clientContextP)
{
	Err err = errNone;
	MemHandle contextH;
	ZDicFontClientContextType * contextP;

	/* Error-check our parameters */
	ErrFatalDisplayIf(gP == NULL, "null globals pointer");
	ErrFatalDisplayIf(clientContextP == NULL, "null context variable pointer");

	/* Initialize return variable */
	*clientContextP = 0;

	/* Allocate a new client context structure */
	contextH = MemHandleNew(sizeof(ZDicFontClientContextType));
	if ( !contextH )
	{
		err = memErrNotEnoughSpace;
	}
	else
	{
		/* save context chunk handle in return variable */
		*clientContextP = (UInt32)contextH;

		/* Initialize the context chunk */
		contextP = (ZDicFontClientContextType *)MemHandleLock(contextH);

		/* save address of open routine as signature to validate context */
		contextP->libSignature = (void *)&ZDicFontOpen;

		/* TODO: Insert code to initialize context members */

		PrvUnlockContext(contextP);

		/* increment context count (for debugging) */
		gP->contextCount++;
		ErrFatalDisplayIf(gP->contextCount == 0, "context count overflow");
	}

	return( err );
}
Ejemplo n.º 20
0
/*******************************************************************
 * Function: getIndexForSystemID
 * Description: return an index for a unique system id.
 * ****************************************************************/ 
UInt16 getIndexForSystemID (DmOpenRef SystemDB, UInt16 sysid) {
	UInt16 i, id, index = 0;
	
	/*	get the number of system records. note that we cant just
		use totalItems++ because systems can be added and deleted
		at will... */
	UInt16 totalItems = DmNumRecordsInCategory (SystemDB, dmAllCategories);
	Boolean stop = false;
	
	/*	iterate through the records, and we will return the highest 
		one it higher than the highest current value. */
	for (i = 0; i < totalItems && !stop; i++) {
		MemHandle scr;
		if ((scr = MemHandleNew (1))) {
			id = getSIDForSystemIndex (SystemDB, i);
			if (id == sysid) index = i;
			freeHandle (scr);
		}
	}
	return index;
}
Ejemplo n.º 21
0
/*******************************************************************
 * Function: getUniqueSystemID
 * Description: return a unique system id that can be assigned to a
 * new system.
 * Note: SystemID 0 is reserved for the Unfiled system. Unfiled is 
 * where beamed accounts go when they are first received if they
 * dont have anywhere else to go.
 * ****************************************************************/ 
UInt16 getUniqueSystemID (DmOpenRef SystemDB) {
	UInt16 i, id;
	
	/*	get the number of system records. note that we cant just
		use totalItems++ because systems can be added and deleted
		at will... */
	UInt16 totalItems = DmNumRecordsInCategory (SystemDB, dmAllCategories);
	UInt16 max = 0;
	
	/*	iterate through the records, and we will return the highest 
		one it higher than the highest current value. */
	for (i = 0; i < totalItems; i++) {
		MemHandle scr;
		if ((scr = MemHandleNew (1))) {
			id = getSIDForSystemIndex (SystemDB, i);
			if (id > max) max = id;
			freeHandle (scr);
		}
	}
	return max + 1;
}
Ejemplo n.º 22
0
/* stores the table of offsets for all records of the current file for
   faster access.  */
static void LoadOffsets(axxPacFD fd)
{
    MemPtr mp;

    /* assumption: there is just one file being read */
    ASSERT_MSG("AIM6", currFileDesc == -1);

    axxPacSeek(LibRef, fd, 76, SEEK_SET);
    axxPacRead(LibRef, fd, &nrec, 2);
    moff = MemHandleNew(nrec * 8L);
    ASSERT_MSG("AIM3", moff != 0);

    mp = MemHandleLock(moff);
    ASSERT_MSG("AIM4", mp != 0);

    axxPacSeek(LibRef, fd, 78, SEEK_SET);
    axxPacRead(LibRef, fd, mp, nrec * 8L);
    MemHandleUnlock(moff);
    currFileDesc = fd;
    nrec--;
}
Ejemplo n.º 23
0
static void MusicTabInit() {
	ControlType *cck1P, *cck2P;
	ListType *list1P, *list2P, *list3P;
	FieldType *fld1P;
	MemHandle tempoH;
	Char *tempoP;

	cck1P = (ControlType *)GetObjectPtr(TabMusicMusicCheckbox);
	cck2P = (ControlType *)GetObjectPtr(TabMusicMultiMidiCheckbox);

	list1P = (ListType *)GetObjectPtr(TabMusicDriverList);
	list2P = (ListType *)GetObjectPtr(TabMusicRateList);
	list3P = (ListType *)GetObjectPtr(TabMusicQualityList);

	fld1P = (FieldType *)GetObjectPtr(TabMusicTempoField);

	CtlSetValue(cck1P, gameInfoP->musicInfo.sound.music);
	CtlSetValue(cck2P, gameInfoP->musicInfo.sound.multiMidi);

	if (gameInfoP->musicInfo.sound.drvMusic > 5)
		gameInfoP->musicInfo.sound.drvMusic = 0;


	LstSetSelection(list1P, gameInfoP->musicInfo.sound.drvMusic);
	LstSetTopItem(list1P, gameInfoP->musicInfo.sound.drvMusic);
	CtlSetLabel((ControlType *)GetObjectPtr(TabMusicDriverPopTrigger), LstGetSelectionText(list1P, LstGetSelection(list1P)));

	LstSetSelection(list2P, gameInfoP->musicInfo.sound.rate);
	LstSetTopItem(list2P, gameInfoP->musicInfo.sound.rate);
	CtlSetLabel((ControlType *)GetObjectPtr(TabMusicRatePopTrigger), LstGetSelectionText(list2P, LstGetSelection(list2P)));

	LstSetSelection(list3P, gameInfoP->fmQuality);
	CtlSetLabel((ControlType *)GetObjectPtr(TabMusicQualityPopTrigger), LstGetSelectionText(list3P, LstGetSelection(list3P)));

	tempoH = MemHandleNew(FldGetMaxChars(fld1P)+1);
	tempoP = (Char *)MemHandleLock(tempoH);
	StrIToA(tempoP, gameInfoP->musicInfo.sound.tempo);
	MemHandleUnlock(tempoH);
	FldSetTextHandle(fld1P, tempoH);
}
Ejemplo n.º 24
0
/* Set the silkscreen to contain the toolbar buttons */
void HanderaSetSilkScreen( void )
{
    UInt16          defaultSize;
    PenBtnListType* defaultButtons;
    UInt16          numNewButtons;
    UInt16          newSize;
    PenBtnListType* newButtons;

    /* currently only handeraSilkScreen supported */
    if ( GetDIAHardware() != DIA_HARDWARE_HANDERA )
        return;

    currentSilkStatus = ( GetDIAState() == DIA_STATE_MAX ? 
                                         HANDERA_SILK_UP : HANDERA_SILK_DOWN );

    /* if we already have defaultButtonsHandle stored in memory, there
       is no point in doing everything again, since its already done */
    if ( defaultButtonsHandle[ currentSilkStatus ] != NULL )
        return;

    defaultSize = SilkGetButtonListSize( (Boolean) currentSilkStatus );

    defaultButtonsHandle[ currentSilkStatus ] = MemHandleNew( defaultSize );
    defaultButtons = MemHandleLock( defaultButtonsHandle[ currentSilkStatus ] );
    SilkGetButtonList( defaultButtons, (Boolean) currentSilkStatus );

    numNewButtons = defaultButtons->numButtons + TOTAL_ICONS;
    newSize = sizeof( PenBtnListType ) +
        ( sizeof( PenBtnInfoType ) * ( numNewButtons - 1 ) );
    newButtons = SafeMemPtrNew( newSize );
    MemMove( newButtons, defaultButtons, defaultSize );

    GetButtons();
    DrawButtons();
    SetButtons( newButtons );
    SilkSetButtonList( newButtons, (Boolean) currentSilkStatus );

    MemPtrUnlock( defaultButtons );
    SafeMemPtrFree( newButtons );
}
Ejemplo n.º 25
0
/*!
 * \brief Set up the new file form.
 * \param form pointer to the form.
 * \return the form pointer.
 */
static FormPtr
cityNewSetup(FormPtr form)
{
	int i;
	MemHandle hText;
	MemPtr pText;

	FrmSetFocus(form, FrmGetObjectIndex(form, fieldID_newGameName));
	FrmSetControlValue(form, FrmGetObjectIndex(form, buttonID_Easy), 1);
	FrmSetControlValue(form, FrmGetObjectIndex(form, buttonID_dis_one), 1);

	for (i = 0; i < 2; i++) {
		hText = MemHandleNew(5);
		pText = MemHandleLock(hText);
		StrPrintF((char *)pText, "%u", 100);
		MemHandleUnlock(hText);
		FldSetTextHandle((FieldPtr)GetObjectPtr(form,
		    (UInt16)(fieldID_width + i)), hText);
	}

	return (form);
}
Ejemplo n.º 26
0
/**
 * FUNCTION: smCreate
 *
 * Creates a new memory block with name memName and size memSize.
 *
 * PRE-Condition:   OS does not know memName; memSize > 0
 *
 * POST-Condition:  memName exists with size memSize; 
 *                  memH refers to new memory block.
 *
 * IN:      memName
 *          Name of new memory block<BR>
 *          Palm version: Name is ignored
 * IN:      memSize
 *          Size of new memory block
 * 
 * OUT:     memH
 *          Handle to new memory block
 *
 * RETURN:  SML_ERR_OK, if O.K.
 *          SML_ERR_WRONG_USAGE, if memName is already known to the OS
 *          SML_ERR_INVALID_SIZE, if memSize <= 0
 *          SML_ERR_NOT_ENOUGH_SPACE, if available memory < memSize
 *
 * @see  smDestroy
 */
Ret_t smCreate (String_t memName, MemSize_t memSize, MemHandle_t *memH) {

  if ( memSize <= 0 ) {
    return SML_ERR_INVALID_SIZE;
  }

  // only one create call does make sense under Palm OS
  if ( smMemH != 0 ) {
    return SML_ERR_WRONG_USAGE;
  }

  // set new values
  smLocked = 0;
  smMemH = 1;
  *memH = smMemH;

  // create memory
  if ( (smPalmH=(Handle)MemHandleNew(memSize)) == 0 ) {
    return SML_ERR_NOT_ENOUGH_SPACE;
  }

  return SML_ERR_OK;
}
Ejemplo n.º 27
0
int AppendField( FieldPtr fld, CharPtr str, UInt len )
{
	Err err=0;
	CharPtr  s;
	VoidHand h;
	UInt prevlen;

	h=(VoidHand)FldGetTextHandle(fld);

	if(h==NULL) {
		h=MemHandleNew(len+1);
		if(h==NULL) return(-1);
		s=MemHandleLock(h);
		StrNCopy(s, str, len);
		s[len]=0;
		MemHandleUnlock(h);
	} else {
		prevlen=FldGetTextLength(fld);

		FldSetTextHandle(fld, NULL);

		if( MemHandleSize(h)<=(prevlen+len)) {
			err=MemHandleResize( h, prevlen+len+1 );
		}
		if( err!=0 ) return(-1);

		s=MemHandleLock(h);
		StrNCopy(s+prevlen, str, len);
		s[len+prevlen]=0;
		MemHandleUnlock(h);
	}

	FldSetTextHandle(fld, (Handle)h);
	/* FldDrawField(fld); */

	return( 0 );
}
Ejemplo n.º 28
0
/*
 * FUNCTION: PrvMakeGlobals
 *
 * DESCRIPTION: Create our library globals.
 *
 * PARAMETERS:
 *
 * refNum
 *		Library reference number returned by SysLibLoad() or SysLibFind().
 *
 * CALLED BY: internal
 *
 * RETURNS:
 *
 *		pointer to our *locked* library globals
 *		NULL if our globals	could not be created.
 */
FlickrGlobals* PrvMakeGlobals(UInt16 refNum)
{
    SysLibTblEntryType* libEntry = SysLibTblEntry(refNum);
    ErrFatalDisplayIf(libEntry == NULL, "invalid InfoMan Flickr Uploader refNum");

    /* Error check to make sure the globals don't already exist */
    ErrFatalDisplayIf(libEntry->globalsP != NULL, "InfoMan Flickr Uploader globals already exist");

    /* Allocate and initialize our library globals. */
    MemHandle handle = MemHandleNew(sizeof(FlickrGlobals));
    if (NULL == handle)
        return NULL;

    FlickrGlobals* globals = (FlickrGlobals*)MemHandleLock(handle);
    if (NULL == globals)
    {
        MemHandleFree(handle);
        return NULL;
    }

    Err err = globals->Init(refNum);
    if (errNone != err)
    {
        MemPtrUnlock(globals);
        MemHandleFree(handle);
        return NULL;
    }

    /* Set the owner of our globals memory chunk to "system" (zero), so it won't get
     * freed automatically by Memory Manager when the first application to call
     * FlickrOpen exits.  This is important if the library is going to stay open
     * between apps. */
    MemPtrSetOwner(globals, 0);
    libEntry->globalsP = (MemPtr)handle;
    return globals;
}
Ejemplo n.º 29
0
/*
** Initiates transfer mode.
*/
void StartXferMode(void) {
  FormType* frm = FrmGetActiveForm();
  FieldType* fld =  GetObjectPointer(frm, XferField);
  const UInt32 len = MemHandleSize(d.record_name);
  MemHandle textH = MemHandleNew(len);

  ASSERT(textH);

  FlushToBuffer();
  FrmSetMenu(frm, XferMenu);
  d.is_xfer_mode = true;
  ToggleButtonBar(frm, false);
  ResetDrawingAreaRectangle(p.formID == DiddleTForm, true);
  FrmUpdateForm(p.formID, 0);
  InitXferList();
  ToggleXferBar(frm, true);
  FrmSetFocus(frm, FrmGetObjectIndex(frm, XferField));

  /* Init field with record title */
  MemMove(MemHandleLock(textH), MemHandleLock(d.record_name), len);
  MemHandleUnlock(textH);
  MemHandleUnlock(d.record_name);
  FldSetTextHandle(fld, textH);
}
Ejemplo n.º 30
0
static void SetField(UInt16 formID, UInt16 fieldID, const char *str)
{
    FormPtr frm;
    FieldPtr fld;
    UInt16 obj;
    CharPtr p;
    VoidHand h;
	
    frm = FrmGetFormPtr(formID);
    obj = FrmGetObjectIndex(frm, fieldID);
    fld = (FieldPtr)FrmGetObjectPtr(frm, obj);
    h = (VoidHand)FldGetTextHandle(fld);
    if (h == NULL)
    {
	h = MemHandleNew (FldGetMaxChars(fld)+1);
	ErrFatalDisplayIf(!h, "No Memory");
    }
	
    p = (CharPtr)MemHandleLock(h);
    StrCopy(p, str);
    MemHandleUnlock(h);
	
    FldSetTextHandle(fld, (Handle)h);
}