2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / gnu / gcj / xlib / natWindow.cc
blob6600795574f5809b8a0cf300051f67c6b12500d8
1 /* Copyright (C) 2000 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 // 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
15 #include <vector>
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>
26 jint gnu::gcj::xlib::Window::createChildXID(java::awt::Rectangle* bounds,
27 jint borderWidth,
28 WindowAttributes* attributes,
29 jint windowIOClass,
30 Visual* visual)
32 ::Window parentXID = xid;
34 int x = bounds->x;
35 int y = bounds->y;
36 int width = bounds->width;
37 int height = bounds->height;
39 long mask = attributes->mask;
40 XSetWindowAttributes* attr = (XSetWindowAttributes*)
41 attributes->getXSetWindowAttributesStructure();
43 ::Visual* vis = CopyFromParent;
44 int depth = CopyFromParent;
45 if (visual != 0)
47 vis = (::Visual*) visual->getVisualStructure();
48 depth = visual->getDepth();
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;
61 void gnu::gcj::xlib::Window::destroy()
63 ::Display* dpy = (::Display*) (display->display);
64 ::Window window = xid;
65 XDestroyWindow(dpy, window);
66 // no fast fail
69 void gnu::gcj::xlib::Window::setAttributes(WindowAttributes* attributes)
71 ::Display* dpy = (::Display*) (display->display);
72 ::Window window = xid;
73 ::XSetWindowAttributes* attr = (::XSetWindowAttributes*)
74 attributes->getXSetWindowAttributesStructure();
76 XChangeWindowAttributes(dpy, window, attributes->mask, attr);
77 // no fast fail
80 void gnu::gcj::xlib::Window::map()
82 ::Display* dpy = (::Display*) (display->display);
83 ::Window window = xid;
84 XMapWindow(dpy, window);
85 // no fast fail
88 void gnu::gcj::xlib::Window::unmap()
90 ::Display* dpy = (::Display*) (display->display);
91 ::Window window = xid;
92 XUnmapWindow(dpy, window);
93 // no fast fail
96 void gnu::gcj::xlib::Window::setProperty(jint nameAtom, jint typeAtom,
97 jbyteArray data)
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;
105 XChangeProperty(dpy, xid, nameAtom, typeAtom, format, mode,
106 pData, len);
107 // no fast fail
110 void gnu::gcj::xlib::Window::setWMProtocols(jintArray atoms)
112 ::Display* dpy = (::Display*) (display->display);
114 size_t length = atoms->length;
115 jint* atomsBegin = elements(atoms);
116 jint* atomsEnd = atomsBegin + length;
118 // Avoid confusion between Xlib.h and Atom.java "Atom" types.
119 typedef ::Atom XLibAtom;
121 std::vector<XLibAtom> atomVector(atomsBegin, atomsEnd);
122 XLibAtom* atomsArray = &(atomVector.front());
124 XSetWMProtocols(dpy, xid, atomsArray, length);
125 // no fail fast
128 jintArray gnu::gcj::xlib::Window::getWMProtocols()
130 ::Display* dpy = (::Display*) (display->display);
132 ::Atom* protocolsReturn;
133 int countReturn;
135 Status success = XGetWMProtocols(dpy, xid, &protocolsReturn,
136 &countReturn);
138 if (!success)
139 throw new XException(JvNewStringLatin1("cannot get "
140 "WM protocols "));
142 jintArray atoms;
145 ::Atom* protocolsBegin = protocolsReturn;
146 ::Atom* protocolsEnd = protocolsBegin + countReturn;
148 atoms = JvNewIntArray(countReturn);
149 jint* atomsBegin = elements(atoms);
151 std::copy(protocolsBegin, protocolsEnd, atomsBegin);
154 catch (...)
156 XFree(protocolsReturn);
157 throw;
159 XFree(protocolsReturn);
161 return atoms;
164 void gnu::gcj::xlib::Window::setBounds(jint x, jint y,
165 jint width, jint height)
167 ::Display* dpy = (::Display*) (display->display);
169 XMoveResizeWindow(dpy, xid, x, y, width, height);
170 // no fast fail