Font.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  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. /************************************<+>*************************************
  24. ****************************************************************************
  25. **
  26. ** File: Font.c
  27. **
  28. ** Project: DT 3.0
  29. **
  30. ** Description: Controls the Dtstyle Font dialog
  31. **
  32. **
  33. ** (c) Copyright Hewlett-Packard Company, 1990.
  34. **
  35. **
  36. **
  37. ****************************************************************************
  38. ************************************<+>*************************************/
  39. /* $XConsortium: Font.c /main/7 1996/10/30 11:14:15 drk $ */
  40. /*+++++++++++++++++++++++++++++++++++++++*/
  41. /* include files */
  42. /*+++++++++++++++++++++++++++++++++++++++*/
  43. #include <X11/Xlib.h>
  44. #include <Xm/MwmUtil.h>
  45. #include <Xm/Xm.h>
  46. #include <Xm/XmP.h>
  47. #include <Xm/MessageB.h>
  48. #include <Xm/Form.h>
  49. #include <Xm/Frame.h>
  50. #include <Xm/LabelG.h>
  51. #include <Xm/List.h>
  52. #include <Xm/Scale.h>
  53. #include <Xm/Text.h>
  54. #include <Xm/TextF.h>
  55. #include <Xm/VendorSEP.h>
  56. #include <Dt/DialogBox.h>
  57. #include <Dt/Icon.h>
  58. #include <Dt/TitleBox.h>
  59. #include <Dt/Message.h>
  60. #include <Dt/SessionM.h>
  61. #include <Dt/HourGlass.h>
  62. #include <string.h>
  63. #include <errno.h>
  64. #include "Help.h"
  65. #include "Main.h"
  66. #include "SaveRestore.h"
  67. /*+++++++++++++++++++++++++++++++++++++++*/
  68. /* Local #defines */
  69. /*+++++++++++++++++++++++++++++++++++++++*/
  70. #define FONT_MSG ((char *)GETMESSAGE(5, 23, "Style Manager - Font"))
  71. #define PREVIEW ((char *)GETMESSAGE(5, 17, "Preview"))
  72. #define IMMEDIATE ((char *)GETMESSAGE(5, 18, "The changes to fonts will show up in some\napplications the next time they are started.\nOther applications, such as file manager and\napplication manager, will not show the font\nchanges until you Exit the desktop and then log\nback in."))
  73. #define LATER ((char *)GETMESSAGE(5, 19, "The selected font will be used when\n you restart this session."))
  74. #define INFO_MSG ((char *)GETMESSAGE(5, 24, "The font that is currently used for your desktop is not\navailable in the Size list. If a new font is selected and\napplied, you will not be able to return to the current font\nusing the Style Manager - Font dialog."))
  75. #define SYSTEM_MSG ((char *)GETMESSAGE(5, 20, "AaBbCcDdEeFfGg0123456789"))
  76. #define USER_MSG ((char *)GETMESSAGE(5, 21, "AaBbCcDdEeFfGg0123456789"))
  77. #define BLANK_MSG " "
  78. #define SIZE ((char *)GETMESSAGE(5, 22, "Size"))
  79. /*+++++++++++++++++++++++++++++++++++++++*/
  80. /* Internal Variables */
  81. /*+++++++++++++++++++++++++++++++++++++++*/
  82. typedef struct {
  83. Widget fontWkarea;
  84. Widget fontpictLabel;
  85. Widget previewTB;
  86. Widget previewForm;
  87. Widget systemLabel;
  88. Widget userText;
  89. Widget sizeTB;
  90. Widget sizeList;
  91. int originalFontIndex;
  92. int selectedFontIndex;
  93. String selectedFontStr;
  94. Boolean userTextChanged;
  95. } FontData;
  96. static FontData font;
  97. static saveRestore save = {FALSE, 0, };
  98. /*+++++++++++++++++++++++++++++++++++++++*/
  99. /* Internal Functions */
  100. /*+++++++++++++++++++++++++++++++++++++++*/
  101. static void CreateFontDlg(
  102. Widget parent) ;
  103. static void _DtmapCB_fontBB(
  104. Widget w,
  105. XtPointer client_data,
  106. XtPointer call_data) ;
  107. static void ButtonCB(
  108. Widget w,
  109. XtPointer client_data,
  110. XtPointer call_data) ;
  111. static void changeSampleFontCB(
  112. Widget w,
  113. XtPointer client_data,
  114. XtPointer call_data) ;
  115. static void valueChangedCB(
  116. Widget w,
  117. XtPointer client_data,
  118. XtPointer call_data) ;
  119. /*+++++++++++++++++++++++++++++++++++++++*/
  120. /* popup_fontBB */
  121. /*+++++++++++++++++++++++++++++++++++++++*/
  122. void
  123. popup_fontBB(
  124. Widget shell )
  125. {
  126. if (style.fontDialog == NULL) {
  127. _DtTurnOnHourGlass(shell);
  128. CreateFontDlg(shell);
  129. XtManageChild(style.fontDialog);
  130. _DtTurnOffHourGlass(shell);
  131. } else {
  132. XtManageChild(style.fontDialog);
  133. raiseWindow(XtWindow(XtParent(style.fontDialog)));
  134. }
  135. /* If no font is found to match current Desktop
  136. font, pop up informative message */
  137. if (font.selectedFontIndex < 0)
  138. InfoDialog(INFO_MSG, style.shell, False);
  139. }
  140. /*+++++++++++++++++++++++++++++++++++++++*/
  141. /* CreateFontDlg */
  142. /*+++++++++++++++++++++++++++++++++++++++*/
  143. static void
  144. CreateFontDlg(
  145. Widget parent )
  146. {
  147. int n;
  148. int i;
  149. Arg args[MAX_ARGS];
  150. Widget appTBox;
  151. Widget sizeMenuPlDn;
  152. XmString button_string[NUM_LABELS];
  153. XmString string;
  154. int count = 0;
  155. Widget widget_list[6];
  156. XmString *sizeItems;
  157. XmStringTable selectedSize;
  158. char sizeStr[111];
  159. Dimension fontheight;
  160. font.selectedFontStr = style.xrdb.systemFontStr;
  161. /* Assume nothing is selected */
  162. font.selectedFontIndex = -1;
  163. /*
  164. * The following flag is used to determine if the user has
  165. * entered anything into the sample user font field. If
  166. * he does, than when the font selection is changed, the
  167. * default message "aAbBcC..." won't be displayed overwriting
  168. * the user's text, only the fontlist will be changed.
  169. * This flag will be set in the valueChanged callback for the
  170. * font.sizeList widget.
  171. */
  172. font.userTextChanged = FALSE;
  173. /*
  174. * Look for the selectedFont in the fontChoice array and set
  175. * selectedFontIndex to that entry
  176. */
  177. for (i=0; i<style.xrdb.numFonts; i++)
  178. if (strcmp (font.selectedFontStr,
  179. style.xrdb.fontChoice[i].sysStr) == 0)
  180. {
  181. font.selectedFontIndex = i;
  182. if (!style.xrdb.fontChoice[i].userFont)
  183. GetUserFontResource(i);
  184. if (!style.xrdb.fontChoice[i].sysFont)
  185. GetSysFontResource(i);
  186. break;
  187. }
  188. /*
  189. * Save the index of the originally selected font. If no
  190. * font is selected, this value will remain -1.
  191. */
  192. font.originalFontIndex = font.selectedFontIndex;
  193. /* Set up button labels. */
  194. button_string[0] = CMPSTR((String) _DtOkString);
  195. button_string[1] = CMPSTR((String) _DtCancelString);
  196. button_string[2] = CMPSTR((String) _DtHelpString);
  197. /* Create toplevel DialogBox */
  198. /* saveRestore
  199. * Note that save.poscnt has been initialized elsewhere.
  200. * save.posArgs may contain information from restoreFont().
  201. */
  202. XtSetArg(save.posArgs[save.poscnt], XmNallowOverlap, False); save.poscnt++;
  203. XtSetArg(save.posArgs[save.poscnt], XmNdefaultPosition, False);
  204. save.poscnt++;
  205. XtSetArg(save.posArgs[save.poscnt], XmNbuttonCount, NUM_LABELS);
  206. save.poscnt++;
  207. XtSetArg(save.posArgs[save.poscnt], XmNbuttonLabelStrings, button_string);
  208. save.poscnt++;
  209. style.fontDialog =
  210. __DtCreateDialogBoxDialog(parent, "Fonts", save.posArgs, save.poscnt);
  211. XtAddCallback(style.fontDialog, XmNcallback, ButtonCB, NULL);
  212. XtAddCallback(style.fontDialog, XmNmapCallback, _DtmapCB_fontBB,
  213. (XtPointer)parent);
  214. XtAddCallback(style.fontDialog, XmNhelpCallback,
  215. (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_FONT_DIALOG);
  216. XmStringFree(button_string[0]);
  217. XmStringFree(button_string[1]);
  218. XmStringFree(button_string[2]);
  219. widget_list[0] = _DtDialogBoxGetButton(style.fontDialog,2);
  220. n=0;
  221. XtSetArg(args[n], XmNautoUnmanage, False); n++;
  222. XtSetArg(args[n], XmNcancelButton, widget_list[0]); n++;
  223. XtSetValues (style.fontDialog, args, n);
  224. n=0;
  225. XtSetArg(args[n], XmNtitle, FONT_MSG); n++;
  226. XtSetArg (args[n], XmNuseAsyncGeometry, True); n++;
  227. XtSetArg(args[n], XmNmwmFunctions, DIALOG_MWM_FUNC); n++;
  228. XtSetValues (XtParent(style.fontDialog), args, n);
  229. n = 0;
  230. XtSetArg (args[n], XmNchildType, XmWORK_AREA); n++;
  231. XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
  232. XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
  233. XtSetArg(args[n], XmNallowOverlap, False); n++;
  234. font.fontWkarea = XmCreateForm(style.fontDialog, "fontWorkArea", args, n);
  235. n = 0;
  236. XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  237. XtSetArg(args[n], XmNtopOffset, style.verticalSpacing); n++;
  238. XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  239. XtSetArg(args[n], XmNfillMode, XmFILL_SELF); n++;
  240. XtSetArg(args[n], XmNbehavior, XmICON_LABEL); n++;
  241. XtSetArg(args[n], XmNpixmapForeground, style.secBSCol); n++;
  242. XtSetArg(args[n], XmNpixmapBackground, style.secTSCol); n++;
  243. XtSetArg(args[n], XmNstring, NULL); n++;
  244. XtSetArg(args[n], XmNshadowThickness, 0); n++;
  245. XtSetArg(args[n], XmNimageName, FONT_ICON); n++;
  246. XtSetArg(args[n], XmNtraversalOn, False); n++;
  247. widget_list[count++] = font.fontpictLabel =
  248. _DtCreateIcon(font.fontWkarea, "fontpictLabel", args, n);
  249. /* Create a TitleBox and Scale/List to choose the font size */
  250. n = 0;
  251. string = CMPSTR(SIZE);
  252. XtSetArg(args[n], XmNtitleString, string); n++;
  253. XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  254. XtSetArg(args[n], XmNtopWidget, font.fontpictLabel); n++;
  255. XtSetArg(args[n], XmNtopOffset, style.verticalSpacing+5); n++;
  256. XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  257. XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
  258. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  259. widget_list[count++] = font.sizeTB =
  260. _DtCreateTitleBox(font.fontWkarea, "sizeTB", args, n);
  261. XmStringFree(string);
  262. /* calculate size for each of the fonts based on system font size */
  263. sizeItems = (XmString *) XtMalloc(sizeof(XmString) * style.xrdb.numFonts);
  264. for (n=0; n<style.xrdb.numFonts; n++)
  265. {
  266. sprintf(sizeStr, "%d", (int)(n+1));
  267. sizeItems[n] = CMPSTR(sizeStr);
  268. style.xrdb.fontChoice[n].pointSize = CMPSTR(sizeStr);
  269. }
  270. n=0;
  271. XtSetArg (args[n], XmNselectionPolicy, XmBROWSE_SELECT); n++;
  272. XtSetArg (args[n], XmNautomaticSelection, True); n++;
  273. XtSetArg (args[n], XmNvisibleItemCount, 7); n++;
  274. XtSetArg (args[n], XmNitemCount, style.xrdb.numFonts); n++;
  275. XtSetArg (args[n], XmNitems, sizeItems); n++;
  276. /*
  277. * If matching font was found for current selection,
  278. * display it as selected. Otherwise, don't select
  279. * anything.
  280. */
  281. if (font.selectedFontIndex >=0) {
  282. selectedSize = &(style.xrdb.fontChoice[font.selectedFontIndex].pointSize);
  283. XtSetArg (args[n], XmNselectedItems, selectedSize); n++;
  284. XtSetArg (args[n], XmNselectedItemCount, 1); n++;
  285. }
  286. font.sizeList = XmCreateScrolledList(font.sizeTB,"sizeList",args,n);
  287. XtAddCallback(font.sizeList, XmNbrowseSelectionCallback,
  288. changeSampleFontCB, NULL);
  289. /* If a font match was found and selected, then set it's point size. */
  290. if (font.selectedFontIndex >=0)
  291. XmListSetItem(font.sizeList,
  292. style.xrdb.fontChoice[font.selectedFontIndex].pointSize);
  293. XtFree((char *)sizeItems);
  294. /* preview TitleBox */
  295. n = 0;
  296. XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  297. XtSetArg(args[n], XmNtopWidget, font.fontpictLabel); n++;
  298. XtSetArg(args[n], XmNtopOffset, style.verticalSpacing+5); n++;
  299. XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  300. XtSetArg(args[n], XmNleftWidget, font.sizeTB); n++;
  301. XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  302. XtSetArg(args[n], XmNrightOffset, style.horizontalSpacing); n++;
  303. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  304. XtSetArg(args[n], XmNbottomOffset, style.verticalSpacing); n++;
  305. string = CMPSTR(PREVIEW);
  306. XtSetArg(args[n], XmNtitleString, string); n++;
  307. widget_list[count++] = font.previewTB =
  308. _DtCreateTitleBox(font.fontWkarea, "systemSample", args, n);
  309. XmStringFree(string);
  310. /*form to contain preview font area*/
  311. n = 0;
  312. font.previewForm =
  313. XmCreateForm(font.previewTB, "previewForm", args, n);
  314. /* sample system font */
  315. n = 0;
  316. /*
  317. * If a font match was found and selected, then set the fontlist
  318. * and the sample string. Otherwise, output a blank message.
  319. */
  320. if (font.selectedFontIndex >=0) {
  321. XtSetArg (args[n], XmNfontList,
  322. style.xrdb.fontChoice[font.selectedFontIndex].sysFont); n++;
  323. string = CMPSTR(SYSTEM_MSG);
  324. } else {
  325. string = CMPSTR(BLANK_MSG);
  326. }
  327. XtSetArg (args[n], XmNlabelString, string); n++;
  328. XtSetArg (args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
  329. XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  330. XtSetArg (args[n], XmNtopOffset, 2 * style.verticalSpacing); n++;
  331. XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  332. XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  333. XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  334. font.systemLabel =
  335. XmCreateLabelGadget(font.previewForm, "systemSample", args, n);
  336. XmStringFree(string);
  337. /* sample user font */
  338. n = 0;
  339. /*
  340. * If a font match was found and selected, then set the fontlist
  341. * and the sample string. Otherwise output a blank message.
  342. */
  343. if (font.selectedFontIndex >=0) {
  344. XtSetArg (args[n], XmNfontList,
  345. style.xrdb.fontChoice[font.selectedFontIndex].userFont); n++;
  346. XtSetArg (args[n], XmNvalue, USER_MSG); n++;
  347. } else {
  348. XtSetArg (args[n], XmNvalue, NULL); n++;
  349. }
  350. XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  351. XtSetArg (args[n], XmNtopWidget, font.systemLabel); n++;
  352. XtSetArg (args[n], XmNtopOffset, 2 * style.verticalSpacing); n++;
  353. XtSetArg (args[n], XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  354. XtSetArg (args[n], XmNleftWidget, font.systemLabel); n++;
  355. XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  356. XtSetArg (args[n], XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  357. XtSetArg (args[n], XmNrightWidget, font.systemLabel); n++;
  358. font.userText =
  359. XmCreateText(font.previewForm, "userText", args, n);
  360. /* Add callback to determine if user changes text in sample field */
  361. XtAddCallback(font.userText, XmNvalueChangedCallback, valueChangedCB, NULL);
  362. XtManageChild(font.systemLabel);
  363. XtManageChild(font.userText);
  364. XtManageChild(font.previewForm);
  365. XtManageChild(font.sizeList);
  366. XtManageChildren(widget_list,count);
  367. XtManageChild(font.fontWkarea);
  368. }
  369. /*+++++++++++++++++++++++++++++++++++++++*/
  370. /* _DtmapCB_fontBB */
  371. /*+++++++++++++++++++++++++++++++++++++++*/
  372. static void
  373. _DtmapCB_fontBB(
  374. Widget w,
  375. XtPointer client_data,
  376. XtPointer call_data )
  377. {
  378. DtWsmRemoveWorkspaceFunctions(style.display, XtWindow(XtParent(w)));
  379. if (!save.restoreFlag)
  380. putDialog ((Widget)client_data, w);
  381. XmTextShowPosition(font.userText, 0);
  382. XtRemoveCallback(style.fontDialog, XmNmapCallback, _DtmapCB_fontBB, NULL);
  383. }
  384. /*+++++++++++++++++++++++++++++++++++++++++++++++++*/
  385. /* ButtonCB */
  386. /* Process callback from PushButtons in DialogBox. */
  387. /*+++++++++++++++++++++++++++++++++++++++++++++++++*/
  388. static void
  389. ButtonCB(
  390. Widget w,
  391. XtPointer client_data,
  392. XtPointer call_data )
  393. {
  394. DtDialogBoxCallbackStruct *cb
  395. = (DtDialogBoxCallbackStruct *) call_data;
  396. int n, len;
  397. XtArgVal items;
  398. char *str, *fntstr, *fntsetstr;
  399. Arg args[MAX_ARGS];
  400. char fontres[8192];
  401. switch (cb->button_position)
  402. {
  403. /* Set the xrdb or pass to dtsession and close the window */
  404. case OK_BUTTON:
  405. /*
  406. * Need to test for the case where the Font dialog maps without
  407. * any fonts selected, and the user presses OK. Do this by
  408. * checking for number of items selected before changing
  409. * anything.
  410. */
  411. XtVaGetValues (font.sizeList, XmNselectedItemCount, &items, NULL);
  412. /* Post an info dialog explaining when the new fonts will appear */
  413. if ((font.selectedFontIndex != font.originalFontIndex) && (items > 0))
  414. {
  415. XtUnmanageChild(style.fontDialog);
  416. if(style.xrdb.writeXrdbImmediate)
  417. {
  418. InfoDialog(IMMEDIATE, style.shell, False);
  419. }
  420. else
  421. {
  422. InfoDialog(LATER, style.shell, False);
  423. }
  424. /*
  425. for *FontSet resource: find first font entry delimited by a ":"
  426. or an "=".
  427. */
  428. len =strcspn(style.xrdb.fontChoice[font.selectedFontIndex].userStr,
  429. ":=");
  430. fntsetstr = (char *) XtCalloc(1, len + 1);
  431. memcpy(fntsetstr,
  432. style.xrdb.fontChoice[font.selectedFontIndex].userStr,
  433. len);
  434. /*
  435. Since the *Font and *FontSet resources may be used by old
  436. X applications, a fontlist of multiple fonts must be converted
  437. to Xt font set format (';'s converted to ','s since many old X
  438. apps don't understand ';' syntax.)
  439. */
  440. str = strstr(fntsetstr,";");
  441. while (str) {
  442. *str = ',';
  443. str = strstr(str,";");
  444. }
  445. /*
  446. for *Font resource: find first font entry delimited by a comma,
  447. a colon or an =
  448. */
  449. len = strcspn(fntsetstr,",:=");
  450. fntstr = (char *) XtCalloc(1, len + 1);
  451. memcpy(fntstr,
  452. style.xrdb.fontChoice[font.selectedFontIndex].userStr,
  453. len);
  454. /*
  455. for *FontSet resource: if we got a font (instead of a font set)
  456. from the first entry, then wildcard its charset fields
  457. */
  458. len = strlen(fntsetstr);
  459. if (style.xrdb.fontChoice[font.selectedFontIndex].userStr[len]
  460. != ':') {
  461. str = strchr(fntsetstr, '-');
  462. for (n = 1; n < 13 && str; n++)
  463. str = strchr(str + 1, '-');
  464. if (str)
  465. strcpy(str + 1, "*-*");
  466. }
  467. /* create the font resource specs with the selected font for xrdb */
  468. sprintf(fontres,
  469. "*systemFont: %s\n*userFont: %s\n*FontList: %s\n*buttonFontList: %s\n*labelFontList: %s\n*textFontList: %s\n*XmText*FontList: %s\n*XmTextField*FontList: %s\n*DtEditor*textFontList: %s\n*Font: %s\n*FontSet: %s\n",
  470. style.xrdb.fontChoice[font.selectedFontIndex].sysStr,
  471. style.xrdb.fontChoice[font.selectedFontIndex].userStr,
  472. style.xrdb.fontChoice[font.selectedFontIndex].sysStr,
  473. style.xrdb.fontChoice[font.selectedFontIndex].sysStr,
  474. style.xrdb.fontChoice[font.selectedFontIndex].sysStr,
  475. style.xrdb.fontChoice[font.selectedFontIndex].userStr,
  476. style.xrdb.fontChoice[font.selectedFontIndex].userStr,
  477. style.xrdb.fontChoice[font.selectedFontIndex].userStr,
  478. style.xrdb.fontChoice[font.selectedFontIndex].userStr,
  479. fntstr, fntsetstr);
  480. XtFree(fntstr);
  481. XtFree(fntsetstr);
  482. /* if writeXrdbImmediate true write to Xrdb else send to session mgr */
  483. if(style.xrdb.writeXrdbImmediate)
  484. _DtAddToResource(style.display,fontres);
  485. SmNewFontSettings(fontres);
  486. font.originalFontIndex = font.selectedFontIndex;
  487. style.xrdb.systemFontStr = font.selectedFontStr;
  488. }
  489. else
  490. XtUnmanageChild(style.fontDialog);
  491. break;
  492. case CANCEL_BUTTON:
  493. /* reset preview area fonts to original and close the window*/
  494. XtUnmanageChild(style.fontDialog);
  495. if (font.originalFontIndex >= 0)
  496. XmListSelectPos(font.sizeList, font.originalFontIndex+1, True);
  497. else {
  498. /*
  499. * if no font was originally selected, need to undo any results
  500. * from selections that were made by user before pressing Cancel.
  501. */
  502. XtVaSetValues (font.sizeList, XmNselectedItemCount, 0, NULL);
  503. XtVaSetValues (font.userText,
  504. XmNvalue, BLANK_MSG,
  505. XmNfontList, style.xrdb.userFont,
  506. NULL);
  507. XtVaSetValues (font.systemLabel,
  508. XmNlabelString, CMPSTR(BLANK_MSG),
  509. XmNfontList, style.xrdb.systemFont,
  510. NULL);
  511. font.userTextChanged = FALSE;
  512. font.selectedFontIndex = -1;
  513. }
  514. break;
  515. case HELP_BUTTON:
  516. XtCallCallbacks(style.fontDialog, XmNhelpCallback, (XtPointer)NULL);
  517. break;
  518. default:
  519. break;
  520. }
  521. }
  522. /*+++++++++++++++++++++++++++++++++++++++*/
  523. /* changSampleFontCB */
  524. /* Change the font in the sample areas */
  525. /*+++++++++++++++++++++++++++++++++++++++*/
  526. static void
  527. changeSampleFontCB(
  528. Widget w,
  529. XtPointer client_data,
  530. XtPointer call_data )
  531. {
  532. int n;
  533. int pos;
  534. int hourGlassOn;
  535. Arg args[MAX_ARGS];
  536. XmListCallbackStruct *cb = (XmListCallbackStruct *) call_data;
  537. pos = cb->item_position-1;
  538. font.selectedFontIndex = pos;
  539. font.selectedFontStr = style.xrdb.fontChoice[pos].sysStr;
  540. hourGlassOn = !style.xrdb.fontChoice[pos].userFont ||
  541. !style.xrdb.fontChoice[pos].sysFont;
  542. if (hourGlassOn)
  543. _DtTurnOnHourGlass(style.fontDialog);
  544. if (!style.xrdb.fontChoice[pos].userFont)
  545. GetUserFontResource(pos);
  546. if (!style.xrdb.fontChoice[pos].sysFont)
  547. GetSysFontResource(pos);
  548. if (hourGlassOn)
  549. _DtTurnOffHourGlass(style.fontDialog);
  550. /* Set the sample System Font string to different Font */
  551. n = 0;
  552. XtSetArg(args[n], XmNfontList, style.xrdb.fontChoice[pos].sysFont); n++;
  553. /* string_val = CMPSTR(SYSTEM_MSG);*/
  554. XtSetArg (args[n], XmNlabelString, CMPSTR(SYSTEM_MSG)); n++;
  555. XtSetValues (font.systemLabel, args, n);
  556. /*
  557. * If the user didn't change the text field, output standard user
  558. * text message.
  559. */
  560. n = 0;
  561. if (!font.userTextChanged)
  562. XtSetArg (args[n], XmNvalue, USER_MSG); n++;
  563. XtSetArg(args[n], XmNfontList, style.xrdb.fontChoice[pos].userFont); n++;
  564. XtSetValues (font.userText, args, n);
  565. XmTextShowPosition(font.userText, 0);
  566. }
  567. /*+++++++++++++++++++++++++++++++++++++++*/
  568. /* valueChangedCB */
  569. /* Set flag indicating that the user */
  570. /* text field has been modified. */
  571. /*+++++++++++++++++++++++++++++++++++++++*/
  572. static void
  573. valueChangedCB(
  574. Widget w,
  575. XtPointer client_data,
  576. XtPointer call_data )
  577. {
  578. font.userTextChanged = TRUE;
  579. }
  580. /************************************************************************
  581. * restoreFonts()
  582. *
  583. * restore any state information saved with saveFonts.
  584. * This is called from restoreSession with the application
  585. * shell and the special xrm database retrieved for restore.
  586. ************************************************************************/
  587. void
  588. restoreFonts(
  589. Widget shell,
  590. XrmDatabase db )
  591. {
  592. XrmName xrm_name[5];
  593. XrmRepresentation rep_type;
  594. XrmValue value;
  595. xrm_name [0] = XrmStringToQuark ("Fonts");
  596. xrm_name [2] = 0;
  597. /* get x position */
  598. xrm_name [1] = XrmStringToQuark ("x");
  599. if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
  600. XtSetArg (save.posArgs[save.poscnt], XmNx, atoi((char *)value.addr));
  601. save.poscnt++;
  602. save.restoreFlag = True;
  603. }
  604. /* get y position */
  605. xrm_name [1] = XrmStringToQuark ("y");
  606. if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
  607. XtSetArg (save.posArgs[save.poscnt], XmNy, atoi((char *)value.addr));
  608. save.poscnt++;
  609. }
  610. xrm_name [1] = XrmStringToQuark ("ismapped");
  611. XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
  612. /* Are we supposed to be mapped? */
  613. if (strcmp(value.addr, "True") == 0)
  614. popup_fontBB(shell);
  615. }
  616. /************************************************************************
  617. * saveFonts()
  618. *
  619. * This routine will write out to the passed file descriptor any state
  620. * information this dialog needs. It is called from saveSessionCB with the
  621. * file already opened.
  622. * All information is saved in xrm format. There is no restriction
  623. * on what can be saved. It doesn't have to be defined or be part of any
  624. * widget or Xt definition. Just name and save it here and recover it in
  625. * restoreFonts. The suggested minimum is whether you are mapped, and your
  626. * location.
  627. ************************************************************************/
  628. void
  629. saveFonts(
  630. int fd )
  631. {
  632. Position x,y;
  633. char *bufr = style.tmpBigStr; /* size=[1024], make bigger if needed */
  634. XmVendorShellExtObject vendorExt;
  635. XmWidgetExtData extData;
  636. if (style.fontDialog != NULL) {
  637. if (XtIsManaged(style.fontDialog))
  638. sprintf(bufr, "*Fonts.ismapped: True\n");
  639. else
  640. sprintf(bufr, "*Fonts.ismapped: False\n");
  641. /* Get and write out the geometry info for our Window */
  642. x = XtX(XtParent(style.fontDialog));
  643. y = XtY(XtParent(style.fontDialog));
  644. /* Modify x & y to take into account window mgr frames
  645. * This is pretty bogus, but I don't know a better way to do it.
  646. */
  647. extData = _XmGetWidgetExtData(style.shell, XmSHELL_EXTENSION);
  648. vendorExt = (XmVendorShellExtObject)extData->widget;
  649. x -= vendorExt->vendor.xOffset;
  650. y -= vendorExt->vendor.yOffset;
  651. sprintf(bufr, "%s*Fonts.x: %d\n", bufr, x);
  652. sprintf(bufr, "%s*Fonts.y: %d\n", bufr, y);
  653. if(-1 == write (fd, bufr, strlen(bufr))) {
  654. perror(strerror(errno));
  655. }
  656. }
  657. }