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 librararies 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>
49 #include <Xm/MwmUtil.h>
52 #include <Xm/LabelG.h>
54 #include <Xm/PushBG.h>
57 #include <Xm/VendorSEP.h>
59 #include <Dt/DialogBox.h>
60 #include <Dt/TitleBox.h>
62 #include <Dt/UserMsg.h>
66 #include "ColorMain.h"
67 #include "ColorFile.h"
69 /*+++++++++++++++++++++++++++++++++++++++*/
70 /* include extern functions */
71 /*+++++++++++++++++++++++++++++++++++++++*/
72 #include "ColorEdit.h"
74 /*+++++++++++++++++++++++++++++++++++++++*/
76 /*+++++++++++++++++++++++++++++++++++++++*/
85 #define MAX_STR_LEN 128
87 #define SCALE_LEFT_POSITION 10
88 #define BUTTON_MARGIN 10
89 #define OLD_BUTTON_LEFT_POSITION 10
90 #define SCALE_WIDTH 300
92 #define SATURATION_BITS "Dtsatur"
93 #define VALUE_BITS "Dtvalue"
95 /*+++++++++++++++++++++++++++++++++++++++*/
96 /* Internal Functions */
97 /*+++++++++++++++++++++++++++++++++++++++*/
99 static void CreateColorEditor( Widget parent) ;
100 static void sliderLayoutCB(
102 XtPointer client_data,
103 XtPointer call_data) ;
104 static void InitializeNewButton( void ) ;
105 static void InitializeOldButton( void ) ;
106 static void GenerateColors( void ) ;
107 static Pixel GetPixel( Widget widget,
108 char *color_string ) ;
109 static void changRGB_CB(
111 XtPointer client_data,
112 XtPointer call_data) ;
113 static void changHSV_CB(
115 XtPointer client_data,
116 XtPointer call_data) ;
117 static void SetScales( XColor *rgb) ;
118 static void SetRGBHSVScales(
123 static void CopyPixelSet(
124 ColorSet *color_set_dest,
125 ColorSet *color_set_src) ;
126 static void HSVtoRGB(
141 static void grabcolorCB(
143 XtPointer client_data,
144 XtPointer call_data) ;
145 static void dialogBoxCB(
147 XtPointer client_data,
148 XtPointer call_data) ;
149 static void _DtmapCB(
151 XtPointer client_data,
152 XtPointer call_data) ;
155 /*+++++++++++++++++++++++++++++++++++++++*/
156 /* Global Variables */
157 /*+++++++++++++++++++++++++++++++++++++++*/
160 /*+++++++++++++++++++++++++++++++++++++++*/
161 /* Internal Variables */
162 /*+++++++++++++++++++++++++++++++++++++++*/
163 static saveRestore save = {FALSE, 0, };
164 static OldNewSame = False;
166 /************************************************************************
167 * ColorEditor() - Create ColorEditor dialog first time up.
168 * If has already been created, set up oldButton and newButton
169 * colors, set the scale values for the new color and manage
171 ************************************************************************/
175 ColorSet *color_set )
177 if (edit.DialogShell == NULL)
179 _DtTurnOnHourGlass(parent);
180 edit.color_set = color_set;
181 CreateColorEditor(parent);
182 _DtTurnOffHourGlass(parent);
186 if (!XtIsManaged(edit.DialogShell))
188 edit.color_set = color_set;
189 CopyPixelSet(&edit.oldButtonColor,edit.color_set);
190 InitializeNewButton();
191 SetScales(&edit.color_set->bg);
192 XtManageChild(edit.DialogShell);
193 XMapRaised(style.display, XtWindow(edit.DialogShell));
199 /************************************************************************
200 * CreateColorEditor()
201 * Create the Color Editor Dialog
202 ************************************************************************/
212 XmString string; /* temp Xm string */
213 Widget widgetlist1[10]; /* main_form */
214 Widget widgetlist2[16]; /* sliderForm */
215 Widget widgetlist3[10]; /* sampleForm */
216 int widget_count1 = 0;
217 int widget_count2 = 0;
218 int widget_count3 = 0;
219 XmString button_string[NUM_LABELS];
220 Pixel foreground, background;
223 Dimension w, width_old, width_new;
225 edit.current_scale = NONE;
227 /* Set up DialogBox button labels. */
228 button_string[0] = CMPSTR((String) _DtOkString);
229 button_string[1] = CMPSTR((String) _DtCancelString);
230 button_string[2] = CMPSTR((String) _DtHelpString);
232 /* Note that save.poscnt has been initialized elsewhere.
233 * save.posArgs may contain information from restoreColorEdit(). */
235 XtSetArg(args[save.poscnt], XmNchildType, XmWORK_AREA); save.poscnt++;
236 XtSetArg(save.posArgs[save.poscnt], XmNbuttonCount, NUM_LABELS);
238 XtSetArg(save.posArgs[save.poscnt], XmNbuttonLabelStrings,
241 XtSetArg(save.posArgs[save.poscnt], XmNdefaultPosition, False);
243 edit.DialogShell = __DtCreateDialogBoxDialog(parent,"colorEditDlg",
244 save.posArgs, save.poscnt);
245 XtAddCallback(edit.DialogShell, XmNmapCallback, sliderLayoutCB, NULL);
246 XtAddCallback(edit.DialogShell, XmNcallback, dialogBoxCB, NULL);
247 XtAddCallback(edit.DialogShell, XmNmapCallback, _DtmapCB, parent);
248 XtAddCallback(edit.DialogShell, XmNhelpCallback,
249 (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_MODIFY_PALETTE_DIALOG);
251 XmStringFree(button_string[0]);
252 XmStringFree(button_string[1]);
253 XmStringFree(button_string[2]);
255 widgetlist1[0] = _DtDialogBoxGetButton(edit.DialogShell,2);
258 XtSetArg(args[n], XmNautoUnmanage, False); n++;
259 XtSetArg(args[n], XmNcancelButton, widgetlist1[0]); n++;
260 XtSetValues (edit.DialogShell, args, n);
263 XtSetArg (args[n], XmNtitle, ((char *)GETMESSAGE(17, 16, "Style Manager - Modify Color"))); n++;
264 XtSetArg (args[n], XmNuseAsyncGeometry, True); n++;
265 XtSetArg(args[n], XmNmwmFunctions, DIALOG_MWM_FUNC); n++;
266 XtSetValues (XtParent(edit.DialogShell), args, n);
269 XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
270 XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
271 edit.main_form = XmCreateForm(edit.DialogShell, "main_form", args, n);
274 XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
275 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
276 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
277 XtSetArg (args[n], XmNmarginWidth, 0); n++;
278 XtSetArg (args[n], XmNmarginHeight, 0); n++;
279 string = CMPSTR(((char *)GETMESSAGE(17, 4, "Color Sample")));
280 XtSetArg (args[n], XmNtitleString, string); n++;
281 sampleTB = _DtCreateTitleBox(edit.main_form, "sampleTB", args, n);
282 widgetlist1[widget_count1++] = sampleTB;
283 XmStringFree(string);
286 XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
287 XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
288 sampleForm = XmCreateForm(sampleTB, "sampleForm", args, n);
290 /* Create Old and New Buttons */
291 InitializeOldButton();
295 string = CMPSTR(((char *)GETMESSAGE(17, 5, "Old")));
296 XtSetArg(args[n], XmNlabelString, string); n++;
297 XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
298 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
299 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
300 /* Set the old button color to the color of the selected button */
301 XtSetArg(args[n], XmNforeground, edit.oldButtonColor.fg.pixel); n++;
302 XtSetArg(args[n], XmNbackground, edit.oldButtonColor.bg.pixel); n++;
303 XtSetArg(args[n], XmNarmColor, edit.oldButtonColor.sc.pixel); n++;
304 XtSetArg(args[n], XmNtopShadowColor,
305 edit.oldButtonColor.ts.pixel); n++;
306 XtSetArg(args[n], XmNbottomShadowColor,
307 edit.oldButtonColor.bs.pixel); n++;
310 XmCreatePushButton(sampleForm, "oldButton", args, n);
311 widgetlist3[widget_count3++] = edit.oldButton;
312 XmStringFree(string);
315 string = CMPSTR(((char *)GETMESSAGE(17, 6, "New")));
317 XtSetArg(args[n], XmNlabelString, string); n++;
318 XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
320 XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
321 XtSetArg (args[n], XmNleftWidget, edit.oldButton); n++;
324 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
326 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
327 edit.newButton = XmCreatePushButton(sampleForm, "newButton", args, n);
328 widgetlist3[widget_count3++] = edit.newButton;
329 XmStringFree(string);
333 /* make old and new button both the size of the larger of the two */
334 width_old = XtWidth(edit.oldButton);
335 width_new = XtWidth(edit.newButton);
336 w = (width_old>width_new) ? width_old : width_new;
339 XtSetArg (args[n], XmNrecomputeSize, False); n++;
340 XtSetArg (args[n], XmNwidth, w+2*BUTTON_MARGIN); n++;
341 XtSetArg (args[n], XmNheight, w+2*BUTTON_MARGIN); n++;
342 XtSetValues(edit.oldButton, args, n);
343 XtSetValues(edit.newButton, args, n);
347 w = XtWidth(edit.newButton);
350 XtSetArg (args[n], XmNrecomputeSize, False); n++;
351 XtSetArg (args[n], XmNwidth, w+2*BUTTON_MARGIN); n++;
352 XtSetArg (args[n], XmNheight, w+2*BUTTON_MARGIN); n++;
353 XtSetValues(edit.newButton, args, n);
357 InitializeNewButton();
360 string = CMPSTR(((char *)GETMESSAGE(17, 7, "Grab Color")));
361 XtSetArg(args[n], XmNlabelString, string); n++;
362 XtSetArg(args[n], XmNnavigationType, XmTAB_GROUP); n++;
363 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
364 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
365 XtSetArg(args[n], XmNmarginHeight, LB_MARGIN_HEIGHT); n++;
366 XtSetArg(args[n], XmNmarginWidth, LB_MARGIN_WIDTH); n++;
367 edit.grabColor = XmCreatePushButtonGadget(sampleForm, "grabColor", args, n);
368 widgetlist3[widget_count3++] = edit.grabColor;
369 XtAddCallback(edit.grabColor, XmNactivateCallback,
370 grabcolorCB, (XtPointer)NULL);
371 XmStringFree(string);
373 /* Create frame for RGB/HSV scales */
375 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
376 XtSetArg(args[n], XmNtopWidget, sampleTB); n++;
377 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
378 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
379 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
380 XtSetArg (args[n], XmNmarginWidth, 0); n++;
381 XtSetArg (args[n], XmNmarginHeight, 0); n++;
382 string = CMPSTR(((char *)GETMESSAGE(17, 8, "Color Editor")));
383 XtSetArg (args[n], XmNtitleString, string); n++;
384 sliderTB = _DtCreateTitleBox(edit.main_form, "sliderTB", args, n);
385 widgetlist1[widget_count1++] = sliderTB;
386 XmStringFree(string);
389 XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
390 XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
391 edit.sliderForm = XmCreateForm(sliderTB, "sliderForm", args, n);
394 * Create Hue label and scale
398 string = CMPSTR(((char *)GETMESSAGE(17, 9, "Hue")));
399 XtSetArg(args[n], XmNlabelString, string); n++;
400 edit.hueLabel = XmCreateLabelGadget(edit.sliderForm, "hueLabel", args, n);
401 widgetlist2[widget_count2++] = edit.hueLabel;
402 XmStringFree(string);
405 XtSetArg(args[n], XmNshowValue, TRUE); n++;
406 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
407 XtSetArg(args[n], XmNprocessingDirection, XmMAX_ON_BOTTOM); n++;
408 XtSetArg(args[n], XmNhighlightThickness, SCALE_HIGHLIGHT_THICKNESS); n++;
409 XtSetArg(args[n], XmNmaximum, 359); n++;
410 XtSetArg(args[n], XmNminimum, 0x0); n++;
411 XtSetArg(args[n], XmNincrement, 1); n++;
412 edit.hueScale = XmCreateScale(edit.sliderForm, "hueScale", args, n);
413 widgetlist2[widget_count2++] = edit.hueScale;
414 XtAddCallback(edit.hueScale, XmNvalueChangedCallback, changHSV_CB, (XtPointer) HUE);
415 XtAddCallback(edit.hueScale, XmNdragCallback, changHSV_CB, (XtPointer) HUE );
421 string = CMPSTR(((char *)GETMESSAGE(17, 10, "R")));
423 XtSetArg(args[n], XmNalignment, XmALIGNMENT_END); n++;
424 XtSetArg(args[n], XmNlabelString, string); n++;
425 XtSetArg(args[n], XmNmarginHeight, 0); n++;
426 edit.redLabel = XmCreateLabelGadget(edit.sliderForm, "redLabel", args, n);
427 widgetlist2[widget_count2++] = edit.redLabel;
428 XmStringFree(string);
430 string = CMPSTR(((char *)GETMESSAGE(17, 11, "G")));
432 XtSetArg(args[n], XmNalignment, XmALIGNMENT_END); n++;
433 XtSetArg(args[n], XmNlabelString, string); n++;
434 XtSetArg(args[n], XmNmarginHeight, 0); n++;
435 edit.greenLabel = XmCreateLabelGadget(edit.sliderForm, "greenLabel", args, n);
436 widgetlist2[widget_count2++] = edit.greenLabel;
437 XmStringFree(string);
439 string = CMPSTR(((char *)GETMESSAGE(17, 12, "B")));
441 XtSetArg(args[n], XmNalignment, XmALIGNMENT_END); n++;
442 XtSetArg(args[n], XmNlabelString, string); n++;
443 XtSetArg(args[n], XmNmarginHeight, 0); n++;
444 edit.blueLabel = XmCreateLabelGadget(edit.sliderForm, "blueLabel", args, n);
445 widgetlist2[widget_count2++] = edit.blueLabel;
446 XmStringFree(string);
449 XtSetArg(args[n], XmNshowValue, TRUE); n++;
450 XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
451 XtSetArg(args[n], XmNprocessingDirection, XmMAX_ON_RIGHT); n++;
452 XtSetArg(args[n], XmNhighlightThickness, SCALE_HIGHLIGHT_THICKNESS); n++;
453 XtSetArg(args[n], XmNmaximum, 0xff); n++;
454 XtSetArg(args[n], XmNminimum, 0x0); n++;
455 XtSetArg(args[n], XmNincrement, 1); n++;
456 XtSetArg(args[n], XmNscaleWidth, SCALE_WIDTH); n++;
457 widgetlist2[widget_count2++] = edit.redScale =
458 XmCreateScale(edit.sliderForm, "redScale", args, n);
459 XtAddCallback(edit.redScale, XmNvalueChangedCallback, changRGB_CB, (XtPointer) RED);
460 XtAddCallback(edit.redScale, XmNdragCallback, changRGB_CB, (XtPointer) RED );
462 widgetlist2[widget_count2++] = edit.greenScale =
463 XmCreateScale(edit.sliderForm, "greenScale", args, n);
464 XtAddCallback(edit.greenScale, XmNvalueChangedCallback, changRGB_CB, (XtPointer) GREEN );
465 XtAddCallback(edit.greenScale, XmNdragCallback, changRGB_CB, (XtPointer) GREEN );
467 widgetlist2[widget_count2++] = edit.blueScale =
468 XmCreateScale(edit.sliderForm, "blueScale", args, n);
469 XtAddCallback(edit.blueScale, XmNvalueChangedCallback, changRGB_CB, (XtPointer) BLUE );
470 XtAddCallback(edit.blueScale, XmNdragCallback, changRGB_CB, (XtPointer) BLUE);
476 /* create Saturation pixmap */
478 XtSetArg(args[n], XmNforeground, &foreground); n++;
479 XtSetArg(args[n], XmNbackground, &background); n++;
480 XtGetValues(edit.sliderForm, args, n);
483 XtSetArg(args[n], XmNalignment, XmALIGNMENT_END); n++;
484 XtSetArg(args[n], XmNlabelType, XmPIXMAP); n++;
485 XtSetArg(args[n], XmNlabelPixmap, XmGetPixmap(style.screen, SATURATION_BITS,
486 foreground, background)); n++;
487 XtSetArg(args[n], XmNmarginHeight, 3); n++;
488 edit.satLabel = XmCreateLabelGadget(edit.sliderForm, "satLabel", args, n);
489 widgetlist2[widget_count2++] = edit.satLabel;
491 /* create Value pixmap */
493 XtSetArg(args[n], XmNalignment, XmALIGNMENT_END); n++;
494 XtSetArg(args[n], XmNlabelType, XmPIXMAP); n++;
495 XtSetArg(args[n], XmNlabelPixmap, XmGetPixmap(style.screen, VALUE_BITS,
496 foreground, background)); n++;
497 XtSetArg(args[n], XmNmarginHeight, 3); n++;
498 edit.valLabel = XmCreateLabelGadget(edit.sliderForm, "valLabel", args, n);
499 widgetlist2[widget_count2++] = edit.valLabel;
502 XtSetArg(args[n], XmNshowValue, TRUE); n++;
503 XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
504 XtSetArg(args[n], XmNprocessingDirection, XmMAX_ON_RIGHT); n++;
505 XtSetArg(args[n], XmNhighlightThickness, SCALE_HIGHLIGHT_THICKNESS); n++;
506 XtSetArg(args[n], XmNmaximum, 0xff); n++;
507 XtSetArg(args[n], XmNminimum, 0x0); n++;
508 XtSetArg(args[n], XmNincrement, 1); n++;
509 XtSetArg(args[n], XmNscaleWidth, SCALE_WIDTH); n++;
510 widgetlist2[widget_count2++] = edit.satScale =
511 XmCreateScale(edit.sliderForm, "satScale", args, n);
512 XtAddCallback(edit.satScale, XmNvalueChangedCallback, changHSV_CB, (XtPointer) SATURATION);
513 XtAddCallback(edit.satScale, XmNdragCallback, changHSV_CB, (XtPointer) SATURATION );
515 widgetlist2[widget_count2++] = edit.valScale =
516 XmCreateScale(edit.sliderForm, "valScale", args, n);
517 XtAddCallback(edit.valScale, XmNvalueChangedCallback, changHSV_CB, (XtPointer) VALUE);
518 XtAddCallback(edit.valScale, XmNdragCallback, changHSV_CB, (XtPointer) VALUE );
520 /* Set the scales to the bg component of the selected color */
521 SetScales(&edit.color_set->bg);
523 /* Do all the mapping */
525 XtManageChildren(widgetlist3, widget_count3);
526 XtManageChild(sampleForm);
528 XtManageChildren(widgetlist2, widget_count2);
529 XtManageChild(edit.sliderForm);
531 XtManageChildren(widgetlist1, widget_count1);
532 XtManageChild(edit.main_form);
534 XtManageChild(edit.DialogShell);
536 if(TypeOfMonitor == XmCO_HIGH_COLOR)
538 /* set the trough colors of the RGB scales -
539 get the composite children of the scales -
540 child[1] is the scrollbar */
542 XtSetArg(args[n], XtNchildren, &children); n++;
543 XtGetValues(edit.redScale, args, n);
545 XtSetArg(args[n], XmNtroughColor, GetPixel(edit.main_form,"red")); n++;
546 XtSetValues (children[1], args, n);
549 XtSetArg(args[n], XtNchildren, &children); n++;
550 XtGetValues(edit.greenScale, args, n);
552 XtSetArg(args[n], XmNtroughColor, GetPixel(edit.main_form,"green")); n++;
553 XtSetValues (children[1], args, n);
556 XtSetArg(args[n], XtNchildren, &children); n++;
557 XtGetValues(edit.blueScale, args, n);
559 XtSetArg(args[n], XmNtroughColor, GetPixel(edit.main_form,"blue")); n++;
560 XtSetValues (children[1], args, n);
569 XtPointer client_data,
570 XtPointer call_data )
574 Dimension redLabelWidth;
575 Dimension greenLabelWidth;
576 Dimension blueLabelWidth;
577 Dimension satLabelWidth;
578 Dimension valLabelWidth;
579 Dimension MaxLabelWidth;
580 Dimension redLabelHeight;
581 Dimension satLabelHeight;
582 Dimension valLabelHeight;
583 Dimension redScaleHeight;
585 Dimension scale_width;
590 * Do the scale and label attachments
593 redLabelHeight = XtHeight(edit.redLabel);
594 MaxLabelWidth = redLabelWidth = XtWidth(edit.redLabel);
596 greenLabelWidth = XtWidth(edit.greenLabel);
597 if (greenLabelWidth > MaxLabelWidth)
599 MaxLabelWidth = greenLabelWidth;
602 blueLabelWidth = XtWidth(edit.blueLabel);
603 if (blueLabelWidth > MaxLabelWidth)
605 MaxLabelWidth = blueLabelWidth;
608 satLabelHeight = XtHeight(edit.satLabel);
609 satLabelWidth = XtWidth(edit.satLabel);
610 if (satLabelWidth > MaxLabelWidth)
612 MaxLabelWidth = satLabelWidth;
615 valLabelHeight = XtHeight(edit.valLabel);
616 valLabelWidth = XtWidth(edit.valLabel);
617 if (valLabelWidth > MaxLabelWidth)
619 MaxLabelWidth = valLabelWidth;
622 redScaleHeight = XtHeight(edit.redScale);
625 /* Attach grab button to New button if they are overlapping */
628 pieces = XtWidth(edit.oldButton) +
629 XtWidth(edit.newButton) +
630 XtWidth(edit.grabColor) +
631 4*style.horizontalSpacing;
633 pieces = XtWidth(edit.newButton) +
634 XtWidth(edit.grabColor) +
635 3*style.horizontalSpacing;
637 if (XtWidth(edit.main_form) < pieces)
640 XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
641 XtSetArg(args[n], XmNleftWidget, edit.newButton); n++;
642 XtSetValues (edit.grabColor, args, n);
644 scale_width = XtWidth(edit.main_form) - MaxLabelWidth -
645 XtWidth(edit.hueScale) - 4*style.horizontalSpacing;
648 XtSetArg(args[n], XmNscaleWidth, scale_width); n++;
649 XtSetValues (edit.redScale, args, n);
650 XtSetValues (edit.greenScale, args, n);
651 XtSetValues (edit.blueScale, args, n);
652 XtSetValues (edit.satScale, args, n);
653 XtSetValues (edit.valScale, args, n);
658 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
659 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
660 XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
661 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
662 XtSetValues (edit.hueLabel, args, n);
666 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
667 XtSetArg(args[n], XmNtopWidget, edit.hueLabel); n++;
668 XtSetArg(args[n], XmNtopOffset, style.verticalSpacing); n++;
669 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
670 XtSetArg(args[n], XmNbottomOffset,
671 2*(style.verticalSpacing + redScaleHeight) + 40); n++;
672 XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
673 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
674 XtSetValues (edit.hueScale, args, n);
678 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
679 XtSetArg(args[n], XmNtopWidget, edit.hueLabel); n++;
680 TopOffset = style.verticalSpacing + redScaleHeight - redLabelHeight;
681 XtSetArg(args[n], XmNtopOffset, TopOffset); n++;
682 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
683 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
684 XtSetArg(args[n], XmNleftOffset,
685 style.horizontalSpacing + (MaxLabelWidth - redLabelWidth)); n++;
686 XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
687 XtSetValues (edit.redLabel, args, n);
691 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
692 XtSetArg(args[n], XmNtopWidget, edit.redLabel); n++;
693 XtSetArg(args[n], XmNtopOffset, TopOffset); n++;
694 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
695 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
696 XtSetArg(args[n], XmNleftOffset,
697 style.horizontalSpacing + (MaxLabelWidth - greenLabelWidth)); n++;
698 XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
699 XtSetValues (edit.greenLabel, args, n);
703 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
704 XtSetArg(args[n], XmNtopWidget, edit.greenLabel); n++;
705 XtSetArg(args[n], XmNtopOffset, TopOffset); n++;
706 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
707 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
708 XtSetArg(args[n], XmNleftOffset,
709 style.horizontalSpacing + (MaxLabelWidth - blueLabelWidth)); n++;
710 XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
711 XtSetValues (edit.blueLabel, args, n);
713 /* Saturation Label */
715 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
716 XtSetArg(args[n], XmNtopWidget, edit.blueLabel); n++;
717 TopOffset = style.verticalSpacing + 40 + redScaleHeight - satLabelHeight;
718 XtSetArg(args[n], XmNtopOffset, TopOffset); n++;
719 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
720 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
721 XtSetArg(args[n], XmNleftOffset,
722 style.horizontalSpacing + (MaxLabelWidth - satLabelWidth)); n++;
723 XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
724 XtSetValues (edit.satLabel, args, n);
728 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
729 XtSetArg(args[n], XmNtopWidget, edit.satLabel); n++;
730 TopOffset = style.verticalSpacing + redScaleHeight - valLabelHeight;
731 XtSetArg(args[n], XmNtopOffset, TopOffset); n++;
732 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
733 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
734 XtSetArg(args[n], XmNleftOffset,
735 style.horizontalSpacing + (MaxLabelWidth - valLabelWidth)); n++;
736 XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
737 XtSetValues (edit.valLabel, args, n);
741 XtSetArg(args[n], XmNtopAttachment, XmATTACH_NONE); n++;
742 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
743 XtSetArg(args[n], XmNbottomWidget, edit.redLabel); n++;
744 XtSetArg(args[n], XmNbottomOffset, 0); n++;
745 XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
746 XtSetArg(args[n], XmNleftWidget, edit.redLabel); n++;
747 XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
748 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
749 XtSetArg(args[n], XmNrightWidget, edit.hueScale); n++;
750 XtSetValues (edit.redScale, args, n);
754 XtSetArg(args[n], XmNtopAttachment, XmATTACH_NONE); n++;
755 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
756 XtSetArg(args[n], XmNbottomWidget, edit.greenLabel); n++;
757 XtSetArg(args[n], XmNbottomOffset, 0); n++;
758 XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
759 XtSetArg(args[n], XmNleftWidget, edit.redLabel); n++;
760 XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
761 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
762 XtSetArg(args[n], XmNrightWidget, edit.hueScale); n++;
763 XtSetValues (edit.greenScale, args, n);
767 XtSetArg(args[n], XmNtopAttachment, XmATTACH_NONE); n++;
768 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
769 XtSetArg(args[n], XmNbottomWidget, edit.blueLabel); n++;
770 XtSetArg(args[n], XmNbottomOffset, 0); n++;
771 XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
772 XtSetArg(args[n], XmNleftWidget, edit.redLabel); n++;
773 XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
774 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
775 XtSetArg(args[n], XmNrightWidget, edit.hueScale); n++;
776 XtSetValues (edit.blueScale, args, n);
778 /* Saturation Scale */
780 XtSetArg(args[n], XmNtopAttachment, XmATTACH_NONE); n++;
781 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
782 XtSetArg(args[n], XmNbottomWidget, edit.satLabel); n++;
783 XtSetArg(args[n], XmNbottomOffset, 0); n++;
784 XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
785 XtSetArg(args[n], XmNleftWidget, edit.redLabel); n++;
786 XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
787 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
788 XtSetArg(args[n], XmNrightWidget, edit.hueScale); n++;
789 XtSetValues (edit.satScale, args, n);
793 XtSetArg(args[n], XmNtopAttachment, XmATTACH_NONE); n++;
794 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
795 XtSetArg(args[n], XmNbottomWidget, edit.valLabel); n++;
796 XtSetArg(args[n], XmNbottomOffset, 0); n++;
797 XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
798 XtSetArg(args[n], XmNleftWidget, edit.redLabel); n++;
799 XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
800 XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
801 XtSetArg(args[n], XmNrightWidget, edit.hueScale); n++;
802 XtSetValues (edit.valScale, args, n);
804 XtRemoveCallback(edit.DialogShell, XmNmapCallback, sliderLayoutCB, NULL);
809 /************************************************************************
810 * InitializeNewButton()
811 * set NewButton colors to point to the PixelSet being
812 * modified so they both get updated.
813 ************************************************************************/
815 InitializeNewButton( void )
821 XtSetArg(args[n], XmNforeground, edit.color_set->fg.pixel); n++;
822 XtSetArg(args[n], XmNbackground, edit.color_set->bg.pixel); n++;
823 XtSetArg(args[n], XmNarmColor, edit.color_set->sc.pixel); n++;
824 if(UsePixmaps == FALSE)
826 XtSetArg(args[n], XmNtopShadowColor,
827 edit.color_set->ts.pixel); n++;
828 XtSetArg(args[n], XmNbottomShadowColor,
829 edit.color_set->bs.pixel); n++;
831 XtSetValues(edit.newButton,args,n);
835 /************************************************************************
836 * InitializeOldButton()
837 * Called only once from CreateColorEditor. Allocates a
838 * new PixelSet to hold onto the original ColorSet values
839 * while the newButton gets updated. Shouldn't be called if
841 ************************************************************************/
843 InitializeOldButton( void )
845 register int i,n, numOfPixels;
846 unsigned long *pixels;
847 unsigned long plane_mask;
848 int hue, val, sat, status;
850 if(UsePixmaps == FALSE)
851 if(FgColor == DYNAMIC)
853 else /* FgColor == BLACK or WHITE */
855 else /* UsePixmaps == TRUE */
856 if(FgColor == DYNAMIC)
858 else /* FgColor == BLACK or WHITE */
861 /* Allocate enough space to store numOfPixels. */
862 pixels = (unsigned long *)XtMalloc (numOfPixels * sizeof (unsigned long));
864 /* Allocate new color cells for the new button */
865 status = XAllocColorCells (style.display, style.colormap,
866 0, &plane_mask, 0, pixels, numOfPixels);
870 /* Dialog stating that can't allocate enough pixels to color
871 the old button. Just don't create old button.*/
872 edit.oldButtonColor.bg.pixel = edit.color_set->bg.pixel;
873 edit.oldButtonColor.bg.flags = edit.color_set->bg.flags;
874 edit.oldButtonColor.fg.pixel = edit.color_set->fg.pixel;
875 edit.oldButtonColor.fg.flags = edit.color_set->fg.flags;
876 edit.oldButtonColor.sc.pixel = edit.color_set->sc.pixel;
877 edit.oldButtonColor.sc.flags = edit.color_set->sc.flags;
878 edit.oldButtonColor.bs.pixel = edit.color_set->bs.pixel;
879 edit.oldButtonColor.bs.flags = edit.color_set->bs.flags;
880 edit.oldButtonColor.ts.pixel = edit.color_set->ts.pixel;
881 edit.oldButtonColor.ts.flags = edit.color_set->ts.flags;
887 /* Assign the pixels */
889 edit.oldButtonColor.bg.pixel = pixels[n++];
890 edit.oldButtonColor.bg.flags = DoRed | DoGreen | DoBlue;
891 edit.oldButtonColor.sc.pixel = pixels[n++];
892 edit.oldButtonColor.sc.flags = DoRed | DoGreen | DoBlue;
893 if(FgColor == DYNAMIC)
895 edit.oldButtonColor.fg.pixel = pixels[n++];
896 edit.oldButtonColor.fg.flags = DoRed | DoGreen | DoBlue;
900 edit.oldButtonColor.fg.pixel = edit.color_set->fg.pixel;
901 edit.oldButtonColor.fg.flags = edit.color_set->fg.flags;
903 if(UsePixmaps == FALSE)
905 edit.oldButtonColor.bs.pixel = pixels[n++];
906 edit.oldButtonColor.bs.flags = DoRed | DoGreen | DoBlue;
907 edit.oldButtonColor.ts.pixel = pixels[n];
908 edit.oldButtonColor.ts.flags = DoRed | DoGreen | DoBlue;
912 edit.oldButtonColor.bs.pixel = edit.color_set->bs.pixel;
913 edit.oldButtonColor.bs.flags = edit.color_set->bs.flags;
914 edit.oldButtonColor.ts.pixel = edit.color_set->ts.pixel;
915 edit.oldButtonColor.ts.flags = edit.color_set->ts.flags;
919 CopyPixelSet(&edit.oldButtonColor,edit.color_set);
921 RGBtoHSV(edit.oldButtonColor.bg.red,
922 edit.oldButtonColor.bg.green,
923 edit.oldButtonColor.bg.blue,
926 XtFree((char *)pixels);
929 /************************************************************************
931 * Generates new RGB values for fg, ts, bs, sc based on bg.
932 * The Color generation routine will be exported in motif1.1
933 * The generated colors are then used to update the pixels
934 * of the ColorSet being edited.
935 ************************************************************************/
937 GenerateColors( void )
943 if (edit.calcRGB == NULL)
944 edit.calcRGB = XmGetColorCalculation();
946 (*edit.calcRGB) (&edit.color_set->bg, &edit.color_set->fg,
947 &edit.color_set->sc, &edit.color_set->ts,
948 &edit.color_set->bs);
950 RGBtoHSV(edit.color_set->bg.red, edit.color_set->bg.green,
951 edit.color_set->bg.blue,
954 colors[j++] = edit.color_set->bg;
955 colors[j++] = edit.color_set->sc;
957 if (FgColor == DYNAMIC)
958 colors[j++] = edit.color_set->fg;
960 if(UsePixmaps == FALSE)
962 colors[j++] = edit.color_set->ts;
963 colors[j++] = edit.color_set->bs;
967 edit.color_set->ts.red = 65535;
968 edit.color_set->ts.green = 65535;
969 edit.color_set->ts.blue = 65535;
971 edit.color_set->bs.red = 0;
972 edit.color_set->bs.green = 0;
973 edit.color_set->bs.blue = 0;
976 XStoreColors(style.display, style.colormap, colors, j );
979 /************************************************************************
981 * Called when one of the RGB scales is moved
982 ************************************************************************/
986 XtPointer client_data,
987 XtPointer call_data )
993 reason_code = ((XmAnyCallbackStruct *)call_data)->reason;
994 if ( reason_code == XmCR_VALUE_CHANGED || reason_code == XmCR_DRAG )
996 color = (int) client_data;
997 value = ((XmScaleCallbackStruct *)call_data)->value;
999 if (edit.current_scale == NONE)
1001 edit.current_scale = color;
1003 * Shift value -- to make up for scale max of only 0xff
1009 edit.color_set->bg.red = value;
1012 edit.color_set->bg.green = value;
1015 edit.color_set->bg.blue = value;
1018 /* this case should never be hit */
1022 SetScales(&edit.color_set->bg);
1024 edit.current_scale = NONE;
1030 /************************************************************************
1032 * Called when one of the HSV scales is moved
1033 ************************************************************************/
1037 XtPointer client_data,
1038 XtPointer call_data )
1045 reason_code = ((XmAnyCallbackStruct *)call_data)->reason;
1046 if ( reason_code == XmCR_VALUE_CHANGED || reason_code == XmCR_DRAG )
1048 scale = (int) client_data;
1049 value = ((XmScaleCallbackStruct *)call_data)->value;
1051 if (edit.current_scale == NONE)
1053 edit.current_scale = scale;
1058 XmScaleGetValue(edit.satScale, &sat);
1059 XmScaleGetValue(edit.valScale, &val);
1062 XmScaleGetValue(edit.hueScale, &hue);
1064 XmScaleGetValue(edit.valScale, &val);
1067 XmScaleGetValue(edit.hueScale, &hue);
1068 XmScaleGetValue(edit.satScale, &sat);
1072 /* this case should never be hit */
1076 HSVtoRGB(hue, sat, val,
1077 &edit.color_set->bg.red,
1078 &edit.color_set->bg.green,
1079 &edit.color_set->bg.blue);
1081 SetRGBHSVScales(&edit.color_set->bg, hue, sat, val);
1083 edit.current_scale = NONE;
1089 /************************************************************************
1091 * passed a XColor, generates HSV values and updates all scales.
1092 ************************************************************************/
1099 RGBtoHSV(rgb->red, rgb->green, rgb->blue, &h, &s, &v);
1101 SetRGBHSVScales(rgb, h, s, v);
1105 /************************************************************************
1107 * updates RGB and HSV scales
1108 ************************************************************************/
1116 XmScaleSetValue(edit.redScale,rgb->red >> 8);
1117 XmScaleSetValue(edit.greenScale,rgb->green >> 8);
1118 XmScaleSetValue(edit.blueScale,rgb->blue >> 8);
1120 XmScaleSetValue(edit.hueScale,h);
1121 XmScaleSetValue(edit.satScale,s);
1122 XmScaleSetValue(edit.valScale,v);
1126 /************************************************************************
1129 ************************************************************************/
1132 ColorSet *color_set_dest,
1133 ColorSet *color_set_src )
1140 color_set_dest->bg.red = color_set_src->bg.red;
1141 color_set_dest->bg.blue = color_set_src->bg.blue;
1142 color_set_dest->bg.green = color_set_src->bg.green;
1144 color_set_dest->bg.pixel = color_set_src->bg.pixel;
1145 colors[j++] = color_set_dest->bg;
1147 color_set_dest->sc.red = color_set_src->sc.red;
1148 color_set_dest->sc.blue = color_set_src->sc.blue;
1149 color_set_dest->sc.green = color_set_src->sc.green;
1151 color_set_dest->bg.pixel = color_set_src->bg.pixel;
1152 colors[j++] = color_set_dest->sc;
1154 color_set_dest->fg.red = color_set_src->fg.red;
1155 color_set_dest->fg.blue = color_set_src->fg.blue;
1156 color_set_dest->fg.green = color_set_src->fg.green;
1157 if(FgColor == DYNAMIC)
1160 color_set_dest->bg.pixel = color_set_src->bg.pixel;
1161 colors[j++] = color_set_dest->fg;
1164 color_set_dest->ts.red = color_set_src->ts.red;
1165 color_set_dest->ts.blue = color_set_src->ts.blue;
1166 color_set_dest->ts.green = color_set_src->ts.green;
1167 color_set_dest->bs.red = color_set_src->bs.red;
1168 color_set_dest->bs.blue = color_set_src->bs.blue;
1169 color_set_dest->bs.green = color_set_src->bs.green;
1170 if(UsePixmaps == FALSE)
1173 color_set_dest->bg.pixel = color_set_src->bg.pixel;
1174 colors[j++] = color_set_dest->ts;
1175 colors[j++] = color_set_dest->bs;
1177 if(OldNewSame && edit.oldButton != NULL)
1180 XtSetArg(args[n], XmNforeground, color_set_dest->fg.pixel); n++;
1181 XtSetArg(args[n], XmNbackground, color_set_dest->bg.pixel); n++;
1182 XtSetArg(args[n], XmNarmColor, color_set_dest->sc.pixel); n++;
1183 XtSetArg(args[n], XmNtopShadowColor,
1184 color_set_dest->ts.pixel); n++;
1185 XtSetArg(args[n], XmNbottomShadowColor,
1186 color_set_dest->bs.pixel); n++;
1188 XtSetValues(edit.oldButton, args, n);
1191 XStoreColors(style.display, style.colormap, colors, j );
1196 /************************************************************************
1199 ************************************************************************/
1202 #if NeedWidePrototypes
1215 double red, green, blue;
1216 double red1, green1, blue1;
1217 double hue, saturation, value;
1221 red1 = (double)r / 65280.0;
1222 green1 = (double)g / 65280.0;
1223 blue1 = (double)b / 65280.0;
1225 value = max(red1, green1, blue1);
1226 base = min(red1, green1, blue1);
1229 saturation = (value - base) / value;
1235 if( saturation != 0.0 )
1237 red = (value - red1 ) / (value - base);
1238 green = (value - green1 ) / (value - base);
1239 blue = (value - blue1 ) / (value - base);
1248 else if(value == green1)
1268 *s = ((int)(saturation * 65280.0)) >> 8;
1269 *v = ((int)(value * 65280.0)) >> 8;
1272 /************************************************************************
1275 * Converts hue, saturation, and value to RGB values.
1276 * Hue is in the range 0 to 360, while saturation and value
1277 * are in the range 0 to 255
1278 ************************************************************************/
1289 double hue, sat, val;
1290 double red, green, blue;
1293 hue = (double)h / 60.0;
1297 val = (double)v / 255.0;
1298 sat = (double)s / 255.0;
1300 p1 = val * (1.0 - sat);
1301 p2 = val * (1.0 -(sat * f));
1302 p3 = val * (1.0 -(sat * (1.0 - f)));
1338 *r = (int)(red * 65280.0);
1339 *g = (int)(green * 65280.0);
1340 *b = (int)(blue * 65280.0);
1345 /************************************************************************
1348 ************************************************************************/
1355 if(x >= y && x >= z)
1358 if(y >= z && y >= x)
1361 if(z >= y && z >= x)
1365 /************************************************************************
1368 ************************************************************************/
1375 if(x <= y && x <= z)
1378 if(y <= z && y <= x)
1381 if(z <= y && z <= x)
1385 /************************************************************************
1387 * Call back routine for grabbing a color from the screen
1388 ************************************************************************/
1392 XtPointer client_data,
1393 XtPointer call_data )
1395 Cursor cursor = XCreateFontCursor(style.display, XC_crosshair);
1401 char color_string[MAX_STR_LEN];
1403 Boolean notDone=True;
1406 /* grab the pointer using target cursor */
1407 status = XtGrabPointer(style.colorDialog, TRUE,
1408 ButtonPressMask | ButtonReleaseMask,
1409 GrabModeAsync, GrabModeAsync, None,
1410 cursor, CurrentTime);
1411 if (status != GrabSuccess)
1413 _DtSimpleError (progName, DtWarning, NULL,
1414 ((char *)GETMESSAGE(17, 14, "Warning, couldn't grab pointer.\n")), NULL);
1418 /* grab the keyboard so we can get the ESC button press */
1419 status = XtGrabKeyboard(style.colorDialog, False, GrabModeAsync,
1420 GrabModeAsync, CurrentTime);
1421 if (status != GrabSuccess)
1423 XtUngrabPointer (style.colorDialog, CurrentTime);
1424 _DtSimpleError (progName, DtWarning, NULL,
1425 ((char *)GETMESSAGE(17, 15, "Warning, couldn't grab Keyboard.\n")), NULL);
1431 XtNextEvent(&event);
1433 switch (event.type) {
1440 /* look for ESC key press and stop if we get one */
1441 if( event.xkey.state & ShiftMask)
1446 keySym = XLookupKeysym((XKeyEvent *)&event, offset);
1447 if (keySym == XK_Escape)
1449 XtUngrabKeyboard (style.colorDialog, CurrentTime);
1450 XtUngrabPointer (style.colorDialog, CurrentTime);
1454 XtDispatchEvent(&event);
1458 XtUngrabKeyboard (style.colorDialog, CurrentTime);
1459 XtUngrabPointer (style.colorDialog, CurrentTime);
1461 x = (Position)event.xbutton.x_root;
1462 y = (Position)event.xbutton.y_root;
1463 image_ptr = XGetImage (style.display, style.root, x, y, 1, 1,
1464 AllPlanes, ZPixmap);
1465 pixel = (Pixel) XGetPixel (image_ptr, 0, 0);
1466 XDestroyImage (image_ptr);
1468 colorStruct.pixel = pixel;
1470 XQueryColor (style.display, style.colormap, &colorStruct);
1472 edit.color_set->bg.red = colorStruct.red;
1473 edit.color_set->bg.green = colorStruct.green;
1474 edit.color_set->bg.blue = colorStruct.blue;
1476 SetScales(&edit.color_set->bg);
1481 /************************************************************************
1484 ************************************************************************/
1488 char *color_string )
1492 from.size = strlen(color_string) + 1;
1493 if (from.size < sizeof(String))
1494 from.size = sizeof(String);
1495 from.addr = color_string;
1496 XtConvert(widget, XmRString, &from, XmRPixel, &to);
1498 return ((Pixel) *((Pixel *) to.addr));
1505 ** Process callback from the Ok, Cancel and Help pushButtons in the
1511 XtPointer client_data,
1512 XtPointer call_data )
1514 palette *tmp_palette;
1515 DtDialogBoxCallbackStruct *cb = (DtDialogBoxCallbackStruct *) call_data;
1517 switch (cb->button_position)
1521 WriteOutPalette( pCurrentPalette->name);
1523 if(strcmp(pCurrentPalette->name, defaultName) == 0)
1525 UpdateDefaultPalette();
1529 XtUnmanageChild(edit.DialogShell);
1533 CopyPixelSet(edit.color_set, &edit.oldButtonColor);
1534 XtUnmanageChild(edit.DialogShell);
1538 XtCallCallbacks(edit.DialogShell, XmNhelpCallback, (XtPointer)NULL);
1548 /************************************************************************
1551 ************************************************************************/
1555 XtPointer client_data,
1556 XtPointer call_data )
1560 Dimension editWidth,editHeight;
1561 Dimension width,height;
1564 XtWidgetGeometry reply;
1565 Widget parent = (Widget) client_data;
1568 DtWsmRemoveWorkspaceFunctions(style.display, XtWindow(XtParent(w)));
1570 if (!save.restoreFlag)
1572 /* get x,y,width,height of parent shell */
1574 x = XtX(XtParent(parent));
1575 y = XtY(XtParent(parent));
1576 height = XtHeight(parent);
1577 width = XtWidth(parent);
1579 editHeight = XtHeight(edit.DialogShell);
1580 editWidth = XtWidth(edit.DialogShell);
1582 newX = x + width/2 - editWidth/2;
1585 newY = y + height/2 - editHeight;
1590 XtSetArg(args[n], XmNx, newX); n++;
1591 XtSetArg(args[n], XmNy, newY); n++;
1592 XtSetValues(edit.DialogShell,args,n);
1596 XtRemoveCallback(edit.DialogShell, XmNmapCallback, _DtmapCB, NULL);
1601 /****************************************************
1602 * restoreColor(shell, db)
1603 * restore any state information saved with saveColor.
1604 * This is called from restoreSession with the application shell
1605 * and the special xrm database retrieved for restore.
1606 ****************************************************/
1613 XrmName xrm_name[5];
1614 XrmRepresentation rep_type;
1617 xrm_name [0] = XrmStringToQuark ("colorEditDlg");
1620 /* get x position */
1621 xrm_name [1] = XrmStringToQuark ("x");
1622 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
1623 XtSetArg (save.posArgs[save.poscnt], XmNx, atoi((char *)value.addr)); save.poscnt++;
1624 save.restoreFlag = True;
1627 /* get y position */
1628 xrm_name [1] = XrmStringToQuark ("y");
1629 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
1630 XtSetArg (save.posArgs[save.poscnt], XmNy, atoi((char *)value.addr)); save.poscnt++;
1633 /*Collect any other parameters you saved into static variables.*/
1635 xrm_name [1] = XrmStringToQuark ("ismapped");
1636 XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
1637 /* Are we supposed to be mapped? */
1638 if (strcmp(value.addr, "True") == 0)
1639 XtCallCallbacks(modifyColorButton, XmNactivateCallback, NULL);
1643 /****************************************************
1645 * This routine will write out to the passed file descriptor any state
1646 * information this dialog needs. It is called from saveSessionCB with
1647 * the file already opened.
1648 * All information is saved in xrm format. There is no restriction
1649 * on what can be saved. It doesn't have to be defined or be part of any
1650 * widget or Xt definition. Just name and save it here and recover it in
1651 * restoreColor. The suggested minimum is whether you are mapped, and your
1653 *****************************************************/
1659 char *bufr = style.tmpBigStr; /* size=[1024], make bigger if needed */
1660 XmVendorShellExtObject vendorExt;
1661 XmWidgetExtData extData;
1663 if (edit.DialogShell != NULL)
1665 if (XtIsManaged(edit.DialogShell))
1666 sprintf(bufr, "*colorEditDlg.ismapped: True\n");
1668 sprintf(bufr, "*colorEditDlg.ismapped: False\n");
1670 /* Get and write out the geometry info for our Window */
1671 x = XtX(XtParent(edit.DialogShell));
1672 y = XtY(XtParent(edit.DialogShell));
1674 /* Modify x & y to take into account window mgr frames
1675 * This is pretty bogus, but I don't know a better way to do it.
1677 extData = _XmGetWidgetExtData(style.shell, XmSHELL_EXTENSION);
1678 vendorExt = (XmVendorShellExtObject)extData->widget;
1679 x -= vendorExt->vendor.xOffset;
1680 y -= vendorExt->vendor.yOffset;
1682 sprintf(bufr, "%s*colorEditDlg.x: %d\n", bufr, x);
1683 sprintf(bufr, "%s*colorEditDlg.y: %d\n", bufr, y);
1684 /*any other parameter you want to save goes here*/
1685 write (fd, bufr, strlen(bufr));