1 /************************************************************************/
2 /*									*/
3 /*  Keep a collection XftColors by number.				*/
4 /*									*/
5 /************************************************************************/
6 
7 #   include	"appFrameConfig.h"
8 
9 #   include	<stdlib.h>
10 #   include	<stdio.h>
11 #   include	<string.h>
12 #   include	<limits.h>
13 #   include	<utilColor.h>
14 #   include	"drawImpl.h"
15 
16 #   include	<appDebugon.h>
17 
18 #   ifdef USE_XFT
19 
20 #   include	"appXftColorList.h"
21 
22 /************************************************************************/
23 /*									*/
24 /*  1)  Number of text attributes per page in the list.			*/
25 /*									*/
26 /************************************************************************/
27 
28 #   define	AXCLsizePAGE	256
29 
appInitAppXftColor(AppXftColor * axc)30 static void appInitAppXftColor(	AppXftColor *	axc )
31     {
32     /* KEY */
33     axc->axcXRenderColor.red= 0;
34     axc->axcXRenderColor.green= 0;
35     axc->axcXRenderColor.blue= 0;
36     axc->axcXRenderColor.alpha= 0;
37 
38     /* DEP */
39     axc->axcXftColorAllocated= 0;
40     axc->axcList= (AppXftColorList *)0;
41 
42     return;
43     }
44 
appCleanAppXftColor(AppXftColor * axc)45 static void appCleanAppXftColor(	AppXftColor *	axc )
46     {
47     if  ( axc->axcXftColorAllocated && axc->axcList )
48 	{
49 	AppXftColorList *	axcl= axc->axcList;
50 
51 	XftColorFree( axcl->axclDisplay, axcl->axclVisual,
52 				    axcl->axclColormap, &(axc->axcXftColor) );
53 	}
54 
55     return;
56     }
57 
appXftAllocateColor(AppXftColor * axc,AppXftColorList * axcl)58 int appXftAllocateColor(	AppXftColor *		axc,
59 				AppXftColorList *	axcl )
60     {
61     int			num= appAppXftColorNumber( axcl, axc );
62     AppXftColor *	got;
63 
64     if  ( num < 0 )
65 	{ LDEB(num); return -1;	}
66 
67     got= (AppXftColor *)utilPagedListGetItemByNumber(
68 			    &(axcl->axclPropertiesList.nplPagedList), num );
69     if  ( ! got )
70 	{ LXDEB(num,got); return -1;	}
71 
72     if  ( ! got->axcXftColorAllocated )
73 	{
74 	if  ( ! XftColorAllocValue( axcl->axclDisplay,
75 						axcl->axclVisual,
76 						axcl->axclColormap,
77 						&(got->axcXRenderColor),
78 						&(got->axcXftColor) ) )
79 	    { LDEB(1); return -1;	}
80 
81 	got->axcXftColorAllocated= 1;
82 	got->axcList= axcl;
83 	}
84 
85     axc->axcXftColor= got->axcXftColor;
86     axc->axcXftColorAllocated= got->axcXftColorAllocated;
87     return 0;
88     }
89 
appSolidXftColor(AppXftColor * to,const APP_COLOR_RGB * from)90 void appSolidXftColor(		AppXftColor *		to,
91 				const APP_COLOR_RGB *	from )
92     {
93     const int	solid= USHRT_MAX;
94 
95     /* KEY */
96     if  ( to->axcXRenderColor.red == from->red		&&
97 	  to->axcXRenderColor.green == from->green	&&
98 	  to->axcXRenderColor.blue == from->blue	&&
99 	  to->axcXRenderColor.alpha == solid		)
100 	{ return;	}
101 
102     to->axcXRenderColor.red= from->red;
103     to->axcXRenderColor.green= from->green;
104     to->axcXRenderColor.blue= from->blue;
105     to->axcXRenderColor.alpha= solid;
106 
107     /* DEP */
108     to->axcXftColorAllocated= 0;
109 
110     return;
111     }
112 
appXftColorGetProperty(const AppXftColor * axc,int prop)113 static int appXftColorGetProperty(	const AppXftColor *	axc,
114 					int			prop )
115     {
116     switch( prop )
117 	{
118 	case RGBAcompRED:
119 	    return axc->axcXRenderColor.red;
120 	case RGBAcompGREEN:
121 	    return axc->axcXRenderColor.green;
122 	case RGBAcompBLUE:
123 	    return axc->axcXRenderColor.blue;
124 	case RGBAcompALPHA:
125 	    return axc->axcXRenderColor.alpha;
126 
127 	default:
128 	    LDEB(prop); return -1;
129 	}
130     }
131 
132 /************************************************************************/
133 /*									*/
134 /*  Initialize/Clean attribute administration.				*/
135 /*									*/
136 /************************************************************************/
137 
appInitAppXftColorList(AppXftColorList * axcl)138 void appInitAppXftColorList(	AppXftColorList *	axcl )
139     {
140     int			num;
141 
142     axcl->axclDisplay= (Display *)0;
143     axcl->axclVisual= (Visual *)0;
144     axcl->axclColormap= (Colormap)0;
145 
146     utilInitNumberedPropertiesList( &(axcl->axclPropertiesList) );
147 
148     utilStartNumberedPropertyList( &(axcl->axclPropertiesList),
149 			RGBAcomp_COUNT,
150 			(NumberedPropertiesGetProperty)appXftColorGetProperty,
151 
152 			sizeof(AppXftColor),
153 			(InitPagedListItem)appInitAppXftColor,
154 			(CleanPagedListItem)appCleanAppXftColor );
155 
156     appInitAppXftColor( &(axcl->axclCurrentColor) );
157 
158     num= appAppXftColorNumber( axcl, &(axcl->axclCurrentColor) );
159     if  ( num != 0 )
160 	{ LDEB(num);	}
161 
162     return;
163     }
164 
appCleanAppXftColorList(AppXftColorList * axcl)165 void appCleanAppXftColorList(	AppXftColorList *	axcl )
166     {
167     utilCleanNumberedPropertiesList( &(axcl->axclPropertiesList) );
168 
169     return;
170     }
171 
172 /************************************************************************/
173 /*									*/
174 /*  Translate a color number to a struct value.				*/
175 /*									*/
176 /************************************************************************/
177 
appGetAppXftColorByNumber(AppXftColor * axc,const AppXftColorList * axcl,int n)178 void appGetAppXftColorByNumber(	AppXftColor *			axc,
179 				const AppXftColorList *		axcl,
180 				int				n )
181     {
182     void *	vaxc;
183 
184     vaxc= utilPagedListGetItemByNumber(
185 				&(axcl->axclPropertiesList.nplPagedList), n );
186     if  ( ! vaxc )
187 	{ LXDEB(n,vaxc); appInitAppXftColor( axc ); return;	}
188 
189     *axc= *((AppXftColor *)vaxc);
190     return;
191     }
192 
193 /************************************************************************/
194 /*									*/
195 /*  Translate a text attribute to its number.				*/
196 /*									*/
197 /************************************************************************/
198 
appAppXftColorNumber(AppXftColorList * axcl,const AppXftColor * axc)199 int appAppXftColorNumber(	AppXftColorList *		axcl,
200 				const AppXftColor *		axc )
201     {
202     const int	make= 1;
203     return utilGetPropertyNumber( &(axcl->axclPropertiesList),
204 						    make, (void *)axc );
205     }
206 
207 #   endif
208