Initial revision
[ssr] / StraySrc / Glass / !Glass / c / wPalette
1 /*
2 * wPalette.c
3 *
4 * Handling of the Icon Palette
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 #include "steel/interface.h"
47 #include "steel/sculptrix.h"
48 #include "steel/caretPtr.h"
49 #include "steel/flex.h"
50
51 /*
52 * Glass headers
53 */
54
55 #include "gStruct.h"
56 #include "gMenus.h"
57 #include "gIcons.h"
58
59 #include "glass.h"
60 #include "gPrefs.h"
61 #include "gSprite.h"
62 #include "window.h"
63 #include "_window.h"
64
65 /*----- Private data ------------------------------------------------------*/
66
67 static wimp_w window__palette; /* Window handle of floating icon palette */
68
69 /*----- Main code ---------------------------------------------------------*/
70
71 /*
72 * void window__paletteHandler(wimp_eventstr *e,void *handle)
73 *
74 * Use
75 * Handles events for the icon palette window.
76 *
77 * Parameters
78 * wimp_eventstr *e == pointer to the current event
79 * void *handle == an unimportant pointer
80 */
81
82 static void window__paletteHandler(wimp_eventstr *e,void *handle)
83 {
84 BOOL more=TRUE;
85 wimp_redrawstr r;
86 wimp_wstate s;
87 wimp_wind *t;
88 os_regset reg;
89 wimp_icon *ic;
90 unused(handle);
91 switch (e->e)
92 {
93 case wimp_EREDRAW:
94 r.w=e->data.o.w;
95 wimpt_noerr(wimp_redraw_wind(&r,&more));
96 while (more)
97 {
98 if (gPrefs_current()->sDispBorders)
99 {
100 sculptrix_setSpriteArea(gSprite_area());
101 sculptrix_redrawWindow(&r);
102 }
103 if (gPrefs_current()->iDispBorders)
104 interface_render3dWindow(&r);
105 if (gPrefs_current()->wDispBorders)
106 {
107 reg.r[1]=(int)&r;
108 os_swix(XWimpExt_Redraw,&reg);
109 }
110 wimpt_noerr(wimp_get_rectangle(&r,&more));
111 }
112 break;
113 case wimp_EOPEN:
114 wimpt_noerr(wimp_open_wind(&e->data.o));
115 break;
116 case wimp_ECLOSE:
117 wimpt_noerr(wimp_get_wind_state(window__palette,&s));
118 t=&template_find("default")->window;
119 t->box=s.o.box;
120 t->scx=s.o.x;
121 t->scy=s.o.y;
122 win_register_event_handler(window__palette,0,0);
123 wimpt_noerr(wimp_delete_wind(window__palette));
124 win_activedec();
125 window__palette=0;
126 break;
127 case wimp_EPTRENTER:
128 caretPtr__pointer(FALSE); /* Don't change pointer in this window */
129 break;
130 case wimp_EBUT:
131 if ((e->data.but.m.bbits==0x40 || e->data.but.m.bbits==0x10) &&
132 e->data.but.m.i!=-1 &&
133 !window_grabbing())
134 {
135 t=&template_find("default")->window;
136 ic=(wimp_icon *)(t+1);
137 window__grabIcon(&e->data.but.m,0);
138 window__qGrabbedIcon()->flags=ic[e->data.but.m.i].flags;
139 }
140 break;
141 }
142 }
143
144 /*
145 * void window__showPalette(void)
146 *
147 * Use
148 * Displays the palette window, as set up in the Defaults template file.
149 */
150
151 void window__showPalette(void)
152 {
153 wimp_wind *w;
154 wimp_wind *t;
155 wimp_icon *ic;
156 wimp_wstate s;
157 int i;
158 int size;
159 static char title[25];
160 if (!window__palette)
161 {
162 t=&template_find("default")->window;
163 size=sizeof(wimp_wind)+t->nicons*sizeof(wimp_icon);
164 if (!flex_alloc((flex_ptr)&w,size))
165 {
166 werr(FALSE,
167 msgs_lookup("wdNEMIP"));
168 return;
169 }
170 memcpy(w,t,size);
171 ic=(wimp_icon *)(w+1);
172 for (i=0;i<w->nicons;i++)
173 ic[i].flags=(ic[i].flags&~0x0000f000)|0x00006000;
174 strcpy(title,msgs_lookup("wdIPT"));
175 w->spritearea=gSprite_area();
176 w->titleflags=wimp_INDIRECT | wimp_IHCENTRE | wimp_ITEXT;
177 w->title.indirecttext.buffer=title;
178 w->title.indirecttext.validstring=(char *)-1;
179 w->flags=wimp_WQUIT |
180 wimp_WBACK |
181 wimp_WTITLE |
182 wimp_WNEW |
183 wimp_WMOVEABLE;
184 if (utils_complain(wimp_create_wind(w,&window__palette),
185 msgs_lookup("wdERIP")))
186 {
187 flex_free((flex_ptr)&w);
188 window__palette=0;
189 return;
190 }
191 flex_free((flex_ptr)&w);
192 win_activeinc();
193 win_register_event_handler(window__palette,window__paletteHandler,0);
194 }
195 wimpt_noerr(wimp_get_wind_state(window__palette,&s));
196 s.o.behind=-1;
197 wimpt_noerr(wimp_open_wind(&s.o));
198 }