/* * wGrab.c * * Handling of grab operations (generally, and grab icons) * * © 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 headers */ #define _STDAPP #define _LOWLVL #include "steel/Steel.h" #include "steel/pointer.h" #include "steel/bbc.h" #include "steel/buffer.h" /* * Glass headers */ #include "gStruct.h" #include "gMenus.h" #include "gIcons.h" #include "glass.h" #include "gPrefs.h" #include "tfile.h" #include "window.h" #include "_window.h" #include "iconData.h" /*----- Private variables -------------------------------------------------*/ static BOOL window__grabbing; static void (*window__grabproc)(wimp_mousestr *m,void *handle); static wimp_mousestr *window__grabhandle; static wimp_icon window__grabbedIcon; /* The icon definition we're grabbing*/ static wimp_t window__grabTask; /* Source task for grab operation */ /*----- Main code ---------------------------------------------------------*/ /* * void window__grabIdles(void *handle) * * Use * Handles the waiting bit in grab mode * * Parameters * void *handle == an unused pointer */ static void window__grabIdles(void *handle) { wimp_mousestr m; static sprite_id id={"ptr_grab",0}; static BOOL released; unused(handle); wimpt_noerr(pointer_set_shape(resspr_area(),&id,0,0)); wimpt_noerr(wimp_get_point_info(&m)); if (!m.bbits) released=TRUE; if ((m.bbits==4 || m.bbits==1) && released) { released=FALSE; win_removeIdleClaimer(window__grabIdles,0); pointer_reset_shape(); window__grabbing=FALSE; window__grabproc(&m,window__grabhandle); } else if (bbc_inkey(-113)) { win_removeIdleClaimer(window__grabIdles,0); window__grabbing=FALSE; pointer_reset_shape(); released=FALSE; } } /* * char *window__grabData(char *ptr,void *handle) * * Use * Grabs data from the destination task, as required when setting up a * grabbed icon. * * Parameters * char *ptr == pointer to data string (in other task's workspace) * void *handle == a pointer (ignored) * * Returns * A pointer to a string in my own workspace (static char array) */ static char *window__grabData(char *ptr,void *handle) { char *buff=buffer_find(); os_error *e; unused(handle); if (window__grabTask) { if (e=wimp_transferblock(window__grabTask,ptr,wimpt_task(),buff,256),e) return (e->errmess); } else return (""); return (buff); } /* * void window__doGrabIcon(wimp_box *b,glass_windPointer *w) * * Use * Actually does a window grab job after all the pallaver. * * Parameters * wimp_box *b == the box in which the icon is contained * glass_windPointer *w == the window into which the icon is to be created * * Returns * TRUE if the evtn has been successfully handled. */ void window__doGrabIcon(wimp_box *b,glass_windPointer *w) { wimp_wstate s; int i; i=window__createIcon(w); if (i==-1) return; w->def->i[i].i=window__grabbedIcon; if (!iconData_handleFont(w,&w->def->i[i].i.flags)) werr(FALSE,msgs_lookup("wdFERGI")); iconData_processIcon(w,i,window__grabData,TRUE,0); wimpt_noerr(wimp_get_wind_state(w->h,&s)); w->def->i[i].i.box=*b; window_redrawIcon(w,i); tfile_markAsAltered(w->t); window__updateMenu(w); } /* * void window__grabIcon(wimp_mousestr *m,void *handle) * * Use * Grabs an icon from another application. * * Parameters * wimp_mousestr *m == pointer to info about which icon to get * void *handle == pointer to destination window */ void window__grabIcon(wimp_mousestr *m,void *handle) { wimp_wstate s; wimp_icon i; int ox; int oy; os_regset r; wimp_msgstr msg; wimp_box bound; unused(handle); if (m->i<0) { note(msgs_lookup("wdNITG")); return; } if (wimp_get_wind_state(m->w,&s)) { note(msgs_lookup("wdCGI")); return; } wimpt_noerr(wimp_get_icon_info(m->w,m->i,&i)); msg.hdr.size=20; msg.hdr.your_ref=0; msg.hdr.action=0; r.r[0]=19; r.r[1]=(int)&msg; r.r[2]=m->w; r.r[3]=m->i; if (os_swix(XWimp_SendMessage,&r)) window__grabTask=0; else window__grabTask=r.r[2]; ox=s.o.box.x0-s.o.x; oy=s.o.box.y1-s.o.y; window__grabbedIcon=i; if (i.flags & wimp_ITEXT && i.flags & wimp_INDIRECT && i.data.indirecttext.validstring!=(char *)-1) { i.data.indirecttext.validstring= window__grabData(i.data.indirecttext.validstring,0); window__bound(&i,&bound,FALSE); } else bound=i.box; window__startDrag(window__GRABICON,&bound,0,m->x-ox,m->y-oy); window__setPtrShape(-2); } /* * void window_grab(void (*proc)(wimp_mousestr *m,void *handle),void *handle) * * Use * Turns on 'grab mode' and calls the specified routine when a mouse button * is clicked. * * Parameters * void (*proc)(wimp_mousestr *m,void *handle) == the routine to call * void *handle == the handle to call the routine with */ void window_grab(void (*proc)(wimp_mousestr *m,void *handle),void *handle) { if (window__grabbing) { note(msgs_lookup("wdAGRB")); return; } window__grabproc=proc; window__grabhandle=handle; win_addIdleClaimer(window__grabIdles,2,0); window__grabbing=TRUE; } /* * wimp_icon *window__qGrabbedIcon(void) * * Use * Returns a pointer to the icon being grabbed */ wimp_icon *window__qGrabbedIcon(void) { return (&window__grabbedIcon); } /* * BOOL window_grabbing(void) * * Use * Returns whether grab mode is set or not * * Returns * TRUE if grab mode set */ BOOL window_grabbing(void) { return (window__grabbing); }