/* * colSelect.c * * Handling of a colour button * * © 1994-1998 Straylight */ /*----- Licensing note ----------------------------------------------------* * * This file is part of Straylight's Glass. * * Glass is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * Glass is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Glass. If not, write to the Free Software Foundation, * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /*----- Header files ------------------------------------------------------*/ /* * ANSI standard headers */ #include /* * Steel headers */ #define _STDAPP #include "steel/Steel.h" #include "steel/akbd.h" #include "steel/colourtran.h" /* * Glass headers */ #include "gIcons.h" #include "glass.h" #include "colSelect.h" /*----- Support routines --------------------------------------------------*/ /* * void colSelect__addBorder(dbox d,int colour) * * Use * Adds a border to an icon in the colour dbox. It chooses the most * suitable colour for the border as being the nearest colour available in * the WIMP palette to either black or white, whichever contrasts most * with the colour to border. * * Parameters * dbox d == the colour dbox handle * int colour == the colour to border */ static void colSelect__addBorder(dbox d,int colour) { static wimp_paletteword blacknwhite[]={0,0,0,0, 0,255,255,255,}; static wimp_palettestr wimppal; int col; wimpt_noerr(wimp_readpalette(&wimppal)); wimpt_noerr(colourtran_return_Oppcolourformode(wimppal.c[colour],0, blacknwhite,&col)); wimpt_noerr(colourtran_return_colourformode(blacknwhite[col],12, wimppal.c,&col)); /* --- We now have the correctly contrasting colour in col --- */ wimpt_noerr(wimp_set_icon_state(dbox_syshandle(d), colour+glass_CSCOLOURS,5+(col<<24),0x0f000005)); } /* * void colSelect__removeBorder(dbox d,int colour) * * Use * Removes the 'selected' border from the colour specified. * * Parameters * dbox d == the colour dbox handle * int colour == the colour to unborder */ static void colSelect__removeBorder(dbox d,int colour) { wimpt_noerr(wimp_set_icon_state(dbox_syshandle(d), colour+glass_CSCOLOURS,0,0x0f000005)); } /*----- External routines -------------------------------------------------*/ /* * void colSelect_setColourButton(dbox d,dbox_field f,int colour) * * Use * Sets a colour button to show a colour * * Parameters * dbox d == dbox containing button * dbox_field f == the icon which is the button * int colour == colour to set the button. 255 means transparent */ void colSelect_setColourButton(dbox d,dbox_field f,int colour) { if (colour==255) { wimpt_noerr(wimp_set_icon_state(dbox_syshandle(d),f, 0x10000003,0xf0000003)); } else { wimpt_noerr(wimp_set_icon_state(dbox_syshandle(d),f, 0x00000001+(colour<<28),0xf0000003)); } } /* * BOOL colSelect__raw(dbox d,wimp_eventstr *e,void *handle) * * Use * Handles raw events (keypresses in particular) in the Glass colour box. * * Parameters * dbox d == the dialogue box handle in question * wimp_eventstr *e == the wimp event block * void *handle == pointer to colour value * * Returns * Whether the event was interesting or not. */ static BOOL colSelect__raw(dbox d,wimp_eventstr *e,void *handle) { int *c = handle; BOOL handled = FALSE; switch (e->e) { case wimp_EKEY: { unsigned mask = 0; int offset = 0; int ncol; if (dbox_selecticon(d,glass_CSTRANS,dbox_READSTATE)) break; switch (e->data.key.chcode) { case key_Left: mask = 0xC; offset = -1; break; case key_Right: mask = 0xC; offset = 1; break; case key_Up: mask = ~0xC; offset = -4; break; case key_Down: mask = ~0xC; offset = 4; break; } if (!mask) break; handled = TRUE; ncol = *c + offset; if ((ncol ^ *c) & mask) break; colSelect__removeBorder(d,*c); colSelect__addBorder(d,ncol); *c = ncol; break; } } return (handled); } /* * void colSelect(dbox d,dbox_field f,wimp_bbits bbits,char *editing, * BOOL allowTrans,colSelect_proc proc,void *handle) * * Use * Handles mouse events on a colour button. * * Parameters * dbox d == the dialogue containing the colour button * dbox_field f == the icon which is the colour button * wimp_bbits bbits == button status that prompted this * char *editing == what we're editing (for dialogue) * BOOL allowTrans == whether we're allowed transparent colour * colSelect_proc proc == routine to take notice of any changes * void *handle == pointer to pass to the proc */ void colSelect(dbox d,dbox_field f,wimp_bbits bbits,char *editing, BOOL allowTrans,colSelect_proc proc,void *handle) { int curcol; wimp_icon ic; dbox cs; dbox_field cf; BOOL done=FALSE; wimpt_noerr(wimp_get_icon_info(dbox_syshandle(d),f,&ic)); curcol=(ic.flags>>28) & 15; if (ic.flags & 2) curcol=255; switch (bbits) { case wimp_BLEFT: switch (curcol) { case 255: curcol=0; break; case 15: curcol=(allowTrans ? 255 : 0); break; default: curcol++; break; } colSelect_setColourButton(d,f,curcol); proc(d,f,curcol,handle); break; case wimp_BRIGHT: switch (curcol) { case 255: curcol=15; break; case 0: curcol=(allowTrans ? 255 : 15); break; default: curcol--; break; } colSelect_setColourButton(d,f,curcol); proc(d,f,curcol,handle); break; case wimp_BMID: if (cs=dbox_create("colourSel"),!cs) return; if (!allowTrans) wimpt_noerr(wimp_set_icon_state(dbox_syshandle(cs),glass_CSTRANS, 1<<23,1<<23)); if (curcol==255) { dbox_selecticon(cs,glass_CSTRANS,TRUE); curcol=7; } else { dbox_selecticon(cs,glass_CSTRANS,FALSE); colSelect__addBorder(cs,curcol); } dbox_setfield(cs,glass_CSEDITING,"%s",editing); dbox_rawEventHandler(cs,colSelect__raw,&curcol); dbox_display(cs,dbox_MENU_OVERPTR); { wimp_caretstr c; c.w = dbox_syshandle(cs); c.i = -1; c.x = -500; c.y = 0; c.height = 40; c.index = -1; wimp_set_caret_pos(&c); } while (!done) { cf=dbox_fillin(cs); switch (cf) { case dbox_CLOSE: dbox_delete(cs); done=TRUE; break; case dbox_HELP: help_startHelp(); help_addLine(msgs_lookup("cshCSDB")); help_readFromIcon(); help_endHelp(); break; case glass_CSCANCEL: dbox_clickicon(cs,cf); dbox_hide(cs); dbox_unclick(); dbox_delete(cs); done=TRUE; break; case glass_CSOK: dbox_clickicon(cs,cf); if (dbox_selecticon(cs,glass_CSTRANS,dbox_READSTATE)) { colSelect_setColourButton(d,f,255); proc(d,f,255,handle); } else { colSelect_setColourButton(d,f,curcol); proc(d,f,curcol,handle); } if (!dbox_wasAdjustClick()) dbox_hide(cs); dbox_unclick(); if (!dbox_wasAdjustClick()) { dbox_delete(cs); done=TRUE; } break; case glass_CSTRANS: if (dbox_selecticon(cs,glass_CSTRANS,dbox_READSTATE)) colSelect__removeBorder(cs,curcol); else colSelect__addBorder(cs,curcol); break; default: cf-=glass_CSCOLOURS; if (cf>=0 && cf<=15 && (cf!=curcol || dbox_selecticon(cs,glass_CSTRANS,dbox_READSTATE))) { if (!dbox_selecticon(cs,glass_CSTRANS,FALSE)) colSelect__removeBorder(cs,curcol); colSelect__addBorder(cs,cf); curcol=cf; } break; } } break; } }