1 /*
2  *   Copyright (C) 1989-1991 Yale University
3  *
4  *   This work is distributed in the hope that it will be useful; you can
5  *   redistribute it and/or modify it under the terms of the
6  *   GNU General Public License as published by the Free Software Foundation;
7  *   either version 2 of the License,
8  *   or any later version, on the following conditions:
9  *
10  *   (a) YALE MAKES NO, AND EXPRESSLY DISCLAIMS
11  *   ALL, REPRESENTATIONS OR WARRANTIES THAT THE MANUFACTURE, USE, PRACTICE,
12  *   SALE OR
13  *   OTHER DISPOSAL OF THE SOFTWARE DOES NOT OR WILL NOT INFRINGE UPON ANY
14  *   PATENT OR
15  *   OTHER RIGHTS NOT VESTED IN YALE.
16  *
17  *   (b) YALE MAKES NO, AND EXPRESSLY DISCLAIMS ALL, REPRESENTATIONS AND
18  *   WARRANTIES
19  *   WHATSOEVER WITH RESPECT TO THE SOFTWARE, EITHER EXPRESS OR IMPLIED,
20  *   INCLUDING,
21  *   BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
22  *   PARTICULAR
23  *   PURPOSE.
24  *
25  *   (c) LICENSEE SHALL MAKE NO STATEMENTS, REPRESENTATION OR WARRANTIES
26  *   WHATSOEVER TO
27  *   ANY THIRD PARTIES THAT ARE INCONSISTENT WITH THE DISCLAIMERS BY YALE IN
28  *   ARTICLE
29  *   (a) AND (b) above.
30  *
31  *   (d) IN NO EVENT SHALL YALE, OR ITS TRUSTEES, DIRECTORS, OFFICERS,
32  *   EMPLOYEES AND
33  *   AFFILIATES BE LIABLE FOR DAMAGES OF ANY KIND, INCLUDING ECONOMIC DAMAGE OR
34  *   INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER YALE SHALL BE
35  *   ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT SHALL KNOW OF THE
36  *   POSSIBILITY OF THE FOREGOING.
37  *
38  */
39 
40 /* -----------------------------------------------------------------
41 FILE:	    edcolors.c
42 DESCRIPTION:These routines allow user to toggle colors of the
43     display.
44 CONTENTS:   TWtoggleColors()
45 DATE:	    Sep 23, 1989 - added TWtoggleColors()
46 REVISIONS:  Dec  7, 1990 - updated for new dialog procedure.
47 	    Wed May  1 18:56:14 EDT 1991 - added toggle for arb fill.
48 	    Sun Nov  3 12:52:21 EST 1991 - fixed gcc complaints.
49 ----------------------------------------------------------------- */
50 
51 #ifndef NOGRAPHICS
52 
53 #include <stdio.h>
54 #include <X11/Xlib.h>
55 #include <X11/Xatom.h>
56 #include <X11/Xutil.h>
57 
58 #include <yalecad/base.h>
59 #include <yalecad/dialog.h>
60 #include <yalecad/colors.h>
61 #include <yalecad/draw.h>
62 #include <yalecad/string.h>
63 #include "info.h"
64 
65 static TWDIALOGPTR fieldS ;
66 static void init_field( P8(INT field, INT row, INT column, INT str_len, char *string,
67 		    INT type, INT color, INT group ) ) ;
68 
69 /* be able to turn off individual colors */
TWtoggleColors()70 void TWtoggleColors()
71 {
72     char **colors ;      /* the standard color array */
73     INT  i ;             /* counter */
74     INT  numfields ;     /* number of dialog fields */
75     INT  numcolors ;     /* the number of colors in color array */
76     INT  row ;           /* current row of dialog */
77     INT  group ;         /* current case group of dialog */
78     INT  color ;         /* current color processed */
79     INT  field ;         /* current field of dialog */
80     BOOL *colorOn ;      /* whether each color is on */
81     TWDIALOGPTR fptr;    /* current field of dialog */
82     TWDRETURNPTR answer ; /* return from user */
83     TWINFOPTR info ;     /* get information from main draw routine */
84 
85     /* get colors for dialog window */
86     info = TWgetDrawInfo() ;
87     colors = info->colors ;
88     numcolors = info->numColors ;
89     colorOn = info->colorOn ;
90 
91     numfields = 3 * numcolors + 7 ;
92     fieldS = YCALLOC( numfields, TWDIALOGBOX ) ;
93 
94     /* set the accept and reject fields */
95     /* field, row, column, strlen, string, type, color, group  */
96     init_field( 0, 1, 5, 8, " ACCEPT ", BUTTONTYPE, TWGREEN, 0 ) ;
97     init_field( 1, 1,30, 8, " REJECT ", BUTTONTYPE, TWRED, 0 ) ;
98 
99     if( TWget_arb_fill() ){
100 	init_field( 2, 3, 5, 9, "Arb Fill:" , CASETYPE,  TWBLACK, 3 ) ;
101     } else {
102 	init_field( 2, 3, 5, 9, "Arb Fill:" , CASETYPE,  TWBLACK, 4 ) ;
103     }
104     init_field( 3, 3, 30, 3, "on", BUTTONTYPE, TWGREEN, 1 ) ;
105     init_field( 4, 3, 35, 3, "off", BUTTONTYPE, TWRED, 1 ) ;
106 
107     init_field( 5, 4, 1, 7, "Colors:" , LABELTYPE,  TWBLACK, 0 ) ;
108     row = 5 ;
109     group = 1 ;
110     for( i = 1, field = 5; i <= numcolors; i++ ){
111 	field++ ;
112 	if( i == 1 ){ /* white - change to black 2 */
113 	    color = 2 ;
114 	} else {
115 	    color = i ;
116 	}
117 	/* set current initial switch position */
118 	if( colorOn[i] ){
119 	    init_field( field, ++row, 5, 5, colors[i], CASETYPE,
120 		color, field+1 ) ;
121 	} else {
122 	    init_field( field, ++row, 5, 5, colors[i], CASETYPE,
123 		color, field+2 ) ;
124 	}
125 	init_field( ++field, row, 30, 3, "on", BUTTONTYPE,
126 	    color, ++group ) ;
127 	init_field( ++field, row, 35, 3, "off", BUTTONTYPE,
128 	    color, group ) ;
129     }
130     /* terminate list with zeros */
131     init_field( ++field, 0, 0, 0, 0, 0, 0, 0 ) ;
132 
133     /* initialization complete */
134 
135     if( answer = TWdialog( fieldS, "colors", NULL ) ){
136 	if( answer[3].bool ){
137 	    TWarb_fill( TRUE ) ;
138 	} else {
139 	    TWarb_fill( FALSE ) ;
140 	}
141 	for( i = 7, color = 0; i < numfields; i +=3 ){
142 	    if( answer[i].bool ){
143     		colorOn[++color] = TRUE ;
144 	    } else {
145     		colorOn[++color] = FALSE ;
146 	    }
147 	}
148     }
149     /* cleanup memory */
150     for( i = 0; i < numfields; i++ ){
151 	if( fieldS[i].string ){
152 	    YFREE( fieldS[i].string ) ;
153 	}
154     }
155     YFREE( fieldS ) ;
156 } /* end TWtoggleColors */
157 
158 
init_field(field,row,column,str_len,string,type,color,group)159 static void init_field( field, row, column, str_len, string,
160 type, color, group )
161 INT field, row, column, str_len, type, color, group ;
162 char *string ;
163 {
164     TWDIALOGPTR fptr;    /* current field of dialog */
165 
166     fptr = &(fieldS[field]) ;
167     fptr->row = row ;
168     fptr->column = column ;
169     fptr->len = str_len ;
170     fptr->type = type ;
171     fptr->color = color ;
172     fptr->group = group ;
173     fptr->string = Ystrclone( string ) ;
174 } /* end init_field */
175 
176 #endif /* NOGRAPHICS */
177