The R Project SVN R

Rev

Rev 68956 | Rev 83755 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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