1 /*
2  * Copyright (c) 1999 Sasha Vasko <sasha at aftercode.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.   See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  *
18  */
19 
20 
21 #define LOCAL_DEBUG
22 #include "../configure.h"
23 #include "../libAfterStep/asapp.h"
24 #include "../libAfterStep/afterstep.h"
25 #include "../libAfterStep/mystyle.h"
26 #include "../libAfterStep/parser.h"
27 #include "../libAfterStep/screen.h"
28 #include "../libAfterStep/session.h"
29 
30 #include "afterconf.h"
31 
32 #define DEBUG_MYSTYLE
33 
34 TermDef MyStyleTerms[] = {
35 /* including MyStyles definitions here so we can process them correctly */
36 	MYSTYLE_TERMS,
37 	{0, NULL, 0, 0, 0}
38 };
39 
40 SyntaxDef MyStyleSyntax = {
41 	'\n',
42 	'\0',
43 	MyStyleTerms,
44 	0,														/* use default hash size */
45 	'\t',
46 	"",
47 	"",
48 	"Look MyStyle definition",
49 	"MyStyle",
50 	"defines combination of color, font, style, background to be used together",
51 	NULL,
52 	0
53 };
54 
55 flag_options_xref MyStyleFlags[] = {
56 	ASCF_DEFINE_MODULE_FLAG_XREF (MYSTYLE, DrawTextBackground,
57 																MyStyleDefinition),
58 	{0, 0, 0}
59 };
60 
61 /*****************************************************************************
62  *
63  * This routine is responsible for reading and parsing the MyStyle settings
64  *
65  ****************************************************************************/
66 
AddMyStyleDefinition(MyStyleDefinition ** tail)67 MyStyleDefinition *AddMyStyleDefinition (MyStyleDefinition ** tail)
68 {
69 	MyStyleDefinition *new_def = safecalloc (1, sizeof (MyStyleDefinition));
70 
71 	new_def->next = *tail;
72 	*tail = new_def;
73 
74 	return new_def;
75 }
76 
free_MSD_back_grad(MyStyleDefinition * msd)77 void free_MSD_back_grad (MyStyleDefinition * msd)
78 {
79 	if (msd->back_grad_npoints > 0) {
80 		if (msd->back_grad_colors) {
81 			register int i = msd->back_grad_npoints;
82 
83 			while (--i >= 0)
84 				if (msd->back_grad_colors[i])
85 					free (msd->back_grad_colors[i]);
86 			free (msd->back_grad_colors);
87 		}
88 		if (msd->back_grad_offsets)
89 			free (msd->back_grad_offsets);
90 	}
91 }
92 
DestroyMyStyleDefinitions(MyStyleDefinition ** list)93 void DestroyMyStyleDefinitions (MyStyleDefinition ** list)
94 {
95 	if (*list) {
96 		MyStyleDefinition *pnext = *list;
97 
98 		while (pnext != NULL) {
99 			MyStyleDefinition *pdef = pnext;
100 
101 			pnext = pdef->next;
102 			destroy_string (&(pdef->Name));
103 			destroy_string (&(pdef->Comment));
104 			if (pdef->inherit) {
105 				int i = pdef->inherit_num;
106 
107 				while (--i >= 0)
108 					destroy_string (&(pdef->inherit[i]));
109 				free (pdef->inherit);
110 			}
111 			destroy_string (&(pdef->Font));
112 			destroy_string (&(pdef->ForeColor));
113 			destroy_string (&(pdef->BackColor));
114 			destroy_string (&(pdef->back_pixmap));
115 			destroy_string (&(pdef->overlay));
116 			free_MSD_back_grad (pdef);
117 			DestroyFreeStorage (&(pdef->more_stuff));
118 			free (pdef);
119 		}
120 		*list = NULL;
121 	}
122 }
123 
PrintMyStyleDefinitions(MyStyleDefinition * list)124 void PrintMyStyleDefinitions (MyStyleDefinition * list)
125 {
126 #ifdef DEBUG_MYSTYLE
127 	while (list) {
128 		if (list->Name)
129 			fprintf (stderr, "\nMyStyle \"%s\"", list->Name);
130 		if (list->Comment)
131 			fprintf (stderr, "\n\tComment \"%s\"", list->Comment);
132 		if (list->inherit) {
133 			int i;
134 
135 			for (i = 0; i < list->inherit_num; ++i)
136 				if (list->inherit[i])
137 					fprintf (stderr, "\n\tInherit \"%s\"", list->inherit[i]);
138 		}
139 		fprintf (stderr, "\n\tInheritCount %d", list->inherit_num);
140 		if (list->Font)
141 			fprintf (stderr, "\n\tFont %s", list->Font);
142 		if (list->ForeColor)
143 			fprintf (stderr, "\n\tForeColor %s", list->ForeColor);
144 		if (list->BackColor)
145 			fprintf (stderr, "\n\tBackColor %s", list->BackColor);
146 
147 		fprintf (stderr, "\n\tTextStyle %d", list->TextStyle);
148 		fprintf (stderr, "\n\tSliceXStart %d", list->SliceXStart);
149 		fprintf (stderr, "\n\tSliceXEnd %d", list->SliceXEnd);
150 		fprintf (stderr, "\n\tSliceYStart %d", list->SliceYStart);
151 		fprintf (stderr, "\n\tSliceYEnd %d", list->SliceYEnd);
152 		fprintf (stderr, "\n\tBlurSize %dx%d", list->BlurSize.width,
153 						 list->BlurSize.height);
154 		if (get_flags (list->set_flags, MYSTYLE_DrawTextBackground)) {
155 			fprintf (stderr, "\n\tDrawTextBackground %d",
156 							 get_flags (list->flags,
157 													MYSTYLE_DrawTextBackground) ? 1 : 0);
158 		}
159 		if (list->overlay && list->overlay_type > TEXTURE_GRADIENT_END)
160 			fprintf (stderr, "\n\tOverlay %d \"%s\"", list->overlay_type,
161 							 list->overlay);
162 
163 		if (list->texture_type > 0) {
164 			if (list->texture_type > TEXTURE_GRADIENT_END) {
165 				if (list->back_pixmap)
166 					fprintf (stderr, "\n\tBackPixmap %d %s", list->texture_type,
167 									 list->back_pixmap);
168 				else
169 					fprintf (stderr, "\n\tBackPixmap %d", list->texture_type);
170 			} else {
171 				register int i = 0;
172 
173 				fprintf (stderr, "\n\tBackMultiGradient %d", list->back_grad_type);
174 				while (i < list->back_grad_npoints) {
175 					fprintf (stderr, "\t%s %f", list->back_grad_colors[i],
176 									 list->back_grad_offsets[i]);
177 					++i;
178 				}
179 			}
180 		}
181 		fprintf (stderr, "\n#set_flags = 0x%lX",
182 						 (unsigned long)list->set_flags);
183 		fprintf (stderr, "\n#flags = 0x%lX", (unsigned long)list->flags);
184 		fprintf (stderr, "\n~MyStyle\n");
185 		list = list->next;
186 	}
187 #endif
188 }
189 
190 void
HandleMyStyleSpecialTerm(MyStyleDefinition * msd,FreeStorageElem * fs)191 HandleMyStyleSpecialTerm (MyStyleDefinition * msd, FreeStorageElem * fs)
192 {
193 	ConfigItem item;
194 
195 	item.memory = NULL;
196 
197 	if (!ReadConfigItem (&item, fs))
198 		return;
199 
200 	switch (fs->term->id) {
201 	case MYSTYLE_Inherit_ID:
202 		{
203 			int pos = msd->inherit_num++;
204 
205 			msd->inherit =
206 					realloc (msd->inherit, sizeof (char *) * msd->inherit_num);
207 			msd->inherit[pos] = item.data.string;
208 		}
209 		break;
210 	case MYSTYLE_BackGradient_ID:
211 		if (fs->argc != 3)
212 			show_error
213 					("invalid number of colors in BackGradient definition (%d)",
214 					 fs->argc);
215 		else {
216 			free_MSD_back_grad (msd);
217 
218 			msd->back_grad_type = item.data.integer;
219 			msd->texture_type =
220 					mystyle_parse_old_gradient (msd->back_grad_type, 0, 0, NULL);
221 			msd->back_grad_npoints = 2;
222 			msd->back_grad_colors = safemalloc (2 * sizeof (char *));
223 			msd->back_grad_offsets = safemalloc (2 * sizeof (double));
224 			msd->back_grad_colors[0] = mystrdup (fs->argv[1]);
225 			msd->back_grad_colors[1] = mystrdup (fs->argv[2]);
226 			msd->back_grad_offsets[1] = 0.0;
227 			msd->back_grad_offsets[1] = 1.0;
228 		}
229 		break;
230 	case MYSTYLE_BackMultiGradient_ID:
231 		if (fs->argc < 4)
232 			show_error
233 					("invalid number of colors in BackMultiGradient definition (%d)",
234 					 fs->argc);
235 		else {
236 			int i;
237 
238 			free_MSD_back_grad (msd);
239 
240 			msd->back_grad_type = item.data.integer;
241 			msd->texture_type =
242 					mystyle_parse_old_gradient (msd->back_grad_type, 0, 0, NULL);
243 			msd->back_grad_npoints = ((fs->argc - 1) + 1) / 2;
244 			msd->back_grad_colors =
245 					safecalloc (msd->back_grad_npoints, sizeof (char *));
246 			msd->back_grad_offsets =
247 					safecalloc (msd->back_grad_npoints, sizeof (double));
248 			for (i = 0; i < msd->back_grad_npoints; ++i) {
249 				msd->back_grad_colors[i] = mystrdup (fs->argv[i * 2 + 1]);
250 				if (i * 2 + 2 < fs->argc)
251 					msd->back_grad_offsets[i] = atof (fs->argv[i * 2 + 2]);
252 			}
253 			msd->back_grad_offsets[msd->back_grad_npoints - 1] = 1.0;
254 		}
255 		break;
256 	case MYSTYLE_BackPixmap_ID:
257 		{
258 			set_string (&(msd->back_pixmap), item.data.string);
259 			msd->texture_type = item.index;
260 		}
261 		break;
262 	case MYSTYLE_Overlay_ID:
263 		{
264 			if (fs->argc > 1) {
265 				set_string (&(msd->overlay), stripcpy2 (fs->argv[1], False));
266 				msd->overlay_type = item.data.integer;
267 			} else
268 				show_error
269 						("Error in MyStyle \"%s\": Overlay option uses format :  \"Overlay <type> <mystyle name>\". Ignoring.",
270 						 msd->Name);
271 		}
272 		break;
273 	default:
274 		item.ok_to_free = 1;
275 	}
276 	ReadConfigItem (&item, NULL);
277 }
278 
CheckMyStyleDefinitionSanity(MyStyleDefinition * msd)279 Bool CheckMyStyleDefinitionSanity (MyStyleDefinition * msd)
280 {
281 	if (msd == NULL)
282 		return False;
283 
284 	if (msd->Name == NULL) {
285 		show_error
286 				("MyStyle without name is encountered and will be ignored.");
287 		return False;
288 	}
289 
290 	if (msd->texture_type < TEXTURE_SOLID
291 			|| msd->texture_type > TEXTURE_TEXTURED_END) {
292 		show_error
293 				("Error in MyStyle \"%s\": unsupported texture type [%d] in BackPixmap setting. Assuming default of [128] instead.",
294 				 msd->Name, msd->texture_type);
295 		msd->texture_type =
296 				msd->back_pixmap ? TEXTURE_PIXMAP : TEXTURE_TRANSPARENT;
297 	}
298 
299 	if (msd->overlay_type != 0)
300 		if (msd->overlay_type < TEXTURE_TEXTURED_START
301 				|| msd->texture_type > TEXTURE_TEXTURED_END) {
302 			show_error
303 					("Error in MyStyle \"%s\": unsupported overlay type [%d]. Assuming default of [131] instead.",
304 					 msd->Name, msd->overlay_type);
305 			msd->overlay_type = TEXTURE_TRANSPIXMAP_ALPHA;
306 		}
307 
308 
309 	return True;
310 }
311 
mystyle_find_or_get_from_file(struct ASHashTable * list,const char * name)312 MyStyle *mystyle_find_or_get_from_file (struct ASHashTable * list,
313 																				const char *name)
314 {
315 	MyStyle *ms;
316 
317 	if ((ms = mystyle_list_find (list, name)) == NULL) {
318 		char *fn =
319 				make_session_data_file (Session, False, S_IFREG, MYSTYLES_DIR,
320 																name, NULL);
321 
322 		if (fn == NULL)
323 			fn = make_session_data_file (Session, False, S_IFREG, MYSTYLES_DIR,
324 																	 "mystyle.", name, NULL);
325 		if (fn == NULL)
326 			fn = make_session_data_file (Session, True, S_IFREG, MYSTYLES_DIR,
327 																	 name, NULL);
328 		if (fn == NULL)
329 			fn = make_session_data_file (Session, True, S_IFREG, MYSTYLES_DIR,
330 																	 "mystyle.", name, NULL);
331 		if (fn != NULL) {
332 			FreeStorageElem *Storage = NULL;
333 			MyStyleDefinition *msd = NULL;
334 
335 			Storage = file2free_storage (fn, MyName, &MyStyleSyntax, NULL, NULL);
336 			if (Storage) {
337 				msd = free_storage_elem2MyStyleDefinition (Storage, name);
338 				DestroyFreeStorage (&Storage);
339 				if (msd != NULL) {
340 					ms = mystyle_create_from_definition (list, msd);
341 					DestroyMyStyleDefinitions (&msd);
342 				}
343 			}
344 			free (fn);
345 		}
346 	}
347 	return ms;
348 }
349 
mystyle_create_from_definition(struct ASHashTable * list,MyStyleDefinition * def)350 MyStyle *mystyle_create_from_definition (struct ASHashTable * list,
351 																				 MyStyleDefinition * def)
352 {
353 	int i;
354 	MyStyle *style;
355 
356 	if (def == NULL || def->Name == NULL)
357 		return NULL;
358 
359 	if ((style = mystyle_find (def->Name)) == NULL)
360 		style = mystyle_new_with_name (def->Name);
361 
362 	if (def->inherit) {
363 		for (i = 0; i < def->inherit_num; ++i) {
364 			MyStyle *parent;
365 
366 			if (def->inherit[i]) {
367 				if ((parent =
368 						 mystyle_find_or_get_from_file (list,
369 																						def->inherit[i])) != NULL)
370 					mystyle_merge_styles (parent, style, True, False);
371 				else
372 					show_error ("unknown style to inherit: %s\n", def->inherit[i]);
373 			}
374 		}
375 	}
376 	if (def->Font) {
377 		if (get_flags (style->user_flags, F_FONT)) {
378 			unload_font (&style->font);
379 			clear_flags (style->user_flags, F_FONT);
380 		}
381 		set_string (&(style->font.name), mystrdup (def->Font));
382 		set_flags (style->user_flags, F_FONT);
383 	}
384 	if (get_flags (def->set_flags, MYSTYLE_TextStyle)) {
385 		set_flags (style->user_flags, F_TEXTSTYLE);
386 		style->text_style = def->TextStyle;
387 	}
388 	if (get_flags (def->set_flags, MYSTYLE_SLICE_SET)) {
389 		set_flags (style->user_flags, F_SLICE);
390 		style->slice_x_start = def->SliceXStart;
391 		style->slice_x_end = def->SliceXEnd;
392 		style->slice_y_start = def->SliceYStart;
393 		style->slice_y_end = def->SliceYEnd;
394 	}
395 	if (get_flags (def->set_flags, MYSTYLE_BlurSize)) {
396 		set_flags (style->user_flags, F_BLUR);
397 		style->blur_x = def->BlurSize.width;
398 		style->blur_y = def->BlurSize.height;
399 	}
400 	if (def->ForeColor) {
401 		if (parse_argb_color (def->ForeColor, &(style->colors.fore)) !=
402 				def->ForeColor)
403 			set_flags (style->user_flags, F_FORECOLOR);
404 		else
405 			show_error ("unable to parse Forecolor \"%s\"", def->ForeColor);
406 	}
407 	if (def->BackColor) {
408 		if (parse_argb_color (def->BackColor, &(style->colors.back)) !=
409 				def->BackColor) {
410 			style->relief.fore = GetHilite (style->colors.back);
411 			style->relief.back = GetShadow (style->colors.back);
412 			set_flags (style->user_flags, F_BACKCOLOR);
413 		} else
414 			show_error ("unable to parse BackColor \"%s\"", def->BackColor);
415 	}
416 	if (def->overlay != NULL) {
417 		MyStyle *o = mystyle_find_or_get_from_file (list, def->overlay);
418 
419 		if (o != NULL) {
420 			style->overlay = o;
421 			style->overlay_type = def->overlay_type;
422 		} else
423 			show_error ("unknown style to be overlayed with: %s\n",
424 									def->overlay);
425 		set_flags (style->user_flags, F_OVERLAY);
426 	}
427 
428 	if (def->texture_type > 0 && def->texture_type <= TEXTURE_GRADIENT_END) {
429 		int type = def->back_grad_type;
430 		ASGradient gradient = { 0 };
431 		Bool success = False;
432 
433 		if (type <= TEXTURE_OLD_GRADIENT_END) {
434 			ARGB32 color1 = ARGB32_White, color2 = ARGB32_Black;
435 
436 			parse_argb_color (def->back_grad_colors[0], &color1);
437 			parse_argb_color (def->back_grad_colors[1], &color2);
438 			if ((type =
439 					 mystyle_parse_old_gradient (type, color1, color2,
440 																			 &gradient)) >= 0) {
441 				if (style->user_flags & F_BACKGRADIENT) {
442 					free (style->gradient.color);
443 					free (style->gradient.offset);
444 				}
445 				style->gradient = gradient;
446 				style->gradient.type = mystyle_translate_grad_type (type);
447 				LOCAL_DEBUG_OUT ("style %p type = %d", style,
448 												 style->gradient.type);
449 				success = True;
450 			} else
451 				show_error ("Error in MyStyle \"%s\": invalid gradient type %d",
452 										style->name, type);
453 		} else {
454 			int i;
455 
456 			gradient.npoints = def->back_grad_npoints;
457 			gradient.color = safecalloc (gradient.npoints, sizeof (ARGB32));
458 			gradient.offset = safecalloc (gradient.npoints, sizeof (double));
459 			for (i = 0; i < gradient.npoints; ++i) {
460 				ARGB32 color = ARGB32_White;
461 
462 				parse_argb_color (def->back_grad_colors[i], &color);
463 				gradient.color[i] = color;
464 				gradient.offset[i] = def->back_grad_offsets[i];
465 			}
466 			gradient.offset[0] = 0.0;
467 			gradient.offset[gradient.npoints - 1] = 1.0;
468 			if (style->user_flags & F_BACKGRADIENT) {
469 				free (style->gradient.color);
470 				free (style->gradient.offset);
471 			}
472 			style->gradient = gradient;
473 			style->gradient.type = mystyle_translate_grad_type (type);
474 			success = True;
475 		}
476 		if (success) {
477 			style->texture_type = def->texture_type;
478 			set_flags (style->user_flags, F_BACKGRADIENT);
479 		} else {
480 			if (gradient.color != NULL)
481 				free (gradient.color);
482 			if (gradient.offset != NULL)
483 				free (gradient.offset);
484 			show_error ("Error in MyStyle \"%s\": bad gradient", style->name);
485 		}
486 	} else if (def->texture_type > TEXTURE_GRADIENT_END
487 						 && def->texture_type <= TEXTURE_TEXTURED_END) {
488 		int type = def->texture_type;
489 
490 		if (get_flags (style->user_flags, F_BACKPIXMAP)) {
491 			mystyle_free_back_icon (style);
492 			clear_flags (style->user_flags, F_BACKTRANSPIXMAP | F_BACKPIXMAP);
493 		}
494 		clear_flags (style->inherit_flags, F_BACKTRANSPIXMAP | F_BACKPIXMAP);
495 		LOCAL_DEBUG_OUT ("calling mystyle_free_back_icon for style %p", style);
496 
497 		if (type == TEXTURE_TRANSPARENT || type == TEXTURE_TRANSPARENT_TWOWAY) {	/* treat second parameter as ARGB tint value : */
498 			if (parse_argb_color (def->back_pixmap, &(style->tint)) ==
499 					def->back_pixmap)
500 				style->tint = TINT_LEAVE_SAME;	/* use no tinting by default */
501 			else if (type == TEXTURE_TRANSPARENT)
502 				style->tint = (style->tint >> 1) & 0x7F7F7F7F;	/* converting old style tint */
503 /*LOCAL_DEBUG_OUT( "tint is 0x%X (from %s)",  style->tint, tmp);*/
504 			set_flags (style->user_flags, F_BACKPIXMAP);
505 			style->texture_type = type;
506 		} else {										/* treat second parameter as an image filename : */
507 			if (load_icon
508 					(&(style->back_icon), def->back_pixmap,
509 					 get_screen_image_manager (NULL))) {
510 				set_flags (style->user_flags, F_BACKPIXMAP);
511 				if (type >= TEXTURE_TRANSPIXMAP)
512 					set_flags (style->user_flags, F_BACKTRANSPIXMAP);
513 				style->texture_type = type;
514 			} else
515 				show_error
516 						("Parsing MyStyle \"%s\" failed to load image file \"%s\".",
517 						 style->name, def->back_pixmap);
518 		}
519 		LOCAL_DEBUG_OUT
520 				("MyStyle \"%s\": BackPixmap %d image = %p, tint = 0x%lX",
521 				 style->name, style->texture_type, style->back_icon.image,
522 				 style->tint);
523 	}
524 	if (get_flags (def->set_flags, MYSTYLE_DrawTextBackground)) {
525 		if (get_flags (def->flags, MYSTYLE_DrawTextBackground))
526 			set_flags (style->user_flags, F_DRAWTEXTBACKGROUND);
527 		else {
528 			clear_flags (style->user_flags, F_DRAWTEXTBACKGROUND);
529 			clear_flags (style->inherit_flags, F_DRAWTEXTBACKGROUND);
530 		}
531 	}
532 
533 	clear_flags (style->inherit_flags, style->user_flags);
534 	style->set_flags = style->inherit_flags | style->user_flags;
535 
536 	return style;
537 }
538 
539 
540 /*
541  * this function process a linked list of MyStyle definitions
542  * and create MyStyle for each valid definition
543  * this operation is destructive in the way that all
544  * data members of definitions that are used in MyStyle will be
545  * set to NULL, so to prevent them being deallocated by destroy function,
546  * and/or being used in other places
547  * ATTENTION !!!!!
548  * MyStyleDefinitions become unusable as the result, and get's destroyed
549  * pointer to a list becomes NULL !
550  */
ProcessMyStyleDefinitions(MyStyleDefinition ** list)551 void ProcessMyStyleDefinitions (MyStyleDefinition ** list)
552 {
553 	MyStyleDefinition *pCurr;
554 
555 	if (list)
556 		if (*list) {
557 			for (pCurr = *list; pCurr; pCurr = pCurr->next)
558 				mystyle_create_from_definition (NULL, pCurr);
559 			DestroyMyStyleDefinitions (list);
560 			mystyle_fix_styles ();
561 		}
562 }
563 
564 void
mystyle_parse(char * tline,FILE * fd,char ** myname,int * mystyle_list)565 mystyle_parse (char *tline, FILE * fd, char **myname, int *mystyle_list)
566 {
567 	FreeStorageElem *Storage = NULL;
568 	MyStyleDefinition **list = (MyStyleDefinition **) mystyle_list, **tail;
569 
570 	if (list == NULL)
571 		return;
572 	for (tail = list; *tail != NULL; tail = &((*tail)->next)) ;
573 
574 	Storage =
575 			tline_subsyntax_parse ("MyStyle", tline, fd, (char *)myname,
576 														 &MyStyleSyntax, NULL, NULL);
577 	if (Storage) {
578 		*tail = free_storage_elem2MyStyleDefinition (Storage, NULL);
579 		DestroyFreeStorage (&Storage);
580 	}
581 }
582 
583 
GetMyStyleDefinition(MyStyleDefinition ** list,const char * name,Bool add_new)584 MyStyleDefinition *GetMyStyleDefinition (MyStyleDefinition ** list,
585 																				 const char *name, Bool add_new)
586 {
587 	register MyStyleDefinition *style = NULL;
588 
589 	if (name) {
590 		for (style = *list; style != NULL; style = style->next)
591 			if (mystrcasecmp (style->Name, name) == 0)
592 				break;
593 		if (style == NULL && add_new) {	/* add new style here */
594 			style = AddMyStyleDefinition (list);
595 			style->Name = mystrdup (name);
596 		}
597 	}
598 	return style;
599 }
600 
601 
602 void
MergeMyStyleText(MyStyleDefinition ** list,const char * name,const char * new_font,const char * new_fcolor,const char * new_bcolor,int new_style)603 MergeMyStyleText (MyStyleDefinition ** list, const char *name,
604 									const char *new_font, const char *new_fcolor,
605 									const char *new_bcolor, int new_style)
606 {
607 	register MyStyleDefinition *style = NULL;
608 
609 	if ((style = GetMyStyleDefinition (list, name, True)) != NULL) {
610 		if (new_font)
611 			set_string (&(style->Font), mystrdup (new_font));
612 		if (new_fcolor)
613 			set_string (&(style->ForeColor), mystrdup (new_fcolor));
614 		if (new_bcolor)
615 			set_string (&(style->BackColor), mystrdup (new_bcolor));
616 		if (new_style >= 0) {
617 			style->TextStyle = new_style;
618 			set_flags (style->set_flags, MYSTYLE_TextStyle);
619 		}
620 	}
621 }
622 
623 void
MergeMyStyleTextureOld(MyStyleDefinition ** list,const char * name,int type,char * color_from,char * color_to,char * pixmap)624 MergeMyStyleTextureOld (MyStyleDefinition ** list, const char *name,
625 												int type, char *color_from, char *color_to,
626 												char *pixmap)
627 {
628 	register MyStyleDefinition *style;
629 
630 	if ((style = GetMyStyleDefinition (list, name, True)) == NULL)
631 		return;
632 
633 #if 0
634 	if (!get_flags (style->set_flags, F_BACKPIXMAP)) {
635 		TextureDef *t =
636 				add_texture_def (&(style->back), &(style->back_layers));
637 
638 		type = pixmap_type2texture_type (type);
639 		if (TEXTURE_IS_ICON (type)) {
640 			if (pixmap != NULL) {
641 				set_string_value (&(t->data.icon.image), pixmap,
642 													&(style->set_flags), F_BACKTEXTURE);
643 				t->type = type;
644 			}
645 		} else if (TEXTURE_IS_GRADIENT (type)) {
646 			if (color_from != NULL && color_to != NULL) {
647 				make_old_gradient (t, type, color_from, color_to);
648 			}
649 		} else if (TEXTURE_IS_TRANSPARENT (type) && pixmap) {
650 			set_string_value (&(t->data.icon.tint), pixmap, &(style->set_flags),
651 												F_BACKTEXTURE);
652 			style->back[0].type = type;
653 		}
654 	}
655 #endif
656 }
657 
MyStyleSpecialTerms2FreeStorage(MyStyleDefinition * msd,SyntaxDef * syntax)658 FreeStorageElem *MyStyleSpecialTerms2FreeStorage (MyStyleDefinition * msd,
659 																									SyntaxDef * syntax)
660 {
661 	int i;
662 	FreeStorageElem *fs = NULL;
663 	FreeStorageElem **tail = &fs;
664 
665 	for (i = 0; i < msd->inherit_num; i++)
666 		tail =
667 				QuotedString2FreeStorage (&MyStyleSyntax, tail, NULL,
668 																	msd->inherit[i], MYSTYLE_Inherit_ID);
669 
670 	tail = Flag2FreeStorage (&MyStyleSyntax, tail, MYSTYLE_DONE_ID);
671 
672 #if 0
673 
674 	if (get_flags (def->set_flags, F_BACKPIXMAP))
675 
676 		for (i = 0; i < def->back_layers; i++)
677 			tail =
678 					TextureDef2FreeStorage (&MyStyleSyntax, tail, &(def->back[i]),
679 																	MYSTYLE_BACKPIXMAP_ID);
680 	if (get_flags (def->set_flags, F_DRAWTEXTBACKGROUND))
681 		tail =
682 				Integer2FreeStorage (&MyStyleSyntax, tail, NULL,
683 														 def->draw_text_background,
684 														 MYSTYLE_DRAWTEXTBACKGROUND_ID);
685 
686 #endif
687 
688 	return fs;
689 }
690