4 * Handling of grab operations (generally, and grab icons)
6 * © 1994-1998 Straylight
9 /*----- Licensing note ----------------------------------------------------*
11 * This file is part of Straylight's Glass.
13 * Glass is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2, or (at your option)
18 * Glass is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with Glass. If not, write to the Free Software Foundation,
25 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 /*----- Header files ------------------------------------------------------*/
31 * ANSI standard headers
44 #include "steel/Steel.h"
46 #include "steel/pointer.h"
47 #include "steel/bbc.h"
48 #include "steel/buffer.h"
65 /*----- Private variables -------------------------------------------------*/
67 static BOOL window__grabbing;
68 static void (*window__grabproc)(wimp_mousestr *m,void *handle);
69 static wimp_mousestr *window__grabhandle;
70 static wimp_icon window__grabbedIcon; /* The icon definition we're grabbing*/
71 static wimp_t window__grabTask; /* Source task for grab operation */
73 /*----- Main code ---------------------------------------------------------*/
76 * void window__grabIdles(void *handle)
79 * Handles the waiting bit in grab mode
82 * void *handle == an unused pointer
85 static void window__grabIdles(void *handle)
88 static sprite_id id={"ptr_grab",0};
92 wimpt_noerr(pointer_set_shape(resspr_area(),&id,0,0));
93 wimpt_noerr(wimp_get_point_info(&m));
96 if ((m.bbits==4 || m.bbits==1) && released)
99 win_removeIdleClaimer(window__grabIdles,0);
100 pointer_reset_shape();
101 window__grabbing=FALSE;
102 window__grabproc(&m,window__grabhandle);
104 else if (bbc_inkey(-113))
106 win_removeIdleClaimer(window__grabIdles,0);
107 window__grabbing=FALSE;
108 pointer_reset_shape();
114 * char *window__grabData(char *ptr,void *handle)
117 * Grabs data from the destination task, as required when setting up a
121 * char *ptr == pointer to data string (in other task's workspace)
122 * void *handle == a pointer (ignored)
125 * A pointer to a string in my own workspace (static char array)
128 static char *window__grabData(char *ptr,void *handle)
130 char *buff=buffer_find();
133 if (window__grabTask)
135 if (e=wimp_transferblock(window__grabTask,ptr,wimpt_task(),buff,256),e)
139 return ("<indirected>");
144 * void window__doGrabIcon(wimp_box *b,glass_windPointer *w)
147 * Actually does a window grab job after all the pallaver.
150 * wimp_box *b == the box in which the icon is contained
151 * glass_windPointer *w == the window into which the icon is to be created
154 * TRUE if the evtn has been successfully handled.
157 void window__doGrabIcon(wimp_box *b,glass_windPointer *w)
161 i=window__createIcon(w);
164 w->def->i[i].i=window__grabbedIcon;
165 if (!iconData_handleFont(w,&w->def->i[i].i.flags))
166 werr(FALSE,msgs_lookup("wdFERGI"));
167 iconData_processIcon(w,i,window__grabData,TRUE,0);
168 wimpt_noerr(wimp_get_wind_state(w->h,&s));
169 w->def->i[i].i.box=*b;
170 window_redrawIcon(w,i);
171 tfile_markAsAltered(w->t);
172 window__updateMenu(w);
176 * void window__grabIcon(wimp_mousestr *m,void *handle)
179 * Grabs an icon from another application.
182 * wimp_mousestr *m == pointer to info about which icon to get
183 * void *handle == pointer to destination window
186 void window__grabIcon(wimp_mousestr *m,void *handle)
199 note(msgs_lookup("wdNITG"));
202 if (wimp_get_wind_state(m->w,&s))
204 note(msgs_lookup("wdCGI"));
207 wimpt_noerr(wimp_get_icon_info(m->w,m->i,&i));
215 if (os_swix(XWimp_SendMessage,&r))
218 window__grabTask=r.r[2];
221 window__grabbedIcon=i;
222 if (i.flags & wimp_ITEXT &&
223 i.flags & wimp_INDIRECT &&
224 i.data.indirecttext.validstring!=(char *)-1)
226 i.data.indirecttext.validstring=
227 window__grabData(i.data.indirecttext.validstring,0);
228 window__bound(&i,&bound,FALSE);
232 window__startDrag(window__GRABICON,&bound,0,m->x-ox,m->y-oy);
233 window__setPtrShape(-2);
237 * void window_grab(void (*proc)(wimp_mousestr *m,void *handle),void *handle)
240 * Turns on 'grab mode' and calls the specified routine when a mouse button
244 * void (*proc)(wimp_mousestr *m,void *handle) == the routine to call
245 * void *handle == the handle to call the routine with
248 void window_grab(void (*proc)(wimp_mousestr *m,void *handle),void *handle)
250 if (window__grabbing)
252 note(msgs_lookup("wdAGRB"));
255 window__grabproc=proc;
256 window__grabhandle=handle;
257 win_addIdleClaimer(window__grabIdles,2,0);
258 window__grabbing=TRUE;
262 * wimp_icon *window__qGrabbedIcon(void)
265 * Returns a pointer to the icon being grabbed
268 wimp_icon *window__qGrabbedIcon(void)
270 return (&window__grabbedIcon);
274 * BOOL window_grabbing(void)
277 * Returns whether grab mode is set or not
280 * TRUE if grab mode set
283 BOOL window_grabbing(void)
285 return (window__grabbing);