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_sides(uint *ret, ExtlTab tab)
101 if(!extl_table_gets_s(tab, "border_sides", &style))
104 if(strcmp(style, "all")==0)
106 else if(strcmp(style, "tb")==0)
108 else if(strcmp(style, "lr")==0)
111 warn(TR("Unknown border side configuration \"%s\"."), style);
117 void de_get_border(DEBorder *border, ExtlTab tab)
119 de_get_border_val(&(border->sh), tab, "shadow_pixels");
120 de_get_border_val(&(border->hl), tab, "highlight_pixels");
121 de_get_border_val(&(border->pad), tab, "padding_pixels");
122 de_get_border_style(&(border->style), tab);
123 de_get_border_sides(&(border->sides), tab);
133 bool de_get_colour(WRootWin *rootwin, DEColour *ret,
134 ExtlTab tab, DEStyle *based_on,
135 const char *what, DEColour substitute)
140 if(extl_table_gets_s(tab, what, &name)){
141 ok=de_alloc_colour(rootwin, ret, name);
144 warn(TR("Unable to allocate colour \"%s\"."), name);
147 }else if(based_on!=NULL){
148 return de_get_colour(rootwin, ret, based_on->data_table,
149 based_on->based_on, what, substitute);
153 ok=de_duplicate_colour(rootwin, substitute, ret);
159 void de_get_colour_group(WRootWin *rootwin, DEColourGroup *cg,
160 ExtlTab tab, DEStyle *based_on)
162 de_get_colour(rootwin, &(cg->hl), tab, based_on, "highlight_colour",
164 de_get_colour(rootwin, &(cg->sh), tab, based_on, "shadow_colour",
166 de_get_colour(rootwin, &(cg->bg), tab, based_on, "background_colour",
168 de_get_colour(rootwin, &(cg->fg), tab, based_on, "foreground_colour",
170 de_get_colour(rootwin, &(cg->pad), tab, based_on, "padding_colour",
175 void de_get_extra_cgrps(WRootWin *rootwin, DEStyle *style, ExtlTab tab)
178 uint i=0, nfailed=0, n=extl_table_get_n(tab);
185 style->extra_cgrps=ALLOC_N(DEColourGroup, n);
187 if(style->extra_cgrps==NULL)
190 for(i=0; i<n-nfailed; i++){
193 if(!extl_table_geti_t(tab, i+1, &sub))
196 if(!get_spec(sub, "substyle_pattern", &spec, NULL)){
197 extl_unref_table(sub);
201 style->extra_cgrps[i-nfailed].spec=spec;
203 de_get_colour_group(rootwin, style->extra_cgrps+i-nfailed, sub,
206 extl_unref_table(sub);
210 warn(TR("Corrupt substyle table %d."), i);
215 free(style->extra_cgrps);
216 style->extra_cgrps=NULL;
219 style->n_extra_cgrps=n-nfailed;
229 void de_get_text_align(int *alignret, ExtlTab tab)
233 if(!extl_table_gets_s(tab, "text_align", &align))
236 if(strcmp(align, "left")==0)
237 *alignret=DEALIGN_LEFT;
238 else if(strcmp(align, "right")==0)
239 *alignret=DEALIGN_RIGHT;
240 else if(strcmp(align, "center")==0)
241 *alignret=DEALIGN_CENTER;
243 warn(TR("Unknown text alignment \"%s\"."), align);
249 void de_get_transparent_background(uint *mode, ExtlTab tab)
253 if(extl_table_gets_b(tab, "transparent_background", &b))
264 void de_get_nonfont(WRootWin *rootwin, DEStyle *style, ExtlTab tab)
266 DEStyle *based_on=style->based_on;
268 style->data_table=extl_ref_table(tab);
271 style->border=based_on->border;
272 style->transparency_mode=based_on->transparency_mode;
273 style->textalign=based_on->textalign;
274 style->spacing=based_on->spacing;
277 de_get_border(&(style->border), tab);
278 de_get_border_val(&(style->spacing), tab, "spacing");
280 de_get_text_align(&(style->textalign), tab);
282 de_get_transparent_background(&(style->transparency_mode), tab);
284 style->cgrp_alloced=TRUE;
285 de_get_colour_group(rootwin, &(style->cgrp), tab, based_on);
286 de_get_extra_cgrps(rootwin, style, tab);
293 * Define a style for the root window \var{rootwin}.
296 bool de_defstyle_rootwin(WRootWin *rootwin, const char *name, ExtlTab tab)
302 DEStyle *based_on=NULL;
303 GrStyleSpec based_on_spec;
308 style=de_create_style(rootwin, name);
313 if(get_spec(tab, "based_on", &based_on_spec, &based_on_name)){
314 based_on=de_get_style(rootwin, &based_on_spec);
316 gr_stylespec_unalloc(&based_on_spec);
319 warn(TR("'based_on' for %s points back to the style itself."),
321 }else if(based_on==NULL){
322 warn(TR("Unknown base style. \"%s\""), based_on_name);
324 style->based_on=based_on;
325 based_on->usecount++;
326 /* Copy simple parameters */
332 de_get_nonfont(rootwin, style, tab);
334 if(extl_table_gets_s(tab, "font", &fnt)){
335 de_load_font_for_style(style, fnt);
337 }else if(based_on!=NULL && based_on->font!=NULL){
338 de_set_font_for_style(style, based_on->font);
341 if(style->font==NULL)
342 de_load_font_for_style(style, CF_FALLBACK_FONT_NAME);
352 bool de_defstyle(const char *name, ExtlTab tab)
357 FOR_ALL_ROOTWINS(rw){
358 if(!de_defstyle_rootwin(rw, name, tab))
371 ExtlTab de_substyle(const char *pattern, ExtlTab tab)
373 extl_table_sets_s(tab, "substyle_pattern", pattern);
374 return extl_ref_table(tab);
381 /*{{{ Module initialisation */
384 #include "../version.h"
386 char de_ion_api_version[]=ION_API_VERSION;
394 if(!de_register_exports())
397 if(!gr_register_engine("de", (GrGetBrushFn*)&de_get_brush))
400 /* Create fallback brushes */
401 FOR_ALL_ROOTWINS(rootwin){
402 style=de_create_style(rootwin, "*");
404 style->is_fallback=TRUE;
405 de_load_font_for_style(style, CF_FALLBACK_FONT_NAME);
412 de_unregister_exports();
419 gr_unregister_engine("de");
420 de_unregister_exports();