]> git.decadent.org.uk Git - ion3.git/blobdiff - de/draw.c
[svn-upgrade] Integrating new upstream version, ion3 (20070506)
[ion3.git] / de / draw.c
index 40a2f8ffe02d257af6847cbbe97152ba8947f306..c48d49ab508dea40e56753aa74d07605ffa3297a 100644 (file)
--- a/de/draw.c
+++ b/de/draw.c
@@ -3,10 +3,7 @@
  *
  * Copyright (c) Tuomo Valkonen 1999-2007. 
  *
- * 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>
@@ -15,6 +12,7 @@
 #include <ioncore/global.h>
 #include <ioncore/common.h>
 #include <ioncore/gr.h>
+#include <ioncore/gr-util.h>
 #include "brush.h"
 #include "font.h"
 #include "private.h"
@@ -296,17 +294,43 @@ static void copy_masked(DEBrush *brush, Drawable src, Drawable dst,
 }
 
 
-static GrStyleSpec dragged_spec=GR_STYLESPEC_INIT;
-static GrStyleSpec tagged_spec=GR_STYLESPEC_INIT;
-static GrStyleSpec submenu_spec=GR_STYLESPEC_INIT;
+
+#define ISSET(S, A) ((S)!=NULL && gr_stylespec_isset(S, A))
+
+
+GR_DEFATTR(dragged);
+GR_DEFATTR(tagged);
+GR_DEFATTR(submenu);
+GR_DEFATTR(numbered);
+GR_DEFATTR(tabnumber);
+
+
+static void ensure_attrs()
+{
+    GR_ALLOCATTR_BEGIN;
+    GR_ALLOCATTR(dragged);
+    GR_ALLOCATTR(tagged);
+    GR_ALLOCATTR(submenu);
+    GR_ALLOCATTR(numbered);
+    GR_ALLOCATTR(tabnumber);
+    GR_ALLOCATTR_END;
+}
+
+
+static int get_ty(const WRectangle *g, const GrBorderWidths *bdw, 
+                  const GrFontExtents *fnte)
+{
+    return (g->y+bdw->top+fnte->baseline
+            +(g->h-bdw->top-bdw->bottom-fnte->max_height)/2);
+}
 
 
 void debrush_tab_extras(DEBrush *brush, const WRectangle *g, 
-                        DEColourGroup *cg, GrBorderWidths *bdw,
-                        GrFontExtents *fnte,
+                        DEColourGroup *cg, const GrBorderWidths *bdw,
+                        const GrFontExtents *fnte,
                         const GrStyleSpec *a1, 
                         const GrStyleSpec *a2,
-                        bool pre)
+                        bool pre, int index)
 {
     DEStyle *d=brush->d;
     GC tmp;
@@ -315,22 +339,55 @@ void debrush_tab_extras(DEBrush *brush, const WRectangle *g,
      */
     static bool swapped=FALSE;
 
-    ENSURE_INITSPEC(dragged_spec, "dragged");
-    ENSURE_INITSPEC(tagged_spec, "tagged");
+    ensure_attrs();
     
     if(pre){
-        if(!MATCHES2(dragged_spec, a1, a2))
-            return;
-        
-        tmp=d->normal_gc;
-        d->normal_gc=d->stipple_gc;
-        d->stipple_gc=tmp;
-        swapped=TRUE;
-        XClearArea(ioncore_g.dpy, brush->win, g->x, g->y, g->w, g->h, False);
+        if(ISSET(a2, GR_ATTR(dragged)) || ISSET(a1, GR_ATTR(dragged))){
+            tmp=d->normal_gc;
+            d->normal_gc=d->stipple_gc;
+            d->stipple_gc=tmp;
+            swapped=TRUE;
+            XClearArea(ioncore_g.dpy, brush->win, g->x, g->y, g->w, g->h, False);
+        }
         return;
     }
     
-    if(MATCHES2(tagged_spec, a1, a2)){
+    
+    if((ISSET(a1, GR_ATTR(numbered)) || ISSET(a2, GR_ATTR(numbered))) 
+       && index>=0){
+        
+        DEColourGroup *cg;
+        GrStyleSpec tmp;
+        
+        gr_stylespec_init(&tmp);
+        gr_stylespec_append(&tmp, a2);
+        gr_stylespec_set(&tmp, GR_ATTR(tabnumber));
+        
+        cg=debrush_get_colour_group2(brush, a1, &tmp);
+        
+        gr_stylespec_unalloc(&tmp);
+
+        if(cg!=NULL){
+            char *s=NULL;
+            
+            libtu_asprintf(&s, "[%d]", index+1);
+            
+            if(s!=NULL){
+                int l=strlen(s);
+                uint w=debrush_get_text_width(brush, s, l);
+                if(w < g->w-bdw->right-bdw->left){
+                    int ty=get_ty(g, bdw, fnte);
+                    int tx=(d->textalign==DEALIGN_RIGHT
+                            ? g->x+bdw->left
+                            : g->x+g->w-bdw->right-w);
+                    debrush_do_draw_string(brush, tx, ty, s, l, TRUE, cg);
+                }
+                free(s);
+            }
+        }
+    }
+    
+    if(ISSET(a2, GR_ATTR(tagged)) || ISSET(a1, GR_ATTR(tagged))){
         XSetForeground(ioncore_g.dpy, d->copy_gc, cg->fg);
             
         copy_masked(brush, d->tag_pixmap, brush->win, 0, 0,
@@ -338,7 +395,7 @@ void debrush_tab_extras(DEBrush *brush, const WRectangle *g,
                     g->x+g->w-bdw->right-d->tag_pixmap_w, 
                     g->y+bdw->top);
     }
-
+    
     if(swapped){
         tmp=d->normal_gc;
         d->normal_gc=d->stipple_gc;
@@ -355,28 +412,26 @@ void debrush_tab_extras(DEBrush *brush, const WRectangle *g,
 void debrush_menuentry_extras(DEBrush *brush, 
                               const WRectangle *g, 
                               DEColourGroup *cg, 
-                              GrBorderWidths *bdw,
-                              GrFontExtents *fnte,
+                              const GrBorderWidths *bdw,
+                              const GrFontExtents *fnte,
                               const GrStyleSpec *a1, 
                               const GrStyleSpec *a2, 
-                              bool pre)
+                              bool pre, int index)
 {
     int tx, ty;
 
     if(pre)
         return;
     
-    ENSURE_INITSPEC(submenu_spec, "submenu");
+    ensure_attrs();
     
-    if(!MATCHES2(submenu_spec, a1, a2))
-        return;
-        
-    ty=(g->y+bdw->top+fnte->baseline
-        +(g->h-bdw->top-bdw->bottom-fnte->max_height)/2);
-    tx=g->x+g->w-bdw->right;
+    if(ISSET(a2, GR_ATTR(submenu)) || ISSET(a1, GR_ATTR(submenu))){
+        ty=get_ty(g, bdw, fnte);
+        tx=g->x+g->w-bdw->right;
 
-    debrush_do_draw_string(brush, tx, ty, DE_SUB_IND, DE_SUB_IND_LEN, 
-                           FALSE, cg);
+        debrush_do_draw_string(brush, tx, ty, DE_SUB_IND, DE_SUB_IND_LEN, 
+                               FALSE, cg);
+    }
 }
 
 
@@ -401,7 +456,8 @@ static void debrush_do_draw_textbox(DEBrush *brush,
                                     DEColourGroup *cg, 
                                     bool needfill,
                                     const GrStyleSpec *a1, 
-                                    const GrStyleSpec *a2)
+                                    const GrStyleSpec *a2,
+                                    int index)
 {
     uint len;
     GrBorderWidths bdw;
@@ -412,7 +468,7 @@ static void debrush_do_draw_textbox(DEBrush *brush,
     grbrush_get_font_extents(&(brush->grbrush), &fnte);
     
     if(brush->extras_fn!=NULL)
-        brush->extras_fn(brush, geom, cg, &bdw, &fnte, a1, a2, TRUE);
+        brush->extras_fn(brush, geom, cg, &bdw, &fnte, a1, a2, TRUE, index);
     
     debrush_do_draw_box(brush, geom, cg, needfill);
     
@@ -436,14 +492,13 @@ static void debrush_do_draw_textbox(DEBrush *brush,
             tx=geom->x+bdw.left;
         }
         
-        ty=(geom->y+bdw.top+fnte.baseline
-            +(geom->h-bdw.top-bdw.bottom-fnte.max_height)/2);
+        ty=get_ty(geom, &bdw, &fnte);
         
         debrush_do_draw_string(brush, tx, ty, text, len, FALSE, cg);
     }while(0);
     
     if(brush->extras_fn!=NULL)
-        brush->extras_fn(brush, geom, cg, &bdw, &fnte, a1, a2, FALSE);
+        brush->extras_fn(brush, geom, cg, &bdw, &fnte, a1, a2, FALSE, index);
 }
 
 
@@ -455,7 +510,7 @@ void debrush_draw_textbox(DEBrush *brush, const WRectangle *geom,
     
     if(cg!=NULL){
         debrush_do_draw_textbox(brush, geom, text, cg, needfill, 
-                                attr, NULL);
+                                attr, NULL, -1);
     }
 }
 
@@ -480,7 +535,7 @@ void debrush_draw_textboxes(DEBrush *brush, const WRectangle *geom,
         
         if(cg!=NULL){
             debrush_do_draw_textbox(brush, &g, elem[i].text, cg, needfill,
-                                    common_attrib, &elem[i].attr);
+                                    common_attrib, &elem[i].attr, i);
         }
         
         if(i==n-1)