void StartRandomWordLookup(AppContext* appContext) { if (!HasCookie(appContext->prefs)) StartCookieRequestWithWordLookup(appContext, NULL); else { ExtensibleBuffer urlBuffer; ebufInit(&urlBuffer, 0); Err error=PrepareGenericRequest(appContext->prefs.cookie, randomWordRequestParam, urlBuffer); if (!error) { const char* requestUrl=ebufGetDataPointer(&urlBuffer); ExtensibleBuffer* context=ebufNew(); if (context) { ebufInitWithStr(context, "random word"); ebufAddChar(context, chrNull); StartConnection(appContext, context, requestUrl, WordLookupStatusTextRenderer, WordLookupResponseProcessor, WordLookupContextDestructor); } else FrmAlert(alertMemError); } else FrmAlert(alertMemError); ebufFreeData(&urlBuffer); } }
void StartWordLookup(AppContext* appContext, const char* word) { if (!HasCookie(appContext->prefs)) { StartCookieRequestWithWordLookup(appContext, word); return; } ExtensibleBuffer urlBuffer; ebufInit(&urlBuffer, 0); Err error = WordLookupPrepareRequest(appContext->prefs.cookie, word, appContext->prefs.regCode, urlBuffer); if (error) { FrmAlert(alertMemError); goto Exit; } const char* requestUrl = ebufGetDataPointer(&urlBuffer); ExtensibleBuffer* context = ebufNew(); if (context) { ebufInitWithStr(context, const_cast<char*>(word)); ebufAddChar(context, chrNull); StartConnection(appContext, context, requestUrl, WordLookupStatusTextRenderer, WordLookupResponseProcessor, WordLookupContextDestructor); } else FrmAlert(alertMemError); Exit: ebufFreeData(&urlBuffer); }
// do a GET_COOKIE request followed by GET_WORD request or GET_RANDOM_WORD // request (if word is NULL) void StartCookieRequestWithWordLookup(AppContext* appContext, const char* word) { ExtensibleBuffer request; ebufInit(&request, 0); Err error=CookieRequestPrepareRequest(request); if (error) { FrmAlert(alertMemError); goto Exit; } if (word) { ExtensibleBuffer* wordBuffer=ebufNew(); if (wordBuffer) { ebufInitWithStr(wordBuffer, const_cast<char*>(word)); ebufAddChar(wordBuffer, chrNull); StartConnection(appContext, wordBuffer, ebufGetDataPointer(&request), GeneralStatusTextRenderer, CookieRequestResponseProcessorWithLookup, CookieRequestContextDestructor); } else FrmAlert(alertMemError); } else { // this means GET_RANDOM_WORD in CookieRequestResponseProcessor StartConnection(appContext, NULL, ebufGetDataPointer(&request), GeneralStatusTextRenderer, CookieRequestResponseProcessorWithLookup, CookieRequestContextDestructor); } Exit: ebufFreeData(&request); }
static Boolean CheckPhonePower(UInt16 PhoneLibRefNum) { UInt16 isSimReady = false; // Make sure that the phone is powered... if (PhnLibModulePowered (PhoneLibRefNum) != phnPowerOn ) { if (resAlertPhoneNotReadyTurnOn == FrmAlert(alertPhoneNotReady)) PhnLibSetModulePower (PhoneLibRefNum, 1); else return false; } //Check if radio has initiliazed the SIM on GSM phone //if not, will ask the user if he wants to check again or cancel out while (!isSimReady) { if ((PhnLibGetSIMStatus(PhoneLibRefNum) != simReady) && (GetPhoneType() == hsAttrPhoneTypeGSM)) { if (resAlertSimNotReadyCheck == FrmAlert(alertSimNotReady)) isSimReady = false; else return false; } else isSimReady = true; } return true; }
Err AppPerformResidentLookup(char* term) { Err error; AppContext* appContext=(AppContext*)MemPtrNew(sizeof(AppContext)); AbstractFile * chosenDb; if (!appContext) { error=memErrNotEnoughSpace; goto OnError; } error=AppCommonInit(appContext); RemoveNonexistingDatabases(appContext); ScanForDictsNoahPro(appContext, false); if (0 == appContext->dictsCount) { FrmAlert(alertNoDB); goto Exit; } else if (1 == appContext->dictsCount ) chosenDb = appContext->dicts[0]; else { // because we can't start resident mode without previously gracefully exiting at least one time Assert(appContext->prefs.lastDbUsedName); chosenDb=FindOpenDatabase(appContext, appContext->prefs.lastDbUsedName); } if (!chosenDb || !DictInit(appContext, chosenDb)) { FrmAlert(alertDbFailed); goto Exit; } if (term) { appContext->currentWord=dictGetFirstMatching(chosenDb, term); error=PopupResidentLookupForm(appContext); } else { appContext->currentWord=-1; error=PopupResidentBrowseForm(appContext); if (!error && appContext->currentWord!=-1) error=PopupResidentLookupForm(appContext); } Exit: AppCommonFree(appContext); OnError: if (appContext) MemPtrFree(appContext); return error; }
UInt32 PilotMain(UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags) { EventType event; Err err = 0; switch (cmd) { case sysAppLaunchCmdNormalLaunch: if(isTheDeviceSupported() == false) { FrmAlert(OldAlert); break; } FrmGotoForm(MainForm); do { UInt16 MenuError; EvtGetEvent(&event, evtWaitForever); if (! SysHandleEvent(&event)) if (! MenuHandleEvent(0, &event, &MenuError)) if (! AppHandleEvent(&event)) FrmDispatchEvent(&event); } while (event.eType != appStopEvent); break; case sysAppLaunchCmdNotify: if(((SysNotifyParamType*) cmdPBP)->notifyType==sysNotifyDisplayResizedEvent) { EventType resizedEvent; MemSet(&resizedEvent,sizeof(EventType),0); resizedEvent.eType=winDisplayChangedEvent; EvtAddUniqueEventToQueue(&resizedEvent,0,true); } break; default: break; } return(err); }
static Err RomVersionCompatible(UInt32 requiredVersion, UInt16 launchFlags) { UInt32 romVersion; /* See if we're on in minimum required version of the ROM or later. */ FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion); if (romVersion < requiredVersion) { if ((launchFlags & (sysAppLaunchFlagNewGlobals | sysAppLaunchFlagUIApp)) == (sysAppLaunchFlagNewGlobals | sysAppLaunchFlagUIApp)) { FrmAlert(kRomIncompatibleAlert); /* Palm OS versions before 2.0 will continuously relaunch this * app unless we switch to another safe one. */ /* DCK: We will never be able to run on PalmOS < 2.0, or < 5.0 for that matter... */ /*if (romVersion < kPalmOS20Version) { AppLaunchWithCommand(sysFileCDefaultApp, sysAppLaunchCmdNormalLaunch, NULL); }*/ } return sysErrRomIncompatible; } return errNone; }
UInt32 PilotMain(UInt16 launchCode, MemPtr launchParameters, UInt16 launchFlags) { Err error; UInt32 romVersion; FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion); if (romVersion < ROM_VERSION_REQUIRED_FOR_FLOP) { FrmAlert(RomIncompatibleAlert); return (sysErrRomIncompatible); } switch(launchCode) { case sysAppLaunchCmdNormalLaunch: error = AppStart(); if (error) return error; FrmGotoForm(FlopForm); AppEventLoop(); AppStop(); break; default: break; } return errNone; }
/*********************************************************************** * * FUNCTION: RomVersionCompatible * * DESCRIPTION: This routine checks that a ROM version is meet your * minimum requirement. * * PARAMETERS: requiredVersion - minimum rom version required * (see sysFtrNumROMVersion in SystemMgr.h * for format) * launchFlags - flags that indicate if the application * UI is initialized. * * RETURNED: error code or zero if rom is compatible * * REVISION HISTORY: * * ***********************************************************************/ static Err RomVersionCompatible(UInt32 requiredVersion, UInt16 launchFlags) { UInt32 romVersion; // See if we're on in minimum required version of the ROM or later. FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion); if (romVersion < requiredVersion) { if ((launchFlags & (sysAppLaunchFlagNewGlobals | sysAppLaunchFlagUIApp)) == (sysAppLaunchFlagNewGlobals | sysAppLaunchFlagUIApp)) { FrmAlert (RomIncompatibleAlert); // Palm OS 1.0 will continuously relaunch this app unless we switch to // another safe one. if (romVersion <= kPalmOS10Version) { AppLaunchWithCommand(sysFileCDefaultApp, sysAppLaunchCmdNormalLaunch, NULL); } } return sysErrRomIncompatible; } return errNone; }
Err show_heap_info() { Err err; UInt16 numHeaps, numRAMHeaps, version; UInt16 heapNo, heapId; UInt32 free, max, heapSize; Char tmp_text[100], tmp_textd1[100], tmp_textd2[100]; FormPtr form; // Initialize the form. form = FrmInitForm(formID_heap_info); // Initialize the form. if (cardNo > MemNumCards()) { FrmAlert(alertID_no_card); return err; } numHeaps = MemNumHeaps(cardNo-1); StrPrintF(tmp_text, "Num. heaps: %u", numHeaps); show_lab(form, labelID_num_heaps, tmp_text); numRAMHeaps = MemNumRAMHeaps(cardNo-1); StrPrintF(tmp_text, "Num. RAM heaps: %u", numRAMHeaps); show_lab(form, labelID_num_RAM_heaps, tmp_text); for (heapNo=0; heapNo < numHeaps && heapNo < 3; heapNo++) { heapId = MemHeapID(cardNo-1,heapNo); heapSize = MemHeapSize(heapId); err = MemHeapFreeBytes(heapId, &free, &max); if (err) return err; if (heapNo < numRAMHeaps) { StrPrintF(tmp_text, "RAM Heap %d is %s", heapNo, (MemHeapDynamic(heapId))?("dynamic"):("non-dynamic")); StrPrintF(tmp_textd1, "Free: %lu Kb.", free); StrPrintF(tmp_textd2, "Max. chunk: %lu Kb.", max); } else { StrPrintF(tmp_text, "ROM Heap %d", heapNo); StrPrintF(tmp_textd1, "Free: %lu Kb.", free); StrPrintF(tmp_textd2, "Max chunk: %lu Kb.", max); } switch (heapNo) { case 0: show_lab(form, labelID_heap1, tmp_text); show_lab(form, labelID_heap1d1, tmp_textd1); show_lab(form, labelID_heap1d2, tmp_textd2); case 1: show_lab(form, labelID_heap2, tmp_text); show_lab(form, labelID_heap2d1, tmp_textd1); show_lab(form, labelID_heap2d2, tmp_textd2); default: show_lab(form, labelID_heap3, tmp_text); show_lab(form, labelID_heap3d1, tmp_textd1); show_lab(form, labelID_heap3d2, tmp_textd2); } } display_modal_form(form); return err; }
static int try_db_name(void) {int i,n;struct database_handle**db=get_database_list(&n); if(*db_name)for(i=0;i<n;i++)if(!StrCompare(db[i]->name,db_name)) if(!load_database(i))return 0; *db_name=0;if(n>0)return load_database(0); FrmAlert(No_Dictionary_Alert_id);return!0; }enum aux_flags_bits{list_mode_bit=0};
// ************************************************************************* // Handling of the events of the Buy Equipment form. // ************************************************************************* Boolean BuyEquipmentFormHandleEvent( EventPtr eventP ) { Boolean handled = false; switch (eventP->eType) { case frmOpenEvent: case frmUpdateEvent: DrawBuyEquipmentForm(); handled = true; break; case ctlSelectEvent: if (eventP->data.ctlSelect.controlID >= BuyEquipmentBuy0Button && eventP->data.ctlSelect.controlID < BuyEquipmentBuy0Button+MAXWEAPONTYPE) { BuyItem( Shiptype[Ship.Type].WeaponSlots, Ship.Weapon, BASEWEAPONPRICE( eventP->data.ctlSelect.controlID - BuyEquipmentBuy0Button ), Weapontype[eventP->data.ctlSelect.controlID - BuyEquipmentBuy0Button].Name, eventP->data.ctlSelect.controlID - BuyEquipmentBuy0Button ); } if (eventP->data.ctlSelect.controlID >= BuyEquipmentBuy0Button+MAXWEAPONTYPE && eventP->data.ctlSelect.controlID < BuyEquipmentBuy0Button+MAXWEAPONTYPE+MAXSHIELDTYPE) { BuyItem( Shiptype[Ship.Type].ShieldSlots, Ship.Shield, BASESHIELDPRICE( eventP->data.ctlSelect.controlID - BuyEquipmentBuy0Button - MAXWEAPONTYPE ), Shieldtype[eventP->data.ctlSelect.controlID - BuyEquipmentBuy0Button - MAXWEAPONTYPE].Name, eventP->data.ctlSelect.controlID - BuyEquipmentBuy0Button - MAXWEAPONTYPE ); } if (eventP->data.ctlSelect.controlID >= BuyEquipmentBuy0Button+MAXWEAPONTYPE+MAXSHIELDTYPE && eventP->data.ctlSelect.controlID < BuyEquipmentBuy0Button+MAXWEAPONTYPE+MAXSHIELDTYPE+MAXGADGETTYPE ) { if (HasGadget( &Ship, eventP->data.ctlSelect.controlID - BuyEquipmentBuy0Button - MAXWEAPONTYPE - MAXSHIELDTYPE ) && EXTRABAYS != eventP->data.ctlSelect.controlID - BuyEquipmentBuy0Button - MAXWEAPONTYPE - MAXSHIELDTYPE) FrmAlert( NoMoreOfItemAlert ); else { BuyItem( Shiptype[Ship.Type].GadgetSlots, Ship.Gadget, BASEGADGETPRICE( eventP->data.ctlSelect.controlID - BuyEquipmentBuy0Button - MAXWEAPONTYPE - MAXSHIELDTYPE ), Gadgettype[eventP->data.ctlSelect.controlID - BuyEquipmentBuy0Button - MAXWEAPONTYPE - MAXSHIELDTYPE].Name, eventP->data.ctlSelect.controlID - BuyEquipmentBuy0Button - MAXWEAPONTYPE - MAXSHIELDTYPE ); } } handled = true; break; default: break; } return handled; }
// Show card info in a modal form. Use global variable cardNo. Err show_card_info() { Char cardName[32]; Char manufName[32]; UInt32 crDate, romSize, ramSize, freeBytes; Err err; UInt16 version; UInt32 free, max; Char tmp_text[100]; // Initialize the form. FormPtr form = FrmInitForm(formID_card_info); // Initialize the form. if (cardNo > MemNumCards()) { FrmAlert(alertID_no_card); return err; } err = MemCardInfo (cardNo-1, cardName, manufName, &version, &crDate, &romSize, &ramSize, &freeBytes); if (err) { FrmAlert(alertID_no_card); return err; } StrPrintF(tmp_text, "Card no.: %u", cardNo); show_lab(form, labelID_card_info_no, tmp_text); StrPrintF(tmp_text, "Card name: %s", cardName); show_lab(form, labelID_card_name, tmp_text); StrPrintF(tmp_text, "Manu name: %s", manufName); show_lab(form, labelID_manu_name, tmp_text); StrPrintF(tmp_text, "Version: %u", version); show_lab(form, labelID_version, tmp_text); StrPrintF(tmp_text, "Cration date: %lu", crDate); show_lab(form, labelID_cr_date, tmp_text); StrPrintF(tmp_text, "ROM size: %lu Kb.", romSize / 1024); show_lab(form, labelID_ROM_size, tmp_text); StrPrintF(tmp_text, "RAM size: %lu Kb.", ramSize / 1024); show_lab(form, labelID_RAM_size, tmp_text); StrPrintF(tmp_text, "Free bytes: %lu Kb.", freeBytes / 1024); show_lab(form, labelID_free_mem, tmp_text); display_modal_form(form); return err; }
static Boolean prefsEventHandler (EventPtr event) { int handled = 0; FormPtr form; ControlPtr ptr; switch (event->eType) { case frmOpenEvent: form = FrmGetActiveForm(); ptr = FrmGetObjectPtr(form, FrmGetObjectIndex(form, cbid_repeats)); CtlSetValue(ptr, repeats); ptr = FrmGetObjectPtr(form, FrmGetObjectIndex(form, cbid_rainbow)); CtlSetValue(ptr, rainbow); ptr = FrmGetObjectPtr(form, FrmGetObjectIndex(form, cbid_extra)); CtlSetValue(ptr, extra); FrmDrawForm(form); handled = 1; break; case ctlSelectEvent: // a button was pressed and released switch (event->data.ctlSelect.controlID) { case cbid_repeats: repeats = event->data.ctlSelect.on; handled = 1; break; case cbid_rainbow: rainbow = event->data.ctlSelect.on; handled = 1; break; case cbid_extra: extra = event->data.ctlSelect.on; handled = 1; break; case bid_ok: FrmGotoForm(fid_kartrando); handled = 1; break; case bid_repeats_help: FrmAlert(aid_repeats_help); break; case bid_rainbow_help: FrmAlert(aid_rainbow_help); break; case bid_extra_help: FrmAlert(aid_extra_help); break; } break; default: break; } return handled; }
// Show a registration dialog where a user enters registration code. // if fDeleteAfterCancel is set to true, we'll remove the registration code // from preferences. We want this behavior if "re-enter registration code" was // pressed after registration process failed (this was an invalid registration code // so we don't want the client to send it to the server -> so we erase it). // If this dialog was brought by "Register" menu item, then we don't want to // touch the registration code (we assume it's correct) // TODO: maybe if we're called from "Register" menu and registartion code // is already present (i.e. valid) we should make it harder to edit it by accident // (e.g. make it read only until user makes some action like pressing a "edit" button) static void MainFormHandleRegister(AppContext* appContext, bool fDeleteAfterCancel) { FormType* form=FrmInitForm(formRegistration); if (!form) { FrmAlert(alertMemError); return; } DefaultFormInit(appContext, form); FrmSetEventHandler(form, RegistrationFormHandleEvent); UInt16 button=FrmDoDialog(form); if (buttonRegister!=button) { if (fDeleteAfterCancel) { appContext->prefs.regCode[0] = '\0'; SavePreferencesInoah(appContext); } goto Exit; } UInt16 index=FrmGetObjectIndex(form, fieldRegCode); Assert(frmInvalidObjectId!=index); const FieldType* field=static_cast<FieldType*>(FrmGetObjectPtr(form, index)); Assert(field); const char* regCode=FldGetTextPtr(field); int regCodeLen = (int)FldGetTextLength(field); if ( (NULL != regCode) && (regCodeLen>0) ) { // save the registration code in preferences so that we can // send it in all requests if (regCodeLen>MAX_REG_CODE_LENGTH) { // this is laziness: reg code longer than MAX_REG_CODE_LENGTH // is invalid for sure so we should just display such message // but we'll just use truncated version and go on with normal // processing regCodeLen=MAX_REG_CODE_LENGTH; } SafeStrNCopy((char*)appContext->prefs.regCode, sizeof(appContext->prefs.regCode), regCode, regCodeLen); RemoveNonDigits( (char*)appContext->prefs.regCode ); // save preferences just for sure - so that we don't loose regCode // in case of a crash SavePreferencesInoah(appContext); // send a registration query to the server so that the user // knows if he registered correctly // it doesn't really matter, in the long run, because every time // we send a request, we also send the registration code and // if it's not correct, we'll reject the query StartRegistration(appContext, (const char*)appContext->prefs.regCode); } Exit: FrmDeleteForm(form); }
static void FlickrAlert(UInt16 alertId) { FormActiveStateType activeState; FrmSaveActiveState(&activeState); MenuEraseStatus(NULL); FrmAlert(alertId); FrmRestoreActiveState(&activeState); }
Boolean PostListFormEventHandler(EventPtr event) { static FormPtr gpForm; UInt16 postCount; switch (event->eType) { case frmOpenEvent: { postCount = 10; // If you exceed 10 you pop a warning and it gets trimmed. setup_database(); FrmDrawForm(gpForm = FrmGetActiveForm()); UpdatePostsTable(gpForm, postCount); return true; } case frmCloseEvent: { FrmEraseForm(gpForm); FrmDeleteForm(gpForm); return true; } case ctlSelectEvent: { switch (event->data.ctlSelect.controlID) { case HelpButton: { FrmCustomAlert(TheError, "Oops, looks like our connection goofed here, try again?", NULL, NULL); return true; } case PalmrMainMenuAbout: { FrmAlert(AboutAlert); return true; } } } case tblSelectEvent: { int row = event->data.tblSelect.row; int column = event->data.tblSelect.column; // char strRow[15]; // char strColumn[15]; // // sprintf(strRow, "%i", row); // sprintf(strColumn, "%i", column); // AlertPrintf3( // "You selected:", // strRow, strColumn); FrmGotoForm(PostViewForm); return true; } default: { return false; } } }
void StartRecentLookupsRequest(AppContext* appContext) { if (!HasCookie(appContext->prefs)) FrmAlert(alertNoLookupsYet); else { ExtensibleBuffer urlBuffer; ebufInit(&urlBuffer, 0); Err error=PrepareGenericRequest(appContext->prefs.cookie, recentLookupsRequestParam, urlBuffer); if (!error) { const char* requestUrl=ebufGetDataPointer(&urlBuffer); StartConnection(appContext, NULL, requestUrl, GeneralStatusTextRenderer, RecentLookupsResponseProcessor, NULL); } else FrmAlert(alertMemError); ebufFreeData(&urlBuffer); } }
void StartCookieRequestWithRegistration(AppContext* appContext, const char* serialNumber) { ExtensibleBuffer request; ebufInit(&request, 0); Err error=CookieRequestPrepareRequest(request); if (!error) { ExtensibleBuffer* snBuffer=ebufNew(); if (snBuffer) { ebufInitWithStr(snBuffer, const_cast<char*>(serialNumber)); ebufAddChar(snBuffer, chrNull); StartConnection(appContext, snBuffer, ebufGetDataPointer(&request), GeneralStatusTextRenderer, CookieRequestResponseProcessorWithRegistration, CookieRequestContextDestructor); } else FrmAlert(alertMemError); } else FrmAlert(alertMemError); ebufFreeData(&request); }
Err RomVersionCompatible ( UInt32 reqVersion ) { if ( romVersion < reqVersion ) { MSG( _( "wrong ROM version detected ( %lx )\n", romVersion ) ); FrmAlert( infoWrongROMVersion ); if ( sysGetROMVerMajor( romVersion ) == 0x01 ) AppLaunchWithCommand( sysFileCDefaultApp, sysAppLaunchCmdNormalLaunch, NULL ); return sysErrRomIncompatible; } return errNone; }
/* Get preferences, open (or create) app database */ static UInt16 StartApplication(void) { UInt32 romversion; UInt16 err; err = FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romversion); /* We *must* be version 2 or greater */ if( err || (romversion < 0x02003000) ) { FrmAlert(alertVersion); return(1); } FrmGotoForm(MainForm); LoadPrefs(); return 0; }
static void MainFormHandleWrongRegCode(AppContext *appContext) { UInt16 buttonId; buttonId = FrmAlert(alertRegistrationFailed); if (0==buttonId) { // this is "Ok" button. Clear-out registration code (since it was invalid) MemSet(appContext->prefs.regCode, sizeof(appContext->prefs.regCode), 0); SavePreferencesInoah(appContext); return; } Assert(1==buttonId); // this must be "Re-enter registration code" button MainFormHandleRegister(appContext,true); }
/*------------------------------------------------------------TestDialog::run-+ | | +----------------------------------------------------------------------------*/ void TestDialog::run() { static char const msg0a[] = "---------- \""; static char const msg0b[] = "\"\n"; static char const msg0[] = "Palm Device wants to read you, OK? (Y/N): "; static char const msg1[] = "More to say? (Y/N): "; static char const msg2[] = "End of connection. Au revoir!\n"; static char const msg3[] = "Enter a line, please.\n"; display(msg0a, sizeof msg0a - 1); display(title(), strlen(title())); display(msg0b, sizeof msg0b - 1); iostream * io = newInOutStream(); char * buf = new char[500]; io->write(msg0, sizeof msg0 - 1); // io->seekg(0, ios::end); for (;;) { int answ; // io->seekg(0, ios::end); answ = io->get(); // io->seekp(0, ios::end); if ((answ != 'Y') && (answ != 'y')) { io->write(msg2, sizeof msg2 - 1); io->flush(); FrmAlert(NoServerAlert); break; }else { io->write(msg3, sizeof msg3 - 1); // io->seekg(0, ios::end); io->get(buf, 500, '\n'); int len = io->gcount(); if (len < 500) { // following gets the '\n' and... avoids an infinite loop! buf[len++] = io->get(); // this gets '\n' } display(buf, cleanUpCR(buf, len)); } io->write(msg1, sizeof msg1 - 1); } delete [] buf; delete io; }
/*********************************************************************** * function is checking ROM version of the palmos operating system * if ROM version is less then required the result of this function is * sysErrRomIncompatible ***********************************************************************/ static Err RomVersionCompatible (UInt32 requiredVersion, UInt16 launchFlags) { // See if we're on in minimum required version of the ROM or later. if (TNPalmOSVersion() < requiredVersion) { if ((launchFlags & (sysAppLaunchFlagNewGlobals | sysAppLaunchFlagUIApp)) == (sysAppLaunchFlagNewGlobals | sysAppLaunchFlagUIApp)) { FrmAlert (ALERT_ROMIncompatible); // PalmOS before 3.5 will continuously relaunch this app unless we switch to // another safe one. AppLaunchWithCommand(sysFileCDefaultApp, sysAppLaunchCmdNormalLaunch, NULL); } return (sysErrRomIncompatible); } return (0); }
// All form-related events are handled here. static Boolean ri_sim_event(EventPtr event){ FormPtr form; int handled = 0; switch (event->eType) { case frmOpenEvent: form = FrmGetActiveForm(); FrmDrawForm(form); draw_histogram(0,region_stack_idx-1); handled = 1; break; case ctlSelectEvent: // A control button was pressed and released. switch (event->data.ctlSelect.controlID) { default: break; } case menuEvent: switch (event->data.menu.itemID) { case menuitemID_about: FrmAlert(alertID_about); handled = 1; break; case menuitemID_card_info: // form = FrmGetActiveForm(); // FrmDeleteForm(form); FrmGotoForm(formID_sys_info); break; } break; case nilEvent: // continue region simulation sim_regs(); update_form_main_ri_sim(); handled = 1; break; } return handled; }
/* ** Popup the transfer details list. */ static void DoXferList(void) { const Int16 num_plugs = PlugIndex(NULL, true); if (!d.xfer.pluglistH || !num_plugs) { FrmAlert(NoPluginInstalled); } else { RectangleType rect; Int16 list_selection = -1; FormType* frm = FrmGetActiveForm(); ListPtr list = GetObjectPointer(frm, XferList); /* Set up plugin list control */ LstSetDrawFunction(list, XferListDrawFunc); LstSetListChoices(list, NULL, num_plugs); LstSetHeight(list, Min(num_plugs, 10)); FrmGetObjectBounds(frm, FrmGetObjectIndex(frm, XferList), &rect); rect.topLeft.x = 16; rect.topLeft.y = 144 - rect.extent.y; rect.extent.x = d.xfer.plug_menu_width; FrmSetObjectBounds(frm, FrmGetObjectIndex(frm, XferList), &rect); /* Pop up the list */ LstSetSelection(list, GetCurrentXferAppListIndex()); list_selection = LstPopupList(list); if (list_selection != -1) { SysDBListItemType* pluglistP = MemHandleLock(d.xfer.pluglistH); /* Store the current plugin */ p.xfer_current_plug = pluglistP[PlugIndex(list_selection, false)].creator; /* Clean up */ MemHandleUnlock(d.xfer.pluglistH); } } }
static Boolean MainFormHandleEvent (EventPtr e) { Boolean handled = false; FormPtr frm; switch (e->eType) { case frmOpenEvent: frm = FrmGetActiveForm(); DrawIntro(); FrmDrawForm(frm); DrawState(); // Draw those dice! handled = true; break; case frmUpdateEvent: DrawPlayers(); break; case menuEvent: MenuEraseStatus(NULL); switch(e->data.menu.itemID) { case MenuItem_Help: FrmHelp( GenericHelp ); break; case MenuItem_About: FrmAlert(About_Info); break; case MenuItem_New: DialogNewGame(); break; case MenuItem_Reset: ResetCubes(); DrawState(); break; case MenuItem_Defaults: Defaults(); ResetCubes(); DrawState(); break; case MenuItem_Variants: if ( GetCurrPlayer() < 0 ) { DialogVariants(); } else { FrmAlert(NoVariants); } break; case MenuItem_Preferences: DialogPreferences(); break; } handled = true; break; case ctlSelectEvent: switch(e->data.ctlSelect.controlID) { case btn_Stay: ShowButtons(false); Stay(); break; case btn_Info: //FrmAlert(About_Info); DialogStatus(); break; case btn_Roll: if ( isGameOn() ) { ShowButtons(false); Roll(); } else { DialogNewGame(); } break; case btnTopStatus: FrmHelp( TS_LastLicks ); break; } handled = true; break; case winExitEvent: if( e->data.winExit.exitWindow == (WinHandle)FrmGetFormPtr(MainForm) ) { /* Turn off animations and the AI */ FreezeBit = true; } break; case winEnterEvent: if (e->data.winEnter.enterWindow == (WinHandle)FrmGetFormPtr(MainForm) && e->data.winEnter.enterWindow == (WinHandle)FrmGetFirstForm ()) { /* Turn back on animations and the AI */ FreezeBit = false; } default: break; } return handled; }
Boolean CourseListHandleEvent(EventPtr event) { FormPtr frm=FrmGetActiveForm(); Boolean handled = false; ListType *lstP=GetObjectPtr(LIST_courses); Boolean categoryEdited, reDraw=false; UInt16 category, numRecords; ControlType *ctl; UInt32 *recordList; if (event->eType == ctlSelectEvent) { // button handling switch (event->data.ctlSelect.controlID) { case BUTTON_courselist_back: handled=true; FrmGotoForm(FORM_main); break; case BUTTON_courselist_del: handled=true; if (LstGetSelection(lstP) == noListSelection) { FrmAlert(ALERT_clist_noitem); } else { DeleteCourse(gCourseInd[LstGetSelection(lstP)]); CleanupCourselist(); DrawCourses(lstP); FrmDrawForm(FrmGetActiveForm()); } break; case BUTTON_courselist_add: handled=true; gMenuCurrentForm=FORM_courselist; AddCourse(); break; case BUTTON_courselist_edit: handled=true; if (LstGetSelection(lstP) == noListSelection) { FrmAlert(ALERT_clist_noitem); } else { gMenuCurrentForm=FORM_courselist; EditCourse(gCourseInd[LstGetSelection(lstP)]); } break; case BUTTON_courselist_beam: handled=true; if (LstGetSelection(lstP) == noListSelection) { FrmAlert(ALERT_clist_noitem); } else { BeamCourse(gCourseInd[LstGetSelection(lstP)]); } break; case LIST_cl_cat_trigger: handled=true; category=DatabaseGetCat(); numRecords=DmNumRecordsInCategory(DatabaseGetRef(), DELETE_CATEGORY); recordList=(UInt32 *)MemPtrNew(numRecords * sizeof(UInt32)); CatPreEdit(numRecords, recordList); categoryEdited = CategorySelect(DatabaseGetRef(), frm, LIST_cl_cat_trigger, LIST_cl_cat, false, &category, gCategoryName, 0, STRING_cat_edit); // categoryDefaultEditCategoryString if (categoryEdited || (category != DatabaseGetCat())) { reDraw=true; DatabaseSetCat(category); ctl = GetObjectPtr(LIST_cl_cat_trigger); CategoryGetName(DatabaseGetRef(), category, gCategoryName); CategorySetTriggerLabel(ctl, gCategoryName); } CatPostEdit(numRecords, recordList); if (reDraw) { CleanupCourselist(); DrawCourses(lstP); FrmDrawForm(FrmGetActiveForm()); } if (recordList != NULL) MemPtrFree((MemPtr)recordList); break; default: break; } } else if (event->eType == keyDownEvent) { // We have a hard button assigned and it was pressed if (TxtCharIsHardKey(event->data.keyDown.modifiers, event->data.keyDown.chr)) { if (! (event->data.keyDown.modifiers & poweredOnKeyMask)) { FrmGotoForm(FORM_main); handled = true; } } else if (EvtKeydownIsVirtual(event)) { // Up or down keys pressed ListType *lst=GetObjectPtr(LIST_courses); switch (event->data.keyDown.chr) { case vchrPageUp: if (LstGetSelection(lst) == noListSelection) { LstSetSelection(lst, gNumCourses-1); CourseListHandleSelection(); } else if (LstGetSelection(lst) > 0) { LstSetSelection(lst, LstGetSelection(lst)-1); CourseListHandleSelection(); } handled=true; break; case vchrPageDown: if (LstGetSelection(lst) == noListSelection) { LstSetSelection(lst, 0); CourseListHandleSelection(); } else if (LstGetSelection(lst) < (gNumCourses-1)) { LstSetSelection(lst, LstGetSelection(lst)+1); CourseListHandleSelection(); } handled=true; break; default: break; } } } else if (event->eType == lstSelectEvent) { return CourseListHandleSelection(); } else if (event->eType == menuOpenEvent) { return HandleMenuOpenEvent(event); } else if (event->eType == menuEvent) { // forwarding of menu events return HandleMenuEvent(event->data.menu.itemID); } else if (event->eType == frmOpenEvent) { // initializes and draws the form ControlType *ctl; frm = FrmGetActiveForm(); lstP=GetObjectPtr(LIST_courses); FrmDrawForm (frm); DrawCourses(lstP); FrmDrawForm (frm); ctl = GetObjectPtr(LIST_cl_cat_trigger); CategoryGetName (DatabaseGetRef(), DatabaseGetCat(), gCategoryName); CategorySetTriggerLabel (ctl, gCategoryName); WinDrawLine(1, 140, 158, 140); handled = true; } else if (event->eType == frmUpdateEvent) { // redraws the form if needed CleanupCourselist(); DrawCourses(GetObjectPtr(LIST_courses)); FrmDrawForm (frm); WinDrawLine(1, 140, 158, 140); handled = false; } else if (event->eType == frmCloseEvent) { // this is done if form is closed CleanupCourselist(); } return (handled); }
static Boolean MainFormHandleEvent(EventPtr eventP) { Boolean handled = false; FormType *frmP; switch (eventP->eType) { case menuEvent: if (eventP->data.menu.itemID == AboutMenuItm) { MenuEraseStatus(0); FrmAlert(AboutAlert); handled = true; break; } break; case frmOpenEvent: frmP = FrmGetActiveForm(); FrmDrawForm(frmP); handled = true; break; case ctlSelectEvent: switch(eventP->data.ctlSelect.controlID) { case JavaButton: playJavaSound(); handled=true; break; default: break; } break; case keyDownEvent: if(NavSelectPressed(eventP)) { playJavaSound(); handled=true; break; } switch (eventP->data.keyDown.chr) { case vchrPageUp: case vchrJogUp: case vchrPageDown: case vchrJogDown: case vchrJogPush: case vchrJogPushedUp: case vchrJogPushedDown: playJavaSound(); handled = true; break; } break; case winDisplayChangedEvent: { RectangleType curBounds,displayBounds; frmP=FrmGetActiveForm(); WinGetBounds(FrmGetWindowHandle(frmP),&curBounds); WinGetBounds(WinGetDisplayWindow(), &displayBounds); JavaFormResizeForm(frmP,&curBounds,&displayBounds); FrmDrawForm(frmP); handled=true; break; } default: break; } return handled; }
/* Finds and opens database, * calls plugin specific code to create new item, * then fills in GoTo parameters. */ static UInt16 PickBooger(KleenexPtr kleenexP) { DmOpenRef dbR; DmSearchStateType searchstate; UInt32 creatorID, dbtype; UInt16 cardNo; LocalID dbID; Boolean closedb = false; UInt16 err, index; UInt32 result; /* Check for the correct version */ if (!((kleenexP->version) & IBVERSION_ORIG)) return (boogerErrorVersionMismatch); /* Open the database */ if (DmGetNextDatabaseByTypeCreator(true, &searchstate, DB_TYPE, DB_CREATOR, true, &cardNo, &dbID)) return (1); if ((dbR = DmOpenDatabase(cardNo, dbID, dmModeReadWrite))) { closedb = true; } else if (DmGetLastErr() == dmErrAlreadyOpenForWrites) { dbR = NULL; while ((dbR = DmNextOpenDatabase(dbR))) { DmOpenDatabaseInfo(dbR, &dbID, NULL, NULL, &cardNo, NULL); DmDatabaseInfo(cardNo, dbID, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &dbtype, &creatorID); if ((dbtype == DB_TYPE) && (creatorID == DB_CREATOR)) break; } if (!dbR) return (1); } /* Call plugin specific routine to create item in database */ err = DoTheBoogie(kleenexP, dbR, &index); /* Close the database */ if (closedb) DmCloseDatabase(dbR); /* Did it work? */ if (err) return (1); /* Load the GoTo parameters */ if (!(kleenexP->booger.cmdPBP = MemPtrNew(sizeof(GoToParamsType)))) return (1); MemSet(kleenexP->booger.cmdPBP, sizeof(GoToParamsType), 0); ((GoToParamsType *)(kleenexP->booger.cmdPBP))->dbCardNo = cardNo; ((GoToParamsType *)(kleenexP->booger.cmdPBP))->dbID = dbID; ((GoToParamsType *)(kleenexP->booger.cmdPBP))->recordNum = index; MemPtrSetOwner(kleenexP->booger.cmdPBP, 0); /* Send signal to set the alarm */ if (kleenexP->alarm_secs) { if (DmGetNextDatabaseByTypeCreator(true, &searchstate, sysFileTApplication, GOTO_ID, true, &cardNo, &dbID)) { FrmAlert(alertID_noDateBk4); MemPtrFree(kleenexP->booger.cmdPBP); return (1); } if (SysAppLaunch(cardNo, dbID, 0, sysAppLaunchCmdSyncNotify, NULL, &result)) FrmAlert(alertID_noAlarmSet); } return (errNone); }