The R Project SVN R

Rev

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

Rev 35930 Rev 36044
Line 36... Line 36...
36
#include <config.h>
36
#include <config.h>
37
#endif
37
#endif
38
 
38
 
39
#include <stdlib.h>
39
#include <stdlib.h>
40
 
40
 
41
/* don't use X11 function prototypes (which tend to ...): */
-
 
42
#define NeedFunctionPrototypes 0
-
 
43
/* XFree 4.4.0 forgets to define this if NeedFunctionPrototypes=0 */
-
 
44
#ifndef _Xconst
41
#ifndef _Xconst
45
#define _Xconst const
42
#define _Xconst const
46
#endif
43
#endif
47
#include <X11/X.h>
44
#include <X11/X.h>
48
#include <X11/Xlib.h>
45
#include <X11/Xlib.h>
49
#include <X11/Xutil.h>
46
#include <X11/Xutil.h>
50
#include <X11/keysym.h>
47
#include <X11/keysym.h>
51
#include <X11/cursorfont.h>
48
#include <X11/cursorfont.h>
-
 
49
#include <X11/Intrinsic.h>
-
 
50
 
-
 
51
 
52
 
52
 
53
#include "Defn.h"
53
#include "Defn.h"
54
#include "Print.h"
54
#include "Print.h"
55
 
55
 
56
#ifdef SUPPORT_MBCS
56
#ifdef SUPPORT_MBCS
Line 1626... Line 1626...
1626
#endif
1626
#endif
1627
    XDestroyWindow(iodisplay, iowindow);
1627
    XDestroyWindow(iodisplay, iowindow);
1628
    XCloseDisplay(iodisplay);
1628
    XCloseDisplay(iodisplay);
1629
}
1629
}
1630
 
1630
 
-
 
1631
#define USE_Xt 1
-
 
1632
 
-
 
1633
#ifdef USE_Xt
-
 
1634
#include <X11/StringDefs.h>
-
 
1635
#include <X11/Intrinsic.h>
-
 
1636
#include <X11/Shell.h>
-
 
1637
typedef struct gx_device_X_s {
-
 
1638
    Pixel background, foreground, borderColor;
-
 
1639
    Dimension borderWidth;
-
 
1640
    String geometry;
-
 
1641
} gx_device_X;
-
 
1642
 
-
 
1643
/* (String) casts are here to suppress warnings about discarding `const' */
-
 
1644
#define RINIT(a,b,t,s,o,it,n)\
-
 
1645
  {(String)(a), (String)(b), (String)t, sizeof(s),\
-
 
1646
   XtOffsetOf(gx_device_X, o), (String)it, (n)}
-
 
1647
#define rpix(a,b,o,n)\
-
 
1648
  RINIT(a,b,XtRPixel,Pixel,o,XtRString,(XtPointer)(n))
-
 
1649
#define rdim(a,b,o,n)\
-
 
1650
  RINIT(a,b,XtRDimension,Dimension,o,XtRImmediate,(XtPointer)(n))
-
 
1651
#define rstr(a,b,o,n)\
-
 
1652
  RINIT(a,b,XtRString,String,o,XtRString,(char*)(n))
-
 
1653
 
-
 
1654
static XtResource x_resources[] = {
-
 
1655
    rpix(XtNforeground, XtCForeground, foreground, "XtDefaultForeground"),
-
 
1656
    rpix(XtNbackground, XtCBackground, background, "XtDefaultBackground"),
-
 
1657
    rstr(XtNgeometry, XtCGeometry, geometry, NULL),
-
 
1658
};
-
 
1659
 
-
 
1660
static const int x_resource_count = XtNumber(x_resources);
-
 
1661
static gx_device_X xdev;
-
 
1662
#endif
-
 
1663
 
1631
static int R_X11Err(Display *dsp, XErrorEvent *event)
1664
static int R_X11Err(Display *dsp, XErrorEvent *event)
1632
{
1665
{
1633
    char buff[1000];
1666
    char buff[1000];
1634
    XGetErrorText(dsp, event->error_code, buff, 1000);
1667
    XGetErrorText(dsp, event->error_code, buff, 1000);
1635
    warning("X11 protocol error: %s", buff);
1668
    warning("X11 protocol error: %s", buff);
Line 1769... Line 1802...
1769
    ioscreen = DefaultScreen(iodisplay);
1802
    ioscreen = DefaultScreen(iodisplay);
1770
    iowhite = WhitePixel(iodisplay, ioscreen);
1803
    iowhite = WhitePixel(iodisplay, ioscreen);
1771
    ioblack = BlackPixel(iodisplay, ioscreen);
1804
    ioblack = BlackPixel(iodisplay, ioscreen);
1772
 
1805
 
1773
 
1806
 
1774
    hint=XAllocSizeHints();
1807
    hint = XAllocSizeHints();
1775
 
1808
 
1776
    hint->x = 0;
1809
    hint->x = 0;
1777
    hint->y = 0;
1810
    hint->y = 0;
1778
    hint->width = windowWidth;
1811
    hint->width = windowWidth;
1779
    hint->height = windowHeight;
1812
    hint->height = windowHeight;
Line 1783... Line 1816...
1783
    hints.flags = InputHint;
1816
    hints.flags = InputHint;
1784
    hints.input = True;
1817
    hints.input = True;
1785
    */
1818
    */
1786
    root = DefaultRootWindow(iodisplay);
1819
    root = DefaultRootWindow(iodisplay);
1787
 
1820
 
-
 
1821
#ifdef USE_Xt
-
 
1822
    {
-
 
1823
	XtAppContext app_con;
-
 
1824
	Widget toplevel;
-
 
1825
	Display *xtdpy;
-
 
1826
        int zero = 0;
-
 
1827
 
-
 
1828
	XtToolkitInitialize();
-
 
1829
	app_con = XtCreateApplicationContext();
-
 
1830
	/* XtAppSetFallbackResources(app_con, x_fallback_resources);*/
-
 
1831
	xtdpy = XtOpenDisplay(app_con, NULL, "r_dataentry", "R_dataentry",
-
 
1832
			      NULL, 0, &zero, NULL);
-
 
1833
	toplevel = XtAppCreateShell(NULL, "R_dataentry",
-
 
1834
				    applicationShellWidgetClass, 
-
 
1835
				    xtdpy, NULL, 0);
-
 
1836
	XtGetApplicationResources(toplevel, (XtPointer) &xdev,
-
 
1837
				  x_resources, 
-
 
1838
				  x_resource_count,
-
 
1839
				  NULL, 0);
-
 
1840
	XtDestroyWidget(toplevel);
-
 
1841
	XtCloseDisplay(xtdpy);
-
 
1842
	XtDestroyApplicationContext(app_con);
-
 
1843
	if (xdev.geometry != NULL) {
-
 
1844
	    char gstr[40];
-
 
1845
	    int bitmask;
-
 
1846
	    
-
 
1847
	    sprintf(gstr, "%dx%d+%d+%d", hint->width,
-
 
1848
		    hint->height, hint->x, hint->y);
-
 
1849
	    bitmask = XWMGeometry(iodisplay, DefaultScreen(iodisplay),
-
 
1850
				  xdev.geometry, gstr, 
-
 
1851
				  1,
-
 
1852
				  hint,
-
 
1853
				  &hint->x, &hint->y,
-
 
1854
				  &hint->width, &hint->height,
-
 
1855
				  &hint->win_gravity);
-
 
1856
	    
-
 
1857
	    if (bitmask & (XValue | YValue))
-
 
1858
		hint->flags |= USPosition;
-
 
1859
	    if (bitmask & (WidthValue | HeightValue)) 
-
 
1860
		hint->flags |= USSize;
-
 
1861
	}
-
 
1862
	ioblack = xdev.foreground;
-
 
1863
	iowhite = xdev.background;
-
 
1864
    }
-
 
1865
#endif
1788
    if ((iowindow = XCreateSimpleWindow(
1866
    if ((iowindow = XCreateSimpleWindow(
1789
	     iodisplay,
1867
	     iodisplay,
1790
	     root,
1868
	     root,
1791
	     hint->x,
1869
	     hint->x,
1792
	     hint->y,
1870
	     hint->y,
Line 1875... Line 1953...
1875
#ifdef USE_FONTSET
1953
#ifdef USE_FONTSET
1876
    if(!mbcslocale)
1954
    if(!mbcslocale)
1877
#endif
1955
#endif
1878
	XSetFont(iodisplay, iogc, font_info->fid);
1956
	XSetFont(iodisplay, iogc, font_info->fid);
1879
    XSetBackground(iodisplay, iogc, iowhite);
1957
    XSetBackground(iodisplay, iogc, iowhite);
1880
    XSetForeground(iodisplay, iogc, BlackPixel(iodisplay,
1958
    XSetForeground(iodisplay, iogc, ioblack);
1881
					       DefaultScreen(iodisplay)));
-
 
1882
    XSetLineAttributes(iodisplay, iogc, 1, LineSolid, CapRound, JoinRound);
1959
    XSetLineAttributes(iodisplay, iogc, 1, LineSolid, CapRound, JoinRound);
1883
 
1960
 
1884
    /*
1961
    /*
1885
    XSelectInput(iodisplay, iowindow,
1962
    XSelectInput(iodisplay, iowindow,
1886
		 ButtonPressMask | KeyPressMask
1963
		 ButtonPressMask | KeyPressMask
Line 1985... Line 2062...
1985
#endif
2062
#endif
1986
 
2063
 
1987
static void drawrectangle(int xpos, int ypos, int width, int height,
2064
static void drawrectangle(int xpos, int ypos, int width, int height,
1988
			  int lwd, int fore)
2065
			  int lwd, int fore)
1989
{
2066
{
-
 
2067
#ifdef USE_Xt
-
 
2068
    if (fore == 0)
-
 
2069
	XSetForeground(iodisplay, iogc, xdev.background);
-
 
2070
    else
-
 
2071
	XSetForeground(iodisplay, iogc, xdev.foreground);
-
 
2072
#else
1990
    if (fore == 0)
2073
    if (fore == 0)
1991
	XSetForeground(iodisplay, iogc, WhitePixel(iodisplay,
2074
	XSetForeground(iodisplay, iogc, WhitePixel(iodisplay,
1992
						   DefaultScreen(iodisplay)));
2075
						   DefaultScreen(iodisplay)));
1993
    else
2076
    else
1994
	XSetForeground(iodisplay, iogc, BlackPixel(iodisplay,
2077
	XSetForeground(iodisplay, iogc, BlackPixel(iodisplay,
1995
						   DefaultScreen(iodisplay)));
2078
						   DefaultScreen(iodisplay)));
-
 
2079
#endif
1996
    XSetLineAttributes(iodisplay, iogc, lwd, LineSolid, CapRound, JoinRound);
2080
    XSetLineAttributes(iodisplay, iogc, lwd, LineSolid, CapRound, JoinRound);
1997
    XDrawRectangle(iodisplay, iowindow, iogc, xpos, ypos, width, height);
2081
    XDrawRectangle(iodisplay, iowindow, iogc, xpos, ypos, width, height);
1998
}
2082
}
1999
 
2083
 
2000
static void drawtext(int xpos, int ypos, char *text, int len)
2084
static void drawtext(int xpos, int ypos, char *text, int len)