/* * iconData.c * * Central handling for icon data * * © 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 /* * Steel headers */ #define _STDAPP #define _LOWLVL #include "steel/Steel.h" /* * Glass headers */ #include "gStruct.h" #include "glass.h" #include "iconData.h" #include "indir.h" /*----- External routines -------------------------------------------------*/ /* * BOOL iconData_processIcon * ( * glass_windPointer *w, * int i; * iconData_proc proc, * BOOL updateSize, * void *handle * ) * * Use * Processes one icon in the given window. This routine will replace all * the indirection pointers with pointers to blocks from the indirection * heap. * * Parameters * glass_windPointer *w == the window data from which the icon is from * int i == the icon to update (-1 for the title) * BOOL updateSize == whether to update the window's size variable * iconData_proc proc == function to return a pointer to an indirected * string given what's in the data word. Pass 0 if its actually a * valid pointer * void *handle == pointer to pass to 'proc' * * Returns * FALSE if it ran out of memory, or TRUE for success */ BOOL iconData_processIcon ( glass_windPointer *w, int i, iconData_proc proc, BOOL updateSize, void *handle ) { char *p; char *q; char *indir; char *valid; int flags; if (i==-1) { flags=w->def->desc.w.titleflags; if (flags & wimp_INDIRECT) { if (proc) indir=proc(w->def->desc.w.title.indirecttext.buffer,handle); else indir=w->def->desc.w.title.indirecttext.buffer; utils_ctermToNterm(indir); if (w->def->desc.w.title.indirecttext.bufflendef->desc.w.title.indirecttext.bufflen=strlen(indir)+1; p=indir_alloc(w->def->desc.w.title.indirecttext.bufflen); if (!p) return (FALSE); /* --- Watch out -- indir might have moved :-( --- */ if (proc) indir=proc(w->def->desc.w.title.indirecttext.buffer,handle); else indir=w->def->desc.w.title.indirecttext.buffer; utils_ctermToNterm(indir); strcpy(p,indir); if (flags & wimp_ITEXT && w->def->desc.w.title.indirecttext.validstring!=(char *)-1) { if (proc) valid=proc(w->def->desc.w.title.indirecttext.validstring,handle); else valid=w->def->desc.w.title.indirecttext.validstring; utils_ctermToNterm(valid); q=indir_alloc(strlen(valid)+1); if (!q) { indir_free(p); return (FALSE); } /* --- Aaarrghh -- valid might have moved. Find it again --- */ if (proc) valid=proc(w->def->desc.w.title.indirecttext.validstring,handle); else valid=w->def->desc.w.title.indirecttext.validstring; utils_ctermToNterm(valid); strcpy(q,valid); w->def->desc.w.title.indirecttext.validstring=q; if (updateSize) w->size+=strlen(valid)+1; } else if ((flags & 3)==2) w->def->desc.w.title.indirectsprite.spritearea=w->t->s; if (updateSize) w->size+=w->def->desc.w.title.indirecttext.bufflen; w->def->desc.w.title.indirecttext.buffer=p; } } else { flags=w->def->i[i].i.flags; if (flags & wimp_INDIRECT) { if (proc) indir=proc(w->def->i[i].i.data.indirecttext.buffer,handle); else indir=w->def->i[i].i.data.indirecttext.buffer; utils_ctermToNterm(indir); if (w->def->i[i].i.data.indirecttext.bufflendef->i[i].i.data.indirecttext.bufflen=strlen(indir)+1; p=indir_alloc(w->def->i[i].i.data.indirecttext.bufflen); if (!p) return (FALSE); /* --- indir may have moved in a nasty way --- */ if (proc) indir=proc(w->def->i[i].i.data.indirecttext.buffer,handle); else indir=w->def->i[i].i.data.indirecttext.buffer; utils_ctermToNterm(indir); strcpy(p,indir); if (flags & wimp_ITEXT && w->def->i[i].i.data.indirecttext.validstring!=(char *)-1) { if (proc) valid=proc(w->def->i[i].i.data.indirecttext.validstring,handle); else valid=w->def->i[i].i.data.indirecttext.validstring; utils_ctermToNterm(valid); q=indir_alloc(strlen(valid)+1); if (!q) { indir_free(p); return (FALSE); } /* --- There's a saboteur about moving valid around --- */ if (proc) valid=proc(w->def->i[i].i.data.indirecttext.validstring,handle); else valid=w->def->i[i].i.data.indirecttext.validstring; utils_ctermToNterm(valid); strcpy(q,valid); w->def->i[i].i.data.indirecttext.validstring=q; if (updateSize) w->size+=strlen(valid)+1; } else if ((flags & 3)==2) w->def->i[i].i.data.indirectsprite.spritearea=w->t->s; if (updateSize) w->size+=w->def->i[i].i.data.indirecttext.bufflen; w->def->i[i].i.data.indirecttext.buffer=p; } } return (TRUE); } /* * BOOL iconData_handleFont(glass_windPointer *w,wimp_iconflags *f) * * Use * Processes a font handle, refinding etc. and adding to font reference * array. It assumes the icon is from an external source, and doesn't * attempt to free the font. * * Parameters * glass_windPointer *w == the window containing the icon/title to fiddle * wimp_iconflags *f == icon flags to fiddle with * * Returns * TRUE if all went well, or FALSE if the icon's font has been lost. In * this case the icon has been deantialiased(!) leaving potentially very * strange colours. */ BOOL iconData_handleFont(glass_windPointer *w,wimp_iconflags *f) { os_regset r; int fhandle; char buff[50]; if (*f & wimp_IFONT) { fhandle=(*f>>24) & 0xff; r.r[0]=fhandle; r.r[1]=(int)buff; if (os_swix(XFont_ReadDefn,&r)) { *f&=~wimp_IFONT; return (FALSE); } r.r[4]=r.r[5]=0; if (os_swix(XFont_FindFont,&r)) { *f&=~wimp_IFONT; return (FALSE); } *f=(*f & 0x00ffffff) | (fhandle<<24); w->antiAliased=TRUE; w->fonts[fhandle]++; } return (TRUE); }