/*********************************************************************** * * FUNCTION: PrvCreateTimeZoneArray * * DESCRIPTION: Create the array of time zone entries from our string * list, gtm offset list, and country list resources. Sort based on * time zone name. * * DOLATER kwk - we could save the time zone array we're creating here * in memory, to avoid the performance hit of creating the array. * On the other hand, then the list of names would need to stay * locked down, unless we also copy those into the memory buffer, * which means another 700+ bytes. * * PARAMETERS: * timeZoneNames <-> Ptr to returned handle to list of names. * numTimeZones <-> Ptr to count of number of time zones. * * RETURNED: * Ptr to allocated array of time zone entry records. * * HISTORY: * 07/31/00 kwk Created by Ken Krugler. * 08/23/00 kwk Fixed bug where release ROMs caused ErrNonFatalDisplayIf * to become a no-op, and thus the country and time zone * offset list ptrs weren't skipping the count word. * ***********************************************************************/ static TimeZoneEntryType* PrvCreateTimeZoneArray(MemHandle* timeZoneNames, UInt16* numTimeZones) { const Char* tzNamesP; TimeZoneEntryType* tzEntries; MemHandle offsetsH; MemHandle countriesH; UInt16* resP; Int16* gmtOffsetsP; UInt16* countriesP; UInt16 i; // Specify the number of items in the list, based on total # of items // in our time zone name list resource. *timeZoneNames = DmGetResource(strListRscType, TimeZoneNamesStringList); ErrNonFatalDisplayIf(*timeZoneNames == NULL, "No time zone names"); tzNamesP = (const Char*)MemHandleLock(*timeZoneNames); // Skip over prefix string, then get the entry count. tzNamesP += StrLen(tzNamesP) + 1; *numTimeZones = *tzNamesP++; *numTimeZones = (*numTimeZones << 8) + *tzNamesP++; // Allocate the array of time zone records. tzEntries = (TimeZoneEntryType*)MemPtrNew(*numTimeZones * sizeof(TimeZoneEntryType)); ErrFatalDisplayIf(tzEntries == NULL, "Out of memory"); // Find and lock down the gtm offset and country integer lists. offsetsH = DmGetResource(wrdListRscType, TimeZoneGMTOffsetsList); ErrNonFatalDisplayIf(offsetsH == NULL, "No time zone offsets"); resP = (UInt16*)MemHandleLock(offsetsH); ErrNonFatalDisplayIf(*resP != *numTimeZones, "GMT offset count != name count"); // Skip count at start of list. gmtOffsetsP = (Int16*)resP + 1; countriesH = DmGetResource(wrdListRscType, TimeZoneCountriesList); ErrNonFatalDisplayIf(countriesH == NULL, "No time zone countries"); resP = (UInt16*)MemHandleLock(countriesH); ErrNonFatalDisplayIf(*resP != *numTimeZones, "Time zone country count != name count"); // Skip count at start of list. countriesP = resP + 1; // Now loop to fill in all of the records. for (i = 0; i < *numTimeZones; i++) { tzEntries[i].tzName = tzNamesP; tzNamesP += StrLen(tzNamesP) + 1; tzEntries[i].tzOffset = gmtOffsetsP[i]; tzEntries[i].tzCountry = (CountryType)countriesP[i]; } MemHandleUnlock(offsetsH); MemHandleUnlock(countriesH); // Now sort the list, based on the time zone name. SysQSort(tzEntries, *numTimeZones, sizeof(TimeZoneEntryType), PrvCompareTimeZoneEntries, 0); return(tzEntries); } // PrvCreateTimeZoneArray
/*********************************************************************** * * FUNCTION: ZDicFontInit * * DESCRIPTION: Initial all font resource * * PARAMETERS: nothing * * RETURN: errNone if success else fail. * * REVISION HISTORY: * Name Date Description * ---- ---- ----------- * ZhongYuanHuan 14/Aug/04 Initial Revision * ***********************************************************************/ Err ZDicFontInit ( UInt16 refNum, ZDicFontType* fontP, Boolean bUseSysFont ) { #pragma unused(refNum) UInt32 version; Err err; MemSet ( fontP, sizeof ( ZDicFontType ), 0 ); fontP->smallFontID = stdFont; fontP->largeFontID = largeFont; if ( bUseSysFont ) return errNone; fontP->fontLibP = DmOpenDatabaseByTypeCreator ( ZDicFontTypeID, ZDicFontCreatorID, dmModeReadOnly ); if ( fontP->fontLibP == 0 ) { err = DmGetLastErr (); return err; } // Load the phonic font resource and assign it a font ID. err = FtrGet(sysFtrCreator, sysFtrNumWinVersion, &version); if (!err && version >= 4 ) { // the screen is double density so use double density of phonetic font. fontP->phonicSmallFontH = DmGetResource('nfnt', PhonicSmallFontHight); fontP->phonicLargeFontH = DmGetResource('nfnt', PhonicLargeFontHight); } if (fontP->phonicSmallFontH == NULL || fontP->phonicLargeFontH == NULL) { if (fontP->phonicSmallFontH != NULL) DmReleaseResource(fontP->phonicSmallFontH); if (fontP->phonicLargeFontH != NULL) DmReleaseResource(fontP->phonicLargeFontH); // the screen is low desity so use low density of phonetic font. fontP->phonicSmallFontH = DmGetResource(fontRscType, PhonicSmallFontLow); fontP->phonicLargeFontH = DmGetResource(fontRscType, PhonicLargeFontLow); } fontP->phonicSmallFontP = (FontType *)MemHandleLock(fontP->phonicSmallFontH); fontP->phonicLargeFontP = (FontType *)MemHandleLock(fontP->phonicLargeFontH); err = FntDefineFont(kPHONIC_SMALL_FONT_ID, fontP->phonicSmallFontP); err = FntDefineFont(kPHONIC_LARGE_FONT_ID, fontP->phonicLargeFontP); fontP->smallFontID = kPHONIC_SMALL_FONT_ID; fontP->largeFontID = kPHONIC_LARGE_FONT_ID; return errNone; }
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); } }
/*********************************************************************** * * FUNCTION: PrvSetTimeField * * DESCRIPTION: Set the given field's text to show a time and day of week. * * PARAMETERS: frm - a pointer to the form containing the field to set * timeFieldID - the ID of the field to set * timeHandle - the handle used for storing the text for this field * time - a pointer to the date and time to show in the field * drawField - whether to draw field after setting its text * * RETURNED: nothing * * REVISION HISTORY: * Name Date Description * ---- ---- ----------- * peter 3/7/00 Initial Revision * ***********************************************************************/ static void PrvSetTimeField(FormType * frm, UInt16 timeFieldID, MemHandle timeHandle, DateTimeType *time, Boolean drawField) { FieldType * timeFieldP; Char * timeString, * timeZoneDOWFormatString, * currentDOWString; MemHandle resHandle; TimeFormatType timeFormat; // Format to display time in timeFormat = (TimeFormatType)PrefGetPreference(prefTimeFormat); timeString = MemHandleLock(timeHandle); TimeToAscii(time->hour, time->minute, timeFormat, timeString); currentDOWString = timeString + StrLen(timeString); currentDOWString[0] = ' '; currentDOWString++; resHandle = DmGetResource(strRsc, DOWformatString); ErrNonFatalDisplayIf(resHandle == NULL, "Missing string resource"); timeZoneDOWFormatString = MemHandleLock(resHandle); DateTemplateToAscii(timeZoneDOWFormatString, time->month, time->day, time->year, currentDOWString, dowLongDateStrLength); MemHandleUnlock(resHandle); MemHandleUnlock(timeHandle); timeFieldP = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, timeFieldID)); FldSetTextHandle(timeFieldP, timeHandle); if (drawField) FldDrawField(timeFieldP); }
void String_Init() { MemHandle Resource; DmResID Id; context* p = Context(); StringAlloc(); for (Id=1000;Id<1000+32;++Id) { Resource = DmGetResource('lang',Id); if (Resource) { int Size = MemHandleSize(Resource); void* Data = MemHandleLock(Resource); if (Size && Data && StringAddBinary(Data,Size)) ArrayAppend(&p->StrModule,&Resource,sizeof(Resource),16); else { if (Data) MemHandleUnlock(Resource); DmReleaseResource(Resource); } } } }
/* ** DrawBitmap */ static void DrawBitmap(UInt16 bitmapID, Coord x, Coord y) { const MemHandle bitmapH = DmGetResource(bitmapRsc, bitmapID); WinDrawBitmap(MemHandleLock(bitmapH), x, y); /* Clean up */ MemHandleUnlock(bitmapH); DmReleaseResource(bitmapH); }
static void playJavaSound() { MemHandle jvHandle; SndPtr jvPtr; jvHandle=DmGetResource('wave',JavaVoice); if(!jvHandle) { return; } jvPtr=MemHandleLock(jvHandle); SndPlayResource(jvPtr,1024,sndFlagAsync); MemHandleUnlock(jvHandle); }
/* 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 Plugin_Search ( void ) { #if 0 // The following code will locate our plug-in resource (which may be in our own // resource file or in a separate PRC file to be opened by type and creator as // demonstrated below) DmSearchStateType searchState; UInt16 tempCardNo[32]; MemHandle tempPlugInResH; // handle to our plug-in resource Boolean newSearch = true; LocalID tempPlugInDbID[32]; Err theErr = 0; UInt8 i = 0; Plug_ParamBlock plugInParamBlock; // The following code could be modified to iterate through // multiple (separate) plug-in database(s), if desired... do { theErr = DmGetNextDatabaseByTypeCreator(newSearch, &searchState, kPlugInFileType, kPlugInFileCreator, false /* all versions */, &tempCardNo[i], &tempPlugInDbID[i]); newSearch = false; if ( !theErr ) i++; } while ( !theErr ); if (theErr) { // no plug-in database found tempPlugInDbID = 0; gPlugInDbRef = 0; } else { // we found a plug-in database if (tempPlugInDbID) { // open the plug-in database gPlugInDbRef = DmOpenDatabase(tempCardNo, tempPlugInDbID, dmModeReadOnly); } } // Get a handle to our plug-in resource tempPlugInResH = DmGetResource(kPlugInResourceType, kFirstPlugInResID); // Make sure we found it if (!tempPlugInResH) return 1; // Lock down the plug-in so it doesn't move gPlugInResP = (Plug_Main *) MemHandleLock(tempPlugInResH); plugInParamBlock.eType = cmdStartup; plugInParamBlock.hostVersion = plugVersion; (*gPlugInResP)(&plugInParamBlock); #endif return 0; }
/***************************************************************************** * Function: GadgetDrawWeekdays * * Description: Draws the weekdays, extra function since called in * GadgetDrawTimeline *****************************************************************************/ void GadgetDrawWeekdays(void) { UInt8 i; MemHandle mh; Char *text; RGBColorType color, prevColor; DateTimeType now; Int16 dow; RectangleType bounds, rect; UInt16 gadgetIndex; // Get info about Gadget gadgetIndex = FrmGetObjectIndex(gForm, gGadgetID); FrmGetObjectBounds(gForm, gadgetIndex, &bounds); // Initialize time constants TimSecondsToDateTime(TimGetSeconds(), &now); dow = DayOfWeek(now.month, now.day, now.year); RctSetRectangle(&rect, bounds.topLeft.x+GADGET_BASELEFT+GADGET_LEFT, bounds.topLeft.y, 130, FntLineHeight()+2); // Erase background WinEraseRectangle(&rect, 0); for (i=0; i < gGadgetDaysNum; ++i) { Int16 leftoff; mh = DmGetResource(strRsc, GADGET_STRINGS_WDAYSTART+i); text = MemHandleLock(mh); leftoff = (gGadgetDaysWidth+2 - FntLineWidth(text, MemPtrSize(text))) / 2; if (TNisColored() && (dow == i+1)) { color.r = 0xFF; color.g = 0x00; color.b = 0x00; TNSetTextColorRGB(&color, &prevColor); } WinDrawChars(text, StrLen(text), bounds.topLeft.x+GADGET_BASELEFT+GADGET_LEFT+i*gGadgetDaysWidth+i+leftoff+2, bounds.topLeft.y); if (dow == i+1) { if (TNisColored()) { TNSetTextColorRGB(&prevColor, NULL); } else { // Draw some kind of underline to determine current day Int16 lineWidth=FntLineWidth(text, StrLen(text)); WinDrawLine(rect.topLeft.x+i*gGadgetDaysWidth+i+leftoff+1, rect.topLeft.y+FntLineHeight(), rect.topLeft.x+i*gGadgetDaysWidth+i+leftoff+1+lineWidth, rect.topLeft.y+FntLineHeight()); } } MemHandleUnlock(mh); } }
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)); } }
/*********************************************************************** * * FUNCTION: RepeatSelectEndDate * * DESCRIPTION: This routine selects the end date of a repeating event. * * PARAMETERS: event - pointer to a popup select event * * RETURNED: nothing * ***********************************************************************/ static void RepeatSelectEndDate(EventType* event) { Int16 month, day, year; Char* titleP = NULL; MemHandle titleH = NULL; /* "No due date" items selected? */ if (event->data.popSelect.selection == repeatNoEndDateItem) DateToInt(d.repeat_end_date) = apptNoEndDate; /* "Select date" item selected? */ else if (event->data.popSelect.selection == repeatChooseDateItem) { if (DateToInt (d.repeat_end_date) == apptNoEndDate) { year = d.frm_date.year; month = d.frm_date.month; day = d.frm_date.day; } else { year = d.repeat_end_date.year + firstYear; month = d.repeat_end_date.month; day = d.repeat_end_date.day; } titleH = DmGetResource(strRsc, endDateTitleString); titleP = MemHandleLock(titleH); if (SelectDay (selectDayByDay, &month, &day, &year, titleP)) { d.repeat_end_date.day = day; d.repeat_end_date.month = month; d.repeat_end_date.year = year - firstYear; /* Make sure the end date is not before the start date. */ if (DateToInt(d.repeat_end_date) < DateToInt (d.frm_date)) { SndPlaySystemSound (sndError); DateToInt (d.repeat_end_date) = apptNoEndDate; } } MemHandleUnlock(titleH); } RepeatSetDateTrigger(d.repeat_end_date); }
/* Get a font resource in the current user font */ MemHandle GetFontResource ( UInt32 resourceType, UInt32 resourceID, FontResourceKind* resourceKindP ) { #ifdef SUPPORT_VFS_FONTS if ( currentFontIsOnVFS ) { Err err; MemHandle handle; err = VFSFileDBGetResource( currentVFSFontRef, resourceType, resourceID, &handle ); if ( err == errNone ) { *resourceKindP = fontResourceVFS; return handle; } } #endif *resourceKindP = fontResourceStorage; return DmGetResource( resourceType, resourceID ); }
void IntlInit(void) { Err result; MemHandle localeCodeH; MemHandle tableListH; MemHandle featureTableH; ROMFtrTableType* featureTableP; ROMFtrCreatorType* creatorTableP; UInt16 creators; Boolean fastSort = true; Boolean fastSearch = true; Boolean fastAttr = true; UInt16 index; UInt32 intlFtrFlags; #if (EMULATION_LEVEL == EMULATION_NONE) UInt16 systemCard; LocalID systemID; DmSearchStateType* searchStateP; MemHandle localeNameH; LocalID moduleID; DmOpenRef moduleRef; // Locate the system DB, so that we know where to look (which card) // for the locale module. searchStateP = (DmSearchStateType*)MemPtrNew(sizeof(DmSearchStateType)); result = DmGetNextDatabaseByTypeCreator( true, searchStateP, sysFileTSystem, sysFileCSystem, true, // onlyLatestVers &systemCard, &systemID); ErrNonFatalDisplayIf((result != errNone) || (systemID == 0), "Can't find system DB"); MemPtrFree((MemPtr)searchStateP); localeNameH = DmGetResource(strRsc, localeModuleNameStrID); ErrNonFatalDisplayIf(localeNameH == NULL, "Missing locale module name string"); moduleID = DmFindDatabaseWithTypeCreator( systemCard, (Char*)MemHandleLock(localeNameH), sysFileTLocaleModule, sysFileCSystem); MemHandleUnlock(localeNameH); if (moduleID != 0) { moduleRef = DmOpenDatabase(systemCard, moduleID, dmModeReadOnly | dmModeLeaveOpen); ErrNonFatalDisplayIf(moduleRef == 0, "Can't open locale module"); if (ResLoadConstant(kIntlLMVersResID) != kIntlLMVersion) { DmCloseDatabase(moduleRef); moduleID = 0; } } // If we couldn't find the locale module, or it has the wrong version, then // default to the ROM locale's locale module. if (moduleID == 0) { SysNVParamsType* romParamsP; OmLocaleType romLocale; Char* overlayName; LocalID overlayID; DmOpenRef overlayRef; Char* systemName; // Open up the system overlay that corresponds to the ROM's locale. // Note that (assuming the ROM locale != current locale) we have to // try to open up the overlay explicitly, since the Overlay Mgr // won't be opening it automatically. We also have to handle the case // of a ROM built without overlays, in which case the ROM locale's // locale module name string is located in the base, which means we // have to make a low-level resource call to get it (otherwise we'll // get the string from the system overlay). romParamsP = (SysNVParamsType*)MemPtrNew(sizeof(SysNVParamsType)); MemGetRomNVParams(romParamsP); romLocale.country = romParamsP->localeCountry; romLocale.language = romParamsP->localeLanguage; MemPtrFree((MemPtr)romParamsP); // Get the name of the system DB, so that we can construct the overlay // name. systemName = (Char*)MemPtrNew(dmDBNameLength); overlayName = (Char*)MemPtrNew(dmDBNameLength); result = DmDatabaseInfo(systemCard, systemID, systemName, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); ErrNonFatalDisplayIf(result != errNone, "Can't get system DB info"); result = OmLocaleToOverlayDBName(systemName, &romLocale, overlayName); ErrNonFatalDisplayIf(result != errNone, "Can't make ROM locale system overlay name"); overlayID = DmFindDatabaseWithTypeCreator(systemCard, overlayName, sysFileTOverlay, sysFileCSystem); MemPtrFree(systemName); MemPtrFree((MemPtr)overlayName); if (overlayID != 0) { overlayRef = DmOpenDatabase(systemCard, overlayID, dmModeReadOnly); ErrNonFatalDisplayIf(overlayRef == 0, "Can't open system overlay"); // Now load the locale module name string from this overlay, and use // it to find the locale module. localeNameH = DmGet1Resource(strRsc, localeModuleNameStrID); ErrNonFatalDisplayIf(localeNameH == NULL, "Missing locale module name string"); moduleID = DmFindDatabaseWithTypeCreator( systemCard, (Char*)MemHandleLock(localeNameH), sysFileTLocaleModule, sysFileCSystem); MemHandleUnlock(localeNameH); DmCloseDatabase(overlayRef); } else { // Assume it's a ROM built without overlays, in which case we need to // get the locale name handle from the system base. DmOpenRef sysRef = NULL; Int16 index; do { LocalID dbID; sysRef = DmNextOpenResDatabase(sysRef); if ((sysRef != NULL) && (DmOpenDatabaseInfo(sysRef, &dbID, NULL, NULL, NULL, NULL) == errNone) && (dbID == systemID)) { break; } } while (sysRef != NULL); ErrNonFatalDisplayIf(sysRef == NULL, "Can't find system DB"); index = DmFindResource(sysRef, strRsc, localeModuleNameStrID, NULL); ErrNonFatalDisplayIf(index == -1, "Missing locale module name string"); localeNameH = DmGetResourceIndex(sysRef, index); ErrNonFatalDisplayIf(localeNameH == NULL, "Missing locale module name string"); moduleID = DmFindDatabaseWithTypeCreator( systemCard, (Char*)MemHandleLock(localeNameH), sysFileTLocaleModule, sysFileCSystem); } // If we found the locale module DB, open it up and make sure it has // the right version. if (moduleID != 0) { moduleRef = DmOpenDatabase(systemCard, moduleID, dmModeReadOnly | dmModeLeaveOpen); if ((moduleRef == 0) || (ResLoadConstant(kIntlLMVersResID) != kIntlLMVersion)) { // Trigger fatal alert below. No need to close the DB in that case. moduleID = 0; } else { // We found a valid locale module, using the ROM locale, so set // the current locale to be the ROM locale. result = FtrSet(sysFtrCreator, sysFtrNumLanguage, romLocale.language); if (result == errNone) { result = FtrSet(sysFtrCreator, sysFtrNumCountry, romLocale.country); } ErrNonFatalDisplayIf(result != errNone, "Can't switch current locale to ROM locale"); } } ErrFatalDisplayIf(moduleID == 0, "No valid locale module"); } result = DmDatabaseProtect(systemCard, moduleID, true); if (result != dmErrROMBased) { ErrNonFatalDisplayIf(result != errNone, "Can't protect locale module"); } #else // Give the locale module code in the Simulator a chance to // initialize itself. If there's no such code (e.g. with latin) then the // routine in SimStubs.cp does nothing. StubPalmOSInitLocaleModule(); #endif // If there's a locale module code resource, load & call it now. localeCodeH = DmGet1Resource(kIntlLMCodeType, kIntlLMCodeResID); if (localeCodeH != NULL) { ProcPtr localeCodeP = (ProcPtr)MemHandleLock(localeCodeH); (*localeCodeP)(); MemHandleUnlock(localeCodeH); } // If the IntlMgr data ptr hasn't been set up by the locale module code, // allocate it now. if (GIntlMgrGlobalsP == NULL) { UInt16 numCustomTransTables; MemPtr globalPtr; numCustomTransTables = ResLoadConstant(kIntlLMCustomTransCountID); ErrNonFatalDisplayIf(numCustomTransTables > kIntlMaxCustomTransliterations, "Too many custom transliterations"); globalPtr = MemPtrNew(sizeof(IntlGlobalsType) + (numCustomTransTables * sizeof(void*))); ErrNonFatalDisplayIf(globalPtr == NULL, "Out of memory"); MemSet(globalPtr, sizeof(IntlGlobalsType) + (numCustomTransTables * sizeof(void*)), 0); GIntlMgrGlobalsP = globalPtr; GIntlData->numCustomTransliterations = numCustomTransTables; } else { // If any of the sorting tables are already configured, we can't do // our fast sorting optimization. for (index = 0; index < kIntlMaxSortLevels; index++) { if (GIntlData->sortTables[index] != NULL) { fastSort = false; break; } } // If the word start or word match tables are already configured, we // can't do our fast word search optimization. if ((GIntlData->findWordStartTable != NULL) || (GIntlData->findWordMatchTable != NULL)) { fastSearch = false; } // If the character attribute table is already configured, we can't do // our fast attribute optimization. if (GIntlData->charAttrTable != NULL) { fastAttr = false; } } // Loop over all of the table resources, locking & setting up pointers in // the IntlMgr global data structure. tableListH = DmGet1Resource(kIntlLMTableListType, kIntlLMTableListResID); if (tableListH != NULL) { IntlLMTableEntryType* curTable; UInt8* globalsP = (UInt8*)GIntlMgrGlobalsP; IntlLMTableResType* tableListP = (IntlLMTableResType*)MemHandleLock(tableListH); for (index = 0, curTable = tableListP->resources; index < tableListP->numResources; index++, curTable++) { void** ptrLocation; MemHandle tableH; tableH = DmGet1Resource(curTable->resType, curTable->resID); ErrFatalDisplayIf(tableH == NULL, "Missing table resource from locale module"); ErrFatalDisplayIf(curTable->tableIndex >= intlLMNumTableIndexes, "Invalid table index"); ptrLocation = (void**)(globalsP + kIntlGlobalOffsets[curTable->tableIndex]); ErrFatalDisplayIf(*ptrLocation != NULL, "Resource overriding existing table ptr"); *ptrLocation = MemHandleLock(tableH); } MemHandleUnlock(tableListH); } // Note that we can't check for the presence of tables here, as a table that // is required by a Text Mgr routine might be NULL if the locale module has // patched out that routine. // As an optimization, see if all of the sorting tables are byte-indexed 8-bit // values. If so, then replace the table ptrs with ptrs to the actual data, // and set the fast sorting intl mgr flag. for (index = 0; (index < kIntlMaxSortLevels) && fastSort; index++) { void* sortTable = GIntlData->sortTables[index]; if (sortTable == NULL) { break; } else if (PrvGetByteIndexedTable(sortTable, 8) == NULL) { fastSort = false; } } if (fastSort) { GIntlData->intlFlags |= kByteSortingFlag; for (index = 0; index < kIntlMaxSortLevels; index++) { GIntlData->sortTables[index] = PrvGetByteIndexedTable(GIntlData->sortTables[index], 8); } } // As an optimization, see if all of the searching tables are byte-indexed 8-bit // values. If so, then replace the table ptrs with ptrs to the actual data, // and set the fast searching intl mgr flag. Note that PrvGetByteIndexedTable // will return NULL if findWordMatchTable is NULL, which is OK because then // TxtFindString must be patched out anyway. The findWordStartTable is optional, // and thus it can either be NULL or a byte indexed byte table. if ((fastSearch) && ((GIntlData->findWordStartTable == NULL) || (PrvGetByteIndexedTable(GIntlData->findWordStartTable, 8) != NULL)) && (PrvGetByteIndexedTable(GIntlData->findWordMatchTable, 8) != NULL)) { GIntlData->intlFlags |= kByteSearchingFlag; GIntlData->findWordStartTable = PrvGetByteIndexedTable(GIntlData->findWordStartTable, 8); GIntlData->findWordMatchTable = PrvGetByteIndexedTable(GIntlData->findWordMatchTable, 8); } // As an optimization, see if the character attribute table is a byte-indexed // table of 16-bit values. If so, then replace the table ptr with a ptr to // the data, and set the kByteCharAttrFlag flag. if (fastAttr && (PrvGetByteIndexedTable(GIntlData->charAttrTable, 16) != NULL)) { GIntlData->intlFlags |= kByteCharAttrFlag; GIntlData->charAttrTable = PrvGetByteIndexedTable(GIntlData->charAttrTable, 16); // As an optimization, see if the character attribute table is a stage index map // table of 16-bit values. If so, then replace the table ptr with a ptr to // the sub-table offsets, set up the result table ptr, and set the // kStageCharAttrFlag flag. } else if (fastAttr && PrvGetStageIndexMapTable(GIntlData->charAttrTable, 16)) { GIntlData->intlFlags |= kStageCharAttrFlag; GIntlData->charAttrTable = PrvGetStageIndexMapTable(GIntlData->charAttrTable, 16); } // If there's a doubleCharTable, we want to (a) verify that it's a byte-indexed // byte table, and (b) set up the pointer now. if (GIntlData->doubleCharTable != NULL) { void* tableP = PrvGetByteIndexedTable(GIntlData->doubleCharTable, 8); ErrNonFatalDisplayIf(tableP == NULL, "Double-char table isn't byte-indexed byte table"); GIntlData->doubleCharTable = tableP; } // Load the 'feat' resource from the locale module, and use it to initialize // various locale-specific features. Typically this includes sysFtrNumCharEncodingFlags, // sysFtrNumEncoding, sysFtrDefaultFont, and sysFtrDefaultBoldFont. // Try to load the 'feat' resource. featureTableH = DmGet1Resource(sysResTFeatures, kIntlLMFeatureResID); ErrFatalDisplayIf(featureTableH == NULL, "Missing feature table"); featureTableP = (ROMFtrTableType*)MemHandleLock(featureTableH); creatorTableP = featureTableP->creator; for (creators = 0; creators < featureTableP->numEntries; creators++) { UInt16 features; for (features = 0; features < creatorTableP->numEntries; features++) { result = FtrSet( creatorTableP->creator, creatorTableP->feature[features].num, creatorTableP->feature[features].value); ErrNonFatalDisplayIf(result != errNone, "Can't set locale feature"); } // Advance to next creator table. creatorTableP = (ROMFtrCreatorType*)((UInt8*)creatorTableP + sizeof(ROMFtrCreatorType) + (creatorTableP->numEntries * sizeof(ROMFtrFeatureType))); } MemHandleUnlock(featureTableH); // Now, set up our internal kByteSearchingFlag flag based on the sysFtrNumCharEncodingFlags // feature value. This means that sysFtrNumCharEncodingFlags is read-only, since if // anybody uses FtrSet to change the settings of the flags, that won't update // our internal flag(s). if ((FtrGet(sysFtrCreator, sysFtrNumCharEncodingFlags, &intlFtrFlags) == errNone) && ((intlFtrFlags & charEncodingOnlySingleByte) != 0)) { GIntlData->intlFlags |= kSingleByteOnlyFlag; } // Finally set the bit that tells everybody we're ready to support IntlMgr/TextMgr calls. FtrSet(sysFtrCreator, sysFtrNumIntlMgr, intlMgrExists); } // IntlInit
int wxMessageDialog::ShowModal() { int AlertID=1000; int Result=0; int wxResult=wxID_OK; const long style = GetMessageDialogStyle(); // Handle to the currently running application database DmOpenRef AppDB; SysGetModuleDatabase(SysGetRefNum(), NULL, &AppDB); // Translate wx styles into Palm OS styles if (style & wxYES_NO) { if (style & wxCANCEL) AlertID=1300; // Yes No Cancel else AlertID=1200; // Yes No } if (style & wxOK) { if (style & wxCANCEL) AlertID=1100; // Ok Cancel else AlertID=1000; // Ok } // Add the icon styles if (style & wxICON_EXCLAMATION) AlertID=AlertID+0; // Warning else if (style & wxICON_HAND) AlertID=AlertID+1; // Error else if (style & wxICON_INFORMATION) AlertID=AlertID+2; // Information else if (style & wxICON_QUESTION) AlertID=AlertID+3; // Confirmation // The Palm OS Dialog API does not support custom titles in a dialog box. // So we have to set the title by manipulating the resource. // Get the alert resource char *AlertPtr; MemHandle AlertHandle; AlertHandle=DmGetResource(AppDB,'Talt',AlertID); AlertPtr=(char *)MemHandleLock(AlertHandle); AlertPtr+=8; // Clear out any old title. This must be done with a static array of chars // because using MemSet is not supported on resources and could result in // crashes or unpredictable behaviour. char ClearTitle[25]={' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '}; MemMove(AlertPtr,&ClearTitle,25); // Get the title length and make sure it is not too long int TitleLength=m_caption.length(); if(TitleLength>25) TitleLength=25; // Center the title in the window int BufferLength=(25-TitleLength)/2; AlertPtr+=BufferLength; // Copy the title MemMove(AlertPtr,m_caption.c_str(),TitleLength); // Release the resource MemHandleUnlock(AlertHandle); DmReleaseResource(AlertHandle); // Display the dialog Result=FrmCustomAlert(AppDB,AlertID,m_message.c_str(),"",""); // Convert the Palm OS result to wxResult if(AlertID<1100) { // Ok wxResult=wxID_OK; } else if(AlertID<1200) { // Ok Cancel if(Result==0) wxResult=wxID_OK; else wxResult=wxID_CANCEL; } else if(AlertID<1300) { // Yes No if(Result==0) wxResult=wxID_YES; else wxResult=wxID_NO; } else { // Yes No Cancel if(Result==0) wxResult=wxID_YES; else if(Result==1) wxResult=wxID_NO; else wxResult=wxID_CANCEL; } return wxResult; }
/* 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 CGameForm::OnDraw() { played_cards.Render(true); player_hand.Render(true); char bid_trump_str[2]; StrPrintF(bid_trump_str, "%d", gManager->tbl->bid ); FormPtr frmP = FrmGetActiveForm(); /* RectangleType bounds; UInt16 gadgetIndex = FrmGetObjectIndex( frmP, MainBidTrumpGadget ); FrmGetObjectBounds(frmP, gadgetIndex, &bounds); // draw the bid char bidval = bid_trump_str[0]; WinPaintChar( bidval, bounds.topLeft.x, bounds.topLeft.y ); Card foo(gManager->trk->getTrump(), (Card::face_t)1 ); // now, draw the suit MemHandle hRsc = DmGetResource(bitmapRsc, foo.SuitBitmap(false) ); ErrFatalDisplayIf(!hRsc, "Could not get bitmap family resource"); BitmapType* bitmapP = (BitmapType*) MemHandleLock(hRsc); WinPaintBitmap (bitmapP, bounds.topLeft.x + 6, bounds.topLeft.y); MemHandleUnlock(hRsc); DmReleaseResource(hRsc); */ // handle MainBidTrumpGadget here also MemHandle hRsc; BitmapType* bitmapP; switch ( gManager->tbl->trump ) { case Card::heart: hRsc = DmGetResource(bitmapRsc, HeartBitmapFamily ); break; case Card::diamond: hRsc = DmGetResource(bitmapRsc, DiamondBitmapFamily ); break; case Card::club: hRsc = DmGetResource(bitmapRsc, ClubBitmapFamily ); break; case Card::spade: hRsc = DmGetResource(bitmapRsc, SpadeBitmapFamily ); break; } RectangleType bounds; // FormPtr frmP = FrmGetActiveForm(); UInt16 gadgetIndex = FrmGetObjectIndex(frmP, MainBidTrumpGadget); FrmGetObjectBounds(frmP, gadgetIndex, &bounds); char bidstr[4]; StrPrintF(bidstr, "%d", gManager->tbl->bid); WinPaintChar(bidstr[0], bounds.topLeft.x, bounds.topLeft.y ); ErrFatalDisplayIf(!hRsc, "Could not get bitmap family resource"); bitmapP = (BitmapType*) MemHandleLock(hRsc); WinDrawBitmap (bitmapP, bounds.topLeft.x + FntCharWidth(bidstr[0]) + 1, bounds.topLeft.y); MemHandleUnlock(hRsc); DmReleaseResource(hRsc); }
/***************************************************************************** * Function: GadgetDrawHintCurrent * * Description: Draw hint for current gTimeIndex if needed (may be forced NOT * to draw with GadgetSetNeedsRedraw(false)); *****************************************************************************/ void GadgetDrawHintCurrent(void) { Char *tmp, *bot, begin[timeStringLength], end[timeStringLength], *day; MemHandle mc, mt, mh, type; CourseDBRecord c; TimeDBRecord *tc; RectangleType rect, bounds; UInt16 gadgetIndex = FrmGetObjectIndex(gForm, gGadgetID); RGBColorType color, prevColor; UInt16 attr; // Need to check that due to damn f*** DmRecordInfo which will show a // fatal alert when called on non-existing record (this happens for example // right after creating the new database... if ((gTimeIndex >= DmNumRecords(DatabaseGetRef())) || (gCourseIndex >= DmNumRecords(DatabaseGetRef())) ) return; if (gHintDrawn) { // Delete border around previous entry if ( (gTimeDrawnIndex < DmNumRecords(DatabaseGetRef())) && (DmRecordInfo(DatabaseGetRef(), gTimeDrawnIndex, &attr, NULL, NULL) == errNone) ) { attr &= dmRecAttrCategoryMask; if (attr == DatabaseGetCat()) { mt = DmQueryRecord(DatabaseGetRef(), gTimeDrawnIndex); if (mt) { // mt may be null, for example if next is drawn after delete! tc = (TimeDBRecord *)MemHandleLock(mt); if ((tc->type == TYPE_TIME) && GadgetEventIsVisible(tc) ) { TNlist *tmpl = gGadgetTimeList; GadgetTimeListType *gtl = NULL; while (tmpl != NULL) { gtl = tmpl->data; if (gtl->index == gTimeDrawnIndex) { break; } tmpl = tmpl->next; } color.r=tc->color[0]; color.g=tc->color[1]; color.b=tc->color[2]; if (gPrefs.showTimeline) GadgetDrawTimeline(gtErase); if (gtl != NULL) { GadgetDrawTime(tc->begin, tc->end, tc->day, &color, tc->course, gtl->num, gtl->pos); } if (gPrefs.showTimeline) GadgetDrawTimeline(gtDraw); } MemHandleUnlock(mt); } } } } gTimeDrawnIndex=gTimeIndex; gHintDrawn=true; if (DmRecordInfo(DatabaseGetRef(), gCourseIndex, &attr, NULL, NULL) == errNone) { attr &= dmRecAttrCategoryMask; if (attr == DatabaseGetCat()) { // Record is in currently displayed category mc = DmQueryRecord(DatabaseGetRef(), gCourseIndex); if (! mc) return; mt = DmQueryRecord(DatabaseGetRef(), gTimeIndex); if (! mt) return; UnpackCourse(&c, MemHandleLock(mc)); tc = (TimeDBRecord *)MemHandleLock(mt); if ( GadgetEventIsVisible(tc) ) { TNlist *tmpl = gGadgetTimeList; GadgetTimeListType *gtl = NULL; while (tmpl != NULL) { gtl = tmpl->data; if (gtl->index == gTimeDrawnIndex) { break; } tmpl = tmpl->next; } mh = DmGetResource(strRsc, GADGET_STRINGS_WDAYSTART+tc->day); day = (Char *)MemHandleLock(mh); // Lecture Name (Teacher) [Typ] tmp=(Char *)MemPtrNew(StrLen(c.name)+StrLen(c.teacherName)+4+3+CTYPE_SHORT_MAXLENGTH); MemSet(tmp, MemPtrSize(tmp), 0); type = MemHandleNew(1); CourseTypeGetShort(&type, c.ctype); StrPrintF(tmp, "%s (%s) [%s]", c.name, c.teacherName, (Char *)MemHandleLock(type)); MemHandleUnlock(type); MemHandleFree(type); // Fr 08:00 - 09:30 (Room) <-- Example // 3 5 3 5 3+StrLen(room) <-- Num Chars for MemPtrNew bot=(Char *)MemPtrNew(20+sizeof(tc->room)+MemPtrSize(day)); MemSet(bot, MemPtrSize(bot), 0); TimeToAscii(tc->begin.hours, tc->begin.minutes, GadgetGetTimeFormat(), begin); TimeToAscii(tc->end.hours, tc->end.minutes, GadgetGetTimeFormat(), end); mh = DmGetResource(strRsc, GADGET_STRINGS_WDAYSTART+tc->day); StrPrintF(bot, "%s %s - %s (%s)", day, begin, end, tc->room); FrmGetObjectBounds(gForm, gadgetIndex, &bounds); if (gtl != NULL) { GadgetTimeSetRect(&rect, tc->begin, tc->end, tc->day, gtl->num, gtl->pos); RctSetRectangle(&rect, // + inset (two boxes, one black, one white) rect.topLeft.x + 2, rect.topLeft.y + 2, // width - 2 * inset rect.extent.x - 4, // height - 2 * inset rect.extent.y - 4 ); /* Invert color, looks not so nice aka bad color.r=255- tc->color[0]; color.g=255- tc->color[1]; color.b=255- tc->color[2]; */ color.r=255; color.g=255; color.b=255; TNSetForeColorRGB(&color, &prevColor); WinDrawRectangleFrame(simpleFrame, &rect); color.r=0; color.g=0; color.b=0; RctSetRectangle(&rect, rect.topLeft.x-1, rect.topLeft.y-1, rect.extent.x+2, rect.extent.y+2); TNSetForeColorRGB(&color, NULL); WinDrawRectangleFrame(simpleFrame, &rect); TNSetForeColorRGB(&prevColor, NULL); } // WinInvertRectangleFrame(simpleFrame, &rect); GadgetDrawHint(tmp, bot, tc->note); MemPtrFree((MemPtr) tmp); MemPtrFree((MemPtr) bot); MemHandleUnlock(mh); } else { MemHandleUnlock(mc); MemHandleUnlock(mt); GadgetDrawHintNext(); return; } MemHandleUnlock(mc); MemHandleUnlock(mt); } // End attr == current category } }
/* Find pattern in text string */ static Boolean DoSearch ( Char* text, /* text string */ UInt16 size, /* size of text */ Char* pattern, /* pattern to search for */ UInt8 matchMode, /* indicates if the search should be case-sensitive or not */ UInt16 xlitMode, /* how should we transliterate? */ UInt16* pos, /* start position, will contain the position of the pattern if found */ UInt16* endFound, /* end of position where pattern is found */ Int16 depth /* depth of this page */ ) { Int16 startPos; Int16 charsize; Int16 topcharsize; UInt16 patternLen; UInt16 wplen; Int16 i; Int16 j; Int16 top; WChar ch; WChar wpattern[ 2 * ( MAX_PATTERN_LEN+1 ) ]; Boolean guaranteed8Bits; #ifdef BUILD_ARMLETS Boolean useArmlet; void* DoSearchArmlet; ArmSearchType armData; MemHandle armChunkH = NULL; #endif static UInt8 lastMatchMode = SEARCH_UNINITIALIZED; static UInt16 lastXlitMode = 0; static Char xlat[ 256 ]; static Boolean multibyteCharFix; static WChar multibyteCharFixTo; #ifdef SUPPORT_TRANSLITERATION static Boolean symmetricXlit; #endif multibyteCharFix = false; if ( lastMatchMode != matchMode || xlitMode != lastXlitMode ) { #ifdef SUPPORT_TRANSLITERATION symmetricXlit = SetTransliteration( xlitMode, xlat, &multibyteCharFix, &multibyteCharFixTo ); #else for ( i = 0 ; i < 256 ; i++ ) { xlat[ i ] = i; } #endif if ( ! ( matchMode & SEARCH_CASESENSITIVE ) ) { for ( i = 0; i < 256; i++ ) xlat[ i ] = TxtGlueLowerChar( ( UInt8 )xlat[ i ] ); } lastMatchMode = matchMode; } startPos = *pos; charsize = 1; patternLen = StrLen( pattern ); /* expand wchar string in advance*/ i = wplen = 0; while ( i < patternLen ) { charsize = TxtGlueGetNextChar( pattern, i, &ch ); if ( charsize == 1 ) { #ifdef SUPPORT_TRANSLITERATION if ( symmetricXlit ) { #endif ch = xlat[ (UInt8) ch ]; #ifdef SUPPORT_TRANSLITERATION } else if ( ! ( matchMode & SEARCH_CASESENSITIVE ) ) { ch = TxtGlueLowerChar( (UInt8) ch ); } #endif } else if ( multibyteCharFix ) ch = multibyteCharFixTo; wpattern[ wplen ] = ch; i += charsize; wplen += 1; } guaranteed8Bits = DeviceUses8BitChars(); #ifdef BUILD_ARMLETS useArmlet = false; DoSearchArmlet = NULL; if ( SupportArmlets() && guaranteed8Bits ) { armChunkH = DmGetResource( ArmletResourceType, armDoSearch ); if ( armChunkH != NULL ) { DoSearchArmlet = MemHandleLock( armChunkH ); armData.size = size; armData.depth = depth; armData.text = text; armData.wpattern = wpattern; armData.wplen = wplen; armData.xlat = xlat; useArmlet = true; } } #endif i = top = *pos; j = 0; topcharsize = 0; while ( j < wplen && i < size ) { #ifdef BUILD_ARMLETS if ( useArmlet ) { armData.i = i; armData.j = j; armData.top = top; ch = (WChar) PceNativeCall( DoSearchArmlet, &armData ); i = armData.i; j = armData.j; top = armData.top; if ( wplen <= j || size <= i ) break; charsize = topcharsize = 1; } else #endif if ( guaranteed8Bits ) { ch = DoSearch8BitText( text, size, wpattern, wplen, xlat, &i, &j, &top, 0 < depth ); if ( wplen <= j || size <= i ) break; charsize = topcharsize = 1; } else charsize = TxtGlueGetNextChar( text, i, &ch ); if ( j == 0 ) topcharsize = charsize; if ( ch == '\0' ) { if ( 0 < depth ) { /* if function is anchor, store it to queue */ if ( text[ i + 1 ] == 0x0A /* ANCHOR_START */ ){ UInt16 reference; Int16 q; Int16 listSize; reference = 256 * (UInt8)text[ i + 2 ] + (UInt8)text[ i + 3 ]; listSize = ListSize( searchQueue ); for ( q = 0; q < listSize; q ++ ){ /*look up in queue, append if not exist*/ QueueNode *node; node = ListGet( searchQueue, q + 1 ); if ( node->reference == reference ) break; } if ( q == listSize ) AddReference( reference, depth ); } } i += 2 + ( text[ i + 1 ] & 0x07 ); top = i; j = 0; continue; } if ( charsize == 1 ) ch = xlat[ (UInt8) ch ]; else if ( multibyteCharFix ) ch = multibyteCharFixTo; if ( ch != wpattern[ j ] ) { top += topcharsize; i = top; j = 0; continue; } i += charsize; j += 1; } #ifdef BUILD_ARMLETS if ( armChunkH != NULL ) { MemHandleUnlock( armChunkH ); DmReleaseResource( armChunkH ); } #endif if ( j == wplen ) { *pos = top; *endFound = i; return true; } else { return false; } }
/* Palm OS does not have good dynamic menu support. About all you can do with * the standard API calls is to add new items to an existing drop-down menu and * hide/show items in a drop-down menu. It is impossible to add, hide, or * change the label on a drop-down menu. * * The easiest and simplest way around this limitation is to modify the Palm OS * MenuBarType structure directly. This gives limited ability to change the * label on a drop-down menu. I have not been able to find a safe way to add, * delete, or resize drop-down menus in OS 6. * * The following routine attempt to work around these limitations present in the * Palm OS API to provide limited dynamic menu support. This solution is far * from perfect, but the only other option is to wait for PalmSource to add full * dynamic menu support, or to recreate the Palm OS menu system from scratch. * * This system is limited in that no more than 4 drop-down menus are allowed per * menu bar, and the label for each drop-down menu is limited to 8 characters of * text. However, this menu system should work for most applications. * * Basically the menu routines select one of four menu bars, depending on * whether or not the requested menu bar has one, two, three, or four drop-down * menus. * * These four "template" menu bars contain one, two, three, or four drop-down * menus. Each menu has a dummy menu item attached to it to allow the Palm OS * MenuAddItem function to add the real items. * * The labels on the drop-down menus are then replaced with the labels of the * real menus. * * The menu is then attached to the active window and the MenuAddItem API * function is called to add the items to each drop-down menu. Finally, * MenuHideItem is called to remove the dummy items from each drop-down menu. */ void wxMenuBar::LoadMenu() { int i=0; int j=0; // Handle to the currently running application database DmOpenRef AppDB; // Get app database reference - needed for some Palm OS Menu API calls. SysGetModuleDatabase(SysGetRefNum(), NULL, &AppDB); // Get the number of menus int NumMenus=GetMenuCount(); // Set up the pointers and handles char *PalmOSMenuBarPtr; MemHandle PalmOSMenuBar; // Load the menu template and set up the menu pointers if(NumMenus==1) { PalmOSMenuBar=DmGetResource(AppDB,'MBAR',1000); PalmOSMenuBarPtr=(char *)MemHandleLock(PalmOSMenuBar); PalmOSMenuBarPtr+=74; } else if(NumMenus==2) { PalmOSMenuBar=DmGetResource(AppDB,'MBAR',2000); PalmOSMenuBarPtr=(char *)MemHandleLock(PalmOSMenuBar); PalmOSMenuBarPtr+=116; } else if(NumMenus==3) { PalmOSMenuBar=DmGetResource(AppDB,'MBAR',3000); PalmOSMenuBarPtr=(char *)MemHandleLock(PalmOSMenuBar); PalmOSMenuBarPtr+=158; } else { // We support a maximum of 4 menus, so make sure that do not create // more than we can handle. NumMenus=4; PalmOSMenuBar=DmGetResource(AppDB,'MBAR',4000); PalmOSMenuBarPtr=(char *)MemHandleLock(PalmOSMenuBar); PalmOSMenuBarPtr+=200; } // Set the proper names for the drop-down triggers. for(i=0;i<NumMenus;i++) { // Clear out the old label char buffer[8]={' ',' ',' ',' ',' ',' ',' ',' '}; MemMove(PalmOSMenuBarPtr,buffer,8); wxString MenuTitle=m_titles.Item(i); // Make sure we don't copy more than 8 bytes for the label int LengthToCopy=MenuTitle.length(); if(LengthToCopy>8) LengthToCopy=8; MemMove(PalmOSMenuBarPtr,MenuTitle,LengthToCopy); PalmOSMenuBarPtr+=11; } // We are done with the menu pointer. MemHandleUnlock(PalmOSMenuBar); DmReleaseResource(PalmOSMenuBar); // We must make the menu active before we can add items to the drop-down // triggers. FrmSetMenu(FrmGetActiveForm(),AppDB,NumMenus*1000); /* Add the menu items to the drop-down triggers. This must be done after * setting the triggers, because setting the names of drop-down triggers * that have a variable number of items requires carefull calculation of * the offsets in the MenuBarType structure. Setting the triggers first * avoids this. */ for(i=0;i<NumMenus;i++) { wxMenu *CurrentMenu=GetMenu(i); for(j=0;j<CurrentMenu->GetMenuItemCount();j++) { wxMenuItem *CurrentItem=CurrentMenu->FindItemByPosition(j); wxString ItemLabel=CurrentItem->GetLabel(); if(CurrentItem->IsSeparator()==true) { char Separator=MenuSeparatorChar; if(j==0) MenuAddItem(9000+i,((i*1000)+1000)+j,0x00,&Separator); else MenuAddItem(((i*1000)+1000)+j-1,((i*1000)+1000)+j,0x00,&Separator); } else { if(j==0) MenuAddItem(9000+i,((i*1000)+1000)+j,0x00,ItemLabel); else MenuAddItem(((i*1000)+1000)+j-1,((i*1000)+1000)+j,0x00,ItemLabel); } } // Hide the dummy menu item, since we don't need it anymore. MenuHideItem(9000+i); } }
Boolean CBiddingForm::OnNilEvent(EventPtr pEvent, Boolean& bHandled) { if ( gManager->Status() == GetHandBids ) { HighlightActiveBidder(); FormPtr frmP = FrmGetActiveForm(); Int16 player_index = (*gManager->tbl->current_bidder)->playerIndex; // // if this is a human player, we need to render the screen widgets for their bid // if ( player_index == gManager->humanIndex && player_has_bid == false ) { player_hand.Render(true); Int16 current_bid = 0; if ( (*gManager->tbl->dealer)->playerIndex != gManager->humanIndex || ! gManager->dealer_take_bid ) { current_bid = gManager->tbl->high_bid; } else { current_bid = gManager->tbl->high_bid - 1; } if ( (*gManager->tbl->dealer)->playerIndex == gManager->humanIndex && gManager->tbl->high_bid < 2 ) { CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid4PushButton )), false); CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid4PushButton )), "-4-"); CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid3PushButton )), false); CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid3PushButton )), "-3-"); CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBidPassPushButton )), false); CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBidPassPushButton )), "-Pass-"); } else { switch (current_bid) { case 5: CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBidSmudgePushButton )), false); CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBidSmudgePushButton )), "-S-"); case 4: CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid4PushButton )), false); CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid4PushButton )), "-4-"); case 3: CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid3PushButton )), false); CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid3PushButton )), "-3-"); case 2: CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid2PushButton )), false); CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid2PushButton )), "-2-"); } } } // if if ( player_index == 3 && player_has_bid == false ) // // handle processing actual bids here - get one automatically if this player isn't // a human, or if the human has already bid // if ( player_index != gManager->humanIndex || player_has_bid == true ) { Boolean player_did_bid = gManager->GetNextBid(gManager->trk, false ); Int16 tmp_bid = (*gManager->tbl->current_bidder)->Bid(); if ( player_did_bid && gManager->tbl->current_bidder == gManager->tbl->winning_bidder && (tmp_bid >= 2) ) { char x[10]; StrPrintF(x, "bids %d", tmp_bid ); bidstr = x; } else { bidstr = "passes"; } bids[(*gManager->tbl->current_bidder)->playerIndex].Replace(bidstr); // // if we just got the dealer's bid, then we are all done // if ( gManager->tbl->current_bidder == gManager->tbl->dealer ) { // // at this point we need to set trump... // gManager->Status(SetHandTrump); if ( (*gManager->tbl->winning_bidder)->playerIndex == gManager->humanIndex ) { CPlayerTrumpForm frmPlayerTrump; frmPlayerTrump.DoModal(); } FrmDrawForm(frmP); // // ... and display the final results // Card::suit_t foo = (*gManager->tbl->winning_bidder)->Trump(); gManager->tbl->trump = foo; gManager->trk->no_trump_first_trick = (*gManager->tbl->winning_bidder)->NoTrumpFirstTrickP(); MemHandle hRsc; BitmapType* bitmapP; switch ( gManager->tbl->trump ) { case Card::heart: hRsc = DmGetResource(bitmapRsc, HeartBitmapFamily ); break; case Card::diamond: hRsc = DmGetResource(bitmapRsc, DiamondBitmapFamily ); break; case Card::club: hRsc = DmGetResource(bitmapRsc, ClubBitmapFamily ); break; case Card::spade: hRsc = DmGetResource(bitmapRsc, SpadeBitmapFamily ); break; } if ( gManager->trk->no_trump_first_trick ) { FrmCustomAlert(NoTrumpFirstTrickAlert, (*gManager->tbl->winning_bidder)->name, "", ""); } RectangleType bounds; UInt16 gadgetIndex = FrmGetObjectIndex(frmP, BiddingTrumpGadget); FrmGetObjectBounds(frmP, gadgetIndex, &bounds); WinPaintChars("Trump Is: ", StrLen("Trump Is: "), bounds.topLeft.x, bounds.topLeft.y ); ErrFatalDisplayIf(!hRsc, "Could not get bitmap family resource"); bitmapP = (BitmapType*) MemHandleLock(hRsc); WinDrawBitmap (bitmapP, bounds.topLeft.x + 40, bounds.topLeft.y); MemHandleUnlock(hRsc); DmReleaseResource(hRsc); UInt32 hsStatusVersion; if (FtrGet (hsFtrCreator, hsFtrIDNavigationSupported, &hsStatusVersion) == 0) { FrmGlueNavObjectTakeFocus(FrmGetActiveForm(), BiddingOKButton ); } } // if ( dealer bid ) else { // move along to the next player gManager->tbl->current_bidder = gManager->getNextPlayerIter(gManager->tbl->current_bidder); EventType event; event.eType = nilEvent; EvtAddEventToQueue (&event); // pause here // SysTaskDelay(SysTicksPerSecond()); gManager->ShortDelay(); } } // if ( player_index != 3 || player_has_bid == true ) } // if GetHandBids bHandled = false; return true; }
/*********************************************************************** * * FUNCTION: RepeatDrawDescription * * DESCRIPTION: This routine draws the text description of the current * repeat type and frequency. * * The description is created from a template string. The * repeat type and frequency determines which template is * used. The template may contain one or more of the * following token: * ^d - day name (ex: Monday) * ^f - frequency * ^x - day of the month ordinal number (ex: 1st - 31th) * ^m - month name (ex: July) * ^w - week ordinal number (1st, 2nd, 3rd, 4th, or last) * * PARAMETERS: frm - pointer to the repeat dialog box * * RETURNED: nothing * ***********************************************************************/ void RepeatDrawDescription(FormType* frm) { UInt8 repeatOn; UInt16 i; UInt16 len; UInt16 freq; UInt16 dayOfWeek; UInt16 templateId = repeatNoneString; UInt16 repeatOnCount = 0; Char* descP = NULL; Char* resP = NULL; Char* saveResP = NULL; MemHandle descH = NULL; MemHandle resH = NULL; RepeatInfoType repeat; FieldType* fld = GetObjectPointer(frm, RepeatDescField); FldEraseField (fld); /* Get the current setting of the repeat ui gadgets. */ RepeatGetUIValues(frm, &repeat); /* ** Determine which template string to use. The template string is ** used to format the description string. Note that we could add ** a soft constant which tells us whether we need to use different ** strings for freq == 1 case (depends on language), thus saving space. */ freq = repeat.repeatFrequency; switch (repeat.repeatType) { case repeatNone: templateId = repeatNoneString; break; case repeatHourly: if (freq == 1) /* "Every hour" */ templateId = everyHourRepeatString; else /* "Every [other | 2nd | 3rd...] hour" */ templateId = hourlyRepeatString; break; case repeatDaily: if (freq == 1) /* "Every day" */ templateId = everyDayRepeatString; else /* "Every [other | 2nd | 3rd...] day" */ templateId = dailyRepeatString; break; case repeatWeekly: if (freq == 1) /* "Every week on [days of week]" */ templateId = everyWeekRepeat1DayString; else templateId = weeklyRepeat1DayString; /* ** Generate offset to appropriate string id, ** based on # of days that we need to append. */ for (i = 0; i < daysInWeek; i++) { if (repeat.repeatOn & (1 << i) ) repeatOnCount++; } templateId += repeatOnCount - 1; break; case repeatMonthlyByDate: if (freq == 1) /* "The ^w ^d of every month" */ templateId = everyMonthByDateRepeatString; else templateId = monthlyByDateRepeatString; break; case repeatMonthlyByDay: if (freq == 1) templateId = everyMonthByDayRepeatString; else templateId = monthlyByDayRepeatString; break; case repeatYearly: if (freq == 1) templateId = everyYearRepeatString; else templateId = yearlyRepeatString; break; default: ErrNonFatalDisplay("Unknown repeat type"); break; } /* ** Allocate a block to hold the description and copy the template ** string into it. */ resH = DmGetResource(strRsc, templateId); resP = MemHandleLock(resH); descH = MemHandleNew(MemPtrSize(resP)); ASSERT(descH); descP = MemHandleLock(descH); StrCopy(descP, resP); MemHandleUnlock(resH); /* Substitute the month name string for the month name token. */ resH = DmGetResource(strRsc, repeatMonthNamesString); resP = MemHandleLock(resH); for (i = 1; i < d.frm_date.month; i++) resP = StrChr(resP, spaceChr) + 1; len = StrChr(resP, spaceChr) - resP; descP = SubstituteStr(descP, monthNameToken, resP, len); MemHandleUnlock(resH); /* Substitute the day name string for the day name token. */ if ((repeatOnCount == 1) || (repeat.repeatType == repeatMonthlyByDay)) templateId = repeatFullDOWNamesString; else templateId = repeatShortDOWNamesString; resH = DmGetResource(strRsc, templateId); resP = MemHandleLock(resH); if (repeat.repeatType == repeatWeekly) { dayOfWeek = repeat.repeatStartOfWeek; repeatOn = repeat.repeatOn; saveResP = resP; while (StrStr (descP, dayNameToken)) { for (i = 0; i < daysInWeek; i++) { if (repeatOn & (1 << dayOfWeek)) { repeatOn &= ~(1 << dayOfWeek); break; } dayOfWeek = (dayOfWeek + 1 + daysInWeek) % daysInWeek; } resP = saveResP; for (i = 0; i < dayOfWeek; i++) resP = StrChr(resP, spaceChr) + 1; len = StrChr(resP, spaceChr) - resP; descP = SubstituteStr(descP, dayNameToken, resP, len); } } else { dayOfWeek = DayOfWeek (d.frm_date.month, d.frm_date.day, d.frm_date.year/* + firstYear*/); for (i = 0; i < dayOfWeek; i++) resP = StrChr(resP, spaceChr) + 1; len = StrChr(resP, spaceChr) - resP; descP = SubstituteStr(descP, dayNameToken, resP, len); } MemHandleUnlock (resH); /* ** Substitute the repeat frequency string for the frequency token. Note that ** we do something special for 2nd (other), since the gender of 'other' changes ** for some languages, depending on whether the next word is day, month, week, ** or year. */ if (freq == 2) { Char otherFreqName[16]; const UInt16 index = repeat.repeatType - repeatNone; SysStringByIndex(freqOrdinal2ndStrlID, index, otherFreqName, sizeof(otherFreqName)); descP = SubstituteStr(descP, frequenceToken, otherFreqName, StrLen(otherFreqName)); } else { resH = DmGetResource(strRsc, freqOrdinalsString); resP = MemHandleLock(resH); for (i = 1; i < freq; i++) resP = StrChr(resP, spaceChr) + 1; len = StrChr(resP, spaceChr) - resP; descP = SubstituteStr(descP, frequenceToken, resP, len); MemHandleUnlock(resH); } /* ** Substitute the repeat week string (1st, 2nd, 3rd, 4th, or last) ** for the week ordinal token. */ if (repeat.repeatType == repeatMonthlyByDay) { resH = DmGetResource(strRsc, weekOrdinalsString); resP = MemHandleLock(resH); for (i = 0; i < repeat.repeatOn / daysInWeek; i++) resP = StrChr (resP, spaceChr) + 1; len = StrChr(resP, spaceChr) - resP; descP = SubstituteStr(descP, weekOrdinalToken, resP, len); MemHandleUnlock(resH); } else { /* make sure the week ordinal token really doesn't appear */ ErrNonFatalDisplayIf(StrStr(descP, weekOrdinalToken) != NULL, "week ordinal not substituted"); } /* ** Substitute the repeat date string (1st, 2nd, ..., 31th) for the ** day ordinal token. */ resH = DmGetResource(strRsc, dayOrdinalsString); resP = MemHandleLock(resH); for (i = 1; i < d.frm_date.day; i++) resP = StrChr(resP, spaceChr) + 1; len = StrChr(resP, spaceChr) - resP; descP = SubstituteStr(descP, dayOrdinalToken, resP, len); MemHandleUnlock(resH); /* Draw the description. */ MemHandleUnlock(descH); FldFreeMemory(fld); FldSetTextHandle(fld, descH); FldDrawField(fld); }
static Boolean RulesFormHandleEvent(EventPtr event) { Boolean handled = false; switch (event->eType) { case ctlRepeatEvent: switch (event->data.ctlRepeat.controlID) { case rulesScrollUp: RulesScroll (winUp, false); break; case rulesScrollDown: RulesScroll (winDown, false); break; } break; case ctlSelectEvent: switch (event->data.ctlSelect.controlID) { case rulesScrollUp: RulesScroll (winUp, false); break; case rulesScrollDown: RulesScroll (winDown, false); break; } break; case keyDownEvent: switch (event->data.keyDown.chr) { case pageDownChr: RulesScroll (winDown, true); handled = true; break; case pageUpChr: RulesScroll (winUp, true); handled = true; break; } break; default: } return handled; } void Rules (void) { FieldPtr field; VoidHand rulesH; rulesH = DmGetResource ('tSTR', ricochetRulesText); if (rulesH) { rulesFrm = FrmInitForm (rulesForm); field = FrmGetObjectPtr (rulesFrm, FrmGetObjectIndex (rulesFrm, rulesText)); FldSetInsPtPosition (field, 0); FldSetTextHandle (field, (Handle) rulesH); RulesSetScrolling (); FrmSetEventHandler (rulesFrm, RulesFormHandleEvent); FrmDoDialog (rulesFrm); FldSetTextHandle (field, 0); DmReleaseResource (rulesH); FrmDeleteForm (rulesFrm); } }
void Plugin_Search ( void ) { DmSearchStateType searchState; UInt16 tempCardNo; MemHandle tempPlugInResH; // handle to our plug-in resource Boolean newSearch = true; LocalID tempPlugInDbID = 0; Err theErr = 0; UInt8 curPlug = 0; MemHandle nameH; Char *nameP; Plug_ParamBlock plugInParamBlock; do { DEBUGINFO("Top of loop."); theErr = DmGetNextDatabaseByTypeCreator(newSearch, &searchState, kPlugInFileType, kPlugInFileCreator, false /* all versions */, &tempCardNo, &tempPlugInDbID); newSearch = false; DEBUGINFO("After search."); if ( !theErr ) { DEBUGINFO("No error."); DEBUGINFO("abba 6"); PluginListP[curPlug] = (Plug_InternalRef *)MemPtrNew(sizeof(Plug_InternalRef)); DEBUGINFO("abba 7"); PluginListP[curPlug]->gPlugInDbRef = DmOpenDatabase(tempCardNo, tempPlugInDbID, dmModeReadOnly); DEBUGINFO("abba 3"); tempPlugInResH = DmGetResource(kPlugInResourceType, kFirstPlugInResID); DEBUGINFO("abba 4"); if ( !tempPlugInResH ) continue; DEBUGINFO("abba 5"); // Get a lock on the code resource. DEBUGINFO("abba"); PluginListP[curPlug]->gPlugInResP = (Plug_Main *)MemHandleLock(tempPlugInResH); DEBUGINFO("abba"); // Get the plugin's long name. DEBUGINFO("abba"); nameH = DmGet1Resource ( 'tAIN', 1000 ); DEBUGINFO("abba"); if ( nameH ) { DEBUGINFO("abba"); nameP = MemHandleLock(nameH); DEBUGINFO(nameP); StrCopy ( PluginListP[curPlug]->longname, nameP ); MemHandleUnlock ( nameH ); } DEBUGINFO("blorg"); // Get the plugin's short (list) name. DEBUGINFO("abba"); nameH = DmGet1Resource ( 'tSTR', 1 ); DEBUGINFO("abba"); if ( nameH ) { DEBUGINFO("abba"); nameP = MemHandleLock(nameH); DEBUGINFO(nameP); StrCopy ( PluginListP[curPlug]->shortname, nameP ); MemHandleUnlock ( nameH ); } DEBUGINFO("shnee"); // Send the plugin a startup event... plugInParamBlock.eType = cmdStartup; theErr = (*PluginListP[curPlug]->gPlugInResP) (&plugInParamBlock); DEBUGINFO("whoot"); if ( theErr ) theErr = 0; } } while (!theErr); }