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>
50 #if defined(_AIX) || defined(__apollo)
53 #include <dirent.h> /* opendir(), directory(3C) */
57 #include <X11/apollosys.h> /* needed for S_ISDIR macro */
63 #include <Xm/MwmUtil.h>
67 #include <Xm/DrawnB.h>
70 #include <Xm/VendorSEP.h>
71 #include <Xm/AtomMgr.h>
73 #include <Dt/DialogBox.h>
75 #include <Dt/Message.h>
76 #include <Dt/SessionM.h>
77 #include <Dt/HourGlass.h>
79 #include <Dt/UserMsg.h>
83 #include "SaveRestore.h"
85 /*+++++++++++++++++++++++++++++++++++++++*/
86 /* include extern functions */
87 /*+++++++++++++++++++++++++++++++++++++++*/
91 /*+++++++++++++++++++++++++++++++++++++++*/
93 /*+++++++++++++++++++++++++++++++++++++++*/
94 #define MAX_STR_LEN 128
96 #define B_APPLY_BUTTON 2
97 #define B_CANCEL_BUTTON 3
98 #define B_HELP_BUTTON 4
100 #define ERR2 ((char *)GETMESSAGE(11, 2, "The backdrop portion of the Style Manager\n\
101 will not operate because there are no backdrop\nfiles available. Check $HOME/.dt/errorlog."))
103 /*+++++++++++++++++++++++++++++++++++++++*/
104 /* Internal Functions */
105 /*+++++++++++++++++++++++++++++++++++++++*/
107 static int CreateBackdropDialog( Widget parent) ;
108 static void MoreBitmaps( void ) ;
109 static ReadBitmaps( void ) ;
110 static Boolean CreatePixmaps( void ) ;
111 static ReadBitmapDirectory( char *dir ) ;
112 static void DrawBitmap(
114 XtPointer client_data,
115 XtPointer call_data) ;
116 static void SizeBitmap(
118 XtPointer client_data,
119 XtPointer call_data) ;
120 static XmString * MakeListStrings( void ) ;
121 static void FreeListStrings( XmString *listPtr) ;
124 XtPointer client_data,
125 XtPointer call_data) ;
126 static void ButtonCB(
128 XtPointer client_data,
129 XtPointer call_data) ;
130 static void GetColors( void ) ;
131 static void FreeAll( void ) ;
132 static void _DtMapCB(
134 XtPointer client_data,
135 XtPointer call_data) ;
138 /*+++++++++++++++++++++++++++++++++++++++*/
139 /* Internal Variables */
140 /*+++++++++++++++++++++++++++++++++++++++*/
146 char **tmpBitmapNames;
148 int tmpMaxNumBitmaps;
162 } Backdrops, *BackdropsPtr;
163 static Backdrops backdrops;
165 static saveRestore save = {FALSE, 0, };
166 char *BACKDROPSDLG = "backdropsDialog";
169 * copy of the system backdrop description file for the
170 * current locale in xrm form
172 static XrmDatabase sys_bd_DB = NULL;
175 * copy of the admin backdrop description file for the
176 * current locale in xrm form
178 static XrmDatabase adm_bd_DB = NULL;
181 * copy of the user's home backdrop description file for the
182 * current locale in xrm form
184 static XrmDatabase hm_bd_DB = NULL;
187 * final combination of the admin & system data bases
189 static XrmDatabase bd_DB = NULL;
193 /*+++++++++++++++++++++++++++++++++++++++*/
195 /*+++++++++++++++++++++++++++++++++++++++*/
198 build_dirList(char * dirStr,
201 char tokenSep[] = ":";
203 char ** dirList = NULL;
206 int len = strlen(dirStr);
209 tmpStr = (char *)XtCalloc(1, len + 1);
210 strcpy(tmpStr, dirStr);
211 token = strtok(tmpStr, tokenSep);
215 token = strtok(NULL, tokenSep);
221 dirList = (char **) XtCalloc(1, i * sizeof(char *));
224 strcpy(tmpStr, dirStr);
225 token = strtok(tmpStr, tokenSep);
229 dirList[*count] = (char *) XtCalloc(1, strlen( token ) + 1);
230 strcpy(dirList[*count], token);
231 token = strtok(NULL, tokenSep);
236 XtFree ((char *) tmpStr);
242 /*+++++++++++++++++++++++++++++++++++++++*/
244 /*+++++++++++++++++++++++++++++++++++++++*/
247 free_dirList(char ** dirList,
255 for (i=0; i<count; i++)
256 XtFree((char *) dirList[i]);
258 XtFree ((char *) dirList);
262 /************************************************************************
263 * SelectCurrentBackdrop() - Selects current backdrop in list
265 ************************************************************************/
266 void SelectCurrentBackdrop(callback)
268 DtWsmWorkspaceInfo *wInfo=NULL;
274 if ((DtWsmGetCurrentWorkspace (style.display, style.root, &aWS)
276 (DtWsmGetWorkspaceInfo (style.display, style.root, aWS, &wInfo)
282 list = XtNameToWidget(style.backdropDialog, "*bitmapList");
284 backdropName = XmGetAtomName(style.display, wInfo->backdropName);
286 for (i = 0; i < backdrops.numBitmaps; i++) {
287 if (strcmp(backdrops.bitmapNames[i], backdropName) == 0) {
288 XmListSelectPos (list, i + 1, callback);
289 XmListSetPos(list, i + 1);
290 backdrops.selected = i;
294 XtFree((char *) backdropName);
295 XtFree((char *) wInfo);
298 /************************************************************************
299 * BackdropDialog() - Create backdrop selection dialog first time up.
300 * If it has already been created, map it.
301 ************************************************************************/
308 if (style.backdropDialog == NULL)
310 _DtTurnOnHourGlass(parent);
311 if (!CreateBackdropDialog(parent)) {
312 _DtTurnOffHourGlass(parent);
315 SelectCurrentBackdrop(False);
316 XtManageChild(style.backdropDialog);
317 XSync(style.display, 0);
318 XmUpdateDisplay(style.backdropDialog);
319 _DtTurnOffHourGlass(parent);
324 SelectCurrentBackdrop(True);
325 XtManageChild(style.backdropDialog);
326 raiseWindow(XtWindow(XtParent(style.backdropDialog)));
327 XmUpdateDisplay(style.backdropDialog);
332 /************************************************************************
333 * CreateBackdropDialog()
334 * Create the Backdrop Dialog
335 ************************************************************************/
337 CreateBackdropDialog(
344 XmString strings[NUM_LABELS+1];
345 XmString *listStrings;
350 if (backdrops.noBitmaps)
352 ErrDialog (backdrops.errStr, style.shell);
356 /* initialize backdrop data */
357 backdrops.bitmapNames = NULL;
358 backdrops.bitmaps = NULL;
359 backdrops.numBitmaps = 0;
360 backdrops.maxNumBitmaps = 100;
361 backdrops.selected = -1;
363 backdrops.errStr = NULL;
364 backdrops.shadow = 2;
365 backdrops.width = 200 - 2*backdrops.shadow;
366 backdrops.height = 200 - 2*backdrops.shadow;
367 backdrops.newColors = True;
370 /* load the backdrop description data base for the given locale*/
371 /* from that locale's description file from the system location */
372 lang = setlocale (LC_CTYPE,NULL);
374 #ifdef hpux /* hpux-specific parsing of the locale string */
375 /* The following code is identical to the
376 ExtractLocaleName function in WmResParse.c
379 #define MAXLOCALE 64 /* buffer size of locale name */
384 static char buf[MAXLOCALE];
386 /* If lang has a substring ":<category>;", extract <category>
387 * from the first such occurrence as the locale name.
391 if (start = strchr (lang, ':')) {
393 if (end = strchr (start, ';')) {
395 strncpy(buf, start, len);
403 bd_desc = (char *)XtMalloc(strlen("/usr/dt/backdrops/desc.") + strlen(lang) + 1);
404 strcpy (bd_desc,"/usr/dt/backdrops/desc.");
405 strcat (bd_desc, lang);
406 if(sys_bd_DB = XrmGetFileDatabase (bd_desc))
407 XrmMergeDatabases(sys_bd_DB, &bd_DB);
410 /* load the backdrop description data base for the given locale*/
411 /* from that locale's description file from the admin location */
412 bd_desc = (char *)XtMalloc(strlen("/etc/dt/backdrops/desc.") + strlen(lang) + 1);
413 strcpy (bd_desc,"/etc/dt/backdrops/desc.");
414 strcat (bd_desc, lang);
415 if (adm_bd_DB = XrmGetFileDatabase (bd_desc))
416 XrmMergeDatabases(adm_bd_DB, &bd_DB);
419 /* load the backdrop description from the user's .dt/backdrops directory */
420 /* regardless of locale */
421 bd_desc = (char *)XtMalloc(strlen(style.home) + strlen("/.dt/backdrops/desc.backdrops") + 1);
422 strcpy (bd_desc, style.home);
423 strcat (bd_desc, "/.dt/backdrops/desc.backdrops");
424 if (hm_bd_DB = XrmGetFileDatabase (bd_desc))
425 XrmMergeDatabases(hm_bd_DB, &bd_DB);
428 /* Set up DialogBox button labels. */
429 strings[0] = XmStringCreateLocalized ((String) _DtOkString);
430 strings[1] = XmStringCreateLocalized ((String) _DtApplyString);
431 strings[2] = XmStringCreateLocalized ((String) _DtCloseString);
432 strings[3] = XmStringCreateLocalized ((String) _DtHelpString);
435 * Note that save.poscnt has been initialized elsewhere.
436 * save.posArgs may contain information from restoreBackdrop().*/
438 /* create the dialog box with shell */
440 XtSetArg (save.posArgs[save.poscnt], XmNbuttonCount, NUM_LABELS+1);
442 XtSetArg (save.posArgs[save.poscnt], XmNbuttonLabelStrings, strings);
444 XtSetArg (save.posArgs[save.poscnt], XmNdefaultPosition, False);
446 XtSetArg (save.posArgs[save.poscnt], XmNallowOverlap, False);
448 style.backdropDialog = __DtCreateDialogBoxDialog (parent, BACKDROPSDLG,
449 save.posArgs, save.poscnt);
450 XtAddCallback(style.backdropDialog, XmNcallback, ButtonCB, NULL);
451 XtAddCallback(style.backdropDialog, XmNmapCallback, _DtMapCB, parent);
452 XtAddCallback(style.backdropDialog, XmNhelpCallback,
453 (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_BACKDROP_DIALOG);
455 /* free compound strings now */
456 XmStringFree (strings[0]);
457 XmStringFree (strings[1]);
458 XmStringFree (strings[2]);
459 XmStringFree (strings[3]);
462 XtSetArg (args[n], XmNtitle, ((char *)GETMESSAGE(11, 12, "Style Manager - Backdrop"))); n++;
463 XtSetArg (args[n], XmNuseAsyncGeometry, True); n++;
464 XtSetValues (XtParent(style.backdropDialog), args, n);
466 /* get bitmap data */
467 if (!ReadBitmaps()) return 0; /* uses style.backdropDialog */
469 /* create the form to go in to dialog box as the work area */
471 XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
472 XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
473 XtSetArg (args[n], XmNchildType, XmWORK_AREA); n++;
475 XtSetArg (args[n], XmNallowOverlap, False); n++;
476 mainForm = XmCreateForm (style.backdropDialog, "backdropsForm", args, n);
478 /* create the scrolled list of bitmap names... first create XmStrings */
479 listStrings = MakeListStrings ();
481 XtSetArg (args[n], XmNautomaticSelection, True); n++;
482 XtSetArg (args[n], XmNselectionPolicy, XmBROWSE_SELECT); n++;
483 XtSetArg (args[n], XmNitems, listStrings); n++;
484 XtSetArg (args[n], XmNitemCount, backdrops.numBitmaps); n++;
485 list = XmCreateScrolledList (mainForm, "bitmapList", args, n);
486 XtAddCallback (list, XmNbrowseSelectionCallback, ListCB, (XtPointer)NULL);
487 FreeListStrings (listStrings); /* after list has copied */
489 /* set up attachments for scrolled list itself */
491 XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
492 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
493 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
494 XtSetValues (XtParent(list), args, n);
496 /* Create drawing area for the bitmap */
498 XtSetArg (args[n], XmNshadowType, XmSHADOW_IN); n++;
499 XtSetArg (args[n], XmNshadowThickness, backdrops.shadow); n++;
500 XtSetArg (args[n], XmNhighlightThickness, 0); n++;
501 XtSetArg (args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
502 XtSetArg (args[n], XmNrightWidget, XtParent(list)); n++;
503 XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
504 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
505 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
506 XtSetArg (args[n], XmNborderWidth, 0); n++;
507 XtSetArg (args[n], XmNwidth, backdrops.width+2*backdrops.shadow); n++;
508 XtSetArg (args[n], XmNheight, backdrops.height+2*backdrops.shadow); n++;
509 XtSetArg (args[n], XmNtraversalOn, False); n++;
510 backdrops.drawnButton = XmCreateDrawnButton (mainForm, "bitmap", args, n);
511 XtAddCallback (backdrops.drawnButton, XmNexposeCallback, DrawBitmap, NULL);
512 XtAddCallback (backdrops.drawnButton, XmNresizeCallback, SizeBitmap, NULL);
514 /* manage all of the widgets */
515 XtManageChild (mainForm);
516 XtManageChild (backdrops.drawnButton);
517 XtManageChild (list);
523 /************************************************************************
525 * Create space for more bitmap entries
526 ************************************************************************/
532 /* allocate space for icon names */
533 newSize = (backdrops.maxNumBitmaps + 100) * sizeof(char *);
534 backdrops.bitmapNames = (char **) XtRealloc((char *)backdrops.bitmapNames,
537 /* now allocate new bitmap space */
538 newSize = (backdrops.maxNumBitmaps + 100) * sizeof(Pixmap);
539 backdrops.bitmaps = (Pixmap *)XtRealloc((char *)backdrops.bitmaps, newSize);
541 backdrops.maxNumBitmaps += 100;
544 /************************************************************************
546 * qsort() sort function, used for sorting bitmap names into alphabetical order
547 * can't use strcmp() due to char** rather than char*
548 ************************************************************************/
550 cmpstringp(const void *p1, const void *p2)
552 return strcmp(*(char * const *) p1, *(char * const *) p2);
555 /************************************************************************
557 * Create an array of bitmaps by reading backdrop directories in the
558 * following order overriding any duplicates:
559 * 1) Read the system location /usr/dt/backdrops
560 * 2) Read the admin location /etc/dt/backdrops
561 * 3) Read the directories specified by the backdropDirectories
563 * 4) Read the user's home directory /$HOME/.dt/backdrops.
564 ************************************************************************/
570 int width, height, x, y;
575 /* allocate space for temporary bitmap info */
576 backdrops.tmpBitmapNames = (char **)XtCalloc(100, sizeof(char *));
577 backdrops.tmpMaxNumBitmaps = 100;
578 backdrops.tmpNumBitmaps = 0;
580 /* read system backdrop directory */
581 ReadBitmapDirectory("/usr/dt/backdrops");
582 /* read sys admin backdrop directory */
583 ReadBitmapDirectory("/etc/dt/backdrops");
585 /* Parse the backdropDirectories resource to get the individual directories */
586 if (style.xrdb.backdropDir)
588 backdrops.dirList = build_dirList(style.xrdb.backdropDir, &backdrops.dirCount);
590 /* compile the list of bitmaps */
591 for (i=0; i<backdrops.dirCount; i++)
592 ReadBitmapDirectory(backdrops.dirList[i]);
595 /* read the directory $HOME/.dt/backdrops */
596 string = (char *)XtMalloc(strlen(style.home) + strlen("/.dt/backdrops") + 1);
597 sprintf(string, "%s/.dt/backdrops", style.home);
598 ReadBitmapDirectory(string);
602 if (backdrops.tmpNumBitmaps == 0)
604 /* give error dialog, free space, and return */
605 backdrops.errStr = (char *)XtMalloc(strlen(ERR2) + 1);
606 sprintf(backdrops.errStr, "%s", ERR2);
607 ErrDialog (backdrops.errStr, style.shell);
609 free_dirList(backdrops.dirList, backdrops.dirCount);
613 /* Sort the list into alphanetical order */
614 qsort(backdrops.tmpBitmapNames, backdrops.tmpNumBitmaps, sizeof(char *), cmpstringp);
616 /* get the fg/bg colors from Dtwm */
617 if (backdrops.newColors)
620 backdrops.newColors = False;
623 /* create all the pixmaps */
624 if (!CreatePixmaps())
626 /* give error dialog, free space, and return */
627 backdrops.errStr = (char *)XtMalloc(strlen(ERR2) + 1);
628 sprintf(backdrops.errStr, "%s", ERR2);
629 ErrDialog (backdrops.errStr, style.shell);
631 free_dirList(backdrops.dirList, backdrops.dirCount);
636 if (backdrops.selected == -1) backdrops.selected = 0;
643 /************************************************************************
645 * Create the pixmpas in the backdrop list
646 with workprocs 10 at a time
647 ************************************************************************/
649 CreatePixmaps( void )
652 static int pixmapsCreated=0;
656 backdrops.numBitmaps = 0;
658 /* allocate space for real bitmap info */
659 backdrops.bitmapNames = (char **)XtCalloc(100, sizeof(char *));
660 backdrops.bitmaps = (Pixmap *)XtCalloc(100, sizeof(Pixmap));
662 for (i=0; i<backdrops.tmpNumBitmaps; i++)
664 tmpPixmap = XmGetPixmap (style.screen,
665 backdrops.tmpBitmapNames[i],
666 backdrops.fg, backdrops.bg);
667 if (tmpPixmap != XmUNSPECIFIED_PIXMAP)
669 if (backdrops.numBitmaps == backdrops.maxNumBitmaps)
672 backdrops.bitmapNames[backdrops.numBitmaps] =
673 backdrops.tmpBitmapNames[i];
674 backdrops.bitmaps[backdrops.numBitmaps] = tmpPixmap;
676 backdrops.numBitmaps++;
680 if (backdrops.numBitmaps)
688 /************************************************************************
689 * ReadBitmapDirectory()
690 * Create an array of bitmap names overriding duplicates
691 ************************************************************************/
698 struct dirent *filep;
703 struct stat stat_buf;
704 char *statPath, *pStatPath;
707 /* open the backdrops directory */
708 if ((dirp = opendir(dir)) == NULL)
710 /* print message to errorlog, free space, and return */
714 /* create string to contain complete path */
715 statPath = (char *) XtMalloc(strlen(dir) + MAX_STR_LEN + 2);
716 strcpy (statPath, dir);
717 strcat (statPath, "/");
718 pStatPath = statPath + strlen(statPath);
720 filep = readdir(dirp);
722 while (filep != NULL)
724 /* append filename to stat path */
725 strcpy (pStatPath, filep->d_name);
728 if ((stat_result = stat (statPath, &stat_buf)) != 0)
730 filep = readdir(dirp);
734 /* skip directories */
735 if ((stat_buf.st_mode & S_IFMT) == S_IFDIR)
737 filep = readdir(dirp);
741 name = (char *) XtMalloc(strlen(filep->d_name) + 1);
742 strcpy (name, filep->d_name);
744 /* strip suffix off filename if it's a .pm or .bm
745 * motif requires other formats like jpg, png etc to
746 * have the extension on to work with the XmGetPixmap() calls */
748 && (0 == strcmp(name + strlen(name) - 3, ".pm")
749 || 0 == strcmp(name + strlen(name) - 3, ".bm")))
751 (void)strtok(name, ".");
754 fprintf(stderr, "'%s'\n", name);
756 /* check for duplicates */
758 for (i=0; i<backdrops.tmpNumBitmaps; i++)
760 if (!strcmp(backdrops.tmpBitmapNames[i], name))
769 /* add to the temporary bitmap list */
771 if (backdrops.tmpNumBitmaps == backdrops.tmpMaxNumBitmaps)
773 /* allocate space for more temporary bitmap info */
774 newSize = (backdrops.tmpMaxNumBitmaps + 100) * sizeof(char *);
775 backdrops.tmpBitmapNames =
776 (char **)XtRealloc((char *)backdrops.tmpBitmapNames, newSize);
777 backdrops.tmpMaxNumBitmaps += 100;
780 backdrops.tmpBitmapNames[backdrops.tmpNumBitmaps] =
781 (char *) XtMalloc(strlen(name)+1);
782 strcpy (backdrops.tmpBitmapNames[backdrops.tmpNumBitmaps], name);
784 backdrops.tmpNumBitmaps++;
787 filep = readdir(dirp);
799 /************************************************************************
801 * This is the exposeCallback for the bitmap drawing area.
802 ************************************************************************/
806 XtPointer client_data,
807 XtPointer call_data )
812 if (backdrops.selected == -1)
815 if (backdrops.newColors)
819 /* we could keep track of which tile pixmaps need to be updated
820 since the last workspace change, but for now simply regenerate
821 each pixmap as it is selected after a workspace change has
824 /* backdrops.newColors = False; */
827 if (backdrops.gc == NULL)
829 gcValues.background = backdrops.bg;
830 gcValues.foreground = backdrops.fg;
831 gcValues.fill_style = FillTiled;
832 gcValues.tile = backdrops.bitmaps[backdrops.selected];
834 backdrops.gc = XCreateGC (style.display, XtWindow(w),
835 GCForeground | GCBackground |
836 GCTile | GCFillStyle, &gcValues);
839 XFillRectangle (style.display, XtWindow(w), backdrops.gc, backdrops.shadow,
840 backdrops.shadow, backdrops.width, backdrops.height);
844 /************************************************************************
846 * This is the resizeCallback for the bitmap drawing area.
847 ************************************************************************/
851 XtPointer client_data,
852 XtPointer call_data )
854 backdrops.width = XtWidth(w) - 2*backdrops.shadow;
855 backdrops.height = XtHeight(w) - 2*backdrops.shadow;
859 /************************************************************************
861 * Make XmStrings from the bitmap descriptions, to pass into list.
863 ************************************************************************/
865 MakeListStrings( void )
871 char *str_type_return;
872 XrmValue value_return;
874 /* allocate space for bitmap descriptions */
875 backdrops.bitmapDescs = (char **)XtCalloc(backdrops.numBitmaps, sizeof(char *));
877 for (i=0; i<backdrops.numBitmaps; i++)
881 name_str = (char *) XtMalloc(strlen("backdrops.") +
882 strlen(backdrops.bitmapNames[i]) +
883 strlen(".desc") + 1);
885 class_str = (char *) XtMalloc(strlen("Backdrops.") +
886 strlen(backdrops.bitmapNames[i]) +
887 strlen(".Desc") + 1);
888 strcpy(name_str, "backdrops.");
889 strcpy(class_str, "Backdrops.");
890 strcat(name_str, backdrops.bitmapNames[i]);
891 strcat(class_str, backdrops.bitmapNames[i]);
892 strcat(name_str, ".desc");
893 strcat(class_str, ".Desc");
895 if (XrmGetResource (bd_DB, name_str, class_str, &str_type_return, &value_return))
897 /* make copy of resource value */
898 backdrops.bitmapDescs[i] = (char *) XtMalloc(value_return.size + 1);
899 strcpy (backdrops.bitmapDescs[i], value_return.addr);
903 backdrops.bitmapDescs[i] = (char *) XtMalloc(strlen(backdrops.bitmapNames[i]) + 1);
904 strcpy(backdrops.bitmapDescs[i], backdrops.bitmapNames[i]);
909 backdrops.bitmapDescs[i] = (char *) XtMalloc(strlen(backdrops.bitmapNames[i]) + 1);
910 strcpy(backdrops.bitmapDescs[i], backdrops.bitmapNames[i]);
914 list = (XmString *) XtCalloc(backdrops.numBitmaps, sizeof(XmString));
916 for (i = 0; i < backdrops.numBitmaps; i++)
918 list[i] = XmStringCreateLocalized (backdrops.bitmapDescs[i]);
925 /************************************************************************
927 * Free XmStrings from the bitmap names, passed into list.
928 ************************************************************************/
935 XmString *list = listPtr;
937 for (i = 0; i < backdrops.numBitmaps; i++)
939 if (list[i]) XmStringFree(list[i]);
941 XtFree ((char *)list);
945 /************************************************************************
947 * Get the bitmap selected from the list
948 ************************************************************************/
952 XtPointer client_data,
953 XtPointer call_data )
955 XmListCallbackStruct *cb = (XmListCallbackStruct *)call_data;
957 backdrops.selected = cb->item_position - 1;
959 XSetTile (style.display, backdrops.gc,
960 backdrops.bitmaps[backdrops.selected]);
962 DrawBitmap (backdrops.drawnButton, NULL, NULL);
967 /************************************************************************
970 ************************************************************************/
974 XtPointer client_data,
975 XtPointer call_data )
980 DtDialogBoxCallbackStruct *cb = (DtDialogBoxCallbackStruct *) call_data;
982 switch (cb->button_position)
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 /* send message to update backdrop */
997 num = backdrops.selected;
999 _DtWsmChangeBackdrop(style.display, style.root,
1000 backdrops.bitmapNames[num],
1001 backdrops.bitmaps[num]);
1005 case B_CANCEL_BUTTON: /* close */
1010 XtCallCallbacks(style.backdropDialog, XmNhelpCallback, (XtPointer)NULL);
1019 /************************************************************************
1021 * Workspace may have changed, so get current workspace
1022 * colors and draw the backdrop bitmap
1024 ************************************************************************/
1026 CheckWorkspace( void )
1028 backdrops.newColors = True; /* need to get new colors */
1029 if (style.backdropDialog && XtIsManaged(style.backdropDialog))
1031 DrawBitmap (backdrops.drawnButton, NULL, NULL);
1036 /************************************************************************
1038 * Get current workspace colors, and update GC if needed
1040 ************************************************************************/
1044 DtWsmWorkspaceInfo *wInfo=NULL;
1045 unsigned long num=0;
1050 if ((DtWsmGetCurrentWorkspace (style.display, style.root, &aWS)
1052 (DtWsmGetWorkspaceInfo (style.display, style.root, aWS, &wInfo)
1055 backdrops.bg = wInfo->bg;
1056 backdrops.fg = wInfo->fg;
1057 DtWsmFreeWorkspaceInfo (wInfo);
1065 if (backdrops.gc) /* update the gc if there is one */
1067 gcValues.background = backdrops.bg;
1068 gcValues.foreground = backdrops.fg;
1070 /* free old pixmap */
1071 XmDestroyPixmap(style.screen,
1072 backdrops.bitmaps[backdrops.selected]);
1074 /* allocate new pixmap */
1075 backdrops.bitmaps[backdrops.selected] =
1076 XmGetPixmap (style.screen,
1077 backdrops.bitmapNames[backdrops.selected],
1078 backdrops.fg, backdrops.bg);
1080 gcValues.tile = backdrops.bitmaps[backdrops.selected];
1082 XChangeGC (style.display, backdrops.gc,
1083 GCForeground | GCBackground | GCTile, &gcValues);
1088 /************************************************************************
1090 * Free some space that was allocated for backdrops
1091 ************************************************************************/
1097 /* set no bitmaps flag, so we won't try to get them next time */
1098 backdrops.noBitmaps = 1;
1100 /* free temporary list of backdrop names */
1101 for (i = 0; i < backdrops.tmpNumBitmaps; i++)
1102 if (backdrops.tmpBitmapNames[i])
1103 XtFree(backdrops.tmpBitmapNames[i]);
1104 XtFree ((char *)backdrops.tmpBitmapNames);
1105 XtFree ((char *)backdrops.bitmapNames);
1107 /* free backdrop bitmaps */
1108 for (i = 0; i < backdrops.numBitmaps; i++) {
1109 if (backdrops.bitmaps[i])
1110 XFreePixmap (style.display, backdrops.bitmaps[i]);
1111 if (backdrops.numBitmaps)
1112 XtFree((char *)backdrops.bitmaps);
1115 /* destory widgets (via first parent) */
1116 XtDestroyWidget (XtParent(style.backdropDialog));
1117 style.backdropDialog = NULL;
1121 /************************************************************************
1124 ************************************************************************/
1128 XtPointer client_data,
1129 XtPointer call_data )
1132 DtWsmRemoveWorkspaceFunctions(style.display, XtWindow(XtParent(w)));
1134 if (!save.restoreFlag)
1135 putDialog((Widget)client_data, w);
1137 XtRemoveCallback(style.backdropDialog, XmNmapCallback, _DtMapCB, NULL);
1141 /************************************************************************
1144 * restore any state information saved with saveBackdrop.
1145 * This is called from restoreSession with the application
1146 * shell and the special xrm database retrieved for restore.
1147 ************************************************************************/
1153 XrmName xrm_name[5];
1154 XrmRepresentation rep_type;
1157 xrm_name [0] = XrmStringToQuark (BACKDROPSDLG);
1160 /* get x position */
1161 xrm_name [1] = XrmStringToQuark ("x");
1162 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
1163 XtSetArg (save.posArgs[save.poscnt], XmNx, atoi((char *)value.addr));
1165 save.restoreFlag = True;
1168 /* get y position */
1169 xrm_name [1] = XrmStringToQuark ("y");
1170 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
1171 XtSetArg (save.posArgs[save.poscnt], XmNy, atoi((char *)value.addr));
1176 xrm_name [1] = XrmStringToQuark ("width");
1177 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
1178 XtSetArg(save.posArgs[save.poscnt], XmNwidth, atoi((char *)value.addr));
1183 xrm_name [1] = XrmStringToQuark ("height");
1184 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
1185 XtSetArg(save.posArgs[save.poscnt],XmNheight, atoi((char *)value.addr));
1189 xrm_name [1] = XrmStringToQuark ("ismapped");
1190 XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
1191 /* Are we supposed to be mapped? */
1192 if (strcmp(value.addr, "True") == 0)
1193 BackdropDialog(shell);
1197 /************************************************************************
1200 * This routine will write out to the passed file descriptor any state
1201 * information this dialog needs. It is called from saveSessionCB with the
1202 * file already opened.
1203 * All information is saved in xrm format. There is no restriction
1204 * on what can be saved. It doesn't have to be defined or be part of any
1205 * widget or Xt definition. Just name and save it here and recover it in
1206 * restoreBackdrop. The suggested minimum is whether you are mapped, and your
1208 ************************************************************************/
1214 Dimension width, height;
1215 char *bufr = style.tmpBigStr; /* size=[1024], make bigger if needed */
1216 XmVendorShellExtObject vendorExt;
1217 XmWidgetExtData extData;
1219 if (style.backdropDialog != NULL)
1221 if (XtIsManaged(style.backdropDialog))
1222 sprintf(bufr, "*backdropsDialog.ismapped: True\n");
1224 sprintf(bufr, "*backdropsDialog.ismapped: False\n");
1226 /* Get and write out the geometry info for our Window */
1227 x = XtX (XtParent(style.backdropDialog));
1228 y = XtY (XtParent(style.backdropDialog));
1229 width = XtWidth (style.backdropDialog);
1230 height = XtHeight (style.backdropDialog);
1232 /* Modify x & y to take into account window mgr frames
1233 * This is pretty bogus, but I don't know a better way to do it.
1235 extData = _XmGetWidgetExtData(style.shell, XmSHELL_EXTENSION);
1236 vendorExt = (XmVendorShellExtObject)extData->widget;
1237 x -= vendorExt->vendor.xOffset;
1238 y -= vendorExt->vendor.yOffset;
1240 sprintf(bufr, "%s*backdropsDialog.x: %d\n", bufr, x);
1241 sprintf(bufr, "%s*backdropsDialog.y: %d\n", bufr, y);
1242 sprintf(bufr, "%s*backdropsDialog.width: %d\n", bufr, width);
1243 sprintf(bufr, "%s*backdropsDialog.height: %d\n", bufr, height);
1244 sprintf(bufr, "%s*backdropsDialog.selectedItemNum: %d\n", bufr,
1245 backdrops.selected);
1246 sprintf(bufr, "%s*backdropsDialog.selectedItem: %s\n", bufr,
1247 backdrops.bitmapNames[backdrops.selected]);
1248 if(-1 == write (fd, bufr, strlen(bufr))) {
1249 perror(strerror(errno));