1 | /* Copyright (C) 2000 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 | // Needed to avoid linking in libstdc++
|
---|
10 | #ifndef __STL_USE_EXCEPTIONS
|
---|
11 | # include <java/lang/OutOfMemoryError.h>
|
---|
12 | # define __THROW_BAD_ALLOC throw new java::lang::OutOfMemoryError()
|
---|
13 | #endif
|
---|
14 |
|
---|
15 | #include <vector>
|
---|
16 |
|
---|
17 | #include <X11/Xlib.h>
|
---|
18 | #include <gcj/cni.h>
|
---|
19 | #include <java/awt/Rectangle.h>
|
---|
20 | #include <gnu/gcj/xlib/Display.h>
|
---|
21 | #include <gnu/gcj/xlib/Window.h>
|
---|
22 | #include <gnu/gcj/xlib/WindowAttributes.h>
|
---|
23 | #include <gnu/gcj/xlib/Visual.h>
|
---|
24 | #include <gnu/gcj/xlib/XException.h>
|
---|
25 |
|
---|
26 | jint gnu::gcj::xlib::Window::createChildXID(java::awt::Rectangle* bounds,
|
---|
27 | jint borderWidth,
|
---|
28 | WindowAttributes* attributes,
|
---|
29 | jint windowIOClass,
|
---|
30 | Visual* visual)
|
---|
31 | {
|
---|
32 | ::Window parentXID = xid;
|
---|
33 |
|
---|
34 | int x = bounds->x;
|
---|
35 | int y = bounds->y;
|
---|
36 | int width = bounds->width;
|
---|
37 | int height = bounds->height;
|
---|
38 |
|
---|
39 | long mask = attributes->mask;
|
---|
40 | XSetWindowAttributes* attr = (XSetWindowAttributes*)
|
---|
41 | attributes->getXSetWindowAttributesStructure();
|
---|
42 |
|
---|
43 | ::Visual* vis = CopyFromParent;
|
---|
44 | int depth = CopyFromParent;
|
---|
45 | if (visual != 0)
|
---|
46 | {
|
---|
47 | vis = (::Visual*) visual->getVisualStructure();
|
---|
48 | depth = visual->getDepth();
|
---|
49 | }
|
---|
50 |
|
---|
51 | ::Window childXID = XCreateWindow((::Display*) (display->display),
|
---|
52 | parentXID,
|
---|
53 | x, y, width, height,
|
---|
54 | borderWidth, depth, windowIOClass,
|
---|
55 | vis,
|
---|
56 | mask, attr);
|
---|
57 | // no fast fail
|
---|
58 | return childXID;
|
---|
59 | }
|
---|
60 |
|
---|
61 | void gnu::gcj::xlib::Window::destroy()
|
---|
62 | {
|
---|
63 | ::Display* dpy = (::Display*) (display->display);
|
---|
64 | ::Window window = xid;
|
---|
65 | XDestroyWindow(dpy, window);
|
---|
66 | // no fast fail
|
---|
67 | }
|
---|
68 |
|
---|
69 | void gnu::gcj::xlib::Window::setAttributes(WindowAttributes* attributes)
|
---|
70 | {
|
---|
71 | ::Display* dpy = (::Display*) (display->display);
|
---|
72 | ::Window window = xid;
|
---|
73 | ::XSetWindowAttributes* attr = (::XSetWindowAttributes*)
|
---|
74 | attributes->getXSetWindowAttributesStructure();
|
---|
75 |
|
---|
76 | XChangeWindowAttributes(dpy, window, attributes->mask, attr);
|
---|
77 | // no fast fail
|
---|
78 | }
|
---|
79 |
|
---|
80 | void gnu::gcj::xlib::Window::map()
|
---|
81 | {
|
---|
82 | ::Display* dpy = (::Display*) (display->display);
|
---|
83 | ::Window window = xid;
|
---|
84 | XMapWindow(dpy, window);
|
---|
85 | // no fast fail
|
---|
86 | }
|
---|
87 |
|
---|
88 | void gnu::gcj::xlib::Window::unmap()
|
---|
89 | {
|
---|
90 | ::Display* dpy = (::Display*) (display->display);
|
---|
91 | ::Window window = xid;
|
---|
92 | XUnmapWindow(dpy, window);
|
---|
93 | // no fast fail
|
---|
94 | }
|
---|
95 |
|
---|
96 | void gnu::gcj::xlib::Window::setProperty(jint nameAtom, jint typeAtom,
|
---|
97 | jbyteArray data)
|
---|
98 | {
|
---|
99 | ::Display* dpy = (::Display*) (display->display);
|
---|
100 | int format = 8;
|
---|
101 | int mode = PropModeReplace;
|
---|
102 | unsigned char* pData = (unsigned char*) elements(data);
|
---|
103 | int len = data->length;
|
---|
104 |
|
---|
105 | XChangeProperty(dpy, xid, nameAtom, typeAtom, format, mode,
|
---|
106 | pData, len);
|
---|
107 | // no fast fail
|
---|
108 | }
|
---|
109 |
|
---|
110 | void gnu::gcj::xlib::Window::setWMProtocols(jintArray atoms)
|
---|
111 | {
|
---|
112 | ::Display* dpy = (::Display*) (display->display);
|
---|
113 |
|
---|
114 | size_t length = atoms->length;
|
---|
115 | jint* atomsBegin = elements(atoms);
|
---|
116 | jint* atomsEnd = atomsBegin + length;
|
---|
117 |
|
---|
118 | // Avoid confusion between Xlib.h and Atom.java "Atom" types.
|
---|
119 | typedef ::Atom XLibAtom;
|
---|
120 |
|
---|
121 | std::vector<XLibAtom> atomVector(atomsBegin, atomsEnd);
|
---|
122 | XLibAtom* atomsArray = &(atomVector.front());
|
---|
123 |
|
---|
124 | XSetWMProtocols(dpy, xid, atomsArray, length);
|
---|
125 | // no fail fast
|
---|
126 | }
|
---|
127 |
|
---|
128 | jintArray gnu::gcj::xlib::Window::getWMProtocols()
|
---|
129 | {
|
---|
130 | ::Display* dpy = (::Display*) (display->display);
|
---|
131 |
|
---|
132 | ::Atom* protocolsReturn;
|
---|
133 | int countReturn;
|
---|
134 |
|
---|
135 | Status success = XGetWMProtocols(dpy, xid, &protocolsReturn,
|
---|
136 | &countReturn);
|
---|
137 |
|
---|
138 | if (!success)
|
---|
139 | throw new XException(JvNewStringLatin1("cannot get "
|
---|
140 | "WM protocols "));
|
---|
141 |
|
---|
142 | jintArray atoms;
|
---|
143 | try
|
---|
144 | {
|
---|
145 | ::Atom* protocolsBegin = protocolsReturn;
|
---|
146 | ::Atom* protocolsEnd = protocolsBegin + countReturn;
|
---|
147 |
|
---|
148 | atoms = JvNewIntArray(countReturn);
|
---|
149 | jint* atomsBegin = elements(atoms);
|
---|
150 |
|
---|
151 | std::copy(protocolsBegin, protocolsEnd, atomsBegin);
|
---|
152 |
|
---|
153 | }
|
---|
154 | catch (...)
|
---|
155 | {
|
---|
156 | XFree(protocolsReturn);
|
---|
157 | throw;
|
---|
158 | }
|
---|
159 | XFree(protocolsReturn);
|
---|
160 |
|
---|
161 | return atoms;
|
---|
162 | }
|
---|
163 |
|
---|
164 | void gnu::gcj::xlib::Window::setBounds(jint x, jint y,
|
---|
165 | jint width, jint height)
|
---|
166 | {
|
---|
167 | ::Display* dpy = (::Display*) (display->display);
|
---|
168 |
|
---|
169 | XMoveResizeWindow(dpy, xid, x, y, width, height);
|
---|
170 | // no fast fail
|
---|
171 | }
|
---|