// 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; }
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); }
/* 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); } }
/* Create an app info chunk if missing, return result from the database call */ static void InitPlkrAppInfo ( DmOpenRef docRef /* reference to document */ ) /* THROWS */ { UInt16 cardNo; MemHandle handle; LocalID dbID; LocalID appInfoID; PlkrAppInfoType* appInfoP; Err err; err = DmOpenDatabaseInfo( docRef, &dbID, NULL, NULL, &cardNo, NULL ); THROW_IF( err != errNone, err ); err = DmDatabaseInfo( cardNo, dbID, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &appInfoID, NULL, NULL, NULL ); THROW_IF( err != errNone, err ); if ( appInfoID == 0 ) { handle = DmNewHandle( docRef, sizeof *appInfoP ); THROW_IF( handle == NULL, dmErrMemError ); appInfoID = MemHandleToLocalID( handle ); DmSetDatabaseInfo( cardNo, dbID, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &appInfoID, NULL, NULL, NULL ); } appInfoP = MemLocalIDToLockedPtr( appInfoID, cardNo ); DmSet( appInfoP, 0, sizeof *appInfoP, 0 ); CategoryInitialize( ( AppInfoPtr ) appInfoP, strCatDefault ); MemPtrUnlock( appInfoP ); }
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); } }
Int16 HDNewRecord(DmOpenRef dbP, HappyDays *r, UInt16 *index) { MemHandle recordH; PackedHappyDays* recordP; Int16 err; UInt16 newIndex; // 1) and 2) (make a new chunk with the correct size) recordH = DmNewHandle(dbP, (Int16)HDPackedSize(r)); if (recordH == NULL) return dmErrMemError; // 3) Copy the data from the unpacked record to the packed one. recordP = MemHandleLock(recordH); PackHappyDays(r, recordP); // Get the index newIndex = HDFindSortPosition(dbP, recordP); MemPtrUnlock(recordP); // 4) attach in place err = DmAttachRecord(dbP, &newIndex, recordH, 0); if (err) MemHandleFree(recordH); else *index = newIndex; return err; }
/************************************************************ * * 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; }
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); } } }
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; }
/* DrawBitmap -- Places a bitmap at a specified location * Args: * Word BitmapID -- ID for bitmap, see the cwimp.rpc file * int formX -- X location on the form * int formY -- Y location on the form * Returns: None */ void DrawBitmap (Word BitmapID, int formX, int formY) { VoidHand resourceHandle; BitmapPtr bitmapPntr; resourceHandle = DmGetResource(bitmapRsc, BitmapID); bitmapPntr = MemHandleLock(resourceHandle); WinDrawBitmap(bitmapPntr, formX, formY); MemPtrUnlock(bitmapPntr); DmReleaseResource(resourceHandle); }
void PrvFreeGlobals(UInt16 refNum) { SysLibTblEntryType* libEntry = SysLibTblEntry(refNum); ErrFatalDisplayIf(libEntry == NULL, "invalid InfoMan Flickr Uploader refNum"); MemHandle handle = (MemHandle)libEntry->globalsP; if (NULL != handle) { FlickrGlobals* globals = (FlickrGlobals*)MemHandleLock(handle); if (NULL != globals) { globals->Dispose(); MemPtrUnlock(globals); } libEntry->globalsP = NULL; MemHandleFree(handle); } }
static void ExamDetailsGetDate(void) { Char *title; Boolean clickedOK=false; Int16 year=gExamDetailsDate.year+MAC_SHIT_YEAR_CONSTANT, month=gExamDetailsDate.month, day=gExamDetailsDate.day; title = MemHandleLock(DmGetResource (strRsc, STRING_ed_title)); clickedOK=SelectDay(selectDayByDay, &month, &day, &year, title); MemPtrUnlock(title); if (clickedOK) { gExamDetailsDate.year=year-MAC_SHIT_YEAR_CONSTANT; gExamDetailsDate.month=month; gExamDetailsDate.day=day; ExamDetailsSetTriggers(GetObjectPtr(SELECTOR_exd_date), GetObjectPtr(SELECTOR_exd_time)); } }
/* 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 ); }
/* 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; }
Boolean NewFindHappyDaysField() { AddrAppInfoPtr addrInfoPtr; Int16 i; gHappyDaysField = -1; if ((addrInfoPtr = (AddrAppInfoPtr)AppInfoGetPtr(AddressDB))) { for (i= firstRenameableLabel; i <= lastRenameableLabel; i++) { if (!StrCaselessCompare(addrInfoPtr->fieldLabels[i], gPrefsR.custom)) { gHappyDaysField = i; break; } } MemPtrUnlock(addrInfoPtr); } if (gHappyDaysField < 0) { // Custom field에 일치하는 게 없는 경우에는 note field를 조사 return true; } return true; }
static MemHandle StrCopyToHandle(const char* text, Int16 len = -1) { if (-1 == len) len = StrLen(text); MemHandle handle = MemHandleNew(len + 1); if (NULL == handle) { DMSG("StrCopyToHandle(): MemHandleNew() failed; size: "); DNUM(len + 1); DENDL; return NULL; } char* p = (char*)MemHandleLock(handle); if (NULL == p) { MemHandleFree(handle); return NULL; } MemMove(p, text, sizeof(char) * len); p[len] = chrNull; MemPtrUnlock(p); return handle; }
/* * 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; }
/** * @brief * @param dbP Happydays DB pointer * @param AddrCategory The category of Address to be displayed * @param start Start position * @return The number of total Item * @remarks * @endif */ UInt16 AddrGetHappyDays(DmOpenRef dbP, UInt16 AddrCategory, DateType start) { UInt16 totalItems; UInt16 recordNum = 0; MemHandle recordH = 0; LineItemPtr ptr; PackedHappyDays* rp; HappyDays r; DateType converted; UInt16 currindex = 0; Int16 age; // if exist, free the memory // if (gTableRowHandle) { MemHandleFree(gTableRowHandle); gTableRowHandle = 0; } totalItems = DmNumRecordsInCategory(dbP, AddrCategory); if (totalItems > 0) { gTableRowHandle = MemHandleNew(sizeof(LineItemType)* totalItems); ErrFatalDisplayIf(!gTableRowHandle, "Out of memory"); if ((ptr = MemHandleLock(gTableRowHandle))) { for (recordNum = 0; recordNum < totalItems; recordNum++) { if ((recordH = DmQueryNextInCategory(dbP, &currindex, (UInt16)AddrCategory))) { ptr[recordNum].birthRecordNum = currindex; rp = (PackedHappyDays *) MemHandleLock(recordH); /* * Build the unpacked structure for an AddressDB * record. It is just a bunch of pointers into the rp * structure. */ UnpackHappyDays(&r, rp); // original r(in MainDB) not changed // local change for LineItemType // converted = r.date; if (r.flag.bits.nthdays) { int syear, smonth, sday; if (r.flag.bits.lunar || r.flag.bits.lunar_leap) { if (lunarL2S(lunarRefNum, converted.year + firstYear, converted.month, converted.day, r.flag.bits.lunar_leap, &syear, &smonth, &sday) != errNone) { MemHandleUnlock(recordH); currindex++; recordNum--; totalItems--; continue; } converted.day = sday; converted.month = smonth; converted.year = syear - firstYear; } DateAdjust(&converted, r.nth); if (DateToDays(converted) < DateToDays(start)) { MemHandleUnlock(recordH); currindex++; recordNum--; totalItems--; continue; } } else if (r.flag.bits.lunar || r.flag.bits.lunar_leap) { if (!FindNearLunar(&converted, start, r.flag.bits.lunar_leap)) { // ignore the records // converted.year = INVALID_CONV_DATE; // max year(for sorting) // indicate for invalid date } } else if (r.flag.bits.solar) { int maxtry = 4; DateType dt; dt = start; DateToInt(dt) = (DateToInt(dt) > DateToInt(converted)) ? DateToInt(dt) : DateToInt(converted); if (converted.month < dt.month || ( converted.month == dt.month && converted.day < dt.day)) { // birthdate is in last year? while (DaysInMonth(converted.month, ++dt.year) < converted.day && maxtry-- > 0) ; } else { while (DaysInMonth(converted.month, dt.year) < converted.day && maxtry-- >0) { dt.year++; } } if (maxtry >0) converted.year = dt.year; else { converted.year = INVALID_CONV_DATE; // max year // indicate for invalid date } } if (converted.year != INVALID_CONV_DATE && !r.flag.bits.nthdays && r.flag.bits.year && (age = CalculateAge(converted, r.date, r.flag)) >= 0) { // calculate age if year exists // ptr[recordNum].age = age; } else { ptr[recordNum].age = -1; } // save the converted data // ptr[recordNum].date = converted; MemHandleUnlock(recordH); currindex++; } } // sort the order if sort order is converted date // if (gPrefsR.sort == 1) { // date sort SysInsertionSort(ptr, totalItems, sizeof(LineItemType), (_comparF *)CompareHappyDaysFunc, 1L); } else if (gPrefsR.sort == 3) { // age sort SysInsertionSort(ptr, totalItems, sizeof(LineItemType), (_comparF *)CompareAgeFunc, 1L); } else if (gPrefsR.sort == 2) { // age sort(re) SysInsertionSort(ptr, totalItems, sizeof(LineItemType), (_comparF *)CompareAgeFunc, -1L); } MemPtrUnlock(ptr); } else return 0; } return totalItems; }
/************************************************************ * * FUNCTION: ApptChangeRecord * * DESCRIPTION: Change a record in the Appointment Database * * PARAMETERS: database pointer * database index * database record * changed fields * * RETURNS: ##0 if successful, errorcode if not * * CREATED: 1/25/95 * * BY: Roger Flores * * COMMENTS: Records are not stored with extra padding - they * are always resized to their exact storage space. This avoids * a database compression issue. The code works as follows: * * 1) get the size of the new record * 2) make the new record * 3) pack the packed record plus the changes into the new record * 4) if the sort position is changes move to the new position * 5) attach in position * *************************************************************/ Err ApptChangeRecord(DmOpenRef dbP, UInt16 *index, ApptDBRecordPtr r, ApptDBRecordFlags changedFields) { Err result; Int16 newIndex; UInt16 attributes; Boolean dontMove; MemHandle oldH; MemHandle srcH; MemHandle dstH; ApptDBRecordType src; ApptPackedDBRecordPtr dst = 0; ApptPackedDBRecordPtr cmp; // We do not assume that r is completely valid so we get a valid // ApptDBRecordPtr... if ((result = ApptGetRecord(dbP, *index, &src, &srcH)) != 0) return result; // and we apply the changes to it. if (changedFields.when) src.when = r->when; if (changedFields.alarm) src.alarm = r->alarm; if (changedFields.repeat) src.repeat = r->repeat; if (changedFields.exceptions) src.exceptions = r->exceptions; if (changedFields.description) src.description = r->description; if (changedFields.note) src.note = r->note; // Allocate a new chunk with the correct size and pack the data from // the unpacked record into it. dstH = DmNewHandle(dbP, (UInt32) ApptPackedSize(&src)); if (dstH) { dst = MemHandleLock (dstH); ApptPack (&src, dst); } MemHandleUnlock (srcH); if (dstH == NULL) return dmErrMemError; // If the sort position is changed move to the new position. // Check if any of the key fields have changed. if ((!changedFields.when) && (! changedFields.repeat)) goto attachRecord; // repeating events aren't in sorted order // Make sure *index-1 < *index < *index+1, if so it's in sorted // order. Leave it there. if (*index > 0) { // This record wasn't deleted and deleted records are at the end of the // database so the prior record may not be deleted! cmp = MemHandleLock (DmQueryRecord(dbP, *index-1)); dontMove = (ApptComparePackedRecords (cmp, dst, 0, NULL, NULL, 0) <= 0); MemPtrUnlock (cmp); } else dontMove = true; if (dontMove && (*index+1 < DmNumRecords (dbP))) { DmRecordInfo(dbP, *index+1, &attributes, NULL, NULL); if ( ! (attributes & dmRecAttrDelete) ) { cmp = MemHandleLock (DmQueryRecord(dbP, *index+1)); dontMove &= (ApptComparePackedRecords (dst, cmp, 0, NULL, NULL, 0) <= 0); MemPtrUnlock (cmp); } } if (dontMove) goto attachRecord; // The record isn't in the right position. Move it. newIndex = ApptFindSortPosition (dbP, dst); DmMoveRecord (dbP, *index, newIndex); if (newIndex > *index) newIndex--; *index = newIndex; // return new position attachRecord: // Attach the new record to the old index, the preserves the // category and record id. result = DmAttachRecord (dbP, index, dstH, &oldH); MemPtrUnlock(dst); if (result) return result; MemHandleFree(oldH); return 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; }
/* Draw the actual buttons onto blank bitmaps, and set them as valid templates on the silkscreen */ static void DrawButtons( void ) { Err err; BitmapPtr silkBitmap; BitmapPtr silkBitmapInv; WinHandle silkWindow; WinHandle silkWindowInv; WinHandle origWindow; UInt16 i; Coord currentX; Coord currentY; Coord silkX; Coord silkY; origWindow = WinGetDrawWindow(); if ( currentSilkStatus == HANDERA_SILK_UP ) { SilkGetTemplateBitmaps( &silkBitmap, &silkBitmapInv, NULL, NULL ); } else { SilkGetTemplateBitmaps( NULL, NULL, &silkBitmap, &silkBitmapInv ); } BmpGlueGetDimensions( silkBitmap, &silkX, &silkY, NULL ); silkWindow = WinCreateOffscreenWindow( silkX, silkY, screenFormat, &err ); silkWindowInv = WinCreateOffscreenWindow( silkX, silkY, screenFormat, &err); WinSetDrawWindow( silkWindow ); WinDrawBitmap( silkBitmap, 0, 0 ); WinSetDrawWindow( silkWindowInv ); WinDrawBitmap( silkBitmapInv, 0, 0 ); /* We need to move down the existing silkscreen to make room for our own toolbar's buttons */ if ( currentSilkStatus == HANDERA_SILK_UP ) { RectangleType area; UInt16 moveY; area.topLeft.x = 40; area.topLeft.y = 1; area.extent.x = 200; area.extent.y = 18; moveY = 14; WinCopyRectangle( silkWindow, silkWindow, &area, area.topLeft.x, moveY, winPaint ); WinCopyRectangle( silkWindowInv, silkWindowInv, &area, area.topLeft.x, moveY, winPaint ); area.extent.y = moveY; WinSetDrawWindow( silkWindow ); WinEraseRectangle( &area, 0 ); WinSetDrawWindow( silkWindowInv ); WinEraseRectangle( &area, 0 ); } currentX = TOOLBAR_START_X; currentY = TOOLBAR_START_Y; for ( i = 0; i < TOTAL_ICONS; i++ ) { MemHandle bitmapH; BitmapPtr bitmap; Coord width; Coord height; if ( iconList[ i ].resourceId == 0 ) { /* This is just a placeholder for our '0' resourced offset image */ width = 22; height = 13; } else { bitmapH = DmGetResource( bitmapRsc, iconList[ i ].resourceId ); bitmap = MemHandleLock( bitmapH ); BmpGlueGetDimensions( bitmap, &width, &height, NULL ); WinSetDrawWindow( silkWindow ); WinDrawBitmap( bitmap, currentX, currentY ); WinSetDrawWindow( silkWindowInv ); WinDrawBitmap( bitmap, currentX, currentY ); MemPtrUnlock( bitmap ); DmReleaseResource( bitmapH ); } iconList[ i ].bounds[ currentSilkStatus ].topLeft.x = currentX; iconList[ i ].bounds[ currentSilkStatus ].topLeft.y = currentY; iconList[ i ].bounds[ currentSilkStatus ].extent.x = width; iconList[ i ].bounds[ currentSilkStatus ].extent.y = height; WinInvertRectangle( &( iconList[ i ].bounds[ currentSilkStatus ]), 0 ); /* Because some icons are meant to appear right beside each other, they're defined here up top. Everything else is spaced so it fits nicely */ switch ( iconList[ i ].resourceId ) { case bmpFind: case bmpAutoscrollDecr: case bmpAutoscrollStop: case bmpLeft: case bmpHome: currentX += width; break; default: currentX += width; if ( currentSilkStatus == HANDERA_SILK_UP ) currentX += 3; else if ( currentSilkStatus == HANDERA_SILK_DOWN ) currentX += 7; break; } } WinSetDrawWindow( origWindow ); silkBitmap = WinGetBitmap( silkWindow ); silkBitmapInv = WinGetBitmap( silkWindowInv ); if ( currentSilkStatus == HANDERA_SILK_UP ) SilkSetTemplateBitmaps( silkBitmap, silkBitmapInv, NULL, NULL ); else SilkSetTemplateBitmaps( NULL, NULL, silkBitmap, silkBitmapInv ); WinDeleteWindow( silkWindow, false ); WinDeleteWindow( silkWindowInv, false ); }
void MsaCDPlayer::play(int track, int num_loops, int start_frame, int duration) { if (!_isInitialized) return; if (!num_loops && !start_frame) return; _msaTrack = track + gVars->CD.firstTrack - 1; // first track >= 1 ?, not 0 (0=album) _msaLoops = num_loops; _msaStartFrame = TO_MSECS(start_frame); _msaDuration = TO_MSECS(duration); Err e; MemHandle trackH; // stop current play if any MsaStop(_msaRefNum, true); _msaStopTime = 0; // retreive track infos e = MsaGetTrackInfo(_msaRefNum, _msaTrack, 0, msa_LANG_CODE_ASCII, &trackH); // track exists if (!e && trackH) { MsaTime msaTime; MsaTrackInfo *trackP; UInt32 SU, fullLength; // FIXME (?) : this enable MsaSuToTime to return the right value in some cases MsaPlay(_msaRefNum, _msaTrack, 0, msa_PBRATE_SP); MsaStop(_msaRefNum, true); // get the msa time trackP = (MsaTrackInfo *)MemHandleLock(trackH); MsaSuToTime(_msaRefNum, trackP->totalsu, &msaTime); SU = trackP->totalsu; MemPtrUnlock(trackP); MemHandleFree(trackH); // MSA frame in milli-seconds fullLength = FROM_MIN(msaTime.minute); fullLength += FROM_SEC(msaTime.second); fullLength += msaTime.frame; if (_msaDuration > 0) { _msaTrackLength = _msaDuration; } else if (_msaStartFrame > 0) { _msaTrackLength = fullLength; _msaTrackLength -= _msaStartFrame; } else { _msaTrackLength = fullLength; } // try to play the track if (start_frame == 0 && duration == 0) { MsaPlay(_msaRefNum, _msaTrack, 0, msa_PBRATE_SP); _msaTrackEndSu = SU; } else { // FIXME : MsaTimeToSu doesn't work ... (may work with previous FIXME) _msaTrackStartSu = (UInt32) ((float)(_msaStartFrame) / ((float)fullLength / (float)SU)); _msaTrackEndSu = (UInt32) ((float)(_msaTrackLength) / ((float)fullLength / (float)SU)); _msaTrackEndSu += _msaTrackStartSu; if (_msaTrackEndSu > SU) _msaTrackEndSu = SU; MsaPlay(_msaRefNum, _msaTrack, _msaTrackStartSu, msa_PBRATE_SP); } } // TODO : use default track length if track not found }