home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2001 Mobile
/
Chip_Mobile_2001.iso
/
palm
/
tools
/
blastpad
/
blastpad.EXE
/
blastpad.c
next >
Wrap
C/C++ Source or Header
|
2000-11-19
|
23KB
|
763 lines
/*************
* Code (C) 2000 Daniel Church
* Distributed under the GNU copyleft (GPL)
*
* This is my first real application for the Palm, so I welcome any comments,
* criticisms, etc. you might have at dchurch@mbhs.edu.
*************/
#include <System/SysAll.h>
#include <UI/UIAll.h>
#include <System/KeyMgr.h>
#include "blastpad.h"
#define BlastAppID 'BPad'
typedef struct {
UInt32 creators[22];
char name[26];
} category;
VoidHand catsHand;
category *cats;
DWord numcats;
DWord curcat=0;
DWord numbtns;
Char displaytype;
Char btnnumdisplay;
Char multistart;
DWord mainformid;
struct application {
UInt32 creator;
Char name[32];
BitmapPtr icon;
LocalID dbID;
UInt16 cardno;
Char clean; // set after database info has been loaded
} *apps=NULL;
DWord numapps;
Char *noselect="-default-";
Char *novalue="-none-";
Char allclean=0; // set after first visit to prefs
Char **names=NULL;
Char **catnames=NULL;
FormType *form=NULL,*oldform=NULL;
DWord LoadGlobals();
void FreeGlobals();
Int16 appCompare(const struct application *, const struct application *,
Int16, SortRecordInfoPtr, SortRecordInfoPtr, VoidHand);
void LoadDBInfo(Int16);
void EventLoop();
DWord NameIndex(DWord,Boolean);
SDWord Target(UInt32,SDWord *,Boolean);
SDWord AppIndex(UInt32);
void ChangeNumBtns(DWord);
void DelCat(DWord);
void BuildNames();
Int16 IconX(UInt32);
Int16 IconY(UInt32);
Int16 TextX(UInt32, Char *);
Int16 TextY(UInt32, Char *);
Boolean mainHandler(EventType *);
Boolean prefsHandler(EventType *);
Boolean hwbtnsHandler(EventType *);
Boolean osbtnsHandler(EventType *);
Boolean newcatHandler(EventType *);
Boolean editcatHandler(EventType *);
Boolean hwcueHandler(EventType *);
Boolean (*handlers[])(EventType *)={
&mainHandler,
&mainHandler,
&mainHandler,
&prefsHandler,
&hwbtnsHandler,
&osbtnsHandler,
&hwcueHandler,
&newcatHandler,
&editcatHandler
};
DWord PilotMain( Word cmd, Ptr cmdPBP, Word launchFlags ) {
if (cmd == sysAppLaunchCmdNormalLaunch) {
if(LoadGlobals())
EventLoop();
else
FrmAlert(AlrNOMEM);
FreeGlobals();
}
return(0);
}
Int16 appCompare(const struct application *a, const struct application *b,
Int16 other, SortRecordInfoPtr p1, SortRecordInfoPtr p2,
VoidHand h)
{
int i;
for(i = 0; i < 32; i++)
if (a->name[i] != b->name[i] || a->name[i]==0)
return a->name[i] - b->name[i];
return 0;
}
DWord LoadGlobals() {
DWord appnum,dbnum,numdbs,cardno;
UInt32 type;
UInt16 size;
Int16 retsize;
UInt32 hwbtns;
Int16 startupbtn=0;
DWord index;
hwbtns=KeyCurrentState();
if(hwbtns==keyBitHard1)
startupbtn=HB1;
if(hwbtns==keyBitHard2)
startupbtn=HB2;
if(hwbtns==keyBitHard3)
startupbtn=HB3;
if(hwbtns==keyBitHard4)
startupbtn=HB4;
size=sizeof(DWord);
retsize=PrefGetAppPreferences(BlastAppID, 0, &numcats, &size, true);
if(retsize==noPreferenceFound) {
numcats=1;
numbtns=4;
catsHand=MemHandleNew(sizeof(category));
cats=MemHandleLock(catsHand);
StrCopy(cats[0].name,"Default");
for(index=0;index<22;index++)
cats[0].creators[index]=1; // no value
} else {
PrefGetAppPreferences(BlastAppID,1,&numbtns,&size,true);
size=sizeof(category)*numcats;
catsHand=MemHandleNew(size);
cats=MemHandleLock(catsHand);
PrefGetAppPreferences(BlastAppID,2,cats,&size,true);
for(index=0;index<22;index++)
if(cats[0].creators[index]==0)
cats[0].creators[index]=1; // fix old versions
}
size=sizeof(Char);
retsize=PrefGetAppPreferences(BlastAppID,3,&multistart,&size,true);
if(retsize==noPreferenceFound)
multistart=0;
retsize=PrefGetAppPreferences(BlastAppID,4,&displaytype,&size,true);
if(retsize==noPreferenceFound)
displaytype=2;
retsize=PrefGetAppPreferences(BlastAppID,5,&btnnumdisplay,&size,true);
if(retsize==noPreferenceFound)
btnnumdisplay=0;
numdbs=0;
for(cardno=0;cardno<MemNumCards();cardno++)
numdbs+=DmNumDatabases(cardno);
if(!(apps = MemPtrNew(sizeof(struct application)*numdbs)))
return(0);
appnum=0;
for(cardno=0;cardno<MemNumCards();cardno++) {
for(dbnum=0;dbnum<DmNumDatabases(cardno);dbnum++) {
apps[appnum].dbID=DmGetDatabase(cardno,dbnum);
apps[appnum].cardno=cardno;
DmDatabaseInfo(cardno,apps[appnum].dbID,apps[appnum].name,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,&type,&(apps[appnum].creator));
if(type!='appl' || apps[appnum].creator=='lnch')
continue;
apps[appnum].clean=0;
appnum++;
}
}
numapps=appnum;
MemPtrResize(apps,sizeof(struct application)*numapps);
if(numbtns==4)
mainformid=Frm4BTN;
if(numbtns==9)
mainformid=Frm9BTN;
if(numbtns==16)
mainformid=Frm16BTN;
if(startupbtn!=0 && multistart!=0 && Target(startupbtn,&index,false)==-1)
curcat=index;
BuildNames();
FrmPopupForm(mainformid);
return(1);
}
void LoadDBInfo(Int16 appnum) {
DmOpenRef db;
VoidHand icon;
apps[appnum].icon=NULL;
db=DmOpenDatabase(apps[appnum].cardno,apps[appnum].dbID,dmModeReadOnly);
if(db!=0) {
icon=DmGet1Resource('tAIN',1000);
if(icon!=NULL) {
StrCopy(apps[appnum].name,MemHandleLock(icon));
MemHandleUnlock(icon);
}
icon=DmGet1Resource('tAIB',1000);
if(icon!=NULL) {
apps[appnum].icon=MemPtrNew(MemHandleSize(icon));
MemMove(apps[appnum].icon,MemHandleLock(icon),MemHandleSize(icon));
MemHandleUnlock(icon);
}
DmCloseDatabase(db);
}
apps[appnum].clean=1;
}
void FreeGlobals() {
int app;
PrefSetAppPreferences(BlastAppID, 0, 2, &numcats, sizeof(DWord), true);
PrefSetAppPreferences(BlastAppID, 1, 2, &numbtns, sizeof(DWord), true);
PrefSetAppPreferences(BlastAppID, 2, 2, cats, sizeof(category)*numcats, true);
PrefSetAppPreferences(BlastAppID, 3, 2, &multistart, sizeof(Char), true);
PrefSetAppPreferences(BlastAppID, 4, 2, &displaytype, sizeof(Char), true);
PrefSetAppPreferences(BlastAppID, 5, 2, &btnnumdisplay, sizeof(Char), true);
if(catsHand) MemHandleFree(catsHand);
if(apps) {
for(app=0;app<numapps;app++)
if(apps[app].icon!=NULL && apps[app].clean)
MemPtrFree(apps[app].icon);
MemPtrFree(apps);
}
if(names) MemPtrFree(names);
}
void EventLoop() {
EventType event;
UInt16 err;
SDWord btnnum;
SDWord type, index;
do {
EvtGetEvent(&event, -1);
if(event.eType == keyDownEvent && !(event.data.keyDown.modifiers & poweredOnKeyMask) && (FrmGetFormId(FrmGetActiveForm())==mainformid || FrmGetFormId(FrmGetActiveForm())==FrmHWCUE)) {
if(event.data.keyDown.chr == vchrFind && FrmGetFormId(FrmGetActiveForm())==mainformid) {
oldform=form;
FrmPopupForm(FrmHWCUE);
continue;
}
switch(event.data.keyDown.chr) {
case vchrHard1: btnnum=HB1; break;
case vchrHard2: btnnum=HB2; break;
case vchrHard3: btnnum=HB3; break;
case vchrHard4: btnnum=HB4; break;
case chrPageUp: btnnum=UP; break;
case chrPageDown: btnnum=DN; break;
default: btnnum=-1; break;
}
type=Target(btnnum,&index,1);
if(type==1) {
SysUIAppSwitch(apps[index].cardno,apps[index].dbID,sysAppLaunchCmdNormalLaunch,NULL);
continue;
}
if(type==-1) {
if(FrmGetFormId(FrmGetActiveForm())==FrmHWCUE) {
form=oldform;
FrmReturnToForm(mainformid);
}
curcat=index;
for(btnnum=0;btnnum<numbtns;btnnum++) {
index=NameIndex(btnnum,1);
CtlSetLabel((ControlType *)FrmGetObjectPtr(form,FrmGetObjectIndex(form,btnnum)),names[index]);
}
continue;
}
}
if(SysHandleEvent(&event)) continue;
if(MenuHandleEvent(NULL, &event, &err)) continue;
if(event.eType==frmLoadEvent) {
form=FrmInitForm(event.data.frmLoad.formID);
FrmSetEventHandler(form,handlers[event.data.frmLoad.formID]);
FrmSetActiveForm(form);
}
FrmDispatchEvent(&event);
} while(event.eType != appStopEvent);
}
Boolean mainHandler(EventType *event) {
DWord type, index,btnnum;
SDWord tindex;
RectangleType bounds;
if(event->eType == frmOpenEvent) {
for(btnnum=0;btnnum<numbtns;btnnum++) {
index=NameIndex(btnnum,1);
if(Target(btnnum,&tindex,1)==1 && apps[tindex].clean==0)
LoadDBInfo(tindex);
if(Target(btnnum,&tindex,1)!=1 || apps[tindex].icon==NULL || displaytype==0)
CtlSetLabel((ControlType *)FrmGetObjectPtr(form,FrmGetObjectIndex(form,btnnum)),names[index]);
if(btnnumdisplay==0)
FrmHideObject(form,FrmGetObjectIndex(form,btnnum+TEXTOFFSET));
}
FrmDrawForm(form);
for(btnnum=0;btnnum<numbtns;btnnum++) {
index=NameIndex(btnnum,1);
if(Target(btnnum,&tindex,1)==1 && apps[tindex].icon!=NULL && displaytype>0) {
WinDrawBitmap(apps[tindex].icon,IconX(btnnum),IconY(btnnum));
if(displaytype==2)
WinDrawChars(names[index],StrLen(names[index]),TextX(btnnum,names[index]),TextY(btnnum,names[index]));
}
}
return(true);
}
if(event->eType == ctlSelectEvent) {
type=Target(event->data.ctlSelect.controlID,&index,1);
if(type==1) {
SysUIAppSwitch(apps[index].cardno,apps[index].dbID,sysAppLaunchCmdNormalLaunch,NULL);
return(true);
}
if(type==-1) {
curcat=index;
for(btnnum=0;btnnum<numbtns;btnnum++) {
index=NameIndex(btnnum,1);
if(Target(btnnum,&tindex,1)==1 && apps[tindex].clean==0)
LoadDBInfo(tindex);
if(Target(btnnum,&tindex,1)!=1 || apps[tindex].icon==NULL || displaytype==0)
CtlSetLabel((ControlType *)FrmGetObjectPtr(form,FrmGetObjectIndex(form,btnnum)),names[index]);
else {
CtlSetLabel((ControlType *)FrmGetObjectPtr(form,FrmGetObjectIndex(form,btnnum)),"");
index=NameIndex(btnnum,1);
WinDrawBitmap(apps[tindex].icon,IconX(btnnum),IconY(btnnum));
if(displaytype==2)
WinDrawChars(names[index],StrLen(names[index]),TextX(btnnum,names[index]),TextY(btnnum,names[index]));
}
}
return(true);
}
}
if(event->eType == menuEvent) {
if(event->data.menu.itemID==0)
FrmGotoForm(FrmGENPREFS);
else
FrmAlert(AlrABOUT);
return(true);
}
return(false);
}
Boolean prefsHandler(EventType *event) {
ListType *list;
DWord index=0;
if(event->eType == frmOpenEvent) {
if(allclean==0) {
for(index=0;index<numapps;index++)
if(apps[index].clean==0)
LoadDBInfo(index);
SysQSort(apps, numapps, sizeof(struct application), (CmpFuncPtr)(&appCompare), 0);
BuildNames();
allclean=1;
}
if(numbtns==4)
index=0;
if(numbtns==9)
index=1;
if(numbtns==16)
index=2;
list=FrmGetObjectPtr(form,FrmGetObjectIndex(form,NUMBTNS+LISTOFFSET));
LstSetSelection(list,index);
CtlSetLabel(FrmGetObjectPtr(form,FrmGetObjectIndex(form,NUMBTNS)),LstGetSelectionText(list,index));
list=FrmGetObjectPtr(form,FrmGetObjectIndex(form,DISPLAYTYPE+LISTOFFSET));
LstSetSelection(list,displaytype);
CtlSetLabel(FrmGetObjectPtr(form,FrmGetObjectIndex(form,DISPLAYTYPE)),LstGetSelectionText(list,displaytype));
list=FrmGetObjectPtr(form,FrmGetObjectIndex(form,CATEGORY+LISTOFFSET));
LstSetListChoices(list,catnames,numcats);
LstSetSelection(list,curcat);
CtlSetLabel(FrmGetObjectPtr(form,FrmGetObjectIndex(form,CATEGORY)),LstGetSelectionText(list,curcat));
CtlSetValue(FrmGetObjectPtr(form,FrmGetObjectIndex(form,MULTISTART)),multistart);
CtlSetValue(FrmGetObjectPtr(form,FrmGetObjectIndex(form,BTNNUMDISPLAY)),btnnumdisplay);
FrmDrawForm(form);
return(true);
}
if(event->eType == frmUpdateEvent && event->data.frmUpdate.updateCode==2) {
list=FrmGetObjectPtr(FrmGetFormPtr(FrmGENPREFS),FrmGetObjectIndex(FrmGetFormPtr(FrmGENPREFS),CATEGORY+LISTOFFSET));
LstSetListChoices(list,catnames,numcats);
LstSetSelection(list,curcat);
CtlSetLabel(FrmGetObjectPtr(FrmGetFormPtr(FrmGENPREFS),FrmGetObjectIndex(FrmGetFormPtr(FrmGENPREFS),CATEGORY)),LstGetSelectionText(list,curcat));
return(true);
}
if(event->eType == popSelectEvent) {
if(event->data.popSelect.listID == NUMBTNS + LISTOFFSET)
ChangeNumBtns(event->data.popSelect.selection);
if(event->data.popSelect.listID == DISPLAYTYPE + LISTOFFSET)
displaytype=event->data.popSelect.selection;
if(event->data.popSelect.listID == CATEGORY + LISTOFFSET)
curcat=event->data.popSelect.selection;
return(false);
}
if(event->eType == ctlSelectEvent) {
if(event->data.ctlSelect.controlID == NEWCAT) {
oldform=form;
FrmPopupForm(FrmNEWCAT);
return(true);
}
if(event->data.ctlSelect.controlID == EDITCAT) {
oldform=form;
FrmPopupForm(FrmEDITCAT);
return(true);
}
if(event->data.ctlSelect.controlID == DELCAT) {
if(curcat==0) {
FrmAlert(AlrNODELDEFAULT);
return(true);
}
if(FrmAlert(AlrQUERYDELCAT)==0) {
DelCat(curcat);
FrmUpdateForm(FrmGENPREFS,2);
}
return(true);
}
if(event->data.ctlSelect.controlID == MODHWBTNS) {
FrmGotoForm(FrmHWBUTTONS);
return(true);
}
if(event->data.ctlSelect.controlID == MODOSBTNS) {
FrmGotoForm(FrmOSBUTTONS);
return(true);
}
if(event->data.ctlSelect.controlID == MULTISTART) {
multistart=CtlGetValue(FrmGetObjectPtr(form,FrmGetObjectIndex(form,MULTISTART)));
return(true);
}
if(event->data.ctlSelect.controlID == BTNNUMDISPLAY) {
btnnumdisplay=CtlGetValue(FrmGetObjectPtr(form,FrmGetObjectIndex(form,BTNNUMDISPLAY)));
return(true);
}
if(event->data.ctlSelect.controlID == OKAYBTN) {
FrmGotoForm(mainformid);
return(true);
}
}
return(false);
}
Boolean osbtnsHandler(EventType *event) {
DWord appnum,sel,btnnum;
ListType *list;
if(event->eType == frmOpenEvent) {
for(btnnum=0;btnnum<16;btnnum++) {
if(btnnum<numbtns) {
list=FrmGetObjectPtr(form,FrmGetObjectIndex(form,btnnum+LISTOFFSET));
LstSetListChoices(list,names+(curcat==0),numapps+numcats+1+(curcat!=0));
LstSetSelection(list,NameIndex(btnnum,0)-(curcat==0));
CtlSetLabel((ControlType *)FrmGetObjectPtr(form,FrmGetObjectIndex(form,btnnum)),names[NameIndex(btnnum,0)]);
} else {
FrmHideObject(form,FrmGetObjectIndex(form,btnnum));
FrmHideObject(form,FrmGetObjectIndex(form,btnnum+TEXTOFFSET));
}
}
FrmDrawForm(form);
return(true);
}
if(event->eType == ctlSelectEvent && event->data.ctlSelect.controlID == OKAYBTN) {
for(appnum=0;appnum<numbtns;appnum++) {
sel=LstGetSelection(FrmGetObjectPtr(form,FrmGetObjectIndex(form,appnum+LISTOFFSET)))+(curcat==0);
if(sel==0 || sel==noListSelection)
cats[curcat].creators[appnum]=0;
else if(sel==1)
cats[curcat].creators[appnum]=1;
else if(sel <= numapps+1)
cats[curcat].creators[appnum]=apps[sel-2].creator;
else
cats[curcat].creators[appnum]=sel-numapps;
}
FrmGotoForm(FrmGENPREFS);
return(true);
}
return(false);
}
Boolean hwbtnsHandler(EventType *event) {
DWord appnum,sel,btnnum;
ListType *list;
if(event->eType == frmOpenEvent) {
for(btnnum=16;btnnum<22;btnnum++) {
list=FrmGetObjectPtr(form,FrmGetObjectIndex(form,btnnum+LISTOFFSET));
LstSetListChoices(list,names+(curcat==0),numapps+numcats+1+(curcat!=0));
LstSetSelection(list,NameIndex(btnnum,0)-(curcat==0));
CtlSetLabel((ControlType *)FrmGetObjectPtr(form,FrmGetObjectIndex(form,btnnum)),names[NameIndex(btnnum,0)]);
}
FrmDrawForm(form);
return(true);
}
if(event->eType == ctlSelectEvent && event->data.ctlSelect.controlID == OKAYBTN) {
for(appnum=16;appnum<22;appnum++) {
sel=LstGetSelection(FrmGetObjectPtr(form,FrmGetObjectIndex(form,appnum+LISTOFFSET)))+(curcat==0);
if(sel==0 || sel==noListSelection)
cats[curcat].creators[appnum]=0;
else if(sel==1)
cats[curcat].creators[appnum]=1;
else if(sel <= numapps+1)
cats[curcat].creators[appnum]=apps[sel-2].creator;
else
cats[curcat].creators[appnum]=sel-numapps;
}
FrmGotoForm(FrmGENPREFS);
return(true);
}
return(false);
}
Boolean newcatHandler(EventType *event) {
Char *name;
if(event->eType == frmOpenEvent) {
FrmDrawForm(form);
FrmSetFocus(form,FrmGetObjectIndex(form,CATNAME));
return(true);
}
if(event->eType == ctlSelectEvent) {
if(event->data.ctlSelect.controlID == OKAYBTN) {
name=FldGetTextPtr(FrmGetObjectPtr(form,FrmGetObjectIndex(form,CATNAME)));
if(name==NULL || StrLen(name)==0) {
FrmAlert(AlrEMPTYCAT);
return(true);
}
numcats++;
MemHandleUnlock(catsHand);
if(MemHandleResize(catsHand,numcats*sizeof(category))==memErrNotEnoughSpace) {
FrmAlert(AlrNOMEM);
numcats--;
cats=MemHandleLock(catsHand);
return(true);
}
cats=MemHandleLock(catsHand);
StrCopy(cats[numcats-1].name,name);
MemSet(&(cats[numcats-1].creators),4*22,0);
BuildNames();
curcat=numcats-1;
FrmUpdateForm(FrmGENPREFS,2);
}
form=oldform;
FrmReturnToForm(FrmGENPREFS);
return(true);
}
return(false);
}
Boolean editcatHandler(EventType *event) {
VoidHand nameHand,oldHand;
FieldType *field;
Char *name;
if(event->eType == frmOpenEvent) {
nameHand=MemHandleNew(26);
name=MemHandleLock(nameHand);
StrCopy(name,cats[curcat].name);
name=NULL;
MemHandleUnlock(nameHand);
field=(FieldType *)FrmGetObjectPtr(form,FrmGetObjectIndex(form,CATNAME));
oldHand=(VoidHand)FldGetTextHandle(field);
FldSetTextHandle(field,(Handle)nameHand);
if(oldHand)
MemHandleFree(oldHand);
FrmDrawForm(form);
FrmSetFocus(form,FrmGetObjectIndex(form,CATNAME));
return(true);
}
if(event->eType == ctlSelectEvent) {
if(event->data.ctlSelect.controlID == OKAYBTN) {
name=FldGetTextPtr(FrmGetObjectPtr(form,FrmGetObjectIndex(form,CATNAME)));
if(name==NULL || StrLen(name)==0) {
FrmAlert(AlrEMPTYCAT);
return(true);
}
StrCopy(cats[curcat].name,name);
BuildNames();
FrmUpdateForm(FrmGENPREFS,2);
}
form=oldform;
FrmReturnToForm(FrmGENPREFS);
return(true);
}
return(false);
}
Boolean hwcueHandler(EventType *event) {
DWord btnnum,namei;
SDWord tindex;
if(event->eType == frmOpenEvent) {
for(btnnum=16;btnnum<22;btnnum++) {
if(Target(btnnum,&tindex,1)==1 && apps[tindex].clean==0)
LoadDBInfo(tindex);
namei=NameIndex(btnnum,1);
CtlSetLabel((ControlType *)FrmGetObjectPtr(form,FrmGetObjectIndex(form,btnnum)),names[namei]);
}
FrmDrawForm(form);
return(true);
}
if(event->eType == penDownEvent || event->eType == keyDownEvent) {
form=oldform;
FrmReturnToForm(mainformid);
return(true);
}
return(false);
}
DWord NameIndex(DWord btnnum, Boolean searchdefault) {
DWord type,index;
type=Target(btnnum,&index,searchdefault);
if(type==0) {
// FrmCustomAlert(AlrDEBUG,"NameIndex","type0","");
return(index);
}
if(type==1) {
// FrmCustomAlert(AlrDEBUG,"NameIndex","type1","");
return(index+2);
}
// FrmCustomAlert(AlrDEBUG,"NameIndex","type-1","");
return(index+numapps+2);
}
void ChangeNumBtns(DWord num) {
mainformid=num;
if(num==0)
numbtns=4;
if(num==1)
numbtns=9;
if(num==2)
numbtns=16;
}
void BuildNames() {
DWord appnum;
if(names) MemPtrFree(names);
if(catnames) MemPtrFree(catnames);
names=MemPtrNew(sizeof(Char *) * (numapps+numcats+2));
catnames=MemPtrNew(sizeof(Char *) * (numcats));
names[0]=noselect;
names[1]=novalue;
for(appnum=0;appnum<numapps;appnum++)
names[appnum+2] = apps[appnum].name;
for(appnum=0;appnum<numcats;appnum++)
names[appnum+numapps+2] = catnames[appnum] = cats[appnum].name;
}
void DelCat(DWord cat) {
DWord catnum,appnum;
if(cat==(--numcats)) {
MemHandleResize(catsHand,numcats*sizeof(category));
BuildNames();
curcat=0;
return;
}
for(catnum=0;catnum<=numcats;catnum++)
for(appnum=0;appnum<22;appnum++) {
if(cats[catnum].creators[appnum]==cat+2)
cats[catnum].creators[appnum]=1;
if(cats[catnum].creators[appnum]==numcats+2)
cats[catnum].creators[appnum]=cat+2;
}
MemMove(&(cats[cat]),&(cats[numcats]),sizeof(category));
MemHandleResize(catsHand,numcats*sizeof(category));
// BuildNames();
curcat=0;
}
SDWord AppIndex(UInt32 creator) {
DWord appnum;
for(appnum=0;appnum<numapps&&apps[appnum].creator!=creator;appnum++)
;
if(appnum<numapps)
return(appnum);
return(-1);
}
SDWord Target(UInt32 btnnum, SDWord *value, Boolean searchdefault) {
UInt32 creator;
if(btnnum<0 || btnnum>=22)
return(0);
creator=cats[curcat].creators[btnnum];
if (creator==0) {
if(searchdefault)
creator=cats[0].creators[btnnum];
*value=creator;
if(creator==0)
return(0);
}
*value=creator;
if (creator<=1)
return(0);
if (creator<=numcats+1) {
*value=creator-2;
return(-1); //category
}
if((*value=AppIndex(creator))!=-1) {
return(1); //application
}
return(0);
}
Int16 IconX(UInt32 btnnum) {
Int16 basex;
switch(numbtns) {
case 4:
basex=80*(btnnum%2);
return(basex+25);
case 9:
basex=53*(btnnum%3);
return(basex+11);
case 16:
basex=40*(btnnum%4);
return(basex+5);
}
return(0);
}
Int16 IconY(UInt32 btnnum) {
Int16 basey;
switch(numbtns) {
case 4:
basey=80*(btnnum/2);
return(basey+27-(4*(displaytype==2)));
case 9:
basey=53*(btnnum/3);
return(basey+13-(4*(displaytype==2)));
case 16:
basey=40*(btnnum/4);
return(basey+7-(4*(displaytype==2)));
}
return(0);
}
Int16 TextX(UInt32 btnnum, Char *string) {
Int16 basex=0;
switch(numbtns) {
case 4:
basex=80*(btnnum%2)+41; break;
case 9:
basex=53*(btnnum%3)+27; break;
case 16:
basex=40*(btnnum%4)+21; break;;
}
return(basex-FntCharsWidth(string,StrLen(string))/2);
}
Int16 TextY(UInt32 btnnum, Char *string) {
Int16 basey;
switch(numbtns) {
case 4:
basey=80*(btnnum/2);
return(basey+47);
case 9:
basey=53*(btnnum/3);
return(basey+33);
case 16:
basey=40*(btnnum/4);
return(basey+27);
}
return(0);
}