1 | /* Copyright (C) 2000, 2003 Free Software Foundation
|
---|
2 |
|
---|
3 | This file is part of libgcj.
|
---|
4 |
|
---|
5 | This software is copyrighted work licensed under the terms of the
|
---|
6 | Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
|
---|
7 | details. */
|
---|
8 |
|
---|
9 | #include <vector>
|
---|
10 |
|
---|
11 | #include <X11/Xlib.h>
|
---|
12 |
|
---|
13 | #include <gcj/cni.h>
|
---|
14 | #include <gcj/array.h>
|
---|
15 | #include <gnu/gcj/RawData.h>
|
---|
16 | #include <java/lang/String.h>
|
---|
17 | #include <java/awt/Rectangle.h>
|
---|
18 |
|
---|
19 | #include <gnu/gcj/xlib/Display.h>
|
---|
20 | #include <gnu/gcj/xlib/XID.h>
|
---|
21 | #include <gnu/gcj/xlib/Drawable.h>
|
---|
22 | #include <gnu/gcj/xlib/Font.h>
|
---|
23 | #include <gnu/gcj/xlib/XImage.h>
|
---|
24 | #include <gnu/gcj/xlib/XException.h>
|
---|
25 | #include <gnu/gcj/xlib/Clip.h>
|
---|
26 | #include <gnu/gcj/xlib/GC.h>
|
---|
27 | #include <gnu/gcj/xlib/XException.h>
|
---|
28 |
|
---|
29 | typedef java::awt::Rectangle AWTRect;
|
---|
30 | typedef JArray<AWTRect*> AWTRectArray;
|
---|
31 | typedef std::vector<XRectangle> XRectVector;
|
---|
32 |
|
---|
33 | void gnu::gcj::xlib::GC::initStructure(GC* copyFrom)
|
---|
34 | {
|
---|
35 | Display* display = target->getDisplay();
|
---|
36 | ::Display* dpy = (::Display*) (display->display);
|
---|
37 | ::Drawable drawableXID = target->getXID();
|
---|
38 |
|
---|
39 | ::GC gc = XCreateGC(dpy, drawableXID, 0, 0);
|
---|
40 |
|
---|
41 | if (gc == 0)
|
---|
42 | throw new XException(JvNewStringLatin1("GC creation failed"));
|
---|
43 |
|
---|
44 | if (copyFrom != 0)
|
---|
45 | {
|
---|
46 | ::GC fromGC = (::GC) copyFrom->structure;
|
---|
47 | XCopyGC(dpy, fromGC, ~0, gc);
|
---|
48 | // no fast fail
|
---|
49 | }
|
---|
50 |
|
---|
51 | structure = reinterpret_cast<gnu::gcj::RawData*>(gc);
|
---|
52 | }
|
---|
53 |
|
---|
54 | void gnu::gcj::xlib::GC::disposeImpl()
|
---|
55 | {
|
---|
56 | gnu::gcj::RawData* lStructure = structure;
|
---|
57 | Drawable* lTargetType = target;
|
---|
58 |
|
---|
59 | if ((lStructure == 0) || (lTargetType == 0))
|
---|
60 | return;
|
---|
61 |
|
---|
62 | structure = 0;
|
---|
63 | target = 0;
|
---|
64 |
|
---|
65 | Display* display = lTargetType->getDisplay();
|
---|
66 | ::Display* dpy = (::Display*) (display->display);
|
---|
67 | ::GC gc = (::GC) lStructure;
|
---|
68 |
|
---|
69 | XFreeGC(dpy, gc);
|
---|
70 | // no fast fail
|
---|
71 | }
|
---|
72 |
|
---|
73 | void gnu::gcj::xlib::GC::setForeground(jlong pixel)
|
---|
74 | {
|
---|
75 | Display* display = target->getDisplay();
|
---|
76 | ::Display* dpy = (::Display*) (display->display);
|
---|
77 | ::GC gc = (::GC) structure;
|
---|
78 | XSetForeground(dpy, gc, pixel);
|
---|
79 | // no fast fail
|
---|
80 | }
|
---|
81 |
|
---|
82 | void gnu::gcj::xlib::GC::setFont(Font* font)
|
---|
83 | {
|
---|
84 | Display* display = target->getDisplay();
|
---|
85 | ::Display* dpy = (::Display*) (display->display);
|
---|
86 | ::GC gc = (::GC) structure;
|
---|
87 | XSetFont(dpy, gc, font->getXID());
|
---|
88 | // no fast fail
|
---|
89 | }
|
---|
90 |
|
---|
91 | void gnu::gcj::xlib::GC::drawString(jstring text, jint x, jint y)
|
---|
92 | {
|
---|
93 | Display* display = target->getDisplay();
|
---|
94 | ::Display* dpy = (::Display*) (display->display);
|
---|
95 | ::Drawable drawableXID = target->getXID();
|
---|
96 | ::GC gc = (::GC) structure;
|
---|
97 |
|
---|
98 | /*
|
---|
99 | FIXME: do something along the lines of the following instead:
|
---|
100 |
|
---|
101 | jint length = text->length();
|
---|
102 | jchar* txt = JvGetStringChars(text);
|
---|
103 |
|
---|
104 | XChar2b xwchars[length];
|
---|
105 |
|
---|
106 | // FIXME: Add convertion and caching
|
---|
107 |
|
---|
108 | for (int i=0; i<length; i++)
|
---|
109 | {
|
---|
110 | XChar2b* xc = &(xwchars[i]);
|
---|
111 | jchar jc = txt[i];
|
---|
112 | xc->byte1 = jc & 0xff;
|
---|
113 | xc->byte2 = jc >> 8;
|
---|
114 | }
|
---|
115 |
|
---|
116 | XDrawString16(dpy, drawableXID, gc, x, y, xwchars, length);
|
---|
117 | */
|
---|
118 |
|
---|
119 | // FIXME, temporary code:
|
---|
120 | int len = JvGetStringUTFLength(text);
|
---|
121 | char ctxt[len+1];
|
---|
122 | JvGetStringUTFRegion(text, 0, text->length(), ctxt);
|
---|
123 | ctxt[len] = '\0';
|
---|
124 | XDrawString(dpy, drawableXID, gc, x, y, ctxt, len);
|
---|
125 | // no fast fail
|
---|
126 | }
|
---|
127 |
|
---|
128 | void gnu::gcj::xlib::GC::drawLine(jint x1, jint y1, jint x2, jint y2)
|
---|
129 | {
|
---|
130 | Display* display = target->getDisplay();
|
---|
131 | ::Display* dpy = (::Display*) (display->display);
|
---|
132 | ::Drawable drawableXID = target->getXID();
|
---|
133 | ::GC gc = (::GC) structure;
|
---|
134 | XDrawLine(dpy, drawableXID, gc, x1, y1, x2, y2);
|
---|
135 | // no fast fail
|
---|
136 | }
|
---|
137 |
|
---|
138 | void gnu::gcj::xlib::GC::drawRectangle(jint x, jint y, jint w, jint h)
|
---|
139 | {
|
---|
140 | Display* display = target->getDisplay();
|
---|
141 | ::Display* dpy = (::Display*) (display->display);
|
---|
142 | ::Drawable drawableXID = target->getXID();
|
---|
143 | ::GC gc = (::GC) structure;
|
---|
144 | XDrawRectangle(dpy, drawableXID, gc, x, y, w, h);
|
---|
145 | // no fast fail
|
---|
146 | }
|
---|
147 |
|
---|
148 | void gnu::gcj::xlib::GC::fillRectangle(jint x, jint y, jint w, jint h)
|
---|
149 | {
|
---|
150 | Display* display = target->getDisplay();
|
---|
151 | ::Display* dpy = (::Display*) (display->display);
|
---|
152 | ::Drawable drawableXID = target->getXID();
|
---|
153 | ::GC gc = (::GC) structure;
|
---|
154 | XFillRectangle(dpy, drawableXID, gc, x, y, w, h);
|
---|
155 | // no fast fail
|
---|
156 | }
|
---|
157 |
|
---|
158 | void gnu::gcj::xlib::GC::fillPolygon(jintArray xPoints, jintArray yPoints,
|
---|
159 | jint nPoints,
|
---|
160 | jint translateX, jint translateY)
|
---|
161 | {
|
---|
162 | Display* display = target->getDisplay();
|
---|
163 | ::Display* dpy = (::Display*) (display->display);
|
---|
164 | ::Drawable drawableXID = target->getXID();
|
---|
165 | ::GC gc = (::GC) structure;
|
---|
166 | typedef ::XPoint xpoint;
|
---|
167 | std::vector<xpoint> points(nPoints+1);
|
---|
168 | for (int i=0; i<nPoints; i++)
|
---|
169 | {
|
---|
170 | points[i].x = elements(xPoints)[i] + translateX;
|
---|
171 | points[i].y = elements(yPoints)[i] + translateY;
|
---|
172 | }
|
---|
173 | points[nPoints] = points[0];
|
---|
174 | XFillPolygon(dpy, drawableXID, gc, &(points.front()), nPoints,
|
---|
175 | Complex, CoordModeOrigin);
|
---|
176 | // no fast fail
|
---|
177 | }
|
---|
178 |
|
---|
179 | void gnu::gcj::xlib::GC::clearArea(jint x, jint y, jint w, jint h,
|
---|
180 | jboolean exposures)
|
---|
181 | {
|
---|
182 | Display* display = target->getDisplay();
|
---|
183 | ::Display* dpy = (::Display*) (display->display);
|
---|
184 | ::Drawable drawableXID = target->getXID();
|
---|
185 |
|
---|
186 | XClearArea(dpy, drawableXID, x, y, w, h,
|
---|
187 | exposures ? True : False);
|
---|
188 | // no fast fail
|
---|
189 | }
|
---|
190 |
|
---|
191 |
|
---|
192 | void gnu::gcj::xlib::GC::putImage(XImage* image,
|
---|
193 | jint srcX, jint srcY,
|
---|
194 | jint destX, jint destY,
|
---|
195 | jint width, jint height)
|
---|
196 | {
|
---|
197 | Display* display = target->getDisplay();
|
---|
198 | ::Display* dpy = (::Display*) (display->display);
|
---|
199 | ::Drawable drawableXID = target->getXID();
|
---|
200 | ::GC gc = (::GC) structure;
|
---|
201 | ::XImage* ximage = (::XImage*) (image->structure);
|
---|
202 |
|
---|
203 | XPutImage(dpy, drawableXID, gc, ximage,
|
---|
204 | srcX, srcY,
|
---|
205 | destX, destY,
|
---|
206 | width, height);
|
---|
207 | // no fast fail
|
---|
208 | }
|
---|
209 |
|
---|
210 | void gnu::gcj::xlib::GC::updateClip()
|
---|
211 | {
|
---|
212 | if (clip == 0)
|
---|
213 | return;
|
---|
214 |
|
---|
215 | Display* display = target->getDisplay();
|
---|
216 | ::Display* dpy = (::Display*) (display->display);
|
---|
217 | ::GC gc = (::GC) structure;
|
---|
218 |
|
---|
219 | XRectVector* xrectvector = (XRectVector*) (clip->xrects);
|
---|
220 | int numRect = xrectvector->size();
|
---|
221 |
|
---|
222 | int originX = 0;
|
---|
223 | int originY = 0;
|
---|
224 | int ordering = Unsorted;
|
---|
225 | XSetClipRectangles(dpy, gc, originX, originY,
|
---|
226 | &(xrectvector->front()), numRect,
|
---|
227 | ordering);
|
---|
228 | // no fast fail
|
---|
229 | }
|
---|