changeset 29700:1e88ad071a1a

(make_shadow_gcs): Set free_top_shadow_color_p and free_top_shadow_color_p flags in the menu widget if top and bottom shadow colors must be freed. (release_shadow_gcs): Free colors only if they must be freed.
author Gerd Moellmann <gerd@gnu.org>
date Fri, 16 Jun 2000 18:34:17 +0000
parents bb36becbd66b
children 3678f877d57f
files lwlib/xlwmenu.c
diffstat 1 files changed, 45 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/lwlib/xlwmenu.c	Fri Jun 16 18:33:58 2000 +0000
+++ b/lwlib/xlwmenu.c	Fri Jun 16 18:34:17 2000 +0000
@@ -1444,10 +1444,18 @@
   XColor topc, botc;
   int top_frobbed = 0, bottom_frobbed = 0;
 
+  mw->menu.free_top_shadow_color_p = 0;
+  mw->menu.free_bottom_shadow_color_p = 0;
+
   if (mw->menu.top_shadow_color == -1)
     mw->menu.top_shadow_color = mw->core.background_pixel;
+  else
+    mw->menu.top_shadow_color = mw->menu.top_shadow_color;
+    
   if (mw->menu.bottom_shadow_color == -1)
     mw->menu.bottom_shadow_color = mw->menu.foreground;
+  else
+    mw->menu.bottom_shadow_color = mw->menu.bottom_shadow_color;
 
   if (mw->menu.top_shadow_color == mw->core.background_pixel ||
       mw->menu.top_shadow_color == mw->menu.foreground)
@@ -1465,6 +1473,7 @@
 #endif
 	{
 	  mw->menu.top_shadow_color = topc.pixel;
+	  mw->menu.free_top_shadow_color_p = 1;
 	  top_frobbed = 1;
 	}
     }
@@ -1483,6 +1492,7 @@
 #endif
 	{
 	  mw->menu.bottom_shadow_color = botc.pixel;
+	  mw->menu.free_bottom_shadow_color_p = 1;
 	  bottom_frobbed = 1;
 	}
     }
@@ -1501,17 +1511,23 @@
 	{
 	  if (botc.pixel == mw->menu.foreground)
 	    {
-	      x_free_dpy_colors (dpy, screen, cmap,
-				 &mw->menu.top_shadow_color, 1);
-	      mw->menu.top_shadow_color
-		= x_copy_dpy_color (dpy, cmap, mw->core.background_pixel);
+	      if (mw->menu.free_top_shadow_color_p)
+		{
+		  x_free_dpy_colors (dpy, screen, cmap,
+				     &mw->menu.top_shadow_color, 1);
+		  mw->menu.free_top_shadow_color_p = 0;
+		}
+	      mw->menu.top_shadow_color = mw->core.background_pixel;
 	    }
 	  else
 	    {
-	      x_free_dpy_colors (dpy, screen, cmap,
-				 &mw->menu.bottom_shadow_color, 1);
-	      mw->menu.bottom_shadow_color
-		= x_copy_dpy_color (dpy, cmap, mw->menu.foreground);
+	      if (mw->menu.free_bottom_shadow_color_p)
+		{
+		  x_free_dpy_colors (dpy, screen, cmap,
+				     &mw->menu.bottom_shadow_color, 1);
+		  mw->menu.free_bottom_shadow_color_p = 0;
+		}
+	      mw->menu.bottom_shadow_color = mw->menu.foreground;
 	    }
 	}
     }
@@ -1520,20 +1536,24 @@
       mw->menu.top_shadow_color == mw->core.background_pixel)
     {
       mw->menu.top_shadow_pixmap = mw->menu.gray_pixmap;
-      if (top_frobbed)
-	x_free_dpy_colors (dpy, screen, cmap, &mw->menu.top_shadow_color, 1);
-      mw->menu.top_shadow_color = x_copy_dpy_color (dpy, cmap,
-						    mw->menu.foreground);
+      if (mw->menu.free_top_shadow_color_p)
+	{
+	  x_free_dpy_colors (dpy, screen, cmap, &mw->menu.top_shadow_color, 1);
+	  mw->menu.free_top_shadow_color_p = 0;
+	}
+      mw->menu.top_shadow_color = mw->menu.foreground;
     }
   if (!mw->menu.bottom_shadow_pixmap &&
       mw->menu.bottom_shadow_color == mw->core.background_pixel)
     {
       mw->menu.bottom_shadow_pixmap = mw->menu.gray_pixmap;
-      if (bottom_frobbed)
-	x_free_dpy_colors (dpy, screen, cmap,
-			   &mw->menu.bottom_shadow_color, 1);
-      mw->menu.bottom_shadow_color = x_copy_dpy_color (dpy, cmap,
-						       mw->menu.foreground);
+      if (mw->menu.free_bottom_shadow_color_p)
+	{
+	  x_free_dpy_colors (dpy, screen, cmap,
+			     &mw->menu.bottom_shadow_color, 1);
+	  mw->menu.free_bottom_shadow_color_p = 0;
+	}
+      mw->menu.bottom_shadow_color = mw->menu.foreground;
     }
 
   xgcv.fill_style = FillStippled;
@@ -1557,10 +1577,15 @@
   Screen *screen = XtScreen ((Widget) mw);
   Colormap cmap = mw->core.colormap;
   Pixel px[2];
+  int i = 0;
 
-  px[0] = mw->menu.top_shadow_color;
-  px[1] = mw->menu.bottom_shadow_color;
-  x_free_dpy_colors (dpy, screen, cmap, px, 2);
+  if (mw->menu.free_top_shadow_color_p)
+    px[i++] = mw->menu.top_shadow_color;
+  if (mw->menu.free_bottom_shadow_color_p)
+    px[i++] = mw->menu.bottom_shadow_color;
+  if (i > 0)
+    x_free_dpy_colors (dpy, screen, cmap, px, i);
+  
   XtReleaseGC ((Widget) mw, mw->menu.shadow_top_gc);
   XtReleaseGC ((Widget) mw, mw->menu.shadow_bottom_gc);
 }