PageRenderTime 247ms CodeModel.GetById 48ms RepoModel.GetById 11ms app.codeStats 0ms

/bm/baremetal/eclipse/gnu/gcj/xlib/natGC.cc

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