1 // resource.cc for bbdate - an tool to display new mail in X11.
2 //
3 //  Copyright (c) 1998-1999 John Kennis, j.m.b.m.kennis@tue.nl
4 //
5 //  This program is free software; you can redistribute it and/or modify
6 //  it under the terms of the GNU General Public License as published by
7 //  the Free Software Foundation; either version 2 of the License, or
8 //  (at your option) any later version.
9 //
10 //  This program is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //  GNU General Public License for more details.
14 //
15 //  You should have received a copy of the GNU General Public License
16 //  along with this program; if not, write to the Free Software
17 //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //
19 // (See the included file COPYING / GPL-2.0)
20 //
21 
22 #include "resource.hh"
23 #include "blackboxstyle.hh"
24 
Resource(ToolWindow * toolwindow)25 Resource::Resource(ToolWindow *toolwindow):
26   BaseResource(toolwindow)
27 {
28   frame.font=0;
29   label.font=0;
30   Load();
31 }
32 
~Resource()33 Resource::~Resource()
34 {
35 	Clean();
36 }
37 
Clean()38 void Resource::Clean()
39 {
40 	if (label.font)
41 		XFreeFont(bbtool->dpy, label.font);
42 	if (frame.font)
43 		XFreeFont(bbtool->dpy, frame.font);
44 }
45 
46 
LoadBBToolResource(void)47 void Resource::LoadBBToolResource(void)
48 {
49 	XrmValue value;
50 	char *value_type;
51 
52 	if (XrmGetResource(resource_db, "bbdate.autoConfig",
53 		     "Bbdate.Autoconfig", &value_type, &value))
54 	{
55     	if (! strncasecmp("true", value.addr, value.size))
56     	{
57 				style.auto_config = True;
58   		}
59 	    else
60     		style.auto_config = False;
61 	}
62 	else
63 		style.auto_config = False;
64 
65   SizeAndPosition();
66 
67 	Frame();
68 	Show();
69 
70 	Label();
71 
72 }
73 
74 
Frame()75 void Resource::Frame()
76 {
77 	XrmValue value;
78 	char *value_type;
79 
80   readDatabaseTexture("bbdate.frame","Bbdate.Frame",BB_FRAME,"Toolbar",
81                       "slategrey","darkslategrey",
82                       BImage_Raised|BImage_Gradient|BImage_Vertical|
83                       BImage_Bevel1,&frame.texture);
84 
85 	if (XrmGetResource(resource_db, "bbdate.bevelWidth","Bbdate.BevelWidth",
86 						&value_type, &value))
87 	{
88 		if (sscanf(value.addr, "%u", &frame.bevelWidth) != 1)
89 			frame.bevelWidth = 4;
90 		else if (frame.bevelWidth == 0)
91 			frame.bevelWidth = 4;
92 	}
93 	else if (XrmGetResource(resource_db, BB_BEVELWIDTH,"BevelWidth", &value_type,
94                           &value))
95 	{
96 		if (sscanf(value.addr, "%u", &frame.bevelWidth) != 1)
97 			frame.bevelWidth = 4;
98 		else if (frame.bevelWidth == 0)
99 			frame.bevelWidth = 4;
100 	}
101 	else
102     	frame.bevelWidth = 4;
103 }
104 
105 
SizeAndPosition()106 void Resource::SizeAndPosition()
107 {
108 	XrmValue value;
109 	char *value_type;
110 	unsigned int w,h;
111 	char positionstring[11];
112 
113   if (!(bbtool->withdrawn))
114   {
115   	if (XrmGetResource(resource_db, "bbdate.withdrawn",
116 		     "Bbdate.Withdrawn", &value_type, &value))
117     {
118   		if (! strncasecmp("true", value.addr, value.size))
119 	  		bbtool->withdrawn = True;
120 	    else
121 		  	bbtool->withdrawn = False;
122   	}
123 	  else
124 		  bbtool->withdrawn = False;
125   }
126 
127   if (!(bbtool->shape))
128   {
129   	if (XrmGetResource(resource_db, "bbdate.shape",
130 		     "Bbdate.Shape", &value_type, &value))
131     {
132   		if (! strncasecmp("true", value.addr, value.size))
133 	  		bbtool->shape = True;
134 	    else
135 		  	bbtool->shape = False;
136   	}
137 	  else
138 		  bbtool->shape = bbtool->withdrawn;
139   }
140 
141 
142 	if (!(bbtool->position))
143 	{
144 		if (!(XrmGetResource(resource_db, "bbdate.position","Bbdate.Position",
145 							&value_type, &value)))
146 			strncpy(positionstring, "-0-0", 5);
147 		else
148 			strncpy(positionstring, value.addr, strlen(value.addr)+1);
149 	}
150 	else
151 		strncpy(positionstring, bbtool->position, strlen(bbtool->position)+1);
152 
153 
154 	position.mask=XParseGeometry(positionstring, &position.x, &position.y, &w, &h);
155 	if (!(position.mask & XValue))
156 		position.x=0;
157 	if (!(position.mask & YValue))
158 		position.y=0;
159 
160 	/* need this to compute the height */
161 	const char *defaultFont = "-*-helvetica-medium-r-*-*-*-120-*-*-*-*-*-*";
162 
163 	if (frame.font)
164 	{
165     	XFreeFont(bbtool->dpy, frame.font);
166 		frame.font = 0;
167 	}
168 
169 	if (XrmGetResource(resource_db, "bbdate.heightBy.font","Bbdate.heightBy.Font",
170 						&value_type, &value))
171 	{
172     	if ((frame.font = XLoadQueryFont(bbtool->dpy, value.addr)) == NULL)
173 		{
174     		fprintf(stderr, " blackbox: couldn't load font '%s'\n"
175 	      					" ...  reverting to default font.", value.addr);
176 	    	if ((frame.font = XLoadQueryFont(bbtool->dpy, defaultFont)) == NULL)
177 			{
178 				fprintf(stderr,"blackbox: couldn't load default font.  please check to\n"
179 								"make sure the necessary font is installed '%s'\n",
180 					defaultFont);
181 				exit(2);
182 			}
183 		}
184 	}
185 	else if (XrmGetResource(resource_db, BB_FONT,"TitleFont", &value_type, &value))
186 	{
187 		if ((frame.font = XLoadQueryFont(bbtool->dpy, value.addr)) == NULL)
188 		{
189     		fprintf(stderr, " blackbox: couldn't load font '%s'\n"
190 	      					" ...  reverting to default font.", value.addr);
191 			if ((frame.font = XLoadQueryFont(bbtool->dpy, defaultFont)) == NULL)
192 			{
193 				fprintf(stderr,
194 					"blackbox: couldn't load default font.  please check to\n"
195 					"make sure the necessary font is installed '%s'\n",
196 					defaultFont);
197 				exit(2);
198 			}
199 		}
200 	}
201 	else
202 	{
203     	if ((frame.font = XLoadQueryFont(bbtool->dpy, defaultFont)) == NULL)
204 		{
205 			fprintf(stderr,
206 	      			"blackbox: couldn't load default font.  please check to\n"
207 	      			"make sure the necessary font is installed '%s'\n", defaultFont);
208 			exit(2);
209 		}
210 	}
211 }
212 
Label(void)213 void Resource::Label(void)
214 {
215 	XrmValue value;
216 	char *value_type;
217 
218 	/* text-label resources */
219 	if (XrmGetResource(resource_db, "bbdate.label.transparent",
220 		     "Bbdate.label.Transparent", &value_type, &value))
221 	{
222 		if (! strncasecmp("true", value.addr, value.size))
223 			label.transparent = True;
224 	    else
225 			label.transparent = False;
226 	}
227 	else
228 		label.transparent = False;
229 
230 	readDatabaseTexture("bbdate.label", "Bbdate.Label",BB_LABEL,"Toolbar.Label",
231                       "slategrey","darkslategrey",
232                       BImage_Sunken|BImage_Gradient|BImage_Vertical|
233                       BImage_Bevel1,&label.texture);
234 
235 		readDatabaseColor("bbdate..textColor",
236       								"Bbdate.TextColor",
237                       BB_LABEL_TEXTCOLOR, "Toolbar.TextColor",
238                       "LightGrey",&label.textColor);
239 
240 
241 	const char *defaultFont = "-*-helvetica-medium-r-*-*-*-120-*-*-*-*-*-*";
242 
243 	if (label.font)
244 	{
245 		XFreeFont(bbtool->dpy, label.font);
246 		label.font = 0;
247 	}
248 
249 	if (XrmGetResource(resource_db, "bbdate.label.font", "Bbdate.Label.Font",
250 						&value_type, &value))
251 	{
252 		if ((label.font = XLoadQueryFont(bbtool->dpy, value.addr)) == NULL)
253 		{
254     	fprintf(stderr, " blackbox: couldn't load font '%s'\n"
255 	      							" ...  reverting to default font.", value.addr);
256 		    if ((label.font = XLoadQueryFont(bbtool->dpy, defaultFont)) == NULL)
257 			{
258 				fprintf(stderr,
259 					"blackbox: couldn't load default font.  please check to\n"
260 					"make sure the necessary font is installed '%s'\n",
261 					defaultFont);
262 			exit(2);
263 			}
264 		}
265 	}
266 	else if  (XrmGetResource(resource_db, BB_FONT, "TitleFont", &value_type, &value))
267 	{
268 		if ((label.font = XLoadQueryFont(bbtool->dpy, value.addr)) == NULL)
269 		{
270 			fprintf(stderr, " blackbox: couldn't load font '%s'\n"
271 	      					" ...  reverting to default font.", value.addr);
272 			if ((label.font = XLoadQueryFont(bbtool->dpy, defaultFont)) == NULL)
273 			{
274 				fprintf(stderr,
275 					"blackbox: couldn't load default font.  please check to\n"
276 					"make sure the necessary font is installed '%s'\n",
277 					defaultFont);
278 				exit(2);
279 			}
280 		}
281 	}
282 	else
283 	{
284 		if ((label.font = XLoadQueryFont(bbtool->dpy, defaultFont)) == NULL)
285 		{
286 			fprintf(stderr,"blackbox: couldn't load default font.  please check to\n"
287 				    "make sure the necessary font is installed '%s'\n", defaultFont);
288 			exit(2);
289 		}
290 	}
291 }
292 
293 
Show()294 void Resource::Show()
295 {
296 	XrmValue value;
297 	char *value_type;
298 
299 	report.euStyle = False;
300 	report.intStyle = False;
301 
302  	if (XrmGetResource(resource_db, "bbdate.show.euStyle",
303 		     "Bbdate.show.EuStyle", &value_type, &value))
304 	{
305     	if (! strncasecmp("true", value.addr, value.size))
306     	{
307 				report.euStyle = True;
308   		}
309 	}
310 	else if (XrmGetResource(resource_db, "bbdate.show.intStyle",
311 			"Bbdate.show.IntStyle", &value_type, &value))
312 	{
313 		if (! strncasecmp("true", value.addr, value.size))
314 		{
315 			report.intStyle = True;
316 		}
317 	}
318 
319 	/* what to show.resources */
320 }
321