/* * tearEdit.c * * Editing icons in tearoff menus * * © 1994-1998 Straylight */ /*----- Licensing note ----------------------------------------------------* * * This file is part of Straylight's Glass. * * Glass is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * Glass is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Glass. If not, write to the Free Software Foundation, * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /*----- Header files ------------------------------------------------------*/ /* * ANSI standard headers */ #include #include #include /* * Steel and RISC_OSLib headers */ #define _STDAPP #include "steel/Steel.h" #include "steel/buttons.h" #include "steel/akbd.h" #include "steel/buffer.h" #include "steel/colourtran.h" #include "steel/tearoff.h" /* * Glass headers */ #include "gStruct.h" #include "glass.h" #include "window.h" #include "tfile.h" #include "indir.h" #include "tearEdit.h" /*----- Static variables --------------------------------------------------*/ static glass_windPointer *tearEdit__window; /* The window with the icon */ static int tearEdit__icon=-1; /* The icon we're editing */ static tearoff tearEdit__main; /* The main tearoff edit menu */ static tearoff tearEdit__data; static tearoff tearEdit__appear; static tearoff tearEdit__actions; static tearoff tearEdit__btype; static tearoff tearEdit__colours; /*----- Menu structure ----------------------------------------------------* * * Icon data => Data => [dbox] * Indirected => [dbox] * Text * Sprite * Appearance => Anti-aliased => Font => [font menu] * Size => [dbox] * Horizontally centred * Vertically centred * Right aligned * Border * Filled background * Half-size sprite * Needs help * Actions => Button type => [type menu] * ESG => [dbox] * Adjust toggles * Selected * Shaded * Colours => Foreground => [dbox] * Background => [dbox] * Position => [dbox] * Size => [dbox] */ /*----- Icon numbers for dialogues ----------------------------------------*/ #define tearEdit__DATAOK 0 #define tearEdit__DATAWRITE 1 #define tearEdit__ESGOK 0 #define tearEdit__ESGUP 1 #define tearEdit__ESGDOWN 2 #define tearEdit__ESGWRITE 3 #define tearEdit__INDOK 0 #define tearEdit__INDINDIR 2 #define tearEdit__INDSWRITE 4 #define tearEdit__INDSUP 5 #define tearEdit__INDSDOWN 6 #define tearEdit__INDMINIMISE 7 #define tearEdit__INDPART 8 #define tearEdit__INDVALID 9 #define tearEdit__INDVALSTRING 10 #define tearEdit__COLOUROK 0 #define tearEdit__COLOURCOLS 2 #define tearEdit__POSOK 0 #define tearEdit__POSUP 2 #define tearEdit__POSDOWN 3 #define tearEdit__POSLEFT 4 #define tearEdit__POSRIGHT 5 #define tearEdit__POSWRITE 6 /*----- Item numbers for menus --------------------------------------------*/ enum { tearEdit__MAINDATA=1, tearEdit__MAINAPPEAR, tearEdit__MAINACTIONS, tearEdit__MAINCOLOURS, tearEdit__MAINPOS, tearEdit__MAINSIZE }; enum { tearEdit__DATADATA=1, tearEdit__DATAINDIR, tearEdit__DATATEXT, tearEdit__DATASPRITE }; enum { tearEdit__APPEARHCENTRE=1, tearEdit__APPEARVCENTRE, tearEdit__APPEARRALIGN, tearEdit__APPEARBORDER, tearEdit__APPEARFILLED, tearEdit__APPEARHALF, tearEdit__APPEARHELP }; enum { tearEdit__ACTIONSBTYPE=1, tearEdit__ACTIONSESG, tearEdit__ACTIONSADJUST, tearEdit__ACTIONSSELECT, tearEdit__ACTIONSSHADE }; enum { tearEdit__COLOURSFORE=1, tearEdit__COLOURSBACK }; /*----- Messing about with indirected data --------------------------------*/ /* * void tearEdit__setData(wimp_icon *icn, * char *data, * char *valid, * int newsize) * * Use * Sets an icon's data as required, possibly extending the data buffer and * indirecting if required. Old buffers are freed and new ones allocated * etc. * * Parameters * wimp_icon *icn == the icon to edit in this way * char *data == pointer to the new data string, or 0 to leave it alone * char *valid == pointer to the new validation string, or 0 to leave it * alone, or tearEdit__NOVALID to delete it * int newsize == the size of the new indirection buffer, or * tearEdit__NOINDIR to not indirect the string */ #define tearEdit__NOVALID ((char *)(-1)) #define tearEdit__NOINDIR (-1) #define tearEdit__NOCHANGE (-2) static void tearEdit__setData(wimp_icon *icn, char *data, char *valid, int newsize) { char nonind[13]; int maxlen=newsize; wimp_iconflags nf=icn->flags; char *p=0,*q; /* --- Fill in default arguments --- */ if (!data) { if (tst(icn->flags,8)) { data=icn->data.indirecttext.buffer; utils_ctermToNterm(data); } else { memcpy(nonind,icn->data.text,12); nonind[12]=0; utils_ctermToNterm(nonind); data=nonind; } } if (!valid) { if (tst(icn->flags,0) && tst(icn->flags,8)) { valid=icn->data.indirecttext.validstring; if (valid!=tearEdit__NOVALID) utils_ctermToNterm(valid); } else valid=tearEdit__NOVALID; } if (maxlen==tearEdit__NOCHANGE) { if (tst(icn->flags,8)) maxlen=icn->data.indirecttext.bufflen; else maxlen=tearEdit__NOINDIR; } /* --- Set up new icon flags --- */ if (maxlen==tearEdit__NOINDIR) { maxlen=12; reset(nf,8); } else set(nf,8); if (strlen(data)>=maxlen) { set(nf,8); maxlen=strlen(data)+1; } /* --- Set up new buffers for data --- */ if (tst(nf,8)) { if (p=indir_alloc(maxlen),!p) { werr(FALSE,msgs_lookup("teNEMUI")); return; } if (tst(nf,0) && valid!=tearEdit__NOVALID) { if (q=indir_alloc(strlen(valid)+1),!q) { indir_free(p); werr(FALSE,msgs_lookup("teNEMUI")); return; } window_redrawIcon(tearEdit__window,tearEdit__icon); strcpy(q,valid); valid=q; tearEdit__window->size+=strlen(valid)+1; } strcpy(p,data); tearEdit__window->size+=maxlen; } /* --- Clear out the old buffers now --- */ if (tst(icn->flags,8)) { tearEdit__window->size-=icn->data.indirecttext.bufflen; if (tst(icn->flags,0) && icn->data.indirecttext.validstring!=tearEdit__NOVALID) { utils_ctermToNterm(icn->data.indirecttext.validstring); tearEdit__window->size-=strlen(icn->data.indirecttext.validstring)+1; } } /* --- Now copy the new data across --- */ if (tst(nf,8)) { icn->data.indirecttext.bufflen=maxlen; icn->data.indirecttext.buffer=p; if ((nf & 3)==2) icn->data.indirectsprite.spritearea=tearEdit__window->t->s; else icn->data.indirecttext.validstring=valid; } else memcpy(icn->data.text,data,12); icn->flags=nf; /* --- That's it (phew!) --- */ window_redrawIcon(tearEdit__window,tearEdit__icon); tfile_markAsAltered(tearEdit__window->t); } /*----- Icon data dialogue boxes ------------------------------------------*/ /* --- Alter data --- */ /* * void tearEdit__dataBox(void) * * Use * Displays a dialogue box allowing the user to change an icon's data. */ static void tearEdit__dataBox(void) { dbox d; wimp_icon *icn; char nonind[256]; char *data; BOOL done=FALSE; if (!tearEdit__window || tearEdit__icon==-1) return; icn=&tearEdit__window->def->i[tearEdit__icon].i; if (!(icn->flags & 3)) return; if (tst(icn->flags,8)) data=icn->data.indirecttext.buffer; else { memcpy(nonind,icn->data.text,12); nonind[13]=0; data=nonind; } utils_ctermToNterm(data); d=dbox_create("teditData"); if (!d) return; dbox_setfield(d,tearEdit__DATAWRITE,"%s",data); dbox_display(d,dbox_MENU_OVERPTR); while (!done) { switch (dbox_fillin(d)) { case dbox_CLOSE: done=TRUE; break; case tearEdit__DATAOK: dbox_clickicon(d,tearEdit__DATAOK); dbox_getfield(d,tearEdit__DATAWRITE,nonind,256); tearEdit__setData(icn,nonind,0,tearEdit__NOCHANGE); if (dbox_wasAdjustClick()) dbox_unclick(); else { dbox_hide(d); dbox_unclick(); done=TRUE; } break; } } dbox_delete(d); } /* --- Alter indirection --- */ /* * void tearEdit__setupIndBox(dbox d,wimp_icon *icn,BOOL *ind,BOOL *val) * * Use * Sets up the icons in an indirection dialogue box. * * Parameters * dbox d == the dialogue box's handle * wimp_icon *icn == the icon to read the definition from * BOOL *ind == (output) whether the icon is indirected * BOOL *val == (output) whether the icon has a validation string */ static void tearEdit__setupIndBox(dbox d,wimp_icon *icn,BOOL *ind,BOOL *val) { if (tst(icn->flags,8)) { *ind=TRUE; dbox_selecticon(d,tearEdit__INDINDIR,TRUE); dbox_shadeicon(d,tearEdit__INDSUP,FALSE); dbox_shadeicon(d,tearEdit__INDSDOWN,FALSE); dbox_shadeicon(d,tearEdit__INDSWRITE,FALSE); dbox_shadeicon(d,tearEdit__INDMINIMISE,FALSE); dbox_shadeicon(d,tearEdit__INDPART,FALSE); dbox_setfield(d,tearEdit__INDSWRITE,"%i",icn->data.indirecttext.bufflen); if (tst(icn->flags,0)) { if (icn->data.indirecttext.validstring!=tearEdit__NOVALID) { *val=TRUE; dbox_selecticon(d,tearEdit__INDVALID,TRUE); dbox_shadeicon(d,tearEdit__INDVALSTRING,FALSE); utils_ctermToNterm(icn->data.indirecttext.validstring); dbox_setfield(d, tearEdit__INDVALSTRING, "%s", icn->data.indirecttext.validstring); } else { *val=FALSE; dbox_selecticon(d,tearEdit__INDVALID,FALSE); dbox_shadeicon(d,tearEdit__INDVALID,FALSE); dbox_shadeicon(d,tearEdit__INDVALSTRING,TRUE); dbox_setfield(d,tearEdit__INDVALSTRING,""); } } else { *val=FALSE; dbox_selecticon(d,tearEdit__INDVALID,FALSE); dbox_shadeicon(d,tearEdit__INDVALID,TRUE); dbox_shadeicon(d,tearEdit__INDVALSTRING,TRUE); dbox_setfield(d,tearEdit__INDVALSTRING,""); } } else { *ind=FALSE; dbox_selecticon(d,tearEdit__INDINDIR,FALSE); dbox_shadeicon(d,tearEdit__INDSUP,TRUE); dbox_shadeicon(d,tearEdit__INDSDOWN,TRUE); dbox_shadeicon(d,tearEdit__INDSWRITE,TRUE); dbox_shadeicon(d,tearEdit__INDMINIMISE,TRUE); dbox_shadeicon(d,tearEdit__INDPART,TRUE); dbox_setfield(d,tearEdit__INDSWRITE,"12"); *val=FALSE; dbox_selecticon(d,tearEdit__INDVALID,FALSE); dbox_shadeicon(d,tearEdit__INDVALID,TRUE); dbox_shadeicon(d,tearEdit__INDVALSTRING,TRUE); dbox_setfield(d,tearEdit__INDVALSTRING,""); } } /* * void tearEdit__indirBox(void) * * Use * Displays and handles an indirection dialogue box. */ static void tearEdit__indirBox(void) { dbox d; char buff[256]; wimp_icon *icn; int size; BOOL done=FALSE; BOOL ind; BOOL val; buttons_simpleArrow sa={0,9999,FALSE}; dbox_field f; if (!tearEdit__window || tearEdit__icon==-1) return; icn=&tearEdit__window->def->i[tearEdit__icon].i; if (!(icn->flags & 3)) return; d=dbox_create("teditIndir"); if (!d) return; tearEdit__setupIndBox(d,icn,&ind,&val); dbox_display(d,dbox_MENU_OVERPTR); while (!done) { switch (f=dbox_fillin(d),f) { case dbox_CLOSE: done=TRUE; break; case tearEdit__INDINDIR: ind=!ind; dbox_shadeicon(d,tearEdit__INDSUP,!ind); dbox_shadeicon(d,tearEdit__INDSDOWN,!ind); dbox_shadeicon(d,tearEdit__INDSWRITE,!ind); dbox_shadeicon(d,tearEdit__INDMINIMISE,!ind); dbox_shadeicon(d,tearEdit__INDPART,!ind); if (tst(icn->flags,0)) { dbox_shadeicon(d,tearEdit__INDVALID,!ind); dbox_shadeicon(d,tearEdit__INDVALSTRING,!(ind && val)); } break; case tearEdit__INDSUP: buttons_arrow(d,f,d,tearEdit__INDSWRITE,0,+1,&sa); break; case tearEdit__INDSDOWN: buttons_arrow(d,f,d,tearEdit__INDSWRITE,0,-1,&sa); break; case tearEdit__INDMINIMISE: dbox_clickicon(d,f); if (icn->flags & wimp_INDIRECT) { dbox_setfield(d,tearEdit__INDSWRITE,"%i", strlen(icn->data.indirecttext.buffer)+1); } else { char buff[15]; memcpy(buff,icn->data.text,12); buff[12]=0; utils_ctermToNterm(buff); dbox_setfield(d,tearEdit__INDSWRITE,"%i",strlen(buff)+1); } dbox_unclick(); break; case tearEdit__INDVALID: val=!val; dbox_shadeicon(d,tearEdit__INDVALSTRING,!val); break; case tearEdit__INDOK: dbox_clickicon(d,tearEdit__INDOK); if (ind) { dbox_scanfield(d,tearEdit__INDSWRITE,"%d",&size); if (val) { dbox_getfield(d,tearEdit__INDVALSTRING,buff,256); tearEdit__setData(icn,0,buff,size); } else tearEdit__setData(icn,0,tearEdit__NOVALID,size); } else tearEdit__setData(icn,0,tearEdit__NOVALID,tearEdit__NOINDIR); if (dbox_wasAdjustClick()) { tearEdit__setupIndBox(d,icn,&ind,&val); dbox_unclick(); } else { dbox_hide(d); dbox_unclick(); done=TRUE; } break; } } dbox_delete(d); } /*----- ESG dialogue box --------------------------------------------------*/ /* * BOOL tearEdit__esgRaw(dbox d,wimp_eventstr *e,void *handle) * * Use * Handles raw events for the ESG dialogue box (basically, it forces the * ESG number to be in the correct range when you type it in. * * Parameters * dbox d == the dialogue box handle for the ESG dbox * wimp_eventstr *e == the event wot happened * void *handle == a handle wot we ignore */ static BOOL tearEdit__esgRaw(dbox d,wimp_eventstr *e,void *handle) { BOOL handled=FALSE; BOOL cursor=FALSE; unused(handle); switch (e->e) { case wimp_EKEY: switch (e->data.key.c.i) { case tearEdit__ESGWRITE: switch (e->data.key.chcode) { case akbd_DownK: case akbd_UpK: case akbd_TabK: case akbd_TabK+akbd_Sh: case akbd_UpK+akbd_Ctl: case akbd_DownK+akbd_Ctl: cursor=TRUE; break; } handled=buttons_insertChar(d,e->data.key.chcode,'0','9'); if (handled || cursor) buttons_arrowClick(d,tearEdit__ESGWRITE,0,31,0,FALSE); break; } break; } return (handled); } /* * void tearEdit__esgBox(void) * * Use * Allows the user to choose an exclusive selection group for an icon. */ static void tearEdit__esgBox(void) { dbox d; BOOL done=FALSE; wimp_icon *icn; int esg; buttons_simpleArrow sa={0,31,FALSE}; dbox_field f; if (!tearEdit__window || tearEdit__icon==-1) return; d=dbox_create("teditESG"); if (!d) return; icn=&tearEdit__window->def->i[tearEdit__icon].i; dbox_setfield(d,tearEdit__ESGWRITE,"%i",(icn->flags & 0x001F0000)>>16); dbox_rawEventHandler(d,tearEdit__esgRaw,0); dbox_display(d,dbox_MENU_OVERPTR); while (!done) { switch (f=dbox_fillin(d),f) { case dbox_CLOSE: done=TRUE; break; case tearEdit__ESGUP: buttons_arrow(d,f,d,tearEdit__ESGWRITE,0,+1,&sa); break; case tearEdit__ESGDOWN: buttons_arrow(d,f,d,tearEdit__ESGWRITE,0,-1,&sa); break; case tearEdit__ESGOK: dbox_clickicon(d,tearEdit__ESGOK); dbox_scanfield(d,tearEdit__ESGWRITE,"%d",&esg); icn->flags &= ~0x001F0000; icn->flags |= esg<<16; window_redrawIcon(tearEdit__window,tearEdit__icon); tfile_markAsAltered(tearEdit__window->t); if (dbox_wasAdjustClick()) dbox_unclick(); else { dbox_hide(d); dbox_unclick(); done=TRUE; } break; } } dbox_delete(d); } /*----- Colour dialogue boxes ---------------------------------------------*/ /* * void tearEdit__addBorder(dbox d,int colour) * * Use * Adds a border around the specified colour. * * Parameters * dbox d == the colour dialogue box's handle * int colour == the number of the colour to select */ static void tearEdit__addBorder(dbox d,int colour) { static wimp_paletteword blacknwhite[]={0,0,0,0, 0,255,255,255,}; static wimp_palettestr wimppal; int col; wimpt_noerr(wimp_readpalette(&wimppal)); wimpt_noerr(colourtran_return_Oppcolourformode(wimppal.c[colour], 0, blacknwhite, &col)); wimpt_noerr(colourtran_return_colourformode(blacknwhite[col], 12, wimppal.c, &col)); /* --- We now have the correctly contrasting colour in col --- */ wimpt_noerr(wimp_set_icon_state(dbox_syshandle(d), colour+tearEdit__COLOURCOLS, 5 | (col<<24), 0x0F000005)); } #define tearEdit__removeBorder(d,colour) \ wimpt_noerr(wimp_set_icon_state(dbox_syshandle(d), \ colour+tearEdit__COLOURCOLS, \ 0x00000000, \ 0x0F000005)); \ /* * void tearEdit__colourBox(BOOL fore) * * Use * Displays a dialogue box from which the user may choose an icon colour. * * Parameters * BOOL fore == whether this is the foreground or background we're editing */ static void tearEdit__colourBox(BOOL fore) { dbox d; wimp_icon *icn; BOOL done=FALSE; int colour; dbox_field f; if (!tearEdit__window || tearEdit__icon==-1) return; icn=&tearEdit__window->def->i[tearEdit__icon].i; if (tst(icn->flags,6)) return; d=dbox_create("teditColour"); if (!d) return; if (fore) colour=(icn->flags & 0x0F000000)>>24; else colour=(icn->flags & 0xF0000000)>>28; win_settitle(dbox_syshandle(d),msgs_lookup(fore ? "teFG" : "teBG")); tearEdit__addBorder(d,colour); dbox_display(d,dbox_MENU_OVERPTR); while (!done) { switch (f=dbox_fillin(d),f) { case dbox_CLOSE: done=TRUE; break; case tearEdit__COLOUROK: dbox_clickicon(d,tearEdit__COLOUROK); if (fore) { icn->flags &= ~0x0F000000; icn->flags |= colour<<24; } else { icn->flags &= ~0xF0000000; icn->flags |= colour<<28; } window_redrawIcon(tearEdit__window,tearEdit__icon); tfile_markAsAltered(tearEdit__window->t); if (dbox_wasAdjustClick()) dbox_unclick(); else { dbox_hide(d); dbox_unclick(); done=TRUE; } break; default: if (f>=tearEdit__COLOURCOLS && fxOrY ? &x : &y; *v+=diff; if (s->sizing && *v<0) *v=0; dbox_setfield(d,f,"%i,%i",x,y); } /* * void tearEdit__coordsBox(BOOL size) * * Use * Displays a dialogue box and allows the user to alter either the size or * position of an icon. * * Parameters * BOOL size == whether to alter the size or position */ static void tearEdit__coordsBox(BOOL size) { dbox d; BOOL done=FALSE; dbox_field f; wimp_icon *icn; int x,y; tearEdit__coordsArrowstr ca; if (!tearEdit__window || tearEdit__icon==-1) return; d=dbox_create(size ? "teditSize" : "teditPos"); if (!d) return; icn=&tearEdit__window->def->i[tearEdit__icon].i; if (size) { x=icn->box.x1-icn->box.x0; y=icn->box.y1-icn->box.y0; } else { x=icn->box.x0; y=icn->box.y0; } ca.sizing=size; dbox_setfield(d,tearEdit__POSWRITE,"%i,%i",x,y); dbox_display(d,dbox_MENU_OVERPTR); while (!done) { f=dbox_fillin(d); switch (f) { case dbox_CLOSE: done=TRUE; break; case tearEdit__POSUP: ca.xOrY=FALSE; buttons_arrow(d,f,d,tearEdit__POSWRITE, tearEdit__coordsArrows,+wimpt_dy(),&ca); break; case tearEdit__POSDOWN: ca.xOrY=FALSE; buttons_arrow(d,f,d,tearEdit__POSWRITE, tearEdit__coordsArrows,-wimpt_dy(),&ca); break; case tearEdit__POSLEFT: ca.xOrY=TRUE; buttons_arrow(d,f,d,tearEdit__POSWRITE, tearEdit__coordsArrows,-wimpt_dx(),&ca); break; case tearEdit__POSRIGHT: ca.xOrY=TRUE; buttons_arrow(d,f,d,tearEdit__POSWRITE, tearEdit__coordsArrows,+wimpt_dx(),&ca); break; case tearEdit__POSOK: dbox_clickicon(d,f); dbox_scanfield(d,tearEdit__POSWRITE,"%d,%d",&x,&y); window_redrawIcon(tearEdit__window,tearEdit__icon); if (size) { icn->box.x1=icn->box.x0+x; icn->box.y1=icn->box.y0+y; } else { icn->box.x1+=x-icn->box.x0; icn->box.y1+=y-icn->box.y0; icn->box.x0=x; icn->box.y0=y; } window_redrawIcon(tearEdit__window,tearEdit__icon); tfile_markAsAltered(tearEdit__window->t); if (dbox_wasAdjustClick()) dbox_unclick(); else { dbox_hide(d); dbox_unclick(); done=TRUE; } break; } } dbox_delete(d); } /*----- Menu handling -----------------------------------------------------*/ /* * void tearEdit__mainHits(tearoff_message m,int hit,void *handle) * etc. * * Use * Handles menu events for the main edit icon menu level * * Parameters * tearoff_message m == the type of event that happened * int hit == the item it happened to * void *handle == a waste of a good argument register */ static void tearEdit__mainHits(tearoff_message m,int hit,void *handle) { unused(handle); switch (m) { case tearoff_SELECTION: case tearoff_SUBMENU: switch (hit) { case tearEdit__MAINPOS: tearEdit__coordsBox(FALSE); break; case tearEdit__MAINSIZE: tearEdit__coordsBox(TRUE); break; } break; } } static void tearEdit__dataHits(tearoff_message m,int hit,void *handle) { unused(handle); switch (m) { case tearoff_SELECTION: case tearoff_SUBMENU: switch (hit) { case tearEdit__DATADATA: tearEdit__dataBox(); break; case tearEdit__DATAINDIR: tearEdit__indirBox(); break; case tearEdit__DATATEXT: tearEdit__window->def->i[tearEdit__icon].i.flags ^= wimp_ITEXT; tearEdit__setData(&tearEdit__window->def->i[tearEdit__icon].i, 0, tearEdit__NOVALID, tearEdit__NOCHANGE); break; case tearEdit__DATASPRITE: tearEdit__window->def->i[tearEdit__icon].i.flags ^= wimp_ISPRITE; tearEdit__setData(&tearEdit__window->def->i[tearEdit__icon].i, 0, 0, tearEdit__NOCHANGE); break; } break; } } static void tearEdit__appearHits(tearoff_message m,int hit,void *handle) { unused(handle); switch (m) { case tearoff_SELECTION: case tearoff_SUBMENU: switch (hit) { case tearEdit__APPEARHCENTRE: tearEdit__window->def->i[tearEdit__icon].i.flags ^= wimp_IHCENTRE; window_redrawIcon(tearEdit__window,tearEdit__icon); tfile_markAsAltered(tearEdit__window->t); break; case tearEdit__APPEARVCENTRE: tearEdit__window->def->i[tearEdit__icon].i.flags ^= wimp_IVCENTRE; window_redrawIcon(tearEdit__window,tearEdit__icon); tfile_markAsAltered(tearEdit__window->t); break; case tearEdit__APPEARRALIGN: tearEdit__window->def->i[tearEdit__icon].i.flags ^= wimp_IRJUST; window_redrawIcon(tearEdit__window,tearEdit__icon); tfile_markAsAltered(tearEdit__window->t); break; case tearEdit__APPEARBORDER: tearEdit__window->def->i[tearEdit__icon].i.flags ^= wimp_IBORDER; window_redrawIcon(tearEdit__window,tearEdit__icon); tfile_markAsAltered(tearEdit__window->t); break; case tearEdit__APPEARFILLED: tearEdit__window->def->i[tearEdit__icon].i.flags ^= wimp_IFILLED; window_redrawIcon(tearEdit__window,tearEdit__icon); tfile_markAsAltered(tearEdit__window->t); break; case tearEdit__APPEARHALF: tearEdit__window->def->i[tearEdit__icon].i.flags ^= wimp_IHALVESPRITE; window_redrawIcon(tearEdit__window,tearEdit__icon); tfile_markAsAltered(tearEdit__window->t); break; case tearEdit__APPEARHELP: tearEdit__window->def->i[tearEdit__icon].i.flags ^= wimp_IREDRAW; window_redrawIcon(tearEdit__window,tearEdit__icon); tfile_markAsAltered(tearEdit__window->t); break; } break; } } static void tearEdit__actionsHits(tearoff_message m,int hit,void *handle) { unused(handle); switch (m) { case tearoff_SELECTION: case tearoff_SUBMENU: switch (hit) { case tearEdit__ACTIONSESG: tearEdit__esgBox(); break; case tearEdit__ACTIONSADJUST: tearEdit__window->def->i[tearEdit__icon].i.flags ^= wimp_IESG_NOC; window_redrawIcon(tearEdit__window,tearEdit__icon); tfile_markAsAltered(tearEdit__window->t); break; case tearEdit__ACTIONSSELECT: tearEdit__window->def->i[tearEdit__icon].i.flags ^= wimp_ISELECTED; window_redrawIcon(tearEdit__window,tearEdit__icon); tfile_markAsAltered(tearEdit__window->t); break; case tearEdit__ACTIONSSHADE: tearEdit__window->def->i[tearEdit__icon].i.flags ^= wimp_INOSELECT; window_redrawIcon(tearEdit__window,tearEdit__icon); tfile_markAsAltered(tearEdit__window->t); break; } break; } } static void tearEdit__btypeHits(tearoff_message m,int hit,void *handle) { unused(handle); if (m==tearoff_SELECTION && hit>=1 && hit<=16) { tearEdit__window->def->i[tearEdit__icon].i.flags &= ~0x0000F000; tearEdit__window->def->i[tearEdit__icon].i.flags |= (hit-1)<<12; window_redrawIcon(tearEdit__window,tearEdit__icon); tfile_markAsAltered(tearEdit__window->t); } } static void tearEdit__coloursHits(tearoff_message m,int hit,void *handle) { unused(handle); switch (m) { case tearoff_SELECTION: case tearoff_SUBMENU: switch (hit) { case tearEdit__COLOURSFORE: tearEdit__colourBox(TRUE); break; case tearEdit__COLOURSBACK: tearEdit__colourBox(FALSE); break; } break; } } /*----- External functions ------------------------------------------------*/ /* * void tearEdit_open(void) * * Use * Opens the edit icon menu, as a submenu if appropriate, otherwise as a * full menu. */ void tearEdit_open(void) { tearoff_displayMenu(tearEdit__main,0); } /* * void tearEdit_update(glass_windPointer *w,int icon) * * Use * Updates the edit icon menu from the specified window and icon. If the * window handle is 0, or the icon is -1 then the menu is made unavailable * (i.e. its items are shaded). Otherwise, the menu is updated to reflect * the state of the icon. * * Parameters * glass_windPointer *w == the window containing the icon to edit * int icon == the icon to be editing in the menu */ void tearEdit_update(glass_windPointer *w,int icon) { int i; wimp_iconflags f; int b; /* --- Remember the new magic icon --- */ tearEdit__window=w; tearEdit__icon=icon; /* --- If there isn't an icon any more, shade the menu --- */ if (!w || icon==-1) { for (i=tearEdit__MAINDATA;i<=tearEdit__MAINSIZE;i++) { tearoff_shadeItem(tearEdit__main,i,TRUE); tearoff_selectItem(tearEdit__main,i,FALSE); } for (i=tearEdit__DATADATA;i<=tearEdit__DATASPRITE;i++) { tearoff_shadeItem(tearEdit__data,i,TRUE); tearoff_selectItem(tearEdit__data,i,FALSE); } for (i=tearEdit__APPEARHCENTRE;i<=tearEdit__APPEARHELP;i++) { tearoff_shadeItem(tearEdit__appear,i,TRUE); tearoff_selectItem(tearEdit__appear,i,FALSE); } for (i=tearEdit__ACTIONSBTYPE;i<=tearEdit__ACTIONSSHADE;i++) { tearoff_shadeItem(tearEdit__actions,i,TRUE); tearoff_selectItem(tearEdit__actions,i,FALSE); } for (i=1;i<=16;i++) { tearoff_shadeItem(tearEdit__btype,i,TRUE); tearoff_selectItem(tearEdit__btype,i,FALSE); } for (i=tearEdit__COLOURSFORE;i<=tearEdit__COLOURSBACK;i++) tearoff_shadeItem(tearEdit__colours,i,TRUE); } else { /* --- Read information about the icon --- */ f=w->def->i[icon].i.flags; /* --- Unshade the main menu --- */ tearoff_shadeItem(tearEdit__main,tearEdit__MAINDATA,FALSE); tearoff_shadeItem(tearEdit__main,tearEdit__MAINAPPEAR,FALSE); tearoff_shadeItem(tearEdit__main,tearEdit__MAINACTIONS,FALSE); tearoff_shadeItem(tearEdit__main,tearEdit__MAINCOLOURS,tst(f,6)); tearoff_shadeItem(tearEdit__main,tearEdit__MAINPOS,FALSE); tearoff_shadeItem(tearEdit__main,tearEdit__MAINSIZE,FALSE); /* --- Handle data things --- */ tearoff_shadeItem(tearEdit__data,tearEdit__DATADATA,!(f & 3)); tearoff_shadeItem(tearEdit__data,tearEdit__DATAINDIR,!(f & 3)); tearoff_selectItem(tearEdit__data,tearEdit__DATAINDIR,tst(f,8)); tearoff_shadeItem(tearEdit__data,tearEdit__DATATEXT,FALSE); tearoff_selectItem(tearEdit__data,tearEdit__DATATEXT,tst(f,0)); tearoff_shadeItem(tearEdit__data,tearEdit__DATASPRITE,FALSE); tearoff_selectItem(tearEdit__data,tearEdit__DATASPRITE,tst(f,1)); /* --- Handle appearance things --- */ tearoff_shadeItem(tearEdit__appear,tearEdit__APPEARHCENTRE,FALSE); tearoff_selectItem(tearEdit__appear,tearEdit__APPEARHCENTRE,tst(f,3)); tearoff_shadeItem(tearEdit__appear,tearEdit__APPEARVCENTRE,FALSE); tearoff_selectItem(tearEdit__appear,tearEdit__APPEARVCENTRE,tst(f,4)); tearoff_shadeItem(tearEdit__appear,tearEdit__APPEARRALIGN,FALSE); tearoff_selectItem(tearEdit__appear,tearEdit__APPEARRALIGN,tst(f,9)); tearoff_shadeItem(tearEdit__appear,tearEdit__APPEARBORDER,FALSE); tearoff_selectItem(tearEdit__appear,tearEdit__APPEARBORDER,tst(f,2)); tearoff_shadeItem(tearEdit__appear,tearEdit__APPEARFILLED,FALSE); tearoff_selectItem(tearEdit__appear,tearEdit__APPEARFILLED,tst(f,5)); tearoff_shadeItem(tearEdit__appear,tearEdit__APPEARHALF,!tst(f,1)); tearoff_selectItem(tearEdit__appear,tearEdit__APPEARHALF,tst(f,11)); tearoff_shadeItem(tearEdit__appear,tearEdit__APPEARHELP,FALSE); tearoff_selectItem(tearEdit__appear,tearEdit__APPEARHELP,tst(f,7)); /* --- Handle actions things --- */ tearoff_shadeItem(tearEdit__actions,tearEdit__ACTIONSBTYPE,FALSE); tearoff_shadeItem(tearEdit__actions,tearEdit__ACTIONSESG,FALSE); tearoff_shadeItem(tearEdit__actions,tearEdit__ACTIONSADJUST,FALSE); tearoff_selectItem(tearEdit__actions,tearEdit__ACTIONSADJUST,tst(f,10)); tearoff_shadeItem(tearEdit__actions,tearEdit__ACTIONSSELECT,FALSE); tearoff_selectItem(tearEdit__actions,tearEdit__ACTIONSSELECT,tst(f,21)); tearoff_shadeItem(tearEdit__actions,tearEdit__ACTIONSSHADE,FALSE); tearoff_selectItem(tearEdit__actions,tearEdit__ACTIONSSHADE,tst(f,22)); /* --- Handle button type --- */ b=(f & 0x0000F000)>>12; for (i=1;i<=16;i++) { tearoff_shadeItem(tearEdit__btype,i,FALSE); tearoff_selectItem(tearEdit__btype,i,(i-1==b) ? tearoff_RADIOED : FALSE); } /* --- Handle colours --- */ tearoff_shadeItem(tearEdit__colours,tearEdit__COLOURSFORE,tst(f,6)); tearoff_shadeItem(tearEdit__colours,tearEdit__COLOURSBACK,tst(f,6)); } } /* * void tearEdit_init(void) * * Use * Initialises the tearoff menus for editing icons and starts up the tearoff * menu manager. */ void tearEdit_init(void) { char *buf=buffer_find(); int i; /* --- If we're already up and running, then someone's stupid --- */ if (tearEdit__main) return; tearoff_init(); tearEdit__main=tearoff_create(msgs_lookup("teEIMT"), msgs_lookup("teEIM"), TRUE, tearEdit__mainHits, 0, 0); tearEdit__data=tearoff_create(msgs_lookup("teEIDT"), msgs_lookup("teEID"), TRUE, tearEdit__dataHits, 0, 0); tearEdit__appear=tearoff_create(msgs_lookup("teAPMT"), msgs_lookup("teAPM"), TRUE, tearEdit__appearHits, 0, 0); tearEdit__actions=tearoff_create(msgs_lookup("teACMT"), msgs_lookup("teACM"), TRUE, tearEdit__actionsHits, 0, 0); tearEdit__colours=tearoff_create(msgs_lookup("teCMT"), msgs_lookup("teCM"), TRUE, tearEdit__coloursHits, 0, 0); /* --- Change this code to use Edit Icon messages --- */ tearEdit__btype=tearoff_create(msgs_lookup("eiBTMT"), msgs_lookup("eiBTYPE0"), TRUE, tearEdit__btypeHits, 0, 0); for (i=1;i<=15;i++) { sprintf(buf,"eiBTYPE%i",i); tearEdit__btype=tearoff_extendMenu(tearEdit__btype,msgs_lookup(buf)); } tearoff_shadeItem(tearEdit__btype,13,TRUE); tearoff_shadeItem(tearEdit__btype,14,TRUE); if (!tearEdit__main || !tearEdit__data || !tearEdit__appear || !tearEdit__actions || !tearEdit__colours || !tearEdit__btype) exit(1); tearoff_attachSubMenu(tearEdit__main, tearEdit__MAINDATA, tearEdit__data); tearoff_attachSubMenu(tearEdit__main, tearEdit__MAINAPPEAR, tearEdit__appear); tearoff_attachSubMenu(tearEdit__main, tearEdit__MAINACTIONS, tearEdit__actions); tearoff_attachSubMenu(tearEdit__main, tearEdit__MAINCOLOURS, tearEdit__colours); tearoff_attachSubMenu(tearEdit__actions, tearEdit__ACTIONSBTYPE, tearEdit__btype); tearEdit_update(0,-1); }