4 * Copyright (c) Tuomo Valkonen 1999-2006.
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>
34 #define CF_BORDER_VAL_SANITY_CHECK 16
36 void de_get_border_val(uint *val, ExtlTab tab, const char *what)
40 if(extl_table_gets_i(tab, what, &g)){
41 if(g>CF_BORDER_VAL_SANITY_CHECK || g<0)
42 warn(TR("Border attribute %s sanity check failed."), what);
49 void de_get_border_style(uint *ret, ExtlTab tab)
53 if(!extl_table_gets_s(tab, "border_style", &style))
56 if(strcmp(style, "inlaid")==0)
58 else if(strcmp(style, "elevated")==0)
59 *ret=DEBORDER_ELEVATED;
60 else if(strcmp(style, "groove")==0)
62 else if(strcmp(style, "ridge")==0)
65 warn(TR("Unknown border style \"%s\"."), style);
71 void de_get_border(DEBorder *border, ExtlTab tab)
73 de_get_border_val(&(border->sh), tab, "shadow_pixels");
74 de_get_border_val(&(border->hl), tab, "highlight_pixels");
75 de_get_border_val(&(border->pad), tab, "padding_pixels");
76 de_get_border_style(&(border->style), tab);
86 bool de_get_colour(WRootWin *rootwin, DEColour *ret,
87 ExtlTab tab, DEStyle *based_on,
88 const char *what, DEColour substitute)
93 if(extl_table_gets_s(tab, what, &name)){
94 ok=de_alloc_colour(rootwin, ret, name);
97 warn(TR("Unable to allocate colour \"%s\"."), name);
100 }else if(based_on!=NULL){
101 return de_get_colour(rootwin, ret, based_on->data_table,
102 based_on->based_on, what, substitute);
106 ok=de_duplicate_colour(rootwin, substitute, ret);
112 void de_get_colour_group(WRootWin *rootwin, DEColourGroup *cg,
113 ExtlTab tab, DEStyle *based_on)
115 de_get_colour(rootwin, &(cg->hl), tab, based_on, "highlight_colour",
117 de_get_colour(rootwin, &(cg->sh), tab, based_on, "shadow_colour",
119 de_get_colour(rootwin, &(cg->bg), tab, based_on, "background_colour",
121 de_get_colour(rootwin, &(cg->fg), tab, based_on, "foreground_colour",
123 de_get_colour(rootwin, &(cg->pad), tab, based_on, "padding_colour",
128 void de_get_extra_cgrps(WRootWin *rootwin, DEStyle *style, ExtlTab tab)
131 uint i=0, nfailed=0, n=extl_table_get_n(tab);
138 style->extra_cgrps=ALLOC_N(DEColourGroup, n);
140 if(style->extra_cgrps==NULL)
143 for(i=0; i<n-nfailed; i++){
144 if(!extl_table_geti_t(tab, i+1, &sub))
146 if(!extl_table_gets_s(sub, "substyle_pattern", &name)){
147 extl_unref_table(sub);
151 /*de_init_colour_group(rootwin, style->extra_cgrps+i-nfailed);*/
152 style->extra_cgrps[i-nfailed].spec=name;
153 de_get_colour_group(rootwin, style->extra_cgrps+i-nfailed, sub,
156 extl_unref_table(sub);
160 warn(TR("Corrupt substyle table %d."), i);
165 free(style->extra_cgrps);
166 style->extra_cgrps=NULL;
169 style->n_extra_cgrps=n-nfailed;
179 void de_get_text_align(int *alignret, ExtlTab tab)
183 if(!extl_table_gets_s(tab, "text_align", &align))
186 if(strcmp(align, "left")==0)
187 *alignret=DEALIGN_LEFT;
188 else if(strcmp(align, "right")==0)
189 *alignret=DEALIGN_RIGHT;
190 else if(strcmp(align, "center")==0)
191 *alignret=DEALIGN_CENTER;
193 warn(TR("Unknown text alignment \"%s\"."), align);
199 void de_get_transparent_background(uint *mode, ExtlTab tab)
203 if(extl_table_gets_b(tab, "transparent_background", &b))
214 void de_get_nonfont(WRootWin *rootwin, DEStyle *style, ExtlTab tab)
216 DEStyle *based_on=style->based_on;
218 style->data_table=extl_ref_table(tab);
221 style->border=based_on->border;
222 style->transparency_mode=based_on->transparency_mode;
223 style->textalign=based_on->textalign;
224 style->spacing=based_on->spacing;
227 de_get_border(&(style->border), tab);
228 de_get_border_val(&(style->spacing), tab, "spacing");
230 de_get_text_align(&(style->textalign), tab);
232 de_get_transparent_background(&(style->transparency_mode), tab);
234 style->cgrp_alloced=TRUE;
235 de_get_colour_group(rootwin, &(style->cgrp), tab, based_on);
236 de_get_extra_cgrps(rootwin, style, tab);
241 * Define a style for the root window \var{rootwin}.
244 bool de_defstyle_rootwin(WRootWin *rootwin, const char *name, ExtlTab tab)
249 DEStyle *based_on=NULL;
250 char *based_on_name=NULL;
255 style=de_create_style(rootwin, name);
260 if(extl_table_gets_s(tab, "based_on", &based_on_name)){
261 based_on=de_get_style(rootwin, based_on_name);
263 warn(TR("'based_on' for %s points back to the style itself."),
265 }else if(based_on==NULL){
266 warn(TR("Unknown base style \"%s\"."), based_on);
268 style->based_on=based_on;
269 based_on->usecount++;
270 /* Copy simple parameters */
275 de_get_nonfont(rootwin, style, tab);
277 if(extl_table_gets_s(tab, "font", &fnt)){
278 de_load_font_for_style(style, fnt);
280 }else if(based_on!=NULL && based_on->font!=NULL){
281 de_set_font_for_style(style, based_on->font);
284 if(style->font==NULL)
285 de_load_font_for_style(style, CF_FALLBACK_FONT_NAME);
295 bool de_defstyle(const char *name, ExtlTab tab)
300 FOR_ALL_ROOTWINS(rw){
301 if(!de_defstyle_rootwin(rw, name, tab))
314 ExtlTab de_substyle(const char *pattern, ExtlTab tab)
316 extl_table_sets_s(tab, "substyle_pattern", pattern);
317 return extl_ref_table(tab);
324 /*{{{ Module initialisation */
327 #include "../version.h"
329 char de_ion_api_version[]=ION_API_VERSION;
337 if(!de_register_exports())
340 if(!gr_register_engine("de", (GrGetBrushFn*)&de_get_brush))
343 /* Create fallback brushes */
344 FOR_ALL_ROOTWINS(rootwin){
345 style=de_create_style(rootwin, "*");
347 style->is_fallback=TRUE;
348 de_load_font_for_style(style, CF_FALLBACK_FONT_NAME);
355 de_unregister_exports();
362 gr_unregister_engine("de");
363 de_unregister_exports();