The R Project SVN R

Rev

Rev 83454 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 83454 Rev 87194
Line 1... Line 1...
1
/*
1
/*
2
 *  R : A Computer Language for Statistical Data Analysis
2
 *  R : A Computer Language for Statistical Data Analysis
3
 *  Copyright (C) 1995, 1996  Robert Gentleman and Ross Ihaka
3
 *  Copyright (C) 1995, 1996  Robert Gentleman and Ross Ihaka
4
 *  Copyright (C) 1998--2022  The R Core Team
4
 *  Copyright (C) 1998--2024  The R Core Team
5
 *
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 2 of the License, or
8
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  (at your option) any later version.
9
 *  (at your option) any later version.
Line 156... Line 156...
156
static void doConfigure(DEstruct, DEEvent *ioevent);
156
static void doConfigure(DEstruct, DEEvent *ioevent);
157
static void drawrectangle(DEstruct, int, int, int, int, int, int);
157
static void drawrectangle(DEstruct, int, int, int, int, int, int);
158
static void drawtext(DEstruct, int, int, char*, int);
158
static void drawtext(DEstruct, int, int, char*, int);
159
static void RefreshKeyboardMapping(DEEvent *ioevent);
159
static void RefreshKeyboardMapping(DEEvent *ioevent);
160
static void Rsync(DEstruct);
160
static void Rsync(DEstruct);
161
static int textwidth(DEstruct, const char*, int);
161
static int textwidth(DEstruct, const char*);
162
static int WhichEvent(DEEvent ioevent);
162
static int WhichEvent(DEEvent ioevent);
163
 
163
 
164
static void R_ProcessX11Events(void *data);
164
static void R_ProcessX11Events(void *data);
165
 
165
 
166
 
166
 
Line 591... Line 591...
591
    for (i = DE->colmin; i <= DE->colmax; i++) drawcol(DE, i);
591
    for (i = DE->colmin; i <= DE->colmax; i++) drawcol(DE, i);
592
 
592
 
593
    if(DE->isEditor) {
593
    if(DE->isEditor) {
594
	/* draw the quit etc boxes */
594
	/* draw the quit etc boxes */
595
 
595
 
596
	i = textwidth(DE, "Quit", 4);
596
	i = textwidth(DE, "Quit");
597
	box_coords[0] = st = DE->fullwindowWidth - 6 - DE->bwidth;
597
	box_coords[0] = st = DE->fullwindowWidth - 6 - DE->bwidth;
598
	box_coords[1] = st - i;
598
	box_coords[1] = st - i;
599
	drawrectangle(DE, st - i, 3, i + 4, DE->hht - 6, 1, 1);
599
	drawrectangle(DE, st - i, 3, i + 4, DE->hht - 6, 1, 1);
600
	drawtext(DE, st + 2 - i, DE->hht - 7, "Quit", 4);
600
	drawtext(DE, st + 2 - i, DE->hht - 7, "Quit", 4);
601
 
601
 
602
	box_coords[4] = st = st - 5*i;
602
	box_coords[4] = st = st - 5*i;
603
	i = textwidth(DE, "Paste", 5);
603
	i = textwidth(DE, "Paste");
604
	box_coords[5] = st - i;
604
	box_coords[5] = st - i;
605
	drawrectangle(DE, st - i, 3, i + 4, DE->hht - 6, 1, 1);
605
	drawrectangle(DE, st - i, 3, i + 4, DE->hht - 6, 1, 1);
606
	drawtext(DE, st + 2 - i, DE->hht - 7, "Paste", 5);
606
	drawtext(DE, st + 2 - i, DE->hht - 7, "Paste", 5);
607
 
607
 
608
	box_coords[2] = st = st - 2*i;
608
	box_coords[2] = st = st - 2*i;
609
	i = textwidth(DE, "Copy", 4);
609
	i = textwidth(DE, "Copy");
610
	box_coords[3] = st - i;
610
	box_coords[3] = st - i;
611
	drawrectangle(DE, st - i, 3, i + 4, DE->hht - 6, 1, 1);
611
	drawrectangle(DE, st - i, 3, i + 4, DE->hht - 6, 1, 1);
612
	drawtext(DE, st + 2 - i, DE->hht - 7, "Copy", 4);
612
	drawtext(DE, st + 2 - i, DE->hht - 7, "Copy", 4);
613
    }
613
    }
614
 
614
 
Line 804... Line 804...
804
	/* don't use NA labels */
804
	/* don't use NA labels */
805
	lab = STRING_ELT(DE->names, col - 1);
805
	lab = STRING_ELT(DE->names, col - 1);
806
	if(lab != NA_STRING) strp = CHAR(lab); else strp = "var12";
806
	if(lab != NA_STRING) strp = CHAR(lab); else strp = "var12";
807
	PrintDefaults();
807
	PrintDefaults();
808
 
808
 
809
	w = textwidth(DE, strp, (int) strlen(strp));
809
	w = textwidth(DE, strp);
810
	for (i = 0; i < INTEGER(DE->lens)[col - 1]; i++) {
810
	for (i = 0; i < INTEGER(DE->lens)[col - 1]; i++) {
811
	    strp = EncodeElement(tmp, i, 0, '.');
811
	    strp = EncodeElement(tmp, i, 0, '.');
812
	    w1 = textwidth(DE, strp, (int) strlen(strp));
812
	    w1 = textwidth(DE, strp);
813
	    if (w1 > w) w = w1;
813
	    if (w1 > w) w = w1;
814
	}
814
	}
815
	if(w < 0.5*DE->box_w) w = (int) (0.5*DE->box_w);
815
	if(w < 0.5*DE->box_w) w = (int) (0.5*DE->box_w);
816
	if(w < 0.8*DE->box_w) w+= (int) (0.1*DE->box_w);
816
	if(w < 0.8*DE->box_w) w+= (int) (0.1*DE->box_w);
817
	if(w > 600) w = 600;
817
	if(w > 600) w = 600;
Line 1214... Line 1214...
1214
	    for(j=0;*(wcspc+j)!=L'\0';j++)wcs[j]=*(wcspc+j);
1214
	    for(j=0;*(wcspc+j)!=L'\0';j++)wcs[j]=*(wcspc+j);
1215
	    wcs[j]=L'\0';
1215
	    wcs[j]=L'\0';
1216
	    w_p=wcs;
1216
	    w_p=wcs;
1217
	    cnt = (int) wcsrtombs(s,(const wchar_t **)&w_p,sizeof(s)-1,NULL);
1217
	    cnt = (int) wcsrtombs(s,(const wchar_t **)&w_p,sizeof(s)-1,NULL);
1218
	    s[cnt]='\0';
1218
	    s[cnt]='\0';
1219
	    if (textwidth(DE, s, (int) strlen(s)) < (bw - DE->text_offset)) break;
1219
	    if (textwidth(DE, s) < (bw - DE->text_offset)) break;
1220
	    *(++wcspc) = L'<';
1220
	    *(++wcspc) = L'<';
1221
	}
1221
	}
1222
    } else {
1222
    } else {
1223
	for (i = wcsbufw; i > 1; i--) {
1223
	for (i = wcsbufw; i > 1; i--) {
1224
	    for(j=0;*(wcspc+j)!=L'\0';j++)wcs[j]=*(wcspc+j);
1224
	    for(j=0;*(wcspc+j)!=L'\0';j++)wcs[j]=*(wcspc+j);
1225
	    wcs[j]=L'\0';
1225
	    wcs[j]=L'\0';
1226
	    w_p=wcs;
1226
	    w_p=wcs;
1227
	    cnt = (int) wcsrtombs(s,(const wchar_t **)&w_p,sizeof(s)-1,NULL);
1227
	    cnt = (int) wcsrtombs(s,(const wchar_t **)&w_p,sizeof(s)-1,NULL);
1228
	    s[cnt]='\0';
1228
	    s[cnt]='\0';
1229
	    if (textwidth(DE, s, (int) strlen(s)) < (bw - DE->text_offset)) break;
1229
	    if (textwidth(DE, s) < (bw - DE->text_offset)) break;
1230
	    *(wcspbuf + i - 2) = L'>';
1230
	    *(wcspbuf + i - 2) = L'>';
1231
	    *(wcspbuf + i - 1) = L'\0';
1231
	    *(wcspbuf + i - 1) = L'\0';
1232
	}
1232
	}
1233
    }
1233
    }
1234
    for(j=0;*(wcspc+j)!=L'\0';j++) wcs[j]=*(wcspc+j);
1234
    for(j=0;*(wcspc+j)!=L'\0';j++) wcs[j]=*(wcspc+j);
Line 1956... Line 1956...
1956
       window size defaults */
1956
       window size defaults */
1957
 
1957
 
1958
    DE->nboxchars = asInteger(GetOption1(install("de.cellwidth")));
1958
    DE->nboxchars = asInteger(GetOption1(install("de.cellwidth")));
1959
    if (DE->nboxchars == NA_INTEGER || DE->nboxchars < 0) DE->nboxchars = 0;
1959
    if (DE->nboxchars == NA_INTEGER || DE->nboxchars < 0) DE->nboxchars = 0;
1960
 
1960
 
1961
    twidth = textwidth(DE, digits, (int) strlen(digits));
1961
    twidth = textwidth(DE, digits);
1962
 
1962
 
1963
    if (DE->nboxchars > 0) twidth = (twidth * DE->nboxchars)/10;
1963
    if (DE->nboxchars > 0) twidth = (twidth * DE->nboxchars)/10;
1964
    DE->box_w = twidth + 4;
1964
    DE->box_w = twidth + 4;
1965
    if(mbcslocale) {
1965
    if(mbcslocale) {
1966
	XFontSetExtents *extent = XExtentsOfFontSet(font_set);
1966
	XFontSetExtents *extent = XExtentsOfFontSet(font_set);
Line 1976... Line 1976...
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
    snprintf(DE->labform, 15, "%%%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")) +
1982
	textwidth(DE, " ", 1) + 8;
1982
	textwidth(DE, " ") + 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
1986
       800 pixels */
1986
       800 pixels */
1987
    w = DE->windowWidth = 0;
1987
    w = DE->windowWidth = 0;
Line 1993... Line 1993...
1993
	}
1993
	}
1994
    }
1994
    }
1995
    if(DE->windowWidth == 0) DE->windowWidth = w;
1995
    if(DE->windowWidth == 0) DE->windowWidth = w;
1996
    DE->windowWidth += 2;
1996
    DE->windowWidth += 2;
1997
    /* allow enough width for buttons */
1997
    /* allow enough width for buttons */
1998
    minwidth = (int)(7.5 * textwidth(DE, "Paste", 5));
1998
    minwidth = (int)(7.5 * textwidth(DE, "Paste"));
1999
    if(DE->windowWidth < minwidth) DE->windowWidth = minwidth;
1999
    if(DE->windowWidth < minwidth) DE->windowWidth = minwidth;
2000
 
2000
 
2001
    ioscreen = DefaultScreen(iodisplay);
2001
    ioscreen = DefaultScreen(iodisplay);
2002
    iowhite = WhitePixel(iodisplay, ioscreen);
2002
    iowhite = WhitePixel(iodisplay, ioscreen);
2003
    ioblack = BlackPixel(iodisplay, ioscreen);
2003
    ioblack = BlackPixel(iodisplay, ioscreen);
Line 2175... Line 2175...
2175
 
2175
 
2176
    /* now set up the menu-window, for now use the same text
2176
    /* now set up the menu-window, for now use the same text
2177
       dimensions as above */
2177
       dimensions as above */
2178
 
2178
 
2179
    /* font size consideration */
2179
    /* font size consideration */
2180
    for(i = 0; i < (sizeof(menu_label)/sizeof(char *)); i++)
2180
    for(i = 0; i < (sizeof(menu_label)/sizeof(char *)); i++) {
2181
	twidth = (twidth<textwidth(DE, menu_label[i],(int) strlen(menu_label[i]))) ?
2181
	int twidthi = textwidth(DE, menu_label[i]);
-
 
2182
	if (twidthi > twidth)
2182
	    textwidth(DE, menu_label[i],(int) strlen(menu_label[i])) : twidth;
2183
	    twidth = twidthi;
-
 
2184
    }
2183
 
2185
 
2184
    menuwindow = XCreateSimpleWindow(iodisplay, root, 0, 0, twidth,
2186
    menuwindow = XCreateSimpleWindow(iodisplay, root, 0, 0, twidth,
2185
				     4 * DE->box_h, 2, ioblack, iowhite);
2187
				     4 * DE->box_h, 2, ioblack, iowhite);
2186
    for (i = 0; i < 4; i++) {
2188
    for (i = 0; i < 4; i++) {
2187
	menupanes[i] = XCreateSimpleWindow(iodisplay, menuwindow, 0,
2189
	menupanes[i] = XCreateSimpleWindow(iodisplay, menuwindow, 0,
Line 2300... Line 2302...
2300
static void Rsync(DEstruct DE)
2302
static void Rsync(DEstruct DE)
2301
{
2303
{
2302
    XSync(iodisplay, 0);
2304
    XSync(iodisplay, 0);
2303
}
2305
}
2304
 
2306
 
2305
static int textwidth(DEstruct DE, const char *text, int nchar)
2307
static int textwidth(DEstruct DE, const char *text)
2306
{
2308
{
2307
    int ans;
2309
    int ans;
2308
    char *buf = CallocCharBuf(nchar);
-
 
2309
    strncpy(buf, text, nchar);
-
 
2310
    if(mbcslocale) {
2310
    if(mbcslocale) {
2311
#ifdef HAVE_XUTF8TEXTESCAPEMENT
2311
#ifdef HAVE_XUTF8TEXTESCAPEMENT
2312
	if (utf8locale)
2312
	if (utf8locale)
2313
	    ans = Xutf8TextEscapement(font_set, buf, nchar);
2313
	    ans = Xutf8TextEscapement(font_set, text, (int)strlen(text));
2314
	else
2314
	else
2315
#endif
2315
#endif
2316
	    ans = XmbTextEscapement(font_set, buf, nchar);
2316
	    ans = XmbTextEscapement(font_set, text, (int)strlen(text));
2317
	R_Free(buf);
-
 
2318
	return ans;
2317
	return ans;
2319
    }
2318
    }
2320
    ans = XTextWidth(DE->font_info, buf, nchar);
2319
    ans = XTextWidth(DE->font_info, text, (int)strlen(text));
2321
    R_Free(buf);
-
 
2322
    return ans;
2320
    return ans;
2323
}
2321
}
2324
 
2322
 
2325
/* Menus */
2323
/* Menus */
2326
 
2324