The R Project SVN R

Rev

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

Rev 48544 Rev 49591
Line 54... Line 54...
54
 
54
 
55
#include <Print.h>
55
#include <Print.h>
56
/* For the input handlers of the event loop mechanism: */
56
/* For the input handlers of the event loop mechanism: */
57
#include <R_ext/eventloop.h>
57
#include <R_ext/eventloop.h>
58
#include <R_ext/RS.h>           /* for CallocCharBuf */
58
#include <R_ext/RS.h>           /* for CallocCharBuf */
59
#ifdef SUPPORT_MBCS
-
 
60
/* This only uses a FontSet in a MBCS */
-
 
61
# define USE_FONTSET 1
59
# define USE_FONTSET 1
62
/* In theory we should do this, but it works less well
60
/* In theory we should do this, but it works less well
63
# ifdef X_HAVE_UTF8_STRING
61
# ifdef X_HAVE_UTF8_STRING
64
#  define HAVE_XUTF8TEXTEXTENTS 1
62
#  define HAVE_XUTF8TEXTEXTENTS 1
65
#  define HAVE_XUTF8DRAWSTRING 1
63
#  define HAVE_XUTF8DRAWSTRING 1
66
#  define HAVE_XUTF8DRAWIMAGESTRING 1
64
#  define HAVE_XUTF8DRAWIMAGESTRING 1
67
# endif */
65
# endif */
68
#endif
-
 
69
 
66
 
70
#ifndef HAVE_KEYSYM
67
#ifndef HAVE_KEYSYM
71
#define KeySym int
68
#define KeySym int
72
#endif
69
#endif
73
 
70
 
Line 168... Line 165...
168
 
165
 
169
 
166
 
170
static const char *get_col_name(DEstruct, int col);
167
static const char *get_col_name(DEstruct, int col);
171
static int  get_col_width(DEstruct, int col);
168
static int  get_col_width(DEstruct, int col);
172
static CellType get_col_type(DEstruct, int col);
169
static CellType get_col_type(DEstruct, int col);
173
#ifdef USE_FONTSET
-
 
174
static void calc_pre_edit_pos(DEstruct DE);
170
static void calc_pre_edit_pos(DEstruct DE);
175
#endif
-
 
176
static int last_wchar_bytes(char *);
171
static int last_wchar_bytes(char *);
177
static SEXP ssNewVector(SEXPTYPE, int);
172
static SEXP ssNewVector(SEXPTYPE, int);
178
static SEXP ssNA_STRING;
173
static SEXP ssNA_STRING;
179
 
174
 
180
 
175
 
Line 194... Line 189...
194
static char buf[BOOSTED_BUF_SIZE];	/* boosted to allow for MBCS */
189
static char buf[BOOSTED_BUF_SIZE];	/* boosted to allow for MBCS */
195
static char *bufp;
190
static char *bufp;
196
static char copycontents[sizeof(buf)+1] ;
191
static char copycontents[sizeof(buf)+1] ;
197
 
192
 
198
/* The next few and used only for the editor in MBCS locales */
193
/* The next few and used only for the editor in MBCS locales */
199
#ifdef USE_FONTSET
-
 
200
static Status           status;
194
static Status           status;
201
static XFontSet         font_set = NULL;
195
static XFontSet         font_set = NULL;
202
static XFontStruct	**fs_list;
196
static XFontStruct	**fs_list;
203
static int		font_set_cnt;
197
static int		font_set_cnt;
204
static char             fontset_name[]="-*-fixed-medium-r-*-*-*-120-*-*-*-*-*-*";
198
static char             fontset_name[]="-*-fixed-medium-r-*-*-*-120-*-*-*-*-*-*";
Line 224... Line 218...
224
    XIMStatusNothing,
218
    XIMStatusNothing,
225
    XIMStatusNone,
219
    XIMStatusNone,
226
    (XIMStyle)NULL,
220
    (XIMStyle)NULL,
227
};
221
};
228
static XIC ioic = NULL;
222
static XIC ioic = NULL;
229
#endif
-
 
230
 
223
 
231
#ifndef max
224
#ifndef max
232
#define max(a, b) (((a)>(b))?(a):(b))
225
#define max(a, b) (((a)>(b))?(a):(b))
233
#endif
226
#endif
234
#ifndef min
227
#ifndef min
Line 403... Line 396...
403
	if(fdView >= 0) { /* might be open after viewers, but unlikely */
396
	if(fdView >= 0) { /* might be open after viewers, but unlikely */
404
	    removeInputHandler(&R_InputHandlers,
397
	    removeInputHandler(&R_InputHandlers,
405
			       getInputHandler(R_InputHandlers,fdView));
398
			       getInputHandler(R_InputHandlers,fdView));
406
	    fdView = -1;
399
	    fdView = -1;
407
	}
400
	}
408
#ifdef USE_FONTSET
-
 
409
	if(font_set) {
401
	if(font_set) {
410
	    XFreeFontSet(iodisplay, font_set);
402
	    XFreeFontSet(iodisplay, font_set);
411
	    font_set = NULL;
403
	    font_set = NULL;
412
	}
404
	}
413
#endif
-
 
414
	XCloseDisplay(iodisplay);
405
	XCloseDisplay(iodisplay);
415
	iodisplay = NULL;
406
	iodisplay = NULL;
416
    }
407
    }
417
 
408
 
418
    /* drop out unused columns */
409
    /* drop out unused columns */
Line 1201... Line 1192...
1201
static void printstring(DEstruct DE, const char *ibuf, int buflen, int row,
1192
static void printstring(DEstruct DE, const char *ibuf, int buflen, int row,
1202
			int col, int left)
1193
			int col, int left)
1203
{
1194
{
1204
    int i, x_pos, y_pos, bw, bufw;
1195
    int i, x_pos, y_pos, bw, bufw;
1205
    char pbuf[BOOSTED_BUF_SIZE];
1196
    char pbuf[BOOSTED_BUF_SIZE];
1206
#ifdef USE_FONTSET
-
 
1207
    int wcsbufw,j;
1197
    int wcsbufw,j;
1208
    wchar_t wcspbuf[BOOSTED_BUF_SIZE], *wcspc = wcspbuf;
1198
    wchar_t wcspbuf[BOOSTED_BUF_SIZE], *wcspc = wcspbuf;
1209
    wchar_t wcs[BOOSTED_BUF_SIZE];
1199
    wchar_t wcs[BOOSTED_BUF_SIZE];
1210
    char    s[BOOSTED_BUF_SIZE];
1200
    char    s[BOOSTED_BUF_SIZE];
1211
    wchar_t *w_p;
1201
    wchar_t *w_p;
Line 1250... Line 1240...
1250
    cnt=wcsrtombs(s,(const wchar_t **)&w_p,sizeof(s)-1,NULL);
1240
    cnt=wcsrtombs(s,(const wchar_t **)&w_p,sizeof(s)-1,NULL);
1251
 
1241
 
1252
    drawtext(DE, x_pos + DE->text_offset, y_pos + DE->box_h - DE->text_offset,
1242
    drawtext(DE, x_pos + DE->text_offset, y_pos + DE->box_h - DE->text_offset,
1253
	     s, cnt);
1243
	     s, cnt);
1254
 
1244
 
1255
#else  /* USE_FONTSET */
-
 
1256
    char *pc = pbuf;
-
 
1257
    find_coords(DE, row, col, &x_pos, &y_pos);
-
 
1258
    if (col == 0) bw = DE->boxw[0]; else bw = BOXW(col+DE->colmin-1);
-
 
1259
    cleararea(DE, x_pos + 2, y_pos + 2, bw - 3, DE->box_h - 3);
-
 
1260
    bufw = (buflen > 200) ? 200 : buflen;
-
 
1261
    strncpy(pbuf, ibuf, bufw);
-
 
1262
    if(left) {
-
 
1263
	for (i = bufw; i > 1; i--) {
-
 
1264
	    if (textwidth(DE, pc, i) < (bw - DE->text_offset)) break;
-
 
1265
	    *(++pc) = '<';
-
 
1266
	}
-
 
1267
    } else {
-
 
1268
	for (i = bufw; i > 1; i--) {
-
 
1269
	    if (textwidth(DE, pbuf, i) < (bw - DE->text_offset)) break;
-
 
1270
	    *(pbuf + i - 2) = '>';
-
 
1271
	}
-
 
1272
    }
-
 
1273
    drawtext(DE, x_pos + DE->text_offset, y_pos + DE->box_h - DE->text_offset,
-
 
1274
	     pc, i);
-
 
1275
#endif /* USE_FONTSET */
-
 
1276
 
-
 
1277
    Rsync(DE);
1245
    Rsync(DE);
1278
}
1246
}
1279
 
1247
 
1280
static void clearrect(DEstruct DE)
1248
static void clearrect(DEstruct DE)
1281
{
1249
{
Line 1289... Line 1257...
1289
/* handlechar has to be able to parse decimal numbers and strings,
1257
/* handlechar has to be able to parse decimal numbers and strings,
1290
   depending on the current column type, only printing characters
1258
   depending on the current column type, only printing characters
1291
   should get this far */
1259
   should get this far */
1292
 
1260
 
1293
/* --- Not true! E.g. ESC ends up in here... */
1261
/* --- Not true! E.g. ESC ends up in here... */
1294
#ifdef USE_FONTSET
-
 
1295
#include <R_ext/rlocale.h>
1262
#include <R_ext/rlocale.h>
1296
#include <wchar.h>
-
 
1297
#include <wctype.h>
-
 
1298
#endif
-
 
1299
 
1263
 
1300
/* <FIXME> This is not correct for stateful MBCSs, but that's hard to
1264
/* <FIXME> This is not correct for stateful MBCSs, but that's hard to
1301
   do as we get a char at a time */
1265
   do as we get a char at a time */
1302
static void handlechar(DEstruct DE, char *text)
1266
static void handlechar(DEstruct DE, char *text)
1303
{
1267
{
1304
    int c = text[0], j;
1268
    int c = text[0], j;
1305
#ifdef USE_FONTSET
-
 
1306
    wchar_t wcs[BOOSTED_BUF_SIZE];
1269
    wchar_t wcs[BOOSTED_BUF_SIZE];
1307
 
1270
 
1308
    memset(wcs,0,sizeof(wcs));
1271
    memset(wcs,0,sizeof(wcs));
1309
#endif
-
 
1310
 
1272
 
1311
    if ( c == '\033' ) { /* ESC */
1273
    if ( c == '\033' ) { /* ESC */
1312
	CellModified = FALSE;
1274
	CellModified = FALSE;
1313
	clength = 0;
1275
	clength = 0;
1314
	bufp = buf;
1276
	bufp = buf;
Line 1344... Line 1306...
1344
	    bufp = buf;
1306
	    bufp = buf;
1345
	}
1307
	}
1346
    }
1308
    }
1347
 
1309
 
1348
    if (currentexp == 1) {	/* we are parsing a number */
1310
    if (currentexp == 1) {	/* we are parsing a number */
-
 
1311
	char *mbs = text;
-
 
1312
	int i, cnt = mbsrtowcs(wcs, (const char **)&mbs, strlen(text)+1, NULL);
1349
 
1313
 
1350
#ifdef USE_FONTSET
-
 
1351
      char *mbs = text;
-
 
1352
      int i, cnt = mbsrtowcs(wcs, (const char **)&mbs, strlen(text)+1, NULL);
-
 
1353
 
-
 
1354
      for(i = 0; i < cnt; i++) {
1314
	for(i = 0; i < cnt; i++) {
1355
	  switch (wcs[i]) {
1315
	    switch (wcs[i]) {
1356
	  case L'-':
1316
	    case L'-':
1357
	      if (nneg == 0) nneg++; else goto donehc;
-
 
1358
	      break;
-
 
1359
	  case L'.':
-
 
1360
	      if (ndecimal == 0) ndecimal++; else goto donehc;
-
 
1361
	      break;
-
 
1362
	  case L'e':
-
 
1363
	  case L'E':
-
 
1364
	      if (ne == 0) {
-
 
1365
		  nneg = ndecimal = 0;	/* might have decimal in exponent */
-
 
1366
		  ne++;
-
 
1367
	      } else goto donehc;
-
 
1368
	      break;
-
 
1369
	case L'N':
-
 
1370
	    if(nneg) goto donehc;
-
 
1371
	case L'I':
-
 
1372
	    inSpecial++;
-
 
1373
	    break;
-
 
1374
	  default:
-
 
1375
	      if (!inSpecial && !iswdigit(wcs[i])) goto donehc;
-
 
1376
	      break;
-
 
1377
	  }
-
 
1378
      }
-
 
1379
#else
-
 
1380
	switch (c) {
-
 
1381
	case '-':
-
 
1382
	    if (nneg == 0) nneg++; else goto donehc;
1317
		if (nneg == 0) nneg++; else goto donehc;
1383
	    break;
-
 
1384
	case '.':
-
 
1385
	    if (ndecimal == 0) ndecimal++; else goto donehc;
-
 
1386
	    break;
1318
	    break;
1387
	case 'e':
-
 
1388
	case 'E':
1319
	    case L'.':
1389
	    if (ne == 0) {
-
 
1390
		nneg = ndecimal = 0;	/* might have decimal in exponent */
1320
		if (ndecimal == 0) ndecimal++; else goto donehc;
1391
		ne++;
-
 
1392
	    } else goto donehc;
-
 
1393
	    break;
1321
	    break;
1394
	case 'N':
1322
	    case L'e':
1395
	    if(nneg) goto donehc;
1323
	    case L'E':
1396
	case 'I':
1324
		if (ne == 0) {
-
 
1325
		    nneg = ndecimal = 0;	/* might have decimal in exponent */
1397
	    inSpecial++;
1326
		    ne++;
-
 
1327
		} else goto donehc;
1398
	    break;
1328
	    break;
1399
	default:
1329
	    case L'N':
1400
	    if (!inSpecial && !isdigit(c)) goto donehc;
1330
		if(nneg) goto donehc;
-
 
1331
	    case L'I':
-
 
1332
		inSpecial++;
1401
	    break;
1333
	    break;
-
 
1334
	    default:
-
 
1335
		if (!inSpecial && !iswdigit(wcs[i])) goto donehc;
-
 
1336
		break;
-
 
1337
	    }
1402
	}
1338
	}
1403
#endif
-
 
1404
    }
1339
    }
1405
    if (currentexp == 3) {
1340
    if (currentexp == 3) {
1406
#ifdef USE_FONTSET
-
 
1407
	char *mbs = text;
1341
	char *mbs = text;
1408
	int i, cnt = mbsrtowcs(wcs, (const char **)&mbs, strlen(text)+1, NULL);
1342
	int i, cnt = mbsrtowcs(wcs, (const char **)&mbs, strlen(text)+1, NULL);
1409
	for(i = 0; i < cnt; i++) {
1343
	for(i = 0; i < cnt; i++) {
1410
	    if (iswspace(wcs[i])) goto donehc;
1344
	    if (iswspace(wcs[i])) goto donehc;
1411
	    if (clength == 0 && wcs[i] != L'.' && !iswalpha(wcs[i]))
1345
	    if (clength == 0 && wcs[i] != L'.' && !iswalpha(wcs[i]))
1412
		goto donehc;
1346
		goto donehc;
1413
	    else if (wcs[i] != L'.' && !iswalnum(wcs[i])) goto donehc;
1347
	    else if (wcs[i] != L'.' && !iswalnum(wcs[i])) goto donehc;
1414
	}
1348
	}
1415
#else
-
 
1416
	if (isspace(c)) goto donehc;
-
 
1417
	if (clength == 0  && c != '.' && !isalpha(c)) goto donehc;
-
 
1418
	else if (c != '.' && !isalnum(c)) goto donehc;
-
 
1419
#endif
-
 
1420
    }
1349
    }
1421
 
1350
 
1422
    if (clength+strlen(text) > BOOSTED_BUF_SIZE - MB_CUR_MAX - 1) {
1351
    if (clength+strlen(text) > BOOSTED_BUF_SIZE - MB_CUR_MAX - 1) {
1423
	warning("dataentry: expression too long");
1352
	warning("dataentry: expression too long");
1424
	goto donehc;
1353
	goto donehc;
Line 1567... Line 1496...
1567
	XFindContext(iodisplay, ioevent.xany.window, deContext, &temp);
1496
	XFindContext(iodisplay, ioevent.xany.window, deContext, &temp);
1568
	if ((DEstruct) temp != DE) { /* so a View window */
1497
	if ((DEstruct) temp != DE) { /* so a View window */
1569
	    if (WhichEvent(ioevent) == Expose)
1498
	    if (WhichEvent(ioevent) == Expose)
1570
		drawwindow((DEstruct) temp);
1499
		drawwindow((DEstruct) temp);
1571
	} else {
1500
	} else {
1572
#ifdef USE_FONTSET
-
 
1573
	    if (XFilterEvent(&ioevent, None)){
1501
	    if (XFilterEvent(&ioevent, None)){
1574
		if(ioic){
1502
		if(ioic){
1575
		    XSetICFocus(ioic);
1503
		    XSetICFocus(ioic);
1576
		    if (ioim_style & XIMPreeditPosition)
1504
		    if (ioim_style & XIMPreeditPosition)
1577
			calc_pre_edit_pos(DE);
1505
			calc_pre_edit_pos(DE);
1578
		}
1506
		}
1579
		continue;
1507
		continue;
1580
	    }
1508
	    }
1581
#endif
-
 
1582
 
1509
 
1583
	    switch (WhichEvent(ioevent)) {
1510
	    switch (WhichEvent(ioevent)) {
1584
	    case keyDown:/* KeyPress */
1511
	    case keyDown:/* KeyPress */
1585
		doSpreadKey(DE, 0, &ioevent);
1512
		doSpreadKey(DE, 0, &ioevent);
1586
		break;
1513
		break;
Line 1683... Line 1610...
1683
	    /* NB: this is removing the handler that is currently
1610
	    /* NB: this is removing the handler that is currently
1684
	       being used: only OK to free here in R > 2.8.0 */
1611
	       being used: only OK to free here in R > 2.8.0 */
1685
	    removeInputHandler(&R_InputHandlers,
1612
	    removeInputHandler(&R_InputHandlers,
1686
			       getInputHandler(R_InputHandlers,fdView));
1613
			       getInputHandler(R_InputHandlers,fdView));
1687
	    fdView = -1;
1614
	    fdView = -1;
1688
#ifdef USE_FONTSET
-
 
1689
	    if(font_set) {
1615
	    if(font_set) {
1690
		XFreeFontSet(iodisplay, font_set);
1616
		XFreeFontSet(iodisplay, font_set);
1691
		font_set = NULL;
1617
		font_set = NULL;
1692
	    }
1618
	    }
1693
#endif
-
 
1694
	    XCloseDisplay(iodisplay);
1619
	    XCloseDisplay(iodisplay);
1695
	    iodisplay = NULL;
1620
	    iodisplay = NULL;
1696
	}
1621
	}
1697
 
1622
 
1698
    }
1623
    }
Line 1704... Line 1629...
1704
}
1629
}
1705
 
1630
 
1706
static void doSpreadKey(DEstruct DE, int key, DEEvent * event)
1631
static void doSpreadKey(DEstruct DE, int key, DEEvent * event)
1707
{
1632
{
1708
    KeySym iokey;
1633
    KeySym iokey;
1709
    char *text;
1634
    char *text = "";
1710
 
1635
 
1711
    iokey = GetKey(event);
1636
    iokey = GetKey(event);
1712
    if(DE->isEditor) text = GetCharP(event);
1637
    if(DE->isEditor) text = GetCharP(event);
1713
 
1638
 
1714
    if (CheckControl(event))
1639
    if (CheckControl(event))
Line 1819... Line 1744...
1819
    static char text[BOOSTED_BUF_SIZE];
1744
    static char text[BOOSTED_BUF_SIZE];
1820
    KeySym iokey;
1745
    KeySym iokey;
1821
 
1746
 
1822
    memset(text,0,sizeof(text));
1747
    memset(text,0,sizeof(text));
1823
 
1748
 
1824
#ifdef USE_FONTSET
-
 
1825
    if(mbcslocale) {
1749
    if(mbcslocale) {
1826
#ifdef HAVE_XUTF8LOOKUPSTRING
1750
#ifdef HAVE_XUTF8LOOKUPSTRING
1827
	if(utf8locale)
1751
	if(utf8locale)
1828
	    Xutf8LookupString(ioic, (XKeyEvent *)event,
1752
	    Xutf8LookupString(ioic, (XKeyEvent *)event,
1829
			      text, sizeof(text) - clength,
1753
			      text, sizeof(text) - clength,
Line 1835... Line 1759...
1835
			    &iokey, &status);
1759
			    &iokey, &status);
1836
	/* FIXME check the return code */
1760
	/* FIXME check the return code */
1837
	if(status == XBufferOverflow)
1761
	if(status == XBufferOverflow)
1838
	    warning("dataentry: expression too long");
1762
	    warning("dataentry: expression too long");
1839
    } else
1763
    } else
1840
#endif
-
 
1841
	XLookupString((XKeyEvent *)event,
1764
	XLookupString((XKeyEvent *)event,
1842
		      text, sizeof(text) - clength,
1765
		      text, sizeof(text) - clength,
1843
		      &iokey, NULL);
1766
		      &iokey, NULL);
1844
    return text;
1767
    return text;
1845
}
1768
}
Line 1900... Line 1823...
1900
/* Initialize/Close Windows */
1823
/* Initialize/Close Windows */
1901
 
1824
 
1902
void closewin(DEstruct DE)
1825
void closewin(DEstruct DE)
1903
{
1826
{
1904
    XFreeGC(iodisplay, DE->iogc);
1827
    XFreeGC(iodisplay, DE->iogc);
1905
#ifdef USE_FONTSET
-
 
1906
    if(mbcslocale  && DE->isEditor) {
1828
    if(mbcslocale  && DE->isEditor) {
1907
	XDestroyIC(ioic);
1829
	XDestroyIC(ioic);
1908
	XCloseIM(ioim);
1830
	XCloseIM(ioim);
1909
    }
1831
    }
1910
#endif
-
 
1911
    XDestroyWindow(iodisplay, DE->iowindow);
1832
    XDestroyWindow(iodisplay, DE->iowindow);
1912
    /* XCloseDisplay(iodisplay); */
1833
    /* XCloseDisplay(iodisplay); */
1913
    Rsync(DE);
1834
    Rsync(DE);
1914
}
1835
}
1915
 
1836
 
Line 1973... Line 1894...
1973
    XEvent ioevent;
1894
    XEvent ioevent;
1974
    XSetWindowAttributes winattr;
1895
    XSetWindowAttributes winattr;
1975
    XWindowAttributes attribs;
1896
    XWindowAttributes attribs;
1976
    XSizeHints *hint;
1897
    XSizeHints *hint;
1977
    unsigned long fevent=0UL;
1898
    unsigned long fevent=0UL;
1978
#ifdef USE_FONTSET
-
 
1979
    int j,k;
1899
    int j,k;
1980
    XVaNestedList   xva_nlist;
1900
    XVaNestedList   xva_nlist;
1981
    XPoint xpoint;
1901
    XPoint xpoint;
1982
#endif
-
 
1983
 
1902
 
1984
    strcpy(copycontents, "");
1903
    strcpy(copycontents, "");
1985
 
1904
 
1986
#ifdef USE_FONTSET
-
 
1987
    if (!XSupportsLocale ())
1905
    if (!XSupportsLocale ())
1988
	warning("locale not supported by Xlib: some X ops will operate in C locale");
1906
	warning("locale not supported by Xlib: some X ops will operate in C locale");
1989
    if (!XSetLocaleModifiers ("")) warning("X cannot set locale modifiers");
1907
    if (!XSetLocaleModifiers ("")) warning("X cannot set locale modifiers");
1990
#endif
-
 
1991
 
1908
 
1992
    if(!iodisplay) {
1909
    if(!iodisplay) {
1993
	if ((iodisplay = XOpenDisplay(NULL)) == NULL) {
1910
	if ((iodisplay = XOpenDisplay(NULL)) == NULL) {
1994
	    warning("unable to open display");
1911
	    warning("unable to open display");
1995
	    return TRUE;
1912
	    return TRUE;
Line 2000... Line 1917...
2000
    }
1917
    }
2001
 
1918
 
2002
 
1919
 
2003
    /* Get Font Loaded if we can */
1920
    /* Get Font Loaded if we can */
2004
 
1921
 
2005
#ifdef USE_FONTSET
-
 
2006
    if(mbcslocale) {
1922
    if(mbcslocale) {
2007
	int  missing_charset_count;
1923
	int  missing_charset_count;
2008
	char **missing_charset_list;
1924
	char **missing_charset_list;
2009
	char *def_string;
1925
	char *def_string;
2010
	char opt_fontset_name[512];
1926
	char opt_fontset_name[512];
Line 2024... Line 1940...
2024
	}
1940
	}
2025
	if (font_set == NULL) {
1941
	if (font_set == NULL) {
2026
	    warning("unable to create fontset %s", opt_fontset_name);
1942
	    warning("unable to create fontset %s", opt_fontset_name);
2027
	    return TRUE; /* ERROR */
1943
	    return TRUE; /* ERROR */
2028
	}
1944
	}
2029
    } else
1945
    } else {
2030
#endif
-
 
2031
    {
-
 
2032
	DE->font_info = XLoadQueryFont(iodisplay, font_name);
1946
	DE->font_info = XLoadQueryFont(iodisplay, font_name);
2033
	if (DE->font_info == NULL) {
1947
	if (DE->font_info == NULL) {
2034
	    warning("unable to losd font %s", font_name);
1948
	    warning("unable to losd font %s", font_name);
2035
	    return TRUE; /* ERROR */
1949
	    return TRUE; /* ERROR */
2036
	}
1950
	}
Line 2044... Line 1958...
2044
 
1958
 
2045
    twidth = textwidth(DE, digits, strlen(digits));
1959
    twidth = textwidth(DE, digits, strlen(digits));
2046
 
1960
 
2047
    if (DE->nboxchars > 0) twidth = (twidth * DE->nboxchars)/10;
1961
    if (DE->nboxchars > 0) twidth = (twidth * DE->nboxchars)/10;
2048
    DE->box_w = twidth + 4;
1962
    DE->box_w = twidth + 4;
2049
#ifdef USE_FONTSET
-
 
2050
    if(mbcslocale) {
1963
    if(mbcslocale) {
2051
	XFontSetExtents *extent = XExtentsOfFontSet(font_set);
1964
	XFontSetExtents *extent = XExtentsOfFontSet(font_set);
2052
	char **ml;
1965
	char **ml;
2053
	DE->box_h = (extent->max_logical_extent.height)
1966
	DE->box_h = (extent->max_logical_extent.height)
2054
	    + (extent->max_logical_extent.height / 5) + 4;
1967
	    + (extent->max_logical_extent.height / 5) + 4;
2055
	font_set_cnt = XFontsOfFontSet(font_set, &fs_list, &ml);
1968
	font_set_cnt = XFontsOfFontSet(font_set, &fs_list, &ml);
2056
	DE->text_offset = 2 + fs_list[0]->max_bounds.descent;
1969
	DE->text_offset = 2 + fs_list[0]->max_bounds.descent;
2057
    } else
1970
    } else {
2058
#endif
-
 
2059
    {
-
 
2060
	DE->box_h = DE->font_info->max_bounds.ascent
1971
	DE->box_h = DE->font_info->max_bounds.ascent
2061
	    + DE->font_info->max_bounds.descent + 4;
1972
	    + DE->font_info->max_bounds.descent + 4;
2062
	DE->text_offset = 2 + DE->font_info->max_bounds.descent;
1973
	DE->text_offset = 2 + DE->font_info->max_bounds.descent;
2063
    }
1974
    }
2064
    DE->windowHeight = 26 * DE->box_h + DE->hht + 2;
1975
    DE->windowHeight = 26 * DE->box_h + DE->hht + 2;
Line 2186... Line 2097...
2186
    XSetWMHints(iodisplay, DE->iowindow, &hints);
2097
    XSetWMHints(iodisplay, DE->iowindow, &hints);
2187
     */
2098
     */
2188
 
2099
 
2189
    DE->iogc = XCreateGC(iodisplay, DE->iowindow, 0, 0);
2100
    DE->iogc = XCreateGC(iodisplay, DE->iowindow, 0, 0);
2190
 
2101
 
2191
#ifdef USE_FONTSET
-
 
2192
    if(mbcslocale && DE->isEditor) {
2102
    if(mbcslocale && DE->isEditor) {
2193
	ioim = XOpenIM(iodisplay, NULL, NULL, NULL);
2103
	ioim = XOpenIM(iodisplay, NULL, NULL, NULL);
2194
	if(!ioim) {
2104
	if(!ioim) {
2195
	    XDestroyWindow(iodisplay, DE->iowindow);
2105
	    XDestroyWindow(iodisplay, DE->iowindow);
2196
	    XCloseDisplay(iodisplay);
2106
	    XCloseDisplay(iodisplay);
Line 2234... Line 2144...
2234
	}
2144
	}
2235
 
2145
 
2236
	/* get XIM processes event. */
2146
	/* get XIM processes event. */
2237
	XGetICValues(ioic, XNFilterEvents, &fevent, NULL);
2147
	XGetICValues(ioic, XNFilterEvents, &fevent, NULL);
2238
    }
2148
    }
2239
#endif
-
 
2240
 
2149
 
2241
#ifdef USE_FONTSET
-
 
2242
    if(!mbcslocale)
2150
    if(!mbcslocale)
2243
#endif
-
 
2244
	XSetFont(iodisplay, DE->iogc, DE->font_info->fid);
2151
	XSetFont(iodisplay, DE->iogc, DE->font_info->fid);
-
 
2152
 
2245
    XSetBackground(iodisplay, DE->iogc, iowhite);
2153
    XSetBackground(iodisplay, DE->iogc, iowhite);
2246
    XSetForeground(iodisplay, DE->iogc, ioblack);
2154
    XSetForeground(iodisplay, DE->iogc, ioblack);
2247
    XSetLineAttributes(iodisplay, DE->iogc, 1, LineSolid, CapRound,
2155
    XSetLineAttributes(iodisplay, DE->iogc, 1, LineSolid, CapRound,
2248
		       JoinRound);
2156
		       JoinRound);
2249
 
2157
 
Line 2370... Line 2278...
2370
		   width, height);
2278
		   width, height);
2371
}
2279
}
2372
 
2280
 
2373
static void drawtext(DEstruct DE, int xpos, int ypos, char *text, int len)
2281
static void drawtext(DEstruct DE, int xpos, int ypos, char *text, int len)
2374
{
2282
{
2375
#ifdef USE_FONTSET
-
 
2376
    if(mbcslocale)
2283
    if(mbcslocale)
2377
#ifdef HAVE_XUTF8DRAWIMAGESTRING
2284
#ifdef HAVE_XUTF8DRAWIMAGESTRING
2378
	if(utf8locale)
2285
	if(utf8locale)
2379
	    Xutf8DrawImageString(iodisplay, DE->iowindow, font_set,
2286
	    Xutf8DrawImageString(iodisplay, DE->iowindow, font_set,
2380
				 DE->iogc, xpos, ypos,text, len);
2287
				 DE->iogc, xpos, ypos,text, len);
2381
	else
2288
	else
2382
#endif
2289
#endif
2383
	    XmbDrawImageString(iodisplay, DE->iowindow, font_set,
2290
	    XmbDrawImageString(iodisplay, DE->iowindow, font_set,
2384
			       DE->iogc, xpos, ypos,text, len);
2291
			       DE->iogc, xpos, ypos,text, len);
2385
    else
2292
    else
2386
#endif
-
 
2387
	XDrawImageString(iodisplay, DE->iowindow, DE->iogc,
2293
	XDrawImageString(iodisplay, DE->iowindow, DE->iogc,
2388
			 xpos, ypos, text, len);
2294
			 xpos, ypos, text, len);
2389
    Rsync(DE);
2295
    Rsync(DE);
2390
}
2296
}
2391
 
2297
 
Line 2397... Line 2303...
2397
static int textwidth(DEstruct DE, const char *text, int nchar)
2303
static int textwidth(DEstruct DE, const char *text, int nchar)
2398
{
2304
{
2399
    int ans;
2305
    int ans;
2400
    char *buf = CallocCharBuf(nchar);
2306
    char *buf = CallocCharBuf(nchar);
2401
    strncpy(buf, text, nchar);
2307
    strncpy(buf, text, nchar);
2402
#ifdef USE_FONTSET
-
 
2403
    if(mbcslocale) {
2308
    if(mbcslocale) {
2404
#ifdef HAVE_XUTF8TEXTESCAPEMENT
2309
#ifdef HAVE_XUTF8TEXTESCAPEMENT
2405
	if (utf8locale)
2310
	if (utf8locale)
2406
	    ans = Xutf8TextEscapement(font_set, buf, nchar);
2311
	    ans = Xutf8TextEscapement(font_set, buf, nchar);
2407
	else
2312
	else
2408
#endif
2313
#endif
2409
	    ans = XmbTextEscapement(font_set, buf, nchar);
2314
	    ans = XmbTextEscapement(font_set, buf, nchar);
2410
	Free(buf);
2315
	Free(buf);
2411
	return ans;
2316
	return ans;
2412
    }
2317
    }
2413
#endif
-
 
2414
    ans = XTextWidth(DE->font_info, buf, nchar);
2318
    ans = XTextWidth(DE->font_info, buf, nchar);
2415
    Free(buf);
2319
    Free(buf);
2416
    return ans;
2320
    return ans;
2417
}
2321
}
2418
 
2322
 
Line 2444... Line 2348...
2444
	REPROTECT(DE->lens = lengthgets(DE->lens, popupcol), DE->lpi);
2348
	REPROTECT(DE->lens = lengthgets(DE->lens, popupcol), DE->lpi);
2445
	DE->xmaxused = popupcol;
2349
	DE->xmaxused = popupcol;
2446
    }
2350
    }
2447
    tvec = VECTOR_ELT(DE->work, popupcol - 1);
2351
    tvec = VECTOR_ELT(DE->work, popupcol - 1);
2448
    name = CHAR(STRING_ELT(DE->names, popupcol - 1));
2352
    name = CHAR(STRING_ELT(DE->names, popupcol - 1));
2449
#ifdef USE_FONTSET
-
 
2450
    if(mbcslocale)
2353
    if(mbcslocale)
2451
#ifdef HAVE_XUTF8DRAWSTRING
2354
#ifdef HAVE_XUTF8DRAWSTRING
2452
	if(utf8locale)
2355
	if(utf8locale)
2453
	    Xutf8DrawString(iodisplay,
2356
	    Xutf8DrawString(iodisplay,
2454
			    menupanes[0],
2357
			    menupanes[0],
Line 2459... Line 2362...
2459
	    XmbDrawString(iodisplay,
2362
	    XmbDrawString(iodisplay,
2460
			  menupanes[0],
2363
			  menupanes[0],
2461
			  font_set, DE->iogc, 3, DE->box_h - 3, name,
2364
			  font_set, DE->iogc, 3, DE->box_h - 3, name,
2462
			  strlen(name));
2365
			  strlen(name));
2463
    else
2366
    else
2464
#endif
-
 
2465
	XDrawString(iodisplay,
2367
	XDrawString(iodisplay,
2466
		    menupanes[0], DE->iogc, 3, DE->box_h - 3, name,
2368
		    menupanes[0], DE->iogc, 3, DE->box_h - 3, name,
2467
		    strlen(name));
2369
		    strlen(name));
2468
    for (i = 1; i < 4; i++)
2370
    for (i = 1; i < 4; i++)
2469
#ifdef USE_FONTSET
-
 
2470
      if(mbcslocale)
2371
	if(mbcslocale)
2471
#ifdef HAVE_XUTF8DRAWSTRING
2372
#ifdef HAVE_XUTF8DRAWSTRING
2472
	if(utf8locale)
2373
	    if(utf8locale)
2473
	  Xutf8DrawString(iodisplay,
2374
		Xutf8DrawString(iodisplay,
2474
			  menupanes[i],
2375
				menupanes[i],
2475
			  font_set, DE->iogc, 3, DE->box_h - 3,
2376
				font_set, DE->iogc, 3, DE->box_h - 3,
2476
			  menu_label[i - 1], strlen(menu_label[i - 1]));
2377
				menu_label[i - 1], strlen(menu_label[i - 1]));
2477
	else
2378
	    else
2478
#endif
2379
#endif
2479
	  XmbDrawString(iodisplay,
2380
		XmbDrawString(iodisplay,
2480
			menupanes[i],
2381
			      menupanes[i],
2481
			font_set, DE->iogc, 3, DE->box_h - 3,
2382
			      font_set, DE->iogc, 3, DE->box_h - 3,
-
 
2383
			      menu_label[i - 1], strlen(menu_label[i - 1]));
-
 
2384
	else
-
 
2385
	    XDrawString(iodisplay,
-
 
2386
			menupanes[i], DE->iogc, 3, DE->box_h - 3,
2482
			menu_label[i - 1], strlen(menu_label[i - 1]));
2387
			menu_label[i - 1], strlen(menu_label[i - 1]));
2483
      else
-
 
2484
#endif
-
 
2485
	XDrawString(iodisplay,
-
 
2486
		    menupanes[i], DE->iogc, 3, DE->box_h - 3,
-
 
2487
		    menu_label[i - 1], strlen(menu_label[i - 1]));
-
 
2488
 
2388
 
2489
    if (isNull(tvec) || TYPEOF(tvec) == REALSXP)
2389
    if (isNull(tvec) || TYPEOF(tvec) == REALSXP)
2490
#ifdef USE_FONTSET
-
 
2491
      if(mbcslocale)
2390
	if(mbcslocale)
2492
#ifdef HAVE_XUTF8DRAWSTRING
2391
#ifdef HAVE_XUTF8DRAWSTRING
2493
	if(utf8locale)
2392
	    if(utf8locale)
2494
	  Xutf8DrawString(iodisplay,
2393
		Xutf8DrawString(iodisplay,
2495
			  menupanes[1],
2394
				menupanes[1],
2496
			  font_set, DE->iogc, 0, DE->box_h - 3,
2395
				font_set, DE->iogc, 0, DE->box_h - 3,
2497
			  "*", 1);
2396
				"*", 1);
2498
	else
2397
	    else
2499
#endif
2398
#endif
2500
	  XmbDrawString(iodisplay,
2399
		XmbDrawString(iodisplay,
2501
			menupanes[1],
2400
			      menupanes[1],
2502
			font_set, DE->iogc, 0, DE->box_h - 3,
2401
			      font_set, DE->iogc, 0, DE->box_h - 3,
-
 
2402
			      "*", 1);
-
 
2403
	else
-
 
2404
	    XDrawString(iodisplay, menupanes[1], DE->iogc, 0, DE->box_h - 3,
2503
			"*", 1);
2405
			"*", 1);
2504
      else
-
 
2505
#endif
-
 
2506
	XDrawString(iodisplay, menupanes[1], DE->iogc, 0, DE->box_h - 3,
-
 
2507
		    "*", 1);
-
 
2508
    else
2406
    else
2509
#ifdef USE_FONTSET
-
 
2510
      if(mbcslocale)
2407
	if(mbcslocale)
2511
#ifdef HAVE_XUTF8DRAWSTRING
2408
#ifdef HAVE_XUTF8DRAWSTRING
2512
	if(utf8locale)
2409
	    if(utf8locale)
2513
	  Xutf8DrawString(iodisplay,
2410
		Xutf8DrawString(iodisplay,
2514
			  menupanes[2],
2411
				menupanes[2],
2515
			  font_set, DE->iogc, 0, DE->box_h - 3,
2412
				font_set, DE->iogc, 0, DE->box_h - 3,
2516
			  "*", 1);
2413
				"*", 1);
2517
	else
2414
	    else
2518
#endif
2415
#endif
2519
	  XmbDrawString(iodisplay,
2416
		XmbDrawString(iodisplay,
2520
			menupanes[2],
2417
			      menupanes[2],
2521
			font_set, DE->iogc, 0, DE->box_h - 3,
2418
			      font_set, DE->iogc, 0, DE->box_h - 3,
-
 
2419
			      "*", 1);
-
 
2420
	else
-
 
2421
	    XDrawString(iodisplay, menupanes[2], DE->iogc, 0, DE->box_h - 3,
2522
			"*", 1);
2422
			"*", 1);
2523
      else
-
 
2524
#endif
-
 
2525
	XDrawString(iodisplay, menupanes[2], DE->iogc, 0, DE->box_h - 3,
-
 
2526
		    "*", 1);
-
 
2527
 
2423
 
2528
/*
2424
/*
2529
  start an event loop; we're looking for a button press and a button
2425
  start an event loop; we're looking for a button press and a button
2530
  release in the same window
2426
  release in the same window
2531
*/
2427
*/
Line 2590... Line 2486...
2590
				DE->box_h - 3,
2486
				DE->box_h - 3,
2591
				menu_label[i - 1], strlen(menu_label[i - 1]));
2487
				menu_label[i - 1], strlen(menu_label[i - 1]));
2592
	    }
2488
	    }
2593
	}
2489
	}
2594
    }
2490
    }
2595
 done:
2491
done:
2596
    popdownmenu(DE);
2492
    popdownmenu(DE);
2597
    highlightrect(DE);
2493
    highlightrect(DE);
2598
}
2494
}
2599
 
2495
 
2600
void popdownmenu(DEstruct DE)
2496
void popdownmenu(DEstruct DE)
Line 2651... Line 2547...
2651
    }
2547
    }
2652
    closerect(DE);
2548
    closerect(DE);
2653
    highlightrect(DE);
2549
    highlightrect(DE);
2654
}
2550
}
2655
 
2551
 
2656
#ifdef USE_FONTSET
-
 
2657
static void calc_pre_edit_pos(DEstruct DE)
2552
static void calc_pre_edit_pos(DEstruct DE)
2658
{
2553
{
2659
    XVaNestedList   xva_nlist;
2554
    XVaNestedList   xva_nlist;
2660
    XPoint          xpoint;
2555
    XPoint          xpoint;
2661
    int i;
2556
    int i;
Line 2689... Line 2584...
2689
    XSetICValues(ioic, XNPreeditAttributes, xva_nlist, NULL);
2584
    XSetICValues(ioic, XNPreeditAttributes, xva_nlist, NULL);
2690
 
2585
 
2691
    XFree(xva_nlist);
2586
    XFree(xva_nlist);
2692
    return;
2587
    return;
2693
}
2588
}
2694
#endif
-
 
2695
 
2589
 
2696
/* last character bytes */
2590
/* last character bytes */
2697
static int last_wchar_bytes(char *str)
2591
static int last_wchar_bytes(char *str)
2698
{
2592
{
2699
#ifdef USE_FONTSET
-
 
2700
    wchar_t   wcs[BOOSTED_BUF_SIZE];
2593
    wchar_t   wcs[BOOSTED_BUF_SIZE];
2701
    mbstate_t mb_st;
2594
    mbstate_t mb_st;
2702
    int cnt;
2595
    int cnt;
2703
    char last_mbs[8];
2596
    char last_mbs[8];
2704
    char *mbs;
2597
    char *mbs;
Line 2716... Line 2609...
2716
    if(wcs[0] == L'\0') return 0;
2609
    if(wcs[0] == L'\0') return 0;
2717
 
2610
 
2718
    memset(last_mbs, 0, sizeof(last_mbs));
2611
    memset(last_mbs, 0, sizeof(last_mbs));
2719
    bytes = wcrtomb(last_mbs, wcs[cnt-1], &mb_st); /* -Wall */
2612
    bytes = wcrtomb(last_mbs, wcs[cnt-1], &mb_st); /* -Wall */
2720
    return(bytes);
2613
    return(bytes);
2721
#else
-
 
2722
    return(1);
-
 
2723
#endif
-
 
2724
}
2614
}