Backdrop.c 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  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)
  10. * any later version.
  11. *
  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
  16. * details.
  17. *
  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
  22. */
  23. /* $TOG: Backdrop.c /main/7 1998/11/25 14:48:36 samborn $ */
  24. /************************************<+>*************************************
  25. ****************************************************************************
  26. **
  27. ** File: Backdrop.c
  28. **
  29. ** Project: DT 3.0
  30. **
  31. ** Description: Controls the Dtstyle Backdrop dialog
  32. **
  33. **
  34. ** (c) Copyright Hewlett-Packard Company, 1990, 1993.
  35. **
  36. **
  37. **
  38. ****************************************************************************
  39. ************************************<+>*************************************/
  40. /*+++++++++++++++++++++++++++++++++++++++*/
  41. /* include files */
  42. /*+++++++++++++++++++++++++++++++++++++++*/
  43. #include <stdio.h>
  44. #include <string.h>
  45. #include <stdlib.h>
  46. #include <sys/types.h>
  47. #include <errno.h>
  48. #if defined(_AIX)
  49. #include <sys/dir.h>
  50. #else
  51. #include <dirent.h> /* opendir(), directory(3C) */
  52. #endif /* _AIX */
  53. #include <locale.h>
  54. #include <X11/Xlib.h>
  55. #include <Xm/MwmUtil.h>
  56. #include <Xm/Xm.h>
  57. #include <Xm/XmP.h>
  58. #include <Xm/DrawnB.h>
  59. #include <Xm/Form.h>
  60. #include <Xm/List.h>
  61. #include <Xm/VendorSEP.h>
  62. #include <Xm/AtomMgr.h>
  63. #include <Xm/RowColumn.h>
  64. #include <Xm/ToggleBG.h>
  65. #include <Dt/DialogBox.h>
  66. #include <Dt/Message.h>
  67. #include <Dt/SessionM.h>
  68. #include <Dt/HourGlass.h>
  69. #include <Dt/Wsm.h>
  70. #include <Dt/UserMsg.h>
  71. #include <Dt/WsmP.h>
  72. #include <Dt/TitleBox.h>
  73. #include "Help.h"
  74. #include "Main.h"
  75. #include "SaveRestore.h"
  76. /*+++++++++++++++++++++++++++++++++++++++*/
  77. /* include extern functions */
  78. /*+++++++++++++++++++++++++++++++++++++++*/
  79. #include "Backdrop.h"
  80. #include "Dtwm.h"
  81. /*+++++++++++++++++++++++++++++++++++++++*/
  82. /* Local #defines */
  83. /*+++++++++++++++++++++++++++++++++++++++*/
  84. #define MAX_STR_LEN 128
  85. #define B_OK_BUTTON 1
  86. #define B_APPLY_BUTTON 2
  87. #define B_CANCEL_BUTTON 3
  88. #define B_HELP_BUTTON 4
  89. #define ERR2 ((char *)GETMESSAGE(11, 2, "The backdrop portion of the Style Manager\n\
  90. will not operate because there are no backdrop\nfiles available. Check $HOME/.dt/errorlog."))
  91. /*+++++++++++++++++++++++++++++++++++++++*/
  92. /* Internal Functions */
  93. /*+++++++++++++++++++++++++++++++++++++++*/
  94. static int CreateBackdropDialog( Widget parent) ;
  95. static void MoreBitmaps( void ) ;
  96. static int ReadBitmaps( void ) ;
  97. static Boolean CreatePixmaps( void ) ;
  98. static int ReadBitmapDirectory( char *dir ) ;
  99. static void DrawBitmap(
  100. Widget w,
  101. XtPointer client_data,
  102. XtPointer call_data) ;
  103. static void SizeBitmap(
  104. Widget w,
  105. XtPointer client_data,
  106. XtPointer call_data) ;
  107. static XmString * MakeListStrings( void ) ;
  108. static void FreeListStrings( XmString *listPtr) ;
  109. static void ListCB(
  110. Widget w,
  111. XtPointer client_data,
  112. XtPointer call_data) ;
  113. static void ButtonCB(
  114. Widget w,
  115. XtPointer client_data,
  116. XtPointer call_data) ;
  117. static void GetColors( void ) ;
  118. static void FreeAll( void ) ;
  119. static void _DtMapCB(
  120. Widget w,
  121. XtPointer client_data,
  122. XtPointer call_data) ;
  123. /*+++++++++++++++++++++++++++++++++++++++*/
  124. /* Internal Variables */
  125. /*+++++++++++++++++++++++++++++++++++++++*/
  126. typedef struct {
  127. Widget drawnButton;
  128. Widget imageStyleTB;
  129. Widget imageTypeRC;
  130. Widget tiledTG;
  131. Widget centeredTG;
  132. #if defined(USE_XRENDER)
  133. Widget fitTG;
  134. Widget fillTG;
  135. #endif /* USE_XRENDER */
  136. char **dirList;
  137. int dirCount;
  138. char **tmpBitmapNames;
  139. int tmpNumBitmaps;
  140. int tmpMaxNumBitmaps;
  141. char **bitmapNames;
  142. char **bitmapDescs;
  143. Pixmap *bitmaps;
  144. int numBitmaps;
  145. int maxNumBitmaps;
  146. int selected;
  147. GC gc;
  148. int width, height;
  149. int shadow;
  150. Pixel fg, bg;
  151. char *errStr;
  152. char noBitmaps;
  153. Boolean newColors;
  154. } Backdrops, *BackdropsPtr;
  155. static Backdrops backdrops;
  156. static saveRestore save = {FALSE, 0, };
  157. char *BACKDROPSDLG = "backdropsDialog";
  158. /*
  159. * copy of the system backdrop description file for the
  160. * current locale in xrm form
  161. */
  162. static XrmDatabase sys_bd_DB = NULL;
  163. /*
  164. * copy of the admin backdrop description file for the
  165. * current locale in xrm form
  166. */
  167. static XrmDatabase adm_bd_DB = NULL;
  168. /*
  169. * copy of the user's home backdrop description file for the
  170. * current locale in xrm form
  171. */
  172. static XrmDatabase hm_bd_DB = NULL;
  173. /*
  174. * final combination of the admin & system data bases
  175. */
  176. static XrmDatabase bd_DB = NULL;
  177. /*+++++++++++++++++++++++++++++++++++++++*/
  178. /* build_dirList */
  179. /*+++++++++++++++++++++++++++++++++++++++*/
  180. char **
  181. build_dirList(char * dirStr,
  182. int * count)
  183. {
  184. char tokenSep[] = ":";
  185. char * token;
  186. char ** dirList = NULL;
  187. int i = 0;
  188. char * tmpStr;
  189. int len = strlen(dirStr);
  190. *count = 0;
  191. tmpStr = (char *)XtCalloc(1, len + 1);
  192. strcpy(tmpStr, dirStr);
  193. token = strtok(tmpStr, tokenSep);
  194. while(token != NULL)
  195. {
  196. ++(i);
  197. token = strtok(NULL, tokenSep);
  198. }
  199. if (i == 0)
  200. return (NULL);
  201. dirList = (char **) XtCalloc(1, i * sizeof(char *));
  202. if( dirList )
  203. {
  204. strcpy(tmpStr, dirStr);
  205. token = strtok(tmpStr, tokenSep);
  206. *count=0;
  207. while(token != NULL)
  208. {
  209. dirList[*count] = (char *) XtCalloc(1, strlen( token ) + 1);
  210. strcpy(dirList[*count], token);
  211. token = strtok(NULL, tokenSep);
  212. ++(*count);
  213. }
  214. }
  215. XtFree ((char *) tmpStr);
  216. return(dirList);
  217. }
  218. /*+++++++++++++++++++++++++++++++++++++++*/
  219. /* free_dirList */
  220. /*+++++++++++++++++++++++++++++++++++++++*/
  221. void
  222. free_dirList(char ** dirList,
  223. int count)
  224. {
  225. int i;
  226. if (dirList == NULL)
  227. return;
  228. for (i=0; i<count; i++)
  229. XtFree((char *) dirList[i]);
  230. XtFree ((char *) dirList);
  231. }
  232. /************************************************************************
  233. * SelectCurrentBackdrop() - Selects current backdrop in list
  234. *
  235. ************************************************************************/
  236. void SelectCurrentBackdrop(int callback)
  237. {
  238. DtWsmWorkspaceInfo *wInfo=NULL;
  239. Atom aWS;
  240. Widget list;
  241. char *backdropName;
  242. int i;
  243. if ((DtWsmGetCurrentWorkspace (style.display, style.root, &aWS)
  244. != Success) ||
  245. (DtWsmGetWorkspaceInfo (style.display, style.root, aWS, &wInfo)
  246. != Success))
  247. {
  248. return;
  249. }
  250. list = XtNameToWidget(style.backdropDialog, "*bitmapList");
  251. backdropName = XmGetAtomName(style.display, wInfo->backdropName);
  252. for (i = 0; i < backdrops.numBitmaps; i++) {
  253. if (strcmp(backdrops.bitmapNames[i], backdropName) == 0) {
  254. XmListSelectPos (list, i + 1, callback);
  255. XmListSetPos(list, i + 1);
  256. backdrops.selected = i;
  257. }
  258. }
  259. switch(wInfo->imageType) {
  260. #if defined(USE_XRENDER)
  261. case DtWSM_BACKDROP_IMAGETYPE_FILL:
  262. XmToggleButtonGadgetSetState(backdrops.fillTG, True, False);
  263. break;
  264. case DtWSM_BACKDROP_IMAGETYPE_FIT:
  265. XmToggleButtonGadgetSetState(backdrops.fitTG, True, False);
  266. break;
  267. #endif /* USE_XRENDER */
  268. case DtWSM_BACKDROP_IMAGETYPE_CENTER:
  269. XmToggleButtonGadgetSetState(backdrops.centeredTG, True, False);
  270. break;
  271. case DtWSM_BACKDROP_IMAGETYPE_TILED:
  272. default:
  273. XmToggleButtonGadgetSetState(backdrops.tiledTG, True, False);
  274. break;
  275. }
  276. XtFree((char *) backdropName);
  277. XtFree((char *) wInfo);
  278. }
  279. /************************************************************************
  280. * BackdropDialog() - Create backdrop selection dialog first time up.
  281. * If it has already been created, map it.
  282. ************************************************************************/
  283. void
  284. BackdropDialog(
  285. Widget parent )
  286. {
  287. int i;
  288. if (style.backdropDialog == NULL)
  289. {
  290. _DtTurnOnHourGlass(parent);
  291. if (!CreateBackdropDialog(parent)) {
  292. _DtTurnOffHourGlass(parent);
  293. return;
  294. }
  295. SelectCurrentBackdrop(False);
  296. XtManageChild(style.backdropDialog);
  297. XSync(style.display, 0);
  298. XmUpdateDisplay(style.backdropDialog);
  299. _DtTurnOffHourGlass(parent);
  300. }
  301. else
  302. {
  303. SelectCurrentBackdrop(True);
  304. XtManageChild(style.backdropDialog);
  305. raiseWindow(XtWindow(XtParent(style.backdropDialog)));
  306. XmUpdateDisplay(style.backdropDialog);
  307. }
  308. }
  309. /************************************************************************
  310. * CreateBackdropDialog()
  311. * Create the Backdrop Dialog
  312. ************************************************************************/
  313. static int
  314. CreateBackdropDialog(
  315. Widget parent )
  316. {
  317. int i, n;
  318. Arg args[20];
  319. Widget mainForm;
  320. Widget list;
  321. XmString strings[NUM_LABELS+1];
  322. XmString *listStrings;
  323. char *bd_desc;
  324. char *lang;
  325. XmString string;
  326. Widget imageStyleForm;
  327. if (backdrops.noBitmaps)
  328. {
  329. ErrDialog (backdrops.errStr, style.shell);
  330. return 0;
  331. }
  332. /* initialize backdrop data */
  333. backdrops.bitmapNames = NULL;
  334. backdrops.bitmaps = NULL;
  335. backdrops.numBitmaps = 0;
  336. backdrops.maxNumBitmaps = 100;
  337. backdrops.selected = -1;
  338. backdrops.gc = NULL;
  339. backdrops.errStr = NULL;
  340. backdrops.shadow = 2;
  341. backdrops.width = 200 - 2*backdrops.shadow;
  342. backdrops.height = 200 - 2*backdrops.shadow;
  343. backdrops.newColors = True;
  344. /* load the backdrop description data base for the given locale*/
  345. /* from that locale's description file from the system location */
  346. lang = setlocale (LC_CTYPE,NULL);
  347. bd_desc = (char *)XtMalloc(strlen("/usr/dt/backdrops/desc.") + strlen(lang) + 1);
  348. strcpy (bd_desc,"/usr/dt/backdrops/desc.");
  349. strcat (bd_desc, lang);
  350. if(sys_bd_DB = XrmGetFileDatabase (bd_desc))
  351. XrmMergeDatabases(sys_bd_DB, &bd_DB);
  352. XtFree(bd_desc);
  353. /* load the backdrop description data base for the given locale*/
  354. /* from that locale's description file from the admin location */
  355. bd_desc = (char *)XtMalloc(strlen("/etc/dt/backdrops/desc.") + strlen(lang) + 1);
  356. strcpy (bd_desc,"/etc/dt/backdrops/desc.");
  357. strcat (bd_desc, lang);
  358. if (adm_bd_DB = XrmGetFileDatabase (bd_desc))
  359. XrmMergeDatabases(adm_bd_DB, &bd_DB);
  360. XtFree(bd_desc);
  361. /* load the backdrop description from the user's .dt/backdrops directory */
  362. /* regardless of locale */
  363. bd_desc = (char *)XtMalloc(strlen(style.home) + strlen("/.dt/backdrops/desc.backdrops") + 1);
  364. strcpy (bd_desc, style.home);
  365. strcat (bd_desc, "/.dt/backdrops/desc.backdrops");
  366. if (hm_bd_DB = XrmGetFileDatabase (bd_desc))
  367. XrmMergeDatabases(hm_bd_DB, &bd_DB);
  368. XtFree(bd_desc);
  369. /* Set up DialogBox button labels. */
  370. strings[0] = XmStringCreateLocalized ((String) _DtOkString);
  371. strings[1] = XmStringCreateLocalized ((String) _DtApplyString);
  372. strings[2] = XmStringCreateLocalized ((String) _DtCloseString);
  373. strings[3] = XmStringCreateLocalized ((String) _DtHelpString);
  374. /* saveRestore
  375. * Note that save.poscnt has been initialized elsewhere.
  376. * save.posArgs may contain information from restoreBackdrop().*/
  377. /* create the dialog box with shell */
  378. XtSetArg (save.posArgs[save.poscnt], XmNbuttonCount, NUM_LABELS+1);
  379. save.poscnt++;
  380. XtSetArg (save.posArgs[save.poscnt], XmNbuttonLabelStrings, strings);
  381. save.poscnt++;
  382. XtSetArg (save.posArgs[save.poscnt], XmNdefaultPosition, False);
  383. save.poscnt++;
  384. XtSetArg (save.posArgs[save.poscnt], XmNallowOverlap, False);
  385. save.poscnt++;
  386. style.backdropDialog = __DtCreateDialogBoxDialog (parent, BACKDROPSDLG,
  387. save.posArgs, save.poscnt);
  388. XtAddCallback(style.backdropDialog, XmNcallback, ButtonCB, NULL);
  389. XtAddCallback(style.backdropDialog, XmNmapCallback, _DtMapCB, parent);
  390. XtAddCallback(style.backdropDialog, XmNhelpCallback,
  391. (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_BACKDROP_DIALOG);
  392. /* free compound strings now */
  393. XmStringFree (strings[0]);
  394. XmStringFree (strings[1]);
  395. XmStringFree (strings[2]);
  396. XmStringFree (strings[3]);
  397. n = 0;
  398. XtSetArg (args[n], XmNtitle, ((char *)GETMESSAGE(11, 12, "Style Manager - Backdrop"))); n++;
  399. XtSetArg (args[n], XmNuseAsyncGeometry, True); n++;
  400. XtSetValues (XtParent(style.backdropDialog), args, n);
  401. /* get bitmap data */
  402. if (!ReadBitmaps()) return 0; /* uses style.backdropDialog */
  403. /* create the form to go in to dialog box as the work area */
  404. n = 0;
  405. XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
  406. XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
  407. XtSetArg (args[n], XmNchildType, XmWORK_AREA); n++;
  408. XtSetArg (args[n], XmNallowOverlap, False); n++;
  409. mainForm = XmCreateForm (style.backdropDialog, "backdropsForm", args, n);
  410. n = 0;
  411. string = CMPSTR((char *)GETMESSAGE(11, 13, "Backdrop Style"));
  412. XtSetArg (args[n], XmNtitleString, string); n++;
  413. XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  414. XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  415. XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  416. backdrops.imageStyleTB
  417. = _DtCreateTitleBox(mainForm, "imageStyleTB", args, n);
  418. XmStringFree(string);
  419. n = 0;
  420. XtSetArg(args[n], XmNallowOverlap, False); n++;
  421. XtSetArg(args[n], XmNchildType, XmWORK_AREA); n++;
  422. imageStyleForm =
  423. XmCreateForm(backdrops.imageStyleTB, "imageStyleForm", args, n);
  424. n = 0;
  425. XtSetArg(args[n], XmNmarginWidth, 0); n++;
  426. XtSetArg(args[n], XmNmarginHeight, 0); n++;
  427. backdrops.imageTypeRC =
  428. XmCreateRadioBox(imageStyleForm, "imageTypeRC", args, n);
  429. n = 0;
  430. string = CMPSTR((char *)GETMESSAGE(11, 14, "Tiled"));
  431. XtSetArg(args[n], XmNlabelString, string); n++;
  432. backdrops.tiledTG =
  433. XmCreateToggleButtonGadget(backdrops.imageTypeRC, "tiledTG", args, n);
  434. XmStringFree(string);
  435. n = 0;
  436. string = CMPSTR((char *)GETMESSAGE(11, 15, "Center"));
  437. XtSetArg(args[n], XmNlabelString, string); n++;
  438. backdrops.centeredTG =
  439. XmCreateToggleButtonGadget(backdrops.imageTypeRC, "centeredTG", args, n);
  440. XmStringFree(string);
  441. #if defined(USE_XRENDER)
  442. n = 0;
  443. string = CMPSTR((char *)GETMESSAGE(11, 16, "Fit"));
  444. XtSetArg(args[n], XmNlabelString, string); n++;
  445. backdrops.fitTG =
  446. XmCreateToggleButtonGadget(backdrops.imageTypeRC, "fitTG", args, n);
  447. XmStringFree(string);
  448. n = 0;
  449. string = CMPSTR((char *)GETMESSAGE(11, 17, "Fill"));
  450. XtSetArg(args[n], XmNlabelString, string); n++;
  451. backdrops.fillTG =
  452. XmCreateToggleButtonGadget(backdrops.imageTypeRC, "fillTG", args, n);
  453. XmStringFree(string);
  454. #endif /* USE_XRENDER */
  455. /* create the scrolled list of bitmap names... first create XmStrings */
  456. listStrings = MakeListStrings ();
  457. n = 0;
  458. XtSetArg (args[n], XmNautomaticSelection, True); n++;
  459. XtSetArg (args[n], XmNselectionPolicy, XmBROWSE_SELECT); n++;
  460. XtSetArg (args[n], XmNitems, listStrings); n++;
  461. XtSetArg (args[n], XmNitemCount, backdrops.numBitmaps); n++;
  462. list = XmCreateScrolledList (mainForm, "bitmapList", args, n);
  463. XtAddCallback (list, XmNbrowseSelectionCallback, ListCB, (XtPointer)NULL);
  464. FreeListStrings (listStrings); /* after list has copied */
  465. /* set up attachments for scrolled list itself */
  466. n = 0;
  467. XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  468. XtSetArg (args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
  469. XtSetArg (args[n], XmNrightWidget, backdrops.imageStyleTB); n++;
  470. XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  471. XtSetValues (XtParent(list), args, n);
  472. /* Create drawing area for the bitmap */
  473. n = 0;
  474. XtSetArg (args[n], XmNshadowType, XmSHADOW_IN); n++;
  475. XtSetArg (args[n], XmNshadowThickness, backdrops.shadow); n++;
  476. XtSetArg (args[n], XmNhighlightThickness, 0); n++;
  477. XtSetArg (args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
  478. XtSetArg (args[n], XmNrightWidget, XtParent(list)); n++;
  479. XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  480. XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  481. XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  482. XtSetArg (args[n], XmNborderWidth, 0); n++;
  483. XtSetArg (args[n], XmNwidth, backdrops.width+2*backdrops.shadow); n++;
  484. XtSetArg (args[n], XmNheight, backdrops.height+2*backdrops.shadow); n++;
  485. XtSetArg (args[n], XmNtraversalOn, False); n++;
  486. backdrops.drawnButton = XmCreateDrawnButton (mainForm, "bitmap", args, n);
  487. XtAddCallback (backdrops.drawnButton, XmNexposeCallback, DrawBitmap, NULL);
  488. XtAddCallback (backdrops.drawnButton, XmNresizeCallback, SizeBitmap, NULL);
  489. /* manage all of the widgets */
  490. XtManageChild (mainForm);
  491. XtManageChild (backdrops.drawnButton);
  492. XtManageChild (list);
  493. XtManageChild(backdrops.imageStyleTB);
  494. XtManageChild(imageStyleForm);
  495. XtManageChild(backdrops.imageTypeRC);
  496. XtManageChild(backdrops.tiledTG);
  497. XtManageChild(backdrops.centeredTG);
  498. #if defined(USE_XRENDER)
  499. XtManageChild(backdrops.fitTG);
  500. XtManageChild(backdrops.fillTG);
  501. #endif /* USE_XRENDER */
  502. return 1;
  503. }
  504. /************************************************************************
  505. * MoreBitmaps()
  506. * Create space for more bitmap entries
  507. ************************************************************************/
  508. static void
  509. MoreBitmaps( void )
  510. {
  511. int newSize;
  512. /* allocate space for icon names */
  513. newSize = (backdrops.maxNumBitmaps + 100) * sizeof(char *);
  514. backdrops.bitmapNames = (char **) XtRealloc((char *)backdrops.bitmapNames,
  515. newSize);
  516. /* now allocate new bitmap space */
  517. newSize = (backdrops.maxNumBitmaps + 100) * sizeof(Pixmap);
  518. backdrops.bitmaps = (Pixmap *)XtRealloc((char *)backdrops.bitmaps, newSize);
  519. backdrops.maxNumBitmaps += 100;
  520. }
  521. /************************************************************************
  522. * cmpstringp()
  523. * qsort() sort function, used for sorting bitmap names into alphabetical order
  524. * can't use strcmp() due to char** rather than char*
  525. ************************************************************************/
  526. static int
  527. cmpstringp(const void *p1, const void *p2)
  528. {
  529. return strcmp(*(char * const *) p1, *(char * const *) p2);
  530. }
  531. /************************************************************************
  532. * ReadBitmaps()
  533. * Create an array of bitmaps by reading backdrop directories in the
  534. * following order overriding any duplicates:
  535. * 1) Read the system location /usr/dt/backdrops
  536. * 2) Read the admin location /etc/dt/backdrops
  537. * 3) Read the directories specified by the backdropDirectories
  538. * resource.
  539. * 4) Read the user's home directory /$HOME/.dt/backdrops.
  540. ************************************************************************/
  541. static int
  542. ReadBitmaps( void )
  543. {
  544. int status;
  545. Pixmap tmpPix = 0;
  546. int width, height, x, y;
  547. Window win;
  548. int num;
  549. int i;
  550. char *string;
  551. /* allocate space for temporary bitmap info */
  552. backdrops.tmpBitmapNames = (char **)XtCalloc(100, sizeof(char *));
  553. backdrops.tmpMaxNumBitmaps = 100;
  554. backdrops.tmpNumBitmaps = 0;
  555. /* read system backdrop directory */
  556. ReadBitmapDirectory("/usr/dt/backdrops");
  557. /* read sys admin backdrop directory */
  558. ReadBitmapDirectory("/etc/dt/backdrops");
  559. /* Parse the backdropDirectories resource to get the individual directories */
  560. if (style.xrdb.backdropDir)
  561. {
  562. backdrops.dirList = build_dirList(style.xrdb.backdropDir, &backdrops.dirCount);
  563. /* compile the list of bitmaps */
  564. for (i=0; i<backdrops.dirCount; i++)
  565. ReadBitmapDirectory(backdrops.dirList[i]);
  566. }
  567. /* read the directory $HOME/.dt/backdrops */
  568. string = (char *)XtMalloc(strlen(style.home) + strlen("/.dt/backdrops") + 1);
  569. if (string != NULL)
  570. {
  571. sprintf(string, "%s/.dt/backdrops", style.home);
  572. ReadBitmapDirectory(string);
  573. XtFree(string);
  574. }
  575. if (backdrops.tmpNumBitmaps == 0)
  576. {
  577. /* give error dialog, free space, and return */
  578. backdrops.errStr = (char *)XtMalloc(strlen(ERR2) + 1);
  579. sprintf(backdrops.errStr, "%s", ERR2);
  580. ErrDialog (backdrops.errStr, style.shell);
  581. FreeAll();
  582. free_dirList(backdrops.dirList, backdrops.dirCount);
  583. return 0;
  584. }
  585. /* Sort the list into alphanetical order */
  586. qsort(backdrops.tmpBitmapNames, backdrops.tmpNumBitmaps, sizeof(char *), cmpstringp);
  587. /* get the fg/bg colors from Dtwm */
  588. if (backdrops.newColors)
  589. {
  590. GetColors();
  591. backdrops.newColors = False;
  592. }
  593. /* create all the pixmaps */
  594. if (!CreatePixmaps())
  595. {
  596. /* give error dialog, free space, and return */
  597. backdrops.errStr = (char *)XtMalloc(strlen(ERR2) + 1);
  598. sprintf(backdrops.errStr, "%s", ERR2);
  599. ErrDialog (backdrops.errStr, style.shell);
  600. FreeAll();
  601. free_dirList(backdrops.dirList, backdrops.dirCount);
  602. return 0;
  603. }
  604. if (backdrops.selected == -1) backdrops.selected = 0;
  605. return 1;
  606. }
  607. /************************************************************************
  608. * CreatePixmaps()
  609. * Create the pixmpas in the backdrop list
  610. with workprocs 10 at a time
  611. ************************************************************************/
  612. static Boolean
  613. CreatePixmaps( void )
  614. {
  615. static int pixmapsCreated=0;
  616. int i;
  617. Pixmap tmpPixmap;
  618. backdrops.numBitmaps = 0;
  619. /* allocate space for real bitmap info */
  620. backdrops.bitmapNames = (char **)XtCalloc(100, sizeof(char *));
  621. backdrops.bitmaps = (Pixmap *)XtCalloc(100, sizeof(Pixmap));
  622. for (i=0; i<backdrops.tmpNumBitmaps; i++)
  623. {
  624. tmpPixmap = XmGetPixmap (style.screen,
  625. backdrops.tmpBitmapNames[i],
  626. backdrops.fg, backdrops.bg);
  627. if (tmpPixmap != XmUNSPECIFIED_PIXMAP)
  628. {
  629. if (backdrops.numBitmaps == backdrops.maxNumBitmaps)
  630. MoreBitmaps();
  631. backdrops.bitmapNames[backdrops.numBitmaps] =
  632. backdrops.tmpBitmapNames[i];
  633. backdrops.bitmaps[backdrops.numBitmaps] = tmpPixmap;
  634. backdrops.numBitmaps++;
  635. }
  636. }
  637. if (backdrops.numBitmaps)
  638. return(True);
  639. else
  640. return(False);
  641. }
  642. /************************************************************************
  643. * ReadBitmapDirectory()
  644. * Create an array of bitmap names overriding duplicates
  645. ************************************************************************/
  646. static int
  647. ReadBitmapDirectory(
  648. char *dir )
  649. {
  650. DIR *dirp;
  651. struct dirent *filep;
  652. int i;
  653. Boolean duplicate;
  654. char *name;
  655. int stat_result;
  656. struct stat stat_buf;
  657. char *statPath, *pStatPath;
  658. int newSize;
  659. /* open the backdrops directory */
  660. if ((dirp = opendir(dir)) == NULL)
  661. {
  662. /* print message to errorlog, free space, and return */
  663. return 0;
  664. }
  665. /* create string to contain complete path */
  666. statPath = (char *) XtMalloc(strlen(dir) + MAX_STR_LEN + 2);
  667. strcpy (statPath, dir);
  668. strcat (statPath, "/");
  669. pStatPath = statPath + strlen(statPath);
  670. filep = readdir(dirp);
  671. while (filep != NULL)
  672. {
  673. /* append filename to stat path */
  674. strcpy (pStatPath, filep->d_name);
  675. /* stat the file */
  676. if ((stat_result = stat (statPath, &stat_buf)) != 0)
  677. {
  678. filep = readdir(dirp);
  679. continue;
  680. }
  681. /* skip directories */
  682. if ((stat_buf.st_mode & S_IFMT) == S_IFDIR)
  683. {
  684. filep = readdir(dirp);
  685. continue;
  686. }
  687. name = (char *) XtMalloc(strlen(filep->d_name) + 1);
  688. strcpy (name, filep->d_name);
  689. /* strip suffix off filename if it's a .pm or .bm
  690. * motif requires other formats like jpg, png etc to
  691. * have the extension on to work with the XmGetPixmap() calls */
  692. if(strlen(name) > 3
  693. && (0 == strcmp(name + strlen(name) - 3, ".pm")
  694. || 0 == strcmp(name + strlen(name) - 3, ".bm")))
  695. {
  696. (void)strtok(name, ".");
  697. }
  698. /* check for duplicates */
  699. duplicate = 0;
  700. for (i=0; i<backdrops.tmpNumBitmaps; i++)
  701. {
  702. if (!strcmp(backdrops.tmpBitmapNames[i], name))
  703. {
  704. duplicate = 1;
  705. break;
  706. }
  707. }
  708. if (!duplicate)
  709. {
  710. /* add to the temporary bitmap list */
  711. if (backdrops.tmpNumBitmaps == backdrops.tmpMaxNumBitmaps)
  712. {
  713. /* allocate space for more temporary bitmap info */
  714. newSize = (backdrops.tmpMaxNumBitmaps + 100) * sizeof(char *);
  715. backdrops.tmpBitmapNames =
  716. (char **)XtRealloc((char *)backdrops.tmpBitmapNames, newSize);
  717. backdrops.tmpMaxNumBitmaps += 100;
  718. }
  719. backdrops.tmpBitmapNames[backdrops.tmpNumBitmaps] =
  720. (char *) XtMalloc(strlen(name)+1);
  721. strcpy (backdrops.tmpBitmapNames[backdrops.tmpNumBitmaps], name);
  722. backdrops.tmpNumBitmaps++;
  723. }
  724. filep = readdir(dirp);
  725. XtFree(name);
  726. }
  727. XtFree(statPath);
  728. closedir (dirp);
  729. return 1;
  730. }
  731. /************************************************************************
  732. * DrawBitmap()
  733. * This is the exposeCallback for the bitmap drawing area.
  734. ************************************************************************/
  735. static void
  736. DrawBitmap(
  737. Widget w,
  738. XtPointer client_data,
  739. XtPointer call_data )
  740. {
  741. XGCValues gcValues;
  742. Arg args[3];
  743. if (backdrops.selected == -1)
  744. return;
  745. if (backdrops.newColors)
  746. {
  747. GetColors();
  748. /* we could keep track of which tile pixmaps need to be updated
  749. since the last workspace change, but for now simply regenerate
  750. each pixmap as it is selected after a workspace change has
  751. occurred */
  752. /* backdrops.newColors = False; */
  753. }
  754. if (backdrops.gc == NULL)
  755. {
  756. gcValues.background = backdrops.bg;
  757. gcValues.foreground = backdrops.fg;
  758. gcValues.fill_style = FillTiled;
  759. gcValues.tile = backdrops.bitmaps[backdrops.selected];
  760. backdrops.gc = XCreateGC (style.display, XtWindow(w),
  761. GCForeground | GCBackground |
  762. GCTile | GCFillStyle, &gcValues);
  763. }
  764. XFillRectangle (style.display, XtWindow(w), backdrops.gc, backdrops.shadow,
  765. backdrops.shadow, backdrops.width, backdrops.height);
  766. }
  767. /************************************************************************
  768. * SizeBitmap()
  769. * This is the resizeCallback for the bitmap drawing area.
  770. ************************************************************************/
  771. static void
  772. SizeBitmap(
  773. Widget w,
  774. XtPointer client_data,
  775. XtPointer call_data )
  776. {
  777. backdrops.width = XtWidth(w) - 2*backdrops.shadow;
  778. backdrops.height = XtHeight(w) - 2*backdrops.shadow;
  779. }
  780. /************************************************************************
  781. * MakeListStrings()
  782. * Make XmStrings from the bitmap descriptions, to pass into list.
  783. *
  784. ************************************************************************/
  785. static XmString *
  786. MakeListStrings( void )
  787. {
  788. int i;
  789. XmString *list;
  790. char *name_str;
  791. char *class_str;
  792. char *str_type_return;
  793. XrmValue value_return;
  794. /* allocate space for bitmap descriptions */
  795. backdrops.bitmapDescs = (char **)XtCalloc(backdrops.numBitmaps, sizeof(char *));
  796. for (i=0; i<backdrops.numBitmaps; i++)
  797. {
  798. if (bd_DB !=NULL)
  799. {
  800. name_str = (char *) XtMalloc(strlen("backdrops.") +
  801. strlen(backdrops.bitmapNames[i]) +
  802. strlen(".desc") + 1);
  803. class_str = (char *) XtMalloc(strlen("Backdrops.") +
  804. strlen(backdrops.bitmapNames[i]) +
  805. strlen(".Desc") + 1);
  806. strcpy(name_str, "backdrops.");
  807. strcpy(class_str, "Backdrops.");
  808. strcat(name_str, backdrops.bitmapNames[i]);
  809. strcat(class_str, backdrops.bitmapNames[i]);
  810. strcat(name_str, ".desc");
  811. strcat(class_str, ".Desc");
  812. if (XrmGetResource (bd_DB, name_str, class_str, &str_type_return, &value_return))
  813. {
  814. /* make copy of resource value */
  815. backdrops.bitmapDescs[i] = (char *) XtMalloc(value_return.size + 1);
  816. strcpy (backdrops.bitmapDescs[i], value_return.addr);
  817. }
  818. else
  819. {
  820. backdrops.bitmapDescs[i] = (char *) XtMalloc(strlen(backdrops.bitmapNames[i]) + 1);
  821. strcpy(backdrops.bitmapDescs[i], backdrops.bitmapNames[i]);
  822. }
  823. }
  824. else
  825. {
  826. backdrops.bitmapDescs[i] = (char *) XtMalloc(strlen(backdrops.bitmapNames[i]) + 1);
  827. strcpy(backdrops.bitmapDescs[i], backdrops.bitmapNames[i]);
  828. }
  829. }
  830. list = (XmString *) XtCalloc(backdrops.numBitmaps, sizeof(XmString));
  831. for (i = 0; i < backdrops.numBitmaps; i++)
  832. {
  833. list[i] = XmStringCreateLocalized (backdrops.bitmapDescs[i]);
  834. }
  835. return (list);
  836. }
  837. /************************************************************************
  838. * FreeListStrings()
  839. * Free XmStrings from the bitmap names, passed into list.
  840. ************************************************************************/
  841. static void
  842. FreeListStrings(
  843. XmString *listPtr )
  844. {
  845. int i;
  846. int n;
  847. XmString *list = listPtr;
  848. for (i = 0; i < backdrops.numBitmaps; i++)
  849. {
  850. if (list[i]) XmStringFree(list[i]);
  851. }
  852. XtFree ((char *)list);
  853. }
  854. /************************************************************************
  855. * ListCB()
  856. * Get the bitmap selected from the list
  857. ************************************************************************/
  858. static void
  859. ListCB(
  860. Widget w,
  861. XtPointer client_data,
  862. XtPointer call_data )
  863. {
  864. XmListCallbackStruct *cb = (XmListCallbackStruct *)call_data;
  865. backdrops.selected = cb->item_position - 1;
  866. XSetTile (style.display, backdrops.gc,
  867. backdrops.bitmaps[backdrops.selected]);
  868. DrawBitmap (backdrops.drawnButton, NULL, NULL);
  869. }
  870. /************************************************************************
  871. * ButtonCB()
  872. *
  873. ************************************************************************/
  874. static void
  875. ButtonCB(
  876. Widget w,
  877. XtPointer client_data,
  878. XtPointer call_data )
  879. {
  880. int n, num;
  881. Arg args[MAX_ARGS];
  882. DtWsmBackdropImageType imageType;
  883. DtDialogBoxCallbackStruct *cb = (DtDialogBoxCallbackStruct *) call_data;
  884. #if defined(USE_XRENDER)
  885. if(XmToggleButtonGadgetGetState(backdrops.fillTG)) {
  886. imageType = DtWSM_BACKDROP_IMAGETYPE_FILL;
  887. } else if (XmToggleButtonGadgetGetState(backdrops.fitTG)) {
  888. imageType = DtWSM_BACKDROP_IMAGETYPE_FIT;
  889. } else
  890. #endif /* USE_XRENDER */
  891. if (XmToggleButtonGadgetGetState(backdrops.centeredTG)) {
  892. imageType = DtWSM_BACKDROP_IMAGETYPE_CENTER;
  893. } else {
  894. /* Default to tiled */
  895. imageType = DtWSM_BACKDROP_IMAGETYPE_TILED;
  896. }
  897. switch (cb->button_position)
  898. {
  899. case B_APPLY_BUTTON:
  900. /* send message to update backdrop */
  901. num = backdrops.selected;
  902. _DtWsmChangeBackdrop(style.display, style.root,
  903. backdrops.bitmapNames[num],
  904. backdrops.bitmaps[num],
  905. imageType);
  906. break;
  907. case B_OK_BUTTON:
  908. /* send message to update backdrop */
  909. num = backdrops.selected;
  910. _DtWsmChangeBackdrop(style.display, style.root,
  911. backdrops.bitmapNames[num],
  912. backdrops.bitmaps[num],
  913. imageType);
  914. XtUnmanageChild(w);
  915. break;
  916. case B_CANCEL_BUTTON: /* close */
  917. XtUnmanageChild(w);
  918. break;
  919. case B_HELP_BUTTON:
  920. XtCallCallbacks(style.backdropDialog, XmNhelpCallback, (XtPointer)NULL);
  921. break;
  922. default:
  923. break;
  924. }
  925. }
  926. /************************************************************************
  927. * CheckWorkspace()
  928. * Workspace may have changed, so get current workspace
  929. * colors and draw the backdrop bitmap
  930. *
  931. ************************************************************************/
  932. void
  933. CheckWorkspace( void )
  934. {
  935. backdrops.newColors = True; /* need to get new colors */
  936. if (style.backdropDialog && XtIsManaged(style.backdropDialog))
  937. {
  938. DrawBitmap (backdrops.drawnButton, NULL, NULL);
  939. }
  940. }
  941. /************************************************************************
  942. * GetColors()
  943. * Get current workspace colors, and update GC if needed
  944. *
  945. ************************************************************************/
  946. static void
  947. GetColors( void )
  948. {
  949. DtWsmWorkspaceInfo *wInfo=NULL;
  950. unsigned long num=0;
  951. Pixel fg, bg;
  952. XGCValues gcValues;
  953. Atom aWS;
  954. if ((DtWsmGetCurrentWorkspace (style.display, style.root, &aWS)
  955. == Success) &&
  956. (DtWsmGetWorkspaceInfo (style.display, style.root, aWS, &wInfo)
  957. == Success))
  958. {
  959. backdrops.bg = wInfo->bg;
  960. backdrops.fg = wInfo->fg;
  961. DtWsmFreeWorkspaceInfo (wInfo);
  962. }
  963. else
  964. {
  965. backdrops.bg = 0;
  966. backdrops.fg = 1;
  967. }
  968. if (backdrops.gc) /* update the gc if there is one */
  969. {
  970. gcValues.background = backdrops.bg;
  971. gcValues.foreground = backdrops.fg;
  972. /* free old pixmap */
  973. XmDestroyPixmap(style.screen,
  974. backdrops.bitmaps[backdrops.selected]);
  975. /* allocate new pixmap */
  976. backdrops.bitmaps[backdrops.selected] =
  977. XmGetPixmap (style.screen,
  978. backdrops.bitmapNames[backdrops.selected],
  979. backdrops.fg, backdrops.bg);
  980. gcValues.tile = backdrops.bitmaps[backdrops.selected];
  981. XChangeGC (style.display, backdrops.gc,
  982. GCForeground | GCBackground | GCTile, &gcValues);
  983. }
  984. }
  985. /************************************************************************
  986. * FreeAll()
  987. * Free some space that was allocated for backdrops
  988. ************************************************************************/
  989. static void
  990. FreeAll( void )
  991. {
  992. int i;
  993. /* set no bitmaps flag, so we won't try to get them next time */
  994. backdrops.noBitmaps = 1;
  995. /* free temporary list of backdrop names */
  996. for (i = 0; i < backdrops.tmpNumBitmaps; i++)
  997. if (backdrops.tmpBitmapNames[i])
  998. XtFree(backdrops.tmpBitmapNames[i]);
  999. XtFree ((char *)backdrops.tmpBitmapNames);
  1000. XtFree ((char *)backdrops.bitmapNames);
  1001. /* free backdrop bitmaps */
  1002. for (i = 0; i < backdrops.numBitmaps; i++) {
  1003. if (backdrops.bitmaps[i])
  1004. XFreePixmap (style.display, backdrops.bitmaps[i]);
  1005. if (backdrops.numBitmaps)
  1006. XtFree((char *)backdrops.bitmaps);
  1007. }
  1008. /* destory widgets (via first parent) */
  1009. XtDestroyWidget (XtParent(style.backdropDialog));
  1010. style.backdropDialog = NULL;
  1011. }
  1012. /************************************************************************
  1013. * _DtMapCB
  1014. *
  1015. ************************************************************************/
  1016. static void
  1017. _DtMapCB(
  1018. Widget w,
  1019. XtPointer client_data,
  1020. XtPointer call_data )
  1021. {
  1022. DtWsmRemoveWorkspaceFunctions(style.display, XtWindow(XtParent(w)));
  1023. if (!save.restoreFlag)
  1024. putDialog((Widget)client_data, w);
  1025. XtRemoveCallback(style.backdropDialog, XmNmapCallback, _DtMapCB, NULL);
  1026. }
  1027. /************************************************************************
  1028. * restoreBackdrop()
  1029. *
  1030. * restore any state information saved with saveBackdrop.
  1031. * This is called from restoreSession with the application
  1032. * shell and the special xrm database retrieved for restore.
  1033. ************************************************************************/
  1034. void
  1035. restoreBackdrop(
  1036. Widget shell,
  1037. XrmDatabase db )
  1038. {
  1039. XrmName xrm_name[5];
  1040. XrmRepresentation rep_type;
  1041. XrmValue value;
  1042. xrm_name [0] = XrmStringToQuark (BACKDROPSDLG);
  1043. xrm_name [2] = 0;
  1044. /* get x position */
  1045. xrm_name [1] = XrmStringToQuark ("x");
  1046. if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
  1047. XtSetArg (save.posArgs[save.poscnt], XmNx, atoi((char *)value.addr));
  1048. save.poscnt++;
  1049. save.restoreFlag = True;
  1050. }
  1051. /* get y position */
  1052. xrm_name [1] = XrmStringToQuark ("y");
  1053. if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
  1054. XtSetArg (save.posArgs[save.poscnt], XmNy, atoi((char *)value.addr));
  1055. save.poscnt++;
  1056. }
  1057. /* get width */
  1058. xrm_name [1] = XrmStringToQuark ("width");
  1059. if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
  1060. XtSetArg(save.posArgs[save.poscnt], XmNwidth, atoi((char *)value.addr));
  1061. save.poscnt++;
  1062. }
  1063. /* get height */
  1064. xrm_name [1] = XrmStringToQuark ("height");
  1065. if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)) {
  1066. XtSetArg(save.posArgs[save.poscnt],XmNheight, atoi((char *)value.addr));
  1067. save.poscnt++;
  1068. }
  1069. xrm_name [1] = XrmStringToQuark ("ismapped");
  1070. XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
  1071. /* Are we supposed to be mapped? */
  1072. if (strcmp(value.addr, "True") == 0)
  1073. BackdropDialog(shell);
  1074. }
  1075. /************************************************************************
  1076. * saveBackdrop()
  1077. *
  1078. * This routine will write out to the passed file descriptor any state
  1079. * information this dialog needs. It is called from saveSessionCB with the
  1080. * file already opened.
  1081. * All information is saved in xrm format. There is no restriction
  1082. * on what can be saved. It doesn't have to be defined or be part of any
  1083. * widget or Xt definition. Just name and save it here and recover it in
  1084. * restoreBackdrop. The suggested minimum is whether you are mapped, and your
  1085. * location.
  1086. ************************************************************************/
  1087. void
  1088. saveBackdrop(
  1089. int fd )
  1090. {
  1091. Position x,y;
  1092. Dimension width, height;
  1093. char bufr[1024]; /* size=[1024], make bigger if needed */
  1094. XmVendorShellExtObject vendorExt;
  1095. XmWidgetExtData extData;
  1096. if (style.backdropDialog != NULL)
  1097. {
  1098. if (XtIsManaged(style.backdropDialog))
  1099. sprintf(bufr, "*backdropsDialog.ismapped: True\n");
  1100. else
  1101. sprintf(bufr, "*backdropsDialog.ismapped: False\n");
  1102. WRITE_STR2FD(fd, bufr);
  1103. /* Get and write out the geometry info for our Window */
  1104. x = XtX (XtParent(style.backdropDialog));
  1105. y = XtY (XtParent(style.backdropDialog));
  1106. width = XtWidth (style.backdropDialog);
  1107. height = XtHeight (style.backdropDialog);
  1108. /* Modify x & y to take into account window mgr frames
  1109. * This is pretty bogus, but I don't know a better way to do it.
  1110. */
  1111. extData = _XmGetWidgetExtData(style.shell, XmSHELL_EXTENSION);
  1112. vendorExt = (XmVendorShellExtObject)extData->widget;
  1113. x -= vendorExt->vendor.xOffset;
  1114. y -= vendorExt->vendor.yOffset;
  1115. snprintf(bufr, sizeof(bufr), "*backdropsDialog.x: %d\n", x);
  1116. WRITE_STR2FD(fd, bufr);
  1117. snprintf(bufr, sizeof(bufr), "*backdropsDialog.y: %d\n", y);
  1118. WRITE_STR2FD(fd, bufr);
  1119. snprintf(bufr, sizeof(bufr), "*backdropsDialog.width: %d\n", width);
  1120. WRITE_STR2FD(fd, bufr);
  1121. snprintf(bufr, sizeof(bufr), "*backdropsDialog.height: %d\n", height);
  1122. WRITE_STR2FD(fd, bufr);
  1123. snprintf(bufr, sizeof(bufr), "*backdropsDialog.selectedItemNum: %d\n",
  1124. backdrops.selected);
  1125. WRITE_STR2FD(fd, bufr);
  1126. snprintf(bufr, sizeof(bufr), "*backdropsDialog.selectedItem: %s\n",
  1127. backdrops.bitmapNames[backdrops.selected]);
  1128. WRITE_STR2FD(fd, bufr);
  1129. }
  1130. }