diff options
author | Chris Apers | 2005-11-05 10:26:46 +0000 |
---|---|---|
committer | Chris Apers | 2005-11-05 10:26:46 +0000 |
commit | d4e1a3997d92cf83d7161bb6b430403234dd842c (patch) | |
tree | 450b626d2f134c968ab0d21ecb946831166238ab /backends/PalmOS/Src | |
parent | dfe8fc25b4cc170f3334b9ccb23b312e63ed945f (diff) | |
download | scummvm-rg350-d4e1a3997d92cf83d7161bb6b430403234dd842c.tar.gz scummvm-rg350-d4e1a3997d92cf83d7161bb6b430403234dd842c.tar.bz2 scummvm-rg350-d4e1a3997d92cf83d7161bb6b430403234dd842c.zip |
New cards form
svn-id: r19438
Diffstat (limited to 'backends/PalmOS/Src')
-rw-r--r-- | backends/PalmOS/Src/forms/formCards.cpp | 365 |
1 files changed, 217 insertions, 148 deletions
diff --git a/backends/PalmOS/Src/forms/formCards.cpp b/backends/PalmOS/Src/forms/formCards.cpp index c4d1e2cdf6..ece4fc4c34 100644 --- a/backends/PalmOS/Src/forms/formCards.cpp +++ b/backends/PalmOS/Src/forms/formCards.cpp @@ -2,7 +2,9 @@ #include <VFSMgr.h> #include "start.h" +#include "formTabs.h" #include "forms.h" +#include "globals.h" typedef struct { UInt16 volRefNum; @@ -10,43 +12,45 @@ typedef struct { } CardInfoType; -void CardSlotCreateDirs() { - if (gPrefs->card.volRefNum != sysInvalidRefNum) { - VFSDirCreate(gPrefs->card.volRefNum, "/PALM"); - VFSDirCreate(gPrefs->card.volRefNum, "/PALM/Programs"); - VFSDirCreate(gPrefs->card.volRefNum, "/PALM/Programs/ScummVM"); - VFSDirCreate(gPrefs->card.volRefNum, "/PALM/Programs/ScummVM/Games"); - VFSDirCreate(gPrefs->card.volRefNum, "/PALM/Programs/ScummVM/Saved"); - VFSDirCreate(gPrefs->card.volRefNum, "/PALM/Programs/ScummVM/Audio"); - VFSDirCreate(gPrefs->card.volRefNum, "/PALM/Programs/ScummVM/Mods"); - } -} +static TabType *myTabP; +static UInt16 lastTab = 0; -static void CardSlotFromShowHideOptions() { - ControlType *cck1P; - FormPtr frmP = FrmGetActiveForm(); +static void CardSlotFormExit(Boolean bSave); - cck1P = (ControlType *)GetObjectPtr(CardSlotMoveCheckbox); +static void CardSlotFreeList() { + MemHandle cards = NULL; + MemHandle items = NULL; - if (CtlGetValue(cck1P)) { - FrmShowObject(frmP, FrmGetObjectIndex (frmP, CardSlotDeleteCheckbox)); - FrmShowObject(frmP, FrmGetObjectIndex (frmP, CardSlotConfirmCheckbox)); - } else { - FrmHideObject(frmP, FrmGetObjectIndex (frmP, CardSlotDeleteCheckbox)); - FrmHideObject(frmP, FrmGetObjectIndex (frmP, CardSlotConfirmCheckbox)); + if (itemsText && itemsList) { + cards = MemPtrRecoverHandle(itemsList); + items = MemPtrRecoverHandle(itemsText); + + itemsText = NULL; + itemsList = NULL; + } + itemsType = ITEM_TYPE_UNKNOWN; + + if (items && cards) { + MemHandleUnlock(items); + MemHandleUnlock(cards); + MemHandleFree(items); + MemHandleFree(cards); } } -static UInt16 CardSlotFormInit(Boolean display, Boolean bDraw) { +static UInt16 CardSlotFillList(Boolean getRefNum = false) { Err err; + UInt16 index; UInt16 volRefNum; UInt32 volIterator = vfsIteratorStart; UInt8 counter = 0; UInt32 other = 1; + MemHandle items = NULL; MemHandle cards = NULL; CardInfoType *cardsInfo; + // retreive card infos while (volIterator != vfsIteratorStop) { err = VFSVolumeEnumerate(&volRefNum, &volIterator); @@ -57,13 +61,13 @@ static UInt16 CardSlotFormInit(Boolean display, Boolean bDraw) { if (err || StrLen(labelP) == 0) { // if no label try to retreive card type VolumeInfoType volInfo; err = VFSVolumeInfo(volRefNum, &volInfo); - + if (!err) { ExpCardInfoType info; err = ExpCardInfo(volInfo.slotRefNum, &info); StrCopy(labelP, info.deviceClassStr); } - + if (err) // if err default name StrPrintF(labelP,"Other Card %ld", other++); } @@ -72,7 +76,7 @@ static UInt16 CardSlotFormInit(Boolean display, Boolean bDraw) { cards = MemHandleNew(sizeof(CardInfoType)); else MemHandleResize(cards, MemHandleSize(cards) + sizeof(CardInfoType)); - + cardsInfo = (CardInfoType *)MemHandleLock(cards); cardsInfo[counter].volRefNum = volRefNum; StrCopy(cardsInfo[counter].nameP, labelP); @@ -81,24 +85,9 @@ static UInt16 CardSlotFormInit(Boolean display, Boolean bDraw) { } } - if (display) { - FormPtr frmP; - ListPtr listP; - ControlType *cck1P, *cck2P, *cck3P; - UInt16 index; - Int16 selected = -1; - - CardInfoType *cardsInfo; - MemHandle items = NULL; - - listP = (ListType *)GetObjectPtr(CardSlotSlotList); - cck1P = (ControlType *)GetObjectPtr(CardSlotMoveCheckbox); - cck2P = (ControlType *)GetObjectPtr(CardSlotDeleteCheckbox); - cck3P = (ControlType *)GetObjectPtr(CardSlotConfirmCheckbox); - - if (counter > 0) { - cardsInfo = (CardInfoType *)MemHandleLock(cards); - + if (counter > 0) { + // set the list items ... + if (!getRefNum) { for (index = 0; index < counter; index++) { if (!items) items = MemHandleNew(sizeof(Char *)); @@ -108,161 +97,223 @@ static UInt16 CardSlotFormInit(Boolean display, Boolean bDraw) { itemsText = (Char **)MemHandleLock(items); itemsText[index] = cardsInfo[index].nameP; MemHandleUnlock(items); - - if (cardsInfo[index].volRefNum == gPrefs->card.volRefNum) - selected = index; } + // save globals itemsText = (Char **)MemHandleLock(items); - LstSetListChoices (listP, itemsText, counter); - LstSetSelection(listP, selected); - // save globals and set list - itemsText = (Char **)MemHandleLock(items); - itemsList = (void *)cardsInfo; - itemsType = ITEM_TYPE_CARD; - - } else { - LstSetListChoices(listP, NULL, 0); - // save globals and set list - itemsText = NULL; - itemsList = NULL; + itemsList = (void *)MemHandleLock(cards); itemsType = ITEM_TYPE_CARD; - } - - // bDraw = true -> draw whole from - // bDraw = false -> redraw list - if (bDraw) { - CtlSetValue(cck1P, gPrefs->card.moveDB); - CtlSetValue(cck2P, gPrefs->card.deleteDB); - CtlSetValue(cck3P, gPrefs->card.confirmMoveDB); - CardSlotFromShowHideOptions(); - frmP = FrmGetActiveForm(); - FrmDrawForm(frmP); + // ... or just return a default volRefNum } else { - WinScreenLock(winLockCopy); - LstDrawList(listP); - WinScreenUnlock(); - } - } else { // if !display, we just want to retreive an avaliable card - if (counter > 0) { UInt16 volRefNum; + cardsInfo = (CardInfoType *)MemHandleLock(cards); volRefNum = cardsInfo[0].volRefNum; // return the first volref MemHandleUnlock(cards); MemHandleFree(cards); + return volRefNum; } + + // no card found ? free old list in any or return invalid volref + } else { + if (!getRefNum) + CardSlotFreeList(); + else + return sysInvalidRefNum; } - return sysInvalidRefNum; // default + return counter; } -static void CardSlotFormExit(Boolean bSave) { - MemHandle cards; - MemHandle items; - CardInfoType *cardsInfo; - UInt16 updateCode = frmRedrawUpdateMS; +static void ConfigTabInit(Boolean update = false) { + ListPtr listP; - if (itemsText && itemsList) { - cardsInfo = (CardInfoType *)itemsList; - cards = MemPtrRecoverHandle(cardsInfo); - items = MemPtrRecoverHandle(itemsText); + UInt16 index; + Int16 selected = -1; - itemsText = NULL; - itemsList = NULL; - } else { - cards = NULL; - items = NULL; - } - itemsType = ITEM_TYPE_UNKNOWN; + UInt16 counter = CardSlotFillList(); + listP = (ListType *)GetObjectPtr(TabCardConfigSlotList); - if (bSave) { - ListType *listP; - ControlType *cck1P, *cck2P, *cck3P; - Int16 selected; - - listP = (ListType *)GetObjectPtr(CardSlotSlotList); - cck1P = (ControlType *)GetObjectPtr(CardSlotMoveCheckbox); - cck2P = (ControlType *)GetObjectPtr(CardSlotDeleteCheckbox); - cck3P = (ControlType *)GetObjectPtr(CardSlotConfirmCheckbox); - selected = LstGetSelection(listP); - - if (selected == -1) { - gPrefs->card.volRefNum = sysInvalidRefNum; - } else if (gPrefs->card.volRefNum != cardsInfo[selected].volRefNum) { - updateCode = frmRedrawUpdateMSImport; - gPrefs->card.volRefNum = cardsInfo[selected].volRefNum; + // itemsText can be NULL if counter = 0 + LstSetListChoices (listP, itemsText, counter); + if (counter > 0) { + CardInfoType *cardsInfo = (CardInfoType *)itemsList; + + for (index = 0; index < counter; index++) { + if (cardsInfo[index].volRefNum == gPrefs->card.volRefNum) { + selected = index; + break; + } } - gPrefs->card.moveDB = CtlGetValue(cck1P); - gPrefs->card.deleteDB = CtlGetValue(cck2P); - gPrefs->card.confirmMoveDB = CtlGetValue(cck3P); - CardSlotCreateDirs(); + LstSetSelection(listP, selected); } - FrmReturnToMain(updateCode); + if (!update) { + FieldType *fld1P; + Char *cacheP; + MemHandle cacheH; + + fld1P = (FieldType *)GetObjectPtr(TabCardConfigCacheSizeField); + cacheH = MemHandleNew(FldGetMaxChars(fld1P)+1); + cacheP = (Char *)MemHandleLock(cacheH); + StrIToA(cacheP, gPrefs->card.cacheSize / 1024); + MemHandleUnlock(cacheH); + + FldSetTextHandle(fld1P, cacheH); + CtlSetValue((ControlType *)GetObjectPtr(TabCardConfigCacheCheckbox), gPrefs->card.useCache); + CtlSetValue((ControlType *)GetObjectPtr(TabCardConfigLedCheckbox), gPrefs->card.showLED); + // update ? redraw the list + } else { + WinScreenLock(winLockCopy); + LstDrawList(listP); + WinScreenUnlock(); + } +} - if (items && cards) { - MemHandleUnlock(items); - MemHandleUnlock(cards); - MemHandleFree(items); - MemHandleFree(cards); +static UInt16 ConfigTabSave() { + ControlType *cckP[2]; + FieldType *fld1P; + ListPtr listP; + FormPtr frmP; + UInt16 updateCode = frmRedrawUpdateMS; + + cckP[0] = (ControlType *)GetObjectPtr(TabCardConfigCacheCheckbox); + cckP[1] = (ControlType *)GetObjectPtr(TabCardConfigLedCheckbox); + + gPrefs->card.useCache = CtlGetValue(cckP[0]); + gPrefs->card.showLED = CtlGetValue(cckP[1]); + + fld1P = (FieldType *)GetObjectPtr(TabCardConfigCacheSizeField); + frmP = FrmGetActiveForm(); + if (FldGetTextLength(fld1P) == 0 && CtlGetValue(cckP[0]) == 1) { + TabSetActive(frmP, myTabP, 0); + FrmSetFocus(frmP, FrmGetObjectIndex(frmP, TabCardConfigCacheSizeField)); + FrmCustomAlert(FrmWarnAlert,"You must specified a cache size.",0,0); + return 0; } + gPrefs->card.cacheSize = StrAToI(FldGetTextPtr(fld1P)) * 1024; + + Int16 selected; + CardInfoType *cardsInfo = (CardInfoType *)itemsList; + + listP = (ListType *)GetObjectPtr(TabCardConfigSlotList); + selected = LstGetSelection(listP); + if (selected == -1) { + gPrefs->card.volRefNum = sysInvalidRefNum; + } else if (gPrefs->card.volRefNum != cardsInfo[selected].volRefNum) { + updateCode = frmRedrawUpdateMSImport; + gPrefs->card.volRefNum = cardsInfo[selected].volRefNum; + } + + CardSlotCreateDirs(); + CardSlotFreeList(); + + return updateCode; } -void CardSlotFormUpdate() { - if (itemsType == ITEM_TYPE_CARD) { - if (itemsText && itemsList) { - MemHandle cards; - MemHandle items; - ListType *listP; +static void GameListTabInit() { + CtlSetValue((ControlType *)GetObjectPtr(TabCardGameListMoveCheckbox), gPrefs->card.moveDB); + CtlSetValue((ControlType *)GetObjectPtr(TabCardGameListDeleteCheckbox), gPrefs->card.deleteDB); + CtlSetValue((ControlType *)GetObjectPtr(TabCardGameListConfirmCheckbox), gPrefs->card.confirmMoveDB); +} - listP = (ListType *)GetObjectPtr(CardSlotSlotList); - cards = MemPtrRecoverHandle(itemsList); - items = MemPtrRecoverHandle(itemsText); +static void GameListTabSave() { + ControlType *cckP[3]; - itemsText = NULL; - itemsList = NULL; - itemsType = ITEM_TYPE_UNKNOWN; + cckP[0] = (ControlType *)GetObjectPtr(TabCardGameListMoveCheckbox); + cckP[1] = (ControlType *)GetObjectPtr(TabCardGameListDeleteCheckbox); + cckP[2] = (ControlType *)GetObjectPtr(TabCardGameListConfirmCheckbox); - MemHandleUnlock(items); - MemHandleUnlock(cards); - MemHandleFree(items); - MemHandleFree(cards); - } - CardSlotFormInit(true, false); + gPrefs->card.moveDB = CtlGetValue(cckP[0]); + gPrefs->card.deleteDB = CtlGetValue(cckP[1]); + gPrefs->card.confirmMoveDB = CtlGetValue(cckP[2]); +} + +static void GameListTabDraw() { + ControlType *cck1P; + FormPtr frmP = FrmGetActiveForm(); + + cck1P = (ControlType *)GetObjectPtr(TabCardGameListMoveCheckbox); + if (CtlGetValue(cck1P)) { + FrmShowObject(frmP, FrmGetObjectIndex (frmP, TabCardGameListDeleteCheckbox)); + FrmShowObject(frmP, FrmGetObjectIndex (frmP, TabCardGameListConfirmCheckbox)); + } else { + FrmHideObject(frmP, FrmGetObjectIndex (frmP, TabCardGameListDeleteCheckbox)); + FrmHideObject(frmP, FrmGetObjectIndex (frmP, TabCardGameListConfirmCheckbox)); } } +static void CardSlotFormInit() { + TabType *tabP; + FormType *frmP = FrmGetActiveForm(); + + tabP = TabNewTabs(2); + TabAddContent(&frmP, tabP, "Cards", TabCardConfigForm); + TabAddContent(&frmP, tabP, "Game List", TabCardGameListForm, GameListTabDraw); + + ConfigTabInit(); + GameListTabInit(); + + FrmDrawForm(frmP); + TabSetActive(frmP, tabP, lastTab); + + myTabP = tabP; +} + +static void CardSlotFormSave() { + UInt16 updateCode; + updateCode = ConfigTabSave(); + if (!updateCode) return; + GameListTabSave(); + CardSlotCreateDirs(); + + TabDeleteTabs(myTabP); + FrmReturnToMain(updateCode); +} + +static void CardSlotFormCancel() { + CardSlotFreeList(); + TabDeleteTabs(myTabP); + FrmReturnToMain(); +} + Boolean CardSlotFormHandleEvent(EventPtr eventP) { + FormPtr frmP = FrmGetActiveForm(); Boolean handled = false; switch (eventP->eType) { - case frmOpenEvent: - CardSlotFormInit(true, true); + CardSlotFormInit(); handled = true; break; case frmCloseEvent: - CardSlotFormExit(false); + CardSlotFormCancel(); handled = true; break; case ctlSelectEvent: switch (eventP->data.ctlSelect.controlID) { + case (CardSlotForm + 1) : + case (CardSlotForm + 2) : + lastTab = (eventP->data.ctlSelect.controlID - CardSlotForm - 1); + TabSetActive(frmP, myTabP, lastTab); + break; + case CardSlotOkButton: - CardSlotFormExit(true); + CardSlotFormSave(); break; case CardSlotCancelButton: - CardSlotFormExit(false); + CardSlotFormCancel(); break; - - case CardSlotMoveCheckbox: - CardSlotFromShowHideOptions(); + + case TabCardGameListMoveCheckbox: + GameListTabDraw(); break; } handled = true; @@ -271,13 +322,31 @@ Boolean CardSlotFormHandleEvent(EventPtr eventP) { default: break; } - + return handled; } -UInt16 parseCards() { - UInt16 volRefNum = CardSlotFormInit(false, false); - CardSlotFormExit(false); +void CardSlotCreateDirs() { + if (gPrefs->card.volRefNum != sysInvalidRefNum) { + VFSDirCreate(gPrefs->card.volRefNum, "/PALM"); + VFSDirCreate(gPrefs->card.volRefNum, "/PALM/Programs"); + VFSDirCreate(gPrefs->card.volRefNum, "/PALM/Programs/ScummVM"); + VFSDirCreate(gPrefs->card.volRefNum, "/PALM/Programs/ScummVM/Games"); + VFSDirCreate(gPrefs->card.volRefNum, "/PALM/Programs/ScummVM/Saved"); + VFSDirCreate(gPrefs->card.volRefNum, "/PALM/Programs/ScummVM/Audio"); + VFSDirCreate(gPrefs->card.volRefNum, "/PALM/Programs/ScummVM/Mods"); + } +} +void CardSlotFormUpdate() { + if (itemsType == ITEM_TYPE_CARD) { + CardSlotFreeList(); + ConfigTabInit(true); + } +} + +UInt16 parseCards() { + UInt16 volRefNum = CardSlotFillList(true); + CardSlotFreeList(); return volRefNum; } |