chiark / gitweb /
Initial revision
[ssr] / StraySrc / Glass / !Glass / c / wSelect
1 /*
2  * wSelect.c
3  *
4  * Handling a selection in a template window
5  *
6  * © 1994-1998 Straylight
7  */
8
9 /*----- Licensing note ----------------------------------------------------*
10  *
11  * This file is part of Straylight's Glass.
12  *
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)
16  * any later version.
17  *
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.
22  *
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.
26  */
27
28 /*----- Header files ------------------------------------------------------*/
29
30 /*
31  * ANSI standard headers
32  */
33
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37
38 /*
39  * Steel headers
40  */
41
42 #define _STDAPP
43 #define _LOWLVL
44 #include "steel/Steel.h"
45
46 /*
47  * Glass headers
48  */
49
50 #include "gStruct.h"
51 #include "gMenus.h"
52 #include "gIcons.h"
53
54 #include "glass.h"
55 #include "gPrefs.h"
56 #include "window.h"
57 #include "_window.h"
58 #include "intMsgs.h"
59 #include "toolbox.h"
60 #include "editIcon.h"
61 #include "editWin.h"
62 #include "indir.h"
63 #include "align.h"
64 #include "iconData.h"
65 #include "tearEdit.h"
66
67
68
69 /*----- Private variables -------------------------------------------------*/
70
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       */
74
75 /*----- Main code ---------------------------------------------------------*/
76
77 /*
78  * void window__updateSelectBox(glass_windPointer *w,int icon,BOOL makesi)
79  *
80  * Use
81  *  Updates the select box around the specified icon.
82  *
83  * Parameters
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
87  */
88
89 static void window__updateSelectBox(glass_windPointer *w,
90                                     int icon,
91                                     BOOL makesi)
92 {
93   wimp_redrawstr r;
94   BOOL more;
95
96   r.w=w->h;
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));
103   while (more)
104   {
105     window__drawSelectBox(w,icon,makesi,&r);
106     wimpt_noerr(wimp_get_rectangle(&r,&more));
107   }
108 }
109
110 /*
111  * void window__select(glass_windPointer *w,int icon,BOOL sel)
112  *
113  * Use
114  *  Selects or deselects the given icon.
115  *
116  * Parameters
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
120  */
121
122 void window__select(glass_windPointer *w,int icon,BOOL sel)
123 {
124   /* --- Make sure there's something sensible to do --- */
125
126   if (icon==-1)
127     return;
128   if (w->def->i[icon].selected==sel)
129     return;
130   if (w->def->i[icon].i.flags & wimp_IDELETED)
131     return;
132
133   /* --- Update the selection counter --- */
134
135   if (sel)
136     w->selno++;
137   else
138     w->selno--;
139   w->def->i[icon].selected=sel;
140
141   /* --- In test mode you can't see the selection rectangles --- */
142
143 #ifndef glass_DEMO
144   if (w->testMode)
145   {
146     if (icon==window__selIcon && w==window__selOwner && !sel)
147       window__selIcon=-1;
148     return;
149   }
150 #endif
151
152   /* --- Draw the selection boxes around the icons --- *
153    *
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
157    * top.
158    */
159
160   window__updateSelectBox(w,icon,FALSE);
161
162   if (icon==window__selIcon && w==window__selOwner && !sel)
163   {
164     window__selIcon=-1;
165     tearEdit_update(w,-1);
166   }
167 }
168
169 /*
170  * void window__setSelectedIcon(int i)
171  *
172  * Use
173  *  Makes the specified icon in the current selection owner highlighted.
174  *
175  * Parameters
176  *  int i == the icon number to highlight
177  */
178
179 void window__setSelectedIcon(int i)
180 {
181   int o=window__selIcon;
182
183   if (i==o)
184     return;
185
186   if (o!=-1)
187     window__updateSelectBox(window__selOwner,o,TRUE);
188
189   window__selIcon=i;
190
191   if (i!=-1)
192   {
193     if (window__selOwner->def->i[i].selected)
194       window__updateSelectBox(window__selOwner,i,TRUE);
195     else
196       window__select(window__selOwner,i,TRUE);
197   }
198   tearEdit_update(window__selOwner,i);
199 }
200
201 /*
202  * void window__setSelectedIconDeselecting(int i)
203  *
204  * Use
205  *  Sets up the currently selected icon, deselecting the old one.
206  *
207  * Parameters
208  *  int i == the new icon to select
209  */
210
211 void window__setSelectedIconDeselecting(int i)
212 {
213   int o=window__selIcon;
214
215   if (o==i)
216     return;
217   else if (o==-1 || i==-1)
218     window__setSelectedIcon(i);
219   else
220   {
221     /* --- To prevent flickering, we must do all the work here --- */
222
223     window__updateSelectBox(window__selOwner,o,FALSE);
224     window__selOwner->def->i[o].selected=FALSE;
225     window__selIcon=i;
226     if (window__selOwner->def->i[i].selected)
227       window__updateSelectBox(window__selOwner,i,TRUE);
228     else
229       window__updateSelectBox(window__selOwner,i,FALSE);
230     window__selOwner->def->i[i].selected=TRUE;
231     tearEdit_update(window__selOwner,i);
232   }
233 }
234
235 /*
236  * int window__lowestSelected(glass_windPointer *w)
237  *
238  * Use
239  *  Returns the selected icon with the lowest number in the specified window.
240  */
241
242 int window__lowestSelected(glass_windPointer *w)
243 {
244   int i;
245   for (i=0;i<w->def->desc.w.nicons;i++)
246   {
247     if (w->def->i[i].selected)
248       return (i);
249   }
250   return (-1);
251 }
252
253 /*
254  * void window__gainSelection(glass_windPointer *w)
255  *
256  * Use
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
259  *  selection is set.
260  *
261  * Parameters
262  *  glass_windPointer *w == the new selection owner
263  */
264
265 void window__gainSelection(glass_windPointer *w)
266 {
267   int i;
268   wimp_caretstr c;
269   if (w)
270   {
271     c.w=w->h;
272     c.i=-1;
273     c.x=w->def->desc.w.ex.x0-50;
274     c.y=0;
275     c.height=0x02000000;
276     c.index=-1;
277     wimpt_noerr(wimp_set_caret_pos(&c));
278   }
279   if (window__selOwner==w)
280     return;
281   if (w)
282     window__renumber(w,FALSE);
283   if (window__selOwner!=0)
284   {
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++)
288     {
289       if (window__selOwner->guide[i].selected)
290       {
291         window__selOwner->guide[i].selected=FALSE;
292         window__redrawGuide(window__selOwner,i);
293       }
294     }
295   }
296   window__selOwner=w;
297   window__moveToolbars(w);
298 }
299
300 /*
301  * glass_windPointer *window_selectionOwner(void)
302  *
303  * Use
304  *  Returns the window currently owning the selection.
305  */
306
307 glass_windPointer *window_selectionOwner(void)
308 {
309   return (window__selOwner);
310 }
311
312 /*
313  * int window__selectedIcon(void)
314  *
315  * Use
316  *  Returns the currently selected icon
317  */
318
319 int window__selectedIcon(void)
320 {
321   return (window__selIcon);
322 }
323
324 /*
325  * void window__renumberSelectedIcon(int nsel)
326  *
327  * Use
328  *  To be called when the selected icon is renumbered.
329  */
330
331 void window__renumberSelectedIcon(int nsel)
332 {
333   window__selIcon=nsel;
334   tearEdit_update(window__selOwner,window__selIcon);
335 }