4 * Copyright (c) Tuomo Valkonen 1999-2007.
6 * Ion is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
14 #include <libextl/readconfig.h>
15 #include <libextl/extl.h>
17 #include <ioncore/common.h>
18 #include <ioncore/global.h>
19 #include <ioncore/rootwin.h>
20 #include <ioncore/extlconv.h>
21 #include <ioncore/ioncore.h>
31 /*{{{ Style specifications */
34 static bool get_spec(ExtlTab tab, const char *name, GrStyleSpec *spec,
40 if(!extl_table_gets_s(tab, name, &str))
43 res=gr_stylespec_load(spec, str);
60 #define CF_BORDER_VAL_SANITY_CHECK 16
62 void de_get_border_val(uint *val, ExtlTab tab, const char *what)
66 if(extl_table_gets_i(tab, what, &g)){
67 if(g>CF_BORDER_VAL_SANITY_CHECK || g<0)
68 warn(TR("Border attribute %s sanity check failed."), what);
75 void de_get_border_style(uint *ret, ExtlTab tab)
79 if(!extl_table_gets_s(tab, "border_style", &style))
82 if(strcmp(style, "inlaid")==0)
84 else if(strcmp(style, "elevated")==0)
85 *ret=DEBORDER_ELEVATED;
86 else if(strcmp(style, "groove")==0)
88 else if(strcmp(style, "ridge")==0)
91 warn(TR("Unknown border style \"%s\"."), style);
97 void de_get_border(DEBorder *border, ExtlTab tab)
99 de_get_border_val(&(border->sh), tab, "shadow_pixels");
100 de_get_border_val(&(border->hl), tab, "highlight_pixels");
101 de_get_border_val(&(border->pad), tab, "padding_pixels");
102 de_get_border_style(&(border->style), tab);
112 bool de_get_colour(WRootWin *rootwin, DEColour *ret,
113 ExtlTab tab, DEStyle *based_on,
114 const char *what, DEColour substitute)
119 if(extl_table_gets_s(tab, what, &name)){
120 ok=de_alloc_colour(rootwin, ret, name);
123 warn(TR("Unable to allocate colour \"%s\"."), name);
126 }else if(based_on!=NULL){
127 return de_get_colour(rootwin, ret, based_on->data_table,
128 based_on->based_on, what, substitute);
132 ok=de_duplicate_colour(rootwin, substitute, ret);
138 void de_get_colour_group(WRootWin *rootwin, DEColourGroup *cg,
139 ExtlTab tab, DEStyle *based_on)
141 de_get_colour(rootwin, &(cg->hl), tab, based_on, "highlight_colour",
143 de_get_colour(rootwin, &(cg->sh), tab, based_on, "shadow_colour",
145 de_get_colour(rootwin, &(cg->bg), tab, based_on, "background_colour",
147 de_get_colour(rootwin, &(cg->fg), tab, based_on, "foreground_colour",
149 de_get_colour(rootwin, &(cg->pad), tab, based_on, "padding_colour",
154 void de_get_extra_cgrps(WRootWin *rootwin, DEStyle *style, ExtlTab tab)
157 uint i=0, nfailed=0, n=extl_table_get_n(tab);
164 style->extra_cgrps=ALLOC_N(DEColourGroup, n);
166 if(style->extra_cgrps==NULL)
169 for(i=0; i<n-nfailed; i++){
172 if(!extl_table_geti_t(tab, i+1, &sub))
175 if(!get_spec(sub, "substyle_pattern", &spec, NULL)){
176 extl_unref_table(sub);
180 style->extra_cgrps[i-nfailed].spec=spec;
182 de_get_colour_group(rootwin, style->extra_cgrps+i-nfailed, sub,
185 extl_unref_table(sub);
189 warn(TR("Corrupt substyle table %d."), i);
194 free(style->extra_cgrps);
195 style->extra_cgrps=NULL;
198 style->n_extra_cgrps=n-nfailed;
208 void de_get_text_align(int *alignret, ExtlTab tab)
212 if(!extl_table_gets_s(tab, "text_align", &align))
215 if(strcmp(align, "left")==0)
216 *alignret=DEALIGN_LEFT;
217 else if(strcmp(align, "right")==0)
218 *alignret=DEALIGN_RIGHT;
219 else if(strcmp(align, "center")==0)
220 *alignret=DEALIGN_CENTER;
222 warn(TR("Unknown text alignment \"%s\"."), align);
228 void de_get_transparent_background(uint *mode, ExtlTab tab)
232 if(extl_table_gets_b(tab, "transparent_background", &b))
243 void de_get_nonfont(WRootWin *rootwin, DEStyle *style, ExtlTab tab)
245 DEStyle *based_on=style->based_on;
247 style->data_table=extl_ref_table(tab);
250 style->border=based_on->border;
251 style->transparency_mode=based_on->transparency_mode;
252 style->textalign=based_on->textalign;
253 style->spacing=based_on->spacing;
256 de_get_border(&(style->border), tab);
257 de_get_border_val(&(style->spacing), tab, "spacing");
259 de_get_text_align(&(style->textalign), tab);
261 de_get_transparent_background(&(style->transparency_mode), tab);
263 style->cgrp_alloced=TRUE;
264 de_get_colour_group(rootwin, &(style->cgrp), tab, based_on);
265 de_get_extra_cgrps(rootwin, style, tab);
272 * Define a style for the root window \var{rootwin}.
275 bool de_defstyle_rootwin(WRootWin *rootwin, const char *name, ExtlTab tab)
281 DEStyle *based_on=NULL;
282 GrStyleSpec based_on_spec;
287 style=de_create_style(rootwin, name);
292 if(get_spec(tab, "based_on", &based_on_spec, &based_on_name)){
293 based_on=de_get_style(rootwin, &based_on_spec);
295 gr_stylespec_unalloc(&based_on_spec);
298 warn(TR("'based_on' for %s points back to the style itself."),
300 }else if(based_on==NULL){
301 warn(TR("Unknown base style. \"%s\""), based_on_name);
303 style->based_on=based_on;
304 based_on->usecount++;
305 /* Copy simple parameters */
311 de_get_nonfont(rootwin, style, tab);
313 if(extl_table_gets_s(tab, "font", &fnt)){
314 de_load_font_for_style(style, fnt);
316 }else if(based_on!=NULL && based_on->font!=NULL){
317 de_set_font_for_style(style, based_on->font);
320 if(style->font==NULL)
321 de_load_font_for_style(style, CF_FALLBACK_FONT_NAME);
331 bool de_defstyle(const char *name, ExtlTab tab)
336 FOR_ALL_ROOTWINS(rw){
337 if(!de_defstyle_rootwin(rw, name, tab))
350 ExtlTab de_substyle(const char *pattern, ExtlTab tab)
352 extl_table_sets_s(tab, "substyle_pattern", pattern);
353 return extl_ref_table(tab);
360 /*{{{ Module initialisation */
363 #include "../version.h"
365 char de_ion_api_version[]=ION_API_VERSION;
373 if(!de_register_exports())
376 if(!gr_register_engine("de", (GrGetBrushFn*)&de_get_brush))
379 /* Create fallback brushes */
380 FOR_ALL_ROOTWINS(rootwin){
381 style=de_create_style(rootwin, "*");
383 style->is_fallback=TRUE;
384 de_load_font_for_style(style, CF_FALLBACK_FONT_NAME);
391 de_unregister_exports();
398 gr_unregister_engine("de");
399 de_unregister_exports();