Пример #1
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 );
}
Пример #2
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 );
}
Пример #3
0
static void SelectUsingFingerAddr()
{
	FormPtr form = FrmGetActiveForm();
	if (FormIsNot(form, FormReply)) return;
	
	UInt16 mode = g_ComposeMode;
	
	char* pszTo = FldGetTextPtr((FieldPtr) GetObjectPtr(form, FieldTo));
	char* pszCompose = FldGetTextPtr((FieldPtr) GetObjectPtr(form, FieldCompose));
	char* pszReference = FldGetTextPtr((FieldPtr) GetObjectPtr(form, FieldReference));
	
	UInt16 lenTo = 0;
	if (pszTo) lenTo = StrLen(pszTo);
	
	UInt16 lenCompose = 0;
	if (pszCompose) lenCompose = StrLen(pszCompose);
	
	UInt16 lenReference = 0;
	if (pszReference) lenReference = StrLen(pszReference);
	
	UInt16 size = sizeof(UInt16) + lenTo + 1 + lenCompose + 1 + lenReference + 1;

	char* ftrBuf = NULL;
	Err err = FtrPtrNew(appFileCreator, (UInt16) FEATURE_FINGER_ADDR, size, (void**) &ftrBuf);
	if (err) return;
	DmSet(ftrBuf, 0, size, 0);
	
	UInt16 offset = 0;
	
	DmWrite(ftrBuf, offset, &mode, sizeof(UInt16));
	offset += sizeof(UInt16);
	
	if (lenTo) {
		DmWrite(ftrBuf, offset, pszTo, lenTo);
	}
	offset += lenTo + 1;
	
	if (lenCompose) {
		DmWrite(ftrBuf, offset, pszCompose, lenCompose);
	}
	offset += lenCompose + 1;
	
	if (lenReference) {
		DmWrite(ftrBuf, offset, pszReference, lenReference);
	}
	
	FasRequestSearch(appFileCreator);
}
Пример #4
0
void Memo_WriteLen(char* cp, UInt len) {
	Long newsize, newalloc;
	Ptr  RecPointer;

	if (!s_pMemoDb || !cp)
		return;
	newsize = s_iOffset + len + 1;

	if (newsize > s_iAllocSize) {
		// If we need more room, round up to next multiple of diAllocSize.
		// This idiom only works if diAllocSize is a power of 2.
		newalloc = (newsize + diAllocSize-1) & ~(diAllocSize-1);
		if (newalloc > diMaxSize) {	// If we are nearly maxed out,
			newalloc = diMaxSize; // use what we've got.
			if (newsize > diMaxSize) // If we are maxed out, give it up.
				return;
		}
		if (s_RecHandle)
			(void) DmReleaseRecord(s_pMemoDb, s_iRecNum, true);
		s_RecHandle = DmResizeRecord(s_pMemoDb, s_iRecNum, newalloc);
		if (s_RecHandle)
			s_iAllocSize = newalloc;
	}
	if (s_RecHandle) {
		if ((RecPointer = MemHandleLock(s_RecHandle))) {
			// Write extra char at end, often it will be null termination...
			if (!DmWrite(RecPointer, s_iOffset, cp, len+1))	// if no error...
				s_iOffset += len;
			(void) MemPtrUnlock(RecPointer);
		}
	}
}
Пример #5
0
/* Save history in session record */
void SaveHistory
    (
    History* recordPtr /* pointer to session record */
    )
{
    DmWrite( recordPtr, 0, &history, sizeof( History ) );
}
Пример #6
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 );
}
Пример #7
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);
	}
}
Пример #8
0
/* Rename document name in document list */
void UpdateDocumentName
    (
    UInt16      index,  /* record index */
    const Char* name,   /* new document name */
    const Char* filename  /* new filename */
    )
    /* THROWS */
{
    MemHandle       handle;
    DocumentData*   handlePtr;

    THROW_IF( name == NULL || *name == '\0', errNoDocumentName );

    handle = OpenRecord( plkrDocList, index );
    THROW_IF( handle == NULL, DmGetLastErr() );

    handlePtr = MemHandleLock( handle );
    DmWrite( handlePtr, OFFSETOF( DocumentData, name ),
        name, StrLen( name ) + 1 );
    if ( handlePtr->location != RAM ) {
        DocumentData*   dataPtr;
        UInt16          infoSize;
        UInt16          dataSize;
        Char            volumeLabel[ LABEL_LEN ];
        UInt16          fileLength;
        UInt16          volumeLabelLength;

        fileLength          = StrLen( handlePtr->data ) + 1;
        volumeLabelLength   = StrLen( handlePtr->data + fileLength ) + 1;
        StrNCopy( volumeLabel, handlePtr->data + fileLength,
            volumeLabelLength );

        MemHandleUnlock( handle );

        infoSize = sizeof *dataPtr;
        dataSize = StrLen( filename ) + StrLen( volumeLabel ) + 2;

        handle  = ResizeRecord( plkrDocList, index, infoSize + dataSize );
        dataPtr = MemHandleLock( handle );
        DmWrite( dataPtr, infoSize, filename, StrLen( filename ) + 1 );
        DmWrite( dataPtr, infoSize + StrLen( filename ) + 1, volumeLabel,
            StrLen( volumeLabel ) + 1 );
    }
    MemHandleUnlock( handle );
    CloseRecord( handle, true );
    DmInsertionSort( plkrDocList, CompareDocumentNames, 0 );
}
Пример #9
0
void writeRecord(MemPtr ptr, UInt32 size, UInt16 index, UInt16 dbID) {
	Err e;
	
	MemHandle recordH = DmNewRecord(dbP[dbID], &index, size);
	MemPtr save = MemHandleLock(recordH);
	e = DmWrite(save, 0, ptr, size);
	MemHandleUnlock(recordH);
	DmReleaseRecord (dbP[dbID], index, 0);
}
Пример #10
0
/************************************************************
 *
 *  FUNCTION: ApptPack
 *
 *  DESCRIPTION: Pack an ApptDBRecordType
 *
 *  PARAMETERS: database record
 *
 *  RETURNS: the ApptPackedDBRecord is packed
 *
 *  CREATED: 1/25/95 
 *
 *  BY: Roger Flores
 *
 *************************************************************/
static void ApptPack(ApptDBRecordPtr s, ApptPackedDBRecordPtr d) {
    ApptDBRecordFlags   flags;
    UInt16    size;
    UInt32    offset = 0;


    *(unsigned char *)&flags = 0;           // clear the flags


    // copy the ApptDateTimeType
    //c = (char *) d;
    offset = 0;
    DmWrite(d, offset, s->when, sizeof(ApptDateTimeType));
    offset += sizeof (ApptDateTimeType) + sizeof (ApptDBRecordFlags);


    if (s->alarm != NULL) {
        DmWrite(d, offset, s->alarm, sizeof(AlarmInfoType));
        offset += sizeof (AlarmInfoType);
        flags.alarm = 1;
    }


    if (s->repeat != NULL) {
        DmWrite(d, offset, s->repeat, sizeof(RepeatInfoType));
        offset += sizeof (RepeatInfoType);
        flags.repeat = 1;
    }


    if (s->exceptions != NULL) {
        size = sizeof (UInt16) +
            (s->exceptions->numExceptions * sizeof (DateType));
        DmWrite(d, offset, s->exceptions, size);
        offset += size;
        flags.exceptions = 1;
    }


    if (s->description != NULL) {
        size = StrLen(s->description) + 1;
        DmWrite(d, offset, s->description, size);
        offset += size;
        flags.description = 1;
    }



    if (s->note != NULL) {
        size = StrLen(s->note) + 1;
        DmWrite(d, offset, s->note, size);
        offset += size;
        flags.note = 1;
    }

    DmWrite(d, sizeof(ApptDateTimeType), &flags, sizeof(flags));
}
Пример #11
0
/* Create new item in app database */
static UInt16
DoTheBoogie(KleenexPtr kleenexP, DmOpenRef dbR, UInt16 *index)
{
    MemHandle hnd;
    MemPtr recordP;
    UInt16 strLen;

    *index = dmMaxRecordIndex;
    if (!(hnd = DmNewRecord(dbR, index, 3360)))
        return (1);
    recordP = MemHandleLock(hnd);
    DmWrite(recordP, 0, kleenexP->data, 3200);
    DmSet(recordP, 3200, 160, 0);
    if ((strLen = StrLen(kleenexP->text)) > 31)
        strLen = 31;
    DmWrite(recordP, 3200, kleenexP->text, strLen);
    MemHandleUnlock(hnd);
    DmReleaseRecord(dbR, *index, true);

    return (errNone);
}
Пример #12
0
void PackHappyDays(HappyDays *hd, void* recordP)
{
    UInt16 offset = 0;

    DmWrite(recordP, offset, (Char*)&hd->addrRecordNum, sizeof(hd->addrRecordNum));
    offset += sizeof(hd->addrRecordNum);
    DmWrite(recordP, offset, (Char*)&hd->date, sizeof(hd->date));
    offset += sizeof(hd->date);
    DmWrite(recordP, offset, (Char*)&hd->flag, sizeof(hd->flag));
    offset += sizeof(hd->flag);  
    DmWrite(recordP, offset, (Char*)&hd->nth, sizeof(hd->nth));
    offset += sizeof(hd->nth);      // for corealign

    if (hd->name1) {
        DmStrCopy(recordP, offset, (Char*)hd->name1);
        offset += StrLen(hd->name1) +1;
    }
    else {
        DmStrCopy(recordP, offset, "\0");
        offset += 1;
    }
    if (hd->name2) {
        DmStrCopy(recordP, offset, (Char*)hd->name2);
        offset += StrLen(hd->name2) +1;
    }
    else {
        DmStrCopy(recordP, offset,"\0");
        offset += 1;
    }

    if (hd->custom) {
        DmStrCopy(recordP, offset, (Char*)hd->custom);
        offset += StrLen(hd->custom) +1;
    }
    else {
        DmStrCopy(recordP, offset,"\0");
        offset += 1;
    }
}
Пример #13
0
/********************************************************************
 * Function: addRecord
 * Description:  function responsible for writing a packed System record
 * to the database. 
 * ******************************************************************/ 
void writeRecord (MemPtr record, MemHandle recordDBrec) {
	UInt16 length = 0, offset = 0;
	Char *ch;
	
	/* get length of the system buffer */
	length = MemPtrSize (record);
	
	/* re-size and write. */
	if (MemHandleResize (recordDBrec, length) == 0) {
		ch = MemHandleLock (recordDBrec);
		DmWrite (ch, offset, record, length);
		MemHandleUnlock (recordDBrec);
	}
}
Пример #14
0
/* Restore data for current record from history */
static void RestoreData( void )
{
    MetaRecord* meta;
    MemHandle   handle;
    UInt16      recordId;

    recordId    = history.records[ history.currentRecord ].recordId;
    handle      = GetMetaHandle( recordId, false );
    meta        = MemHandleLock( handle );

    DmWrite( meta, OFFSETOF( MetaRecord, verticalOffset ),
        &history.records[ history.currentRecord ],
        sizeof( HistoryData ) - sizeof( Int16 ) );

    MemHandleUnlock( handle );
    CloseRecord( handle, true );
}
Пример #15
0
// Write the header
void WriteHeader(void) {
  MemHandle headerMH = NULL;
  MemPtr headerMP = NULL;

  headerMH = DmGetRecord(JMPalmPrefs, 0);

  if (headerMH != NULL)
    headerMP = MemHandleLock(headerMH);

  // write new data
  if (headerMH != NULL) {
    //hd.record_count = record_count;
    DmWrite(headerMP, 0, &hd, sizeof(hd));
    MemHandleUnlock(headerMH);
    DmReleaseRecord(JMPalmPrefs, 0, true);
  }
}
Пример #16
0
/* Restore data for current bookmark, return the record ID or if
   there are no bookmarks NO_RECORD */
UInt16 RestoreBookmarkData
    (
    UInt16 index     /* index in bookmarks list */
    )
{
    MetaRecord*     meta;
    BookmarkData    bookmarkData;
    UInt8*          bookmarkPtr;
    MemHandle       handle;
    UInt16          offset;

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

    bookmarkPtr  = MemHandleLock( handle );
    offset       = GET_OFFSET( bookmarkPtr );
    bookmarkPtr += offset + index * sizeof( BookmarkData );
    MemMove( &bookmarkData, bookmarkPtr, sizeof( BookmarkData ) );

    meta = MemHandleLock( GetMetaHandle( bookmarkData.recordId, false ) );
    DmWrite( meta, OFFSETOF( MetaRecord, verticalOffset ), &bookmarkData,
        sizeof( BookmarkData ) - sizeof( UInt16 ) );

    /* Add to history */
    AddToHistory( bookmarkData.recordId );
    SetHistoryFirstParagraph( bookmarkData.firstVisibleParagraph,
        bookmarkData.firstParagraphY );
#ifdef STORE_LAST_VISIBLE
    SetHistoryLastParagraph( bookmarkData.lastVisibleParagraph,
        bookmarkData.lastParagraphY );
#endif
    SetHistoryVerticalOffset( bookmarkData.verticalOffset );
    SetHistoryCharacterPosition( bookmarkData.characterPosition );

    MemPtrUnlock( meta );
    MemHandleUnlock( handle );

    return bookmarkData.recordId;
}
Пример #17
0
static void MusicFormSave(UInt16 index) {
	if (index != dmMaxRecordIndex) {
		MemHandle recordH;
		GameInfoType *ogameInfoP;

		if (!MusicTabSave()) return;
		if (!AudioCDTabSave()) return;
		VolumeTabSave();

		recordH = DmGetRecord(gameDB, index);
		ogameInfoP = (GameInfoType *)MemHandleLock(recordH);
		DmWrite(ogameInfoP, 0, gameInfoP, sizeof(GameInfoType));
		MemHandleUnlock(recordH);
		DmReleaseRecord (gameDB, index, 0);
	}

	MemPtrFree(gameInfoP);
	gameInfoP = NULL;

	TabDeleteTabs(myTabP);
	FrmReturnToMain();
}
Пример #18
0
/* Deactivate Plucker document */
static void DeactivateOneDocument
    (
    UInt16 index
    )
{
    MemHandle   handle;
    Boolean     active;

    active = false;
    handle = OpenRecord( plkrDocList, index );
    if ( handle != NULL ) {
        DocumentData* handlePtr;

        handlePtr = MemHandleLock( handle );
        if ( Prefs()->syncPolicy != SYNC_IGNORE_CARD ||
             handlePtr->location == RAM )
            DmWrite( handlePtr, OFFSETOF( DocumentData, active ), &active,
                sizeof( Boolean ) );
        MemHandleUnlock( handle );
        CloseRecord( handle, true );
    }
}
Пример #19
0
/* Create a new record recNum in a databse db that contains given word */
static Err WriteWordInRecord(DmOpenRef db, UInt16 recNum, char *word)
{
    int         wordLen;
    MemHandle   recHandle;
    MemPtr      recData;
    Err         err;

    Assert(db);
    Assert(word);

    wordLen = StrLen(word)+1;

    recHandle = DmNewRecord(db, &recNum, wordLen);
    if (!recHandle)
        return DmGetLastErr();

    recData = MemHandleLock(recHandle);
    Assert( recData );

    err = DmWrite(recData, 0, word, wordLen);
    MemHandleUnlock(recHandle);
    DmReleaseRecord(db, recNum, true);
    return err;
}
Пример #20
0
/* Store when the document is read */
void StoreReadTimeInDocumentList
    (
    Char*  name,     /* name of document that should be updated */
    UInt32 newValue  /* time from epoch */
    )
{
    MemHandle handle;

    ErrTry {
        handle = FindDocData( name, ALL_ELEMENTS, NULL );
        if ( handle != NULL ) {
            DocumentInfo* recordPtr;

            recordPtr = MemHandleLock( handle );
            DmWrite( recordPtr, OFFSETOF( DocumentData, timestamp ),
                &newValue, sizeof( UInt32 ) );

            MemHandleUnlock( handle );
            CloseRecord( handle, true );
        }
    }
    ErrCatch( UNUSED_PARAM( err ) ) {
    } ErrEndCatch
}
Пример #21
0
static Boolean
ExamDetailsFormSave(void)
{
  MemHandle newExam=NULL;
  UInt16 index = dmMaxRecordIndex;
  ListType *course;
  ControlType *course_tr, *date_tr, *time_tr;
  Char *room;
  Char empty[1]={'\0'};
  FieldType *fldRoom;

  course = GetObjectPtr(LIST_exd_course);
  course_tr = GetObjectPtr(LIST_exd_course_trigger);
  date_tr = GetObjectPtr(SELECTOR_exd_date);
  time_tr = GetObjectPtr(SELECTOR_exd_time);

  fldRoom = GetObjectPtr(FIELD_exd_room);
  room = FldGetTextPtr(fldRoom);
  if (room == NULL)  room=empty;

  if (gExamsLastSelRowUID == 0) {
    // New record
    newExam = DmNewRecord(DatabaseGetRefN(DB_MAIN), &index, sizeof(ExamDBRecord));
  } else {
    // Load record
    DmFindRecordByID(DatabaseGetRefN(DB_MAIN), gExamsLastSelRowUID, &index);
    newExam = DmGetRecord(DatabaseGetRefN(DB_MAIN), index);
  }
  if (! newExam) {
    // Could not create entry
    FrmAlert(ALERT_nomem);
    return false;
  } else {
    UInt16 attr=0;
    ExamDBRecord ex, *ep;

    ep = (ExamDBRecord *)MemHandleLock(newExam);

    ex.type=TYPE_EXAM;
    ex.course=gExamDetailsItemIDs[LstGetSelection(course)];
    ex.note = (gExamsLastSelRowUID == 0) ? 0 : ep->note;
    ex.date.year = gExamDetailsDate.year;
    ex.date.month = gExamDetailsDate.month;
    ex.date.day = gExamDetailsDate.day;
    ex.begin.hours = gExamDetailsBegin.hours;
    ex.begin.minutes = gExamDetailsBegin.minutes;
    ex.end.hours = gExamDetailsEnd.hours;
    ex.end.minutes = gExamDetailsEnd.minutes;
    ex.flags = 0x0000;
    StrNCopy(ex.room, room, sizeof(ex.room));

    DmWrite(ep, 0, &ex, sizeof(ExamDBRecord));
    MemHandleUnlock(newExam);
    DmReleaseRecord(DatabaseGetRef(), index, false);
    DmRecordInfo(DatabaseGetRef(), index, &attr, NULL, NULL);
    attr |= DatabaseGetCat();
    DmSetRecordInfo(DatabaseGetRef(), index, &attr, NULL);

    DatabaseSort();
  } 

  AlarmReset(DatabaseGetRef());
  return true;
}
Пример #22
0
Boolean
ExamsFormHandleEvent(EventPtr event)
{
  FormPtr frm=FrmGetActiveForm();
  Boolean handled = false;
  Boolean categoryEdited, reDraw=false;
  UInt16 category, numRecords;
  ControlType *ctl;
  UInt32 *recordList;

  if (event->eType == ctlSelectEvent) {
    // button handling
    switch (event->data.ctlSelect.controlID) {
      case BUTTON_ex_back:
        handled=true;
        FrmGotoForm(FORM_main);
        break;

      case BUTTON_ex_add:
        handled=true;
        if (CountCourses() > 0) {
          gExamsLastSelRowUID=0;
          FrmPopupForm(FORM_exam_details);
        } else {
          FrmAlert(ALERT_nocourses);
        }
        break;

      case BUTTON_ex_edit:
        handled=true;
        gExamsLastSelRowUID=TblGetRowData(GetObjectPtr(TABLE_exams), gExamsSelRow);
        FrmPopupForm(FORM_exam_details);
        break;

      case BUTTON_ex_note:
      {
        UInt16 index=0;

        handled=true;

        gExamsLastSelRowUID=TblGetRowData(GetObjectPtr(TABLE_exams), gExamsSelRow);
        DmFindRecordByID(DatabaseGetRefN(DB_MAIN), gExamsLastSelRowUID, &index);
        NoteSet(index, FORM_exams);
        FrmPopupForm(NewNoteView);
        break;
      }

      case BUTTON_ex_del:
        handled=true;
        gExamsLastSelRowUID=TblGetRowData(GetObjectPtr(TABLE_exams), gExamsSelRow);
        ExamDelete();
        break;

      case BUTTON_ex_beam:
        handled=true;
        gExamsLastSelRowUID=TblGetRowData(GetObjectPtr(TABLE_exams), gExamsSelRow);
        ExamBeam();
        break;

      case LIST_ex_cat_trigger:
        handled=true;
        category=DatabaseGetCat();
        numRecords=DmNumRecordsInCategory(DatabaseGetRef(), DELETE_CATEGORY);
        recordList=(UInt32 *)MemPtrNew(numRecords * sizeof(UInt32));
        CatPreEdit(numRecords, recordList);
        categoryEdited = CategorySelect(DatabaseGetRef(), frm,
                                        LIST_ex_cat_trigger, LIST_ex_cat, false,
                                        &category, gCategoryName, 0,
                                        STRING_cat_edit); // categoryDefaultEditCategoryString
        if (categoryEdited || (category != DatabaseGetCat())) {
          reDraw=true;
          DatabaseSetCat(category);
          ctl = GetObjectPtr(LIST_ex_cat_trigger);
          CategoryGetName(DatabaseGetRef(), category, gCategoryName); 
          CategorySetTriggerLabel(ctl, gCategoryName);
        }
        CatPostEdit(numRecords, recordList);
        if (reDraw) {
          gExamsOffset=0;
          gExamsSelRow=0;
          FrmUpdateForm(FORM_exams, frmRedrawUpdateCode);
        }
        if (recordList != NULL)  MemPtrFree((MemPtr)recordList);
        break;

      default:
        break;
    }
  } else if (event->eType == tblEnterEvent) {
    UInt16 i;
    
    if (event->data.tblEnter.column == EXCOL_DONE) {
      handled=false;
    } else if (event->data.tblEnter.column == EXCOL_NOTE) {
      MemHandle m;
      Boolean hasNote=false;

      gExamsSelRow=event->data.tblEnter.row;
      for (i=0; i < TblGetNumberOfRows(event->data.tblEnter.pTable); ++i) {
        RectangleType r;
        TblGetItemBounds(event->data.tblEnter.pTable, i, EXCOL_SELI, &r);
        TableDrawSelection(event->data.tblEnter.pTable, i, event->data.tblEnter.column, &r);
      }


      m = DmQueryRecord(DatabaseGetRefN(DB_MAIN), TblGetRowID(event->data.tblEnter.pTable, event->data.tblEnter.row));
      if (m) {
        ExamDBRecord *ex = (ExamDBRecord *)MemHandleLock(m);
        if (ex->note) hasNote = true;
        else          hasNote = false;
        MemHandleUnlock(m);
      }

      if (hasNote) {
        Coord newPointX, newPointY;
        Boolean isPenDown=false, drawn=false;
        RectangleType fieldBounds;
        IndexedColorType curForeColor, curBackColor, curTextColor;
        Char noteSymb[2] = { GADGET_NOTESYMBOL, 0 };
        FontID oldFont;
  
  
        EvtGetPen(&newPointX, &newPointY, &isPenDown);
        TblGetItemBounds(event->data.tblEnter.pTable, event->data.tblEnter.row, EXCOL_NOTE, &fieldBounds);
  
        oldFont = FntSetFont(symbolFont);
        while (isPenDown){
          if (! drawn && RctPtInRectangle(newPointX, newPointY, &fieldBounds)) {
            curForeColor = WinSetForeColor(UIColorGetTableEntryIndex(UIObjectSelectedForeground));
            curBackColor = WinSetBackColor(UIColorGetTableEntryIndex(UIObjectSelectedFill));
            curTextColor = WinSetTextColor(UIColorGetTableEntryIndex(UIObjectSelectedForeground));
            TNDrawCharsToFitWidth(noteSymb, &fieldBounds);
            WinSetForeColor(curForeColor);
            WinSetForeColor(curBackColor);
            WinSetForeColor(curTextColor);
            drawn = true;
          } else if (drawn && ! RctPtInRectangle(newPointX, newPointY, &fieldBounds)) {
            curForeColor = WinSetForeColor(UIColorGetTableEntryIndex(UIObjectForeground));
            curBackColor = WinSetBackColor(UIColorGetTableEntryIndex(UIObjectFill));
            curTextColor = WinSetTextColor(UIColorGetTableEntryIndex(UIObjectForeground));
            TNDrawCharsToFitWidth(noteSymb, &fieldBounds);
            WinSetForeColor(curForeColor);
            WinSetForeColor(curBackColor);
            WinSetForeColor(curTextColor);
            drawn = false;
          }
          EvtGetPen(&newPointX, &newPointY, &isPenDown);
        }
        FntSetFont(oldFont);
      } else {
        handled = true;
      }
    } else {
      gExamsSelRow=event->data.tblEnter.row;
      for (i=0; i < TblGetNumberOfRows(event->data.tblEnter.pTable); ++i) {
        RectangleType r;
        TblGetItemBounds(event->data.tblEnter.pTable, i, EXCOL_SELI, &r);
        TableDrawSelection(event->data.tblEnter.pTable, i, event->data.tblEnter.column, &r);
      }
      handled=true;
    }
  } else if (event->eType == tblSelectEvent) {
    if (event->data.tblEnter.column == EXCOL_DONE) {
      MemHandle mex;
      ExamDBRecord *ex;
      Boolean done=(TblGetItemInt(event->data.tblSelect.pTable, event->data.tblSelect.row, event->data.tblSelect.column) == 0) ? false : true;
      UInt16 flags, index=TblGetRowID(event->data.tblSelect.pTable, event->data.tblSelect.row);

      mex=DmGetRecord(DatabaseGetRefN(DB_MAIN), index);
      ex = MemHandleLock(mex);
      flags = ex->flags;

      if (done) {
        flags |= EX_FLAG_DONE;
      } else {
        flags &= (EX_FLAG_DONE ^ 0xFFFF);
      }

      DmWrite(ex, offsetof(ExamDBRecord, flags), &flags, sizeof(flags));
      DmReleaseRecord(DatabaseGetRefN(DB_MAIN), index, false);

      TblMarkRowInvalid(event->data.tblSelect.pTable, event->data.tblSelect.row);
      TblRedrawTable(event->data.tblSelect.pTable);

      MemHandleUnlock(mex);

    } else if (event->data.tblEnter.column == EXCOL_NOTE) {
      ControlType *ctl=GetObjectPtr(BUTTON_ex_note);
      // Don't need code twice, just read ctlSelect Event for BUTTON_ex_note
      CtlHitControl(ctl);
    }
    handled=true;
  } else if (event->eType == ctlRepeatEvent) {
    // Repeat buttons pressed
    if( event->data.ctlRepeat.controlID == REPEAT_ex_up )
      gExamsOffset -= 1;
    else
      gExamsOffset += 1;

    ExamsTableInit();
    TblMarkTableInvalid(GetObjectPtr(TABLE_exams));
    TblRedrawTable(GetObjectPtr(TABLE_exams));
  } else if (event->eType == keyDownEvent) {
    // We have a hard button assigned and it was pressed
    if (TxtCharIsHardKey(event->data.keyDown.modifiers, event->data.keyDown.chr)) {
      if (! (event->data.keyDown.modifiers & poweredOnKeyMask)) {
        FrmGotoForm(FORM_main);
        handled = true;
      }
    }
  } else if (event->eType == menuOpenEvent) {
    return HandleMenuOpenEvent(event);
  } else if (event->eType == menuEvent) {
    // forwarding of menu events
    return HandleMenuEvent(event->data.menu.itemID);
  } else if (event->eType == frmOpenEvent) {
    // initializes and draws the form
    ControlType *ctl;

    gExamsOffset=0;
    ExamsTableInit();
    FrmDrawForm (frm);

    ctl = GetObjectPtr(LIST_ex_cat_trigger);
    CategoryGetName (DatabaseGetRef(), DatabaseGetCat(), gCategoryName); 
    CategorySetTriggerLabel (ctl, gCategoryName); 

    handled = true;
  } else if (event->eType == frmUpdateEvent) {
    // redraws the form if needed
    gExamsOffset=0;
    ExamsTableInit();
    FrmDrawForm(frm);
    handled = false;
  } else if (event->eType == frmCloseEvent) {
    // this is done if form is closed
    // TblEraseTable(GetObjectPtr(TABLE_exams));
    // ExamsFormFree();
    FrmEraseForm(frm);
  }

  return (handled);

}
Пример #23
0
// Save preferences previously set via ErrSet*() calls to a database.
// If something goes wrong, returns an error
// Possible errors:
//   memErrNotEnoughSpace - not enough memory to allocate needed structures
//   errors from Dm*() calls
Err PrefsStoreWriter::ErrSavePreferences()
{
    Err     err = errNone;
    long    blobSize;
    void *  prefsBlob = SerializeItems(_items, _itemsCount, &blobSize);
    if ( NULL == prefsBlob ) 
        return memErrNotEnoughSpace;

    DmOpenRef db = DmOpenDatabaseByTypeCreator(_dbType, _dbCreator, dmModeReadWrite);
    if (!db)
    {
        err = DmCreateDatabase(0, _dbName, _dbCreator, _dbType, false);
        if ( err)
            return err;

        db = DmOpenDatabaseByTypeCreator(_dbType, _dbCreator, dmModeReadWrite);
        if (!db)
            return DmGetLastErr();
    }

    // set backup bit on the database. code adapted from DataStore.cpp
    // DataStore::open()
    if (errNone == err)
    {
        LocalID localId;
        UInt16 cardNo;
        UInt16 attribs;
        err = DmOpenDatabaseInfo(db, &localId, NULL, NULL, &cardNo, NULL);
        if (errNone != err)
            goto Continue;
        err = DmDatabaseInfo(cardNo, localId, NULL, &attribs, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
        if (errNone != err)
            goto Continue;
        if (0 != attribs & dmHdrAttrBackup)
            goto Continue;
        attribs |= dmHdrAttrBackup;
        err = DmSetDatabaseInfo(cardNo, localId, NULL, &attribs, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
Continue:
        err = errNone;
    }

    UInt16    recNo = 0;
    UInt16    recsCount = DmNumRecords(db);
    MemHandle recHandle;
    Boolean   fRecordBusy = false;
    Boolean   fRecFound = false;
    void *    recData;
    long      recSize;
    while (recNo < recsCount)
    {
        recHandle = DmGetRecord(db, recNo);
        fRecordBusy = true;
        recData = MemHandleLock(recHandle);
        recSize = MemHandleSize(recHandle);
        if (IsValidPrefRecord(recData))
        {
            fRecFound = true;
            break;
        }
        MemPtrUnlock(recData);
        DmReleaseRecord(db, recNo, true);
        fRecordBusy = false;
        ++recNo;
    }

    if (fRecFound && blobSize>recSize)
    {
        /* need to resize the record */
        MemPtrUnlock(recData);
        DmReleaseRecord(db,recNo,true);
        fRecordBusy = false;
        recHandle = DmResizeRecord(db, recNo, blobSize);
        if ( NULL == recHandle )
            return DmGetLastErr();
        recData = MemHandleLock(recHandle);
        Assert( MemHandleSize(recHandle) == blobSize );        
    }

    if (!fRecFound)
    {
        recNo = 0;
        recHandle = DmNewRecord(db, &recNo, blobSize);
        if (!recHandle)
        {
            err = DmGetLastErr();
            goto CloseDbExit;
        }
        recData = MemHandleLock(recHandle);
        fRecordBusy = true;
    }

    err = DmWrite(recData, 0, prefsBlob, blobSize);
    MemPtrUnlock(recData);
    if (fRecordBusy)
        DmReleaseRecord(db, recNo, true);
CloseDbExit:
    // if had error before - preserve that error
    // otherwise return error code from DmCloseDatabase()
    if (err)
        DmCloseDatabase(db);
    else
        err = DmCloseDatabase(db);
    new_free( prefsBlob );
    return err;
}
Пример #24
0
/* Delete bookmark, return true if list is empty */
void DeleteBookmark
    (
    UInt16 index     /* index in bookmarks list */
    )
{
    BookmarkData  bookmarkData;
    MemHandle     handle;
    UInt16        entries;
    UInt16        offset;
    UInt16        tempOffset;
    UInt16        newSize;
    UInt16        nameLength;
    UInt16        i;
    UInt8*        bookmarkPtr;
    UInt8*        readPtr;

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

    bookmarkPtr = MemHandleLock( handle );
    entries     = GET_ENTRIES( bookmarkPtr );
    if ( entries <= 1 ) {
        MemHandleUnlock( handle );
        ReleaseBookmarkList();
        RemoveBookmarkRecord();
        return;
    }

    /* Find name string for bookmark  */
    readPtr = bookmarkPtr + BOOKMARK_HEADER_LEN;
    for ( i = 0; i < index; i++ )
        readPtr += StrLen( readPtr ) + 1;

    tempOffset  = readPtr - bookmarkPtr;
    nameLength  = StrLen( readPtr ) + 1;
    readPtr    += nameLength;
    for ( i = 0; i < entries - index - 1; i++ ) {
        UInt16  length;
        Char    tempString[ MAX_BOOKMARK_LEN + 1 ];

        MemMove( tempString, readPtr, StrLen( readPtr ) + 1 );
        length = StrLen( tempString ) + 1;

        DmWrite( bookmarkPtr, tempOffset, tempString, length );

        tempOffset  += length;
        readPtr     += length;
    }

    /* Reshuffle blocks with bookmark data */
    offset  = GET_OFFSET( bookmarkPtr );
    readPtr = bookmarkPtr + offset;
    for ( i = 0; i < index; i++ ) {
        MemMove( &bookmarkData, readPtr, sizeof( BookmarkData ) );

        DmWrite( bookmarkPtr, tempOffset, &bookmarkData,
            sizeof( BookmarkData ) );
        tempOffset  += sizeof( BookmarkData );
        readPtr     += sizeof( BookmarkData );
    }
    readPtr += sizeof( BookmarkData );
    for ( i = index + 1; i < entries; i++ ) {
        MemMove( &bookmarkData, readPtr, sizeof( BookmarkData ) );

        DmWrite( bookmarkPtr, tempOffset, &bookmarkData,
            sizeof( BookmarkData ) );
        tempOffset  += sizeof( BookmarkData );
        readPtr     += sizeof( BookmarkData );
    }

    entries--;
    DmWrite( bookmarkPtr, sizeof( UInt16 ), &entries, sizeof( UInt16 ) );
    offset -= nameLength;
    DmWrite( bookmarkPtr, 2 * sizeof( UInt16 ), &offset, sizeof( UInt16 ) );

    newSize = MemHandleSize( handle ) - sizeof( BookmarkData ) - nameLength;

    MemHandleUnlock( handle );

    ResizeMetaRecord( INTERNAL_BOOKMARKS_ID, newSize, &handle );
}
Пример #25
0
/* Add data for bookmark */
void AddBookmark
    (
    Char* name      /* name of bookmark */
    )
    /* THROWS */
{
    MetaRecord*     meta;
    BookmarkData    bookmarkData;
    UInt8*          bookmarkPtr;
    MemHandle       handle;
    UInt32          endOfRecord;
    UInt16          entries;
    UInt16          offset;
    UInt16          newSize;
    UInt16          nameLength;
    UInt16          i;

    THROW_IF( name == NULL || *name == '\0', errNoBookmarkName );

    handle = ReturnMetaHandle( INTERNAL_BOOKMARKS_ID, NO_PARAGRAPHS );
    if ( handle == NULL )
        AddBookmarkRecord( &handle );

    endOfRecord = MemHandleSize( handle );
    TrimText( name, BOOKMARKLISTWIDTH );
    nameLength  = StrLen( name ) + 1;
        
    newSize     = endOfRecord + sizeof( BookmarkData ) + nameLength;

    ResizeMetaRecord( INTERNAL_BOOKMARKS_ID, newSize, &handle );

    bookmarkPtr = MemHandleLock( handle );

    entries = GET_ENTRIES( bookmarkPtr ) + 1;
    offset  = GET_OFFSET( bookmarkPtr ) + nameLength;
    DmWrite( bookmarkPtr, sizeof( UInt16 ), &entries, sizeof( UInt16 ) );
    DmWrite( bookmarkPtr, 2 * sizeof( UInt16 ), &offset, sizeof( UInt16 ) );

    meta = MemHandleLock( GetMetaRecord() );

    bookmarkData.verticalOffset         = meta->verticalOffset;
    bookmarkData.characterPosition      = meta->characterPosition;
    bookmarkData.firstVisibleParagraph  = meta->firstVisibleParagraph;
    bookmarkData.firstParagraphY        = meta->firstParagraphY;
#ifdef STORE_LAST_VISIBLE
    bookmarkData.lastVisibleParagraph   = meta->lastVisibleParagraph;
    bookmarkData.lastParagraphY         = meta->lastParagraphY;
#endif
    bookmarkData.recordId               = GetHistoryCurrent();

    /* Write new block of bookmark data */
    DmWrite( bookmarkPtr, endOfRecord + nameLength, &bookmarkData,
        sizeof( BookmarkData ) );
    endOfRecord -= sizeof( BookmarkData );

    /* Reshuffle old blocks with bookmark data */
    for ( i = 1; i < entries; i++ ) {
        MemMove( &bookmarkData, bookmarkPtr + endOfRecord,
            sizeof( BookmarkData ) );
        DmWrite( bookmarkPtr, endOfRecord + nameLength, &bookmarkData,
            sizeof( BookmarkData ) );
        endOfRecord -= sizeof( BookmarkData );
    }

    /* Write new bookmark name */
    DmStrCopy( bookmarkPtr, offset - nameLength, name );

    MemHandleUnlock( GetMetaRecord() );
    MemHandleUnlock( handle );
}