Button proper freeing/newing.
authorDave Foster <daf@minuslab.net>
Fri, 21 Sep 2007 02:36:52 +0000 (22:36 -0400)
committerMikael Magnusson <mikachu@comhem.se>
Sat, 12 Jan 2008 02:57:34 +0000 (03:57 +0100)
render/button.c
render/button.h
render/render.c
render/render.h

index 5d3f92035c72cae5448c8e806e2ed3443d6f26d4..399888dc8f389e546c29253ce380531c65945d96 100644 (file)
@@ -6,15 +6,12 @@
 #include <X11/Xutil.h>
 #include <string.h>
 
-static void RrButtonFreeReal(RrButton* b);
-
 RrButton *RrButtonNew (const RrInstance *inst)
 {
     RrButton *out = NULL;
 
     out = g_new(RrButton, 1);
     out->inst = inst;
-    out->ref = 1;
 
     /* no need to alloc colors, set them null (for freeing later) */
     out->focused_unpressed_color = NULL;
@@ -60,14 +57,7 @@ RrButton *RrButtonNew (const RrInstance *inst)
     return out;
 }
 
-void RrButtonFree(RrButton *b)
-{
-    b->ref--;
-    if (b->ref <= 0)
-        RrButtonFreeReal(b);
-}
-
-void RrButtonFreeReal(RrButton* b)
+void RrButtonFree(RrButton* b)
 {
     /* colors */
     if (b->focused_unpressed_color) 
@@ -100,4 +90,27 @@ void RrButtonFreeReal(RrButton* b)
         RrColorFree(b->toggled_unfocused_unpressed_color);
 
     /* masks */
+    if (mask) RrPixmapMaskFree(mask);
+    if (pressed_mask) RrPixmapMaskFree(pressed_mask);
+    if (disabled_mask) RrPixmapMaskFree(disabled_mask);
+    if (hover_mask) RrPixmapMaskFree(hover_mask);
+    if (toggled_mask) RrPixmapMaskFree(toggled_mask);
+    if (toggled_hover_mask) RrPixmapMaskFree(toggled_hover_mask);
+    if (toggled_pressed_mask) RrPixmapMaskFree(toggled_pressed_mask);
+
+    /* appearances */
+    RrAppearanceFree(a_focused_unpressed);
+    RrAppearanceFree(a_unfocused_unpressed);
+    RrAppearanceFree(a_focused_pressed);
+    RrAppearanceFree(a_unfocused_pressed);
+    RrAppearanceFree(a_disabled_focused);
+    RrAppearanceFree(a_disabled_unfocused);
+    RrAppearanceFree(a_hover_focused);
+    RrAppearanceFree(a_hover_unfocused);
+    RrAppearanceFree(a_toggled_focused_unpressed);
+    RrAppearanceFree(a_toggled_unfocused_unpressed);
+    RrAppearanceFree(a_toggled_focused_pressed);
+    RrAppearanceFree(a_toggled_unfocused_pressed);
+    RrAppearanceFree(a_toggled_hover_focused);
+    RrAppearanceFree(a_toggled_hover_unfocused);
 }
index 75459642145fa21f0258e3297cb3f1c11a035fb7..59d04f944c006416061e2c505c5f8d3a2a8f443d 100644 (file)
@@ -10,9 +10,6 @@
 struct _RrButton {
     const RrInstance *inst;
 
-    /* reference count */
-    gint ref;
-
     /* colors */
     RrColor *focused_unpressed_color;
     RrColor *unfocused_unpressed_color;
index c116162cc4c3e7f0f1f996fe8a65f8ef669b6fe6..63b7e4c8b993cb6735130563f361d0dcc6fa3cb9 100644 (file)
@@ -170,7 +170,6 @@ RrAppearance *RrAppearanceNew(const RrInstance *inst, gint numtex)
 
   out = g_new0(RrAppearance, 1);
   out->inst = inst;
-  out->ref = 1;
   out->textures = numtex;
   out->surface.bevel_light_adjust = 128;
   out->surface.bevel_dark_adjust = 64;
@@ -187,15 +186,6 @@ void RrAppearanceAddTextures(RrAppearance *a, gint numtex)
     if (numtex) a->texture = g_new0(RrTexture, numtex);
 }
 
-/* shallow copy means up the ref count and return it */
-RrAppearance *RrAppearanceCopyShallow(RrAppearance *orig)
-{
-    orig->ref++;
-    return orig;
-}
-
-/* deep copy of orig, means reset ref to 1 on copy
- * and copy each thing memwise. */
 RrAppearance *RrAppearanceCopy(RrAppearance *orig)
 {
     RrSurface *spo, *spc;
@@ -203,7 +193,6 @@ RrAppearance *RrAppearanceCopy(RrAppearance *orig)
     gint i;
 
     copy->inst = orig->inst;
-    copy->ref = 1;
 
     spo = &(orig->surface);
     spc = &(copy->surface);
@@ -294,11 +283,6 @@ void RrAppearanceFree(RrAppearance *a)
 
     if (!a) return;
 
-    /* decrement ref counter */
-    if (a->ref-- > 0) 
-        return;
-
-    /* if we're here we have no more refs to this appearance, free it */   
     RrSurface *p;
     if (a->pixmap != None) XFreePixmap(RrDisplay(a->inst), a->pixmap);
     if (a->xftdraw != NULL) XftDrawDestroy(a->xftdraw);
index f6475eaa401bb426bd75e9a2321319fedaca91de..c70f8cd21946015d7a958fa0bdaf2df60008da39 100644 (file)
@@ -191,8 +191,6 @@ struct _RrTexture {
 struct _RrAppearance {
     const RrInstance *inst;
     
-    gint ref;
-
     RrSurface surface;
     gint textures;
     RrTexture *texture;
@@ -246,7 +244,6 @@ gulong   RrColorPixel (const RrColor *c);
 GC       RrColorGC    (RrColor *c);
 
 RrAppearance *RrAppearanceNew  (const RrInstance *inst, gint numtex);
-RrAppearance *RrAppearanceCopyShallow (RrAppearance *a);
 RrAppearance *RrAppearanceCopy (RrAppearance *a);
 void          RrAppearanceFree (RrAppearance *a);
 void          RrAppearanceAddTextures(RrAppearance *a, gint numtex);