4 * Handling of a colour button
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
41 #include "steel/Steel.h"
42 #include "steel/akbd.h"
43 #include "steel/colourtran.h"
52 #include "colSelect.h"
54 /*----- Support routines --------------------------------------------------*/
57 * void colSelect__addBorder(dbox d,int colour)
60 * Adds a border to an icon in the colour dbox. It chooses the most
61 * suitable colour for the border as being the nearest colour available in
62 * the WIMP palette to either black or white, whichever contrasts most
63 * with the colour to border.
66 * dbox d == the colour dbox handle
67 * int colour == the colour to border
70 static void colSelect__addBorder(dbox d,int colour)
72 static wimp_paletteword blacknwhite[]={0,0,0,0, 0,255,255,255,};
73 static wimp_palettestr wimppal;
75 wimpt_noerr(wimp_readpalette(&wimppal));
76 wimpt_noerr(colourtran_return_Oppcolourformode(wimppal.c[colour],0,
78 wimpt_noerr(colourtran_return_colourformode(blacknwhite[col],12,
80 /* --- We now have the correctly contrasting colour in col --- */
81 wimpt_noerr(wimp_set_icon_state(dbox_syshandle(d),
82 colour+glass_CSCOLOURS,5+(col<<24),0x0f000005));
86 * void colSelect__removeBorder(dbox d,int colour)
89 * Removes the 'selected' border from the colour specified.
92 * dbox d == the colour dbox handle
93 * int colour == the colour to unborder
96 static void colSelect__removeBorder(dbox d,int colour)
98 wimpt_noerr(wimp_set_icon_state(dbox_syshandle(d),
99 colour+glass_CSCOLOURS,0,0x0f000005));
102 /*----- External routines -------------------------------------------------*/
105 * void colSelect_setColourButton(dbox d,dbox_field f,int colour)
108 * Sets a colour button to show a colour
111 * dbox d == dbox containing button
112 * dbox_field f == the icon which is the button
113 * int colour == colour to set the button. 255 means transparent
116 void colSelect_setColourButton(dbox d,dbox_field f,int colour)
120 wimpt_noerr(wimp_set_icon_state(dbox_syshandle(d),f,
121 0x10000003,0xf0000003));
125 wimpt_noerr(wimp_set_icon_state(dbox_syshandle(d),f,
126 0x00000001+(colour<<28),0xf0000003));
131 * BOOL colSelect__raw(dbox d,wimp_eventstr *e,void *handle)
134 * Handles raw events (keypresses in particular) in the Glass colour box.
137 * dbox d == the dialogue box handle in question
138 * wimp_eventstr *e == the wimp event block
139 * void *handle == pointer to colour value
142 * Whether the event was interesting or not.
145 static BOOL colSelect__raw(dbox d,wimp_eventstr *e,void *handle)
148 BOOL handled = FALSE;
155 if (dbox_selecticon(d,glass_CSTRANS,dbox_READSTATE))
157 switch (e->data.key.chcode)
180 if ((ncol ^ *c) & mask)
182 colSelect__removeBorder(d,*c);
183 colSelect__addBorder(d,ncol);
192 * void colSelect(dbox d,dbox_field f,wimp_bbits bbits,char *editing,
193 * BOOL allowTrans,colSelect_proc proc,void *handle)
196 * Handles mouse events on a colour button.
199 * dbox d == the dialogue containing the colour button
200 * dbox_field f == the icon which is the colour button
201 * wimp_bbits bbits == button status that prompted this
202 * char *editing == what we're editing (for dialogue)
203 * BOOL allowTrans == whether we're allowed transparent colour
204 * colSelect_proc proc == routine to take notice of any changes
205 * void *handle == pointer to pass to the proc
208 void colSelect(dbox d,dbox_field f,wimp_bbits bbits,char *editing,
209 BOOL allowTrans,colSelect_proc proc,void *handle)
216 wimpt_noerr(wimp_get_icon_info(dbox_syshandle(d),f,&ic));
217 curcol=(ic.flags>>28) & 15;
229 curcol=(allowTrans ? 255 : 0);
235 colSelect_setColourButton(d,f,curcol);
236 proc(d,f,curcol,handle);
245 curcol=(allowTrans ? 255 : 15);
251 colSelect_setColourButton(d,f,curcol);
252 proc(d,f,curcol,handle);
255 if (cs=dbox_create("colourSel"),!cs)
258 wimpt_noerr(wimp_set_icon_state(dbox_syshandle(cs),glass_CSTRANS,
262 dbox_selecticon(cs,glass_CSTRANS,TRUE);
267 dbox_selecticon(cs,glass_CSTRANS,FALSE);
268 colSelect__addBorder(cs,curcol);
270 dbox_setfield(cs,glass_CSEDITING,"%s",editing);
271 dbox_rawEventHandler(cs,colSelect__raw,&curcol);
272 dbox_display(cs,dbox_MENU_OVERPTR);
275 c.w = dbox_syshandle(cs);
281 wimp_set_caret_pos(&c);
294 help_addLine(msgs_lookup("cshCSDB"));
299 dbox_clickicon(cs,cf);
306 dbox_clickicon(cs,cf);
307 if (dbox_selecticon(cs,glass_CSTRANS,dbox_READSTATE))
309 colSelect_setColourButton(d,f,255);
310 proc(d,f,255,handle);
314 colSelect_setColourButton(d,f,curcol);
315 proc(d,f,curcol,handle);
317 if (!dbox_wasAdjustClick())
320 if (!dbox_wasAdjustClick())
327 if (dbox_selecticon(cs,glass_CSTRANS,dbox_READSTATE))
328 colSelect__removeBorder(cs,curcol);
330 colSelect__addBorder(cs,curcol);
334 if (cf>=0 && cf<=15 && (cf!=curcol ||
335 dbox_selecticon(cs,glass_CSTRANS,dbox_READSTATE)))
337 if (!dbox_selecticon(cs,glass_CSTRANS,FALSE))
338 colSelect__removeBorder(cs,curcol);
339 colSelect__addBorder(cs,cf);