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
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()
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
,
28 WindowAttributes
* attributes
,
32 ::Window parentXID
= xid
;
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
;
47 vis
= (::Visual
*) visual
->getVisualStructure();
48 depth
= visual
->getDepth();
51 ::Window childXID
= XCreateWindow((::Display
*) (display
->display
),
54 borderWidth
, depth
, windowIOClass
,
61 void gnu::gcj::xlib::Window::destroy()
63 ::Display
* dpy
= (::Display
*) (display
->display
);
64 ::Window window
= xid
;
65 XDestroyWindow(dpy
, window
);
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
);
80 void gnu::gcj::xlib::Window::toBack()
82 ::Display
* dpy
= (::Display
*) (display
->display
);
83 ::Window window
= xid
;
84 XLowerWindow(dpy
, window
);
87 void gnu::gcj::xlib::Window::toFront()
89 ::Display
* dpy
= (::Display
*) (display
->display
);
90 ::Window window
= xid
;
91 XRaiseWindow(dpy
, window
);
94 void gnu::gcj::xlib::Window::map()
96 ::Display
* dpy
= (::Display
*) (display
->display
);
97 ::Window window
= xid
;
98 XMapWindow(dpy
, window
);
102 void gnu::gcj::xlib::Window::unmap()
104 ::Display
* dpy
= (::Display
*) (display
->display
);
105 ::Window window
= xid
;
106 XUnmapWindow(dpy
, window
);
110 void gnu::gcj::xlib::Window::setProperty(jint nameAtom
, jint typeAtom
,
113 ::Display
* dpy
= (::Display
*) (display
->display
);
115 int mode
= PropModeReplace
;
116 unsigned char* pData
= (unsigned char*) elements(data
);
117 int len
= data
->length
;
119 XChangeProperty(dpy
, xid
, nameAtom
, typeAtom
, format
, mode
,
124 void gnu::gcj::xlib::Window::setWMProtocols(jintArray atoms
)
126 ::Display
* dpy
= (::Display
*) (display
->display
);
128 size_t length
= atoms
->length
;
129 jint
* atomsBegin
= elements(atoms
);
130 jint
* atomsEnd
= atomsBegin
+ length
;
132 // Avoid confusion between Xlib.h and Atom.java "Atom" types.
133 typedef ::Atom XLibAtom
;
135 std::vector
<XLibAtom
> atomVector(atomsBegin
, atomsEnd
);
136 XLibAtom
* atomsArray
= &(atomVector
.front());
138 XSetWMProtocols(dpy
, xid
, atomsArray
, length
);
142 jintArray
gnu::gcj::xlib::Window::getWMProtocols()
144 ::Display
* dpy
= (::Display
*) (display
->display
);
146 ::Atom
* protocolsReturn
;
149 Status success
= XGetWMProtocols(dpy
, xid
, &protocolsReturn
,
153 throw new XException(JvNewStringLatin1("cannot get "
159 ::Atom
* protocolsBegin
= protocolsReturn
;
160 ::Atom
* protocolsEnd
= protocolsBegin
+ countReturn
;
162 atoms
= JvNewIntArray(countReturn
);
163 jint
* atomsBegin
= elements(atoms
);
165 std::copy(protocolsBegin
, protocolsEnd
, atomsBegin
);
170 XFree(protocolsReturn
);
173 XFree(protocolsReturn
);
178 void gnu::gcj::xlib::Window::setBounds(jint x
, jint y
,
179 jint width
, jint height
)
181 ::Display
* dpy
= (::Display
*) (display
->display
);
183 XMoveResizeWindow(dpy
, xid
, x
, y
, width
, height
);