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 /*+++++++++++++++++++++++++++++++++++++++*/
45 #include <sys/types.h>
47 #if defined(_AIX) || defined(__apollo)
50 #include <dirent.h> /* opendir(), directory(3C) */
54 #include <X11/apollosys.h> /* needed for S_ISDIR macro */
60 #include <Xm/MwmUtil.h>
64 #include <Xm/DrawnB.h>
67 #include <Xm/VendorSEP.h>
68 #include <Xm/AtomMgr.h>
70 #include <Dt/DialogBox.h>
72 #include <Dt/Message.h>
73 #include <Dt/SessionM.h>
74 #include <Dt/HourGlass.h>
76 #include <Dt/UserMsg.h>
80 #include "SaveRestore.h"
82 /*+++++++++++++++++++++++++++++++++++++++*/
83 /* include extern functions */
84 /*+++++++++++++++++++++++++++++++++++++++*/
88 /*+++++++++++++++++++++++++++++++++++++++*/
90 /*+++++++++++++++++++++++++++++++++++++++*/
91 #define MAX_STR_LEN 128
93 #define B_APPLY_BUTTON 2
94 #define B_CANCEL_BUTTON 3
95 #define B_HELP_BUTTON 4
97 #define ERR2 ((char *)GETMESSAGE(11, 2, "The backdrop portion of the Style Manager\n\
98 will not operate because there are no backdrop\nfiles available. Check $HOME/.dt/errorlog."))
100 /*+++++++++++++++++++++++++++++++++++++++*/
101 /* Internal Functions */
102 /*+++++++++++++++++++++++++++++++++++++++*/
104 static int CreateBackdropDialog( Widget parent) ;
105 static void MoreBitmaps( void ) ;
106 static ReadBitmaps( void ) ;
107 static Boolean CreatePixmaps( void ) ;
108 static ReadBitmapDirectory( char *dir ) ;
109 static void DrawBitmap(
111 XtPointer client_data,
112 XtPointer call_data) ;
113 static void SizeBitmap(
115 XtPointer client_data,
116 XtPointer call_data) ;
117 static XmString * MakeListStrings( void ) ;
118 static void FreeListStrings( XmString *listPtr) ;
121 XtPointer client_data,
122 XtPointer call_data) ;
123 static void ButtonCB(
125 XtPointer client_data,
126 XtPointer call_data) ;
127 static void GetColors( void ) ;
128 static void FreeAll( void ) ;
129 static void _DtMapCB(
131 XtPointer client_data,
132 XtPointer call_data) ;
135 /*+++++++++++++++++++++++++++++++++++++++*/
136 /* Internal Variables */
137 /*+++++++++++++++++++++++++++++++++++++++*/
143 char **tmpBitmapNames;
145 int tmpMaxNumBitmaps;
159 } Backdrops, *BackdropsPtr;
160 static Backdrops backdrops;
162 static saveRestore save = {FALSE, 0, };
163 char *BACKDROPSDLG = "backdropsDialog";
166 * copy of the system backdrop description file for the
167 * current locale in xrm form
169 static XrmDatabase sys_bd_DB = NULL;
172 * copy of the admin backdrop description file for the
173 * current locale in xrm form
175 static XrmDatabase adm_bd_DB = NULL;
178 * copy of the user's home backdrop description file for the
179 * current locale in xrm form
181 static XrmDatabase hm_bd_DB = NULL;
184 * final combination of the admin & system data bases
186 static XrmDatabase bd_DB = NULL;
190 /*+++++++++++++++++++++++++++++++++++++++*/
192 /*+++++++++++++++++++++++++++++++++++++++*/
195 build_dirList(char * dirStr,
198 char tokenSep[] = ":";
200 char ** dirList = NULL;
203 int len = strlen(dirStr);
206 tmpStr = (char *)XtCalloc(1, len + 1);
207 strcpy(tmpStr, dirStr);
208 token = strtok(tmpStr, tokenSep);
212 token = strtok(NULL, tokenSep);
218 dirList = (char **) XtCalloc(1, i * sizeof(char *));
221 strcpy(tmpStr, dirStr);
222 token = strtok(tmpStr, tokenSep);
226 dirList[*count] = (char *) XtCalloc(1, strlen( token ) + 1);
227 strcpy(dirList[*count], token);
228 token = strtok(NULL, tokenSep);
233 XtFree ((char *) tmpStr);
239 /*+++++++++++++++++++++++++++++++++++++++*/
241 /*+++++++++++++++++++++++++++++++++++++++*/
244 free_dirList(char ** dirList,
252 for (i=0; i<count; i++)
253 XtFree((char *) dirList[i]);
255 XtFree ((char *) dirList);
259 /************************************************************************
260 * SelectCurrentBackdrop() - Selects current backdrop in list
262 ************************************************************************/
263 void SelectCurrentBackdrop(callback)
265 DtWsmWorkspaceInfo *wInfo=NULL;
271 if ((DtWsmGetCurrentWorkspace (style.display, style.root, &aWS)
273 (DtWsmGetWorkspaceInfo (style.display, style.root, aWS, &wInfo)
279 list = XtNameToWidget(style.backdropDialog, "*bitmapList");
281 backdropName = XmGetAtomName(style.display, wInfo->backdropName);
283 for (i = 0; i < backdrops.numBitmaps; i++) {
284 if (strcmp(backdrops.bitmapNames[i], backdropName) == 0) {
285 XmListSelectPos (list, i + 1, callback);
286 XmListSetPos(list, i + 1);
287 backdrops.selected = i;
291 XtFree((char *) backdropName);
292 XtFree((char *) wInfo);
295 /************************************************************************
296 * BackdropDialog() - Create backdrop selection dialog first time up.
297 * If it has already been created, map it.
298 ************************************************************************/
305 if (style.backdropDialog == NULL)
307 _DtTurnOnHourGlass(parent);
308 if (!CreateBackdropDialog(parent)) {
309 _DtTurnOffHourGlass(parent);
312 SelectCurrentBackdrop(False);
313 XtManageChild(style.backdropDialog);
314 XSync(style.display, 0);
315 XmUpdateDisplay(style.backdropDialog);
316 _DtTurnOffHourGlass(parent);
321 SelectCurrentBackdrop(True);
322 XtManageChild(style.backdropDialog);
323 raiseWindow(XtWindow(XtParent(style.backdropDialog)));
324 XmUpdateDisplay(style.backdropDialog);
329 /************************************************************************
330 * CreateBackdropDialog()
331 * Create the Backdrop Dialog
332 ************************************************************************/
334 CreateBackdropDialog(
341 XmString strings[NUM_LABELS+1];
342 XmString *listStrings;
347 if (backdrops.noBitmaps)
349 ErrDialog (backdrops.errStr, style.shell);
353 /* initialize backdrop data */
354 backdrops.bitmapNames = NULL;
355 backdrops.bitmaps = NULL;
356 backdrops.numBitmaps = 0;
357 backdrops.maxNumBitmaps = 100;
358 backdrops.selected = -1;
360 backdrops.errStr = NULL;
361 backdrops.shadow = 2;
362 backdrops.width = 200 - 2*backdrops.shadow;
363 backdrops.height = 200 - 2*backdrops.shadow;
364 backdrops.newColors = True;
367 /* load the backdrop description data base for the given locale*/
368 /* from that locale's description file from the system location */
369 lang = setlocale (LC_CTYPE,NULL);
371 #ifdef hpux /* hpux-specific parsing of the locale string */
372 /* The following code is identical to the
373 ExtractLocaleName function in WmResParse.c
376 #define MAXLOCALE 64 /* buffer size of locale name */
381 static char buf[MAXLOCALE];
383 /* If lang has a substring ":<category>;", extract <category>
384 * from the first such occurrence as the locale name.
388 if (start = strchr (lang, ':')) {
390 if (end = strchr (start, ';')) {
392 strncpy(buf, start, len);
400 bd_desc = (char *)XtMalloc(strlen("/usr/dt/backdrops/desc.") + strlen(lang) + 1);
401 strcpy (bd_desc,"/usr/dt/backdrops/desc.");
402 strcat (bd_desc, lang);
403 if(sys_bd_DB = XrmGetFileDatabase (bd_desc))
404 XrmMergeDatabases(sys_bd_DB, &bd_DB);
407 /* load the backdrop description data base for the given locale*/
408 /* from that locale's description file from the admin location */
409 bd_desc = (char *)XtMalloc(strlen("/etc/dt/backdrops/desc.") + strlen(lang) + 1);
410 strcpy (bd_desc,"/etc/dt/backdrops/desc.");
411 strcat (bd_desc, lang);
412 if (adm_bd_DB = XrmGetFileDatabase (bd_desc))
413 XrmMergeDatabases(adm_bd_DB, &bd_DB);
416 /* load the backdrop description from the user's .dt/backdrops directory */
417 /* regardless of locale */
418 bd_desc = (char *)XtMalloc(strlen(style.home) + strlen("/.dt/backdrops/desc.backdrops") + 1);
419 strcpy (bd_desc, style.home);
420 strcat (bd_desc, "/.dt/backdrops/desc.backdrops");
421 if (hm_bd_DB = XrmGetFileDatabase (bd_desc))
422 XrmMergeDatabases(hm_bd_DB, &bd_DB);
425 /* Set up DialogBox button labels. */
426 strings[0] = XmStringCreateLocalized (_DtOkString);
427 strings[1] = XmStringCreateLocalized (_DtApplyString);
428 strings[2] = XmStringCreateLocalized (_DtCloseString);
429 strings[3] = XmStringCreateLocalized (_DtHelpString);
432 * Note that save.poscnt has been initialized elsewhere.
433 * save.posArgs may contain information from restoreBackdrop().*/
435 /* create the dialog box with shell */
437 XtSetArg (save.posArgs[save.poscnt], XmNbuttonCount, NUM_LABELS+1);
439 XtSetArg (save.posArgs[save.poscnt], XmNbuttonLabelStrings, strings);
441 XtSetArg (save.posArgs[save.poscnt], XmNdefaultPosition, False);
443 XtSetArg (save.posArgs[save.poscnt], XmNallowOverlap, False);
445 style.backdropDialog = __DtCreateDialogBoxDialog (parent, BACKDROPSDLG,
446 save.posArgs, save.poscnt);
447 XtAddCallback(style.backdropDialog, XmNcallback, ButtonCB, NULL);
448 XtAddCallback(style.backdropDialog, XmNmapCallback, _DtMapCB, parent);
449 XtAddCallback(style.backdropDialog, XmNhelpCallback,
450 (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_BACKDROP_DIALOG);
452 /* free compound strings now */
453 XmStringFree (strings[0]);
454 XmStringFree (strings[1]);
455 XmStringFree (strings[2]);
456 XmStringFree (strings[3]);
459 XtSetArg (args[n], XmNtitle, ((char *)GETMESSAGE(11, 12, "Style Manager - Backdrop"))); n++;
460 XtSetArg (args[n], XmNuseAsyncGeometry, True); n++;
461 XtSetValues (XtParent(style.backdropDialog), args, n);
463 /* get bitmap data */
464 if (!ReadBitmaps()) return 0; /* uses style.backdropDialog */
466 /* create the form to go in to dialog box as the work area */
468 XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
469 XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
470 XtSetArg (args[n], XmNchildType, XmWORK_AREA); n++;
472 XtSetArg (args[n], XmNallowOverlap, False); n++;
473 mainForm = XmCreateForm (style.backdropDialog, "backdropsForm", args, n);
475 /* create the scrolled list of bitmap names... first create XmStrings */
476 listStrings = MakeListStrings ();
478 XtSetArg (args[n], XmNautomaticSelection, True); n++;
479 XtSetArg (args[n], XmNselectionPolicy, XmBROWSE_SELECT); n++;
480 XtSetArg (args[n], XmNitems, listStrings); n++;
481 XtSetArg (args[n], XmNitemCount, backdrops.numBitmaps); n++;
482 list = XmCreateScrolledList (mainForm, "bitmapList", args, n);
483 XtAddCallback (list, XmNbrowseSelectionCallback, ListCB, (XtPointer)NULL);
484 FreeListStrings (listStrings); /* after list has copied */
486 /* set up attachments for scrolled list itself */
488 XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
489 XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
490 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
491 XtSetValues (XtParent(list), args, n);
493 /* Create drawing area for the bitmap */
495 XtSetArg (args[n], XmNshadowType, XmSHADOW_IN); n++;
496 XtSetArg (args[n], XmNshadowThickness, backdrops.shadow); n++;
497 XtSetArg (args[n], XmNhighlightThickness, 0); n++;
498 XtSetArg (args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
499 XtSetArg (args[n], XmNrightWidget, XtParent(list)); n++;
500 XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
501 XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
502 XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
503 XtSetArg (args[n], XmNborderWidth, 0); n++;
504 XtSetArg (args[n], XmNwidth, backdrops.width+2*backdrops.shadow); n++;
505 XtSetArg (args[n], XmNheight, backdrops.height+2*backdrops.shadow); n++;
506 XtSetArg (args[n], XmNtraversalOn, False); n++;
507 backdrops.drawnButton = XmCreateDrawnButton (mainForm, "bitmap", args, n);
508 XtAddCallback (backdrops.drawnButton, XmNexposeCallback, DrawBitmap, NULL);
509 XtAddCallback (backdrops.drawnButton, XmNresizeCallback, SizeBitmap, NULL);
511 /* manage all of the widgets */
512 XtManageChild (mainForm);
513 XtManageChild (backdrops.drawnButton);
514 XtManageChild (list);
520 /************************************************************************
522 * Create space for more bitmap entries
523 ************************************************************************/
529 /* allocate space for icon names */
530 newSize = (backdrops.maxNumBitmaps + 100) * sizeof(char *);
531 backdrops.bitmapNames = (char **) XtRealloc((char *)backdrops.bitmapNames,
534 /* now allocate new bitmap space */
535 newSize = (backdrops.maxNumBitmaps + 100) * sizeof(Pixmap);
536 backdrops.bitmaps = (Pixmap *)XtRealloc((char *)backdrops.bitmaps, newSize);
538 backdrops.maxNumBitmaps += 100;
541 /************************************************************************
543 * Create an array of bitmaps by reading backdrop directories in the
544 * following order overriding any duplicates:
545 * 1) Read the system location /usr/dt/backdrops
546 * 2) Read the admin location /etc/dt/backdrops
547 * 3) Read the directories specified by the backdropDirectories
549 * 4) Read the user's home directory /$HOME/.dt/backdrops.
550 ************************************************************************/
555 Pixmap tmpPix = NULL;
556 int width, height, x, y;
561 /* allocate space for temporary bitmap info */
562 backdrops.tmpBitmapNames = (char **)XtCalloc(100, sizeof(char *));
563 backdrops.tmpMaxNumBitmaps = 100;
564 backdrops.tmpNumBitmaps = 0;
566 /* read system backdrop directory */
567 ReadBitmapDirectory("/usr/dt/backdrops");
568 /* read sys admin backdrop directory */
569 ReadBitmapDirectory("/etc/dt/backdrops");
571 /* Parse the backdropDirectories resource to get the individual directories */
572 if (style.xrdb.backdropDir)
574 backdrops.dirList = build_dirList(style.xrdb.backdropDir, &backdrops.dirCount);
576 /* compile the list of bitmaps */
577 for (i=0; i<backdrops.dirCount; i++)
578 ReadBitmapDirectory(backdrops.dirList[i]);
581 /* read the directory $HOME/.dt/backdrops */
582 string = (char *)XtMalloc(strlen(style.home) + strlen("/.dt/backdrops") + 1);
583 sprintf(string, "%s/.dt/backdrops", style.home);
584 ReadBitmapDirectory(string);
588 if (backdrops.tmpNumBitmaps == 0)
590 /* give error dialog, free space, and return */
591 backdrops.errStr = (char *)XtMalloc(strlen(ERR2) + 1);
592 sprintf(backdrops.errStr, ERR2);
593 ErrDialog (backdrops.errStr, style.shell);
595 free_dirList(backdrops.dirList, backdrops.dirCount);
599 /* get the fg/bg colors from Dtwm */
600 if (backdrops.newColors)
603 backdrops.newColors = False;
606 /* create all the pixmaps */
607 if (!CreatePixmaps())
609 /* give error dialog, free space, and return */
610 backdrops.errStr = (char *)XtMalloc(strlen(ERR2) + 1);
611 sprintf(backdrops.errStr, ERR2);
612 ErrDialog (backdrops.errStr, style.shell);
614 free_dirList(backdrops.dirList, backdrops.dirCount);
619 if (backdrops.selected == -1) backdrops.selected = 0;
626 /************************************************************************
628 * Create the pixmpas in the backdrop list
629 with workprocs 10 at a time
630 ************************************************************************/
632 CreatePixmaps( void )
635 static int pixmapsCreated=0;
639 backdrops.numBitmaps = 0;
641 /* allocate space for real bitmap info */
642 backdrops.bitmapNames = (char **)XtCalloc(100, sizeof(char *));
643 backdrops.bitmaps = (Pixmap *)XtCalloc(100, sizeof(Pixmap));
645 for (i=0; i<backdrops.tmpNumBitmaps; i++)
647 tmpPixmap = XmGetPixmap (style.screen,
648 backdrops.tmpBitmapNames[i],
649 backdrops.fg, backdrops.bg);
650 if (tmpPixmap != XmUNSPECIFIED_PIXMAP)
652 if (backdrops.numBitmaps == backdrops.maxNumBitmaps)
655 backdrops.bitmapNames[backdrops.numBitmaps] =
656 backdrops.tmpBitmapNames[i];
657 backdrops.bitmaps[backdrops.numBitmaps] = tmpPixmap;
659 backdrops.numBitmaps++;
663 if (backdrops.numBitmaps)
671 /************************************************************************
672 * ReadBitmapDirectory()
673 * Create an array of bitmap names overriding duplicates
674 ************************************************************************/
681 struct dirent *filep;
686 struct stat stat_buf;
687 char *statPath, *pStatPath;
690 /* open the backdrops directory */
691 if ((dirp = opendir(dir)) == NULL)
693 /* print message to errorlog, free space, and return */
697 /* create string to contain complete path */
698 statPath = (char *) XtMalloc(strlen(dir) + MAX_STR_LEN + 2);
699 strcpy (statPath, dir);
700 strcat (statPath, "/");
701 pStatPath = statPath + strlen(statPath);
703 filep = readdir(dirp);
705 while (filep != NULL)
707 /* append filename to stat path */
708 strcpy (pStatPath, filep->d_name);
711 if ((stat_result = stat (statPath, &stat_buf)) != 0)
713 filep = readdir(dirp);
717 /* skip directories */
718 if ((stat_buf.st_mode & S_IFMT) == S_IFDIR)
720 filep = readdir(dirp);
725 /* strip suffix off filename */
726 name = (char *) XtMalloc(strlen(filep->d_name) + 1);
727 strcpy (name, filep->d_name);
728 (void)strtok(name, ".");
730 /* check for duplicates */
732 for (i=0; i<backdrops.tmpNumBitmaps; i++)
734 if (!strcmp(backdrops.tmpBitmapNames[i], name))
743 /* add to the temporary bitmap list */
745 if (backdrops.tmpNumBitmaps == backdrops.tmpMaxNumBitmaps)
747 /* allocate space for more temporary bitmap info */
748 newSize = (backdrops.tmpMaxNumBitmaps + 100) * sizeof(char *);
749 backdrops.tmpBitmapNames =
750 (char **)XtRealloc((char *)backdrops.tmpBitmapNames, newSize);
751 backdrops.tmpMaxNumBitmaps += 100;
754 backdrops.tmpBitmapNames[backdrops.tmpNumBitmaps] =
755 (char *) XtMalloc(strlen(name)+1);
756 strcpy (backdrops.tmpBitmapNames[backdrops.tmpNumBitmaps], name);
758 backdrops.tmpNumBitmaps++;
761 filep = readdir(dirp);
773 /************************************************************************
775 * This is the exposeCallback for the bitmap drawing area.
776 ************************************************************************/
780 XtPointer client_data,
781 XtPointer call_data )
786 if (backdrops.selected == -1)
789 if (backdrops.newColors)
793 /* we could keep track of which tile pixmaps need to be updated
794 since the last workspace change, but for now simply regenerate
795 each pixmap as it is selected after a workspace change has
798 /* backdrops.newColors = False; */
801 if (backdrops.gc == NULL)
803 gcValues.background = backdrops.bg;
804 gcValues.foreground = backdrops.fg;
805 gcValues.fill_style = FillTiled;
806 gcValues.tile = backdrops.bitmaps[backdrops.selected];
808 backdrops.gc = XCreateGC (style.display, XtWindow(w),
809 GCForeground | GCBackground |
810 GCTile | GCFillStyle, &gcValues);
813 XFillRectangle (style.display, XtWindow(w), backdrops.gc, backdrops.shadow,
814 backdrops.shadow, backdrops.width, backdrops.height);
818 /************************************************************************
820 * This is the resizeCallback for the bitmap drawing area.
821 ************************************************************************/
825 XtPointer client_data,
826 XtPointer call_data )
828 backdrops.width = XtWidth(w) - 2*backdrops.shadow;
829 backdrops.height = XtHeight(w) - 2*backdrops.shadow;
833 /************************************************************************
835 * Make XmStrings from the bitmap descriptions, to pass into list.
837 ************************************************************************/
839 MakeListStrings( void )
845 char *str_type_return;
846 XrmValue value_return;
848 /* allocate space for bitmap descriptions */
849 backdrops.bitmapDescs = (char **)XtCalloc(backdrops.numBitmaps, sizeof(char *));
851 for (i=0; i<backdrops.numBitmaps; i++)
855 name_str = (char *) XtMalloc(strlen("backdrops.") +
856 strlen(backdrops.bitmapNames[i]) +
857 strlen(".desc") + 1);
859 class_str = (char *) XtMalloc(strlen("Backdrops.") +
860 strlen(backdrops.bitmapNames[i]) +
861 strlen(".Desc") + 1);
862 strcpy(name_str, "backdrops.");
863 strcpy(class_str, "Backdrops.");
864 strcat(name_str, backdrops.bitmapNames[i]);
865 strcat(class_str, backdrops.bitmapNames[i]);
866 strcat(name_str, ".desc");
867 strcat(class_str, ".Desc");
869 if (XrmGetResource (bd_DB, name_str, class_str, &str_type_return, &value_return))
871 /* make copy of resource value */
872 backdrops.bitmapDescs[i] = (char *) XtMalloc(value_return.size + 1);
873 strcpy (backdrops.bitmapDescs[i], value_return.addr);
877 backdrops.bitmapDescs[i] = (char *) XtMalloc(strlen(backdrops.bitmapNames[i]) + 1);
878 strcpy(backdrops.bitmapDescs[i], backdrops.bitmapNames[i]);
883 backdrops.bitmapDescs[i] = (char *) XtMalloc(strlen(backdrops.bitmapNames[i]) + 1);
884 strcpy(backdrops.bitmapDescs[i], backdrops.bitmapNames[i]);
888 list = (XmString *) XtCalloc(backdrops.numBitmaps, sizeof(XmString));
890 for (i = 0; i < backdrops.numBitmaps; i++)
892 list[i] = XmStringCreateLocalized (backdrops.bitmapDescs[i]);
899 /************************************************************************
901 * Free XmStrings from the bitmap names, passed into list.
902 ************************************************************************/
909 XmString *list = listPtr;
911 for (i = 0; i < backdrops.numBitmaps; i++)
913 if (list[i]) XmStringFree(list[i]);
915 XtFree ((char *)list);
919 /************************************************************************
921 * Get the bitmap selected from the list
922 ************************************************************************/
926 XtPointer client_data,
927 XtPointer call_data )
929 XmListCallbackStruct *cb = (XmListCallbackStruct *)call_data;
931 backdrops.selected = cb->item_position - 1;
933 XSetTile (style.display, backdrops.gc,
934 backdrops.bitmaps[backdrops.selected]);
936 DrawBitmap (backdrops.drawnButton, NULL, NULL);
941 /************************************************************************
944 ************************************************************************/
948 XtPointer client_data,
949 XtPointer call_data )
954 DtDialogBoxCallbackStruct *cb = (DtDialogBoxCallbackStruct *) call_data;
956 switch (cb->button_position)
959 /* send message to update backdrop */
961 num = backdrops.selected;
963 _DtWsmChangeBackdrop(style.display, style.root,
964 backdrops.bitmapNames[num],
965 backdrops.bitmaps[num]);
969 /* send message to update backdrop */
971 num = backdrops.selected;
973 _DtWsmChangeBackdrop(style.display, style.root,
974 backdrops.bitmapNames[num],
975 backdrops.bitmaps[num]);
979 case B_CANCEL_BUTTON: /* close */
984 XtCallCallbacks(style.backdropDialog, XmNhelpCallback, (XtPointer)NULL);
993 /************************************************************************
995 * Workspace may have changed, so get current workspace
996 * colors and draw the backdrop bitmap
998 ************************************************************************/
1000 CheckWorkspace( void )
1002 backdrops.newColors = True; /* need to get new colors */
1003 if (style.backdropDialog && XtIsManaged(style.backdropDialog))
1005 DrawBitmap (backdrops.drawnButton, NULL, NULL);
1010 /************************************************************************
1012 * Get current workspace colors, and update GC if needed
1014 ************************************************************************/
1018 DtWsmWorkspaceInfo *wInfo=NULL;
1019 unsigned long num=0;
1024 if ((DtWsmGetCurrentWorkspace (style.display, style.root, &aWS)
1026 (DtWsmGetWorkspaceInfo (style.display, style.root, aWS, &wInfo)
1029 backdrops.bg = wInfo->bg;
1030 backdrops.fg = wInfo->fg;
1031 DtWsmFreeWorkspaceInfo (wInfo);
1039 if (backdrops.gc) /* update the gc if there is one */
1041 gcValues.background = backdrops.bg;
1042 gcValues.foreground = backdrops.fg;
1044 /* free old pixmap */
1045 XmDestroyPixmap(style.screen,
1046 backdrops.bitmaps[backdrops.selected]);
1048 /* allocate new pixmap */
1049 backdrops.bitmaps[backdrops.selected] =
1050 XmGetPixmap (style.screen,
1051 backdrops.bitmapNames[backdrops.selected],
1052 backdrops.fg, backdrops.bg);
1054 gcValues.tile = backdrops.bitmaps[backdrops.selected];
1056 XChangeGC (style.display, backdrops.gc,
1057 GCForeground | GCBackground | GCTile, &gcValues);
1062 /************************************************************************
1064 * Free some space that was allocated for backdrops
1065 ************************************************************************/
1071 /* set no bitmaps flag, so we won't try to get them next time */
1072 backdrops.noBitmaps = 1;
1074 /* free temporary list of backdrop names */
1075 for (i = 0; i < backdrops.tmpNumBitmaps; i++)
1076 if (backdrops.tmpBitmapNames[i])
1077 XtFree(backdrops.tmpBitmapNames[i]);
1078 XtFree ((char *)backdrops.tmpBitmapNames);
1079 XtFree ((char *)backdrops.bitmapNames);
1081 /* free backdrop bitmaps */
1082 for (i = 0; i < backdrops.numBitmaps; i++) {
1083 if (backdrops.bitmaps[i])
1084 XFreePixmap (style.display, backdrops.bitmaps[i]);
1085 if (backdrops.numBitmaps)
1086 XtFree((char *)backdrops.bitmaps);
1089 /* destory widgets (via first parent) */
1090 XtDestroyWidget (XtParent(style.backdropDialog));
1091 style.backdropDialog = NULL;
1095 /************************************************************************
1098 ************************************************************************/
1102 XtPointer client_data,
1103 XtPointer call_data )
1106 DtWsmRemoveWorkspaceFunctions(style.display, XtWindow(XtParent(w)));
1108 if (!save.restoreFlag)
1109 putDialog((Widget)client_data, w);
1111 XtRemoveCallback(style.backdropDialog, XmNmapCallback, _DtMapCB, NULL);
1115 /************************************************************************
1118 * restore any state information saved with saveBackdrop.
1119 * This is called from restoreSession with the application
1120 * shell and the special xrm database retrieved for restore.
1121 ************************************************************************/
1127 XrmName xrm_name[5];
1128 XrmRepresentation rep_type;
1131 xrm_name [0] = XrmStringToQuark (BACKDROPSDLG);
1132 xrm_name [2] = NULL;
1134 /* get x position */
1135 xrm_name [1] = XrmStringToQuark ("x");
1136 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
1137 XtSetArg (save.posArgs[save.poscnt], XmNx, atoi((char *)value.addr));
1139 save.restoreFlag = True;
1142 /* get y position */
1143 xrm_name [1] = XrmStringToQuark ("y");
1144 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
1145 XtSetArg (save.posArgs[save.poscnt], XmNy, atoi((char *)value.addr));
1150 xrm_name [1] = XrmStringToQuark ("width");
1151 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
1152 XtSetArg(save.posArgs[save.poscnt], XmNwidth, atoi((char *)value.addr));
1157 xrm_name [1] = XrmStringToQuark ("height");
1158 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
1159 XtSetArg(save.posArgs[save.poscnt],XmNheight, atoi((char *)value.addr));
1163 xrm_name [1] = XrmStringToQuark ("ismapped");
1164 XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
1165 /* Are we supposed to be mapped? */
1166 if (strcmp(value.addr, "True") == 0)
1167 BackdropDialog(shell);
1171 /************************************************************************
1174 * This routine will write out to the passed file descriptor any state
1175 * information this dialog needs. It is called from saveSessionCB with the
1176 * file already opened.
1177 * All information is saved in xrm format. There is no restriction
1178 * on what can be saved. It doesn't have to be defined or be part of any
1179 * widget or Xt definition. Just name and save it here and recover it in
1180 * restoreBackdrop. The suggested minimum is whether you are mapped, and your
1182 ************************************************************************/
1188 Dimension width, height;
1189 char *bufr = style.tmpBigStr; /* size=[1024], make bigger if needed */
1190 XmVendorShellExtObject vendorExt;
1191 XmWidgetExtData extData;
1193 if (style.backdropDialog != NULL)
1195 if (XtIsManaged(style.backdropDialog))
1196 sprintf(bufr, "*backdropsDialog.ismapped: True\n");
1198 sprintf(bufr, "*backdropsDialog.ismapped: False\n");
1200 /* Get and write out the geometry info for our Window */
1201 x = XtX (XtParent(style.backdropDialog));
1202 y = XtY (XtParent(style.backdropDialog));
1203 width = XtWidth (style.backdropDialog);
1204 height = XtHeight (style.backdropDialog);
1206 /* Modify x & y to take into account window mgr frames
1207 * This is pretty bogus, but I don't know a better way to do it.
1209 extData = _XmGetWidgetExtData(style.shell, XmSHELL_EXTENSION);
1210 vendorExt = (XmVendorShellExtObject)extData->widget;
1211 x -= vendorExt->vendor.xOffset;
1212 y -= vendorExt->vendor.yOffset;
1214 sprintf(bufr, "%s*backdropsDialog.x: %d\n", bufr, x);
1215 sprintf(bufr, "%s*backdropsDialog.y: %d\n", bufr, y);
1216 sprintf(bufr, "%s*backdropsDialog.width: %d\n", bufr, width);
1217 sprintf(bufr, "%s*backdropsDialog.height: %d\n", bufr, height);
1218 sprintf(bufr, "%s*backdropsDialog.selectedItemNum: %d\n", bufr,
1219 backdrops.selected);
1220 sprintf(bufr, "%s*backdropsDialog.selectedItem: %s\n", bufr,
1221 backdrops.bitmapNames[backdrops.selected]);
1222 write (fd, bufr, strlen(bufr));