/* ** 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); }
/***************************************************************************** * 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); }
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; }
/* 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; }
void get_default_username(Char *buf, Short max_len) { Char *tmp, *first_wspace; VoidHand h; tmp = md_malloc(sizeof(Char) * (dlkMaxUserNameLength + 1)); DlkGetSyncInfo(NULL, NULL, NULL, tmp, NULL, NULL); /* if it's too long, use the first name only */ // if (StrLen(tmp) > max_len-1) { if (StrLen(tmp) > 8) { first_wspace = StrChr(tmp, spaceChr); if (first_wspace) *(first_wspace) = '\0'; else tmp[max_len-1] = '\0'; } if (StrLen(tmp)) StrNCopy(buf, tmp, max_len); else { Short t = rund(3); switch(t) { case 0: StrPrintF(buf, "Noman"); break; case 1: StrPrintF(buf, "Outis"); break; // "no man" in greek, says the web default: StrPrintF(buf, "Metis"); break; // "no one"/"cunning" pun in greek } } h = MemPtrRecoverHandle(tmp); if (h) MemHandleFree(h); }
/************************************************************ * * 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; }
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; }
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); } }
/* Unlock list handle and free allocated memory */ void ReleaseBookmarkList( void ) { if ( nameListHandle != NULL ) { MemHandleUnlock( nameListHandle ); MemHandleFree( nameListHandle ); nameListHandle = NULL; } }
void CleanField( FieldPtr fld ) { VoidHand h; h = (VoidHand)FldGetTextHandle(fld); FldSetTextHandle(fld, NULL); if( h!=NULL ) MemHandleFree(h); }
static Err UserCredentialsFormInit(FormType* form, const FlickrPrefs& prefs) { FieldType* field; MemHandle handle; MemHandle newText; UInt16 len; FrmSetEventHandler(form, UserCredentialsFormHandleEvent); field = (FieldType*)FrmGetObjectPtr(form, FrmGetObjectIndex(form, emailField)); assert(field != NULL); // FldSetMaxVisibleLines(field, 2); if (0 != (len = StrLen(prefs.email))) { newText = StrCopyToHandle(prefs.email, len); if (NULL == newText) return exgMemError; handle = FldGetTextHandle(field); if (NULL != handle) MemHandleFree(handle); FldSetTextHandle(field, newText); FldSetSelection(field, 0, len); FldRecalculateField(field, false); } if (0 != (len = StrLen(prefs.password))) { field = (FieldType*)FrmGetObjectPtr(form, FrmGetObjectIndex(form, passwordField)); assert(field != NULL); newText = StrCopyToHandle(prefs.password, len); if (NULL == newText) return exgMemError; handle = FldGetTextHandle(field); if (NULL != handle) MemHandleFree(handle); FldSetTextHandle(field, newText); FldSetSelection(field, 0, len); FldRecalculateField(field, false); } return errNone; }
/************************************************************************ * Function: freeHandle * Description: free the given handle * **********************************************************************/ MemHandle freeHandle (MemHandle handle) { if (handle) { MemPtr p = MemHandleLock (handle); MemSet (p, MemPtrSize (p), 0); MemHandleUnlock (handle); MemHandleFree (handle); } return(handle=NULL); }
static void PlayButtonClick (void) { MemHandle smfH; smfH = smfutils_create(¬elist); smfutils_playHandle(smfH); MemHandleFree(smfH); }
static void TableDrawData(void *table, Int16 row, Int16 column, RectangleType *bounds) { UInt16 index=TblGetRowID(table, row); ExamDBRecord *ex; MemHandle mex; RGBColorType fore={0x00, 0x00, 0x00, 0x00}, back={0x00, 0xFF, 0xFF, 0xFF}; if (! TblRowUsable(table, row)) return; TNSetBackColorRGB(&back, NULL); TNSetForeColorRGB(&back, NULL); WinDrawRectangle(bounds, 0); mex = DmQueryRecord(DatabaseGetRefN(DB_MAIN), index); ex = (ExamDBRecord *)MemHandleLock(mex); if (column == EXCOL_COURSE) { Char *temp; MemHandle m=MemHandleNew(1); CourseGetName(ex->course, &m, true); temp = MemHandleLock(m); TNSetForeColorRGB(&fore, NULL); TNDrawCharsToFitWidth(temp, bounds); MemHandleUnlock(m); MemHandleFree(m); } else if (column == EXCOL_NOTE) { if (ex->note) { Char noteSymb[2] = { GADGET_NOTESYMBOL, 0 }; FontID oldFont = FntSetFont(symbolFont); TNDrawCharsToFitWidth(noteSymb, bounds); FntSetFont(oldFont); } } else if (column == EXCOL_DATE) { Char dateTemp[dateStringLength]; DateToAscii(ex->date.month, ex->date.day, ex->date.year+MAC_SHIT_YEAR_CONSTANT, PrefGetPreference(prefDateFormat), dateTemp); TNDrawCharsToFitWidth(dateTemp, bounds); } else if (column == EXCOL_TIME) { Char timeTemp[timeStringLength]; TimeToAscii(ex->begin.hours, ex->begin.minutes, PrefGetPreference(prefTimeFormat), timeTemp); TNDrawCharsToFitWidth(timeTemp, bounds); } if (ex->flags & EX_FLAG_DONE) { RGBColorType red = {0x00, 0xFF, 0x00, 0x00}, old; Int16 yCoord=bounds->topLeft.y+(bounds->extent.y / 2); TNSetForeColorRGB(&red, &old); WinDrawLine(bounds->topLeft.x, yCoord, bounds->topLeft.x+bounds->extent.x, yCoord); TNSetForeColorRGB(&old, NULL); } MemHandleUnlock(mex); }
/***************************************************************************** * Function: DrawCourses * * Description: local function to fill the course list *****************************************************************************/ static void DrawCourses(ListType *lst) { MemHandle mWebsite, mEmail, old; Char *buffer; FieldType *fldWebsite, *fldEmail; gNumCourses=CountCourses(); gCourseList = (Char **) MemPtrNew(gNumCourses * sizeof(Char *)); gCourseInd = (UInt16 *) MemPtrNew(gNumCourses * sizeof(UInt16)); CourseListGen(gCourseList, NULL, gCourseInd, gNumCourses, 0, CLIST_SEARCH_INDEX); LstSetListChoices(lst, gCourseList, gNumCourses); LstSetSelection(lst, -1); fldWebsite = GetObjectPtr(FIELD_cl_website); fldEmail = GetObjectPtr(FIELD_cl_email); mWebsite = MemHandleNew(4); buffer = MemHandleLock(mWebsite); MemSet(buffer, 4, 0); StrCopy(buffer, "-?-"); MemHandleUnlock(mWebsite); old = FldGetTextHandle(fldWebsite); FldSetTextHandle(fldWebsite, mWebsite); if (old != NULL) MemHandleFree(old); mEmail = MemHandleNew(4); buffer = MemHandleLock(mEmail); MemSet(buffer, 4, 0); StrCopy(buffer, "-?-"); MemHandleUnlock(mEmail); old = FldGetTextHandle(fldEmail); FldSetTextHandle(fldEmail, mEmail); if (old != NULL) MemHandleFree(old); }
void FF_CM_Delete(FF_CM_Class *theCache, int *errCode) { tsiMemObject *tempmem = theCache->mem; *errCode = 0; #ifdef PALM MemHandleFree(memH); #else tsi_DeAllocMem( theCache->mem, (void *)theCache); #endif tsi_DeleteMemhandler( tempmem); }
/** * FUNCTION: smClose * * Close link to memory block. * * PRE-Condition: memH is a valid memory block handle; memH is unlocked; * no pointers to records are in use * * POST-Condition: memH is not valid anymore * * IN: memH * Handle to close * * RETURN: SML_ERR_OK, if O.K. * SML_ERR_WRONG_USAGE, if memH is locked * * @see smOpen */ Ret_t smClose (MemHandle_t memH) { Err ret; // reset handle if ( (ret=MemHandleFree((VoidHand)smPalmH)) != 0 ) { return SML_ERR_WRONG_USAGE; } smMemH = 0; smLocked = 0; return SML_ERR_OK; }
Err GetPhoneNumber(ExtensibleBuffer* out) { Boolean fNeedToRemove=false; UInt16 refNum; Err error = GetPhoneLib(&refNum,&fNeedToRemove); if (error) return error; if ( !CheckPhonePower(refNum) ) return sysErrNotAllowed; Assert(sysInvalidRefNum!=refNum); PhnAddressList addressList=NULL; error=PhnLibGetOwnNumbers(refNum, &addressList); if (error) goto Exit; PhnAddressHandle address=NULL; error=PhnLibAPGetNth(refNum, addressList, 1, &address); if (!error && address) { char* number=PhnLibAPGetField(refNum, address, phnAddrFldPhone); MemHandleFree(address); if (number) { ebufAddStr(out, number); MemPtrFree(number); } else error=sysErrNotAllowed; } MemHandleFree(addressList); Exit: if (fNeedToRemove) SysLibRemove(refNum); return error; }
/* * 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; }
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; }
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); } }
/* SetFieldTextFromHandle -- Fills a field with contents of a handle * Args: * Word fieldID -- ID of field to fill, see cwimp.rpc file * VoidHand txtH -- Handle of String to fill ID with * Returns: * FieldPtr -- Ptr to the field set. */ FieldPtr SetFieldTextFromHandle(Word fieldID, VoidHand txtH) { Handle oldTxtH; FormPtr frm = FrmGetActiveForm(); FieldPtr fldP; fldP = FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, fieldID)); ErrNonFatalDisplayIf(!fldP, "missing field"); oldTxtH = FldGetTextHandle(fldP); FldSetTextHandle(fldP, (Handle) txtH); // FldEraseField( fldP ); FldDrawField(fldP); if (oldTxtH) MemHandleFree((VoidHand) oldTxtH); return fldP; }
/* Release a font resource */ void ReleaseFontResource ( MemHandle handle, FontResourceKind kind ) { if ( handle == NULL ) return; #ifdef SUPPORT_VFS_FONTS if ( kind == fontResourceVFS ) { MemHandleFree( handle ); } else #endif { DmReleaseResource( handle ); } return; }
void SetFieldFromHandle ( UInt16 fieldID, MemHandle txtH ) { MemHandle oldTxtH; /* Old text */ FormType * frmP; /* Form pointer */ FieldType * fldP; /* Field pointer */ frmP = FrmGetActiveForm(); /* Find form pointer */ fldP = FrmGetObjectPtr (frmP, FrmGetObjectIndex ( frmP, fieldID)); /* Find field pointer */ ErrNonFatalDisplayIf ( !fldP, "missing field"); /* Check if the current object exists */ oldTxtH = FldGetTextHandle(fldP); /* Find text pointer of old text */ FldSetTextHandle(fldP, txtH); /* Set the new text */ FldDrawField(fldP); /* Redraw field */ if (oldTxtH != NULL) /* Free up old text */ MemHandleFree(oldTxtH); }
static void PrvFreeGlobals(UInt16 refNum) { MemHandle gH; SysLibTblEntryType * libEntryP; /* Get our library globals handle */ libEntryP = SysLibTblEntry(refNum); ErrFatalDisplayIf(libEntryP == NULL, "invalid ZDicFont refNum"); gH = (MemHandle)(libEntryP->globalsP); /* Free our library globals */ if ( gH ) { /* clear our globals reference */ libEntryP->globalsP = NULL; /* free our globals */ MemHandleFree(gH); } }
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: SelectTime * * DESCRIPTION: Display a form showing a start and end time. * Allow the user to change the time and then * return them. * pTimeDiff. * * PARAMETERS: pStartTime - pointer to TimeType * pEndTime - pointer to TimeType * untimed - true if there isn't a time. * title - string containing the title * startOfDay - used when "All Day" button selected. * endOfDay - our used when "All Day" button selected. * startOfDisplay - first hour initially visible * * RETURNED: True if the time was changed by the user. * The first three parameters may change. * * REVISION HISTORY: * Name Date Description * ---- ---- ----------- * roger 12/2/94 Initial Revision * trev 08/12/97 made non modified passed variables constant * css 06/08/99 added new parameter & "All Day" button for gromit change. * ***********************************************************************/ Boolean SelectTime (TimeType * startTimeP, TimeType * endTimeP, Boolean untimed, const Char * titleP, Int16 startOfDay, Int16 endOfDay, Int16 startOfDisplay) { Int16 firstHour; Char startTimeText [timeStringLength]; Char endTimeText [timeStringLength]; Char timeChars [timeStringLength]; TimePtr timeP; FormType *originalForm, *frm; ListPtr hoursLst, minutesLst; ControlPtr startTimeCtl, endTimeCtl; EventType event; Boolean confirmed = false; MemHandle hoursItems; TimeType startTime, endTime, timeDiff; TimeFormatType timeFormat; ChangingTimeType changingTime; // Get the time format from the system preerances; timeFormat = (TimeFormatType)PrefGetPreference(prefTimeFormat); // Because this routine only deals with minutes in five minute // intervals we convert the proposed times from those passed. startTime.hours = startTimeP->hours; startTime.minutes = startTimeP->minutes; endTime.hours = endTimeP->hours; endTime.minutes = endTimeP->minutes; TimeDifference (&endTime, &startTime, &timeDiff); // Make sure the end time is displayable (clips at 11:55 pm) AdjustTimes (&startTime, &endTime, &timeDiff, changingStartTime); // Clear the buffer that holds written characters. *timeChars = 0; startOfDisplay = min (startOfDisplay, 12); originalForm = FrmGetActiveForm(); frm = (FormType *) FrmInitForm (TimeSelectorForm); FrmSetActiveForm (frm); hoursLst = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, TimeSelectorHourList)); minutesLst = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, TimeSelectorMinuteList)); startTimeCtl = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, TimeSelectorStartTimeButton)); endTimeCtl = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, TimeSelectorEndTimeButton)); // Set list to use either 12 or 24 hour time hoursItems = SysFormPointerArrayToStrings ( ((timeFormat == tfColon24h) || (timeFormat == tfDot24h)) ? (Char *) Hours24Array() : (Char *) Hours12Array(), 24); LstSetListChoices (hoursLst, MemHandleLock(hoursItems), 24); LstSetTopItem (hoursLst, startOfDisplay); // Used to do LstMakeItemVisible (hoursLst, startTime.hours); no longer. if (! untimed) { LstSetSelection (hoursLst, startTime.hours); LstSetSelection (minutesLst, startTime.minutes / 5); CtlSetValue (startTimeCtl, true); changingTime = changingStartTime; } else { // The hour list is dynamically created and doesn't have a selection LstSetSelection (minutesLst, noListSelection); changingTime = changingNoTime; } // Set the start and end time buttons to the current times or blank them // if No Time is selected. SetTimeTriggers (startTime, endTime, startTimeText, endTimeText, timeFormat, untimed); // This needs to be taken out when SelectTimeV33 goes away. It allows for backward // compatibility for this change of adding the end of day variable as a parameter. if (endOfDay != noDisplayOfAllDay) { FrmShowObject (frm, FrmGetObjectIndex (frm, TimeSelectorAllDayButton)); } FrmSetTitle (frm, (Char *) titleP); FrmDrawForm (frm); while (true) { EvtGetEvent (&event, evtWaitForever); if (SysHandleEvent ((EventType *)&event)) continue; if (event.eType == appStopEvent) { // Cancel the dialog and repost this event for the app EvtAddEventToQueue(&event); confirmed = false; break; } // Handle these before the form does to overide the default behavior if (changingTime == changingNoTime && event.eType == lstEnterEvent && event.data.lstEnter.listID == TimeSelectorMinuteList) { SndPlaySystemSound(sndError); continue; } FrmHandleEvent (frm, &event); // If the start or end time buttons are pressed then change // the time displayed in the lists. if (event.eType == ctlSelectEvent) { // "Ok" button pressed? if (event.data.ctlSelect.controlID == TimeSelectorOKButton) { confirmed = true; } // "Cancel" button pressed? else if (event.data.ctlSelect.controlID == TimeSelectorCancelButton) { break; } // Start time button pressed? else if (event.data.ctlSelect.controlID == TimeSelectorStartTimeButton) { if (changingTime != changingStartTime) { if (changingTime == changingNoTime) { SetTimeTriggers (startTime, endTime, startTimeText, endTimeText, timeFormat, false); } CtlSetValue (endTimeCtl, false); LstSetSelection (hoursLst, startTime.hours); LstSetSelection (minutesLst, startTime.minutes / 5); changingTime = changingStartTime; } else CtlSetValue(startTimeCtl, true); } // End time button pressed? else if (event.data.ctlSelect.controlID == TimeSelectorEndTimeButton) { if (changingTime != changingEndTime) { if (changingTime == changingNoTime) { SetTimeTriggers (startTime, endTime, startTimeText, endTimeText, timeFormat, false); } CtlSetValue(startTimeCtl, false); LstSetSelection (hoursLst, endTime.hours); LstSetSelection (minutesLst, endTime.minutes / 5); changingTime = changingEndTime; } else CtlSetValue(endTimeCtl, true); } // No time button pressed? else if (event.data.ctlSelect.controlID == TimeSelectorNoTimeButton) { if (changingTime != changingNoTime) { if (changingTime == changingStartTime) CtlSetValue(startTimeCtl, false); else CtlSetValue(endTimeCtl, false); SetTimeTriggers (startTime, endTime, startTimeText, endTimeText, timeFormat, true); LstSetSelection (hoursLst, noListSelection); LstSetSelection (minutesLst, noListSelection); changingTime = changingNoTime; } // Get us out of this form display now. confirmed = true; } // All day button pressed? else if (event.data.ctlSelect.controlID == TimeSelectorAllDayButton) { if (changingTime != changingNoTime) { if (changingTime == changingStartTime) CtlSetValue(startTimeCtl, false); else CtlSetValue(endTimeCtl, false); LstSetSelection (hoursLst, noListSelection); LstSetSelection (minutesLst, noListSelection); changingTime = changingNoTime; } // No matter what, the minutes are 0 for both because only the hour is registered for start/end // times. startTime.minutes = 0; endTime.minutes = 0; startTime.hours = startOfDay; endTime.hours = endOfDay; // Set the times to the new times. SetTimeTriggers (startTime, endTime, startTimeText, endTimeText, timeFormat, true); // Get us out of this form display now. First set the changing time to anything but the changingNoTime value // so that the pointers at the end of this function get set correctly. changingTime = changingStartTime; confirmed = true; } // Clear the buffer that holds written characters. *timeChars = 0; } // If either list is changed then get the new time. If the // start time is changed then change the end time so that the // the time difference remains the same. If the end time is // changed then make sure the end time isn't before the start // time. Also calculate a new time difference. else if (event.eType == lstSelectEvent) { // First, get the info from the list which has changed. if (event.data.lstSelect.listID == TimeSelectorHourList) { if (changingTime == changingStartTime) startTime.hours = (UInt8) LstGetSelection (hoursLst); else if (changingTime == changingEndTime) endTime.hours = (UInt8) LstGetSelection (hoursLst); else if (changingTime == changingNoTime) { startTime.hours = (UInt8) LstGetSelection (hoursLst); SetTimeTriggers (startTime, endTime, startTimeText, endTimeText, timeFormat, false); CtlSetValue (endTimeCtl, false); LstSetSelection (minutesLst, startTime.minutes / 5); changingTime = changingStartTime; } } else if (event.data.lstSelect.listID == TimeSelectorMinuteList) { if (changingTime == changingStartTime) startTime.minutes = (UInt8) LstGetSelection (minutesLst) * 5; else if (changingTime == changingEndTime) endTime.minutes = (UInt8) LstGetSelection (minutesLst) * 5; else if (changingTime == changingNoTime) { ErrNonFatalDisplay("lstEnterEvent not being filtered."); } } if (AdjustTimes (&startTime, &endTime, &timeDiff, changingTime)) { if (changingTime == changingStartTime) { TimeToAscii (startTime.hours, startTime.minutes, timeFormat, startTimeText); CtlSetLabel (startTimeCtl, startTimeText); } else if (changingTime == changingEndTime) { LstSetSelection (hoursLst, startTime.hours); LstSetSelection (minutesLst, startTime.minutes / 5); } } TimeToAscii(endTime.hours, endTime.minutes, timeFormat, endTimeText); CtlSetLabel(endTimeCtl, endTimeText); // Clear the buffer that holds written characters. *timeChars = 0; } // Handle character written in the time picker. else if (event.eType == keyDownEvent) { if (changingTime == changingEndTime) { timeP = &endTime; firstHour = startTime.hours; } else { timeP = &startTime; firstHour = startOfDisplay; } // If a backspace character was written, change the time picker's // current setting to "no-time". if (event.data.keyDown.chr == backspaceChr) { *timeChars = 0; if (changingTime != changingNoTime) { if (changingTime == changingStartTime) CtlSetValue (startTimeCtl, false); else CtlSetValue (endTimeCtl, false); SetTimeTriggers (startTime, endTime, startTimeText, endTimeText, timeFormat, true); LstSetSelection (hoursLst, noListSelection); LstSetSelection (minutesLst, noListSelection); changingTime = changingNoTime; } } // A linefeed character confirms the dialog box. else if (event.data.keyDown.chr == linefeedChr) { confirmed = true; } // If next-field character toggle between start time in end // time. else if (event.data.keyDown.chr == nextFieldChr) { *timeChars = 0; if (changingTime == changingStartTime) { CtlSetValue (startTimeCtl, false); CtlSetValue (endTimeCtl, true); changingTime = changingEndTime; } else { CtlSetValue (endTimeCtl, false); CtlSetValue (startTimeCtl, true); changingTime = changingStartTime; } } // If a valid time character was written, translate the written // character into a time and update the time picker's UI. else if (TranslateTime (timeFormat, event.data.keyDown.chr, firstHour, timeChars, timeP)) { if (changingTime == changingNoTime) { changingTime = changingStartTime; CtlSetValue (startTimeCtl, true); } AdjustTimes (&startTime, &endTime, &timeDiff, changingTime); SetTimeTriggers (startTime, endTime, startTimeText, endTimeText, timeFormat, false); LstSetSelection (hoursLst, timeP->hours); LstSetSelection (minutesLst, timeP->minutes / 5); } } // Has the dialog been confirmed. if (confirmed) { if (changingTime != changingNoTime) { *startTimeP = startTime; *endTimeP = endTime; } else { TimeToInt(*startTimeP) = noTime; TimeToInt(*endTimeP) = noTime; } break; } } FrmEraseForm (frm); FrmDeleteForm (frm); MemHandleFree (hoursItems); FrmSetActiveForm(originalForm); return (confirmed); }
/*********************************************************************** * * FUNCTION: ThumbnailViewHandleEvent * * DESCRIPTION: This routine is the event handler for the "Thumbnail View" * of the Record application. * * PARAMETERS: event - a pointer to an EventType structure * * RETURNED: true if the event was handled and should not be passed * to a higher level handler. * ***********************************************************************/ Boolean ThumbnailViewHandleEvent (EventPtr event) { FormPtr frm = NULL; Boolean handled = false; switch (event->eType) { case keyDownEvent: /* Hardware button pressed? */ if (TxtCharIsHardKey(event->data.keyDown.modifiers, event->data.keyDown.chr)) { if (!(event->data.keyDown.modifiers & poweredOnKeyMask)) ThumbnailViewNextCategory(); handled = true; } else if (EvtKeydownIsVirtual(event)) { switch (event->data.keyDown.chr) { case vchrPageUp: case vchrRockerUp: if (d.fiveWayNavigation) { /* Deselect previous item */ ToggleButton(d.thumbnailX, d.thumbnailY, false); /* Select new item, scroll if necessary */ if (ThumbnailViewMoveCursorUp()) ThumbnailViewScroll(-1); UpdateButtonAndIndex(); } else { ThumbnailViewPageScroll(winUp); } handled = true; break; case vchrPageDown: case vchrRockerDown: if (d.fiveWayNavigation) { /* Deselect previous item */ ToggleButton(d.thumbnailX, d.thumbnailY, false); /* Select new item, scroll if necessary */ if (ThumbnailViewMoveCursorDown()) ThumbnailViewScroll(1); UpdateButtonAndIndex(); } else { ThumbnailViewPageScroll(winDown); } handled = true; break; /* Treo 600 5-way navigation */ case vchrRockerCenter: handled = ThumbnailViewHandleFiveWayNavSelect(); break; case vchrRockerLeft: handled = ThumbnailViewHandleFiveWayNavLeft(); break; case vchrRockerRight: handled = ThumbnailViewHandleFiveWayNavRight(); break; /* Tungsten 5-way navigation */ case vchrNavChange: if (NavDirectionPressed(event, Left)) handled = ThumbnailViewHandleFiveWayNavLeft(); else if (NavDirectionPressed(event, Right)) handled = ThumbnailViewHandleFiveWayNavRight(); else if (NavSelectPressed(event)) handled = ThumbnailViewHandleFiveWayNavSelect(); break; /* case vchrSendData: */ /* ThumbnailViewDoCommand(ThumbnailRecordBeamCategoryCmd); */ /* handled = true; */ /* break; */ default: /* ignore */ } } break; case ctlSelectEvent: switch (event->data.ctlSelect.controlID) { case NewButton: /* Create new sketch after all existing ones */ p.dbI = DmNumRecords(d.dbR); AllocImage(); FrmGotoForm(p.flags & PFLAGS_WITH_TITLEBAR ? DiddleTForm : DiddleForm); handled = true; break; case CategoryPop: ThumbnailViewSelectCategory(); handled = true; break; case TextListButton: FrmGotoForm(DiddleListForm); handled = true; break; case ThumbnailDetailListButton: FrmGotoForm(DiddleThumbnailDetailForm); handled = true; break; } break; case frmGotoEvent: p.dbI = event->data.frmGoto.recordNum; SwitchCategoryForGoto(); FrmGotoForm(p.flags & PFLAGS_WITH_TITLEBAR ? DiddleTForm : DiddleForm); event->eType = dbOpenRecordFieldEvent; EvtAddEventToQueue(event); handled = true; break; case menuEvent: { Char chr = 0; switch(event->data.menu.itemID) { case menuitemID_CmdAbout: DoAboutDialog(); handled = true; break; case menuitemID_CmdSecurity: ThumbnailDoCmdSecurity(); handled = true; break; case menuitemID_CmdSortByAlarm: case menuitemID_CmdSortByName: if (event->data.menu.itemID == menuitemID_CmdSortByAlarm) DmInsertionSort(d.dbR, &SortByAlarmTime, 0); else DmInsertionSort(d.dbR, &SortByName, 0); SetTopVisibleRecord(0); ThumbnailViewLoadRecords(FrmGetActiveForm()); handled = true; break; case menuitemID_CmdPref: chr=cmdPref; break; case menuitemID_CmdExtPref: chr=cmdExtPref; break; case menuitemID_CmdHWPref: chr=cmdHWPref; break; case menuitemID_CmdAlarmPref: chr=cmdAlarmPref; break; case menuitemID_CmdHelp: chr=cmdHelp; break; } if (!handled) handled = KeyDown(chr); } break; case frmOpenEvent: frm = FrmGetActiveForm(); ThumbnailViewInit(frm); FrmDrawForm(frm); /* Disable 5-way navigation initially */ d.fiveWayNavigation = false; /* Clean up */ if (d.record_name) MemHandleFree(d.record_name); d.record_name = NULL; if (d.record_note) MemHandleFree(d.record_note); d.record_note = NULL; handled = true; break; case frmUpdateEvent: handled = ThumbnailViewUpdateDisplay(event->data.frmUpdate.updateCode); break; case menuCmdBarOpenEvent: MenuCmdBarAddButton(menuCmdBarOnLeft, BarSecureBitmap, menuCmdBarResultMenuItem, menuitemID_CmdSecurity, 0); /* Tell the field package to not add buttons automatically; */ /* we've done it all ourselves. */ event->data.menuCmdBarOpen.preventFieldButtons = true; /* don't set handled to true; this event must fall through to the system. */ break; case sclRepeatEvent: ThumbnailViewScroll (event->data.sclRepeat.newValue - event->data.sclRepeat.value); break; case dbNonKeyCommandEvent: handled = HandleNonKeyCommandCode(event->data.menu.itemID); break; /* case frmObjectFocusTakeEvent: */ /* { */ /* RectangleType r; */ /* FormType* frm = FrmGetFormPtr(event->data.frmObjectFocusTake.formID); */ /* const UInt16 id = event->data.frmObjectFocusTake.objectID; */ /* const UInt16 idx = FrmGetObjectIndex(frm, id); */ /* if (id >= Thumb1 && id <= Thumb30) { */ /* FrmGetObjectBounds(frm, idx, &r); */ /* FrmSetFocus(frm, idx); */ /* HsNavDrawFocusRing(frm, id, hsNavFocusRingNoExtraInfo, &r, */ /* hsNavFocusRingStyleObjectTypeDefault, false); */ /* handled = true; */ /* } */ /* } */ /* break; */ default: /* do nothing */ } return handled; }
/************************************************************ * * 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; }
UInt16 CourseListGen(Char **itemList, UInt16 *courseID, UInt16 *courseInd, UInt16 numItems, UInt16 curInd, UInt8 searchFor) { UInt16 index=0, i=0, rv=0; MemHandle m; UInt16 *tmpCourseInd=NULL; if (courseInd == NULL) tmpCourseInd = (UInt16 *)MemPtrNew(numItems * sizeof(UInt16)); while((i < numItems) && ((m = DmQueryNextInCategory(DatabaseGetRef(), &index, DatabaseGetCat())) != NULL)) { Char *s=(Char *)MemHandleLock(m); if (s[0] == TYPE_COURSE) { UInt16 j; CourseDBRecord c; Char *tempString; MemHandle shortType=MemHandleNew(1); UnpackCourse(&c, s); tempString=(Char *)MemPtrNew(StrLen(c.name)+3+StrLen(c.teacherName)+CTYPE_SHORT_MAXLENGTH+CTYPE_ADD_MAXLENGTH+1); CourseTypeGetShort(&shortType, c.ctype); // StrPrintF(shortType, "T"); StrPrintF(tempString, "%s (%s) [%s]", c.name, c.teacherName, (Char *)MemHandleLock(shortType)); MemHandleUnlock(shortType); MemHandleFree(shortType); // Do a nice insertion sort here. DatAlg MUST have been good for something :-) j = i; while ( (j > 0) && (StrCompare(itemList[j-1], tempString) > 0) ) { itemList[j] = itemList[j-1]; if (courseInd != NULL) courseInd[j]=courseInd[j-1]; else tmpCourseInd[j]=tmpCourseInd[j-1]; if (courseID != NULL) courseID[j]=courseID[j-1]; j -= 1; } itemList[j]=tempString; if (courseInd != NULL) courseInd[j]=index; else tmpCourseInd[j]=index; if (courseID != NULL) courseID[j]=c.id; i += 1; } MemHandleUnlock(m); index += 1; } // We iterate through all to get the item to be selected // We could do that in the loop above, but we would need // a) to mess with insertion sort (make it slow) // b) to make the code ugly at two points // c) We don't care since we expect about 20 courses, that's nothing to iterate... // We implement the loop multiple times (once for each search type, last param) // so that we do not need a condition inside the loop for every run i = 0; if (searchFor == CLIST_SEARCH_INDEX) { while (! rv && (i < numItems)) { if (courseInd == NULL) { if (tmpCourseInd[i] == curInd) rv = i; } else { if (courseInd[i] == curInd) rv = i; } i += 1; } } else if ((searchFor == CLIST_SEARCH_ID) && (courseID != NULL)) { while (! rv && (i < numItems)) { if (courseID[i] == curInd) rv = i; i += 1; } } if (tmpCourseInd != NULL) MemPtrFree((MemPtr)tmpCourseInd); return rv; }