Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / gnu / gcj / xlib / natGC.cc
blob4529ebb609fb82cf553edf98b88bc4bdb7e1658e
1 /* Copyright (C) 2000, 2003 Free Software Foundation
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
7 details. */
9 #include <vector>
11 #include <X11/Xlib.h>
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>
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>
29 typedef java::awt::Rectangle AWTRect;
30 typedef JArray<AWTRect*> AWTRectArray;
31 typedef std::vector<XRectangle> XRectVector;
33 void gnu::gcj::xlib::GC::initStructure(GC* copyFrom)
35 Display* display = target->getDisplay();
36 ::Display* dpy = (::Display*) (display->display);
37 ::GC gc = (::GC) structure;
38 if (gc == 0)
40 // If we haven't already created a GC, create one now
41 ::Drawable drawableXID = target->getXID();
42 gc = XCreateGC(dpy, drawableXID, 0, 0);
43 structure = reinterpret_cast<gnu::gcj::RawData*>(gc);
44 if (gc == 0)
45 throw new XException(JvNewStringLatin1("GC creation failed"));
48 if (copyFrom != 0)
50 ::GC fromGC = (::GC) copyFrom->structure;
51 XCopyGC(dpy, fromGC, ~0, gc);
52 // no fast fail
56 void gnu::gcj::xlib::GC::disposeImpl()
58 gnu::gcj::RawData* lStructure = structure;
59 Drawable* lTargetType = target;
61 if ((lStructure == 0) || (lTargetType == 0))
62 return;
64 structure = 0;
65 target = 0;
67 Display* display = lTargetType->getDisplay();
68 ::Display* dpy = (::Display*) (display->display);
69 ::GC gc = (::GC) lStructure;
71 XFreeGC(dpy, gc);
72 // no fast fail
75 void gnu::gcj::xlib::GC::setForeground(jlong pixel)
77 Display* display = target->getDisplay();
78 ::Display* dpy = (::Display*) (display->display);
79 ::GC gc = (::GC) structure;
80 XSetForeground(dpy, gc, pixel);
81 // no fast fail
84 void gnu::gcj::xlib::GC::setFont(Font* font)
86 Display* display = target->getDisplay();
87 ::Display* dpy = (::Display*) (display->display);
88 ::GC gc = (::GC) structure;
89 XSetFont(dpy, gc, font->getXID());
90 // no fast fail
93 void gnu::gcj::xlib::GC::drawString(jstring text, jint x, jint y)
95 Display* display = target->getDisplay();
96 ::Display* dpy = (::Display*) (display->display);
97 ::Drawable drawableXID = target->getXID();
98 ::GC gc = (::GC) structure;
100 jint length = text->length();
101 jchar* txt = JvGetStringChars(text);
103 XChar2b xwchars[length];
105 // FIXME: Convert to the character set used in the font, which may
106 // or may not be unicode. For now, treat everything as 16-bit and
107 // use character codes directly, which should be OK for unicode or
108 // 8-bit ascii fonts.
110 for (int i=0; i<length; i++)
112 XChar2b* xc = &(xwchars[i]);
113 jchar jc = txt[i];
114 xc->byte1 = (jc >> 8) & 0xff;
115 xc->byte2 = jc & 0xff;
117 XDrawString16(dpy, drawableXID, gc, x, y, xwchars, length);
120 void gnu::gcj::xlib::GC::drawPoint(jint x, jint y)
122 Display* display = target->getDisplay();
123 ::Display* dpy = (::Display*) (display->display);
124 ::Drawable drawableXID = target->getXID();
125 ::GC gc = (::GC) structure;
126 XDrawPoint (dpy, drawableXID, gc, x, y);
129 void gnu::gcj::xlib::GC::drawLine(jint x1, jint y1, jint x2, jint y2)
131 Display* display = target->getDisplay();
132 ::Display* dpy = (::Display*) (display->display);
133 ::Drawable drawableXID = target->getXID();
134 ::GC gc = (::GC) structure;
135 XDrawLine(dpy, drawableXID, gc, x1, y1, x2, y2);
136 // no fast fail
139 void gnu::gcj::xlib::GC::drawRectangle(jint x, jint y, jint w, jint h)
141 Display* display = target->getDisplay();
142 ::Display* dpy = (::Display*) (display->display);
143 ::Drawable drawableXID = target->getXID();
144 ::GC gc = (::GC) structure;
145 XDrawRectangle(dpy, drawableXID, gc, x, y, w, h);
146 // no fast fail
149 void gnu::gcj::xlib::GC::fillRectangle(jint x, jint y, jint w, jint h)
151 Display* display = target->getDisplay();
152 ::Display* dpy = (::Display*) (display->display);
153 ::Drawable drawableXID = target->getXID();
154 ::GC gc = (::GC) structure;
155 XFillRectangle(dpy, drawableXID, gc, x, y, w, h);
156 // no fast fail
159 void gnu::gcj::xlib::GC::drawArc(jint x, jint y, jint w, jint h,jint startAngle, jint arcAngle)
161 Display* display = target->getDisplay();
162 ::Display* dpy = (::Display*) (display->display);
163 ::Drawable drawableXID = target->getXID();
164 ::GC gc = (::GC) structure;
165 XDrawArc(dpy, drawableXID, gc, x, y, w, h, startAngle * 64, arcAngle * 64);
168 void gnu::gcj::xlib::GC::fillArc(jint x, jint y, jint w, jint h,jint startAngle, jint arcAngle)
170 Display* display = target->getDisplay();
171 ::Display* dpy = (::Display*) (display->display);
172 ::Drawable drawableXID = target->getXID();
173 ::GC gc = (::GC) structure;
174 XFillArc(dpy, drawableXID, gc, x, y, w, h, startAngle * 64, arcAngle * 64);
177 void gnu::gcj::xlib::GC::fillPolygon(jintArray xPoints, jintArray yPoints,
178 jint nPoints,
179 jint translateX, jint translateY)
181 Display* display = target->getDisplay();
182 ::Display* dpy = (::Display*) (display->display);
183 ::Drawable drawableXID = target->getXID();
184 ::GC gc = (::GC) structure;
185 typedef ::XPoint xpoint;
186 std::vector<xpoint> points(nPoints+1);
187 for (int i=0; i<nPoints; i++)
189 points[i].x = elements(xPoints)[i] + translateX;
190 points[i].y = elements(yPoints)[i] + translateY;
192 points[nPoints] = points[0];
193 XFillPolygon(dpy, drawableXID, gc, &(points.front()), nPoints,
194 Complex, CoordModeOrigin);
195 // no fast fail
198 void gnu::gcj::xlib::GC::clearArea(jint x, jint y, jint w, jint h,
199 jboolean exposures)
201 Display* display = target->getDisplay();
202 ::Display* dpy = (::Display*) (display->display);
203 ::Drawable drawableXID = target->getXID();
205 XClearArea(dpy, drawableXID, x, y, w, h,
206 exposures ? True : False);
207 // no fast fail
211 void gnu::gcj::xlib::GC::putImage(XImage* image,
212 jint srcX, jint srcY,
213 jint destX, jint destY,
214 jint width, jint height)
216 Display* display = target->getDisplay();
217 ::Display* dpy = (::Display*) (display->display);
218 ::Drawable drawableXID = target->getXID();
219 ::GC gc = (::GC) structure;
220 ::XImage* ximage = (::XImage*) (image->structure);
222 XPutImage(dpy, drawableXID, gc, ximage,
223 srcX, srcY,
224 destX, destY,
225 width, height);
226 // no fast fail
229 void gnu::gcj::xlib::GC::updateClip(AWTRectArray* rectangles)
231 int numRect = JvGetArrayLength(rectangles);
232 XRectVector* xrectvector = new XRectVector(numRect);
234 for (int i=0; i<numRect; i++)
236 AWTRect* awtrect = elements(rectangles)[i];
237 XRectangle& xrect = (*xrectvector)[i];
239 xrect.x = awtrect->x;
240 xrect.y = awtrect->y;
241 xrect.width = awtrect->width;
242 xrect.height = awtrect->height;
245 Display* display = target->getDisplay();
246 ::Display* dpy = (::Display*) (display->display);
247 ::GC gc = (::GC) structure;
249 int originX = 0;
250 int originY = 0;
251 int ordering = Unsorted;
252 XSetClipRectangles(dpy, gc, originX, originY,
253 &(xrectvector->front()), numRect,
254 ordering);
255 delete xrectvector;
258 void gnu::gcj::xlib::GC::copyArea (gnu::gcj::xlib::Drawable * source,
259 jint srcX, jint srcY,
260 jint destX, jint destY,
261 jint width, jint height)
263 Display* display = target->getDisplay ();
264 ::Display* dpy = (::Display*) (display->display);
265 ::Drawable drawableXID = target->getXID ();
266 ::GC gc = (::GC) structure;
267 ::Drawable srcXID = source->getXID ();
269 XCopyArea (dpy, srcXID, drawableXID, gc, srcX, srcY, width, height,
270 destX, destY);