PageRenderTime 27ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/R-2.10.1-patched/src/gnuwin32/preferences.c

http://r4jvm.googlecode.com/
C | 889 lines | 744 code | 102 blank | 43 comment | 179 complexity | 723854292db37efb9fd06f79c8435323 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.0, LGPL-3.0, BSD-3-Clause, AGPL-3.0, GPL-2.0, LGPL-2.1
  1. /*
  2. * R : A Computer Language for Statistical Data Analysis
  3. * file preferences.c
  4. * Copyright (C) 2000 Guido Masarotto and Brian Ripley
  5. * 2004-8 R Core Development Team
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, a copy is available at
  19. * http://www.r-project.org/Licenses/
  20. */
  21. #ifdef HAVE_CONFIG_H
  22. #include <config.h>
  23. #endif
  24. #include "win-nls.h"
  25. #ifdef Win32
  26. #define USE_MDI 1
  27. #endif
  28. #define WIN32_LEAN_AND_MEAN 1
  29. #include <windows.h>
  30. #include <ctype.h> /* isspace */
  31. #include "graphapp/ga.h"
  32. #include "graphapp/graphapp.h"
  33. #include "opt.h"
  34. #include "console.h"
  35. #include "consolestructs.h"
  36. #include "rui.h"
  37. #include "preferences.h"
  38. #include <Fileio.h>
  39. void R_fixbackslash(char *s);
  40. #define gettext GA_gettext
  41. extern char fontname[LF_FACESIZE+4]; /* from console.c */
  42. extern int consolex, consoley; /* from console.c */
  43. extern int pagerMultiple, haveusedapager; /* from pager.c */
  44. void editorsetfont(font f);
  45. static void showDialog(Gui gui);
  46. extern __declspec(dllimport) const char *ColorName[]; /* from graphapp/rgb.c */
  47. static int cmatch(const char *col, const char **list)
  48. {
  49. int i=0;
  50. const char **pos = list;
  51. while(*pos != NULL) {
  52. if(strcmpi(*pos, col) == 0) return(i);
  53. i++; pos++;
  54. }
  55. return(-1);
  56. }
  57. static const char *StyleList[] = {"normal", "bold", "italic", NULL};
  58. static const char *PointsList[] = {"6", "7", "8", "9", "10", "11", "12", "14", "16", "18", "20", "22", "24", "26", "28", "32", "36", NULL};
  59. static const char *FontsList[] = {"Courier", "Courier New", "FixedSys", "FixedFont", "Lucida Console", "Consolas", "Terminal", "BatangChe", "DotumChe", "GulimChe", "MingLiU", "MS Gothic", "MS Mincho", "NSimSun", NULL};
  60. static const char *GuiElementNames[numGuiColors+1] = {"background", "normaltext", "usertext",
  61. "pagerbg", "pagertext", "highlight",
  62. "dataeditbg", "dataedittext", "dataedituser",
  63. "editorbg", "editortext", NULL};
  64. static window wconfig;
  65. static button bApply, bSave, bLoad, bOK, bCancel;
  66. static label l_mdi, l_mwin, l_font, l_point, l_style, l_lang, l_crows, l_ccols,
  67. l_cx, l_cy, l_prows, l_pcols, l_grx, l_gry,
  68. l_cols, l_cbb, l_cbl;
  69. static radiogroup g_mwin;
  70. static radiobutton rb_mdi, rb_sdi, rb_mwin, rb_swin;
  71. static listbox f_font, f_style, d_point, guielement, guicolor;
  72. static checkbox toolbar, statusbar, tt_font, c_resize, c_buff;
  73. static field f_crows, f_ccols, f_prows, f_pcols, f_cx, f_cy, f_cbb,f_cbl,
  74. f_grx, f_gry, f_lang;
  75. static textbox guisample;
  76. static font samplefont = NULL;
  77. static int samplePointsize = 10;
  78. static int sampleStyle = Plain;
  79. static int sampleFontNum;
  80. static rgb dialogColors[numGuiColors];
  81. static void getChoices(Gui p)
  82. {
  83. p->MDI = ischecked(rb_mdi);
  84. p->toolbar = ischecked(toolbar);
  85. p->statusbar = ischecked(statusbar);
  86. p->pagerMultiple = ischecked(rb_mwin);
  87. strcpy(p->language, gettext(f_lang));
  88. strcpy(p->font, gettext(f_font));
  89. p->tt_font = ischecked(tt_font);
  90. p->pointsize = atoi(gettext(d_point));
  91. strcpy(p->style, gettext(f_style));
  92. p->crows = atoi(gettext(f_crows));
  93. p->ccols = atoi(gettext(f_ccols));
  94. p->cx = atoi(gettext(f_cx));
  95. p->cy = atoi(gettext(f_cy));
  96. p->setWidthOnResize = ischecked(c_resize);
  97. p->buffered = ischecked(c_buff);
  98. p->cbb = atoi(gettext(f_cbb));
  99. p->cbl = atoi(gettext(f_cbl));
  100. p->prows = atoi(gettext(f_prows));
  101. p->pcols = atoi(gettext(f_pcols));
  102. p->grx = atoi(gettext(f_grx));
  103. p->gry = atoi(gettext(f_gry));
  104. dialogColors[cmatch(gettext(guielement),GuiElementNames)] = nametorgb(gettext(guicolor));
  105. for (int i=0; i<numGuiColors; i++)
  106. p->guiColors[i] = dialogColors[i];
  107. /* MDIsize is not currently a choice in the dialog, only in the Rconsole file */
  108. }
  109. void getDefaults(Gui gui)
  110. {
  111. gui->crows = 25;
  112. gui->ccols = 80;
  113. gui->cx = gui->cy = 0;
  114. gui->grx = Rwin_graphicsx;
  115. gui->gry = Rwin_graphicsy;
  116. gui->guiColors[consolebg] = White;
  117. gui->guiColors[consolefg] = DarkBlue;
  118. gui->guiColors[consoleuser] = gaRed;
  119. gui->guiColors[pagerbg] = White;
  120. gui->guiColors[pagerfg] = DarkBlue;
  121. gui->guiColors[pagerhighlight] = DarkRed;
  122. gui->guiColors[dataeditbg] = White;
  123. gui->guiColors[dataeditfg] = DarkBlue;
  124. gui->guiColors[dataedituser] = gaRed;
  125. gui->guiColors[editorbg] = White;
  126. gui->guiColors[editorfg] = Black;
  127. gui->prows = 25;
  128. gui->pcols = 80;
  129. gui->pagerMultiple = 0;
  130. gui->cbb = 65000;
  131. gui->cbl = 8000;
  132. gui->setWidthOnResize = 1;
  133. strcpy(gui->font, "Courier New");
  134. strcpy(gui->style, "normal");
  135. gui->tt_font = 1;
  136. gui->pointsize = 10;
  137. strcpy(gui->language, "");
  138. gui->buffered = 1;
  139. #ifdef USE_MDI
  140. gui->toolbar = ((RguiMDI & RW_TOOLBAR) != 0);
  141. gui->statusbar = ((RguiMDI & RW_STATUSBAR) != 0);
  142. gui->MDI = ((RguiMDI & RW_MDI) != 0);
  143. gui->MDIsize = rect(0, 0, 0, 0);
  144. #endif
  145. }
  146. void getActive(Gui gui)
  147. {
  148. rect r;
  149. ConsoleData p;
  150. if (RConsole && (p = (ConsoleData) getdata(RConsole))) {
  151. gui->toolbar = ((RguiMDI & RW_TOOLBAR) != 0);
  152. gui->statusbar = ((RguiMDI & RW_STATUSBAR) != 0);
  153. gui->MDI = ((RguiMDI & RW_MDI) != 0);
  154. gui->pagerMultiple = pagerMultiple;
  155. {
  156. const char *p = getenv("LANGUAGE");
  157. strcpy(gui->language, p ? p : "");
  158. }
  159. /* Font, pointsize, style */
  160. gui->tt_font = FALSE;
  161. {
  162. const char *pf;
  163. if ((strlen(fontname) > 1) &&
  164. (fontname[0] == 'T') && (fontname[1] == 'T')) {
  165. gui->tt_font = TRUE;
  166. for (pf = fontname+2; isspace(*pf) ; pf++);
  167. } else pf = fontname;
  168. strcpy(gui->font, pf);
  169. }
  170. gui->pointsize = pointsize;
  171. if (fontsty & Italic) strcpy(gui->style, "italic");
  172. else if (fontsty & Bold) strcpy(gui->style, "Bold");
  173. else strcpy(gui->style, "normal");
  174. /* Console size, set widthonresize */
  175. gui->crows = ROWS;
  176. gui->ccols = COLS;
  177. r = GetCurrentWinPos(RConsole);
  178. gui->cx = r.x;
  179. gui->cy = r.y;
  180. gui->setWidthOnResize = setWidthOnResize;
  181. gui->cbb = p->lbuf->dim;
  182. gui->cbl = p->lbuf->ms;
  183. gui->buffered = consolebuffered;
  184. /* Pager size */
  185. gui->prows = pagerrow;
  186. gui->pcols = pagercol;
  187. /* Graphics window */
  188. gui->grx = Rwin_graphicsx;
  189. gui->gry = Rwin_graphicsy;
  190. /* Font colours */
  191. for (int i=0; i<numGuiColors; i++)
  192. gui->guiColors[i] = guiColors[i];
  193. /* MDIsize is not currently a choice in the dialog, only in the Rconsole file, so is not set here */
  194. } else
  195. getDefaults(gui);
  196. }
  197. static int has_changed(Gui a, Gui b)
  198. {
  199. Rboolean colorchange = FALSE;
  200. if (a)
  201. for (int i=0; i<numGuiColors; i++)
  202. colorchange |= a->guiColors[i] != b->guiColors[i];
  203. return !a || colorchange ||
  204. a->MDI != b->MDI ||
  205. a->toolbar != b->toolbar ||
  206. a->statusbar != b->statusbar ||
  207. a->pagerMultiple != b->pagerMultiple ||
  208. strcmp(a->language, b->language) ||
  209. strcmp(a->font, b->font) ||
  210. a->tt_font != b->tt_font ||
  211. a->pointsize != b->pointsize ||
  212. strcmp(a->style, b->style) ||
  213. a->crows != b->crows ||
  214. a->ccols != b->ccols ||
  215. a->cx != b->cx ||
  216. a->cy != b->cy ||
  217. a->cbb != b->cbb ||
  218. a->cbl != b->cbl ||
  219. a->setWidthOnResize != b->setWidthOnResize ||
  220. a->prows != b->prows ||
  221. a->pcols != b->pcols ||
  222. a->grx != b->grx ||
  223. a->gry != b->gry ;
  224. }
  225. static void cleanup(void)
  226. {
  227. hide(wconfig);
  228. delobj(l_mdi); delobj(rb_mdi); delobj(rb_sdi);
  229. delobj(toolbar); delobj(statusbar);
  230. delobj(l_mwin); delobj(g_mwin); delobj(rb_mwin); delobj(rb_swin);
  231. delobj(l_lang); delobj(f_lang);
  232. delobj(l_font); delobj(f_font); delobj(tt_font);
  233. delobj(l_point); delobj(d_point);
  234. delobj(l_style); delobj(f_style);
  235. delobj(l_crows); delobj(f_crows); delobj(l_ccols); delobj(f_ccols);
  236. delobj(c_resize); delobj(c_buff);
  237. delobj(l_cx); delobj(f_cx); delobj(l_cy); delobj(f_cy);
  238. delobj(l_cbb); delobj(f_cbb); delobj(l_cbl); delobj(f_cbl);
  239. delobj(l_prows); delobj(f_prows); delobj(l_pcols); delobj(f_pcols);
  240. delobj(l_grx); delobj(f_grx); delobj(l_gry); delobj(f_gry);
  241. delobj(l_cols);
  242. delobj(guielement); delobj(guicolor); delobj(guisample);
  243. delobj(bApply); delobj(bSave); delobj(bOK); delobj(bCancel);
  244. delobj(wconfig);
  245. }
  246. void applyGUI(Gui newGUI)
  247. {
  248. rect r = getrect(RConsole);
  249. ConsoleData p = (ConsoleData) getdata(RConsole);
  250. int havenewfont = 0;
  251. struct structGUI curGUI;
  252. getActive(&curGUI);
  253. if(!has_changed(&curGUI, newGUI)) return;
  254. if(newGUI->MDI != curGUI.MDI || newGUI->toolbar != curGUI.toolbar ||
  255. newGUI->statusbar != curGUI.statusbar)
  256. askok(G_("The overall console properties cannot be changed\non a running console.\n\nSave the preferences and restart Rgui to apply them.\n"));
  257. if(strcmp(newGUI->language, curGUI.language)) {
  258. char *buf = malloc(50);
  259. askok(G_("The language for menus cannot be changed on a\n running console.\n\nSave the preferences and restart Rgui to apply to menus.\n"));
  260. sprintf(buf, "LANGUAGE=%s", newGUI->language);
  261. putenv(buf);
  262. }
  263. /* Set a new font? */
  264. if(strcmp(newGUI->font, curGUI.font) ||
  265. newGUI->pointsize != curGUI.pointsize ||
  266. strcmp(newGUI->style, curGUI.style))
  267. {
  268. char msg[LF_FACESIZE + 128];
  269. int sty = Plain;
  270. if(newGUI->tt_font) strcpy(fontname, "TT "); else strcpy(fontname, "");
  271. strcat(fontname, newGUI->font);
  272. if (!strcmp(newGUI->style, "bold")) sty = Bold;
  273. if (!strcmp(newGUI->style, "italic")) sty = Italic;
  274. pointsize = newGUI->pointsize;
  275. fontsty = sty;
  276. /* Don't delete font: open pagers may be using it */
  277. if (strcmp(fontname, "FixedFont"))
  278. consolefn = gnewfont(NULL, fontname, fontsty, pointsize, 0.0, 1);
  279. else consolefn = FixedFont;
  280. if (!consolefn) {
  281. sprintf(msg,
  282. G_("Font %s-%d-%d not found.\nUsing system fixed font"),
  283. fontname, fontsty | FixedWidth, pointsize);
  284. R_ShowMessage(msg);
  285. consolefn = FixedFont;
  286. }
  287. /* if (!ghasfixedwidth(consolefn)) {
  288. sprintf(msg,
  289. G_("Font %s-%d-%d has variable width.\nUsing system fixed font"),
  290. fontname, fontsty, pointsize);
  291. R_ShowMessage(msg);
  292. consolefn = FixedFont;
  293. } */
  294. p->f = consolefn;
  295. FH = fontheight(p->f);
  296. FW = fontwidth(p->f);
  297. havenewfont = 1;
  298. }
  299. /* resize console, possibly with new font */
  300. if (consoler != newGUI->crows || consolec != newGUI->ccols || havenewfont) {
  301. char buf[20];
  302. consoler = newGUI->crows;
  303. consolec = newGUI->ccols;
  304. r.width = (consolec + 1) * FW;
  305. r.height = (consoler + 1) * FH;
  306. resize(RConsole, r);
  307. sprintf(buf, "%d", ROWS); settext(f_crows, buf);
  308. sprintf(buf, "%d", COLS); settext(f_ccols, buf);
  309. }
  310. if (p->lbuf->dim != newGUI->cbb || p->lbuf->ms != newGUI->cbl)
  311. xbufgrow(p->lbuf, newGUI->cbb, newGUI->cbl);
  312. /* Set colours and redraw */
  313. for (int i=0; i<numGuiColors; i++)
  314. p->guiColors[i] = guiColors[i] = newGUI->guiColors[i];
  315. drawconsole(RConsole, r);
  316. if(haveusedapager &&
  317. (newGUI->prows != curGUI.prows || newGUI->pcols != curGUI.pcols))
  318. askok(G_("Changes in pager size will not apply to any open pagers"));
  319. pagerrow = newGUI->prows;
  320. pagercol = newGUI->pcols;
  321. if(newGUI->pagerMultiple != pagerMultiple) {
  322. if(!haveusedapager ||
  323. askokcancel(G_("Do not change pager type if any pager is open\nProceed?"))
  324. == YES)
  325. pagerMultiple = newGUI->pagerMultiple;
  326. if(pagerMultiple) {
  327. check(rb_mwin); uncheck(rb_swin);
  328. } else {check(rb_swin); uncheck(rb_mwin);}
  329. }
  330. setWidthOnResize = newGUI->setWidthOnResize;
  331. consolebuffered = newGUI->buffered;
  332. Rwin_graphicsx = newGUI->grx;
  333. Rwin_graphicsy = newGUI->gry;
  334. }
  335. static void do_apply(void)
  336. {
  337. struct structGUI newGUI;
  338. getChoices(&newGUI);
  339. applyGUI(&newGUI);
  340. }
  341. static void save(button b)
  342. {
  343. char *file, buf[256], *p;
  344. FILE *fp;
  345. setuserfilter("All files (*.*)\0*.*\0\0");
  346. strcpy(buf, getenv("R_USER"));
  347. R_fixbackslash(buf);
  348. file = askfilesavewithdir(G_("Select directory for file 'Rconsole'"),
  349. "Rconsole", buf);
  350. if(!file) return;
  351. strcpy(buf, file);
  352. p = buf + strlen(buf) - 2;
  353. if(!strncmp(p, ".*", 2)) *p = '\0';
  354. fp = R_fopen(buf, "w");
  355. if(fp == NULL) {
  356. MessageBox(0, "Cannot open file to fp",
  357. "Configuration Save Error",
  358. MB_TASKMODAL | MB_ICONSTOP | MB_OK);
  359. return;
  360. }
  361. fprintf(fp, "%s\n%s\n%s\n\n%s\n%s\n",
  362. "# Optional parameters for the console and the pager",
  363. "# The system-wide copy is in rwxxxx/etc.",
  364. "# A user copy can be installed in `R_USER'.",
  365. "## Style",
  366. "# This can be `yes' (for MDI) or `no' (for SDI).");
  367. fprintf(fp, "MDI = %s\n", ischecked(rb_mdi)?"yes":"no");
  368. fprintf(fp, "%s\n%s%s\n%s%s\n\n",
  369. "# the next two are only relevant for MDI",
  370. "toolbar = ", ischecked(toolbar)?"yes":"no",
  371. "statusbar = ", ischecked(statusbar)?"yes":"no");
  372. fprintf(fp, "%s\n%s\n%s\n%s\n%s\n",
  373. "## Font.",
  374. "# Please use only fixed width font.",
  375. "# If font=FixedFont the system fixed font is used; in this case",
  376. "# points and style are ignored. If font begins with \"TT \", only",
  377. "# True Type fonts are searched for.");
  378. fprintf(fp, "font = %s%s\npoints = %s\nstyle = %s # Style can be normal, bold, italic\n\n\n",
  379. ischecked(tt_font)?"TT ":"",
  380. gettext(f_font),
  381. gettext(d_point),
  382. gettext(f_style));
  383. fprintf(fp, "# Dimensions (in characters) of the console.\n");
  384. fprintf(fp, "rows = %s\ncolumns = %s\n",
  385. gettext(f_crows), gettext(f_ccols));
  386. fprintf(fp, "# Dimensions (in characters) of the internal pager.\n");
  387. fprintf(fp, "pgrows = %s\npgcolumns = %s\n",
  388. gettext(f_prows), gettext(f_pcols));
  389. fprintf(fp, "# should options(width=) be set to the console width?\n");
  390. fprintf(fp, "setwidthonresize = %s\n\n",
  391. ischecked(c_resize) ? "yes" : "no");
  392. fprintf(fp, "# memory limits for the console scrolling buffer, in chars and lines\n");
  393. fprintf(fp, "bufbytes = %s\nbuflines = %s\n\n",
  394. gettext(f_cbb), gettext(f_cbl));
  395. fprintf(fp, "# Initial position of the console (pixels, relative to the workspace for MDI)\n");
  396. fprintf(fp, "xconsole = %s\nyconsole = %s\n\n",
  397. gettext(f_cx), gettext(f_cy));
  398. fprintf(fp, "%s\n%s\n%s\n%s\n%s\n%s\n\n",
  399. "# Dimension of MDI frame in pixels",
  400. "# Format (w*h+xorg+yorg) or use -ve w and h for offsets from right bottom",
  401. "# This will come up maximized if w==0",
  402. "# MDIsize = 0*0+0+0",
  403. "# MDIsize = 1000*800+100+0",
  404. "# MDIsize = -50*-50+50+50 # 50 pixels space all round");
  405. fprintf(fp, "%s\n%s\n%s\npagerstyle = %s\n\n\n",
  406. "# The internal pager can displays help in a single window",
  407. "# or in multiple windows (one for each topic)",
  408. "# pagerstyle can be set to `singlewindow' or `multiplewindows'",
  409. ischecked(rb_mwin) ? "multiplewindows" : "singlewindow");
  410. fprintf(fp, "## Colours for console and pager(s)\n# (see rwxxxx/etc/rgb.txt for the known colours).\n");
  411. for (int i=0; i<numGuiColors; i++)
  412. fprintf(fp, "%s = %s\n", GuiElementNames[i], rgbtoname(dialogColors[i]));
  413. fprintf(fp, "\n\n%s\n%s\nxgraphics = %s\nygraphics = %s\n",
  414. "## Initial position of the graphics window",
  415. "## (pixels, <0 values from opposite edge)",
  416. gettext(f_grx), gettext(f_gry));
  417. fprintf(fp, "\n\n%s\nlanguage = %s\n",
  418. "## Language for messages",
  419. gettext(f_lang));
  420. fprintf(fp, "\n\n## Default setting for console buffering: 'yes' or 'no'\n");
  421. fprintf(fp, "buffered = %s\n",
  422. ischecked(c_buff) ? "yes" : "no");
  423. fclose(fp);
  424. }
  425. static void load(button b) /* button callback */
  426. {
  427. char *optf, buf[256];
  428. struct structGUI newGUI;
  429. setuserfilter("All files (*.*)\0*.*\0\0");
  430. strcpy(buf, getenv("R_USER"));
  431. R_fixbackslash(buf);
  432. optf = askfilenamewithdir(G_("Select 'Rconsole' file"), "Rconsole", buf);
  433. if(!optf) return;
  434. getChoices(&newGUI);
  435. if (loadRconsole(&newGUI, optf)) {
  436. cleanup();
  437. showDialog(&newGUI);
  438. }
  439. }
  440. int loadRconsole(Gui gui, const char *optf)
  441. {
  442. int ok, done, cfgerr;
  443. char *opt[2];
  444. if (!optopenfile(optf)) {
  445. return 0; /* this should not happen unless there are permission problems, etc */
  446. }
  447. cfgerr = 0;
  448. while ((ok = optread(opt, '='))) {
  449. done = 0;
  450. if (ok == 2) {
  451. if (!strcmp(opt[0], "font")) {
  452. if(strlen(opt[1]) > 127) opt[1][127] = '\0';
  453. gui->tt_font = FALSE;
  454. {
  455. const char *pf;
  456. if ((strlen(opt[1]) > 1) &&
  457. (opt[1][0] == 'T') && (opt[1][1] == 'T')) {
  458. gui->tt_font = TRUE;
  459. for (pf = opt[1]+2; isspace(*pf) ; pf++);
  460. } else pf = opt[1];
  461. strcpy(gui->font, pf);
  462. }
  463. done = 1;
  464. }
  465. if (!strcmp(opt[0], "points")) {
  466. gui->pointsize = atoi(opt[1]);
  467. done = 1;
  468. }
  469. if (!strcmp(opt[0], "style")) {
  470. strcpy(gui->style, opt[1]);
  471. done = 1;
  472. }
  473. if (!strcmp(opt[0], "rows")) {
  474. gui->crows = atoi(opt[1]);
  475. done = 1;
  476. }
  477. if (!strcmp(opt[0], "columns")) {
  478. gui->ccols = atoi(opt[1]);
  479. done = 1;
  480. }
  481. if (!strcmp(opt[0], "xconsole")) {
  482. gui->cx = atoi(opt[1]);
  483. done = 1;
  484. }
  485. if (!strcmp(opt[0], "yconsole")) {
  486. gui->cy = atoi(opt[1]);
  487. done = 1;
  488. }
  489. if (!strcmp(opt[0], "xgraphics")) {
  490. gui->grx = atoi(opt[1]);
  491. done = 1;
  492. }
  493. if (!strcmp(opt[0], "ygraphics")) {
  494. gui->gry = atoi(opt[1]);
  495. done = 1;
  496. }
  497. if (!strcmp(opt[0], "pgrows")) {
  498. gui->prows = atoi(opt[1]);
  499. done = 1;
  500. }
  501. if (!strcmp(opt[0], "pgcolumns")) {
  502. gui->pcols = atoi(opt[1]);
  503. done = 1;
  504. }
  505. if (!strcmp(opt[0], "pagerstyle")) {
  506. if (!strcmp(opt[1], "singlewindow"))
  507. gui->pagerMultiple = 0;
  508. else
  509. gui->pagerMultiple = 1;
  510. done = 1;
  511. }
  512. if (!strcmp(opt[0], "bufbytes")) {
  513. gui->cbb = atoi(opt[1]);
  514. done = 1;
  515. }
  516. if (!strcmp(opt[0], "buflines")) {
  517. gui->cbl = atoi(opt[1]);
  518. done = 1;
  519. }
  520. #ifdef USE_MDI
  521. if (!strcmp(opt[0], "MDI")) {
  522. if (!strcmp(opt[1], "yes"))
  523. gui->MDI = 1;
  524. else if (!strcmp(opt[1], "no"))
  525. gui->MDI = 0;
  526. done = 1;
  527. }
  528. if (!strcmp(opt[0], "toolbar")) {
  529. if (!strcmp(opt[1], "yes"))
  530. gui->toolbar = 1;
  531. else if (!strcmp(opt[1], "no"))
  532. gui->toolbar = 0;
  533. done = 1;
  534. }
  535. if (!strcmp(opt[0], "statusbar")) {
  536. if (!strcmp(opt[1], "yes"))
  537. gui->statusbar = 1;
  538. else if (!strcmp(opt[1], "no"))
  539. gui->statusbar = 0;
  540. done = 1;
  541. }
  542. if (!strcmp(opt[0], "MDIsize")) { /* wxh+x+y */
  543. int x=0, y=0, w=0, h=0, sign;
  544. char *p = opt[1];
  545. if(*p == '-') {sign = -1; p++;} else sign = +1;
  546. for(w=0; isdigit(*p); p++) w = 10*w + (*p - '0');
  547. w *= sign;
  548. p++;
  549. if(*p == '-') {sign = -1; p++;} else sign = +1;
  550. for(h=0; isdigit(*p); p++) h = 10*h + (*p - '0');
  551. h *= sign;
  552. if(*p == '-') sign = -1; else sign = +1;
  553. p++;
  554. for(x=0; isdigit(*p); p++) x = 10*x + (*p - '0');
  555. x *= sign;
  556. if(*p == '-') sign = -1; else sign = +1;
  557. p++;
  558. for(y=0; isdigit(*p); p++) y = 10*y + (*p - '0');
  559. y *= sign;
  560. gui->MDIsize = rect(x, y, w, h);
  561. done = 1;
  562. }
  563. #endif
  564. for (int i=0; i<numGuiColors; i++)
  565. if (!strcmp(opt[0], GuiElementNames[i])) {
  566. if (!strcmpi(opt[1], "Windows"))
  567. gui->guiColors[i] = myGetSysColor(COLOR_WINDOW);
  568. else gui->guiColors[i] = nametorgb(opt[1]);
  569. if (gui->guiColors[i] != Transparent)
  570. done = 1;
  571. }
  572. if (!strcmp(opt[0], "setwidthonresize")) {
  573. if (!strcmp(opt[1], "yes"))
  574. gui->setWidthOnResize = 1;
  575. else if (!strcmp(opt[1], "no"))
  576. gui->setWidthOnResize = 0;
  577. done = 1;
  578. }
  579. if (!strcmp(opt[0], "language")) {
  580. strcpy(gui->language, opt[1]);
  581. done = 1;
  582. }
  583. if (!strcmp(opt[0], "buffered")) {
  584. if (!strcmp(opt[1], "yes"))
  585. gui->buffered = 1;
  586. else if (!strcmp(opt[1], "no"))
  587. gui->buffered = 0;
  588. done = 1;
  589. }
  590. } else if (ok == 3) { /* opt[1] == "" */
  591. if (!strcmp(opt[0], "language")) {
  592. strcpy(gui->language, opt[1]);
  593. done = 1;
  594. }
  595. }
  596. if (!done) {
  597. char buf[128];
  598. snprintf(buf, 128, G_("Error at line %d of file %s"),
  599. optline(), optfile());
  600. askok(buf);
  601. cfgerr = 1;
  602. }
  603. }
  604. return !cfgerr;
  605. }
  606. static void apply(button b) /* button callback */
  607. {
  608. do_apply(); /* to be used outside button callbacks */
  609. }
  610. static void cancel(button b)
  611. {
  612. cleanup();
  613. show(RConsole);
  614. }
  615. static void ok(button b)
  616. {
  617. do_apply();
  618. cleanup();
  619. show(RConsole);
  620. }
  621. static void cMDI(button b)
  622. {
  623. enable(toolbar);
  624. enable(statusbar);
  625. }
  626. static void cSDI(button b)
  627. {
  628. disable(toolbar);
  629. disable(statusbar);
  630. }
  631. static rgb whichbg[numGuiColors] = { consolebg, consolebg, consolebg,
  632. pagerbg, pagerbg, pagerbg,
  633. dataeditbg, dataeditbg, dataeditbg,
  634. editorbg, editorbg };
  635. static rgb whichfg[numGuiColors] = { consolefg, consolefg, consoleuser,
  636. pagerfg, pagerfg, pagerhighlight,
  637. dataeditfg, dataeditfg, dataedituser,
  638. editorfg, editorfg };
  639. static void clickColor(control c, int argument)
  640. {
  641. int element = cmatch(gettext(guielement), GuiElementNames);
  642. dialogColors[element] = nametorgb(ColorName[argument]);
  643. setforeground(guisample, dialogColors[whichfg[element]]);
  644. setbackground(guisample, dialogColors[whichbg[element]]);
  645. }
  646. static void changeElement(control c, int argument)
  647. {
  648. int newcolor = rgbtonum(dialogColors[argument]);
  649. setlistitem(guicolor, newcolor);
  650. clickColor(guicolor, newcolor);
  651. }
  652. static void changeFont(control c)
  653. {
  654. char fontname[LF_FACESIZE+4];
  655. if (samplefont) delobj(samplefont);
  656. if(ischecked(tt_font)) strcpy(fontname, "TT "); else strcpy(fontname, "");
  657. if (sampleFontNum >= 0) {
  658. strcat(fontname, FontsList[sampleFontNum]);
  659. } else
  660. strcat(fontname, gettext(f_font));
  661. samplefont = gnewfont(NULL, fontname, sampleStyle, samplePointsize, 0.0, 1);
  662. settextfont(guisample, samplefont);
  663. clickColor(c, getlistitem(guicolor));
  664. }
  665. static void scrollFont(scrollbar s, int position)
  666. {
  667. sampleFontNum = position;
  668. changeFont(s);
  669. }
  670. static void scrollPoints(scrollbar s, int position)
  671. {
  672. samplePointsize = atoi(PointsList[position]);
  673. changeFont(s);
  674. }
  675. static void scrollStyle(scrollbar s, int position)
  676. {
  677. sampleStyle = Plain;
  678. if (!strcmp(gettext(f_style), "bold")) sampleStyle = Bold;
  679. if (!strcmp(gettext(f_style), "italic")) sampleStyle = Italic;
  680. changeFont(s);
  681. }
  682. static void showDialog(Gui gui)
  683. {
  684. char buf[100];
  685. wconfig = newwindow(G_("Rgui Configuration Editor"), rect(0, 0, 550, 450),
  686. Titlebar | Centered | Modal);
  687. setbackground(wconfig, dialog_bg());
  688. l_mdi = newlabel("Single or multiple windows",
  689. rect(10, 10, 140, 20), AlignLeft);
  690. rb_mdi = newradiobutton("MDI", rect(150, 10 , 70, 20), cMDI);
  691. rb_sdi = newradiobutton("SDI", rect(220, 10 , 70, 20), cSDI);
  692. toolbar = newcheckbox("MDI toolbar", rect(300, 10, 100, 20), NULL);
  693. if(gui->toolbar) check(toolbar);
  694. statusbar = newcheckbox("MDI statusbar", rect(420, 10, 130, 20), NULL);
  695. if(gui->statusbar) check(statusbar);
  696. if(gui->MDI) {
  697. check(rb_mdi); cMDI(rb_mdi);
  698. } else {
  699. check(rb_sdi); cSDI(rb_sdi);
  700. }
  701. l_mwin = newlabel("Pager style", rect(10, 40, 90, 20), AlignLeft);
  702. g_mwin = newradiogroup();
  703. rb_mwin = newradiobutton("multiple windows", rect(150, 40, 150, 20), NULL);
  704. rb_swin = newradiobutton("single window", rect(150, 60 , 150, 20), NULL);
  705. if(gui->pagerMultiple) check(rb_mwin); else check(rb_swin);
  706. l_lang = newlabel("Language for menus\nand messages",
  707. rect(320, 40, 130, 40), AlignLeft);
  708. f_lang = newfield(gui->language, rect(450, 45, 60, 20));
  709. /* Font, pointsize, style */
  710. l_font = newlabel("Font", rect(10, 100, 40, 20), AlignLeft);
  711. f_font = newdropfield(FontsList, rect(50, 100, 120, 20), scrollFont);
  712. tt_font = newcheckbox("TrueType only", rect(180, 100, 110, 20), changeFont);
  713. if (gui->tt_font) check(tt_font);
  714. settext(f_font, gui->font);
  715. l_point = newlabel("size", rect(310, 100, 30, 20), AlignLeft);
  716. d_point = newdropfield(PointsList, rect(345, 100, 50, 20), scrollPoints);
  717. sprintf(buf, "%d", gui->pointsize);
  718. settext(d_point, buf);
  719. l_style = newlabel("style", rect(410, 100, 40, 20), AlignLeft);
  720. f_style = newdroplist(StyleList, rect(450, 100, 80, 20), scrollStyle);
  721. setlistitem(f_style, cmatch(gui->style, StyleList));
  722. /* Console size, set widthonresize */
  723. l_crows = newlabel("Console rows", rect(10, 150, 100, 20), AlignLeft);
  724. sprintf(buf, "%d", gui->crows);
  725. f_crows = newfield(buf, rect(110, 150, 30, 20));
  726. l_ccols = newlabel("columns", rect(150, 150, 60, 20), AlignLeft);
  727. sprintf(buf, "%d", gui->ccols);
  728. f_ccols = newfield(buf, rect(220, 150, 30, 20));
  729. l_cx = newlabel("Initial left", rect(270, 150, 70, 20), AlignLeft);
  730. sprintf(buf, "%d", gui->cx);
  731. f_cx = newfield(buf, rect(350, 150, 40, 20));
  732. l_cy = newlabel("top", rect(430, 150, 30, 20), AlignLeft);
  733. sprintf(buf, "%d", gui->cy);
  734. f_cy = newfield(buf, rect(480, 150, 40, 20));
  735. c_resize = newcheckbox("set options(width) on resize?",
  736. rect(20, 175, 200, 20), NULL);
  737. if(gui->setWidthOnResize) check(c_resize);
  738. l_cbb = newlabel("buffer chars", rect(270, 175, 70, 20), AlignLeft);
  739. sprintf(buf, "%d", gui->cbb);
  740. f_cbb = newfield(buf, rect(350, 175, 60, 20));
  741. l_cbl = newlabel("lines", rect(430, 175, 50, 20), AlignLeft);
  742. sprintf(buf, "%d", gui->cbl);
  743. f_cbl = newfield(buf, rect(480, 175, 40, 20));
  744. c_buff = newcheckbox("buffer console by default?",
  745. rect(20, 190, 200, 20), NULL);
  746. if(gui->buffered) check(c_buff);
  747. /* Pager size */
  748. l_prows = newlabel("Pager rows", rect(10, 220, 100, 20), AlignLeft);
  749. sprintf(buf, "%d", gui->prows);
  750. f_prows = newfield(buf, rect(110, 220, 30, 20));
  751. l_pcols = newlabel("columns", rect(150, 220, 60, 20), AlignLeft);
  752. sprintf(buf, "%d", gui->pcols);
  753. f_pcols = newfield(buf, rect(220, 220, 30, 20));
  754. /* Graphics window */
  755. l_grx = newlabel("Graphics windows: initial left",
  756. rect(10, 260, 190, 20), AlignLeft);
  757. sprintf(buf, "%d", gui->grx);
  758. f_grx = newfield(buf, rect(200, 260, 40, 20));
  759. l_gry = newlabel("top", rect(270, 260, 30, 20), AlignLeft);
  760. sprintf(buf, "%d", gui->gry);
  761. f_gry = newfield(buf, rect(300, 260, 40, 20));
  762. /* Font colours */
  763. l_cols = newlabel("Console and Pager Colours",
  764. rect(10, 300, 520, 20), AlignCenter);
  765. guielement = newlistbox(GuiElementNames, rect(50, 320, 100, 80), changeElement, NULL);
  766. guicolor = newlistbox(ColorName, rect(205, 320, 100, 80), clickColor, NULL);
  767. guisample = newrichtextarea("Sample text", rect(350, 320, 150, 55));
  768. for (int i=0; i<numGuiColors; i++)
  769. dialogColors[i] = gui->guiColors[i];
  770. setlistitem(guielement, 0);
  771. changeElement(guielement, 0);
  772. sampleFontNum = cmatch(gettext(f_font), FontsList);
  773. samplePointsize = atoi(gettext(d_point));
  774. scrollStyle(f_style, 0); /* the 0 is ignored */
  775. bApply = newbutton("Apply", rect(50, 410, 70, 25), apply);
  776. bSave = newbutton("Save...", rect(130, 410, 70, 25), save);
  777. bLoad = newbutton("Load...", rect(210, 410, 70, 25), load);
  778. bOK = newbutton("OK", rect(350, 410, 70, 25), ok);
  779. bCancel = newbutton("Cancel", rect(430, 410, 70, 25), cancel);
  780. show(wconfig);
  781. }
  782. void Rgui_configure()
  783. {
  784. struct structGUI curGUI;
  785. getActive(&curGUI);
  786. showDialog(&curGUI);
  787. }