/* * CaretPtr * handles a 'caret pointer' - one that changes to a 'I' shape if over a * writable icon. * * Also (as of 05-Apr-1994), changes pointer according to `xp,,' * validation string commands. * * v. 1.00 (25 July 1993) * * © 1993-1998 Straylight */ /*----- Licensing note ----------------------------------------------------* * * This file is part of Straylight's Steel library. * * Steel 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. * * Steel 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 Steel. If not, write to the Free Software Foundation, * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include "pointer.h" #include "win.h" #include "wimpt.h" #include "wimp.h" #include "os.h" #include "caretptr.h" #include "resspr.h" /* * The SWI number for Wimp_SendMessage. */ #define Wimp_SendMessage 0x600E7 static BOOL caretptr__onOrOff; static sprite_id caretptr__name; static sprite_area *caretptr__area; static int caretptr__x; static int caretptr__y; static wimp_i caretptr__icon=-20; static BOOL caretptr__stdptr=TRUE; /* * void caretptr__idles(void *handle) * * Use * Called every null event to update the pointer. * * Parameters * void *handle == handle from win segment, not used. */ static void caretptr__idles(void *handle) { wimp_mousestr mse; wimp_icon i; int bt; handle=handle; wimpt_noerr(wimp_get_point_info(&mse)); if (caretptr__icon!=mse.i) { wimpt_noerr(wimp_get_icon_info(mse.w,mse.i,&i)); bt=(((int)i.flags)>>12)&15; if ((i.flags & wimp_INDIRECT) && (i.flags & wimp_ITEXT) && !((wimpt_options() & wimpt_ONOWIMPSHADE) && (i.flags & 0x001f0000)==0x001f0000) && (i.data.indirecttext.validstring!=(char *)-1)) { char name[15]; int x=0; int y=0; int state=1; char *p=i.data.indirecttext.validstring; char *q=name; sprite_id sid; for (;*p>31 && state!=5;p++) { switch (*p) { case '\\': if (p[1]>31) p++; if (state==1) state=0; else if (state==2) *q++=*p; break; case ';': if (state>1) state=5; else state=1; break; case 'X': case 'x': if (state==1) { if (p[1]=='p' || p[1]=='P') { p++; state=2; } } else if (state==2) *q++=*p; break; case ',': switch (state) { case 2: *q++=0; /* Drop through */ case 3: case 4: state++; } break; default: switch (state) { case 1: state=0; break; case 2: *q++=*p; break; case 3: if (isdigit(*p)) x=(x*10)+(*p-'0'); break; case 4: if (isdigit(*p)) y=(y*10)+(*p-'0'); break; } break; } } if (state>1) { sid.s.name=name; sid.tag=sprite_id_name; pointer_set_shape(resspr_area(),&sid,x,y); caretptr__stdptr=FALSE; caretptr__icon=mse.i; return; } } if (bt==14 || bt==15) { wimpt_noerr(pointer_set_shape(caretptr__area, &caretptr__name, caretptr__x, caretptr__y)); caretptr__stdptr=FALSE; } else if (!caretptr__stdptr) { pointer_reset_shape(); caretptr__stdptr=TRUE; } caretptr__icon=mse.i; } } /* * void caretPtr(char *name,sprite_area *area,int x,int y) * * Use * Turns the caret pointer on * * Parameters * char *name == the name of the sprite to use * sprite_area *area == pointer to sprite area * int x == x position of hotspot * int y == y position of hotspot */ void caretPtr(char *name,sprite_area *area,int x,int y) { if (caretptr__onOrOff) return; caretptr__name.s.name=name; caretptr__name.tag=sprite_id_name; caretptr__area=area; caretptr__x=x; caretptr__y=y; caretptr__onOrOff=TRUE; caretptr__icon=-20; } void caretPtr__pointer(BOOL ownIt) { if (caretptr__onOrOff) { if (ownIt) { win_addIdleClaimer(caretptr__idles,win_DONTCARE,0); caretptr__icon=-20; } else { win_remove_idle_claimer(caretptr__idles,0); if (!caretptr__stdptr) pointer_reset_shape(); caretptr__stdptr=TRUE; caretptr__icon=-1; } } } /* * void caretPtrOff(void) * * Use * Turns the caretPtr off. */ void caretPtrOff(void) { if (!caretptr__onOrOff) return; if (caretptr__icon>-20) { win_remove_idle_claimer(caretptr__idles,0); pointer_reset_shape(); } }