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::map()
82 ::Display
* dpy
= (::Display
*) (display
->display
);
83 ::Window window
= xid
;
84 XMapWindow(dpy
, window
);
88 void gnu::gcj::xlib::Window::unmap()
90 ::Display
* dpy
= (::Display
*) (display
->display
);
91 ::Window window
= xid
;
92 XUnmapWindow(dpy
, window
);
96 void gnu::gcj::xlib::Window::setProperty(jint nameAtom
, jint typeAtom
,
99 ::Display
* dpy
= (::Display
*) (display
->display
);
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
,
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
);
128 jintArray
gnu::gcj::xlib::Window::getWMProtocols()
130 ::Display
* dpy
= (::Display
*) (display
->display
);
132 ::Atom
* protocolsReturn
;
135 Status success
= XGetWMProtocols(dpy
, xid
, &protocolsReturn
,
139 throw new XException(JvNewStringLatin1("cannot get "
145 ::Atom
* protocolsBegin
= protocolsReturn
;
146 ::Atom
* protocolsEnd
= protocolsBegin
+ countReturn
;
148 atoms
= JvNewIntArray(countReturn
);
149 jint
* atomsBegin
= elements(atoms
);
151 std::copy(protocolsBegin
, protocolsEnd
, atomsBegin
);
156 XFree(protocolsReturn
);
159 XFree(protocolsReturn
);
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
);