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 /************************************<+>*************************************
24 ****************************************************************************
30 ** Description: Controls the Dtstyle Color dialog
33 ** (c) Copyright Hewlett-Packard Company, 1990.
37 ****************************************************************************
38 ************************************<+>*************************************/
39 /* $TOG: ColorMain.c /main/8 1998/01/12 10:41:53 cshi $ */
40 /*+++++++++++++++++++++++++++++++++++++++*/
42 /*+++++++++++++++++++++++++++++++++++++++*/
44 #include "/sys5/usr/include/limits.h"
45 #else /* common default */
51 #include <X11/Intrinsic.h>
53 #include <Xm/MwmUtil.h>
61 #include <Xm/MessageB.h>
62 #include <Xm/Protocols.h>
64 #include <Xm/PushBG.h>
65 #include <Xm/ToggleBG.h>
66 #include <Xm/RowColumn.h>
67 #include <Xm/SelectioB.h>
69 #include <Xm/VendorSEP.h>
71 #include <Dt/DialogBox.h>
73 #include <Dt/TitleBox.h>
75 #include <Dt/HourGlass.h>
79 #include "SaveRestore.h"
80 #include "ColorMain.h"
81 #include "ColorFile.h"
82 #include "ColorEdit.h"
88 /*+++++++++++++++++++++++++++++++++++++++*/
89 /* include extern functions */
90 /*+++++++++++++++++++++++++++++++++++++++*/
93 /*+++++++++++++++++++++++++++++++++++++++*/
95 /*+++++++++++++++++++++++++++++++++++++++*/
96 #define DEFAULT_PALETTE "Default"
97 #define TYPE_OF_MONITOR "Type Of Monitor" /* also in dtsession/SrvPalette.c */
99 #define BORDER_WIDTH 3
100 #define COLOR_BUTTON_WIDTH 35
101 #define COLOR_BUTTON_HEIGHT 35
102 #define ADD_PALETTE_TOP_OFFSET 20
103 #define ADD_PALETTE_LEFT_POSITION 65
104 #define PALETTE_RC_RIGHT_POSITION 60
106 #define DEFAULT_COLOR (XmCO_HIGH_COLOR + 1)
108 #define B_W_STR "B_W"
109 #define LOW_COLOR_STR "LOW_COLOR"
110 #define MEDIUM_COLOR_STR "MEDIUM_COLOR"
111 #define HIGH_COLOR_STR "HIGH_COLOR"
112 #define DEFAULT_COLOR_STR "DEFAULT"
114 #define STR1 ((char *)GETMESSAGE(14, 29, "A palette named '%s' already exists.\nThis new palette will overwrite the old one.\nIs this what you want to do?"))
115 #define STR2 ((char *)GETMESSAGE(14, 23, "Delete palette '%s'?\n"))
116 #define NEXT_SESSION ((char *)GETMESSAGE(14, 28, "The selected palette will take effect\nat your next session."))
117 #define CANT_DELETE ((char *)GETMESSAGE(14, 18, "Can't delete the last palette.\n"))
118 #define COLORUSE_WHEN ((char *)GETMESSAGE(14, 27, "The new Color Use value will take effect\nat your next session."))
120 /*+++++++++++++++++++++++++++++++++++++++*/
122 /*+++++++++++++++++++++++++++++++++++++++*/
128 Widget addPaletteButton;
129 Widget deletePaletteButton;
133 Widget mediumColorTG;
139 char *currentColorUseStr;
143 /*+++++++++++++++++++++++++++++++++++++++*/
144 /* Internal Functions */
145 /*+++++++++++++++++++++++++++++++++++++++*/
147 static int CreateMainWindow( Widget parent) ;
148 static void selectPaletteCB(
150 XtPointer client_data,
151 XtPointer call_data) ;
152 static void selectColorCB(
154 XtPointer client_data,
155 XtPointer call_data) ;
156 static void timeoutCB(
157 XtPointer client_data,
159 static void addPaletteCB(
161 XtPointer client_data,
162 XtPointer call_data) ;
163 static void addCancelCB(
165 XtPointer client_data,
166 XtPointer call_data) ;
169 XtPointer client_data,
170 XtPointer call_data) ;
171 static void setDlgOkCB(
173 XtPointer client_data,
174 XtPointer call_data) ;
175 static void modifyColorCB(
177 XtPointer client_data,
178 XtPointer call_data) ;
179 static void dialogBoxCB(
181 XtPointer client_data,
182 XtPointer call_data) ;
184 palette *newPalette) ;
185 static void deletePaletteCB(
187 XtPointer client_data,
188 XtPointer call_data) ;
189 static void deleteOkCB(
191 XtPointer client_data,
192 XtPointer call_data) ;
193 static void deleteCancelCB(
195 XtPointer client_data,
196 XtPointer call_data) ;
197 static void resourcesCB(
199 XtPointer client_data,
200 XtPointer call_data) ;
201 static void colorUseCB(
203 XtPointer client_data,
204 XtPointer call_data) ;
205 static void colorUseExitCB(
207 XtPointer client_data,
208 XtPointer call_data) ;
209 static void activateCBexitColor(
211 XtPointer client_data,
212 XtPointer call_data) ;
213 static void _DtmapCB(
215 XtPointer client_data,
216 XtPointer call_data) ;
217 static void _DtmapCB_colorUse(
219 XtPointer client_data,
220 XtPointer call_data) ;
221 static Boolean ValidName( char *name) ;
226 /*+++++++++++++++++++++++++++++++++++++++*/
227 /* Global Variables */
228 /*+++++++++++++++++++++++++++++++++++++++*/
231 Atom XA_TYPE_MONITOR;
233 /* Palettes exist in a linked list. */
234 palette *pHeadPalette;
235 palette *pCurrentPalette;
236 palette *pOldPalette;
238 Widget modifyColorButton;
248 /*+++++++++++++++++++++++++++++++++++++++*/
249 /* Internal Variables */
250 /*+++++++++++++++++++++++++++++++++++++++*/
252 /* palette names without the .dp */
253 static char *WHITE_BLACK = "WhiteBlack";
254 static char *BLACK_WHITE = "BlackWhite";
255 static char *WHITE_ONLY = "White";
256 static char *BLACK_ONLY = "Black";
258 static char *PALETTEDLG = "paletteDlg";
259 static saveRestore save = {FALSE, 0, };
261 static Widget colorButton[XmCO_MAX_NUM_COLORS];
262 static Widget addDialog;
263 static Widget deleteDialog;
264 static Widget colorUseDialog;
265 static palette OrgPalette;
266 static XtIntervalId timeID;
267 static int dclick_time;
268 static int selected_button;
269 static int selected_position;
270 static Atom XA_WM_DELETE_WINDOW;
271 static char defaultName_restore[50];
272 static palette *loop_palette, *loop_palette2;
273 static int loopcount = 0;
274 static colorWidgets colorDialog;
275 static Widget gParent;
279 * copy of the system palette description file for the
280 * current locale in xrm form
282 XrmDatabase sys_pl_DB = NULL;
285 * copy of the admin palette description file for the
286 * current locale in xrm form
288 XrmDatabase adm_pl_DB = NULL;
291 * final combination of the admin & system dta bases
293 XrmDatabase pl_DB = NULL;
296 * copy of the palette description file from the user's home
297 * directory. This database is locale independent and will always
300 XrmDatabase hm_pl_DB = NULL;
310 /* load the palette description data base for the given locale*/
311 /* from that locale's description file from the system location */
313 lang = setlocale (LC_CTYPE,NULL);
315 #ifdef hpux /* hpux-specific parsing of the locale string */
316 /* The following code is identical to the
317 ExtractLocaleName function in WmResParse.c
320 #define MAXLOCALE 64 /* buffer size of locale name */
325 static char buf[MAXLOCALE];
327 /* If lang has a substring ":<category>;", extract <category>
328 * from the first such occurrence as the locale name.
332 if (start = strchr (lang, ':')) {
334 if (end = strchr (start, ';')) {
336 strncpy(buf, start, len);
344 pl_desc = (char *)XtMalloc(strlen("/usr/dt/palettes/desc.") + strlen(lang) + 1);
345 strcpy (pl_desc,"/usr/dt/palettes/desc.");
346 strcat (pl_desc, lang);
347 if(sys_pl_DB = XrmGetFileDatabase (pl_desc))
348 XrmMergeDatabases(sys_pl_DB, &pl_DB);
351 /* load the palette description data base for the given locale*/
352 /* from that locale's description file from the admin location */
353 pl_desc = (char *)XtMalloc(strlen("/etc/dt/palettes/desc.") + strlen(lang) + 1);
354 strcpy (pl_desc,"/etc/dt/palettes/desc.");
355 strcat (pl_desc, lang);
356 if (adm_pl_DB = XrmGetFileDatabase (pl_desc))
357 XrmMergeDatabases(adm_pl_DB, &pl_DB);
360 /* load the palette description data base regardless of locale*/
361 pl_desc = (char *) XtMalloc(strlen(style.home) +(strlen("/.dt/palettes/desc.palettes") + 1));
362 strcpy (pl_desc, style.home);
363 strcat (pl_desc, "/.dt/palettes/desc.palettes");
364 if (hm_pl_DB = XrmGetFileDatabase (pl_desc))
365 XrmMergeDatabases(hm_pl_DB, &pl_DB);
368 /* load the palette description data base regardless of locale for later use*/
369 pl_desc = (char *) XtMalloc(strlen(style.home) +(strlen("/.dt/palettes/desc.palettes") + 1));
370 strcpy (pl_desc, style.home);
371 strcat (pl_desc, "/.dt/palettes/desc.palettes");
372 if (XrmCombineFileDatabase (pl_desc, &pl_DB, True))
373 /* load a separate home data base to be later saved as a file */
374 /* if any palettes are added */
375 hm_pl_DB = XrmGetFileDatabase (pl_desc);
388 ** Main routine does the following:
389 ** 1. Creates the color dialog shell
390 ** 2. Checks which monitor the customizer is running on
391 ** 3. Initialize color palettes
395 /* can the user access the Color portion of Style? */
397 /* Not if Color Server is not running */
398 if (style.colorSrv == FALSE)
400 ErrDialog(((char *)GETMESSAGE(14, 25, "The color portion of the Style Manager\nwill not operate because the color server\nis not running. Check $HOME/.dt/errorlog.")), style.shell);
404 /* Not if useColorObj resource is False. XmeUseColorObj will return false
405 if color server is not running or if the resource UseColorObj is False.
406 If the color server is not running, that case is caught above so if
407 we get here, the resource UseColorObj must be False. This is an
408 undocumented resource. */
410 if (XmeUseColorObj() == FALSE)
412 ErrDialog(((char *)GETMESSAGE(14, 26, "The color portion of the Style Manager\nwill not operate because the resource\n'useColorObj' is set to False.")), style.shell);
416 if (style.colorDialog == NULL || style.count < 12)
418 _DtTurnOnHourGlass(shell);
420 /* Create Main Color Dialog */
421 if(CreateMainWindow(shell) == -1)
423 _DtTurnOffHourGlass(shell);
426 XtManageChild(style.colorDialog);
428 _DtTurnOffHourGlass(shell);
432 XtManageChild(style.colorDialog);
434 raiseWindow(XtWindow(XtParent(style.colorDialog)));
437 /* also determine if system uses long filenames, used by add palette only */
445 ** This routine creates the Color Customizer Main Window. It is passed
446 ** the top level shell.
453 /* Create the DialogBox dialog */
454 CreateDialogBoxD(parent);
456 /* add some more to the dialog box */
459 /* Create the top part of the color dialog */
463 /* read in palettes */
464 ReadInPalettes(style.xrdb.paletteDir);
466 if (NumOfPalettes == 0)
468 /* error dialog - no palettes */
469 ErrDialog(((char *)GETMESSAGE(14, 38, "The color portion of the Style Manager\n\
470 will not operate because there are no palette\n\
471 files available. Check $HOME/.dt/errorlog.")), style.shell);
475 /* go get the list of palettes of the color dialog */
476 InitializePaletteList(parent,paletteList, False);
478 /* Allocate the pixels for the Current palette.
479 * Will get the pixel values from the color server.
481 AllocatePaletteCells(parent);
483 /* go create the bottom portion of the color dialog */
487 ** Create the color buttons. Have to do it after
488 ** initialize palettes so the correct pixels would be used.
490 CreatePaletteButtons(style.buttonsForm);
498 CreatePaletteButtons(
510 if (TypeOfMonitor == XmCO_BLACK_WHITE) /* create pixmaps for top/bottom shadow */
512 edit.pixmap25 = XmGetPixmap (style.screen, "25_foreground",
513 BlackPixelOfScreen(style.screen),
514 WhitePixelOfScreen(style.screen));
515 edit.pixmap75 = XmGetPixmap (style.screen, "75_foreground",
516 BlackPixelOfScreen(style.screen),
517 WhitePixelOfScreen(style.screen));
519 pixmap100 = XmGetPixmap (style.screen, "background",
520 BlackPixelOfScreen(style.screen),
521 pCurrentPalette->color[pCurrentPalette->active].bg.pixel);
523 XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
524 XtSetArg (args[n], XmNtopOffset, 0); n++;
525 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
526 XtSetArg (args[n], XmNleftOffset, 0); n++;
527 XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
528 XtSetArg (args[n], XmNrightPosition, PALETTE_RC_RIGHT_POSITION); n++;
529 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
530 XtSetArg (args[n], XmNbottomOffset, 0); n++;
531 XtSetArg (args[n], XmNspacing, 0); n++;
532 XtSetArg (args[n], XmNmarginWidth, style.horizontalSpacing); n++;
533 XtSetArg (args[n], XmNmarginHeight, style.verticalSpacing); n++;
534 XtSetArg (args[n], XmNorientation, XmHORIZONTAL); n++;
535 XtSetArg (args[n], XmNpacking, XmPACK_COLUMN); n++;
536 XtSetArg (args[n], XmNadjustLast, False); n++;
537 if(TypeOfMonitor == XmCO_HIGH_COLOR)
539 XtSetArg (args[n], XmNnumColumns, 2); n++;
543 XtSetArg (args[n], XmNnumColumns, 1); n++;
545 paletteRc = XmCreateRowColumn(parent, "paletteRc", args, n);
546 XtManageChild(paletteRc);
548 for (i=0; i<XmCO_MAX_NUM_COLORS; i++)
551 XtSetArg (args[n], XmNrecomputeSize, False); n++;
552 XtSetArg (args[n], XmNwidth, COLOR_BUTTON_WIDTH); n++;
553 XtSetArg (args[n], XmNheight, COLOR_BUTTON_HEIGHT); n++;
554 /* allow traversal only if dynamicColor is on */
555 if (!style.dynamicColor)
557 XtSetArg (args[n], XmNtraversalOn, False); n++;
559 XtSetArg (args[n], XmNborderWidth, BORDER_WIDTH); n++;
560 XtSetArg (args[n], XmNborderColor,
561 pCurrentPalette->color[pCurrentPalette->secondary].bg.pixel); n++;
562 XtSetArg (args[n], XmNforeground,
563 pCurrentPalette->color[i].fg.pixel); n++;
564 XtSetArg (args[n], XmNbackground,
565 pCurrentPalette->color[i].bg.pixel); n++;
566 XtSetArg (args[n], XmNarmColor, pCurrentPalette->color[i].sc.pixel); n++;
567 XtSetArg (args[n], XmNmultiClick, XmMULTICLICK_KEEP); n++;
568 if (TypeOfMonitor == XmCO_LOW_COLOR)
570 XtSetArg (args[n], XmNhighlightColor,
571 pCurrentPalette->color[pCurrentPalette->secondary].fg.pixel); n++;
575 XtSetArg (args[n], XmNhighlightPixmap, pixmap100); n++;
577 if(UsePixmaps == FALSE && TypeOfMonitor != XmCO_BLACK_WHITE)
579 XtSetArg (args[n], XmNtopShadowColor,
580 pCurrentPalette->color[i].ts.pixel); n++;
581 XtSetArg (args[n], XmNbottomShadowColor,
582 pCurrentPalette->color[i].bs.pixel); n++;
584 else if (TypeOfMonitor == XmCO_BLACK_WHITE)
586 XtSetArg (args[n], XmNtopShadowPixmap, edit.pixmap25); n++;
587 XtSetArg (args[n], XmNbottomShadowPixmap, edit.pixmap75); n++;
589 string = CMPSTR(" ");
590 XtSetArg (args[n], XmNlabelString, string); n++;
591 colorButton[i] = XmCreatePushButton(paletteRc, "colorButton", args, n);
592 /* allow access to modify functionality only if dynamicColor is on */
593 if (style.dynamicColor)
594 XtAddCallback(colorButton[i], XmNactivateCallback, selectColorCB,
596 XmStringFree(string);
598 XtManageChildren(colorButton,pCurrentPalette->num_of_colors);
600 if(!save.restoreFlag)
603 /* draw selection border only if dynamicColor is on */
604 if (style.dynamicColor)
607 XtSetArg (args[n], XmNborderColor, BlackPixelOfScreen(style.screen)); n++;
608 XtSetValues(colorButton[selected_button],args,n);
615 InitializePaletteList(
618 #if NeedWidePrototypes
627 XmStringTable string_table;
630 char *str_type_return;
631 XrmValue value_return;
637 ** Add the palettes read in from ReadInPalettes
640 if (TypeOfMonitor != XmCO_BLACK_WHITE) {
641 loop_palette = pHeadPalette;
642 loop_palette2 = pHeadPalette;
645 loop_palette = pHeadPalette;
646 loop_palette2 = NULL;
647 while(loop_palette != NULL)
648 if(strcmp(loop_palette->name, "Black") == 0) {
649 loop_palette2 = loop_palette;
653 loop_palette = loop_palette->next;
654 loop_palette = pHeadPalette;
655 if(loop_palette2 == NULL)
656 loop_palette2 = pHeadPalette;
659 while( loop_palette != NULL)
663 name_str = (char *) XtMalloc(strlen("palettes.") +
664 strlen(loop_palette->name) +
665 strlen(".desc") + 1);
667 class_str = (char *) XtMalloc(strlen("Palettes.") +
668 strlen(loop_palette->name) +
669 strlen(".Desc") + 1);
670 strcpy(name_str, "palettes.");
671 strcpy(class_str, "Palettes.");
672 strcat(name_str, loop_palette->name);
673 strcat(class_str, loop_palette->name);
674 strcat(name_str, ".desc");
675 strcat(class_str, ".Desc");
677 if (XrmGetResource (pl_DB, name_str, class_str, &str_type_return, &value_return))
679 loop_palette->desc = (char *)XtMalloc(strlen (value_return.addr) + 1 );
680 strcpy(loop_palette->desc, value_return.addr);
684 loop_palette->desc = (char *)XtMalloc(strlen (loop_palette->name) + 1 );
685 strcpy(loop_palette->desc, loop_palette->name);
692 loop_palette->desc = (char *)XtMalloc(strlen (loop_palette->name) + 1 );
693 strcpy(loop_palette->desc, loop_palette->name);
696 XmListAddItem(list, CMPSTR(loop_palette->desc), loop_palette->item_position);
698 /* if the item is the same as the default name provided by the
699 color Server, save it */
700 if(!save.restoreFlag || defaultName_restore == NULL) {
701 if (!(strcmp(loop_palette->name, defaultName)))
702 loop_palette2 = loop_palette;
705 if (!(strcmp(loop_palette->name, defaultName_restore)))
706 loop_palette2 = loop_palette;
708 loop_palette = loop_palette->next;
710 if((loopcount % 5 == 0) && startup)
717 ** Make the palette named by the color Server the selected palette, if the
718 ** palette returned by the color server doesn't match make it the head
723 /* the default name is the name to be selected */
724 if (loop_palette2->name == NULL)
727 string = CMPSTR(loop_palette2->desc);
728 string_table = &string;
731 XtSetArg (args[n], XmNselectedItemCount, 1); n++;
732 XtSetArg (args[n], XmNselectedItems, string_table); n++;
733 XtSetValues (list, args, n);
734 XmStringFree(string);
736 XmListSetPos(list, loop_palette2->item_position);
739 pCurrentPalette = loop_palette2;
740 selected_position = pCurrentPalette->item_position;
747 ** This is the selection callback for the Scrolled list.
748 ** The routine finds the item the user selected and changes
749 ** the already allocated pixels to the colors of the selected palette.
754 XtPointer client_data,
755 XtPointer call_data )
759 XmListCallbackStruct *cb = (XmListCallbackStruct *)call_data;
760 palette *tmp_palette;
763 static unsigned long pixels[XmCO_MAX_NUM_COLORS*5];
765 static Boolean First = True;
768 white = WhitePixelOfScreen(style.screen);
769 black = BlackPixelOfScreen(style.screen);
771 if (((edit.DialogShell == NULL) || (!XtIsManaged(edit.DialogShell))) &&
772 selected_position != cb->item_position)
774 selected_position = cb->item_position;
776 tmp_palette = pHeadPalette;
777 while( tmp_palette->item_position != selected_position &&
779 tmp_palette = tmp_palette->next;
781 if(tmp_palette->item_position == selected_position)
783 pOldPalette = pCurrentPalette;
784 pCurrentPalette = tmp_palette;
787 string = CMPSTR(pCurrentPalette->desc);
788 XtSetArg (args[n], XmNtitleString, string); n++;
789 XtSetValues (colorDialog.buttonsTB, args, n);
790 XmStringFree(string);
792 if (style.dynamicColor)
796 /* PUT DIALOG saying can't dynamically change */
799 InfoDialog(NEXT_SESSION, style.colorDialog, False);
804 if (TypeOfMonitor != XmCO_BLACK_WHITE)
806 /* free the cells from last selection */
807 XFreeColors(style.display, style.colormap, pixels,
811 if (TypeOfMonitor != XmCO_BLACK_WHITE)
813 /* allocate new colors */
816 for (i=0; i<pCurrentPalette->num_of_colors; i++)
819 if (XAllocColor(style.display, style.colormap,
820 &(pCurrentPalette->color[i].bg)) == 0)
822 pixels[count++] = pCurrentPalette->color[i].bg.pixel;
823 XtSetArg (args[n], XmNbackground,
824 pCurrentPalette->color[i].bg.pixel); n++;
826 if (XAllocColor(style.display, style.colormap,
827 &(pCurrentPalette->color[i].sc)) == 0)
829 pixels[count++] = pCurrentPalette->color[i].sc.pixel;
830 XtSetArg (args[n], XmNarmColor,
831 pCurrentPalette->color[i].sc.pixel); n++;
833 if (UsePixmaps == FALSE)
835 if (XAllocColor(style.display, style.colormap,
836 &(pCurrentPalette->color[i].ts)) == 0)
838 pixels[count++] = pCurrentPalette->color[i].ts.pixel;
839 XtSetArg (args[n], XmNtopShadowColor,
840 pCurrentPalette->color[i].ts.pixel); n++;
842 if (XAllocColor(style.display, style.colormap,
843 &(pCurrentPalette->color[i].bs)) == 0)
845 pixels[count++] = pCurrentPalette->color[i].bs.pixel;
846 XtSetArg (args[n], XmNbottomShadowColor,
847 pCurrentPalette->color[i].bs.pixel); n++;
849 else /* create pixmaps for top/bottom shadow */
851 XmDestroyPixmap(style.screen, edit.pixmap25);
852 XmDestroyPixmap(style.screen, edit.pixmap75);
854 edit.pixmap25 = XmGetPixmap (style.screen,
856 pCurrentPalette->color[i].bg.pixel,
857 WhitePixelOfScreen(style.screen));
859 edit.pixmap75 = XmGetPixmap (style.screen,
861 pCurrentPalette->color[i].bg.pixel,
862 BlackPixelOfScreen(style.screen));
864 XtSetArg (args[n], XmNtopShadowPixmap, edit.pixmap25);
866 XtSetArg (args[n], XmNbottomShadowPixmap, edit.pixmap75);
870 XtSetValues(colorButton[i], args, n);
873 else /* XmCO_BLACK_WHITE */
875 /* set color buttons for new palette - read only cells */
876 /* primary=color[1] secondary=color[0] */
877 if (strcmp(pCurrentPalette->name, WHITE_BLACK) == 0)
879 n=0; /* secondary color white */
880 XtSetArg (args[n], XmNforeground, black); n++;
881 XtSetArg (args[n], XmNbackground, white); n++;
882 XtSetArg (args[n], XmNarmColor, white); n++;
883 XtSetValues(colorButton[0], args, n);
884 pCurrentPalette->color[0].fg.pixel = black;
885 pCurrentPalette->color[0].bg.pixel = white;
886 pCurrentPalette->color[0].sc.pixel = white;
887 pCurrentPalette->color[0].ts.pixel = black;
888 pCurrentPalette->color[0].bs.pixel = black;
890 n=0; /* primary color black */
891 XtSetArg (args[n], XmNforeground, white); n++;
892 XtSetArg (args[n], XmNbackground, black); n++;
893 XtSetArg (args[n], XmNarmColor, black); n++;
894 XtSetValues(colorButton[1], args, n);
895 pCurrentPalette->color[1].fg.pixel = white;
896 pCurrentPalette->color[1].bg.pixel = black;
897 pCurrentPalette->color[1].sc.pixel = black;
898 pCurrentPalette->color[1].ts.pixel = white;
899 pCurrentPalette->color[1].bs.pixel = white;
901 else if (strcmp(pCurrentPalette->name, BLACK_WHITE) == 0)
903 n=0; /* secondary color black */
904 XtSetArg (args[n], XmNforeground, white); n++;
905 XtSetArg (args[n], XmNbackground, black); n++;
906 XtSetArg (args[n], XmNarmColor, black); n++;
907 XtSetValues(colorButton[0], args, n);
908 pCurrentPalette->color[0].fg.pixel = white;
909 pCurrentPalette->color[0].bg.pixel = black;
910 pCurrentPalette->color[0].sc.pixel = black;
911 pCurrentPalette->color[0].ts.pixel = white;
912 pCurrentPalette->color[0].bs.pixel = white;
914 n=0; /* primary color white */
915 XtSetArg (args[n], XmNforeground, black); n++;
916 XtSetArg (args[n], XmNbackground, white); n++;
917 XtSetArg (args[n], XmNarmColor, white); n++;
918 XtSetValues(colorButton[1], args, n);
919 pCurrentPalette->color[1].fg.pixel = black;
920 pCurrentPalette->color[1].bg.pixel = white;
921 pCurrentPalette->color[1].sc.pixel = white;
922 pCurrentPalette->color[1].ts.pixel = black;
923 pCurrentPalette->color[1].bs.pixel = black;
925 else if (strcmp(pCurrentPalette->name, BLACK_ONLY) == 0)
927 n=0; /* primary and secondary color black */
928 XtSetArg (args[n], XmNforeground, white); n++;
929 XtSetArg (args[n], XmNbackground, black); n++;
930 XtSetArg (args[n], XmNarmColor, black); n++;
931 XtSetValues(colorButton[0], args, n);
932 pCurrentPalette->color[0].fg.pixel = white;
933 pCurrentPalette->color[0].bg.pixel = black;
934 pCurrentPalette->color[0].sc.pixel = black;
935 pCurrentPalette->color[0].ts.pixel = white;
936 pCurrentPalette->color[0].bs.pixel = white;
937 XtSetValues(colorButton[1], args, n);
938 pCurrentPalette->color[1].fg.pixel = white;
939 pCurrentPalette->color[1].bg.pixel = black;
940 pCurrentPalette->color[1].sc.pixel = black;
941 pCurrentPalette->color[1].ts.pixel = white;
942 pCurrentPalette->color[1].bs.pixel = white;
944 else /* WHITE_ONLY */
946 n=0; /* primary and secondary color white */
947 XtSetArg (args[n], XmNforeground, black); n++;
948 XtSetArg (args[n], XmNbackground, white); n++;
949 XtSetArg (args[n], XmNarmColor, white); n++;
950 XtSetValues(colorButton[0], args, n);
951 pCurrentPalette->color[0].fg.pixel = black;
952 pCurrentPalette->color[0].bg.pixel = white;
953 pCurrentPalette->color[0].sc.pixel = white;
954 pCurrentPalette->color[0].ts.pixel = black;
955 pCurrentPalette->color[0].bs.pixel = black;
956 XtSetValues(colorButton[1], args, n);
957 pCurrentPalette->color[1].fg.pixel = black;
958 pCurrentPalette->color[1].bg.pixel = white;
959 pCurrentPalette->color[1].sc.pixel = white;
960 pCurrentPalette->color[1].ts.pixel = black;
961 pCurrentPalette->color[1].bs.pixel = black;
973 XtPointer client_data,
974 XtPointer call_data )
979 XmPushButtonCallbackStruct *cb = (XmPushButtonCallbackStruct *)call_data;
981 i = (int) client_data;
983 /* if click_count == 1 .. first button press, set time out */
984 if(cb->click_count == 1)
986 timeID = XtAppAddTimeOut(XtWidgetToApplicationContext(gParent),
987 (unsigned long) dclick_time, timeoutCB,
992 /* else .. second button press, remove the time out */
993 XtRemoveTimeOut(timeID);
995 if ((edit.DialogShell == NULL) || (!XtIsManaged(edit.DialogShell)))
997 /* make the new selected button have a border color */
999 XtSetArg (args[n], XmNborderColor,
1000 pCurrentPalette->color[pCurrentPalette->secondary].bg.pixel);
1002 XtSetValues(colorButton[selected_button],args,n);
1005 XtSetArg (args[n], XmNborderColor, BlackPixelOfScreen(style.screen));
1007 XtSetValues(colorButton[i],args,n);
1009 selected_button = i;
1011 color_set = (ColorSet *) &pCurrentPalette->color[selected_button];
1012 ColorEditor(style.colorDialog,color_set);
1018 ** This is the double click timeout callback. If this routine is called
1019 ** then there was only a single click on a colorbutton
1023 XtPointer client_data,
1030 if (TypeOfMonitor == XmCO_BLACK_WHITE)
1033 i = (int)client_data;
1035 if ((edit.DialogShell == NULL) || (!XtIsManaged(edit.DialogShell)))
1037 /* make the new selected button have a border color */
1039 XtSetArg (args[n], XmNborderColor,
1040 pCurrentPalette->color[pCurrentPalette->secondary].bg.pixel);
1042 XtSetValues(colorButton[selected_button],args,n);
1045 XtSetArg (args[n], XmNborderColor, BlackPixelOfScreen(style.screen));
1047 XtSetValues(colorButton[i],args,n);
1048 selected_button = i;
1055 XtPointer client_data,
1056 XtPointer call_data )
1064 if (addDialog == NULL)
1068 XtSetArg(args[n], XmNokLabelString, CMPSTR((String) _DtOkString)); n++;
1069 XtSetArg(args[n], XmNcancelLabelString, CMPSTR((String) _DtCancelString)); n++;
1070 XtSetArg(args[n], XmNhelpLabelString, CMPSTR((String) _DtHelpString)); n++;
1071 string = CMPSTR(((char *)GETMESSAGE(14, 10, "New palette name:")));
1072 XtSetArg(args[n], XmNselectionLabelString, string); n++;
1073 string1 = CMPSTR("");
1074 XtSetArg(args[n], XmNtextString, string1); n++;
1075 XtSetArg(args[n], XmNborderWidth, 3); n++;
1076 XtSetArg(args[n], XmNautoUnmanage, False); n++;
1077 addDialog = XmCreatePromptDialog(style.colorDialog,"AddDialog",
1079 XmStringFree(string);
1080 XmStringFree(string1);
1082 XtAddCallback(addDialog, XmNokCallback, addOkCB,
1084 XtAddCallback(addDialog, XmNcancelCallback, addCancelCB,
1086 XtAddCallback(addDialog, XmNhelpCallback,
1087 (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_ADD_PALETTE_DIALOG);
1090 XtSetArg (args[n], XmNmwmInputMode,
1091 MWM_INPUT_PRIMARY_APPLICATION_MODAL); n++;
1092 XtSetArg (args[n], XmNuseAsyncGeometry, True); n++;
1093 XtSetArg (args[n], XmNtitle, ((char *)GETMESSAGE(14, 11, "Add Palette"))); n++;
1094 XtSetArg (args[n], XmNmwmFunctions, DIALOG_MWM_FUNC); n++;
1095 XtSetValues (XtParent (addDialog), args, n);
1098 string = CMPSTR("");
1099 XtSetArg(args[n], XmNtextString, string); n++;
1100 XtSetValues(addDialog, args, n);
1101 XmStringFree(string);
1103 XtManageChild(addDialog);
1110 XtPointer client_data,
1111 XtPointer call_data )
1113 XtUnmanageChild(addDialog);
1119 XtPointer client_data,
1120 XtPointer call_data )
1125 char *name, *filename, *tmpstr;
1126 palette *tmpPalette, *newPalette;
1131 /* Get the text from the promp dialog */
1132 name = XmTextFieldGetString( XmSelectionBoxGetChild(addDialog, XmDIALOG_TEXT));
1134 /* see if the user typed in a valid palette name */
1135 if(!ValidName(name)) {
1136 ErrDialog(((char *)GETMESSAGE(14, 12, "The palette name cannot contain\nthese characters:\n\n * : ( ) [ ] { } < > ! | \" / \\")),
1142 /* check the number of characters in name in a locale independent way */
1143 for ( ii = 0, count = 0; name[ii] != '\0'; ii += length ) {
1144 length = mblen( &(name[ii]), MB_CUR_MAX );
1150 /* make sure the length of name is ok, short file names can only be 11 chars */
1151 if(count > 10 && !style.longfilename) {
1152 ErrDialog(((char *)GETMESSAGE(14, 13, "The palette name must be\n10 characters or less.\n")),style.colorDialog);
1157 /* Unmanage the promptDialog */
1158 XtUnmanageChild(addDialog);
1160 /* first search through palette descriptions and make sure the name to */
1161 /* add is not already in the list and go to the end of the palette list */
1162 for(tmpPalette = pHeadPalette; tmpPalette->next != NULL;
1163 tmpPalette = tmpPalette->next)
1165 if((strcmp(tmpPalette->desc, name) == 0)) {
1166 SameName(w, tmpPalette, name);
1172 /* Check the last palette */
1173 if((strcmp(tmpPalette->desc, name) == 0)) {
1174 SameName(w, tmpPalette, name);
1179 /* allocate space for a new palette */
1180 newPalette = (palette *)XtMalloc(sizeof(palette) + 1 );
1182 /* set the previous last palatte to this new one, it is now the last one*/
1183 tmpPalette->next = newPalette;
1184 newPalette->next = NULL;
1186 /* malloc space for the new palette desc */
1187 newPalette->desc = (char *)XtMalloc(strlen(name) + 1);
1188 for(i = 0; i < strlen(name); i++)
1189 newPalette->desc[i] = name[i];
1190 newPalette->desc[i] = '\0';
1192 /* malloc space for the new palette name directory */
1193 newPalette->directory = (char *)XtMalloc(strlen(style.home) +
1194 strlen(DT_PAL_DIR) + 1);
1195 strcpy(newPalette->directory, style.home);
1196 strcat(newPalette->directory, DT_PAL_DIR);
1198 /* makeup a new name for the palette */
1199 tmpstr = (char *)XtMalloc(strlen(style.home) + strlen(DT_PAL_DIR) +
1200 strlen("dtXXXXXX") + 1);
1201 strcpy(tmpstr, newPalette->directory);
1202 len = strlen(tmpstr);
1203 strcat(tmpstr, "dtXXXXXX");
1206 newPalette->name = (char *) XtMalloc(15 * sizeof(char));
1207 strcpy(newPalette->name, tmpstr + len);
1210 /* the new palette is the next palette .. increase NumOfPalettes by one */
1211 newPalette->item_position = NumOfPalettes + 1;
1214 /* set all the new palette's color parameters to the current palette */
1215 newPalette->num_of_colors = pCurrentPalette->num_of_colors;
1216 for(i = 0; i < XmCO_MAX_NUM_COLORS; i++)
1218 newPalette->color[i].fg.pixel = pCurrentPalette->color[i].fg.pixel;
1219 newPalette->color[i].fg.red = pCurrentPalette->color[i].fg.red;
1220 newPalette->color[i].fg.green = pCurrentPalette->color[i].fg.green;
1221 newPalette->color[i].fg.blue = pCurrentPalette->color[i].fg.blue;
1222 newPalette->color[i].fg.flags = pCurrentPalette->color[i].fg.flags;
1224 newPalette->color[i].bg.pixel = pCurrentPalette->color[i].bg.pixel;
1225 newPalette->color[i].bg.red = pCurrentPalette->color[i].bg.red;
1226 newPalette->color[i].bg.green = pCurrentPalette->color[i].bg.green;
1227 newPalette->color[i].bg.blue = pCurrentPalette->color[i].bg.blue;
1228 newPalette->color[i].bg.flags = pCurrentPalette->color[i].bg.flags;
1230 newPalette->color[i].ts.pixel = pCurrentPalette->color[i].ts.pixel;
1231 newPalette->color[i].ts.red = pCurrentPalette->color[i].ts.red;
1232 newPalette->color[i].ts.green = pCurrentPalette->color[i].ts.green;
1233 newPalette->color[i].ts.blue = pCurrentPalette->color[i].ts.blue;
1234 newPalette->color[i].ts.flags = pCurrentPalette->color[i].ts.flags;
1236 newPalette->color[i].bs.pixel = pCurrentPalette->color[i].bs.pixel;
1237 newPalette->color[i].bs.red = pCurrentPalette->color[i].bs.red;
1238 newPalette->color[i].bs.green = pCurrentPalette->color[i].bs.green;
1239 newPalette->color[i].bs.blue = pCurrentPalette->color[i].bs.blue;
1240 newPalette->color[i].bs.flags = pCurrentPalette->color[i].bs.flags;
1242 newPalette->color[i].sc.pixel = pCurrentPalette->color[i].sc.pixel;
1243 newPalette->color[i].sc.red = pCurrentPalette->color[i].sc.red;
1244 newPalette->color[i].sc.green = pCurrentPalette->color[i].sc.green;
1245 newPalette->color[i].sc.blue = pCurrentPalette->color[i].sc.blue;
1246 newPalette->color[i].sc.flags = pCurrentPalette->color[i].sc.flags;
1249 /* Write out the palette */
1250 if ((WriteOutPalette(newPalette->name)) == -1)
1254 /* remove palette from list */
1255 tmpPalette->next = NULL;
1256 XtFree ((char *)newPalette);
1261 WriteOutDesc(newPalette);
1264 /* add the name to the scrolled window list and select it */
1265 AddName(newPalette);
1267 /* now check to see if there is a ~filename .. if there is delete it */
1268 /* use the $HOME environment varible then constuct the full file name */
1269 filename = (char *)XtMalloc(strlen(style.home) + strlen(DT_PAL_DIR) +
1270 strlen(newPalette->name) + strlen(PALETTE_SUFFIX) + 2);
1272 /* create the full path name plus file name */
1273 strcpy(filename, style.home);
1274 strcat(filename, DT_PAL_DIR);
1275 strcat(filename, "~");
1276 strcat(filename, newPalette->name);
1277 strcat(filename, PALETTE_SUFFIX);
1284 /* Go write out the palette */
1285 pCurrentPalette = newPalette;
1292 XtPointer client_data,
1293 XtPointer call_data )
1295 palette *tmpPalette = (palette *)client_data;
1298 /* free the directory */
1299 XtFree(tmpPalette->directory);
1301 /* put the new (users) directory there */
1302 tmpPalette->directory = (char *)XtMalloc(strlen(style.home) +
1303 strlen(DT_PAL_DIR) + 1);
1304 strcpy(tmpPalette->directory, style.home);
1305 strcat(tmpPalette->directory, DT_PAL_DIR);
1307 for(i = 0; i < XmCO_MAX_NUM_COLORS; i++)
1309 tmpPalette->color[i].fg.pixel = pCurrentPalette->color[i].fg.pixel;
1310 tmpPalette->color[i].fg.red = pCurrentPalette->color[i].fg.red;
1311 tmpPalette->color[i].fg.green = pCurrentPalette->color[i].fg.green;
1312 tmpPalette->color[i].fg.blue = pCurrentPalette->color[i].fg.blue;
1313 tmpPalette->color[i].fg.flags = pCurrentPalette->color[i].fg.flags;
1315 tmpPalette->color[i].bg.pixel = pCurrentPalette->color[i].bg.pixel;
1316 tmpPalette->color[i].bg.red = pCurrentPalette->color[i].bg.red;
1317 tmpPalette->color[i].bg.green = pCurrentPalette->color[i].bg.green;
1318 tmpPalette->color[i].bg.blue = pCurrentPalette->color[i].bg.blue;
1319 tmpPalette->color[i].bg.flags = pCurrentPalette->color[i].bg.flags;
1321 tmpPalette->color[i].ts.pixel = pCurrentPalette->color[i].ts.pixel;
1322 tmpPalette->color[i].ts.red = pCurrentPalette->color[i].ts.red;
1323 tmpPalette->color[i].ts.green = pCurrentPalette->color[i].ts.green;
1324 tmpPalette->color[i].ts.blue = pCurrentPalette->color[i].ts.blue;
1325 tmpPalette->color[i].ts.flags = pCurrentPalette->color[i].ts.flags;
1327 tmpPalette->color[i].bs.pixel = pCurrentPalette->color[i].bs.pixel;
1328 tmpPalette->color[i].bs.red = pCurrentPalette->color[i].bs.red;
1329 tmpPalette->color[i].bs.green = pCurrentPalette->color[i].bs.green;
1330 tmpPalette->color[i].bs.blue = pCurrentPalette->color[i].bs.blue;
1331 tmpPalette->color[i].bs.flags = pCurrentPalette->color[i].bs.flags;
1333 tmpPalette->color[i].sc.pixel = pCurrentPalette->color[i].sc.pixel;
1334 tmpPalette->color[i].sc.red = pCurrentPalette->color[i].sc.red;
1335 tmpPalette->color[i].sc.green = pCurrentPalette->color[i].sc.green;
1336 tmpPalette->color[i].sc.blue = pCurrentPalette->color[i].sc.blue;
1337 tmpPalette->color[i].sc.flags = pCurrentPalette->color[i].sc.flags;
1340 /* Write out the palette */
1341 if ((WriteOutPalette(tmpPalette->name)) == -1)
1344 WriteOutDesc(tmpPalette);
1346 pCurrentPalette = tmpPalette;
1348 /* select item in list as if user had selected it */
1349 XmListSelectPos (paletteList, tmpPalette->item_position, TRUE);
1350 XmListSetBottomPos(paletteList, tmpPalette->item_position);
1351 selected_position = tmpPalette->item_position;
1358 XtPointer client_data,
1359 XtPointer call_data )
1361 ColorSet *color_set;
1363 if(TypeOfMonitor == XmCO_BLACK_WHITE)
1366 color_set = (ColorSet *) &pCurrentPalette->color[selected_button];
1367 ColorEditor(style.colorDialog,color_set);
1374 ** Process callback from the Ok, Cancel and Help pushButtons in the
1380 XtPointer client_data,
1381 XtPointer call_data )
1383 palette *tmp_palette;
1385 DtDialogBoxCallbackStruct *cb = (DtDialogBoxCallbackStruct *) call_data;
1387 switch (cb->button_position)
1390 if ((edit.DialogShell != NULL) && (XtIsManaged(edit.DialogShell)))
1391 XtUnmanageChild(edit.DialogShell);
1393 XtUnmanageChild(style.colorDialog);
1394 UpdateDefaultPalette();
1398 if ((edit.DialogShell != NULL) && (XtIsManaged(edit.DialogShell)))
1399 XtUnmanageChild(edit.DialogShell);
1401 if ((addDialog != NULL) && (XtIsManaged(addDialog)))
1402 XtCallCallbacks(addDialog, XmNcancelCallback, (XtPointer)NULL);
1404 if ((deleteDialog != NULL) && (XtIsManaged(deleteDialog)))
1405 XtCallCallbacks(deleteDialog, XmNcancelCallback, (XtPointer)NULL);
1407 if ((colorUseDialog != NULL) && (XtIsManaged(colorUseDialog)))
1408 XtCallCallbacks(colorUseDialog, XmNcallback, (XtPointer)NULL);
1410 XtUnmanageChild(style.colorDialog);
1412 tmp_palette = pHeadPalette;
1413 for(tmp_palette = pHeadPalette; tmp_palette != NULL; tmp_palette = tmp_palette->next)
1414 if(!(strcmp(tmp_palette->name, defaultName)))
1420 if(match == FALSE) /* the default palette is no longer valid */
1421 UpdateDefaultPalette();
1423 RestoreOrgPalette();
1428 XtCallCallbacks(style.colorDialog, XmNhelpCallback, (XtPointer)NULL);
1439 palette *newPalette )
1444 ** Add the palette name to the list
1446 string = CMPSTR(newPalette->desc);
1447 XmListAddItem(paletteList, string, newPalette->item_position);
1448 XmListSelectPos(paletteList, newPalette->item_position, TRUE);
1449 XmListSetBottomPos(paletteList, newPalette->item_position);
1450 selected_position = newPalette->item_position;
1451 XSync(style.display, 0);
1452 XmStringFree(string);
1458 XtPointer client_data,
1459 XtPointer call_data )
1464 palette *tmp_palette;
1467 char *str_type_return;
1468 XrmValue value_return;
1470 tmp_palette = pHeadPalette;
1472 while( tmp_palette->item_position != selected_position &&
1473 tmp_palette != NULL)
1474 tmp_palette = tmp_palette->next;
1476 if (deleteDialog == NULL)
1479 XtSetArg(args[n], XmNokLabelString, CMPSTR((String) _DtOkString)); n++;
1480 XtSetArg(args[n], XmNcancelLabelString, CMPSTR((String) _DtCancelString)); n++;
1481 XtSetArg(args[n], XmNhelpLabelString, CMPSTR((String) _DtHelpString)); n++;
1482 XtSetArg(args[n], XmNdialogType, XmDIALOG_INFORMATION); n++;
1483 XtSetArg(args[n], XmNborderWidth, 3); n++;
1484 XtSetArg(args[n], XmNdefaultPosition, False); n++;
1485 deleteDialog = XmCreateQuestionDialog(style.colorDialog,
1486 "deleteDialog", args, n);
1487 XtAddCallback(deleteDialog, XmNmapCallback, CenterMsgCB,
1489 XtAddCallback(deleteDialog, XmNcancelCallback, deleteCancelCB, NULL);
1490 XtAddCallback(deleteDialog, XmNokCallback, deleteOkCB,
1491 (XtPointer)(paletteList));
1492 XtAddCallback(deleteDialog, XmNhelpCallback,
1493 (XtCallbackProc)HelpRequestCB,
1494 (XtPointer)HELP_DELETE_PALETTE_WARNING_DIALOG);
1498 XtSetArg (args[n], XmNmwmInputMode,
1499 MWM_INPUT_PRIMARY_APPLICATION_MODAL); n++;
1500 XtSetArg (args[n], XmNuseAsyncGeometry, True); n++;
1501 XtSetArg (args[n], XmNtitle, ((char *)GETMESSAGE(14, 16, "Delete Palette"))); n++;
1502 XtSetArg (args[n], XmNmwmFunctions, DIALOG_MWM_FUNC); n++;
1503 XtSetValues (XtParent (deleteDialog), args, n);
1508 tmpStr = XtMalloc(strlen(STR2) + strlen(tmp_palette->desc) + 1);
1509 sprintf(tmpStr, STR2, tmp_palette->desc);
1510 XtSetArg(args[n], XmNmessageString, CMPSTR(tmpStr)); n++;
1511 XtSetValues(deleteDialog, args, n);
1514 XtManageChild(deleteDialog);
1520 XtPointer client_data,
1521 XtPointer call_data )
1524 XtUnmanageChild(deleteDialog);
1526 if(NumOfPalettes == 1)
1528 InfoDialog(CANT_DELETE, style.colorDialog, False);
1532 if (RemovePalette() == True)
1533 DeletePaletteFromLinkList((Widget)client_data);
1540 XtPointer client_data,
1541 XtPointer call_data )
1543 XtUnmanageChild(deleteDialog);
1549 XtPointer client_data,
1550 XtPointer call_data )
1555 XmString button_string[NUM_LABELS];
1557 Widget parent = (Widget) client_data;
1560 Widget widget_list[10];
1565 if (colorUseDialog == NULL)
1569 /* Set up DialogBox button labels. */
1570 button_string[0] = CMPSTR((String) _DtOkString);
1571 button_string[1] = CMPSTR((String) _DtCancelString);
1572 button_string[2] = CMPSTR((String) _DtHelpString);
1574 XtSetArg (args[n], XmNchildType, XmWORK_AREA); n++;
1575 XtSetArg (args[n], XmNbuttonCount, NUM_LABELS); n++;
1576 XtSetArg (args[n], XmNbuttonLabelStrings, button_string); n++;
1577 XtSetArg (args[n], XmNdefaultPosition, False); n++;
1578 colorUseDialog = __DtCreateDialogBoxDialog(parent, "colorUseDialog",
1580 XtAddCallback(colorUseDialog, XmNcallback, colorUseExitCB, NULL);
1581 XtAddCallback(colorUseDialog, XmNmapCallback, _DtmapCB_colorUse, NULL);
1582 XtAddCallback(colorUseDialog, XmNhelpCallback,
1583 (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_COLOR_USE_DIALOG);
1585 XmStringFree(button_string[0]);
1586 XmStringFree(button_string[1]);
1587 XmStringFree(button_string[2]);
1589 widget_list[0] = _DtDialogBoxGetButton(colorUseDialog,2);
1591 XtSetArg(args[n], XmNautoUnmanage, False); n++;
1592 XtSetArg(args[n], XmNcancelButton, widget_list[0]); n++;
1593 XtSetValues (colorUseDialog, args, n);
1596 XtSetArg (args[n], XmNuseAsyncGeometry, True); n++;
1597 XtSetArg (args[n], XmNtitle,
1598 ((char *)GETMESSAGE(14, 39, "Number Of Colors To Use:"))); n++;
1599 XtSetArg (args[n], XmNmwmFunctions, DIALOG_MWM_FUNC); n++;
1600 XtSetValues (XtParent(colorUseDialog), args, n);
1603 XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
1604 XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
1605 XtSetArg(args[n], XmNallowOverlap, False); n++;
1606 XtSetArg(args[n], XmNchildType, XmWORK_AREA); n++;
1607 form = XmCreateForm(colorUseDialog, "colorUseForm", args, n);
1608 XtManageChild(form);
1611 XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
1612 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1613 XtSetArg (args[n], XmNrightAttachment, XmATTACH_NONE); n++;
1614 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
1615 XtSetArg (args[n], XmNbehavior, XmICON_LABEL); n++;
1616 XtSetArg (args[n], XmNshadowThickness, 0); n++;
1617 XtSetArg (args[n], XmNstring, NULL); n++;
1618 XtSetArg (args[n], XmNpixmapForeground, style.primBSCol); n++;
1619 XtSetArg (args[n], XmNpixmapBackground, style.primTSCol); n++;
1620 XtSetArg (args[n], XmNimageName, COLOR_ICON); n++;
1621 XtSetArg (args[n], XmNtraversalOn, False); n++;
1622 pictLabel = _DtCreateIcon(form, "pictLabel", args, n);
1623 XtManageChild(pictLabel);
1626 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
1627 XtSetArg (args[n], XmNtopWidget, pictLabel); n++;
1628 XtSetArg (args[n], XmNtopOffset, style.verticalSpacing); n++;
1629 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
1630 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
1631 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
1633 = XmCreateFrame(form, "colorUseTB", args, n);
1634 XtManageChild(colorUseTB);
1636 /* create a rowColumn for ColorUse selections */
1638 colorUseRC = XmCreateRadioBox(colorUseTB, "colorUseRC", args, n);
1639 XtManageChild(colorUseRC);
1642 string = CMPSTR(((char *)GETMESSAGE(14, 41, "More Colors for Desktop")));
1643 XtSetArg(args[n], XmNlabelString, string); n++;
1644 widget_list[count++] = colorDialog.highColorTG
1645 = XmCreateToggleButtonGadget(colorUseRC,"highColorTG", args, n);
1646 XtAddCallback(colorDialog.highColorTG, XmNvalueChangedCallback,
1647 colorUseCB, (XtPointer)XmCO_HIGH_COLOR);
1648 XmStringFree(string);
1651 string = CMPSTR(((char *)GETMESSAGE(14, 42, "More Colors for Applications")));
1652 XtSetArg(args[n], XmNlabelString, string); n++;
1653 widget_list[count++] = colorDialog.mediumColorTG
1654 = XmCreateToggleButtonGadget(colorUseRC,"mediumColorTG", args, n);
1655 XmStringFree(string);
1656 XtAddCallback(colorDialog.mediumColorTG, XmNvalueChangedCallback,
1657 colorUseCB, (XtPointer)XmCO_MEDIUM_COLOR);
1660 string = CMPSTR(((char *)GETMESSAGE(14, 43, "Most Colors for Applications")));
1661 XtSetArg(args[n], XmNlabelString, string); n++;
1662 widget_list[count++] = colorDialog.lowColorTG
1663 = XmCreateToggleButtonGadget(colorUseRC,"lowColorTG", args, n);
1664 XmStringFree(string);
1665 XtAddCallback(colorDialog.lowColorTG, XmNvalueChangedCallback,
1666 colorUseCB, (XtPointer)XmCO_LOW_COLOR);
1669 string = CMPSTR(((char *)GETMESSAGE(14, 34, "Black and White")));
1670 XtSetArg(args[n], XmNlabelString, string); n++;
1671 widget_list[count++] = colorDialog.blackWhiteTG
1672 = XmCreateToggleButtonGadget(colorUseRC,"blackWhiteTG", args, n);
1673 XmStringFree(string);
1674 XtAddCallback(colorDialog.blackWhiteTG, XmNvalueChangedCallback,
1675 colorUseCB, (XtPointer)XmCO_BLACK_WHITE);
1678 string = CMPSTR(((char *)GETMESSAGE(14, 35, "Default")));
1679 XtSetArg(args[n], XmNlabelString, string); n++;
1680 widget_list[count++] = colorDialog.defaultTG
1681 = XmCreateToggleButtonGadget(colorUseRC,"defaultTG", args, n);
1682 XmStringFree(string);
1683 XtAddCallback(colorDialog.defaultTG, XmNvalueChangedCallback,
1684 colorUseCB, (XtPointer)DEFAULT_COLOR);
1686 XtManageChildren(widget_list,count);
1687 putDialog (XtParent(style.colorDialog), colorUseDialog);
1690 XtManageChild(colorUseDialog);
1695 ** Process new ColorUse selection
1700 XtPointer client_data,
1701 XtPointer call_data )
1704 XmToggleButtonCallbackStruct *cb =
1705 (XmToggleButtonCallbackStruct *)call_data;
1707 colorDialog.currentColorUse = (int) client_data;
1708 switch (colorDialog.currentColorUse)
1710 case XmCO_HIGH_COLOR:
1711 colorDialog.currentColorUseStr = HIGH_COLOR_STR;
1714 case XmCO_MEDIUM_COLOR:
1715 colorDialog.currentColorUseStr = MEDIUM_COLOR_STR;
1718 case XmCO_LOW_COLOR:
1719 colorDialog.currentColorUseStr = LOW_COLOR_STR;
1722 case XmCO_BLACK_WHITE:
1723 colorDialog.currentColorUseStr = B_W_STR;
1727 colorDialog.currentColorUseStr = DEFAULT_COLOR_STR;
1737 ** Process callback from the Ok, Cancel and Help pushButtons in the
1738 ** Configure DT Colors DialogBox.
1743 XtPointer client_data,
1744 XtPointer call_data )
1747 char colorUseRes[64];
1748 DtDialogBoxCallbackStruct *cb = (DtDialogBoxCallbackStruct *) call_data;
1750 switch (cb->button_position)
1753 XtCallCallbacks(colorUseDialog, XmNhelpCallback, (XtPointer)NULL);
1758 XtUnmanageChild(colorUseDialog);
1760 if (colorDialog.origColorUse != colorDialog.currentColorUse)
1762 InfoDialog(COLORUSE_WHEN, style.colorDialog, False);
1764 /* create the ColorUse resource spec for xrdb */
1765 /* remove ColorUse specification from database for DEFAULT_COLOR */
1767 sprintf(colorUseRes, "*%d*ColorUse: %s\n",
1768 style.screenNum,colorDialog.currentColorUseStr);
1770 switch (colorDialog.currentColorUse)
1772 case XmCO_MEDIUM_COLOR:
1773 sprintf(colorUseRes+strlen(colorUseRes),
1774 "*HelpColorUse: GRAY_SCALE\n");
1778 case XmCO_LOW_COLOR:
1779 case XmCO_BLACK_WHITE:
1780 sprintf(colorUseRes+strlen(colorUseRes),
1781 "*HelpColorUse: B_W\n");
1785 case XmCO_HIGH_COLOR:
1788 sprintf(colorUseRes+strlen(colorUseRes),
1789 "*HelpColorUse: COLOR\n");
1793 _DtAddToResource(style.display, colorUseRes);
1795 colorDialog.origColorUse = colorDialog.currentColorUse;
1803 XtUnmanageChild(colorUseDialog);
1805 switch (colorDialog.origColorUse)
1807 case XmCO_HIGH_COLOR:
1808 XmToggleButtonGadgetSetState(colorDialog.highColorTG, True, True);
1811 case XmCO_MEDIUM_COLOR:
1812 XmToggleButtonGadgetSetState(colorDialog.mediumColorTG, True, True);
1815 case XmCO_LOW_COLOR:
1816 XmToggleButtonGadgetSetState(colorDialog.lowColorTG, True, True);
1819 case XmCO_BLACK_WHITE:
1820 XmToggleButtonGadgetSetState(colorDialog.blackWhiteTG, True, True);
1824 XmToggleButtonGadgetSetState(colorDialog.defaultTG, True, True);
1834 activateCBexitColor(
1836 XtPointer client_data,
1837 XtPointer call_data )
1839 DtDialogBoxCallbackStruct CancelBut;
1841 if(style.colorDialog != NULL && XtIsManaged(style.colorDialog)) {
1842 CancelBut.button_position = CANCEL_BUTTON;
1843 XtCallCallbacks(style.colorDialog, XmNcallback, &CancelBut);
1850 XtPointer client_data,
1852 XtPointer call_data )
1855 DtWsmRemoveWorkspaceFunctions(style.display, XtWindow(XtParent(w)));
1857 if (!save.restoreFlag)
1858 putDialog ((Widget)client_data, XtParent(w));
1860 XtRemoveCallback(style.colorDialog, XmNmapCallback, _DtmapCB, NULL);
1866 XtPointer client_data,
1868 XtPointer call_data )
1871 char *str_type_return;
1872 XrmValue value_return;
1877 char instanceString[24], nameString[24];
1879 DtWsmRemoveWorkspaceFunctions(style.display, XtWindow(XtParent(w)));
1881 db = XtDatabase(style.display);
1883 /* Get ColorUse value */
1884 sprintf (instanceString, "dtsession*%d*colorUse",style.screenNum);
1885 sprintf (nameString, "Dtsession*%d*ColorUse",style.screenNum);
1887 if (status = XrmGetResource (db, instanceString,
1889 &str_type_return, &value_return))
1891 /* make local copy of string */
1892 string = (char *) XtMalloc( value_return.size );
1893 strcpy (string, value_return.addr);
1895 if (strcmp(string, HIGH_COLOR_STR) == 0)
1897 XmToggleButtonGadgetSetState (colorDialog.highColorTG, True, True);
1898 colorDialog.origColorUse = XmCO_HIGH_COLOR;
1900 else if (strcmp(string, MEDIUM_COLOR_STR) == 0)
1902 XmToggleButtonGadgetSetState (colorDialog.mediumColorTG, True, True);
1903 colorDialog.origColorUse = XmCO_MEDIUM_COLOR;
1905 else if (strcmp(string, LOW_COLOR_STR) == 0)
1907 XmToggleButtonGadgetSetState (colorDialog.lowColorTG, True, True);
1908 colorDialog.origColorUse = XmCO_LOW_COLOR;
1910 else if (strcmp(string, B_W_STR) == 0)
1912 XmToggleButtonGadgetSetState (colorDialog.blackWhiteTG, True, True);
1913 colorDialog.origColorUse = XmCO_BLACK_WHITE;
1917 XmToggleButtonGadgetSetState (colorDialog.defaultTG, True, True);
1918 colorDialog.origColorUse = DEFAULT_COLOR;
1923 else /* ColorUse not specified */
1925 XmToggleButtonGadgetSetState (colorDialog.defaultTG, True, True);
1926 colorDialog.origColorUse = DEFAULT_COLOR;
1929 XtRemoveCallback(colorUseDialog, XmNmapCallback, _DtmapCB_colorUse, NULL);
1932 /************************************************************************
1934 * DeletePaletteFromLinkList - routine used to delete a palette from
1935 * the link list of palettes. The palette which is at the current
1936 * selected_position is the palette that is going to be deleted.
1937 * Special things have to happen if the selected palette is at the
1940 ************************************************************************/
1942 DeletePaletteFromLinkList(
1949 palette *tmp_palette, *tmp2_palette;
1950 palette *selected_palette;
1953 selected_palette = pHeadPalette;
1954 while( selected_palette->item_position != selected_position &&
1955 selected_palette != NULL)
1956 selected_palette = selected_palette->next;
1958 XmListDeletePos (list, selected_palette->item_position);
1960 /* delete item from palette list structure */
1962 /* If the palette is at the head .. remove the head and the next
1963 palette becomes the new selected palette */
1964 if (selected_palette->item_position == 1)
1966 pHeadPalette = selected_palette->next;
1967 tmp_palette = pHeadPalette;
1968 tmp_palette->item_position--;
1969 /* new current palette */
1970 pCurrentPalette = tmp_palette;
1972 else /* find the palette just above the palette to be deleted .. it
1973 will become the new selected palette */
1975 tmp_palette = pHeadPalette;
1976 for (i=1; i < selected_palette->item_position-1; i++)
1977 tmp_palette = tmp_palette->next;
1979 tmp_palette->next = selected_palette->next;
1981 /* what is CurrentPalette now? prev or next item?
1982 special case empty list or NULL entry */
1983 if (tmp_palette->next != NULL)
1984 pCurrentPalette = tmp_palette->next;
1986 pCurrentPalette = tmp_palette;
1989 /* decrement item_positions values in remaining palette entries */
1990 tmp2_palette = tmp_palette;
1991 while ((tmp2_palette = tmp2_palette->next) != NULL)
1993 tmp2_palette->item_position--;
1996 /* go copy the pixel numbers to the new palette */
1997 CopyPixel(selected_palette->color, pCurrentPalette->color,
1998 selected_palette->num_of_colors);
2000 /* select item in list as if user had selected it */
2001 XmListSelectPos (list, tmp_palette->item_position, TRUE);
2002 /* Need to check to see if the first palette is being deleted if it is
2003 need to change colors and update title box */
2004 if(selected_position == tmp_palette->item_position) {
2005 pOldPalette = selected_palette;
2008 string = CMPSTR(pCurrentPalette->desc);
2009 XtSetArg (args[n], XmNtitleString, string); n++;
2010 XtSetValues (colorDialog.buttonsTB, args, n);
2011 XmStringFree(string);
2016 XmListSetBottomPos(paletteList, tmp_palette->item_position);
2017 selected_position = tmp_palette->item_position;
2021 /* deallocate the palette structure */
2022 XtFree(selected_palette->name);
2023 XtFree(selected_palette->desc);
2024 XtFree(selected_palette->directory);
2025 XtFree((char *)selected_palette);
2030 ColorSet srcPixels[XmCO_MAX_NUM_COLORS],
2031 ColorSet dstPixels[XmCO_MAX_NUM_COLORS],
2036 for(i=0; i < numOfColors; i++)
2038 dstPixels[i].bg.pixel = srcPixels[i].bg.pixel;
2039 dstPixels[i].fg.pixel = srcPixels[i].fg.pixel;
2040 dstPixels[i].ts.pixel = srcPixels[i].ts.pixel;
2041 dstPixels[i].bs.pixel = srcPixels[i].bs.pixel;
2042 dstPixels[i].sc.pixel = srcPixels[i].sc.pixel;
2047 SaveOrgPalette( void )
2050 palette *tmp_palette, *tmp2_palette;
2052 if(save.restoreFlag && defaultName_restore[0] != 0) {
2053 tmp_palette = pHeadPalette;
2054 while(tmp_palette->next != NULL )
2055 if(strcmp(tmp_palette->name, defaultName))
2057 tmp_palette = tmp_palette->next;
2063 if(!strcmp(tmp_palette->name, defaultName)) {
2064 tmp2_palette = pCurrentPalette;
2065 pCurrentPalette = tmp_palette;
2071 OrgPalette.item_position = pCurrentPalette->item_position;
2072 OrgPalette.num_of_colors = pCurrentPalette->num_of_colors;
2073 for(i = 0; i < XmCO_MAX_NUM_COLORS; i++)
2075 OrgPalette.primary = pCurrentPalette->primary;
2076 OrgPalette.secondary = pCurrentPalette->secondary;
2077 OrgPalette.active = pCurrentPalette->active;
2078 OrgPalette.inactive = pCurrentPalette->inactive;
2080 if(save.restoreFlag && defaultName_restore[0] != 0)
2081 OrgPalette.color[i].bg.pixel = tmp2_palette->color[i].bg.pixel;
2083 OrgPalette.color[i].bg.pixel = pCurrentPalette->color[i].bg.pixel;
2084 OrgPalette.color[i].bg.red = pCurrentPalette->color[i].bg.red;
2085 OrgPalette.color[i].bg.green = pCurrentPalette->color[i].bg.green;
2086 OrgPalette.color[i].bg.blue = pCurrentPalette->color[i].bg.blue;
2088 if(save.restoreFlag && defaultName_restore[0] != 0)
2089 OrgPalette.color[i].fg.pixel = tmp2_palette->color[i].fg.pixel;
2091 OrgPalette.color[i].fg.pixel = pCurrentPalette->color[i].fg.pixel;
2092 OrgPalette.color[i].fg.red = pCurrentPalette->color[i].fg.red;
2093 OrgPalette.color[i].fg.green = pCurrentPalette->color[i].fg.green;
2094 OrgPalette.color[i].fg.blue = pCurrentPalette->color[i].fg.blue;
2096 if(save.restoreFlag && defaultName_restore[0] != 0)
2097 OrgPalette.color[i].ts.pixel = tmp2_palette->color[i].ts.pixel;
2099 OrgPalette.color[i].ts.pixel = pCurrentPalette->color[i].ts.pixel;
2100 OrgPalette.color[i].ts.red = pCurrentPalette->color[i].ts.red;
2101 OrgPalette.color[i].ts.green = pCurrentPalette->color[i].ts.green;
2102 OrgPalette.color[i].ts.blue = pCurrentPalette->color[i].ts.blue;
2104 if(save.restoreFlag && defaultName_restore[0] != 0)
2105 OrgPalette.color[i].bs.pixel = tmp2_palette->color[i].bs.pixel;
2107 OrgPalette.color[i].bs.pixel = pCurrentPalette->color[i].bs.pixel;
2108 OrgPalette.color[i].bs.red = pCurrentPalette->color[i].bs.red;
2109 OrgPalette.color[i].bs.green = pCurrentPalette->color[i].bs.green;
2110 OrgPalette.color[i].bs.blue = pCurrentPalette->color[i].bs.blue;
2112 if(save.restoreFlag && defaultName_restore[0] != 0)
2113 OrgPalette.color[i].sc.pixel = tmp2_palette->color[i].sc.pixel;
2115 OrgPalette.color[i].sc.pixel = pCurrentPalette->color[i].sc.pixel;
2116 OrgPalette.color[i].sc.red = pCurrentPalette->color[i].sc.red;
2117 OrgPalette.color[i].sc.green = pCurrentPalette->color[i].sc.green;
2118 OrgPalette.color[i].sc.blue = pCurrentPalette->color[i].sc.blue;
2121 if(save.restoreFlag && defaultName_restore[0] != 0)
2122 if(tmp_palette != NULL)
2123 pCurrentPalette = tmp2_palette;
2128 RestoreOrgPalette( void )
2131 palette *tmp_palette;
2133 XColor colors[XmCO_MAX_NUM_COLORS * 5];
2135 tmp_palette = pHeadPalette;
2136 while ( tmp_palette != NULL &&
2137 tmp_palette->item_position != OrgPalette.item_position )
2138 tmp_palette = tmp_palette->next;
2140 if ( tmp_palette != NULL &&
2141 tmp_palette->item_position == OrgPalette.item_position)
2143 pCurrentPalette = tmp_palette;
2144 OrgPalette.num_of_colors = pCurrentPalette->num_of_colors;
2145 for(i = 0; i < XmCO_MAX_NUM_COLORS; i++)
2147 pCurrentPalette->primary = OrgPalette.primary;
2148 pCurrentPalette->secondary = OrgPalette.secondary;
2149 pCurrentPalette->inactive = OrgPalette.inactive;
2150 pCurrentPalette->active = OrgPalette.active;
2152 pCurrentPalette->color[i].bg.pixel = OrgPalette.color[i].bg.pixel;
2153 pCurrentPalette->color[i].bg.red = OrgPalette.color[i].bg.red;
2154 pCurrentPalette->color[i].bg.green = OrgPalette.color[i].bg.green;
2155 pCurrentPalette->color[i].bg.blue = OrgPalette.color[i].bg.blue;
2156 if(i < OrgPalette.num_of_colors && TypeOfMonitor != XmCO_BLACK_WHITE)
2157 colors[j++] = pCurrentPalette->color[i].bg;
2159 pCurrentPalette->color[i].sc.pixel = OrgPalette.color[i].sc.pixel;
2160 pCurrentPalette->color[i].sc.red = OrgPalette.color[i].sc.red;
2161 pCurrentPalette->color[i].sc.green = OrgPalette.color[i].sc.green;
2162 pCurrentPalette->color[i].sc.blue = OrgPalette.color[i].sc.blue;
2163 if(i < OrgPalette.num_of_colors && TypeOfMonitor != XmCO_BLACK_WHITE)
2164 colors[j++] = pCurrentPalette->color[i].sc;
2166 pCurrentPalette->color[i].fg.pixel = OrgPalette.color[i].fg.pixel;
2167 pCurrentPalette->color[i].fg.red = OrgPalette.color[i].fg.red;
2168 pCurrentPalette->color[i].fg.green = OrgPalette.color[i].fg.green;
2169 pCurrentPalette->color[i].fg.blue = OrgPalette.color[i].fg.blue;
2170 if(i < OrgPalette.num_of_colors && TypeOfMonitor != XmCO_BLACK_WHITE)
2171 if(FgColor == DYNAMIC)
2172 colors[j++] = pCurrentPalette->color[i].fg;
2174 pCurrentPalette->color[i].ts.pixel = OrgPalette.color[i].ts.pixel;
2175 pCurrentPalette->color[i].ts.red = OrgPalette.color[i].ts.red;
2176 pCurrentPalette->color[i].ts.green = OrgPalette.color[i].ts.green;
2177 pCurrentPalette->color[i].ts.blue = OrgPalette.color[i].ts.blue;
2178 if(i < OrgPalette.num_of_colors && TypeOfMonitor != XmCO_BLACK_WHITE)
2179 if(UsePixmaps == FALSE)
2180 colors[j++] = pCurrentPalette->color[i].ts;
2182 pCurrentPalette->color[i].bs.pixel = OrgPalette.color[i].bs.pixel;
2183 pCurrentPalette->color[i].bs.red = OrgPalette.color[i].bs.red;
2184 pCurrentPalette->color[i].bs.green = OrgPalette.color[i].bs.green;
2185 pCurrentPalette->color[i].bs.blue = OrgPalette.color[i].bs.blue;
2186 if(i < OrgPalette.num_of_colors && TypeOfMonitor != XmCO_BLACK_WHITE)
2187 if(UsePixmaps == FALSE)
2188 colors[j++] = pCurrentPalette->color[i].bs;
2192 if (style.dynamicColor)
2193 XStoreColors (style.display, style.colormap, colors, j);
2195 XmListSelectPos (paletteList, OrgPalette.item_position, TRUE);
2196 XmListSetBottomPos(paletteList, OrgPalette.item_position);
2202 UpdateDefaultPalette( void )
2205 char temp[XmCO_MAX_NUM_COLORS][60];
2206 char xrdb_string[100];
2207 XColor saved_color[2];
2209 for(i = 0; i < XmCO_MAX_NUM_COLORS; i++)
2211 /* put the colors of the palette in the form #RRRRGGGGBBBB */
2212 if(TypeOfMonitor == XmCO_LOW_COLOR && (i == 0 || i == 1))
2213 sprintf(temp[i],"#%04x%04x%04x\n", saved_color[i].red,
2214 saved_color[i].green,
2215 saved_color[i].blue);
2216 else if(TypeOfMonitor == XmCO_LOW_COLOR && i == 2)
2217 sprintf(temp[i],"#%04x%04x%04x\n",pCurrentPalette->color[1].bg.red,
2218 pCurrentPalette->color[1].bg.green,
2219 pCurrentPalette->color[1].bg.blue);
2220 else if(TypeOfMonitor == XmCO_LOW_COLOR && i == 3)
2221 sprintf(temp[i],"#%04x%04x%04x\n",pCurrentPalette->color[0].bg.red,
2222 pCurrentPalette->color[0].bg.green,
2223 pCurrentPalette->color[0].bg.blue);
2225 sprintf(temp[i],"#%04x%04x%04x\n",pCurrentPalette->color[i].bg.red,
2226 pCurrentPalette->color[i].bg.green,
2227 pCurrentPalette->color[i].bg.blue);
2230 /* update the resource manager property with the palette resource */
2231 if (TypeOfMonitor == XmCO_BLACK_WHITE)
2233 sprintf(xrdb_string, "*%d*MonochromePalette: %s%s\n",
2234 style.screenNum, pCurrentPalette->name, PALETTE_SUFFIX);
2238 sprintf(xrdb_string, "*%d*ColorPalette: %s%s\n",
2239 style.screenNum, pCurrentPalette->name, PALETTE_SUFFIX);
2241 _DtAddToResource(style.display, xrdb_string);
2243 /* update the defaultName */
2244 XtFree(defaultName);
2245 defaultName = (char *)XtMalloc(strlen(pCurrentPalette->name)+1);
2246 strcpy(defaultName, pCurrentPalette->name);
2249 /* update Xrdb for non Motif1.1 clients */
2250 if (style.xrdb.writeXrdbColors)
2253 OWsyncColorResources(style.display, TypeOfMonitor,
2254 pCurrentPalette->color);
2256 int chipnum = TypeOfMonitor == XmCO_HIGH_COLOR ? 4 : 1;
2257 sprintf(xrdb_string,
2258 "*background: #%04X%04X%04X\n*foreground: #%04X%04X%04X\n",
2259 pCurrentPalette->color[chipnum].bg.red,
2260 pCurrentPalette->color[chipnum].bg.green,
2261 pCurrentPalette->color[chipnum].bg.blue,
2262 pCurrentPalette->color[chipnum].fg.red,
2263 pCurrentPalette->color[chipnum].fg.green,
2264 pCurrentPalette->color[chipnum].fg.blue);
2265 _DtAddToResource(style.display, xrdb_string);
2275 XtPointer client_data,
2279 unsigned long *length,
2284 style.colorSrv = True;
2287 if((int)client_data == GET_TYPE_MONITOR)
2289 sscanf ((char *)value, "%x_%x_%x_%x", (unsigned int *) &(TypeOfMonitor),
2290 (unsigned int *) &(UsePixmaps), (unsigned int *) &(FgColor), (unsigned int *) &dynamic_color);
2291 if(dynamic_color == FALSE)
2292 style.dynamicColor = False;
2294 style.dynamicColor = True;
2297 WaitSelection = FALSE;
2300 else /* no response from Color Server - it must not be there */
2302 style.colorSrv = False;
2303 WaitSelection = FALSE;
2307 /************************************************************************
2310 * restore any state information saved with saveBackdrop.
2311 * This is called from restoreSession with the application
2312 * shell and the special xrm database retrieved for restore.
2313 ************************************************************************/
2319 XrmName xrm_name[5];
2320 XrmRepresentation rep_type;
2322 palette *tmp_palette;
2324 /*"paletteDlg" is the resource name of the dialog shell we are saving for.*/
2325 xrm_name [0] = XrmStringToQuark (PALETTEDLG);
2328 /* get x position */
2329 xrm_name [1] = XrmStringToQuark ("x");
2330 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
2331 XtSetArg (save.posArgs[save.poscnt], XmNx, atoi((char *)value.addr)); save.poscnt++;
2334 /* get y position */
2335 xrm_name [1] = XrmStringToQuark ("y");
2336 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
2337 XtSetArg (save.posArgs[save.poscnt], XmNy, atoi((char *)value.addr)); save.poscnt++;
2340 /* get selected palette */
2341 xrm_name [1] = XrmStringToQuark ("selected_palette");
2342 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
2343 strcpy(defaultName_restore, value.addr);
2346 defaultName_restore[0] = 0;
2348 /* get selected button */
2349 xrm_name [1] = XrmStringToQuark ("selected_button");
2350 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
2351 selected_button = atoi((char *)value.addr);
2354 /* need to have some variables initialized before creating the
2355 Color's dialog ... */
2357 CheckMonitor(shell);
2358 GetDefaultPal(shell);
2360 xrm_name [1] = XrmStringToQuark ("ismapped");
2361 XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
2362 /* Are we supposed to be mapped? */
2363 if (strcmp(value.addr, "True") == 0) {
2364 save.restoreFlag = True;
2370 /************************************************************************
2373 * This routine will write out to the passed file descriptor any state
2374 * information this dialog needs. It is called from saveSessionCB with the
2375 * file already opened.
2376 * All information is saved in xrm format. There is no restriction
2377 * on what can be saved. It doesn't have to be defined or be part of any
2378 * widget or Xt definition. Just name and save it here and recover it in
2379 * restoreBackdrop. The suggested minimum is whether you are mapped, and your
2381 ************************************************************************/
2387 char *bufr = style.tmpBigStr; /* size=[1024], make bigger if needed */
2388 XmVendorShellExtObject vendorExt;
2389 XmWidgetExtData extData;
2391 if (style.colorDialog != NULL)
2393 if (XtIsManaged(style.colorDialog))
2394 sprintf(bufr, "*paletteDlg.ismapped: True\n");
2396 sprintf(bufr, "*paletteDlg.ismapped: False\n");
2398 /* Get and write out the geometry info for our Window */
2399 x = XtX(XtParent(style.colorDialog));
2400 y = XtY(XtParent(style.colorDialog));
2402 /* Modify x & y to take into account window mgr frames
2403 * This is pretty bogus, but I don't know a better way to do it.
2405 extData = _XmGetWidgetExtData(style.shell, XmSHELL_EXTENSION);
2406 vendorExt = (XmVendorShellExtObject)extData->widget;
2407 x -= vendorExt->vendor.xOffset;
2408 y -= vendorExt->vendor.yOffset;
2410 sprintf(bufr, "%s*paletteDlg.x: %d\n", bufr, x);
2411 sprintf(bufr, "%s*paletteDlg.y: %d\n", bufr, y);
2412 sprintf(bufr, "%s*paletteDlg.selected_palette: %s\n", bufr,
2413 pCurrentPalette->name);
2414 sprintf(bufr, "%s*paletteDlg.selected_button: %d\n", bufr,
2416 write (fd, bufr, strlen(bufr));
2420 /**************************************************************************
2422 * SameName - procedure used by the Add palette .. if the palette desc the
2423 * user selects is the same name as a palette already in the
2424 * linked list this procedure gets called. It set up a
2425 * Warning dialog asking the user if they really want to add
2426 * a palette with the same name as an existing palette.
2428 **************************************************************************/
2432 palette *tmpPalette,
2439 if (colorDialog.dlg == NULL) {
2440 tmpStr = (char *)XtMalloc(strlen(STR1) + strlen(name) + 1);
2441 sprintf(tmpStr, STR1, name);
2442 XtSetArg(args[n], XmNmessageString, CMPSTR(tmpStr)); n++;
2443 XtSetArg(args[n], XmNokLabelString, CMPSTR((String) _DtOkString)); n++;
2444 XtSetArg(args[n], XmNcancelLabelString, CMPSTR((String) _DtCancelString)); n++;
2445 XtSetArg(args[n], XmNhelpLabelString, CMPSTR((String) _DtHelpString)); n++;
2446 XtSetArg(args[n], XmNmwmFunctions, DIALOG_MWM_FUNC ); n++;
2447 XtSetArg(args[n], XmNdialogTitle, CMPSTR(((char *)GETMESSAGE(14, 21, "Warning")))); n++;
2448 colorDialog.dlg = XmCreateWarningDialog(style.colorDialog, "QNotice", args, n);
2449 XtAddCallback(colorDialog.dlg, XmNokCallback, setDlgOkCB, (XtPointer)tmpPalette);
2450 XtAddCallback(colorDialog.dlg, XmNhelpCallback,
2451 (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_ADD_PALETTE_WARNING_DIALOG);
2454 XtSetArg (args[n], XmNmwmInputMode,
2455 MWM_INPUT_PRIMARY_APPLICATION_MODAL); n++;
2456 XtSetValues (XtParent(colorDialog.dlg), args, n);
2459 XtManageChild(colorDialog.dlg);
2462 /****************************************************************************
2464 * ValidName - procedure which checks to make sure the name being passed
2465 * in is a valid filename. Weeds out many of the non
2466 * alphabit characters.
2468 ***************************************************************************/
2474 Boolean valid = True;
2479 if (!name || strlen(name) == 0)
2485 chlen = mblen (&name[0], MB_CUR_MAX);
2486 for (i = 0; (i < strlen(name)) && chlen && valid; i += chlen)
2488 chlen = mblen (&name[i], MB_CUR_MAX);
2490 ((name[i] == '*') ||
2492 (name[i] == '\\') ||
2510 for (i = 0; (i < strlen(name)) && valid; i++)
2512 if (strchr ("|!(){}[]<>*:\"\\", (int) name[i]))
2522 InitializeAtoms( void )
2526 sprintf(cust_str,"%s%d", XmSCUSTOMIZE_DATA, style.screenNum);
2527 XA_CUSTOMIZE = XInternAtom(style.display, cust_str, FALSE);
2528 XA_TYPE_MONITOR = XInternAtom(style.display, TYPE_OF_MONITOR, FALSE);
2529 XA_WM_DELETE_WINDOW = XInternAtom(style.display, "WM_DELETE_WINDOW", False);
2536 char *str_type_return;
2537 XrmValue value_return;
2542 char instanceName[30], instanceClass[30];
2544 /* get the current default palette from the Reource Manager Property */
2546 db = XtDatabase(style.display);
2548 if (TypeOfMonitor == XmCO_BLACK_WHITE)
2550 sprintf(instanceName,"dtsession.%d.monochromePalette", style.screenNum);
2551 sprintf(instanceClass,"Dtsession.%d.MonochromePalette", style.screenNum);
2555 sprintf(instanceName,"dtsession.%d.colorPalette", style.screenNum);
2556 sprintf(instanceClass,"Dtsession.%d.ColorPalette", style.screenNum);
2559 if (status = XrmGetResource (db, instanceName, instanceClass,
2560 &str_type_return, &value_return))
2562 /* copy string to defaultName */
2563 defaultName = (char *) XtMalloc( value_return.size );
2564 strcpy (defaultName, value_return.addr);
2565 p = strstr (defaultName, PALETTE_SUFFIX);
2570 /* set defaultName to default palette */
2571 defaultName = (char *) XtMalloc( strlen(DEFAULT_PALETTE));
2572 strcpy (defaultName, DEFAULT_PALETTE);
2580 XmString button_string[NUM_LABELS];
2588 /* Get the default value of multiclick */
2589 dclick_time = XtGetMultiClickTime(style.display);
2592 if(!XtIsRealized(parent))
2593 XtRealizeWidget(parent);
2595 /* Set up DialogBox button labels. */
2596 button_string[0] = CMPSTR((String) _DtOkString);
2597 button_string[1] = CMPSTR((String) _DtCancelString);
2598 button_string[2] = CMPSTR((String) _DtHelpString);
2601 * Note that save.poscnt has been initialized elsewhere.
2602 * save.posArgs may contain information from restoreColor().*/
2604 XtSetArg (save.posArgs[save.poscnt], XmNchildType, XmWORK_AREA); save.poscnt++;
2605 XtSetArg (save.posArgs[save.poscnt], XmNbuttonCount, NUM_LABELS); save.poscnt++;
2606 XtSetArg (save.posArgs[save.poscnt], XmNbuttonLabelStrings, button_string); save.poscnt++;
2607 XtSetArg (save.posArgs[save.poscnt], XmNdefaultPosition, False); save.poscnt++;
2608 style.colorDialog = __DtCreateDialogBoxDialog(parent,PALETTEDLG, save.posArgs, save.poscnt);
2609 XtAddCallback(style.colorDialog, XmNcallback, dialogBoxCB, NULL);
2610 XtAddCallback(style.colorDialog, XmNmapCallback, _DtmapCB, parent);
2611 XtAddCallback(style.colorDialog, XmNhelpCallback,
2612 (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_COLOR_DIALOG);
2614 XmStringFree(button_string[0]);
2615 XmStringFree(button_string[1]);
2616 XmStringFree(button_string[2]);
2618 w = _DtDialogBoxGetButton(style.colorDialog,2);
2620 XtSetArg(args[n], XmNautoUnmanage, False); n++;
2621 XtSetArg(args[n], XmNcancelButton, w); n++;
2622 XtSetValues (style.colorDialog, args, n);
2628 AddToDialogBox( void )
2637 XtSetArg (args[n], XmNtitle, ((char *)GETMESSAGE(14, 30, "Style Manager - Color"))); n++;
2638 XtSetArg (args[n], XmNuseAsyncGeometry, True); n++;
2639 XtSetArg (args[n], XmNmwmFunctions, DIALOG_MWM_FUNC); n++;
2640 XtSetValues (XtParent(style.colorDialog), args, n);
2642 /* Add save session property to the main window */
2643 XmAddWMProtocolCallback(XtParent(style.colorDialog),
2644 XA_WM_DELETE_WINDOW, activateCBexitColor, NULL);
2647 ** Create a main form for color dialog
2650 XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
2651 XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
2652 colorDialog.colorForm = XmCreateForm(style.colorDialog, "colorForm", args, n);
2653 XtManageChild(colorDialog.colorForm);
2659 CreateTopColor1( void )
2668 ** titlebox as child of the main form
2671 XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
2672 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2673 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
2674 XtSetArg (args[n], XmNmarginWidth, 0); n++;
2675 XtSetArg (args[n], XmNmarginHeight, 0); n++;
2676 string = CMPSTR(((char *)GETMESSAGE(14, 5, "Palettes")));
2677 XtSetArg (args[n], XmNtitleString, string); n++;
2678 colorDialog.paletteTB = _DtCreateTitleBox(colorDialog.colorForm, "paletteTB", args, n);
2679 XtManageChild(colorDialog.paletteTB);
2680 XmStringFree(string);
2683 ** Create a form inside palette titlebox
2686 XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
2687 XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
2688 colorDialog.palettesForm = XmCreateForm(colorDialog.paletteTB, "palettesForm", args, n);
2689 XtManageChild(colorDialog.palettesForm);
2695 CreateTopColor2( void )
2703 ** Create a scrolled list widget. This widget will contain the list of
2704 ** palettes currently loaded (by ReadPalettes) in the customizer.
2707 XtSetArg (args[n], XmNselectionPolicy, XmBROWSE_SELECT); n++;
2708 XtSetArg (args[n], XmNautomaticSelection, True); n++;
2709 XtSetArg (args[n], XmNvisibleItemCount, 6); n++;
2710 paletteList = XmCreateScrolledList(colorDialog.palettesForm,"paletteList",args,n);
2711 XtAddCallback(paletteList, XmNbrowseSelectionCallback,
2712 selectPaletteCB, NULL);
2715 XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
2716 XtSetArg (args[n], XmNtopOffset, style.horizontalSpacing); n++;
2717 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2718 XtSetArg (args[n], XmNleftOffset, style.horizontalSpacing); n++;
2719 XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
2720 XtSetArg (args[n], XmNrightPosition, 60); n++;
2721 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
2722 XtSetValues (XtParent(paletteList), args, n);
2728 CreateBottomColor( void )
2733 Widget addDeleteForm;
2736 colorDialog.dlg = NULL;
2738 if(style.count > 10)
2742 if(style.dynamicColor)
2744 /* Create form for Add and Delete buttons */
2746 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
2747 XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
2748 XtSetArg(args[n], XmNleftWidget, paletteList); n++;
2749 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
2750 XtSetArg(args[n], XmNrightOffset, 0); n++;
2751 XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
2752 XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
2753 XtSetArg(args[n], XmNallowOverlap, False); n++;
2754 XtSetArg(args[n], XmNchildType, XmWORK_AREA); n++;
2756 XmCreateForm(colorDialog.palettesForm, "addDeleteForm", args, n);
2757 XtManageChild(addDeleteForm);
2759 /* Create Add button */
2761 XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
2762 XtSetArg (args[n], XmNtopOffset, ADD_PALETTE_TOP_OFFSET); n++;
2763 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2764 XtSetArg (args[n], XmNleftOffset, style.horizontalSpacing); n++;
2765 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
2766 string = CMPSTR(((char *)GETMESSAGE(14, 6, "Add...")));
2767 XtSetArg (args[n], XmNlabelString, string); n++;
2768 colorDialog.addPaletteButton =
2769 XmCreatePushButtonGadget(addDeleteForm, "addPalette", args, n);
2770 XmStringFree(string);
2771 XtManageChild(colorDialog.addPaletteButton);
2772 XtAddCallback(colorDialog.addPaletteButton, XmNactivateCallback, addPaletteCB,
2775 /* Create Delete button */
2777 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
2778 XtSetArg (args[n], XmNtopWidget, colorDialog.addPaletteButton); n++;
2779 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2780 XtSetArg (args[n], XmNleftOffset, style.horizontalSpacing); n++;
2781 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
2782 string = CMPSTR(((char *)GETMESSAGE(14, 7, "Delete...")));
2783 XtSetArg (args[n], XmNlabelString, string); n++;
2784 colorDialog.deletePaletteButton =
2785 XmCreatePushButtonGadget(addDeleteForm,"deletePalette",args,n);
2786 XmStringFree(string);
2787 XtManageChild(colorDialog.deletePaletteButton);
2788 XtAddCallback(colorDialog.deletePaletteButton, XmNactivateCallback, deletePaletteCB,
2793 ** Create a title box for palette color buttons
2796 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
2797 XtSetArg (args[n], XmNtopWidget, colorDialog.paletteTB); n++;
2798 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2799 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
2800 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
2801 XtSetArg (args[n], XmNmarginWidth, 0); n++;
2802 XtSetArg (args[n], XmNmarginHeight, 0); n++;
2803 string = CMPSTR(pCurrentPalette->desc);
2804 XtSetArg (args[n], XmNtitleString, string); n++;
2805 colorDialog.buttonsTB = _DtCreateTitleBox(colorDialog.colorForm, "ButtonsTB", args, n);
2806 XtManageChild(colorDialog.buttonsTB);
2807 XmStringFree(string);
2809 /* Create a form inside palette buttons titlebox */
2811 XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
2812 XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
2813 style.buttonsForm = XmCreateForm(colorDialog.buttonsTB, "buttonsForm", args, n);
2814 XtManageChild(style.buttonsForm);
2816 /* Create Modify... button */
2817 if(style.dynamicColor)
2820 XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
2821 XtSetArg (args[n], XmNtopOffset, style.horizontalSpacing+BORDER_WIDTH); n++;
2822 XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
2823 XtSetArg (args[n], XmNleftPosition, ADD_PALETTE_LEFT_POSITION); n++;
2824 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
2825 string = CMPSTR(((char *)GETMESSAGE(14, 8, "Modify...")));
2826 XtSetArg (args[n], XmNlabelString, string); n++;
2828 XmCreatePushButtonGadget(style.buttonsForm, "modifyColorButton", args, n);
2829 XmStringFree(string);
2830 XtManageChild(modifyColorButton);
2831 XtAddCallback(modifyColorButton, XmNactivateCallback, modifyColorCB,
2835 ** Create a pushbutton for configuring DT colors
2838 XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
2839 XtSetArg (args[n], XmNtopWidget, colorDialog.buttonsTB); n++;
2840 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
2841 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
2842 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
2843 XtSetArg (args[n], XmNnavigationType, XmTAB_GROUP); n++;
2844 string = CMPSTR(((char *)GETMESSAGE(14, 40, "Number Of Colors...")));
2845 XtSetArg (args[n], XmNlabelString, string); n++;
2846 resourcesPB = XmCreatePushButtonGadget(colorDialog.colorForm, "resourcesPB", args, n);
2847 XtManageChild(resourcesPB);
2848 XtAddCallback(resourcesPB, XmNactivateCallback, resourcesCB,
2849 (XtPointer) style.colorDialog);
2850 XmStringFree(string);