4 * Handling a selection in a template window
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"
69 /*----- Private variables -------------------------------------------------*/
71 static glass_windPointer *window__selOwner; /* The window that owns the */
72 /* current selection. */
73 static int window__selIcon=-1; /* The main currently selected icon */
75 /*----- Main code ---------------------------------------------------------*/
78 * void window__updateSelectBox(glass_windPointer *w,int icon,BOOL makesi)
81 * Updates the select box around the specified icon.
84 * glass_windPointer *w == the window containing the icon
85 * int icon == the icon number whose selection border we change
86 * BOOL makesi == whether to change the border from main sel to normal sel
89 static void window__updateSelectBox(glass_windPointer *w,
97 window_boundingBox(w,icon,&r.box);
98 r.box.x0-=window__HANDLEWIDTH+16;
99 r.box.x1+=window__HANDLEWIDTH+16;
100 r.box.y0-=window__HANDLEWIDTH+16;
101 r.box.y1+=window__HANDLEWIDTH+16;
102 wimpt_noerr(wimp_update_wind(&r,&more));
105 window__drawSelectBox(w,icon,makesi,&r);
106 wimpt_noerr(wimp_get_rectangle(&r,&more));
111 * void window__select(glass_windPointer *w,int icon,BOOL sel)
114 * Selects or deselects the given icon.
117 * glass_windPointer *w == the window we're talking about
118 * int icon == the icon to select (or not)
119 * BOOL sel == TRUE to select, FALSE to deslect
122 void window__select(glass_windPointer *w,int icon,BOOL sel)
124 /* --- Make sure there's something sensible to do --- */
128 if (w->def->i[icon].selected==sel)
130 if (w->def->i[icon].i.flags & wimp_IDELETED)
133 /* --- Update the selection counter --- */
139 w->def->i[icon].selected=sel;
141 /* --- In test mode you can't see the selection rectangles --- */
146 if (icon==window__selIcon && w==window__selOwner && !sel)
152 /* --- Draw the selection boxes around the icons --- *
154 * It doesn't matter whether we're drawing or undrawing -- seeing as we're
155 * using XOR plotting for the rectangles, and we know that the seleciton
156 * state has changed, we just draw the selection boxes straight over the
160 window__updateSelectBox(w,icon,FALSE);
162 if (icon==window__selIcon && w==window__selOwner && !sel)
165 tearEdit_update(w,-1);
170 * void window__setSelectedIcon(int i)
173 * Makes the specified icon in the current selection owner highlighted.
176 * int i == the icon number to highlight
179 void window__setSelectedIcon(int i)
181 int o=window__selIcon;
187 window__updateSelectBox(window__selOwner,o,TRUE);
193 if (window__selOwner->def->i[i].selected)
194 window__updateSelectBox(window__selOwner,i,TRUE);
196 window__select(window__selOwner,i,TRUE);
198 tearEdit_update(window__selOwner,i);
202 * void window__setSelectedIconDeselecting(int i)
205 * Sets up the currently selected icon, deselecting the old one.
208 * int i == the new icon to select
211 void window__setSelectedIconDeselecting(int i)
213 int o=window__selIcon;
217 else if (o==-1 || i==-1)
218 window__setSelectedIcon(i);
221 /* --- To prevent flickering, we must do all the work here --- */
223 window__updateSelectBox(window__selOwner,o,FALSE);
224 window__selOwner->def->i[o].selected=FALSE;
226 if (window__selOwner->def->i[i].selected)
227 window__updateSelectBox(window__selOwner,i,TRUE);
229 window__updateSelectBox(window__selOwner,i,FALSE);
230 window__selOwner->def->i[i].selected=TRUE;
231 tearEdit_update(window__selOwner,i);
236 * int window__lowestSelected(glass_windPointer *w)
239 * Returns the selected icon with the lowest number in the specified window.
242 int window__lowestSelected(glass_windPointer *w)
245 for (i=0;i<w->def->desc.w.nicons;i++)
247 if (w->def->i[i].selected)
254 * void window__gainSelection(glass_windPointer *w)
257 * Gives the specified window the input focus, tool and info bars, and the
258 * selection. If 0 is specified, then the tool bars are taken down, and no
262 * glass_windPointer *w == the new selection owner
265 void window__gainSelection(glass_windPointer *w)
273 c.x=w->def->desc.w.ex.x0-50;
277 wimpt_noerr(wimp_set_caret_pos(&c));
279 if (window__selOwner==w)
282 window__renumber(w,FALSE);
283 if (window__selOwner!=0)
285 for (i=0;i<window__selOwner->def->desc.w.nicons;i++)
286 window__select(window__selOwner,i,FALSE);
287 for (i=0;i<glass_GUIDELIMIT;i++)
289 if (window__selOwner->guide[i].selected)
291 window__selOwner->guide[i].selected=FALSE;
292 window__redrawGuide(window__selOwner,i);
297 window__moveToolbars(w);
301 * glass_windPointer *window_selectionOwner(void)
304 * Returns the window currently owning the selection.
307 glass_windPointer *window_selectionOwner(void)
309 return (window__selOwner);
313 * int window__selectedIcon(void)
316 * Returns the currently selected icon
319 int window__selectedIcon(void)
321 return (window__selIcon);
325 * void window__renumberSelectedIcon(int nsel)
328 * To be called when the selected icon is renumbered.
331 void window__renumberSelectedIcon(int nsel)
333 window__selIcon=nsel;
334 tearEdit_update(window__selOwner,window__selIcon);