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);
}
Beispiel #2
0
/***********************************************************************
 *
 * FUNCTION:    PrvCreateTimeZoneArray
 *
 * DESCRIPTION: Create the array of time zone entries from our string
 *		list, gtm offset list, and country list resources. Sort based on
 *		time zone name.
 *
 *	DOLATER kwk - we could save the time zone array we're creating here
 *		in memory, to avoid the performance hit of creating the array.
 *		On the other hand, then the list of names would need to stay
 *		locked down, unless we also copy those into the memory buffer,
 *		which means another 700+ bytes.
 *
 * PARAMETERS:
 *		timeZoneNames	<->	Ptr to returned handle to list of names.
 *		numTimeZones	<->	Ptr to count of number of time zones.
 *
 * RETURNED:
 *		Ptr to allocated array of time zone entry records.
 *
 * HISTORY:
 *		07/31/00	kwk	Created by Ken Krugler.
 *		08/23/00	kwk	Fixed bug where release ROMs caused ErrNonFatalDisplayIf
 *							to become a no-op, and thus the country and time zone
 *							offset list ptrs weren't skipping the count word.
 *
 ***********************************************************************/
static TimeZoneEntryType* PrvCreateTimeZoneArray(MemHandle* timeZoneNames, UInt16* numTimeZones)
{
	const Char* tzNamesP;
	TimeZoneEntryType* tzEntries;
	MemHandle offsetsH;
	MemHandle countriesH;
	UInt16* resP;
	Int16* gmtOffsetsP;
	UInt16* countriesP;
	UInt16 i;
	
	// Specify the number of items in the list, based on total # of items
	// in our time zone name list resource.
	*timeZoneNames = DmGetResource(strListRscType, TimeZoneNamesStringList);
	ErrNonFatalDisplayIf(*timeZoneNames == NULL, "No time zone names");
	tzNamesP = (const Char*)MemHandleLock(*timeZoneNames);
	
	// Skip over prefix string, then get the entry count.
	tzNamesP += StrLen(tzNamesP) + 1;
	*numTimeZones = *tzNamesP++;
	*numTimeZones = (*numTimeZones << 8) +  *tzNamesP++;
	
	// Allocate the array of time zone records.
	tzEntries = (TimeZoneEntryType*)MemPtrNew(*numTimeZones * sizeof(TimeZoneEntryType));
	ErrFatalDisplayIf(tzEntries == NULL, "Out of memory");
	
	// Find and lock down the gtm offset and country integer lists.
	offsetsH = DmGetResource(wrdListRscType, TimeZoneGMTOffsetsList);
	ErrNonFatalDisplayIf(offsetsH == NULL, "No time zone offsets");
	resP = (UInt16*)MemHandleLock(offsetsH);
	ErrNonFatalDisplayIf(*resP != *numTimeZones, "GMT offset count != name count");
	
	// Skip count at start of list.
	gmtOffsetsP = (Int16*)resP + 1;
	
	countriesH = DmGetResource(wrdListRscType, TimeZoneCountriesList);
	ErrNonFatalDisplayIf(countriesH == NULL, "No time zone countries");
	resP = (UInt16*)MemHandleLock(countriesH);
	ErrNonFatalDisplayIf(*resP != *numTimeZones, "Time zone country count != name count");
	
	// Skip count at start of list.
	countriesP = resP + 1;
	
	// Now loop to fill in all of the records.
	for (i = 0; i < *numTimeZones; i++)
	{
		tzEntries[i].tzName = tzNamesP;
		tzNamesP += StrLen(tzNamesP) + 1;
		tzEntries[i].tzOffset = gmtOffsetsP[i];
		tzEntries[i].tzCountry = (CountryType)countriesP[i];
	}
	
	MemHandleUnlock(offsetsH);
	MemHandleUnlock(countriesH);
	
	// Now sort the list, based on the time zone name.
	SysQSort(tzEntries, *numTimeZones, sizeof(TimeZoneEntryType), PrvCompareTimeZoneEntries, 0);
	
	return(tzEntries);
} // PrvCreateTimeZoneArray
Beispiel #3
0
/***********************************************************************
 *
 * FUNCTION:    PrvSetTimeField
 *
 * DESCRIPTION: Set the given field's text to show a time and day of week.
 *
 * PARAMETERS:  frm - a pointer to the form containing the field to set
 *					 timeFieldID - the ID of the field to set
 *					 timeHandle - the handle used for storing the text for this field
 *					 time - a pointer to the date and time to show in the field
 *					 drawField - whether to draw field after setting its text
 *
 * RETURNED:	 nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			peter	3/7/00	Initial Revision
 *
 ***********************************************************************/
static void PrvSetTimeField(FormType * frm, UInt16 timeFieldID, MemHandle timeHandle,
	DateTimeType *time, Boolean drawField)
{
	FieldType * timeFieldP;
	Char * timeString, * timeZoneDOWFormatString, * currentDOWString;
	MemHandle resHandle;
	TimeFormatType timeFormat;			// Format to display time in

	timeFormat = (TimeFormatType)PrefGetPreference(prefTimeFormat);
	
	timeString = MemHandleLock(timeHandle);
	TimeToAscii(time->hour, time->minute, timeFormat, timeString);
	currentDOWString = timeString + StrLen(timeString);
	currentDOWString[0] = ' ';
	currentDOWString++;

	resHandle = DmGetResource(strRsc, DOWformatString);
	ErrNonFatalDisplayIf(resHandle == NULL, "Missing string resource");
	timeZoneDOWFormatString = MemHandleLock(resHandle);
	DateTemplateToAscii(timeZoneDOWFormatString, time->month, time->day, time->year,
		currentDOWString, dowLongDateStrLength);
	MemHandleUnlock(resHandle);
	
	MemHandleUnlock(timeHandle);
	timeFieldP = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, timeFieldID));
	FldSetTextHandle(timeFieldP, timeHandle);
	
	if (drawField)
		FldDrawField(timeFieldP);
}
Beispiel #4
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);
  }
}
Beispiel #5
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);
}
/*
** 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);
}
Beispiel #7
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);
}
Beispiel #8
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;
}
Beispiel #9
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;
}
Beispiel #10
0
/***********************************************************************
 *
 * FUNCTION: ZDicFontInit
 *
 * DESCRIPTION: Initial all font resource
 *
 * PARAMETERS:	nothing
 *
 * RETURN:		errNone if success else fail.
 *
 * REVISION HISTORY:
 *		Name			Date		Description
 *		----			----		-----------
 *		ZhongYuanHuan	14/Aug/04	Initial Revision 
 *				
 ***********************************************************************/
Err ZDicFontInit ( UInt16 refNum, ZDicFontType* fontP, Boolean bUseSysFont )
{
	#pragma unused(refNum)
	
	UInt32  version;	
	Err     err;
	
	MemSet ( fontP, sizeof ( ZDicFontType ), 0 );
	fontP->smallFontID = stdFont;
	fontP->largeFontID = largeFont;
	
	if ( bUseSysFont ) return errNone;
	
	fontP->fontLibP = DmOpenDatabaseByTypeCreator ( ZDicFontTypeID, ZDicFontCreatorID, dmModeReadOnly );
	
	if ( fontP->fontLibP == 0 )
	{
	    err = DmGetLastErr ();
	    return err;
	}
	
	// Load the phonic font resource and assign it a font ID.
	err = FtrGet(sysFtrCreator, sysFtrNumWinVersion, &version);
	if (!err && version >= 4 )
	{
		// the screen is double density so use double density of phonetic font.
		fontP->phonicSmallFontH = DmGetResource('nfnt', PhonicSmallFontHight);
		fontP->phonicLargeFontH = DmGetResource('nfnt', PhonicLargeFontHight);		
	}
		
	if (fontP->phonicSmallFontH == NULL || fontP->phonicLargeFontH == NULL)
	{
		if (fontP->phonicSmallFontH != NULL) DmReleaseResource(fontP->phonicSmallFontH);
		if (fontP->phonicLargeFontH != NULL) DmReleaseResource(fontP->phonicLargeFontH);
		
		// the screen is low desity so use low density of phonetic font.
		fontP->phonicSmallFontH = DmGetResource(fontRscType, PhonicSmallFontLow);
		fontP->phonicLargeFontH = DmGetResource(fontRscType, PhonicLargeFontLow);		
	}
		
	fontP->phonicSmallFontP = (FontType *)MemHandleLock(fontP->phonicSmallFontH);
	fontP->phonicLargeFontP = (FontType *)MemHandleLock(fontP->phonicLargeFontH);
	err = FntDefineFont(kPHONIC_SMALL_FONT_ID, fontP->phonicSmallFontP);
	err = FntDefineFont(kPHONIC_LARGE_FONT_ID, fontP->phonicLargeFontP);
	fontP->smallFontID = kPHONIC_SMALL_FONT_ID;
	fontP->largeFontID = kPHONIC_LARGE_FONT_ID;		

	return errNone;
}
Beispiel #11
0
/**************************************************************************
 * Function: getSystemFromIndex
 * Description: based upon a system database index, this will locate the
 * system for that index, unpack and decrypt it and initialize s
 * ************************************************************************/ 
void getSystemFromIndex (DmOpenRef SystemDB, md_hash * SysPass, UInt16 index, MemHandle tmp, System * s) {
	MemHandle rec = DmQueryRecord (SystemDB, index);
	if (rec) {
		MemPtr scratch, buff = MemHandleLock (rec);
		
			/*	resize the buffer */
		if (MemHandleResize (tmp, MemPtrSize (buff)) == 0) {
			scratch = MemHandleLock (tmp);
			
			/*	unpack and decrypt the account */
			UnpackSystem (s, buff, scratch, SysPass, MemHandleSize (rec), true); 
		}
		MemHandleUnlock (rec);
	}
}
Beispiel #12
0
static void ModSetStack(UInt32 newSize, UInt16 cardNo, LocalID dbID) {
	DmOpenRef dbRef = DmOpenDatabase(cardNo, dbID, dmModeReadWrite);

	if (dbRef) {
		MemHandle pref = DmGetResource('pref',0);
		UInt32 size = 0;
		
		if (pref) {
			SysAppPrefsType *data = (SysAppPrefsType *)MemHandleLock(pref);
			size = data->stackSize;

			if (newSize) {
				SysAppPrefsType newData;
				MemMove(&newData, data, sizeof(SysAppPrefsType));
				newData.stackSize = newSize;
				DmWrite(data, 0, &newData, sizeof(SysAppPrefsType));
			}

			MemPtrUnlock(data);
			DmReleaseResource(pref);
		}

		DmCloseDatabase(dbRef);
	}
}
Beispiel #13
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;
}
Beispiel #14
0
/*----------------------------------------CIRexxApp::copyScriptFromFindResult-+
|                                                                             |
+----------------------------------------------------------------------------*/
void CIRexxApp::copyScriptFromFindResult(GoToParamsPtr pGoToParams)
{
   Err err;
   LocalID dbID;
   UInt16 cardNo = 0;
   DmOpenRef dbP;
   DmSearchStateType searchState;
   MemHandle hRecord;

   if ((err = DmGetNextDatabaseByTypeCreator(
       true, &searchState, 'data', CREATORID, true, &cardNo, &dbID)) != errNone) {
      return;
   }
   if ((dbP = DmOpenDatabase(cardNo, dbID, dmModeReadOnly)) == 0) {
      return;
   }
   if (!(hRecord = DmQueryRecord(dbP, pGoToParams->recordNum))) {
      DmCloseDatabase(dbP);
      return;
   }
   Char * p = (char *)MemHandleLock(hRecord);
   UInt32 size = MemHandleSize(hRecord);
   if (p[size - 1] == '\0') { --size; }
   emptyScript();
   appendScript(p, size);
   MemHandleUnlock(hRecord);
   DmCloseDatabase(dbP);
   return;
}
Beispiel #15
0
static void MainFormLookupClipboard(AppContext* appContext)
{
    char          txtBuf[MAX_WORD_IN_CLIP_LEN+1];
    MemHandle     clipItemHandle;
    UInt16        clipTxtLen;

    clipItemHandle = ClipboardGetItem(clipboardText, &clipTxtLen);

    if (!clipItemHandle || 0==clipTxtLen)
        return;

    const char* clipTxt=static_cast<const char*>(MemHandleLock(clipItemHandle));
    if (!clipTxt)
    {
        MemHandleUnlock( clipItemHandle );
        return;
    }

    SafeStrNCopy(txtBuf, sizeof(txtBuf), clipTxt, clipTxtLen);
    MemHandleUnlock(clipItemHandle);

    StringExtractWord(txtBuf);

    StartWordLookup(appContext, static_cast<const char*>(txtBuf));
}
Beispiel #16
0
/* Return the number of external bookmarks */
UInt16 CountExtBookmarks( void )
{
    UInt16      entries;
    MemHandle   handle;
    UInt8*      bookmarkPtr;

    handle          = NULL;
    bookmarkPtr     = NULL;
    entries         = 0;

    ErrTry {
        handle  = ReturnRecordHandle( EXTERNAL_BOOKMARKS_ID );
    }
    ErrCatch( UNUSED_PARAM( err ) ) {
        FreeRecordHandle( &handle );
        return 0;
    } ErrEndCatch

    if ( handle == NULL )
        return NO_BOOKMARKS;

    bookmarkPtr     = MemHandleLock( handle );
    bookmarkPtr    += sizeof( Header );
    entries         = GET_EXTFIRSTFIELD( bookmarkPtr );

    MemHandleUnlock( handle );
    FreeRecordHandle( &handle );
    return entries;
}
Beispiel #17
0
/* Restore data for external bookmark, return the record ID or
   NO_RECORD if it doesn't exist */
UInt16 GotoExtBookmark
    (
    UInt16 index     /* index in bookmarks list */
    )
{

    UInt16      uid;
    UInt16      offset;
    MemHandle   handle;
    UInt8*      bookmarkPtr;

    handle          = NULL;
    bookmarkPtr     = NULL;
    offset          = 0;

    handle  = ReturnRecordHandle( EXTERNAL_BOOKMARKS_ID );

    if ( handle == NULL )
        return NO_RECORD;

    bookmarkPtr     = MemHandleLock( handle );
    bookmarkPtr    += sizeof( Header );
    bookmarkPtr    += GET_EXTSECONDFIELD( bookmarkPtr ) - sizeof( Header );
    bookmarkPtr    += index * 4;

    uid             = GET_EXTFIRSTFIELD( bookmarkPtr );
    offset          = GET_EXTSECONDFIELD( bookmarkPtr );

    if ( IsFullscreenformActive() )
        FsFrmGotoForm ( GetMainFormId() );
    JumpToRecord( uid, offset, NO_OFFSET );
    MemHandleUnlock( handle );

    return uid;
}
Beispiel #18
0
/* Reset the verticalOffset fields in all the bookmarks */
void ResetBookmarkVerticalOffsets( void )
{
    UInt8*          bookmarkPtr;
    MemHandle       handle;
    UInt16          offset;
    Int16           entries;

    handle = ReturnMetaHandle( INTERNAL_BOOKMARKS_ID, NO_PARAGRAPHS );
    if ( handle == NULL )
        return;

    bookmarkPtr  = MemHandleLock( handle );
    offset       = GET_OFFSET( bookmarkPtr );
    entries      = GET_ENTRIES( bookmarkPtr );

    while ( entries-- ) {
        YOffset verticalOffset;
        verticalOffset = NO_VERTICAL_OFFSET;
        DmWrite( bookmarkPtr, offset + OFFSETOF( BookmarkData, verticalOffset ),
            &verticalOffset, sizeof( YOffset ) );
        offset += sizeof( BookmarkData );
    }

    MemHandleUnlock( handle );
}
Beispiel #19
0
/* Populate array with external bookmarks, return number of bookmarks */
static UInt16 InitExtBookmarkList
    (
    Char** nameList,
    UInt16 offset     /* where to start in the list */
    )
{
    UInt16      entries;
    UInt16      i;
    MemHandle   handle;
    UInt8*      bookmarkPtr;

    handle          = NULL;
    bookmarkPtr     = NULL;

    handle  = ReturnRecordHandle( EXTERNAL_BOOKMARKS_ID );

    if ( handle == NULL )
        return NO_BOOKMARKS;

    bookmarkPtr     = MemHandleLock( handle );
    bookmarkPtr    += sizeof( Header );
    entries         = GET_EXTFIRSTFIELD( bookmarkPtr );
    bookmarkPtr    += 4;

    for ( i = offset; i < entries + offset; i++ ) {
        nameList[ i ]   = bookmarkPtr;
        bookmarkPtr    += StrLen( bookmarkPtr ) + 1;
    }

    MemHandleUnlock( handle );
    FreeRecordHandle( &handle );

    return entries;
}
Beispiel #20
0
/* remove an item from the list and move te rest one position up */
static Int16 RemoveFileRec(FileRef fr)
{
    Int16 i;
    Err ret;
    file_rec_t* axxFileList;
    axxPacFD FileDesc;

    axxFileList = MemHandleLock(axxFileListHandle);
    i = GetFilePos((Int16)fr);
    if (i == -1)
        return -1;
    
    FileDesc=axxFileList[i].fd;
    for (; i < axxFLSize - 1; i++) {
        MemMove (&axxFileList[i], &axxFileList[i + 1],sizeof(axxFileList));
    }    
    axxFLSize--;
    ret = MemHandleResize(axxFileListHandle, sizeof(file_rec_t) * axxFLSize);
    ret = MemHandleUnlock(axxFileListHandle);
    /* Check if the current file is the one removed from the list */
    if ((currFileDesc != -1) && ( FileDesc== currFileDesc)) {
        /* the cache of offsets is no longer valid if this file
           was closed */
        currFileDesc = -1;
        MemHandleFree(moff);
    }
    return 0;
}
Beispiel #21
0
/************************************************************
 *
 *  FUNCTION: ApptNewRecord
 *
 *  DESCRIPTION: Create a new packed record in sorted position
 *
 *  PARAMETERS: database pointer
 *              database record
 *
 *  RETURNS: ##0 if successful, error code if not
 *
 *  CREATED: 1/25/95 
 *
 *  BY: Roger Flores
 *
 *************************************************************/
Err ApptNewRecord(DmOpenRef dbP, ApptDBRecordPtr r, UInt16 *index) {
    MemHandle recordH;
    ApptPackedDBRecordPtr recordP;
    UInt16                    newIndex;
    Err err;


    // Make a new chunk with the correct size.
    recordH = DmNewHandle (dbP, (UInt32) ApptPackedSize(r));
    if (recordH == NULL)
        return dmErrMemError;

    recordP = MemHandleLock (recordH);

    // Copy the data from the unpacked record to the packed one.
    ApptPack (r, recordP);

    newIndex = ApptFindSortPosition(dbP, recordP);

    MemPtrUnlock (recordP);

    // 4) attach in place
    err = DmAttachRecord(dbP, &newIndex, recordH, 0);
    if (err)
        MemHandleFree(recordH);
    else
        *index = newIndex;

    return err;
}
Beispiel #22
0
static void LoadPreferencesNoahPro(AppContext* appContext)
{
    DmOpenRef    db;
    UInt         recNo;
    void *       recData;
    MemHandle    recHandle;
    UInt         recsCount;
    Boolean      fRecFound = false;

    appContext->fFirstRun = true;
    db = DmOpenDatabaseByTypeCreator(NOAH_PREF_TYPE, NOAH_PRO_CREATOR, dmModeReadWrite);
    if (!db) return;
    recsCount = DmNumRecords(db);
    for (recNo = 0; (recNo < recsCount) && !fRecFound; recNo++)
    {
        recHandle = DmQueryRecord(db, recNo);
        recData = MemHandleLock(recHandle);
        if ( (MemHandleSize(recHandle)>=PREF_REC_MIN_SIZE) && IsValidPrefRecord( recData ) )
        {
            LogG( "LoadPreferencesNoahPro(), found prefs record" );
            fRecFound = true;
            appContext->fFirstRun = false;
            DeserializePreferencesNoahPro(appContext, (unsigned char*)recData, MemHandleSize(recHandle) );
        }
        MemPtrUnlock(recData);
    }
    DmCloseDatabase(db);
}
Beispiel #23
0
/*
** Convert between absolute and versioned indices.
*/
static Int16 PlugIndex(Int16 index, Boolean absoluteToVersioned) {
  SysDBListItemType *pluglistP = NULL;
  Int16 a_index = 0;
  Int16 v_index = 0;
  Int16 ret = 0;

  if (d.xfer.pluglistH) {
    pluglistP = MemHandleLock(d.xfer.pluglistH);

    for (; a_index < d.xfer.num_plugs; a_index++) {
      if ((pluglistP[a_index].version)&(IBVERSION_ORIG|IBVERSION_PICTURE)) {
	if (absoluteToVersioned && index == a_index) 
	  ret = v_index;
	
	if (!absoluteToVersioned && index == v_index)
	  ret = a_index;

	v_index++;
      }
    }

    MemHandleUnlock(d.xfer.pluglistH);

    if (!index && absoluteToVersioned)
      ret = v_index;
  }
  
  return ret;
}
Beispiel #24
0
/*
** GetCurrentXferAppListIndex - returns -1 for no current app
*/
static Int16 GetCurrentXferAppListIndex(void) {
  Int16 ret = -1;
  Int16 i = 0;
  SysDBListItemType *pluglistP = NULL;

  if (!d.xfer.pluglistH) {
    d.xfer.num_plugs = 0;
  } else {
    pluglistP = MemHandleLock(d.xfer.pluglistH);

    for (; i < d.xfer.num_plugs; i++) {
      /* Search for the currently selected plugin */
      if ((pluglistP[i].creator == p.xfer_current_plug) &&
	  (pluglistP[i].version&(IBVERSION_ORIG|IBVERSION_PICTURE))) {
	ret = i;
      }
    }

    if (ret == -1)
      p.xfer_current_plug = 0;
    
    /* Clean up */
    MemHandleUnlock(d.xfer.pluglistH);
  }
  
  return ret;
}
Beispiel #25
0
UInt16
CourseNewID(DmOpenRef cats, UInt16 category)
{
  Err err=errNone;
  MemHandle m;
  UInt16 index=0,lastid=0;

  err = DmSeekRecordInCategory(cats, &index, 0, dmSeekForward, category);
  if (err != errNone) return 0;

  while ((m = DmQueryNextInCategory(cats, &index, category))) {
    Char *s = MemHandleLock(m);
    if (s[0] == TYPE_COURSE) {
      CourseDBRecord c;
      UnpackCourse(&c, s);

      if (c.id > lastid) lastid = c.id;

    }
    index += 1;
    MemHandleUnlock(m);
  }

  // lastid contains the last existing ID here, so return lastid+1 to get the first
  // non-existing one
  return lastid+1;
}
Beispiel #26
0
/* Get current selected note and fill out note properties elements.
   If selected == -1, clear and disable this fields. */
static void
UpdateNoteProperties()
{
  FormPtr frm = FrmGetActiveForm ();

  if (notelist.selected == -1) {
    FrmHideObject(frm, FrmGetObjectIndex(frm, ID_EditorDuration));
    FrmHideObject(frm, FrmGetObjectIndex(frm, ID_EditorVelocity));
    FrmHideObject(frm, FrmGetObjectIndex(frm, ID_EditorPause));
  }
  else {
    NotePtr notes = MemHandleLock(notelist.bufH);
    NotePtr note = notes + notelist.selected;

    ErrFatalDisplayIf(notelist.selected > notelist.num, "Invalid note index!");

    SetFieldTextFromNumber(ID_EditorDuration, note->dur);
    SetFieldTextFromNumber(ID_EditorVelocity, note->vel);
    SetFieldTextFromNumber(ID_EditorPause, note->pause);

    FrmShowObject(frm, FrmGetObjectIndex(frm, ID_EditorDuration));
    FrmShowObject(frm, FrmGetObjectIndex(frm, ID_EditorVelocity));
    FrmShowObject(frm, FrmGetObjectIndex(frm, ID_EditorPause));

    MemPtrUnlock(notes);
  }
}
Beispiel #27
0
static void
CourseNameCacheLoad(CacheID id, UInt16 *ids, Char **values, UInt16 numItems)
{
  MemHandle m; 
  UInt16 index=0, i=0;
  
  while ((i < numItems) && ((m = DmQueryNextInCategory(DatabaseGetRef(), &index, DatabaseGetCat())) != NULL)) {
    Char *s=(Char *)MemHandleLock(m);
    if (s[0] == TYPE_COURSE) {
      CourseDBRecord c;
      Char *tempString;

      UnpackCourse(&c, s);
      
      tempString=(Char *)MemPtrNew(StrLen(c.name)+1);
      MemSet(tempString, MemPtrSize(tempString), 0);
      StrCopy(tempString, c.name);

      ids[i] = c.id;
      values[i] = tempString;
      i += 1;
    }
    MemHandleUnlock(m);
    index += 1;
  }
}
Beispiel #28
0
/* The returned handle must be released via CloseRecord(). */
void UpdateDocument
    (
    DocumentInfo*   docInfo,
    Char*           volumeLabel,
    UInt16          index,
    MemHandle*      handleP
    )
    /* THROWS */
{
    DocumentData*   dataPtr;
    UInt16          infoSize;
    UInt16          dataSize;

    infoSize = sizeof *dataPtr;
    if ( docInfo->location == RAM )
        dataSize = 0;
    else
        dataSize = StrLen( docInfo->filename ) + StrLen( volumeLabel ) + 2;

    *handleP = ResizeRecord( plkrDocList, index, infoSize + dataSize );
    dataPtr  = MemHandleLock( *handleP );

    DmWrite( dataPtr, 0, docInfo, infoSize );
    if ( docInfo->location != RAM ) {
        DmWrite( dataPtr, infoSize, docInfo->filename,
            StrLen( docInfo->filename ) + 1 );
        DmWrite( dataPtr, infoSize + StrLen( docInfo->filename ) + 1,
            volumeLabel, StrLen( volumeLabel ) + 1 );
    }
    
    MarkRecordDirty( *handleP );
    MemHandleUnlock( *handleP );
}
Beispiel #29
0
/* Delete a bookmark for a given word in a bookmark database indicated by sortType */
static Err DeleteBookmarkInDB(AppContext* appContext, BookmarkSortType sortType, char *word)
{
    Err          err;
    UInt16       recsCount, i;
    MemHandle    recHandle;
    char *       wordInRecord;

    err = OpenBookmarksDB(appContext, sortType);
    if ( errNone != err )
        return err;

    recsCount = DmNumRecords(appContext->bookmarksDb);
    for (i = 0; i < recsCount; i++)
    {
        recHandle = DmQueryRecord(appContext->bookmarksDb, i);
        if (!recHandle)
        {
            err = DmGetLastErr();
            goto OnError;
        }

        wordInRecord = (char*)MemHandleLock(recHandle);
        Assert(wordInRecord);
        if (0 == StrCompare(wordInRecord, word))
        {
            MemHandleUnlock(recHandle);
            DmRemoveRecord(appContext->bookmarksDb, i);
            break;
        }
        MemHandleUnlock(recHandle);
    }
OnError:
    CloseBookmarksDB(appContext);
    return err;
}
Beispiel #30
0
/* Add Plucker document */
void AddDocument
    (
    DocumentInfo*   docInfo,
    Char*           volumeLabel
    )
    /* THROWS */
{
    MemHandle   handle;
    UInt8*      dataPtr;
    UInt16      infoSize;
    UInt16      dataSize;
    UInt16      dbIndex;

    infoSize = sizeof *docInfo - 2 * sizeof( UInt16) - sizeof( Char* );
    if ( docInfo->location == RAM )
        dataSize = 0;
    else
        dataSize = StrLen( docInfo->filename ) + StrLen( volumeLabel ) + 2;

    dbIndex = dmMaxRecordIndex;
    handle  = NewRecord( plkrDocList, &dbIndex, infoSize + dataSize );
    THROW_IF( handle == NULL, DmGetLastErr() );
    dataPtr = MemHandleLock( handle );
    DmWrite( dataPtr, 0, docInfo, infoSize );
    if ( docInfo->location != RAM ) {
        DmWrite( dataPtr, infoSize, docInfo->filename,
            StrLen( docInfo->filename ) + 1 );
        DmWrite( dataPtr, infoSize + StrLen( docInfo->filename ) + 1,
            volumeLabel, StrLen( volumeLabel ) + 1 );
    }
    MemHandleUnlock( handle );
    CloseRecord( handle, true );
}