]> git.decadent.org.uk Git - ion3.git/blobdiff - de/style.c
Imported Upstream version 20090110
[ion3.git] / de / style.c
index cf44e4787f2748dc9decff94e9a5e500ec869b5f..d5debb9c6530b3b9925dddda292943c924ee86a2 100644 (file)
@@ -1,12 +1,9 @@
 /*
  * ion/de/style.c
  *
- * Copyright (c) Tuomo Valkonen 1999-2006
+ * Copyright (c) Tuomo Valkonen 1999-2009
  *
- * Ion is free software; you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
+ * See the included file LICENSE for details.
  */
 
 #include <string.h>
@@ -119,7 +116,7 @@ void destyle_create_tab_gcs(DEStyle *style)
 static DEStyle *styles=NULL;
 
 
-DEStyle *de_get_style(WRootWin *rootwin, const char *stylename)
+DEStyle *de_get_style(WRootWin *rootwin, const GrStyleSpec *spec)
 {
     DEStyle *style, *maxstyle=NULL;
     int score, maxscore=0;
@@ -127,7 +124,7 @@ DEStyle *de_get_style(WRootWin *rootwin, const char *stylename)
     for(style=styles; style!=NULL; style=style->next){
         if(style->rootwin!=rootwin)
             continue;
-        score=gr_stylespec_score(style->style, stylename);
+        score=gr_stylespec_score(&style->spec, spec);
         if(score>maxscore){
             maxstyle=style;
             maxscore=score;
@@ -160,8 +157,7 @@ void destyle_deinit(DEStyle *style)
     
     UNLINK_ITEM(styles, style, next, prev);
     
-    if(style->style!=NULL)
-        free(style->style);
+    gr_stylespec_unalloc(&style->spec);
     
     if(style->font!=NULL){
         de_free_font(style->font);
@@ -177,7 +173,7 @@ void destyle_deinit(DEStyle *style)
     if(style->extra_cgrps!=NULL)
         free(style->extra_cgrps);
     
-    extl_unref_table(style->data_table);
+    extl_unref_table(style->extras_table);
     
     XFreeGC(ioncore_g.dpy, style->normal_gc);
     
@@ -196,7 +192,7 @@ void destyle_deinit(DEStyle *style)
 }
 
 
-static void dump_style(DEStyle *style)
+void destyle_dump(DEStyle *style)
 {
     /* Allow the style still be used but get if off the list. */
     UNLINK_ITEM(styles, style, next, prev);
@@ -206,8 +202,7 @@ static void dump_style(DEStyle *style)
 
 bool destyle_init(DEStyle *style, WRootWin *rootwin, const char *name)
 {
-    style->style=scopy(name);
-    if(style->style==NULL)
+    if(!gr_stylespec_load(&style->spec, name))
         return FALSE;
     
     style->based_on=NULL;
@@ -222,18 +217,19 @@ bool destyle_init(DEStyle *style, WRootWin *rootwin, const char *name)
     style->border.hl=1;
     style->border.pad=1;
     style->border.style=DEBORDER_INLAID;
+    style->border.sides=DEBORDER_ALL;
 
     style->spacing=0;
     
     style->textalign=DEALIGN_CENTER;
 
     style->cgrp_alloced=FALSE;
-    style->cgrp.spec=NULL;
     style->cgrp.bg=DE_BLACK(rootwin);
     style->cgrp.pad=DE_BLACK(rootwin);
     style->cgrp.fg=DE_WHITE(rootwin);
     style->cgrp.hl=DE_WHITE(rootwin);
     style->cgrp.sh=DE_WHITE(rootwin);
+    gr_stylespec_init(&style->cgrp.spec);
     
     style->font=NULL;
     
@@ -242,7 +238,7 @@ bool destyle_init(DEStyle *style, WRootWin *rootwin, const char *name)
     style->n_extra_cgrps=0;
     style->extra_cgrps=NULL;
     
-    style->data_table=extl_table_none();
+    style->extras_table=extl_table_none();
     
     create_normal_gc(style, rootwin);
     
@@ -252,7 +248,7 @@ bool destyle_init(DEStyle *style, WRootWin *rootwin, const char *name)
 }
 
 
-static DEStyle *do_create_style(WRootWin *rootwin, const char *name)
+DEStyle *de_create_style(WRootWin *rootwin, const char *name)
 {
     DEStyle *style=ALLOC(DEStyle);
     if(style!=NULL){
@@ -265,32 +261,12 @@ static DEStyle *do_create_style(WRootWin *rootwin, const char *name)
 }
 
 
-DEStyle *de_create_style(WRootWin *rootwin, const char *name)
+void destyle_add(DEStyle *style)
 {
-    DEStyle *oldstyle, *style;
-
-    style=do_create_style(rootwin, name);
-    
-    if(style==NULL)
-        return NULL;
-    
-    for(oldstyle=styles; oldstyle!=NULL; oldstyle=oldstyle->next){
-        if(oldstyle->rootwin==rootwin && oldstyle->style!=NULL && 
-           strcmp(oldstyle->style, name)==0){
-            break;
-        }
-    }
-    
-    if(oldstyle!=NULL && !oldstyle->is_fallback)
-        dump_style(oldstyle);
-    
     LINK_ITEM_FIRST(styles, style, next, prev);
-    
-    return style;
 }
 
 
-
 /*EXTL_DOC
  * Clear all styles from drawing engine memory.
  */
@@ -301,7 +277,7 @@ void de_reset()
     for(style=styles; style!=NULL; style=next){
         next=style->next;
         if(!style->is_fallback)
-            dump_style(style);
+            destyle_dump(style);
     }
 }
 
@@ -312,10 +288,10 @@ void de_deinit_styles()
     for(style=styles; style!=NULL; style=next){
         next=style->next;
         if(style->usecount>1){
-            warn(TR("Style %s still in use [%d] but the module "
-                    "is being unloaded!"), style->style, style->usecount);
+            warn(TR("Style is still in use [%d] but the module "
+                    "is being unloaded!"), style->usecount);
         }
-        dump_style(style);
+        destyle_dump(style);
     }
 }