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 /* $TOG: Backdrop.c /main/7 1998/11/25 14:48:36 samborn $ */
24 /************************************<+>*************************************
25 ****************************************************************************
31 ** Description: Controls the Dtstyle Backdrop dialog
34 ** (c) Copyright Hewlett-Packard Company, 1990, 1993.
38 ****************************************************************************
39 ************************************<+>*************************************/
41 /*+++++++++++++++++++++++++++++++++++++++*/
43 /*+++++++++++++++++++++++++++++++++++++++*/
47 #include <sys/types.h>
49 #if defined(_AIX) || defined(__apollo)
52 #include <dirent.h> /* opendir(), directory(3C) */
56 #include <X11/apollosys.h> /* needed for S_ISDIR macro */
62 #include <Xm/MwmUtil.h>
66 #include <Xm/DrawnB.h>
69 #include <Xm/VendorSEP.h>
70 #include <Xm/AtomMgr.h>
72 #include <Dt/DialogBox.h>
74 #include <Dt/Message.h>
75 #include <Dt/SessionM.h>
76 #include <Dt/HourGlass.h>
78 #include <Dt/UserMsg.h>
82 #include "SaveRestore.h"
84 /*+++++++++++++++++++++++++++++++++++++++*/
85 /* include extern functions */
86 /*+++++++++++++++++++++++++++++++++++++++*/
90 /*+++++++++++++++++++++++++++++++++++++++*/
92 /*+++++++++++++++++++++++++++++++++++++++*/
93 #define MAX_STR_LEN 128
95 #define B_APPLY_BUTTON 2
96 #define B_CANCEL_BUTTON 3
97 #define B_HELP_BUTTON 4
99 #define ERR2 ((char *)GETMESSAGE(11, 2, "The backdrop portion of the Style Manager\n\
100 will not operate because there are no backdrop\nfiles available. Check $HOME/.dt/errorlog."))
102 /*+++++++++++++++++++++++++++++++++++++++*/
103 /* Internal Functions */
104 /*+++++++++++++++++++++++++++++++++++++++*/
106 static int CreateBackdropDialog( Widget parent) ;
107 static void MoreBitmaps( void ) ;
108 static ReadBitmaps( void ) ;
109 static Boolean CreatePixmaps( void ) ;
110 static ReadBitmapDirectory( char *dir ) ;
111 static void DrawBitmap(
113 XtPointer client_data,
114 XtPointer call_data) ;
115 static void SizeBitmap(
117 XtPointer client_data,
118 XtPointer call_data) ;
119 static XmString * MakeListStrings( void ) ;
120 static void FreeListStrings( XmString *listPtr) ;
123 XtPointer client_data,
124 XtPointer call_data) ;
125 static void ButtonCB(
127 XtPointer client_data,
128 XtPointer call_data) ;
129 static void GetColors( void ) ;
130 static void FreeAll( void ) ;
131 static void _DtMapCB(
133 XtPointer client_data,
134 XtPointer call_data) ;
137 /*+++++++++++++++++++++++++++++++++++++++*/
138 /* Internal Variables */
139 /*+++++++++++++++++++++++++++++++++++++++*/
145 char **tmpBitmapNames;
147 int tmpMaxNumBitmaps;
161 } Backdrops, *BackdropsPtr;
162 static Backdrops backdrops;
164 static saveRestore save = {FALSE, 0, };
165 char *BACKDROPSDLG = "backdropsDialog";
168 * copy of the system backdrop description file for the
169 * current locale in xrm form
171 static XrmDatabase sys_bd_DB = NULL;
174 * copy of the admin backdrop description file for the
175 * current locale in xrm form
177 static XrmDatabase adm_bd_DB = NULL;
180 * copy of the user's home backdrop description file for the
181 * current locale in xrm form
183 static XrmDatabase hm_bd_DB = NULL;
186 * final combination of the admin & system data bases
188 static XrmDatabase bd_DB = NULL;
192 /*+++++++++++++++++++++++++++++++++++++++*/
194 /*+++++++++++++++++++++++++++++++++++++++*/
197 build_dirList(char * dirStr,
200 char tokenSep[] = ":";
202 char ** dirList = NULL;
205 int len = strlen(dirStr);
208 tmpStr = (char *)XtCalloc(1, len + 1);
209 strcpy(tmpStr, dirStr);
210 token = strtok(tmpStr, tokenSep);
214 token = strtok(NULL, tokenSep);
220 dirList = (char **) XtCalloc(1, i * sizeof(char *));
223 strcpy(tmpStr, dirStr);
224 token = strtok(tmpStr, tokenSep);
228 dirList[*count] = (char *) XtCalloc(1, strlen( token ) + 1);
229 strcpy(dirList[*count], token);
230 token = strtok(NULL, tokenSep);
235 XtFree ((char *) tmpStr);
241 /*+++++++++++++++++++++++++++++++++++++++*/
243 /*+++++++++++++++++++++++++++++++++++++++*/
246 free_dirList(char ** dirList,
254 for (i=0; i<count; i++)
255 XtFree((char *) dirList[i]);
257 XtFree ((char *) dirList);
261 /************************************************************************
262 * SelectCurrentBackdrop() - Selects current backdrop in list
264 ************************************************************************/
265 void SelectCurrentBackdrop(callback)
267 DtWsmWorkspaceInfo *wInfo=NULL;
273 if ((DtWsmGetCurrentWorkspace (style.display, style.root, &aWS)
275 (DtWsmGetWorkspaceInfo (style.display, style.root, aWS, &wInfo)
281 list = XtNameToWidget(style.backdropDialog, "*bitmapList");
283 backdropName = XmGetAtomName(style.display, wInfo->backdropName);
285 for (i = 0; i < backdrops.numBitmaps; i++) {
286 if (strcmp(backdrops.bitmapNames[i], backdropName) == 0) {
287 XmListSelectPos (list, i + 1, callback);
288 XmListSetPos(list, i + 1);
289 backdrops.selected = i;
293 XtFree((char *) backdropName);
294 XtFree((char *) wInfo);
297 /************************************************************************
298 * BackdropDialog() - Create backdrop selection dialog first time up.
299 * If it has already been created, map it.
300 ************************************************************************/
307 if (style.backdropDialog == NULL)
309 _DtTurnOnHourGlass(parent);
310 if (!CreateBackdropDialog(parent)) {
311 _DtTurnOffHourGlass(parent);
314 SelectCurrentBackdrop(False);
315 XtManageChild(style.backdropDialog);
316 XSync(style.display, 0);
317 XmUpdateDisplay(style.backdropDialog);
318 _DtTurnOffHourGlass(parent);
323 SelectCurrentBackdrop(True);
324 XtManageChild(style.backdropDialog);
325 raiseWindow(XtWindow(XtParent(style.backdropDialog)));
326 XmUpdateDisplay(style.backdropDialog);
331 /************************************************************************
332 * CreateBackdropDialog()
333 * Create the Backdrop Dialog
334 ************************************************************************/
336 CreateBackdropDialog(
343 XmString strings[NUM_LABELS+1];
344 XmString *listStrings;
349 if (backdrops.noBitmaps)
351 ErrDialog (backdrops.errStr, style.shell);
355 /* initialize backdrop data */
356 backdrops.bitmapNames = NULL;
357 backdrops.bitmaps = NULL;
358 backdrops.numBitmaps = 0;
359 backdrops.maxNumBitmaps = 100;
360 backdrops.selected = -1;
362 backdrops.errStr = NULL;
363 backdrops.shadow = 2;
364 backdrops.width = 200 - 2*backdrops.shadow;
365 backdrops.height = 200 - 2*backdrops.shadow;
366 backdrops.newColors = True;
369 /* load the backdrop description data base for the given locale*/
370 /* from that locale's description file from the system location */
371 lang = setlocale (LC_CTYPE,NULL);
373 #ifdef hpux /* hpux-specific parsing of the locale string */
374 /* The following code is identical to the
375 ExtractLocaleName function in WmResParse.c
378 #define MAXLOCALE 64 /* buffer size of locale name */
383 static char buf[MAXLOCALE];
385 /* If lang has a substring ":<category>;", extract <category>
386 * from the first such occurrence as the locale name.
390 if (start = strchr (lang, ':')) {
392 if (end = strchr (start, ';')) {
394 strncpy(buf, start, len);
402 bd_desc = (char *)XtMalloc(strlen("/usr/dt/backdrops/desc.") + strlen(lang) + 1);
403 strcpy (bd_desc,"/usr/dt/backdrops/desc.");
404 strcat (bd_desc, lang);
405 if(sys_bd_DB = XrmGetFileDatabase (bd_desc))
406 XrmMergeDatabases(sys_bd_DB, &bd_DB);
409 /* load the backdrop description data base for the given locale*/
410 /* from that locale's description file from the admin location */
411 bd_desc = (char *)XtMalloc(strlen("/etc/dt/backdrops/desc.") + strlen(lang) + 1);
412 strcpy (bd_desc,"/etc/dt/backdrops/desc.");
413 strcat (bd_desc, lang);
414 if (adm_bd_DB = XrmGetFileDatabase (bd_desc))
415 XrmMergeDatabases(adm_bd_DB, &bd_DB);
418 /* load the backdrop description from the user's .dt/backdrops directory */
419 /* regardless of locale */
420 bd_desc = (char *)XtMalloc(strlen(style.home) + strlen("/.dt/backdrops/desc.backdrops") + 1);
421 strcpy (bd_desc, style.home);
422 strcat (bd_desc, "/.dt/backdrops/desc.backdrops");
423 if (hm_bd_DB = XrmGetFileDatabase (bd_desc))
424 XrmMergeDatabases(hm_bd_DB, &bd_DB);
427 /* Set up DialogBox button labels. */
428 strings[0] = XmStringCreateLocalized ((String) _DtOkString);
429 strings[1] = XmStringCreateLocalized ((String) _DtApplyString);
430 strings[2] = XmStringCreateLocalized ((String) _DtCloseString);
431 strings[3] = XmStringCreateLocalized ((String) _DtHelpString);
434 * Note that save.poscnt has been initialized elsewhere.
435 * save.posArgs may contain information from restoreBackdrop().*/
437 /* create the dialog box with shell */
439 XtSetArg (save.posArgs[save.poscnt], XmNbuttonCount, NUM_LABELS+1);
441 XtSetArg (save.posArgs[save.poscnt], XmNbuttonLabelStrings, strings);
443 XtSetArg (save.posArgs[save.poscnt], XmNdefaultPosition, False);
445 XtSetArg (save.posArgs[save.poscnt], XmNallowOverlap, False);
447 style.backdropDialog = __DtCreateDialogBoxDialog (parent, BACKDROPSDLG,
448 save.posArgs, save.poscnt);
449 XtAddCallback(style.backdropDialog, XmNcallback, ButtonCB, NULL);
450 XtAddCallback(style.backdropDialog, XmNmapCallback, _DtMapCB, parent);
451 XtAddCallback(style.backdropDialog, XmNhelpCallback,
452 (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_BACKDROP_DIALOG);
454 /* free compound strings now */
455 XmStringFree (strings[0]);
456 XmStringFree (strings[1]);
457 XmStringFree (strings[2]);
458 XmStringFree (strings[3]);
461 XtSetArg (args[n], XmNtitle, ((char *)GETMESSAGE(11, 12, "Style Manager - Backdrop"))); n++;
462 XtSetArg (args[n], XmNuseAsyncGeometry, True); n++;
463 XtSetValues (XtParent(style.backdropDialog), args, n);
465 /* get bitmap data */
466 if (!ReadBitmaps()) return 0; /* uses style.backdropDialog */
468 /* create the form to go in to dialog box as the work area */
470 XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
471 XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
472 XtSetArg (args[n], XmNchildType, XmWORK_AREA); n++;
474 XtSetArg (args[n], XmNallowOverlap, False); n++;
475 mainForm = XmCreateForm (style.backdropDialog, "backdropsForm", args, n);
477 /* create the scrolled list of bitmap names... first create XmStrings */
478 listStrings = MakeListStrings ();
480 XtSetArg (args[n], XmNautomaticSelection, True); n++;
481 XtSetArg (args[n], XmNselectionPolicy, XmBROWSE_SELECT); n++;
482 XtSetArg (args[n], XmNitems, listStrings); n++;
483 XtSetArg (args[n], XmNitemCount, backdrops.numBitmaps); n++;
484 list = XmCreateScrolledList (mainForm, "bitmapList", args, n);
485 XtAddCallback (list, XmNbrowseSelectionCallback, ListCB, (XtPointer)NULL);
486 FreeListStrings (listStrings); /* after list has copied */
488 /* set up attachments for scrolled list itself */
490 XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
491 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
492 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
493 XtSetValues (XtParent(list), args, n);
495 /* Create drawing area for the bitmap */
497 XtSetArg (args[n], XmNshadowType, XmSHADOW_IN); n++;
498 XtSetArg (args[n], XmNshadowThickness, backdrops.shadow); n++;
499 XtSetArg (args[n], XmNhighlightThickness, 0); n++;
500 XtSetArg (args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
501 XtSetArg (args[n], XmNrightWidget, XtParent(list)); n++;
502 XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
503 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
504 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
505 XtSetArg (args[n], XmNborderWidth, 0); n++;
506 XtSetArg (args[n], XmNwidth, backdrops.width+2*backdrops.shadow); n++;
507 XtSetArg (args[n], XmNheight, backdrops.height+2*backdrops.shadow); n++;
508 XtSetArg (args[n], XmNtraversalOn, False); n++;
509 backdrops.drawnButton = XmCreateDrawnButton (mainForm, "bitmap", args, n);
510 XtAddCallback (backdrops.drawnButton, XmNexposeCallback, DrawBitmap, NULL);
511 XtAddCallback (backdrops.drawnButton, XmNresizeCallback, SizeBitmap, NULL);
513 /* manage all of the widgets */
514 XtManageChild (mainForm);
515 XtManageChild (backdrops.drawnButton);
516 XtManageChild (list);
522 /************************************************************************
524 * Create space for more bitmap entries
525 ************************************************************************/
531 /* allocate space for icon names */
532 newSize = (backdrops.maxNumBitmaps + 100) * sizeof(char *);
533 backdrops.bitmapNames = (char **) XtRealloc((char *)backdrops.bitmapNames,
536 /* now allocate new bitmap space */
537 newSize = (backdrops.maxNumBitmaps + 100) * sizeof(Pixmap);
538 backdrops.bitmaps = (Pixmap *)XtRealloc((char *)backdrops.bitmaps, newSize);
540 backdrops.maxNumBitmaps += 100;
543 /************************************************************************
545 * qsort() sort function, used for sorting bitmap names into alphabetical order
546 * can't use strcmp() due to char** rather than char*
547 ************************************************************************/
549 cmpstringp(const void *p1, const void *p2)
551 return strcmp(*(char * const *) p1, *(char * const *) p2);
554 /************************************************************************
556 * Create an array of bitmaps by reading backdrop directories in the
557 * following order overriding any duplicates:
558 * 1) Read the system location /usr/dt/backdrops
559 * 2) Read the admin location /etc/dt/backdrops
560 * 3) Read the directories specified by the backdropDirectories
562 * 4) Read the user's home directory /$HOME/.dt/backdrops.
563 ************************************************************************/
569 int width, height, x, y;
574 /* allocate space for temporary bitmap info */
575 backdrops.tmpBitmapNames = (char **)XtCalloc(100, sizeof(char *));
576 backdrops.tmpMaxNumBitmaps = 100;
577 backdrops.tmpNumBitmaps = 0;
579 /* read system backdrop directory */
580 ReadBitmapDirectory("/usr/dt/backdrops");
581 /* read sys admin backdrop directory */
582 ReadBitmapDirectory("/etc/dt/backdrops");
584 /* Parse the backdropDirectories resource to get the individual directories */
585 if (style.xrdb.backdropDir)
587 backdrops.dirList = build_dirList(style.xrdb.backdropDir, &backdrops.dirCount);
589 /* compile the list of bitmaps */
590 for (i=0; i<backdrops.dirCount; i++)
591 ReadBitmapDirectory(backdrops.dirList[i]);
594 /* read the directory $HOME/.dt/backdrops */
595 string = (char *)XtMalloc(strlen(style.home) + strlen("/.dt/backdrops") + 1);
596 sprintf(string, "%s/.dt/backdrops", style.home);
597 ReadBitmapDirectory(string);
601 if (backdrops.tmpNumBitmaps == 0)
603 /* give error dialog, free space, and return */
604 backdrops.errStr = (char *)XtMalloc(strlen(ERR2) + 1);
605 sprintf(backdrops.errStr, "%s", ERR2);
606 ErrDialog (backdrops.errStr, style.shell);
608 free_dirList(backdrops.dirList, backdrops.dirCount);
612 /* Sort the list into alphanetical order */
613 qsort(backdrops.tmpBitmapNames, backdrops.tmpNumBitmaps, sizeof(char *), cmpstringp);
615 /* get the fg/bg colors from Dtwm */
616 if (backdrops.newColors)
619 backdrops.newColors = False;
622 /* create all the pixmaps */
623 if (!CreatePixmaps())
625 /* give error dialog, free space, and return */
626 backdrops.errStr = (char *)XtMalloc(strlen(ERR2) + 1);
627 sprintf(backdrops.errStr, "%s", ERR2);
628 ErrDialog (backdrops.errStr, style.shell);
630 free_dirList(backdrops.dirList, backdrops.dirCount);
635 if (backdrops.selected == -1) backdrops.selected = 0;
642 /************************************************************************
644 * Create the pixmpas in the backdrop list
645 with workprocs 10 at a time
646 ************************************************************************/
648 CreatePixmaps( void )
651 static int pixmapsCreated=0;
655 backdrops.numBitmaps = 0;
657 /* allocate space for real bitmap info */
658 backdrops.bitmapNames = (char **)XtCalloc(100, sizeof(char *));
659 backdrops.bitmaps = (Pixmap *)XtCalloc(100, sizeof(Pixmap));
661 for (i=0; i<backdrops.tmpNumBitmaps; i++)
663 tmpPixmap = XmGetPixmap (style.screen,
664 backdrops.tmpBitmapNames[i],
665 backdrops.fg, backdrops.bg);
666 if (tmpPixmap != XmUNSPECIFIED_PIXMAP)
668 if (backdrops.numBitmaps == backdrops.maxNumBitmaps)
671 backdrops.bitmapNames[backdrops.numBitmaps] =
672 backdrops.tmpBitmapNames[i];
673 backdrops.bitmaps[backdrops.numBitmaps] = tmpPixmap;
675 backdrops.numBitmaps++;
679 if (backdrops.numBitmaps)
687 /************************************************************************
688 * ReadBitmapDirectory()
689 * Create an array of bitmap names overriding duplicates
690 ************************************************************************/
697 struct dirent *filep;
702 struct stat stat_buf;
703 char *statPath, *pStatPath;
706 /* open the backdrops directory */
707 if ((dirp = opendir(dir)) == NULL)
709 /* print message to errorlog, free space, and return */
713 /* create string to contain complete path */
714 statPath = (char *) XtMalloc(strlen(dir) + MAX_STR_LEN + 2);
715 strcpy (statPath, dir);
716 strcat (statPath, "/");
717 pStatPath = statPath + strlen(statPath);
719 filep = readdir(dirp);
721 while (filep != NULL)
723 /* append filename to stat path */
724 strcpy (pStatPath, filep->d_name);
727 if ((stat_result = stat (statPath, &stat_buf)) != 0)
729 filep = readdir(dirp);
733 /* skip directories */
734 if ((stat_buf.st_mode & S_IFMT) == S_IFDIR)
736 filep = readdir(dirp);
741 /* strip suffix off filename */
742 name = (char *) XtMalloc(strlen(filep->d_name) + 1);
743 strcpy (name, filep->d_name);
744 (void)strtok(name, ".");
746 /* check for duplicates */
748 for (i=0; i<backdrops.tmpNumBitmaps; i++)
750 if (!strcmp(backdrops.tmpBitmapNames[i], name))
759 /* add to the temporary bitmap list */
761 if (backdrops.tmpNumBitmaps == backdrops.tmpMaxNumBitmaps)
763 /* allocate space for more temporary bitmap info */
764 newSize = (backdrops.tmpMaxNumBitmaps + 100) * sizeof(char *);
765 backdrops.tmpBitmapNames =
766 (char **)XtRealloc((char *)backdrops.tmpBitmapNames, newSize);
767 backdrops.tmpMaxNumBitmaps += 100;
770 backdrops.tmpBitmapNames[backdrops.tmpNumBitmaps] =
771 (char *) XtMalloc(strlen(name)+1);
772 strcpy (backdrops.tmpBitmapNames[backdrops.tmpNumBitmaps], name);
774 backdrops.tmpNumBitmaps++;
777 filep = readdir(dirp);
789 /************************************************************************
791 * This is the exposeCallback for the bitmap drawing area.
792 ************************************************************************/
796 XtPointer client_data,
797 XtPointer call_data )
802 if (backdrops.selected == -1)
805 if (backdrops.newColors)
809 /* we could keep track of which tile pixmaps need to be updated
810 since the last workspace change, but for now simply regenerate
811 each pixmap as it is selected after a workspace change has
814 /* backdrops.newColors = False; */
817 if (backdrops.gc == NULL)
819 gcValues.background = backdrops.bg;
820 gcValues.foreground = backdrops.fg;
821 gcValues.fill_style = FillTiled;
822 gcValues.tile = backdrops.bitmaps[backdrops.selected];
824 backdrops.gc = XCreateGC (style.display, XtWindow(w),
825 GCForeground | GCBackground |
826 GCTile | GCFillStyle, &gcValues);
829 XFillRectangle (style.display, XtWindow(w), backdrops.gc, backdrops.shadow,
830 backdrops.shadow, backdrops.width, backdrops.height);
834 /************************************************************************
836 * This is the resizeCallback for the bitmap drawing area.
837 ************************************************************************/
841 XtPointer client_data,
842 XtPointer call_data )
844 backdrops.width = XtWidth(w) - 2*backdrops.shadow;
845 backdrops.height = XtHeight(w) - 2*backdrops.shadow;
849 /************************************************************************
851 * Make XmStrings from the bitmap descriptions, to pass into list.
853 ************************************************************************/
855 MakeListStrings( void )
861 char *str_type_return;
862 XrmValue value_return;
864 /* allocate space for bitmap descriptions */
865 backdrops.bitmapDescs = (char **)XtCalloc(backdrops.numBitmaps, sizeof(char *));
867 for (i=0; i<backdrops.numBitmaps; i++)
871 name_str = (char *) XtMalloc(strlen("backdrops.") +
872 strlen(backdrops.bitmapNames[i]) +
873 strlen(".desc") + 1);
875 class_str = (char *) XtMalloc(strlen("Backdrops.") +
876 strlen(backdrops.bitmapNames[i]) +
877 strlen(".Desc") + 1);
878 strcpy(name_str, "backdrops.");
879 strcpy(class_str, "Backdrops.");
880 strcat(name_str, backdrops.bitmapNames[i]);
881 strcat(class_str, backdrops.bitmapNames[i]);
882 strcat(name_str, ".desc");
883 strcat(class_str, ".Desc");
885 if (XrmGetResource (bd_DB, name_str, class_str, &str_type_return, &value_return))
887 /* make copy of resource value */
888 backdrops.bitmapDescs[i] = (char *) XtMalloc(value_return.size + 1);
889 strcpy (backdrops.bitmapDescs[i], value_return.addr);
893 backdrops.bitmapDescs[i] = (char *) XtMalloc(strlen(backdrops.bitmapNames[i]) + 1);
894 strcpy(backdrops.bitmapDescs[i], backdrops.bitmapNames[i]);
899 backdrops.bitmapDescs[i] = (char *) XtMalloc(strlen(backdrops.bitmapNames[i]) + 1);
900 strcpy(backdrops.bitmapDescs[i], backdrops.bitmapNames[i]);
904 list = (XmString *) XtCalloc(backdrops.numBitmaps, sizeof(XmString));
906 for (i = 0; i < backdrops.numBitmaps; i++)
908 list[i] = XmStringCreateLocalized (backdrops.bitmapDescs[i]);
915 /************************************************************************
917 * Free XmStrings from the bitmap names, passed into list.
918 ************************************************************************/
925 XmString *list = listPtr;
927 for (i = 0; i < backdrops.numBitmaps; i++)
929 if (list[i]) XmStringFree(list[i]);
931 XtFree ((char *)list);
935 /************************************************************************
937 * Get the bitmap selected from the list
938 ************************************************************************/
942 XtPointer client_data,
943 XtPointer call_data )
945 XmListCallbackStruct *cb = (XmListCallbackStruct *)call_data;
947 backdrops.selected = cb->item_position - 1;
949 XSetTile (style.display, backdrops.gc,
950 backdrops.bitmaps[backdrops.selected]);
952 DrawBitmap (backdrops.drawnButton, NULL, NULL);
957 /************************************************************************
960 ************************************************************************/
964 XtPointer client_data,
965 XtPointer call_data )
970 DtDialogBoxCallbackStruct *cb = (DtDialogBoxCallbackStruct *) call_data;
972 switch (cb->button_position)
975 /* send message to update backdrop */
977 num = backdrops.selected;
979 _DtWsmChangeBackdrop(style.display, style.root,
980 backdrops.bitmapNames[num],
981 backdrops.bitmaps[num]);
985 /* send message to update backdrop */
987 num = backdrops.selected;
989 _DtWsmChangeBackdrop(style.display, style.root,
990 backdrops.bitmapNames[num],
991 backdrops.bitmaps[num]);
995 case B_CANCEL_BUTTON: /* close */
1000 XtCallCallbacks(style.backdropDialog, XmNhelpCallback, (XtPointer)NULL);
1009 /************************************************************************
1011 * Workspace may have changed, so get current workspace
1012 * colors and draw the backdrop bitmap
1014 ************************************************************************/
1016 CheckWorkspace( void )
1018 backdrops.newColors = True; /* need to get new colors */
1019 if (style.backdropDialog && XtIsManaged(style.backdropDialog))
1021 DrawBitmap (backdrops.drawnButton, NULL, NULL);
1026 /************************************************************************
1028 * Get current workspace colors, and update GC if needed
1030 ************************************************************************/
1034 DtWsmWorkspaceInfo *wInfo=NULL;
1035 unsigned long num=0;
1040 if ((DtWsmGetCurrentWorkspace (style.display, style.root, &aWS)
1042 (DtWsmGetWorkspaceInfo (style.display, style.root, aWS, &wInfo)
1045 backdrops.bg = wInfo->bg;
1046 backdrops.fg = wInfo->fg;
1047 DtWsmFreeWorkspaceInfo (wInfo);
1055 if (backdrops.gc) /* update the gc if there is one */
1057 gcValues.background = backdrops.bg;
1058 gcValues.foreground = backdrops.fg;
1060 /* free old pixmap */
1061 XmDestroyPixmap(style.screen,
1062 backdrops.bitmaps[backdrops.selected]);
1064 /* allocate new pixmap */
1065 backdrops.bitmaps[backdrops.selected] =
1066 XmGetPixmap (style.screen,
1067 backdrops.bitmapNames[backdrops.selected],
1068 backdrops.fg, backdrops.bg);
1070 gcValues.tile = backdrops.bitmaps[backdrops.selected];
1072 XChangeGC (style.display, backdrops.gc,
1073 GCForeground | GCBackground | GCTile, &gcValues);
1078 /************************************************************************
1080 * Free some space that was allocated for backdrops
1081 ************************************************************************/
1087 /* set no bitmaps flag, so we won't try to get them next time */
1088 backdrops.noBitmaps = 1;
1090 /* free temporary list of backdrop names */
1091 for (i = 0; i < backdrops.tmpNumBitmaps; i++)
1092 if (backdrops.tmpBitmapNames[i])
1093 XtFree(backdrops.tmpBitmapNames[i]);
1094 XtFree ((char *)backdrops.tmpBitmapNames);
1095 XtFree ((char *)backdrops.bitmapNames);
1097 /* free backdrop bitmaps */
1098 for (i = 0; i < backdrops.numBitmaps; i++) {
1099 if (backdrops.bitmaps[i])
1100 XFreePixmap (style.display, backdrops.bitmaps[i]);
1101 if (backdrops.numBitmaps)
1102 XtFree((char *)backdrops.bitmaps);
1105 /* destory widgets (via first parent) */
1106 XtDestroyWidget (XtParent(style.backdropDialog));
1107 style.backdropDialog = NULL;
1111 /************************************************************************
1114 ************************************************************************/
1118 XtPointer client_data,
1119 XtPointer call_data )
1122 DtWsmRemoveWorkspaceFunctions(style.display, XtWindow(XtParent(w)));
1124 if (!save.restoreFlag)
1125 putDialog((Widget)client_data, w);
1127 XtRemoveCallback(style.backdropDialog, XmNmapCallback, _DtMapCB, NULL);
1131 /************************************************************************
1134 * restore any state information saved with saveBackdrop.
1135 * This is called from restoreSession with the application
1136 * shell and the special xrm database retrieved for restore.
1137 ************************************************************************/
1143 XrmName xrm_name[5];
1144 XrmRepresentation rep_type;
1147 xrm_name [0] = XrmStringToQuark (BACKDROPSDLG);
1150 /* get x position */
1151 xrm_name [1] = XrmStringToQuark ("x");
1152 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
1153 XtSetArg (save.posArgs[save.poscnt], XmNx, atoi((char *)value.addr));
1155 save.restoreFlag = True;
1158 /* get y position */
1159 xrm_name [1] = XrmStringToQuark ("y");
1160 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
1161 XtSetArg (save.posArgs[save.poscnt], XmNy, atoi((char *)value.addr));
1166 xrm_name [1] = XrmStringToQuark ("width");
1167 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
1168 XtSetArg(save.posArgs[save.poscnt], XmNwidth, atoi((char *)value.addr));
1173 xrm_name [1] = XrmStringToQuark ("height");
1174 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
1175 XtSetArg(save.posArgs[save.poscnt],XmNheight, atoi((char *)value.addr));
1179 xrm_name [1] = XrmStringToQuark ("ismapped");
1180 XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
1181 /* Are we supposed to be mapped? */
1182 if (strcmp(value.addr, "True") == 0)
1183 BackdropDialog(shell);
1187 /************************************************************************
1190 * This routine will write out to the passed file descriptor any state
1191 * information this dialog needs. It is called from saveSessionCB with the
1192 * file already opened.
1193 * All information is saved in xrm format. There is no restriction
1194 * on what can be saved. It doesn't have to be defined or be part of any
1195 * widget or Xt definition. Just name and save it here and recover it in
1196 * restoreBackdrop. The suggested minimum is whether you are mapped, and your
1198 ************************************************************************/
1204 Dimension width, height;
1205 char *bufr = style.tmpBigStr; /* size=[1024], make bigger if needed */
1206 XmVendorShellExtObject vendorExt;
1207 XmWidgetExtData extData;
1209 if (style.backdropDialog != NULL)
1211 if (XtIsManaged(style.backdropDialog))
1212 sprintf(bufr, "*backdropsDialog.ismapped: True\n");
1214 sprintf(bufr, "*backdropsDialog.ismapped: False\n");
1216 /* Get and write out the geometry info for our Window */
1217 x = XtX (XtParent(style.backdropDialog));
1218 y = XtY (XtParent(style.backdropDialog));
1219 width = XtWidth (style.backdropDialog);
1220 height = XtHeight (style.backdropDialog);
1222 /* Modify x & y to take into account window mgr frames
1223 * This is pretty bogus, but I don't know a better way to do it.
1225 extData = _XmGetWidgetExtData(style.shell, XmSHELL_EXTENSION);
1226 vendorExt = (XmVendorShellExtObject)extData->widget;
1227 x -= vendorExt->vendor.xOffset;
1228 y -= vendorExt->vendor.yOffset;
1230 sprintf(bufr, "%s*backdropsDialog.x: %d\n", bufr, x);
1231 sprintf(bufr, "%s*backdropsDialog.y: %d\n", bufr, y);
1232 sprintf(bufr, "%s*backdropsDialog.width: %d\n", bufr, width);
1233 sprintf(bufr, "%s*backdropsDialog.height: %d\n", bufr, height);
1234 sprintf(bufr, "%s*backdropsDialog.selectedItemNum: %d\n", bufr,
1235 backdrops.selected);
1236 sprintf(bufr, "%s*backdropsDialog.selectedItem: %s\n", bufr,
1237 backdrops.bitmapNames[backdrops.selected]);
1238 write (fd, bufr, strlen(bufr));