2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $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>
53 #include <dirent.h> /* opendir(), directory(3C) */
58 #include <Xm/MwmUtil.h>
62 #include <Xm/DrawnB.h>
65 #include <Xm/VendorSEP.h>
66 #include <Xm/AtomMgr.h>
68 #include <Dt/DialogBox.h>
70 #include <Dt/Message.h>
71 #include <Dt/SessionM.h>
72 #include <Dt/HourGlass.h>
74 #include <Dt/UserMsg.h>
78 #include "SaveRestore.h"
80 /*+++++++++++++++++++++++++++++++++++++++*/
81 /* include extern functions */
82 /*+++++++++++++++++++++++++++++++++++++++*/
86 /*+++++++++++++++++++++++++++++++++++++++*/
88 /*+++++++++++++++++++++++++++++++++++++++*/
89 #define MAX_STR_LEN 128
91 #define B_APPLY_BUTTON 2
92 #define B_CANCEL_BUTTON 3
93 #define B_HELP_BUTTON 4
95 #define ERR2 ((char *)GETMESSAGE(11, 2, "The backdrop portion of the Style Manager\n\
96 will not operate because there are no backdrop\nfiles available. Check $HOME/.dt/errorlog."))
98 /*+++++++++++++++++++++++++++++++++++++++*/
99 /* Internal Functions */
100 /*+++++++++++++++++++++++++++++++++++++++*/
102 static int CreateBackdropDialog( Widget parent) ;
103 static void MoreBitmaps( void ) ;
104 static ReadBitmaps( void ) ;
105 static Boolean CreatePixmaps( void ) ;
106 static ReadBitmapDirectory( char *dir ) ;
107 static void DrawBitmap(
109 XtPointer client_data,
110 XtPointer call_data) ;
111 static void SizeBitmap(
113 XtPointer client_data,
114 XtPointer call_data) ;
115 static XmString * MakeListStrings( void ) ;
116 static void FreeListStrings( XmString *listPtr) ;
119 XtPointer client_data,
120 XtPointer call_data) ;
121 static void ButtonCB(
123 XtPointer client_data,
124 XtPointer call_data) ;
125 static void GetColors( void ) ;
126 static void FreeAll( void ) ;
127 static void _DtMapCB(
129 XtPointer client_data,
130 XtPointer call_data) ;
133 /*+++++++++++++++++++++++++++++++++++++++*/
134 /* Internal Variables */
135 /*+++++++++++++++++++++++++++++++++++++++*/
141 char **tmpBitmapNames;
143 int tmpMaxNumBitmaps;
157 } Backdrops, *BackdropsPtr;
158 static Backdrops backdrops;
160 static saveRestore save = {FALSE, 0, };
161 char *BACKDROPSDLG = "backdropsDialog";
164 * copy of the system backdrop description file for the
165 * current locale in xrm form
167 static XrmDatabase sys_bd_DB = NULL;
170 * copy of the admin backdrop description file for the
171 * current locale in xrm form
173 static XrmDatabase adm_bd_DB = NULL;
176 * copy of the user's home backdrop description file for the
177 * current locale in xrm form
179 static XrmDatabase hm_bd_DB = NULL;
182 * final combination of the admin & system data bases
184 static XrmDatabase bd_DB = NULL;
188 /*+++++++++++++++++++++++++++++++++++++++*/
190 /*+++++++++++++++++++++++++++++++++++++++*/
193 build_dirList(char * dirStr,
196 char tokenSep[] = ":";
198 char ** dirList = NULL;
201 int len = strlen(dirStr);
204 tmpStr = (char *)XtCalloc(1, len + 1);
205 strcpy(tmpStr, dirStr);
206 token = strtok(tmpStr, tokenSep);
210 token = strtok(NULL, tokenSep);
216 dirList = (char **) XtCalloc(1, i * sizeof(char *));
219 strcpy(tmpStr, dirStr);
220 token = strtok(tmpStr, tokenSep);
224 dirList[*count] = (char *) XtCalloc(1, strlen( token ) + 1);
225 strcpy(dirList[*count], token);
226 token = strtok(NULL, tokenSep);
231 XtFree ((char *) tmpStr);
237 /*+++++++++++++++++++++++++++++++++++++++*/
239 /*+++++++++++++++++++++++++++++++++++++++*/
242 free_dirList(char ** dirList,
250 for (i=0; i<count; i++)
251 XtFree((char *) dirList[i]);
253 XtFree ((char *) dirList);
257 /************************************************************************
258 * SelectCurrentBackdrop() - Selects current backdrop in list
260 ************************************************************************/
261 void SelectCurrentBackdrop(int callback)
263 DtWsmWorkspaceInfo *wInfo=NULL;
269 if ((DtWsmGetCurrentWorkspace (style.display, style.root, &aWS)
271 (DtWsmGetWorkspaceInfo (style.display, style.root, aWS, &wInfo)
277 list = XtNameToWidget(style.backdropDialog, "*bitmapList");
279 backdropName = XmGetAtomName(style.display, wInfo->backdropName);
281 for (i = 0; i < backdrops.numBitmaps; i++) {
282 if (strcmp(backdrops.bitmapNames[i], backdropName) == 0) {
283 XmListSelectPos (list, i + 1, callback);
284 XmListSetPos(list, i + 1);
285 backdrops.selected = i;
289 XtFree((char *) backdropName);
290 XtFree((char *) wInfo);
293 /************************************************************************
294 * BackdropDialog() - Create backdrop selection dialog first time up.
295 * If it has already been created, map it.
296 ************************************************************************/
303 if (style.backdropDialog == NULL)
305 _DtTurnOnHourGlass(parent);
306 if (!CreateBackdropDialog(parent)) {
307 _DtTurnOffHourGlass(parent);
310 SelectCurrentBackdrop(False);
311 XtManageChild(style.backdropDialog);
312 XSync(style.display, 0);
313 XmUpdateDisplay(style.backdropDialog);
314 _DtTurnOffHourGlass(parent);
319 SelectCurrentBackdrop(True);
320 XtManageChild(style.backdropDialog);
321 raiseWindow(XtWindow(XtParent(style.backdropDialog)));
322 XmUpdateDisplay(style.backdropDialog);
327 /************************************************************************
328 * CreateBackdropDialog()
329 * Create the Backdrop Dialog
330 ************************************************************************/
332 CreateBackdropDialog(
339 XmString strings[NUM_LABELS+1];
340 XmString *listStrings;
345 if (backdrops.noBitmaps)
347 ErrDialog (backdrops.errStr, style.shell);
351 /* initialize backdrop data */
352 backdrops.bitmapNames = NULL;
353 backdrops.bitmaps = NULL;
354 backdrops.numBitmaps = 0;
355 backdrops.maxNumBitmaps = 100;
356 backdrops.selected = -1;
358 backdrops.errStr = NULL;
359 backdrops.shadow = 2;
360 backdrops.width = 200 - 2*backdrops.shadow;
361 backdrops.height = 200 - 2*backdrops.shadow;
362 backdrops.newColors = True;
365 /* load the backdrop description data base for the given locale*/
366 /* from that locale's description file from the system location */
367 lang = setlocale (LC_CTYPE,NULL);
369 #ifdef hpux /* hpux-specific parsing of the locale string */
370 /* The following code is identical to the
371 ExtractLocaleName function in WmResParse.c
374 #define MAXLOCALE 64 /* buffer size of locale name */
379 static char buf[MAXLOCALE];
381 /* If lang has a substring ":<category>;", extract <category>
382 * from the first such occurrence as the locale name.
386 if (start = strchr (lang, ':')) {
388 if (end = strchr (start, ';')) {
390 strncpy(buf, start, len);
398 bd_desc = (char *)XtMalloc(strlen("/usr/dt/backdrops/desc.") + strlen(lang) + 1);
399 strcpy (bd_desc,"/usr/dt/backdrops/desc.");
400 strcat (bd_desc, lang);
401 if(sys_bd_DB = XrmGetFileDatabase (bd_desc))
402 XrmMergeDatabases(sys_bd_DB, &bd_DB);
405 /* load the backdrop description data base for the given locale*/
406 /* from that locale's description file from the admin location */
407 bd_desc = (char *)XtMalloc(strlen("/etc/dt/backdrops/desc.") + strlen(lang) + 1);
408 strcpy (bd_desc,"/etc/dt/backdrops/desc.");
409 strcat (bd_desc, lang);
410 if (adm_bd_DB = XrmGetFileDatabase (bd_desc))
411 XrmMergeDatabases(adm_bd_DB, &bd_DB);
414 /* load the backdrop description from the user's .dt/backdrops directory */
415 /* regardless of locale */
416 bd_desc = (char *)XtMalloc(strlen(style.home) + strlen("/.dt/backdrops/desc.backdrops") + 1);
417 strcpy (bd_desc, style.home);
418 strcat (bd_desc, "/.dt/backdrops/desc.backdrops");
419 if (hm_bd_DB = XrmGetFileDatabase (bd_desc))
420 XrmMergeDatabases(hm_bd_DB, &bd_DB);
423 /* Set up DialogBox button labels. */
424 strings[0] = XmStringCreateLocalized ((String) _DtOkString);
425 strings[1] = XmStringCreateLocalized ((String) _DtApplyString);
426 strings[2] = XmStringCreateLocalized ((String) _DtCloseString);
427 strings[3] = XmStringCreateLocalized ((String) _DtHelpString);
430 * Note that save.poscnt has been initialized elsewhere.
431 * save.posArgs may contain information from restoreBackdrop().*/
433 /* create the dialog box with shell */
435 XtSetArg (save.posArgs[save.poscnt], XmNbuttonCount, NUM_LABELS+1);
437 XtSetArg (save.posArgs[save.poscnt], XmNbuttonLabelStrings, strings);
439 XtSetArg (save.posArgs[save.poscnt], XmNdefaultPosition, False);
441 XtSetArg (save.posArgs[save.poscnt], XmNallowOverlap, False);
443 style.backdropDialog = __DtCreateDialogBoxDialog (parent, BACKDROPSDLG,
444 save.posArgs, save.poscnt);
445 XtAddCallback(style.backdropDialog, XmNcallback, ButtonCB, NULL);
446 XtAddCallback(style.backdropDialog, XmNmapCallback, _DtMapCB, parent);
447 XtAddCallback(style.backdropDialog, XmNhelpCallback,
448 (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_BACKDROP_DIALOG);
450 /* free compound strings now */
451 XmStringFree (strings[0]);
452 XmStringFree (strings[1]);
453 XmStringFree (strings[2]);
454 XmStringFree (strings[3]);
457 XtSetArg (args[n], XmNtitle, ((char *)GETMESSAGE(11, 12, "Style Manager - Backdrop"))); n++;
458 XtSetArg (args[n], XmNuseAsyncGeometry, True); n++;
459 XtSetValues (XtParent(style.backdropDialog), args, n);
461 /* get bitmap data */
462 if (!ReadBitmaps()) return 0; /* uses style.backdropDialog */
464 /* create the form to go in to dialog box as the work area */
466 XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
467 XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
468 XtSetArg (args[n], XmNchildType, XmWORK_AREA); n++;
470 XtSetArg (args[n], XmNallowOverlap, False); n++;
471 mainForm = XmCreateForm (style.backdropDialog, "backdropsForm", args, n);
473 /* create the scrolled list of bitmap names... first create XmStrings */
474 listStrings = MakeListStrings ();
476 XtSetArg (args[n], XmNautomaticSelection, True); n++;
477 XtSetArg (args[n], XmNselectionPolicy, XmBROWSE_SELECT); n++;
478 XtSetArg (args[n], XmNitems, listStrings); n++;
479 XtSetArg (args[n], XmNitemCount, backdrops.numBitmaps); n++;
480 list = XmCreateScrolledList (mainForm, "bitmapList", args, n);
481 XtAddCallback (list, XmNbrowseSelectionCallback, ListCB, (XtPointer)NULL);
482 FreeListStrings (listStrings); /* after list has copied */
484 /* set up attachments for scrolled list itself */
486 XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
487 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
488 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
489 XtSetValues (XtParent(list), args, n);
491 /* Create drawing area for the bitmap */
493 XtSetArg (args[n], XmNshadowType, XmSHADOW_IN); n++;
494 XtSetArg (args[n], XmNshadowThickness, backdrops.shadow); n++;
495 XtSetArg (args[n], XmNhighlightThickness, 0); n++;
496 XtSetArg (args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
497 XtSetArg (args[n], XmNrightWidget, XtParent(list)); n++;
498 XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
499 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
500 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
501 XtSetArg (args[n], XmNborderWidth, 0); n++;
502 XtSetArg (args[n], XmNwidth, backdrops.width+2*backdrops.shadow); n++;
503 XtSetArg (args[n], XmNheight, backdrops.height+2*backdrops.shadow); n++;
504 XtSetArg (args[n], XmNtraversalOn, False); n++;
505 backdrops.drawnButton = XmCreateDrawnButton (mainForm, "bitmap", args, n);
506 XtAddCallback (backdrops.drawnButton, XmNexposeCallback, DrawBitmap, NULL);
507 XtAddCallback (backdrops.drawnButton, XmNresizeCallback, SizeBitmap, NULL);
509 /* manage all of the widgets */
510 XtManageChild (mainForm);
511 XtManageChild (backdrops.drawnButton);
512 XtManageChild (list);
518 /************************************************************************
520 * Create space for more bitmap entries
521 ************************************************************************/
527 /* allocate space for icon names */
528 newSize = (backdrops.maxNumBitmaps + 100) * sizeof(char *);
529 backdrops.bitmapNames = (char **) XtRealloc((char *)backdrops.bitmapNames,
532 /* now allocate new bitmap space */
533 newSize = (backdrops.maxNumBitmaps + 100) * sizeof(Pixmap);
534 backdrops.bitmaps = (Pixmap *)XtRealloc((char *)backdrops.bitmaps, newSize);
536 backdrops.maxNumBitmaps += 100;
539 /************************************************************************
541 * qsort() sort function, used for sorting bitmap names into alphabetical order
542 * can't use strcmp() due to char** rather than char*
543 ************************************************************************/
545 cmpstringp(const void *p1, const void *p2)
547 return strcmp(*(char * const *) p1, *(char * const *) p2);
550 /************************************************************************
552 * Create an array of bitmaps by reading backdrop directories in the
553 * following order overriding any duplicates:
554 * 1) Read the system location /usr/dt/backdrops
555 * 2) Read the admin location /etc/dt/backdrops
556 * 3) Read the directories specified by the backdropDirectories
558 * 4) Read the user's home directory /$HOME/.dt/backdrops.
559 ************************************************************************/
565 int width, height, x, y;
570 /* allocate space for temporary bitmap info */
571 backdrops.tmpBitmapNames = (char **)XtCalloc(100, sizeof(char *));
572 backdrops.tmpMaxNumBitmaps = 100;
573 backdrops.tmpNumBitmaps = 0;
575 /* read system backdrop directory */
576 ReadBitmapDirectory("/usr/dt/backdrops");
577 /* read sys admin backdrop directory */
578 ReadBitmapDirectory("/etc/dt/backdrops");
580 /* Parse the backdropDirectories resource to get the individual directories */
581 if (style.xrdb.backdropDir)
583 backdrops.dirList = build_dirList(style.xrdb.backdropDir, &backdrops.dirCount);
585 /* compile the list of bitmaps */
586 for (i=0; i<backdrops.dirCount; i++)
587 ReadBitmapDirectory(backdrops.dirList[i]);
590 /* read the directory $HOME/.dt/backdrops */
591 string = (char *)XtMalloc(strlen(style.home) + strlen("/.dt/backdrops") + 1);
594 sprintf(string, "%s/.dt/backdrops", style.home);
595 ReadBitmapDirectory(string);
599 if (backdrops.tmpNumBitmaps == 0)
601 /* give error dialog, free space, and return */
602 backdrops.errStr = (char *)XtMalloc(strlen(ERR2) + 1);
603 sprintf(backdrops.errStr, "%s", ERR2);
604 ErrDialog (backdrops.errStr, style.shell);
606 free_dirList(backdrops.dirList, backdrops.dirCount);
610 /* Sort the list into alphanetical order */
611 qsort(backdrops.tmpBitmapNames, backdrops.tmpNumBitmaps, sizeof(char *), cmpstringp);
613 /* get the fg/bg colors from Dtwm */
614 if (backdrops.newColors)
617 backdrops.newColors = False;
620 /* create all the pixmaps */
621 if (!CreatePixmaps())
623 /* give error dialog, free space, and return */
624 backdrops.errStr = (char *)XtMalloc(strlen(ERR2) + 1);
625 sprintf(backdrops.errStr, "%s", ERR2);
626 ErrDialog (backdrops.errStr, style.shell);
628 free_dirList(backdrops.dirList, backdrops.dirCount);
633 if (backdrops.selected == -1) backdrops.selected = 0;
640 /************************************************************************
642 * Create the pixmpas in the backdrop list
643 with workprocs 10 at a time
644 ************************************************************************/
646 CreatePixmaps( void )
649 static int pixmapsCreated=0;
653 backdrops.numBitmaps = 0;
655 /* allocate space for real bitmap info */
656 backdrops.bitmapNames = (char **)XtCalloc(100, sizeof(char *));
657 backdrops.bitmaps = (Pixmap *)XtCalloc(100, sizeof(Pixmap));
659 for (i=0; i<backdrops.tmpNumBitmaps; i++)
661 tmpPixmap = XmGetPixmap (style.screen,
662 backdrops.tmpBitmapNames[i],
663 backdrops.fg, backdrops.bg);
664 if (tmpPixmap != XmUNSPECIFIED_PIXMAP)
666 if (backdrops.numBitmaps == backdrops.maxNumBitmaps)
669 backdrops.bitmapNames[backdrops.numBitmaps] =
670 backdrops.tmpBitmapNames[i];
671 backdrops.bitmaps[backdrops.numBitmaps] = tmpPixmap;
673 backdrops.numBitmaps++;
677 if (backdrops.numBitmaps)
685 /************************************************************************
686 * ReadBitmapDirectory()
687 * Create an array of bitmap names overriding duplicates
688 ************************************************************************/
695 struct dirent *filep;
700 struct stat stat_buf;
701 char *statPath, *pStatPath;
704 /* open the backdrops directory */
705 if ((dirp = opendir(dir)) == NULL)
707 /* print message to errorlog, free space, and return */
711 /* create string to contain complete path */
712 statPath = (char *) XtMalloc(strlen(dir) + MAX_STR_LEN + 2);
713 strcpy (statPath, dir);
714 strcat (statPath, "/");
715 pStatPath = statPath + strlen(statPath);
717 filep = readdir(dirp);
719 while (filep != NULL)
721 /* append filename to stat path */
722 strcpy (pStatPath, filep->d_name);
725 if ((stat_result = stat (statPath, &stat_buf)) != 0)
727 filep = readdir(dirp);
731 /* skip directories */
732 if ((stat_buf.st_mode & S_IFMT) == S_IFDIR)
734 filep = readdir(dirp);
738 name = (char *) XtMalloc(strlen(filep->d_name) + 1);
739 strcpy (name, filep->d_name);
741 /* strip suffix off filename if it's a .pm or .bm
742 * motif requires other formats like jpg, png etc to
743 * have the extension on to work with the XmGetPixmap() calls */
745 && (0 == strcmp(name + strlen(name) - 3, ".pm")
746 || 0 == strcmp(name + strlen(name) - 3, ".bm")))
748 (void)strtok(name, ".");
752 /* check for duplicates */
754 for (i=0; i<backdrops.tmpNumBitmaps; i++)
756 if (!strcmp(backdrops.tmpBitmapNames[i], name))
765 /* add to the temporary bitmap list */
767 if (backdrops.tmpNumBitmaps == backdrops.tmpMaxNumBitmaps)
769 /* allocate space for more temporary bitmap info */
770 newSize = (backdrops.tmpMaxNumBitmaps + 100) * sizeof(char *);
771 backdrops.tmpBitmapNames =
772 (char **)XtRealloc((char *)backdrops.tmpBitmapNames, newSize);
773 backdrops.tmpMaxNumBitmaps += 100;
776 backdrops.tmpBitmapNames[backdrops.tmpNumBitmaps] =
777 (char *) XtMalloc(strlen(name)+1);
778 strcpy (backdrops.tmpBitmapNames[backdrops.tmpNumBitmaps], name);
780 backdrops.tmpNumBitmaps++;
783 filep = readdir(dirp);
795 /************************************************************************
797 * This is the exposeCallback for the bitmap drawing area.
798 ************************************************************************/
802 XtPointer client_data,
803 XtPointer call_data )
808 if (backdrops.selected == -1)
811 if (backdrops.newColors)
815 /* we could keep track of which tile pixmaps need to be updated
816 since the last workspace change, but for now simply regenerate
817 each pixmap as it is selected after a workspace change has
820 /* backdrops.newColors = False; */
823 if (backdrops.gc == NULL)
825 gcValues.background = backdrops.bg;
826 gcValues.foreground = backdrops.fg;
827 gcValues.fill_style = FillTiled;
828 gcValues.tile = backdrops.bitmaps[backdrops.selected];
830 backdrops.gc = XCreateGC (style.display, XtWindow(w),
831 GCForeground | GCBackground |
832 GCTile | GCFillStyle, &gcValues);
835 XFillRectangle (style.display, XtWindow(w), backdrops.gc, backdrops.shadow,
836 backdrops.shadow, backdrops.width, backdrops.height);
840 /************************************************************************
842 * This is the resizeCallback for the bitmap drawing area.
843 ************************************************************************/
847 XtPointer client_data,
848 XtPointer call_data )
850 backdrops.width = XtWidth(w) - 2*backdrops.shadow;
851 backdrops.height = XtHeight(w) - 2*backdrops.shadow;
855 /************************************************************************
857 * Make XmStrings from the bitmap descriptions, to pass into list.
859 ************************************************************************/
861 MakeListStrings( void )
867 char *str_type_return;
868 XrmValue value_return;
870 /* allocate space for bitmap descriptions */
871 backdrops.bitmapDescs = (char **)XtCalloc(backdrops.numBitmaps, sizeof(char *));
873 for (i=0; i<backdrops.numBitmaps; i++)
877 name_str = (char *) XtMalloc(strlen("backdrops.") +
878 strlen(backdrops.bitmapNames[i]) +
879 strlen(".desc") + 1);
881 class_str = (char *) XtMalloc(strlen("Backdrops.") +
882 strlen(backdrops.bitmapNames[i]) +
883 strlen(".Desc") + 1);
884 strcpy(name_str, "backdrops.");
885 strcpy(class_str, "Backdrops.");
886 strcat(name_str, backdrops.bitmapNames[i]);
887 strcat(class_str, backdrops.bitmapNames[i]);
888 strcat(name_str, ".desc");
889 strcat(class_str, ".Desc");
891 if (XrmGetResource (bd_DB, name_str, class_str, &str_type_return, &value_return))
893 /* make copy of resource value */
894 backdrops.bitmapDescs[i] = (char *) XtMalloc(value_return.size + 1);
895 strcpy (backdrops.bitmapDescs[i], value_return.addr);
899 backdrops.bitmapDescs[i] = (char *) XtMalloc(strlen(backdrops.bitmapNames[i]) + 1);
900 strcpy(backdrops.bitmapDescs[i], backdrops.bitmapNames[i]);
905 backdrops.bitmapDescs[i] = (char *) XtMalloc(strlen(backdrops.bitmapNames[i]) + 1);
906 strcpy(backdrops.bitmapDescs[i], backdrops.bitmapNames[i]);
910 list = (XmString *) XtCalloc(backdrops.numBitmaps, sizeof(XmString));
912 for (i = 0; i < backdrops.numBitmaps; i++)
914 list[i] = XmStringCreateLocalized (backdrops.bitmapDescs[i]);
921 /************************************************************************
923 * Free XmStrings from the bitmap names, passed into list.
924 ************************************************************************/
931 XmString *list = listPtr;
933 for (i = 0; i < backdrops.numBitmaps; i++)
935 if (list[i]) XmStringFree(list[i]);
937 XtFree ((char *)list);
941 /************************************************************************
943 * Get the bitmap selected from the list
944 ************************************************************************/
948 XtPointer client_data,
949 XtPointer call_data )
951 XmListCallbackStruct *cb = (XmListCallbackStruct *)call_data;
953 backdrops.selected = cb->item_position - 1;
955 XSetTile (style.display, backdrops.gc,
956 backdrops.bitmaps[backdrops.selected]);
958 DrawBitmap (backdrops.drawnButton, NULL, NULL);
963 /************************************************************************
966 ************************************************************************/
970 XtPointer client_data,
971 XtPointer call_data )
976 DtDialogBoxCallbackStruct *cb = (DtDialogBoxCallbackStruct *) call_data;
978 switch (cb->button_position)
981 /* send message to update backdrop */
983 num = backdrops.selected;
985 _DtWsmChangeBackdrop(style.display, style.root,
986 backdrops.bitmapNames[num],
987 backdrops.bitmaps[num]);
991 /* send message to update backdrop */
993 num = backdrops.selected;
995 _DtWsmChangeBackdrop(style.display, style.root,
996 backdrops.bitmapNames[num],
997 backdrops.bitmaps[num]);
1001 case B_CANCEL_BUTTON: /* close */
1006 XtCallCallbacks(style.backdropDialog, XmNhelpCallback, (XtPointer)NULL);
1015 /************************************************************************
1017 * Workspace may have changed, so get current workspace
1018 * colors and draw the backdrop bitmap
1020 ************************************************************************/
1022 CheckWorkspace( void )
1024 backdrops.newColors = True; /* need to get new colors */
1025 if (style.backdropDialog && XtIsManaged(style.backdropDialog))
1027 DrawBitmap (backdrops.drawnButton, NULL, NULL);
1032 /************************************************************************
1034 * Get current workspace colors, and update GC if needed
1036 ************************************************************************/
1040 DtWsmWorkspaceInfo *wInfo=NULL;
1041 unsigned long num=0;
1046 if ((DtWsmGetCurrentWorkspace (style.display, style.root, &aWS)
1048 (DtWsmGetWorkspaceInfo (style.display, style.root, aWS, &wInfo)
1051 backdrops.bg = wInfo->bg;
1052 backdrops.fg = wInfo->fg;
1053 DtWsmFreeWorkspaceInfo (wInfo);
1061 if (backdrops.gc) /* update the gc if there is one */
1063 gcValues.background = backdrops.bg;
1064 gcValues.foreground = backdrops.fg;
1066 /* free old pixmap */
1067 XmDestroyPixmap(style.screen,
1068 backdrops.bitmaps[backdrops.selected]);
1070 /* allocate new pixmap */
1071 backdrops.bitmaps[backdrops.selected] =
1072 XmGetPixmap (style.screen,
1073 backdrops.bitmapNames[backdrops.selected],
1074 backdrops.fg, backdrops.bg);
1076 gcValues.tile = backdrops.bitmaps[backdrops.selected];
1078 XChangeGC (style.display, backdrops.gc,
1079 GCForeground | GCBackground | GCTile, &gcValues);
1084 /************************************************************************
1086 * Free some space that was allocated for backdrops
1087 ************************************************************************/
1093 /* set no bitmaps flag, so we won't try to get them next time */
1094 backdrops.noBitmaps = 1;
1096 /* free temporary list of backdrop names */
1097 for (i = 0; i < backdrops.tmpNumBitmaps; i++)
1098 if (backdrops.tmpBitmapNames[i])
1099 XtFree(backdrops.tmpBitmapNames[i]);
1100 XtFree ((char *)backdrops.tmpBitmapNames);
1101 XtFree ((char *)backdrops.bitmapNames);
1103 /* free backdrop bitmaps */
1104 for (i = 0; i < backdrops.numBitmaps; i++) {
1105 if (backdrops.bitmaps[i])
1106 XFreePixmap (style.display, backdrops.bitmaps[i]);
1107 if (backdrops.numBitmaps)
1108 XtFree((char *)backdrops.bitmaps);
1111 /* destory widgets (via first parent) */
1112 XtDestroyWidget (XtParent(style.backdropDialog));
1113 style.backdropDialog = NULL;
1117 /************************************************************************
1120 ************************************************************************/
1124 XtPointer client_data,
1125 XtPointer call_data )
1128 DtWsmRemoveWorkspaceFunctions(style.display, XtWindow(XtParent(w)));
1130 if (!save.restoreFlag)
1131 putDialog((Widget)client_data, w);
1133 XtRemoveCallback(style.backdropDialog, XmNmapCallback, _DtMapCB, NULL);
1137 /************************************************************************
1140 * restore any state information saved with saveBackdrop.
1141 * This is called from restoreSession with the application
1142 * shell and the special xrm database retrieved for restore.
1143 ************************************************************************/
1149 XrmName xrm_name[5];
1150 XrmRepresentation rep_type;
1153 xrm_name [0] = XrmStringToQuark (BACKDROPSDLG);
1156 /* get x position */
1157 xrm_name [1] = XrmStringToQuark ("x");
1158 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
1159 XtSetArg (save.posArgs[save.poscnt], XmNx, atoi((char *)value.addr));
1161 save.restoreFlag = True;
1164 /* get y position */
1165 xrm_name [1] = XrmStringToQuark ("y");
1166 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
1167 XtSetArg (save.posArgs[save.poscnt], XmNy, atoi((char *)value.addr));
1172 xrm_name [1] = XrmStringToQuark ("width");
1173 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
1174 XtSetArg(save.posArgs[save.poscnt], XmNwidth, atoi((char *)value.addr));
1179 xrm_name [1] = XrmStringToQuark ("height");
1180 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
1181 XtSetArg(save.posArgs[save.poscnt],XmNheight, atoi((char *)value.addr));
1185 xrm_name [1] = XrmStringToQuark ("ismapped");
1186 XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
1187 /* Are we supposed to be mapped? */
1188 if (strcmp(value.addr, "True") == 0)
1189 BackdropDialog(shell);
1193 /************************************************************************
1196 * This routine will write out to the passed file descriptor any state
1197 * information this dialog needs. It is called from saveSessionCB with the
1198 * file already opened.
1199 * All information is saved in xrm format. There is no restriction
1200 * on what can be saved. It doesn't have to be defined or be part of any
1201 * widget or Xt definition. Just name and save it here and recover it in
1202 * restoreBackdrop. The suggested minimum is whether you are mapped, and your
1204 ************************************************************************/
1210 Dimension width, height;
1211 char *bufr = style.tmpBigStr; /* size=[1024], make bigger if needed */
1212 XmVendorShellExtObject vendorExt;
1213 XmWidgetExtData extData;
1215 if (style.backdropDialog != NULL)
1217 if (XtIsManaged(style.backdropDialog))
1218 sprintf(bufr, "*backdropsDialog.ismapped: True\n");
1220 sprintf(bufr, "*backdropsDialog.ismapped: False\n");
1222 /* Get and write out the geometry info for our Window */
1223 x = XtX (XtParent(style.backdropDialog));
1224 y = XtY (XtParent(style.backdropDialog));
1225 width = XtWidth (style.backdropDialog);
1226 height = XtHeight (style.backdropDialog);
1228 /* Modify x & y to take into account window mgr frames
1229 * This is pretty bogus, but I don't know a better way to do it.
1231 extData = _XmGetWidgetExtData(style.shell, XmSHELL_EXTENSION);
1232 vendorExt = (XmVendorShellExtObject)extData->widget;
1233 x -= vendorExt->vendor.xOffset;
1234 y -= vendorExt->vendor.yOffset;
1236 sprintf(bufr, "%s*backdropsDialog.x: %d\n", bufr, x);
1237 sprintf(bufr, "%s*backdropsDialog.y: %d\n", bufr, y);
1238 sprintf(bufr, "%s*backdropsDialog.width: %d\n", bufr, width);
1239 sprintf(bufr, "%s*backdropsDialog.height: %d\n", bufr, height);
1240 sprintf(bufr, "%s*backdropsDialog.selectedItemNum: %d\n", bufr,
1241 backdrops.selected);
1242 sprintf(bufr, "%s*backdropsDialog.selectedItem: %s\n", bufr,
1243 backdrops.bitmapNames[backdrops.selected]);
1244 if(-1 == write (fd, bufr, strlen(bufr))) {
1245 perror(strerror(errno));