The R Project SVN R

Rev

Rev 82931 | Rev 83454 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 82931 Rev 83436
Line 304... Line 304...
304
{
304
{
305
    SEXP colmodes, tnames, tvec, tvec2, work2;
305
    SEXP colmodes, tnames, tvec, tvec2, work2;
306
    SEXPTYPE type;
306
    SEXPTYPE type;
307
    int i, j, cnt, len, nprotect;
307
    int i, j, cnt, len, nprotect;
308
    RCNTXT cntxt;
308
    RCNTXT cntxt;
309
    char clab[25];
-
 
310
    char *title = "R Data Editor";
309
    char *title = "R Data Editor";
311
    destruct DE1;
310
    destruct DE1;
312
    DEstruct DE = &DE1;
311
    DEstruct DE = &DE1;
313
 
312
 
314
    nprotect = 0;/* count the PROTECT()s */
313
    nprotect = 0;/* count the PROTECT()s */
Line 345... Line 344...
345
 
344
 
346
    if (isNull(tnames)) {
345
    if (isNull(tnames)) {
347
	PROTECT_WITH_INDEX(DE->names = allocVector(STRSXP, DE->xmaxused),
346
	PROTECT_WITH_INDEX(DE->names = allocVector(STRSXP, DE->xmaxused),
348
			   &DE->npi);
347
			   &DE->npi);
349
	for(i = 0; i < DE->xmaxused; i++) {
348
	for(i = 0; i < DE->xmaxused; i++) {
-
 
349
	    char clab[25];
350
	    sprintf(clab, "var%d", i);
350
	    snprintf(clab, 25, "var%d", i);
351
	    SET_STRING_ELT(DE->names, i, mkChar(clab));
351
	    SET_STRING_ELT(DE->names, i, mkChar(clab));
352
	}
352
	}
353
    } else
353
    } else
354
	PROTECT_WITH_INDEX(DE->names = duplicate(tnames), &DE->npi);
354
	PROTECT_WITH_INDEX(DE->names = duplicate(tnames), &DE->npi);
355
    nprotect++;
355
    nprotect++;
Line 872... Line 872...
872
 
872
 
873
    find_coords(DE, row, 0, &src_x, &src_y);
873
    find_coords(DE, row, 0, &src_x, &src_y);
874
    cleararea(DE, src_x, src_y, DE->windowWidth, DE->box_h);
874
    cleararea(DE, src_x, src_y, DE->windowWidth, DE->box_h);
875
    drawrectangle(DE, src_x, src_y, DE->boxw[0], DE->box_h, 1, 1);
875
    drawrectangle(DE, src_x, src_y, DE->boxw[0], DE->box_h, 1, 1);
876
 
876
 
877
    sprintf(rlab, DE->labform, whichrow);
877
    snprintf(rlab, 15, DE->labform, whichrow);
878
    printstring(DE, rlab, (int)strlen(rlab), row, 0, 0);
878
    printstring(DE, rlab, (int)strlen(rlab), row, 0, 0);
879
 
879
 
880
    w = DE->bwidth + DE->boxw[0];
880
    w = DE->bwidth + DE->boxw[0];
881
    for (i = DE->colmin; i <= DE->colmax; i++) {
881
    for (i = DE->colmin; i <= DE->colmax; i++) {
882
	drawrectangle(DE, w, src_y, BOXW(i), DE->box_h, 1, 1);
882
	drawrectangle(DE, w, src_y, BOXW(i), DE->box_h, 1, 1);
Line 1006... Line 1006...
1006
static Rboolean getccol(DEstruct DE)
1006
static Rboolean getccol(DEstruct DE)
1007
{
1007
{
1008
    SEXP tmp, tmp2;
1008
    SEXP tmp, tmp2;
1009
    int i, len, newlen, wcol, wrow;
1009
    int i, len, newlen, wcol, wrow;
1010
    SEXPTYPE type;
1010
    SEXPTYPE type;
1011
    char clab[25];
-
 
1012
    Rboolean newcol = FALSE;
1011
    Rboolean newcol = FALSE;
1013
 
1012
 
1014
    wcol = DE->ccol + DE->colmin - 1;
1013
    wcol = DE->ccol + DE->colmin - 1;
1015
    wrow = DE->crow + DE->rowmin - 1;
1014
    wrow = DE->crow + DE->rowmin - 1;
1016
    if (wcol > DE->xmaxused) {
1015
    if (wcol > DE->xmaxused) {
1017
	/* extend work, names and lens */
1016
	/* extend work, names and lens */
1018
	REPROTECT(DE->work = lengthgets(DE->work, wcol), DE->wpi);
1017
	REPROTECT(DE->work = lengthgets(DE->work, wcol), DE->wpi);
1019
	REPROTECT(DE->names = lengthgets(DE->names, wcol), DE->npi);
1018
	REPROTECT(DE->names = lengthgets(DE->names, wcol), DE->npi);
1020
	for (i = DE->xmaxused; i < wcol; i++) {
1019
	for (i = DE->xmaxused; i < wcol; i++) {
-
 
1020
	    char clab[25];
1021
	    sprintf(clab, "var%d", i + 1);
1021
	    snprintf(clab, 25, "var%d", i + 1);
1022
	    SET_STRING_ELT(DE->names, i, mkChar(clab));
1022
	    SET_STRING_ELT(DE->names, i, mkChar(clab));
1023
	}
1023
	}
1024
	REPROTECT(DE->lens = lengthgets(DE->lens, wcol), DE->lpi);
1024
	REPROTECT(DE->lens = lengthgets(DE->lens, wcol), DE->lpi);
1025
	DE->xmaxused = wcol;
1025
	DE->xmaxused = wcol;
1026
    }
1026
    }
Line 1097... Line 1097...
1097
static void closerect(DEstruct DE)
1097
static void closerect(DEstruct DE)
1098
{
1098
{
1099
    SEXP cvec;
1099
    SEXP cvec;
1100
    int i, wcol = DE->ccol + DE->colmin - 1,
1100
    int i, wcol = DE->ccol + DE->colmin - 1,
1101
	wrow = DE->rowmin + DE->crow - 1, wrow0;
1101
	wrow = DE->rowmin + DE->crow - 1, wrow0;
1102
    char clab[25];
-
 
1103
    Rboolean newcol;
1102
    Rboolean newcol;
1104
 
1103
 
1105
    *bufp = '\0';
1104
    *bufp = '\0';
1106
 
1105
 
1107
    /* first check to see if anything has been entered */
1106
    /* first check to see if anything has been entered */
Line 1113... Line 1112...
1113
		    /* extend work, names and lens */
1112
		    /* extend work, names and lens */
1114
		    REPROTECT(DE->work = lengthgets(DE->work, wcol), DE->wpi);
1113
		    REPROTECT(DE->work = lengthgets(DE->work, wcol), DE->wpi);
1115
		    REPROTECT(DE->names = lengthgets(DE->names, wcol),
1114
		    REPROTECT(DE->names = lengthgets(DE->names, wcol),
1116
			      DE->npi);
1115
			      DE->npi);
1117
		    for (i = DE->xmaxused; i < wcol - 1; i++) {
1116
		    for (i = DE->xmaxused; i < wcol - 1; i++) {
-
 
1117
			char clab[25];
1118
			sprintf(clab, "var%d", i + 1);
1118
			snprintf(clab, 25, "var%d", i + 1);
1119
			SET_STRING_ELT(DE->names, i, mkChar(clab));
1119
			SET_STRING_ELT(DE->names, i, mkChar(clab));
1120
		    }
1120
		    }
1121
		    REPROTECT(DE->lens = lengthgets(DE->lens, wcol), DE->lpi);
1121
		    REPROTECT(DE->lens = lengthgets(DE->lens, wcol), DE->lpi);
1122
		    DE->xmaxused = wcol;
1122
		    DE->xmaxused = wcol;
1123
		}
1123
		}
1124
		SET_STRING_ELT(DE->names, wcol - 1, mkChar(buf));
1124
		SET_STRING_ELT(DE->names, wcol - 1, mkChar(buf));
1125
		printstring(DE ,buf, (int) strlen(buf), 0, wcol, 0);
1125
		printstring(DE ,buf, (int) strlen(buf), 0, wcol, 0);
1126
	    } else {
1126
	    } else {
1127
		sprintf(buf, "var%d", DE->ccol);
1127
		snprintf(buf, BOOSTED_BUF_SIZE, "var%d", DE->ccol);
1128
		printstring(DE ,buf, (int) strlen(buf), 0, wcol, 0);
1128
		printstring(DE, buf, (int) strlen(buf), 0, wcol, 0);
1129
	    }
1129
	    }
1130
	} else {
1130
	} else {
1131
	    newcol = getccol(DE);
1131
	    newcol = getccol(DE);
1132
	    cvec = VECTOR_ELT(DE->work, wcol - 1);
1132
	    cvec = VECTOR_ELT(DE->work, wcol - 1);
1133
	    wrow0 = INTEGER(DE->lens)[wcol - 1];
1133
	    wrow0 = INTEGER(DE->lens)[wcol - 1];
Line 1365... Line 1365...
1365
    bell();
1365
    bell();
1366
}
1366
}
1367
 
1367
 
1368
static void printlabs(DEstruct DE)
1368
static void printlabs(DEstruct DE)
1369
{
1369
{
1370
    char clab[15];
-
 
1371
    const char *p;
1370
    const char *p;
1372
    int i;
1371
    int i;
1373
 
1372
 
1374
    for (i = DE->colmin; i <= DE->colmax; i++) {
1373
    for (i = DE->colmin; i <= DE->colmax; i++) {
1375
	p = get_col_name(DE, i);
1374
	p = get_col_name(DE, i);
1376
	printstring(DE, p, (int) strlen(p), 0, i - DE->colmin + 1, 0);
1375
	printstring(DE, p, (int) strlen(p), 0, i - DE->colmin + 1, 0);
1377
    }
1376
    }
1378
    for (i = DE->rowmin; i <= DE->rowmax; i++) {
1377
    for (i = DE->rowmin; i <= DE->rowmax; i++) {
-
 
1378
	char clab[15];
1379
	sprintf(clab, DE->labform, i);
1379
	snprintf(clab, 15, DE->labform, i);
1380
	printstring(DE, clab, (int) strlen(clab), i - DE->rowmin + 1, 0, 0);
1380
	printstring(DE, clab, (int) strlen(clab), i - DE->rowmin + 1, 0, 0);
1381
    }
1381
    }
1382
}
1382
}
1383
 
1383
 
1384
	       /* ================ X11-specific ================ */
1384
	       /* ================ X11-specific ================ */
Line 1929... Line 1929...
1929
 
1929
 
1930
	/* options("X11fonts")[1] read font name */
1930
	/* options("X11fonts")[1] read font name */
1931
	SEXP opt = GetOption1(install("X11fonts"));
1931
	SEXP opt = GetOption1(install("X11fonts"));
1932
	if(isString(opt)) {
1932
	if(isString(opt)) {
1933
	    const char *s = CHAR(STRING_ELT(opt, 0));
1933
	    const char *s = CHAR(STRING_ELT(opt, 0));
1934
	    sprintf(opt_fontset_name, s, "medium", "r", 12);
1934
	    snprintf(opt_fontset_name, 512, s, "medium", "r", 12);
1935
	} else strcpy(opt_fontset_name, fontset_name);
1935
	} else strcpy(opt_fontset_name, fontset_name);
1936
 
1936
 
1937
	if(font_set == NULL) {
1937
	if(font_set == NULL) {
1938
	    font_set = XCreateFontSet(iodisplay, opt_fontset_name,
1938
	    font_set = XCreateFontSet(iodisplay, opt_fontset_name,
1939
				      &missing_charset_list,
1939
				      &missing_charset_list,
Line 1975... Line 1975...
1975
	DE->text_offset = 2 + DE->font_info->max_bounds.descent;
1975
	DE->text_offset = 2 + DE->font_info->max_bounds.descent;
1976
    }
1976
    }
1977
    DE->windowHeight = 26 * DE->box_h + DE->hht + 2;
1977
    DE->windowHeight = 26 * DE->box_h + DE->hht + 2;
1978
    /* this used to presume 4 chars sufficed for row numbering */
1978
    /* this used to presume 4 chars sufficed for row numbering */
1979
    labdigs = max(3, 1+ (int) floor(log10((double)DE->ymaxused)));
1979
    labdigs = max(3, 1+ (int) floor(log10((double)DE->ymaxused)));
1980
    sprintf(DE->labform, "%%%dd", labdigs);
1980
    snprintf(DE->labform, 15, "%%%dd", labdigs);
1981
    DE->boxw[0] = (int)( 0.1*labdigs*textwidth(DE, "0123456789", 10)) +
1981
    DE->boxw[0] = (int)( 0.1*labdigs*textwidth(DE, "0123456789", 10)) +
1982
	textwidth(DE, " ", 1) + 8;
1982
	textwidth(DE, " ", 1) + 8;
1983
    for(i = 1; i < 100; i++) DE->boxw[i] = get_col_width(DE, i);
1983
    for(i = 1; i < 100; i++) DE->boxw[i] = get_col_width(DE, i);
1984
 
1984
 
1985
    /* try for a window width that covers all the columns, or is around
1985
    /* try for a window width that covers all the columns, or is around
Line 2041... Line 2041...
2041
	XtDestroyApplicationContext(app_con);
2041
	XtDestroyApplicationContext(app_con);
2042
	if (xdev.geometry != NULL) {
2042
	if (xdev.geometry != NULL) {
2043
	    char gstr[40];
2043
	    char gstr[40];
2044
	    int bitmask;
2044
	    int bitmask;
2045
 
2045
 
2046
	    sprintf(gstr, "%dx%d+%d+%d", hint->width,
2046
	    snprintf(gstr, 40, "%dx%d+%d+%d", hint->width,
2047
		    hint->height, hint->x, hint->y);
2047
		     hint->height, hint->x, hint->y);
2048
	    bitmask = XWMGeometry(iodisplay, DefaultScreen(iodisplay),
2048
	    bitmask = XWMGeometry(iodisplay, DefaultScreen(iodisplay),
2049
				  xdev.geometry, gstr,
2049
				  xdev.geometry, gstr,
2050
				  1,
2050
				  1,
2051
				  hint,
2051
				  hint,
2052
				  &hint->x, &hint->y,
2052
				  &hint->x, &hint->y,
Line 2326... Line 2326...
2326
 
2326
 
2327
void popupmenu(DEstruct DE, int x_pos, int y_pos, int col, int row)
2327
void popupmenu(DEstruct DE, int x_pos, int y_pos, int col, int row)
2328
{
2328
{
2329
    int i, button, popupcol = col + DE->colmin - 1;
2329
    int i, button, popupcol = col + DE->colmin - 1;
2330
    const char *name;
2330
    const char *name;
2331
    char clab[20];
-
 
2332
    XEvent event;
2331
    XEvent event;
2333
    Window selected_pane;
2332
    Window selected_pane;
2334
    SEXP tvec;
2333
    SEXP tvec;
2335
 
2334
 
2336
    XMoveWindow(iodisplay, menuwindow, x_pos, y_pos);
2335
    XMoveWindow(iodisplay, menuwindow, x_pos, y_pos);
Line 2342... Line 2341...
2342
    if (popupcol > DE->xmaxused) {
2341
    if (popupcol > DE->xmaxused) {
2343
	/* extend work, names and lens */
2342
	/* extend work, names and lens */
2344
	REPROTECT(DE->work = lengthgets(DE->work, popupcol), DE->wpi);
2343
	REPROTECT(DE->work = lengthgets(DE->work, popupcol), DE->wpi);
2345
	REPROTECT(DE->names = lengthgets(DE->names, popupcol), DE->npi);
2344
	REPROTECT(DE->names = lengthgets(DE->names, popupcol), DE->npi);
2346
	for (i = DE->xmaxused+1; i < popupcol; i++) {
2345
	for (i = DE->xmaxused+1; i < popupcol; i++) {
-
 
2346
	    char clab[20];
2347
	    sprintf(clab, "var%d", i + 1);
2347
	    snprintf(clab, 20, "var%d", i + 1);
2348
	    SET_STRING_ELT(DE->names, i, mkChar(clab));
2348
	    SET_STRING_ELT(DE->names, i, mkChar(clab));
2349
	}
2349
	}
2350
	REPROTECT(DE->lens = lengthgets(DE->lens, popupcol), DE->lpi);
2350
	REPROTECT(DE->lens = lengthgets(DE->lens, popupcol), DE->lpi);
2351
	DE->xmaxused = popupcol;
2351
	DE->xmaxused = popupcol;
2352
    }
2352
    }