dthelp: Change to ANSI function definitions
[oweals/cde.git] / cde / programs / dtstyle / ColorEdit.c
index eeb32b389eff4261ea5a2201ef5cb1c1e2e9f932..9ba5ded7ac1241b72044088f69286c48f37a89ee 100644 (file)
@@ -16,7 +16,7 @@
  * details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with these librararies and programs; if not, write
+ * License along with these libraries and programs; if not, write
  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  * Floor, Boston, MA 02110-1301 USA
  */
@@ -44,6 +44,7 @@
 #include <X11/keysym.h>
 
 #include <math.h>
+#include <errno.h>
 
 #include <X11/Xlib.h>
 #include <Xm/MwmUtil.h>
@@ -187,6 +188,16 @@ ColorEditor(
        {
             edit.color_set = color_set;
            CopyPixelSet(&edit.oldButtonColor,edit.color_set);
+
+               /* update "old" button if necessary */
+               if(style.visualClass==TrueColor || style.visualClass==DirectColor){
+                       XtVaSetValues(edit.oldButton,
+                               XmNbackground,edit.color_set->bg.pixel,
+                               XmNarmColor,edit.color_set->bg.pixel,
+                               XmNforeground,edit.color_set->fg.pixel,
+                               XmNtopShadowColor,edit.color_set->ts.pixel,
+                               XmNbottomShadowColor,edit.color_set->bs.pixel,NULL);
+               }
            InitializeNewButton();
            SetScales(&edit.color_set->bg);
            XtManageChild(edit.DialogShell);
@@ -287,8 +298,17 @@ CreateColorEditor(
         XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
        sampleForm = XmCreateForm(sampleTB, "sampleForm", args, n);
        
-        /*   Create Old and New Buttons */
-        InitializeOldButton();
+        /* Create Old and New Buttons */
+               if(style.visualClass==TrueColor || style.visualClass==DirectColor){
+                       edit.oldButtonColor.bg.pixel = edit.color_set->bg.pixel;
+                       edit.oldButtonColor.fg.pixel = edit.color_set->fg.pixel;
+                       edit.oldButtonColor.sc.pixel = edit.color_set->sc.pixel;
+                       edit.oldButtonColor.bs.pixel = edit.color_set->bs.pixel;
+                       edit.oldButtonColor.ts.pixel = edit.color_set->ts.pixel;
+                       CopyPixelSet(&edit.oldButtonColor,edit.color_set);
+               }else{
+                       InitializeOldButton();
+               }
 
         if(!OldNewSame) {
           n=0;
@@ -973,7 +993,36 @@ GenerateColors( void )
         edit.color_set->bs.blue = 0;
     }
 
-    XStoreColors(style.display, style.colormap, colors, j );
+    if(style.visualClass==PseudoColor || style.visualClass==StaticColor)
+       {
+               XStoreColors(style.display, style.colormap, colors, j );
+       }
+       else if(style.visualClass==TrueColor || style.visualClass==DirectColor)
+       {
+               static unsigned long pixels[4];
+               static int count=0;
+
+               if(count){
+                       XFreeColors(style.display,style.colormap,pixels,count,0);
+                       count=0;
+               }
+
+               if(XAllocColor(style.display,style.colormap,&edit.color_set->fg))
+                       pixels[count++]=edit.color_set->fg.pixel;
+               if(XAllocColor(style.display,style.colormap,&edit.color_set->bg))
+                       pixels[count++]=edit.color_set->bg.pixel;
+               if(XAllocColor(style.display,style.colormap,&edit.color_set->ts))
+                       pixels[count++]=edit.color_set->ts.pixel;
+               if(XAllocColor(style.display,style.colormap,&edit.color_set->bs))
+                       pixels[count++]=edit.color_set->bs.pixel;
+
+               XtVaSetValues(edit.newButton,
+                       XmNbackground,edit.color_set->bg.pixel,
+                       XmNarmColor,edit.color_set->bg.pixel,
+                       XmNforeground,edit.color_set->fg.pixel,
+                       XmNtopShadowColor,edit.color_set->ts.pixel,
+                       XmNbottomShadowColor,edit.color_set->bs.pixel,NULL);
+       }
  }
 
 /************************************************************************
@@ -993,7 +1042,7 @@ changRGB_CB(
     reason_code = ((XmAnyCallbackStruct *)call_data)->reason;
     if ( reason_code == XmCR_VALUE_CHANGED || reason_code == XmCR_DRAG )
     {
-       color = (int) client_data;
+       color = (int) (intptr_t) client_data;
        value = ((XmScaleCallbackStruct *)call_data)->value;
 
        if (edit.current_scale == NONE)
@@ -1045,7 +1094,7 @@ changHSV_CB(
     reason_code = ((XmAnyCallbackStruct *)call_data)->reason;
     if ( reason_code == XmCR_VALUE_CHANGED || reason_code == XmCR_DRAG )
     {
-       scale = (int) client_data;
+       scale = (int) (intptr_t) client_data;
        value = ((XmScaleCallbackStruct *)call_data)->value;
 
        if (edit.current_scale == NONE)
@@ -1187,8 +1236,8 @@ CopyPixelSet(
 
        XtSetValues(edit.oldButton, args, n);
     }
-
-    XStoreColors(style.display, style.colormap, colors, j );
+       if(style.visualClass == PseudoColor || style.visualClass == GrayScale)
+               XStoreColors(style.display, style.colormap, colors, j );
 
 }
 
@@ -1682,7 +1731,9 @@ saveColorEdit(
         sprintf(bufr, "%s*colorEditDlg.x: %d\n", bufr, x);
         sprintf(bufr, "%s*colorEditDlg.y: %d\n", bufr, y);
         /*any other parameter you want to save goes here*/
-        write (fd, bufr, strlen(bufr));
+        if(-1 == write (fd, bufr, strlen(bufr))) {
+               perror(strerror(errno));
+       }
     }
 }