2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: ColorEdit.c /main/5 1995/10/30 13:08:03 rswiston $ */
24 /************************************<+>*************************************
25 ***************************************************************************
31 ** Description: Controls the Dtstyle Color Editor dialog
34 ** (c) Copyright Hewlett-Packard Company, 1990.
38 ****************************************************************************
39 ************************************<+>*************************************/
40 /* +++++++++++++++++++++++++++++++++++++++*/
42 /* +++++++++++++++++++++++++++++++++++++++*/
43 #include <X11/cursorfont.h>
44 #include <X11/keysym.h>
50 #include <Xm/MwmUtil.h>
53 #include <Xm/LabelG.h>
55 #include <Xm/PushBG.h>
58 #include <Xm/VendorSEP.h>
60 #include <Dt/DialogBox.h>
61 #include <Dt/TitleBox.h>
63 #include <Dt/UserMsg.h>
67 #include "ColorMain.h"
68 #include "ColorFile.h"
70 /*+++++++++++++++++++++++++++++++++++++++*/
71 /* include extern functions */
72 /*+++++++++++++++++++++++++++++++++++++++*/
73 #include "ColorEdit.h"
75 /*+++++++++++++++++++++++++++++++++++++++*/
77 /*+++++++++++++++++++++++++++++++++++++++*/
86 #define MAX_STR_LEN 128
88 #define SCALE_LEFT_POSITION 10
89 #define BUTTON_MARGIN 10
90 #define OLD_BUTTON_LEFT_POSITION 10
91 #define SCALE_WIDTH 300
93 #define SATURATION_BITS "Dtsatur"
94 #define VALUE_BITS "Dtvalue"
96 /*+++++++++++++++++++++++++++++++++++++++*/
97 /* Internal Functions */
98 /*+++++++++++++++++++++++++++++++++++++++*/
100 static void CreateColorEditor( Widget parent) ;
101 static void sliderLayoutCB(
103 XtPointer client_data,
104 XtPointer call_data) ;
105 static void InitializeNewButton( void ) ;
106 static void InitializeOldButton( void ) ;
107 static void GenerateColors( void ) ;
108 static Pixel GetPixel( Widget widget,
109 char *color_string ) ;
110 static void changRGB_CB(
112 XtPointer client_data,
113 XtPointer call_data) ;
114 static void changHSV_CB(
116 XtPointer client_data,
117 XtPointer call_data) ;
118 static void SetScales( XColor *rgb) ;
119 static void SetRGBHSVScales(
124 static void CopyPixelSet(
125 ColorSet *color_set_dest,
126 ColorSet *color_set_src) ;
127 static void HSVtoRGB(
142 static void grabcolorCB(
144 XtPointer client_data,
145 XtPointer call_data) ;
146 static void dialogBoxCB(
148 XtPointer client_data,
149 XtPointer call_data) ;
150 static void _DtmapCB(
152 XtPointer client_data,
153 XtPointer call_data) ;
156 /*+++++++++++++++++++++++++++++++++++++++*/
157 /* Global Variables */
158 /*+++++++++++++++++++++++++++++++++++++++*/
161 /*+++++++++++++++++++++++++++++++++++++++*/
162 /* Internal Variables */
163 /*+++++++++++++++++++++++++++++++++++++++*/
164 static saveRestore save = {FALSE, 0, };
165 static OldNewSame = False;
167 /************************************************************************
168 * ColorEditor() - Create ColorEditor dialog first time up.
169 * If has already been created, set up oldButton and newButton
170 * colors, set the scale values for the new color and manage
172 ************************************************************************/
176 ColorSet *color_set )
178 if (edit.DialogShell == NULL)
180 _DtTurnOnHourGlass(parent);
181 edit.color_set = color_set;
182 CreateColorEditor(parent);
183 _DtTurnOffHourGlass(parent);
187 if (!XtIsManaged(edit.DialogShell))
189 edit.color_set = color_set;
190 CopyPixelSet(&edit.oldButtonColor,edit.color_set);
192 /* update "old" button if necessary */
193 if(style.visualClass==TrueColor || style.visualClass==DirectColor){
194 XtVaSetValues(edit.oldButton,
195 XmNbackground,edit.color_set->bg.pixel,
196 XmNarmColor,edit.color_set->bg.pixel,
197 XmNforeground,edit.color_set->fg.pixel,
198 XmNtopShadowColor,edit.color_set->ts.pixel,
199 XmNbottomShadowColor,edit.color_set->bs.pixel,NULL);
201 InitializeNewButton();
202 SetScales(&edit.color_set->bg);
203 XtManageChild(edit.DialogShell);
204 XMapRaised(style.display, XtWindow(edit.DialogShell));
210 /************************************************************************
211 * CreateColorEditor()
212 * Create the Color Editor Dialog
213 ************************************************************************/
223 XmString string; /* temp Xm string */
224 Widget widgetlist1[10]; /* main_form */
225 Widget widgetlist2[16]; /* sliderForm */
226 Widget widgetlist3[10]; /* sampleForm */
227 int widget_count1 = 0;
228 int widget_count2 = 0;
229 int widget_count3 = 0;
230 XmString button_string[NUM_LABELS];
231 Pixel foreground, background;
234 Dimension w, width_old, width_new;
236 edit.current_scale = NONE;
238 /* Set up DialogBox button labels. */
239 button_string[0] = CMPSTR((String) _DtOkString);
240 button_string[1] = CMPSTR((String) _DtCancelString);
241 button_string[2] = CMPSTR((String) _DtHelpString);
243 /* Note that save.poscnt has been initialized elsewhere.
244 * save.posArgs may contain information from restoreColorEdit(). */
246 XtSetArg(args[save.poscnt], XmNchildType, XmWORK_AREA); save.poscnt++;
247 XtSetArg(save.posArgs[save.poscnt], XmNbuttonCount, NUM_LABELS);
249 XtSetArg(save.posArgs[save.poscnt], XmNbuttonLabelStrings,
252 XtSetArg(save.posArgs[save.poscnt], XmNdefaultPosition, False);
254 edit.DialogShell = __DtCreateDialogBoxDialog(parent,"colorEditDlg",
255 save.posArgs, save.poscnt);
256 XtAddCallback(edit.DialogShell, XmNmapCallback, sliderLayoutCB, NULL);
257 XtAddCallback(edit.DialogShell, XmNcallback, dialogBoxCB, NULL);
258 XtAddCallback(edit.DialogShell, XmNmapCallback, _DtmapCB, parent);
259 XtAddCallback(edit.DialogShell, XmNhelpCallback,
260 (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_MODIFY_PALETTE_DIALOG);
262 XmStringFree(button_string[0]);
263 XmStringFree(button_string[1]);
264 XmStringFree(button_string[2]);
266 widgetlist1[0] = _DtDialogBoxGetButton(edit.DialogShell,2);
269 XtSetArg(args[n], XmNautoUnmanage, False); n++;
270 XtSetArg(args[n], XmNcancelButton, widgetlist1[0]); n++;
271 XtSetValues (edit.DialogShell, args, n);
274 XtSetArg (args[n], XmNtitle, ((char *)GETMESSAGE(17, 16, "Style Manager - Modify Color"))); n++;
275 XtSetArg (args[n], XmNuseAsyncGeometry, True); n++;
276 XtSetArg(args[n], XmNmwmFunctions, DIALOG_MWM_FUNC); n++;
277 XtSetValues (XtParent(edit.DialogShell), args, n);
280 XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
281 XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
282 edit.main_form = XmCreateForm(edit.DialogShell, "main_form", args, n);
285 XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
286 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
287 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
288 XtSetArg (args[n], XmNmarginWidth, 0); n++;
289 XtSetArg (args[n], XmNmarginHeight, 0); n++;
290 string = CMPSTR(((char *)GETMESSAGE(17, 4, "Color Sample")));
291 XtSetArg (args[n], XmNtitleString, string); n++;
292 sampleTB = _DtCreateTitleBox(edit.main_form, "sampleTB", args, n);
293 widgetlist1[widget_count1++] = sampleTB;
294 XmStringFree(string);
297 XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
298 XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
299 sampleForm = XmCreateForm(sampleTB, "sampleForm", args, n);
301 /* Create Old and New Buttons */
302 if(style.visualClass==TrueColor || style.visualClass==DirectColor){
303 edit.oldButtonColor.bg.pixel = edit.color_set->bg.pixel;
304 edit.oldButtonColor.fg.pixel = edit.color_set->fg.pixel;
305 edit.oldButtonColor.sc.pixel = edit.color_set->sc.pixel;
306 edit.oldButtonColor.bs.pixel = edit.color_set->bs.pixel;
307 edit.oldButtonColor.ts.pixel = edit.color_set->ts.pixel;
308 CopyPixelSet(&edit.oldButtonColor,edit.color_set);
310 InitializeOldButton();
315 string = CMPSTR(((char *)GETMESSAGE(17, 5, "Old")));
316 XtSetArg(args[n], XmNlabelString, string); n++;
317 XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
318 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
319 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
320 /* Set the old button color to the color of the selected button */
321 XtSetArg(args[n], XmNforeground, edit.oldButtonColor.fg.pixel); n++;
322 XtSetArg(args[n], XmNbackground, edit.oldButtonColor.bg.pixel); n++;
323 XtSetArg(args[n], XmNarmColor, edit.oldButtonColor.sc.pixel); n++;
324 XtSetArg(args[n], XmNtopShadowColor,
325 edit.oldButtonColor.ts.pixel); n++;
326 XtSetArg(args[n], XmNbottomShadowColor,
327 edit.oldButtonColor.bs.pixel); n++;
330 XmCreatePushButton(sampleForm, "oldButton", args, n);
331 widgetlist3[widget_count3++] = edit.oldButton;
332 XmStringFree(string);
335 string = CMPSTR(((char *)GETMESSAGE(17, 6, "New")));
337 XtSetArg(args[n], XmNlabelString, string); n++;
338 XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
340 XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
341 XtSetArg (args[n], XmNleftWidget, edit.oldButton); n++;
344 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
346 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
347 edit.newButton = XmCreatePushButton(sampleForm, "newButton", args, n);
348 widgetlist3[widget_count3++] = edit.newButton;
349 XmStringFree(string);
353 /* make old and new button both the size of the larger of the two */
354 width_old = XtWidth(edit.oldButton);
355 width_new = XtWidth(edit.newButton);
356 w = (width_old>width_new) ? width_old : width_new;
359 XtSetArg (args[n], XmNrecomputeSize, False); n++;
360 XtSetArg (args[n], XmNwidth, w+2*BUTTON_MARGIN); n++;
361 XtSetArg (args[n], XmNheight, w+2*BUTTON_MARGIN); n++;
362 XtSetValues(edit.oldButton, args, n);
363 XtSetValues(edit.newButton, args, n);
367 w = XtWidth(edit.newButton);
370 XtSetArg (args[n], XmNrecomputeSize, False); n++;
371 XtSetArg (args[n], XmNwidth, w+2*BUTTON_MARGIN); n++;
372 XtSetArg (args[n], XmNheight, w+2*BUTTON_MARGIN); n++;
373 XtSetValues(edit.newButton, args, n);
377 InitializeNewButton();
380 string = CMPSTR(((char *)GETMESSAGE(17, 7, "Grab Color")));
381 XtSetArg(args[n], XmNlabelString, string); n++;
382 XtSetArg(args[n], XmNnavigationType, XmTAB_GROUP); n++;
383 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
384 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
385 XtSetArg(args[n], XmNmarginHeight, LB_MARGIN_HEIGHT); n++;
386 XtSetArg(args[n], XmNmarginWidth, LB_MARGIN_WIDTH); n++;
387 edit.grabColor = XmCreatePushButtonGadget(sampleForm, "grabColor", args, n);
388 widgetlist3[widget_count3++] = edit.grabColor;
389 XtAddCallback(edit.grabColor, XmNactivateCallback,
390 grabcolorCB, (XtPointer)NULL);
391 XmStringFree(string);
393 /* Create frame for RGB/HSV scales */
395 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
396 XtSetArg(args[n], XmNtopWidget, sampleTB); n++;
397 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
398 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
399 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
400 XtSetArg (args[n], XmNmarginWidth, 0); n++;
401 XtSetArg (args[n], XmNmarginHeight, 0); n++;
402 string = CMPSTR(((char *)GETMESSAGE(17, 8, "Color Editor")));
403 XtSetArg (args[n], XmNtitleString, string); n++;
404 sliderTB = _DtCreateTitleBox(edit.main_form, "sliderTB", args, n);
405 widgetlist1[widget_count1++] = sliderTB;
406 XmStringFree(string);
409 XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
410 XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
411 edit.sliderForm = XmCreateForm(sliderTB, "sliderForm", args, n);
414 * Create Hue label and scale
418 string = CMPSTR(((char *)GETMESSAGE(17, 9, "Hue")));
419 XtSetArg(args[n], XmNlabelString, string); n++;
420 edit.hueLabel = XmCreateLabelGadget(edit.sliderForm, "hueLabel", args, n);
421 widgetlist2[widget_count2++] = edit.hueLabel;
422 XmStringFree(string);
425 XtSetArg(args[n], XmNshowValue, TRUE); n++;
426 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
427 XtSetArg(args[n], XmNprocessingDirection, XmMAX_ON_BOTTOM); n++;
428 XtSetArg(args[n], XmNhighlightThickness, SCALE_HIGHLIGHT_THICKNESS); n++;
429 XtSetArg(args[n], XmNmaximum, 359); n++;
430 XtSetArg(args[n], XmNminimum, 0x0); n++;
431 XtSetArg(args[n], XmNincrement, 1); n++;
432 edit.hueScale = XmCreateScale(edit.sliderForm, "hueScale", args, n);
433 widgetlist2[widget_count2++] = edit.hueScale;
434 XtAddCallback(edit.hueScale, XmNvalueChangedCallback, changHSV_CB, (XtPointer) HUE);
435 XtAddCallback(edit.hueScale, XmNdragCallback, changHSV_CB, (XtPointer) HUE );
441 string = CMPSTR(((char *)GETMESSAGE(17, 10, "R")));
443 XtSetArg(args[n], XmNalignment, XmALIGNMENT_END); n++;
444 XtSetArg(args[n], XmNlabelString, string); n++;
445 XtSetArg(args[n], XmNmarginHeight, 0); n++;
446 edit.redLabel = XmCreateLabelGadget(edit.sliderForm, "redLabel", args, n);
447 widgetlist2[widget_count2++] = edit.redLabel;
448 XmStringFree(string);
450 string = CMPSTR(((char *)GETMESSAGE(17, 11, "G")));
452 XtSetArg(args[n], XmNalignment, XmALIGNMENT_END); n++;
453 XtSetArg(args[n], XmNlabelString, string); n++;
454 XtSetArg(args[n], XmNmarginHeight, 0); n++;
455 edit.greenLabel = XmCreateLabelGadget(edit.sliderForm, "greenLabel", args, n);
456 widgetlist2[widget_count2++] = edit.greenLabel;
457 XmStringFree(string);
459 string = CMPSTR(((char *)GETMESSAGE(17, 12, "B")));
461 XtSetArg(args[n], XmNalignment, XmALIGNMENT_END); n++;
462 XtSetArg(args[n], XmNlabelString, string); n++;
463 XtSetArg(args[n], XmNmarginHeight, 0); n++;
464 edit.blueLabel = XmCreateLabelGadget(edit.sliderForm, "blueLabel", args, n);
465 widgetlist2[widget_count2++] = edit.blueLabel;
466 XmStringFree(string);
469 XtSetArg(args[n], XmNshowValue, TRUE); n++;
470 XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
471 XtSetArg(args[n], XmNprocessingDirection, XmMAX_ON_RIGHT); n++;
472 XtSetArg(args[n], XmNhighlightThickness, SCALE_HIGHLIGHT_THICKNESS); n++;
473 XtSetArg(args[n], XmNmaximum, 0xff); n++;
474 XtSetArg(args[n], XmNminimum, 0x0); n++;
475 XtSetArg(args[n], XmNincrement, 1); n++;
476 XtSetArg(args[n], XmNscaleWidth, SCALE_WIDTH); n++;
477 widgetlist2[widget_count2++] = edit.redScale =
478 XmCreateScale(edit.sliderForm, "redScale", args, n);
479 XtAddCallback(edit.redScale, XmNvalueChangedCallback, changRGB_CB, (XtPointer) RED);
480 XtAddCallback(edit.redScale, XmNdragCallback, changRGB_CB, (XtPointer) RED );
482 widgetlist2[widget_count2++] = edit.greenScale =
483 XmCreateScale(edit.sliderForm, "greenScale", args, n);
484 XtAddCallback(edit.greenScale, XmNvalueChangedCallback, changRGB_CB, (XtPointer) GREEN );
485 XtAddCallback(edit.greenScale, XmNdragCallback, changRGB_CB, (XtPointer) GREEN );
487 widgetlist2[widget_count2++] = edit.blueScale =
488 XmCreateScale(edit.sliderForm, "blueScale", args, n);
489 XtAddCallback(edit.blueScale, XmNvalueChangedCallback, changRGB_CB, (XtPointer) BLUE );
490 XtAddCallback(edit.blueScale, XmNdragCallback, changRGB_CB, (XtPointer) BLUE);
496 /* create Saturation pixmap */
498 XtSetArg(args[n], XmNforeground, &foreground); n++;
499 XtSetArg(args[n], XmNbackground, &background); n++;
500 XtGetValues(edit.sliderForm, args, n);
503 XtSetArg(args[n], XmNalignment, XmALIGNMENT_END); n++;
504 XtSetArg(args[n], XmNlabelType, XmPIXMAP); n++;
505 XtSetArg(args[n], XmNlabelPixmap, XmGetPixmap(style.screen, SATURATION_BITS,
506 foreground, background)); n++;
507 XtSetArg(args[n], XmNmarginHeight, 3); n++;
508 edit.satLabel = XmCreateLabelGadget(edit.sliderForm, "satLabel", args, n);
509 widgetlist2[widget_count2++] = edit.satLabel;
511 /* create Value pixmap */
513 XtSetArg(args[n], XmNalignment, XmALIGNMENT_END); n++;
514 XtSetArg(args[n], XmNlabelType, XmPIXMAP); n++;
515 XtSetArg(args[n], XmNlabelPixmap, XmGetPixmap(style.screen, VALUE_BITS,
516 foreground, background)); n++;
517 XtSetArg(args[n], XmNmarginHeight, 3); n++;
518 edit.valLabel = XmCreateLabelGadget(edit.sliderForm, "valLabel", args, n);
519 widgetlist2[widget_count2++] = edit.valLabel;
522 XtSetArg(args[n], XmNshowValue, TRUE); n++;
523 XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
524 XtSetArg(args[n], XmNprocessingDirection, XmMAX_ON_RIGHT); n++;
525 XtSetArg(args[n], XmNhighlightThickness, SCALE_HIGHLIGHT_THICKNESS); n++;
526 XtSetArg(args[n], XmNmaximum, 0xff); n++;
527 XtSetArg(args[n], XmNminimum, 0x0); n++;
528 XtSetArg(args[n], XmNincrement, 1); n++;
529 XtSetArg(args[n], XmNscaleWidth, SCALE_WIDTH); n++;
530 widgetlist2[widget_count2++] = edit.satScale =
531 XmCreateScale(edit.sliderForm, "satScale", args, n);
532 XtAddCallback(edit.satScale, XmNvalueChangedCallback, changHSV_CB, (XtPointer) SATURATION);
533 XtAddCallback(edit.satScale, XmNdragCallback, changHSV_CB, (XtPointer) SATURATION );
535 widgetlist2[widget_count2++] = edit.valScale =
536 XmCreateScale(edit.sliderForm, "valScale", args, n);
537 XtAddCallback(edit.valScale, XmNvalueChangedCallback, changHSV_CB, (XtPointer) VALUE);
538 XtAddCallback(edit.valScale, XmNdragCallback, changHSV_CB, (XtPointer) VALUE );
540 /* Set the scales to the bg component of the selected color */
541 SetScales(&edit.color_set->bg);
543 /* Do all the mapping */
545 XtManageChildren(widgetlist3, widget_count3);
546 XtManageChild(sampleForm);
548 XtManageChildren(widgetlist2, widget_count2);
549 XtManageChild(edit.sliderForm);
551 XtManageChildren(widgetlist1, widget_count1);
552 XtManageChild(edit.main_form);
554 XtManageChild(edit.DialogShell);
556 if(TypeOfMonitor == XmCO_HIGH_COLOR)
558 /* set the trough colors of the RGB scales -
559 get the composite children of the scales -
560 child[1] is the scrollbar */
562 XtSetArg(args[n], XtNchildren, &children); n++;
563 XtGetValues(edit.redScale, args, n);
565 XtSetArg(args[n], XmNtroughColor, GetPixel(edit.main_form,"red")); n++;
566 XtSetValues (children[1], args, n);
569 XtSetArg(args[n], XtNchildren, &children); n++;
570 XtGetValues(edit.greenScale, args, n);
572 XtSetArg(args[n], XmNtroughColor, GetPixel(edit.main_form,"green")); n++;
573 XtSetValues (children[1], args, n);
576 XtSetArg(args[n], XtNchildren, &children); n++;
577 XtGetValues(edit.blueScale, args, n);
579 XtSetArg(args[n], XmNtroughColor, GetPixel(edit.main_form,"blue")); n++;
580 XtSetValues (children[1], args, n);
589 XtPointer client_data,
590 XtPointer call_data )
594 Dimension redLabelWidth;
595 Dimension greenLabelWidth;
596 Dimension blueLabelWidth;
597 Dimension satLabelWidth;
598 Dimension valLabelWidth;
599 Dimension MaxLabelWidth;
600 Dimension redLabelHeight;
601 Dimension satLabelHeight;
602 Dimension valLabelHeight;
603 Dimension redScaleHeight;
605 Dimension scale_width;
610 * Do the scale and label attachments
613 redLabelHeight = XtHeight(edit.redLabel);
614 MaxLabelWidth = redLabelWidth = XtWidth(edit.redLabel);
616 greenLabelWidth = XtWidth(edit.greenLabel);
617 if (greenLabelWidth > MaxLabelWidth)
619 MaxLabelWidth = greenLabelWidth;
622 blueLabelWidth = XtWidth(edit.blueLabel);
623 if (blueLabelWidth > MaxLabelWidth)
625 MaxLabelWidth = blueLabelWidth;
628 satLabelHeight = XtHeight(edit.satLabel);
629 satLabelWidth = XtWidth(edit.satLabel);
630 if (satLabelWidth > MaxLabelWidth)
632 MaxLabelWidth = satLabelWidth;
635 valLabelHeight = XtHeight(edit.valLabel);
636 valLabelWidth = XtWidth(edit.valLabel);
637 if (valLabelWidth > MaxLabelWidth)
639 MaxLabelWidth = valLabelWidth;
642 redScaleHeight = XtHeight(edit.redScale);
645 /* Attach grab button to New button if they are overlapping */
648 pieces = XtWidth(edit.oldButton) +
649 XtWidth(edit.newButton) +
650 XtWidth(edit.grabColor) +
651 4*style.horizontalSpacing;
653 pieces = XtWidth(edit.newButton) +
654 XtWidth(edit.grabColor) +
655 3*style.horizontalSpacing;
657 if (XtWidth(edit.main_form) < pieces)
660 XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
661 XtSetArg(args[n], XmNleftWidget, edit.newButton); n++;
662 XtSetValues (edit.grabColor, args, n);
664 scale_width = XtWidth(edit.main_form) - MaxLabelWidth -
665 XtWidth(edit.hueScale) - 4*style.horizontalSpacing;
668 XtSetArg(args[n], XmNscaleWidth, scale_width); n++;
669 XtSetValues (edit.redScale, args, n);
670 XtSetValues (edit.greenScale, args, n);
671 XtSetValues (edit.blueScale, args, n);
672 XtSetValues (edit.satScale, args, n);
673 XtSetValues (edit.valScale, args, n);
678 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
679 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
680 XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
681 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
682 XtSetValues (edit.hueLabel, args, n);
686 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
687 XtSetArg(args[n], XmNtopWidget, edit.hueLabel); n++;
688 XtSetArg(args[n], XmNtopOffset, style.verticalSpacing); n++;
689 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
690 XtSetArg(args[n], XmNbottomOffset,
691 2*(style.verticalSpacing + redScaleHeight) + 40); n++;
692 XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
693 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
694 XtSetValues (edit.hueScale, args, n);
698 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
699 XtSetArg(args[n], XmNtopWidget, edit.hueLabel); n++;
700 TopOffset = style.verticalSpacing + redScaleHeight - redLabelHeight;
701 XtSetArg(args[n], XmNtopOffset, TopOffset); n++;
702 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
703 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
704 XtSetArg(args[n], XmNleftOffset,
705 style.horizontalSpacing + (MaxLabelWidth - redLabelWidth)); n++;
706 XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
707 XtSetValues (edit.redLabel, args, n);
711 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
712 XtSetArg(args[n], XmNtopWidget, edit.redLabel); n++;
713 XtSetArg(args[n], XmNtopOffset, TopOffset); n++;
714 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
715 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
716 XtSetArg(args[n], XmNleftOffset,
717 style.horizontalSpacing + (MaxLabelWidth - greenLabelWidth)); n++;
718 XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
719 XtSetValues (edit.greenLabel, args, n);
723 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
724 XtSetArg(args[n], XmNtopWidget, edit.greenLabel); n++;
725 XtSetArg(args[n], XmNtopOffset, TopOffset); n++;
726 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
727 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
728 XtSetArg(args[n], XmNleftOffset,
729 style.horizontalSpacing + (MaxLabelWidth - blueLabelWidth)); n++;
730 XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
731 XtSetValues (edit.blueLabel, args, n);
733 /* Saturation Label */
735 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
736 XtSetArg(args[n], XmNtopWidget, edit.blueLabel); n++;
737 TopOffset = style.verticalSpacing + 40 + redScaleHeight - satLabelHeight;
738 XtSetArg(args[n], XmNtopOffset, TopOffset); n++;
739 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
740 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
741 XtSetArg(args[n], XmNleftOffset,
742 style.horizontalSpacing + (MaxLabelWidth - satLabelWidth)); n++;
743 XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
744 XtSetValues (edit.satLabel, args, n);
748 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
749 XtSetArg(args[n], XmNtopWidget, edit.satLabel); n++;
750 TopOffset = style.verticalSpacing + redScaleHeight - valLabelHeight;
751 XtSetArg(args[n], XmNtopOffset, TopOffset); n++;
752 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
753 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
754 XtSetArg(args[n], XmNleftOffset,
755 style.horizontalSpacing + (MaxLabelWidth - valLabelWidth)); n++;
756 XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
757 XtSetValues (edit.valLabel, args, n);
761 XtSetArg(args[n], XmNtopAttachment, XmATTACH_NONE); n++;
762 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
763 XtSetArg(args[n], XmNbottomWidget, edit.redLabel); n++;
764 XtSetArg(args[n], XmNbottomOffset, 0); n++;
765 XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
766 XtSetArg(args[n], XmNleftWidget, edit.redLabel); n++;
767 XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
768 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
769 XtSetArg(args[n], XmNrightWidget, edit.hueScale); n++;
770 XtSetValues (edit.redScale, args, n);
774 XtSetArg(args[n], XmNtopAttachment, XmATTACH_NONE); n++;
775 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
776 XtSetArg(args[n], XmNbottomWidget, edit.greenLabel); n++;
777 XtSetArg(args[n], XmNbottomOffset, 0); n++;
778 XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
779 XtSetArg(args[n], XmNleftWidget, edit.redLabel); n++;
780 XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
781 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
782 XtSetArg(args[n], XmNrightWidget, edit.hueScale); n++;
783 XtSetValues (edit.greenScale, args, n);
787 XtSetArg(args[n], XmNtopAttachment, XmATTACH_NONE); n++;
788 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
789 XtSetArg(args[n], XmNbottomWidget, edit.blueLabel); n++;
790 XtSetArg(args[n], XmNbottomOffset, 0); n++;
791 XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
792 XtSetArg(args[n], XmNleftWidget, edit.redLabel); n++;
793 XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
794 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
795 XtSetArg(args[n], XmNrightWidget, edit.hueScale); n++;
796 XtSetValues (edit.blueScale, args, n);
798 /* Saturation Scale */
800 XtSetArg(args[n], XmNtopAttachment, XmATTACH_NONE); n++;
801 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
802 XtSetArg(args[n], XmNbottomWidget, edit.satLabel); n++;
803 XtSetArg(args[n], XmNbottomOffset, 0); n++;
804 XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
805 XtSetArg(args[n], XmNleftWidget, edit.redLabel); n++;
806 XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
807 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
808 XtSetArg(args[n], XmNrightWidget, edit.hueScale); n++;
809 XtSetValues (edit.satScale, args, n);
813 XtSetArg(args[n], XmNtopAttachment, XmATTACH_NONE); n++;
814 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
815 XtSetArg(args[n], XmNbottomWidget, edit.valLabel); n++;
816 XtSetArg(args[n], XmNbottomOffset, 0); n++;
817 XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
818 XtSetArg(args[n], XmNleftWidget, edit.redLabel); n++;
819 XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
820 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
821 XtSetArg(args[n], XmNrightWidget, edit.hueScale); n++;
822 XtSetValues (edit.valScale, args, n);
824 XtRemoveCallback(edit.DialogShell, XmNmapCallback, sliderLayoutCB, NULL);
829 /************************************************************************
830 * InitializeNewButton()
831 * set NewButton colors to point to the PixelSet being
832 * modified so they both get updated.
833 ************************************************************************/
835 InitializeNewButton( void )
841 XtSetArg(args[n], XmNforeground, edit.color_set->fg.pixel); n++;
842 XtSetArg(args[n], XmNbackground, edit.color_set->bg.pixel); n++;
843 XtSetArg(args[n], XmNarmColor, edit.color_set->sc.pixel); n++;
844 if(UsePixmaps == FALSE)
846 XtSetArg(args[n], XmNtopShadowColor,
847 edit.color_set->ts.pixel); n++;
848 XtSetArg(args[n], XmNbottomShadowColor,
849 edit.color_set->bs.pixel); n++;
851 XtSetValues(edit.newButton,args,n);
855 /************************************************************************
856 * InitializeOldButton()
857 * Called only once from CreateColorEditor. Allocates a
858 * new PixelSet to hold onto the original ColorSet values
859 * while the newButton gets updated. Shouldn't be called if
861 ************************************************************************/
863 InitializeOldButton( void )
865 register int i,n, numOfPixels;
866 unsigned long *pixels;
867 unsigned long plane_mask;
868 int hue, val, sat, status;
870 if(UsePixmaps == FALSE)
871 if(FgColor == DYNAMIC)
873 else /* FgColor == BLACK or WHITE */
875 else /* UsePixmaps == TRUE */
876 if(FgColor == DYNAMIC)
878 else /* FgColor == BLACK or WHITE */
881 /* Allocate enough space to store numOfPixels. */
882 pixels = (unsigned long *)XtMalloc (numOfPixels * sizeof (unsigned long));
884 /* Allocate new color cells for the new button */
885 status = XAllocColorCells (style.display, style.colormap,
886 0, &plane_mask, 0, pixels, numOfPixels);
890 /* Dialog stating that can't allocate enough pixels to color
891 the old button. Just don't create old button.*/
892 edit.oldButtonColor.bg.pixel = edit.color_set->bg.pixel;
893 edit.oldButtonColor.bg.flags = edit.color_set->bg.flags;
894 edit.oldButtonColor.fg.pixel = edit.color_set->fg.pixel;
895 edit.oldButtonColor.fg.flags = edit.color_set->fg.flags;
896 edit.oldButtonColor.sc.pixel = edit.color_set->sc.pixel;
897 edit.oldButtonColor.sc.flags = edit.color_set->sc.flags;
898 edit.oldButtonColor.bs.pixel = edit.color_set->bs.pixel;
899 edit.oldButtonColor.bs.flags = edit.color_set->bs.flags;
900 edit.oldButtonColor.ts.pixel = edit.color_set->ts.pixel;
901 edit.oldButtonColor.ts.flags = edit.color_set->ts.flags;
907 /* Assign the pixels */
909 edit.oldButtonColor.bg.pixel = pixels[n++];
910 edit.oldButtonColor.bg.flags = DoRed | DoGreen | DoBlue;
911 edit.oldButtonColor.sc.pixel = pixels[n++];
912 edit.oldButtonColor.sc.flags = DoRed | DoGreen | DoBlue;
913 if(FgColor == DYNAMIC)
915 edit.oldButtonColor.fg.pixel = pixels[n++];
916 edit.oldButtonColor.fg.flags = DoRed | DoGreen | DoBlue;
920 edit.oldButtonColor.fg.pixel = edit.color_set->fg.pixel;
921 edit.oldButtonColor.fg.flags = edit.color_set->fg.flags;
923 if(UsePixmaps == FALSE)
925 edit.oldButtonColor.bs.pixel = pixels[n++];
926 edit.oldButtonColor.bs.flags = DoRed | DoGreen | DoBlue;
927 edit.oldButtonColor.ts.pixel = pixels[n];
928 edit.oldButtonColor.ts.flags = DoRed | DoGreen | DoBlue;
932 edit.oldButtonColor.bs.pixel = edit.color_set->bs.pixel;
933 edit.oldButtonColor.bs.flags = edit.color_set->bs.flags;
934 edit.oldButtonColor.ts.pixel = edit.color_set->ts.pixel;
935 edit.oldButtonColor.ts.flags = edit.color_set->ts.flags;
939 CopyPixelSet(&edit.oldButtonColor,edit.color_set);
941 RGBtoHSV(edit.oldButtonColor.bg.red,
942 edit.oldButtonColor.bg.green,
943 edit.oldButtonColor.bg.blue,
946 XtFree((char *)pixels);
949 /************************************************************************
951 * Generates new RGB values for fg, ts, bs, sc based on bg.
952 * The Color generation routine will be exported in motif1.1
953 * The generated colors are then used to update the pixels
954 * of the ColorSet being edited.
955 ************************************************************************/
957 GenerateColors( void )
963 if (edit.calcRGB == NULL)
964 edit.calcRGB = XmGetColorCalculation();
966 (*edit.calcRGB) (&edit.color_set->bg, &edit.color_set->fg,
967 &edit.color_set->sc, &edit.color_set->ts,
968 &edit.color_set->bs);
970 RGBtoHSV(edit.color_set->bg.red, edit.color_set->bg.green,
971 edit.color_set->bg.blue,
974 colors[j++] = edit.color_set->bg;
975 colors[j++] = edit.color_set->sc;
977 if (FgColor == DYNAMIC)
978 colors[j++] = edit.color_set->fg;
980 if(UsePixmaps == FALSE)
982 colors[j++] = edit.color_set->ts;
983 colors[j++] = edit.color_set->bs;
987 edit.color_set->ts.red = 65535;
988 edit.color_set->ts.green = 65535;
989 edit.color_set->ts.blue = 65535;
991 edit.color_set->bs.red = 0;
992 edit.color_set->bs.green = 0;
993 edit.color_set->bs.blue = 0;
996 if(style.visualClass==PseudoColor || style.visualClass==StaticColor)
998 XStoreColors(style.display, style.colormap, colors, j );
1000 else if(style.visualClass==TrueColor || style.visualClass==DirectColor)
1002 static unsigned long pixels[4];
1006 XFreeColors(style.display,style.colormap,pixels,count,0);
1010 if(XAllocColor(style.display,style.colormap,&edit.color_set->fg))
1011 pixels[count++]=edit.color_set->fg.pixel;
1012 if(XAllocColor(style.display,style.colormap,&edit.color_set->bg))
1013 pixels[count++]=edit.color_set->bg.pixel;
1014 if(XAllocColor(style.display,style.colormap,&edit.color_set->ts))
1015 pixels[count++]=edit.color_set->ts.pixel;
1016 if(XAllocColor(style.display,style.colormap,&edit.color_set->bs))
1017 pixels[count++]=edit.color_set->bs.pixel;
1019 XtVaSetValues(edit.newButton,
1020 XmNbackground,edit.color_set->bg.pixel,
1021 XmNarmColor,edit.color_set->bg.pixel,
1022 XmNforeground,edit.color_set->fg.pixel,
1023 XmNtopShadowColor,edit.color_set->ts.pixel,
1024 XmNbottomShadowColor,edit.color_set->bs.pixel,NULL);
1028 /************************************************************************
1030 * Called when one of the RGB scales is moved
1031 ************************************************************************/
1035 XtPointer client_data,
1036 XtPointer call_data )
1042 reason_code = ((XmAnyCallbackStruct *)call_data)->reason;
1043 if ( reason_code == XmCR_VALUE_CHANGED || reason_code == XmCR_DRAG )
1045 color = (int) (intptr_t) client_data;
1046 value = ((XmScaleCallbackStruct *)call_data)->value;
1048 if (edit.current_scale == NONE)
1050 edit.current_scale = color;
1052 * Shift value -- to make up for scale max of only 0xff
1058 edit.color_set->bg.red = value;
1061 edit.color_set->bg.green = value;
1064 edit.color_set->bg.blue = value;
1067 /* this case should never be hit */
1071 SetScales(&edit.color_set->bg);
1073 edit.current_scale = NONE;
1079 /************************************************************************
1081 * Called when one of the HSV scales is moved
1082 ************************************************************************/
1086 XtPointer client_data,
1087 XtPointer call_data )
1094 reason_code = ((XmAnyCallbackStruct *)call_data)->reason;
1095 if ( reason_code == XmCR_VALUE_CHANGED || reason_code == XmCR_DRAG )
1097 scale = (int) (intptr_t) client_data;
1098 value = ((XmScaleCallbackStruct *)call_data)->value;
1100 if (edit.current_scale == NONE)
1102 edit.current_scale = scale;
1107 XmScaleGetValue(edit.satScale, &sat);
1108 XmScaleGetValue(edit.valScale, &val);
1111 XmScaleGetValue(edit.hueScale, &hue);
1113 XmScaleGetValue(edit.valScale, &val);
1116 XmScaleGetValue(edit.hueScale, &hue);
1117 XmScaleGetValue(edit.satScale, &sat);
1121 /* this case should never be hit */
1125 HSVtoRGB(hue, sat, val,
1126 &edit.color_set->bg.red,
1127 &edit.color_set->bg.green,
1128 &edit.color_set->bg.blue);
1130 SetRGBHSVScales(&edit.color_set->bg, hue, sat, val);
1132 edit.current_scale = NONE;
1138 /************************************************************************
1140 * passed a XColor, generates HSV values and updates all scales.
1141 ************************************************************************/
1148 RGBtoHSV(rgb->red, rgb->green, rgb->blue, &h, &s, &v);
1150 SetRGBHSVScales(rgb, h, s, v);
1154 /************************************************************************
1156 * updates RGB and HSV scales
1157 ************************************************************************/
1165 XmScaleSetValue(edit.redScale,rgb->red >> 8);
1166 XmScaleSetValue(edit.greenScale,rgb->green >> 8);
1167 XmScaleSetValue(edit.blueScale,rgb->blue >> 8);
1169 XmScaleSetValue(edit.hueScale,h);
1170 XmScaleSetValue(edit.satScale,s);
1171 XmScaleSetValue(edit.valScale,v);
1175 /************************************************************************
1178 ************************************************************************/
1181 ColorSet *color_set_dest,
1182 ColorSet *color_set_src )
1189 color_set_dest->bg.red = color_set_src->bg.red;
1190 color_set_dest->bg.blue = color_set_src->bg.blue;
1191 color_set_dest->bg.green = color_set_src->bg.green;
1193 color_set_dest->bg.pixel = color_set_src->bg.pixel;
1194 colors[j++] = color_set_dest->bg;
1196 color_set_dest->sc.red = color_set_src->sc.red;
1197 color_set_dest->sc.blue = color_set_src->sc.blue;
1198 color_set_dest->sc.green = color_set_src->sc.green;
1200 color_set_dest->bg.pixel = color_set_src->bg.pixel;
1201 colors[j++] = color_set_dest->sc;
1203 color_set_dest->fg.red = color_set_src->fg.red;
1204 color_set_dest->fg.blue = color_set_src->fg.blue;
1205 color_set_dest->fg.green = color_set_src->fg.green;
1206 if(FgColor == DYNAMIC)
1209 color_set_dest->bg.pixel = color_set_src->bg.pixel;
1210 colors[j++] = color_set_dest->fg;
1213 color_set_dest->ts.red = color_set_src->ts.red;
1214 color_set_dest->ts.blue = color_set_src->ts.blue;
1215 color_set_dest->ts.green = color_set_src->ts.green;
1216 color_set_dest->bs.red = color_set_src->bs.red;
1217 color_set_dest->bs.blue = color_set_src->bs.blue;
1218 color_set_dest->bs.green = color_set_src->bs.green;
1219 if(UsePixmaps == FALSE)
1222 color_set_dest->bg.pixel = color_set_src->bg.pixel;
1223 colors[j++] = color_set_dest->ts;
1224 colors[j++] = color_set_dest->bs;
1226 if(OldNewSame && edit.oldButton != NULL)
1229 XtSetArg(args[n], XmNforeground, color_set_dest->fg.pixel); n++;
1230 XtSetArg(args[n], XmNbackground, color_set_dest->bg.pixel); n++;
1231 XtSetArg(args[n], XmNarmColor, color_set_dest->sc.pixel); n++;
1232 XtSetArg(args[n], XmNtopShadowColor,
1233 color_set_dest->ts.pixel); n++;
1234 XtSetArg(args[n], XmNbottomShadowColor,
1235 color_set_dest->bs.pixel); n++;
1237 XtSetValues(edit.oldButton, args, n);
1239 if(style.visualClass == PseudoColor || style.visualClass == GrayScale)
1240 XStoreColors(style.display, style.colormap, colors, j );
1245 /************************************************************************
1248 ************************************************************************/
1251 #if NeedWidePrototypes
1264 double red, green, blue;
1265 double red1, green1, blue1;
1266 double hue, saturation, value;
1270 red1 = (double)r / 65280.0;
1271 green1 = (double)g / 65280.0;
1272 blue1 = (double)b / 65280.0;
1274 value = max(red1, green1, blue1);
1275 base = min(red1, green1, blue1);
1278 saturation = (value - base) / value;
1284 if( saturation != 0.0 )
1286 red = (value - red1 ) / (value - base);
1287 green = (value - green1 ) / (value - base);
1288 blue = (value - blue1 ) / (value - base);
1297 else if(value == green1)
1317 *s = ((int)(saturation * 65280.0)) >> 8;
1318 *v = ((int)(value * 65280.0)) >> 8;
1321 /************************************************************************
1324 * Converts hue, saturation, and value to RGB values.
1325 * Hue is in the range 0 to 360, while saturation and value
1326 * are in the range 0 to 255
1327 ************************************************************************/
1338 double hue, sat, val;
1339 double red, green, blue;
1342 hue = (double)h / 60.0;
1346 val = (double)v / 255.0;
1347 sat = (double)s / 255.0;
1349 p1 = val * (1.0 - sat);
1350 p2 = val * (1.0 -(sat * f));
1351 p3 = val * (1.0 -(sat * (1.0 - f)));
1387 *r = (int)(red * 65280.0);
1388 *g = (int)(green * 65280.0);
1389 *b = (int)(blue * 65280.0);
1394 /************************************************************************
1397 ************************************************************************/
1404 if(x >= y && x >= z)
1407 if(y >= z && y >= x)
1410 if(z >= y && z >= x)
1414 /************************************************************************
1417 ************************************************************************/
1424 if(x <= y && x <= z)
1427 if(y <= z && y <= x)
1430 if(z <= y && z <= x)
1434 /************************************************************************
1436 * Call back routine for grabbing a color from the screen
1437 ************************************************************************/
1441 XtPointer client_data,
1442 XtPointer call_data )
1444 Cursor cursor = XCreateFontCursor(style.display, XC_crosshair);
1450 char color_string[MAX_STR_LEN];
1452 Boolean notDone=True;
1455 /* grab the pointer using target cursor */
1456 status = XtGrabPointer(style.colorDialog, TRUE,
1457 ButtonPressMask | ButtonReleaseMask,
1458 GrabModeAsync, GrabModeAsync, None,
1459 cursor, CurrentTime);
1460 if (status != GrabSuccess)
1462 _DtSimpleError (progName, DtWarning, NULL,
1463 ((char *)GETMESSAGE(17, 14, "Warning, couldn't grab pointer.\n")), NULL);
1467 /* grab the keyboard so we can get the ESC button press */
1468 status = XtGrabKeyboard(style.colorDialog, False, GrabModeAsync,
1469 GrabModeAsync, CurrentTime);
1470 if (status != GrabSuccess)
1472 XtUngrabPointer (style.colorDialog, CurrentTime);
1473 _DtSimpleError (progName, DtWarning, NULL,
1474 ((char *)GETMESSAGE(17, 15, "Warning, couldn't grab Keyboard.\n")), NULL);
1480 XtNextEvent(&event);
1482 switch (event.type) {
1489 /* look for ESC key press and stop if we get one */
1490 if( event.xkey.state & ShiftMask)
1495 keySym = XLookupKeysym((XKeyEvent *)&event, offset);
1496 if (keySym == XK_Escape)
1498 XtUngrabKeyboard (style.colorDialog, CurrentTime);
1499 XtUngrabPointer (style.colorDialog, CurrentTime);
1503 XtDispatchEvent(&event);
1507 XtUngrabKeyboard (style.colorDialog, CurrentTime);
1508 XtUngrabPointer (style.colorDialog, CurrentTime);
1510 x = (Position)event.xbutton.x_root;
1511 y = (Position)event.xbutton.y_root;
1512 image_ptr = XGetImage (style.display, style.root, x, y, 1, 1,
1513 AllPlanes, ZPixmap);
1514 pixel = (Pixel) XGetPixel (image_ptr, 0, 0);
1515 XDestroyImage (image_ptr);
1517 colorStruct.pixel = pixel;
1519 XQueryColor (style.display, style.colormap, &colorStruct);
1521 edit.color_set->bg.red = colorStruct.red;
1522 edit.color_set->bg.green = colorStruct.green;
1523 edit.color_set->bg.blue = colorStruct.blue;
1525 SetScales(&edit.color_set->bg);
1530 /************************************************************************
1533 ************************************************************************/
1537 char *color_string )
1541 from.size = strlen(color_string) + 1;
1542 if (from.size < sizeof(String))
1543 from.size = sizeof(String);
1544 from.addr = color_string;
1545 XtConvert(widget, XmRString, &from, XmRPixel, &to);
1547 return ((Pixel) *((Pixel *) to.addr));
1554 ** Process callback from the Ok, Cancel and Help pushButtons in the
1560 XtPointer client_data,
1561 XtPointer call_data )
1563 palette *tmp_palette;
1564 DtDialogBoxCallbackStruct *cb = (DtDialogBoxCallbackStruct *) call_data;
1566 switch (cb->button_position)
1570 WriteOutPalette( pCurrentPalette->name);
1572 if(strcmp(pCurrentPalette->name, defaultName) == 0)
1574 UpdateDefaultPalette();
1578 XtUnmanageChild(edit.DialogShell);
1582 CopyPixelSet(edit.color_set, &edit.oldButtonColor);
1583 XtUnmanageChild(edit.DialogShell);
1587 XtCallCallbacks(edit.DialogShell, XmNhelpCallback, (XtPointer)NULL);
1597 /************************************************************************
1600 ************************************************************************/
1604 XtPointer client_data,
1605 XtPointer call_data )
1609 Dimension editWidth,editHeight;
1610 Dimension width,height;
1613 XtWidgetGeometry reply;
1614 Widget parent = (Widget) client_data;
1617 DtWsmRemoveWorkspaceFunctions(style.display, XtWindow(XtParent(w)));
1619 if (!save.restoreFlag)
1621 /* get x,y,width,height of parent shell */
1623 x = XtX(XtParent(parent));
1624 y = XtY(XtParent(parent));
1625 height = XtHeight(parent);
1626 width = XtWidth(parent);
1628 editHeight = XtHeight(edit.DialogShell);
1629 editWidth = XtWidth(edit.DialogShell);
1631 newX = x + width/2 - editWidth/2;
1634 newY = y + height/2 - editHeight;
1639 XtSetArg(args[n], XmNx, newX); n++;
1640 XtSetArg(args[n], XmNy, newY); n++;
1641 XtSetValues(edit.DialogShell,args,n);
1645 XtRemoveCallback(edit.DialogShell, XmNmapCallback, _DtmapCB, NULL);
1650 /****************************************************
1651 * restoreColor(shell, db)
1652 * restore any state information saved with saveColor.
1653 * This is called from restoreSession with the application shell
1654 * and the special xrm database retrieved for restore.
1655 ****************************************************/
1662 XrmName xrm_name[5];
1663 XrmRepresentation rep_type;
1666 xrm_name [0] = XrmStringToQuark ("colorEditDlg");
1669 /* get x position */
1670 xrm_name [1] = XrmStringToQuark ("x");
1671 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
1672 XtSetArg (save.posArgs[save.poscnt], XmNx, atoi((char *)value.addr)); save.poscnt++;
1673 save.restoreFlag = True;
1676 /* get y position */
1677 xrm_name [1] = XrmStringToQuark ("y");
1678 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
1679 XtSetArg (save.posArgs[save.poscnt], XmNy, atoi((char *)value.addr)); save.poscnt++;
1682 /*Collect any other parameters you saved into static variables.*/
1684 xrm_name [1] = XrmStringToQuark ("ismapped");
1685 XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
1686 /* Are we supposed to be mapped? */
1687 if (strcmp(value.addr, "True") == 0)
1688 XtCallCallbacks(modifyColorButton, XmNactivateCallback, NULL);
1692 /****************************************************
1694 * This routine will write out to the passed file descriptor any state
1695 * information this dialog needs. It is called from saveSessionCB with
1696 * the file already opened.
1697 * All information is saved in xrm format. There is no restriction
1698 * on what can be saved. It doesn't have to be defined or be part of any
1699 * widget or Xt definition. Just name and save it here and recover it in
1700 * restoreColor. The suggested minimum is whether you are mapped, and your
1702 *****************************************************/
1708 char *bufr = style.tmpBigStr; /* size=[1024], make bigger if needed */
1709 XmVendorShellExtObject vendorExt;
1710 XmWidgetExtData extData;
1712 if (edit.DialogShell != NULL)
1714 if (XtIsManaged(edit.DialogShell))
1715 sprintf(bufr, "*colorEditDlg.ismapped: True\n");
1717 sprintf(bufr, "*colorEditDlg.ismapped: False\n");
1719 /* Get and write out the geometry info for our Window */
1720 x = XtX(XtParent(edit.DialogShell));
1721 y = XtY(XtParent(edit.DialogShell));
1723 /* Modify x & y to take into account window mgr frames
1724 * This is pretty bogus, but I don't know a better way to do it.
1726 extData = _XmGetWidgetExtData(style.shell, XmSHELL_EXTENSION);
1727 vendorExt = (XmVendorShellExtObject)extData->widget;
1728 x -= vendorExt->vendor.xOffset;
1729 y -= vendorExt->vendor.yOffset;
1731 sprintf(bufr, "%s*colorEditDlg.x: %d\n", bufr, x);
1732 sprintf(bufr, "%s*colorEditDlg.y: %d\n", bufr, y);
1733 /*any other parameter you want to save goes here*/
1734 if(-1 == write (fd, bufr, strlen(bufr))) {
1735 perror(strerror(errno));