jdk/src/solaris/classes/sun/awt/X11/XAtom.java
author yan
Mon, 06 Oct 2008 16:45:00 +0400
changeset 1966 12a51fb0db0d
parent 439 3488710b02f8
child 5506 202f599c92aa
permissions -rw-r--r--
5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif Summary: Does not work on Motif but works on XToolkit now; implemented using XQueryPointer. Reviewed-by: anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
114
a777da6f3f55 6636368: XAtom contains unused code
son
parents: 2
diff changeset
     2
 * Copyright 2002-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * XAtom is a class that allows you to create and modify X Window properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * An X Atom is an identifier for a property that you can set on any X Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * Standard X Atom are defined by X11 and these atoms are defined in this class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * for convenience. Common X Atoms like <code>XA_WM_NAME</code> are used to communicate with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * Window manager to let it know the Window name. The use and protocol for these
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * atoms are defined in the Inter client communications converntions manual.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * User specified XAtoms are defined by specifying a name that gets Interned
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * by the XServer and an <code>XAtom</code> object is returned. An <code>XAtom</code> can also be created
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * by using a pre-exisiting atom like <code>XA_WM_CLASS</code>. A <code>display</code> has to be specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * in order to create an <code>XAtom</code>. <p> <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * Once an <code>XAtom</code> instance is created, you can call get and set property methods to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * set the values for a particular window. <p> <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Example usage : To set the window name for a top level: <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * XAtom xa = new XAtom(display,XAtom.XA_WM_NAME); <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * xa.setProperty(window,"Hello World");<p></code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * To get the cut buffer :<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <p><code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * XAtom xa = new XAtom(display,XAtom.XA_CUT_BUFFER0);<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * String selection = xa.getProperty(root_window);<p></code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @author  Bino George
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @since       JDK1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import sun.misc.Unsafe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
114
a777da6f3f55 6636368: XAtom contains unused code
son
parents: 2
diff changeset
    61
public final class XAtom {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    // Order of lock:  XAWTLock -> XAtom.class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /* Predefined Atoms - automatically extracted from XAtom.h */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private static Unsafe unsafe = XlibWrapper.unsafe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private static XAtom[] emptyList = new XAtom[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public static final long XA_PRIMARY=1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public static final long XA_SECONDARY=2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public static final long XA_ARC=3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public static final long XA_ATOM=4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public static final long XA_BITMAP=5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public static final long XA_CARDINAL=6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public static final long XA_COLORMAP=7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public static final long XA_CURSOR=8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public static final long XA_CUT_BUFFER0=9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public static final long XA_CUT_BUFFER1=10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public static final long XA_CUT_BUFFER2=11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public static final long XA_CUT_BUFFER3=12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public static final long XA_CUT_BUFFER4=13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public static final long XA_CUT_BUFFER5=14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public static final long XA_CUT_BUFFER6=15;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public static final long XA_CUT_BUFFER7=16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public static final long XA_DRAWABLE=17;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public static final long XA_FONT=18;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public static final long XA_INTEGER=19;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public static final long XA_PIXMAP=20;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public static final long XA_POINT=21;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public static final long XA_RECTANGLE=22;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public static final long XA_RESOURCE_MANAGER=23;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public static final long XA_RGB_COLOR_MAP=24;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public static final long XA_RGB_BEST_MAP=25;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public static final long XA_RGB_BLUE_MAP=26;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public static final long XA_RGB_DEFAULT_MAP=27;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public static final long XA_RGB_GRAY_MAP=28;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public static final long XA_RGB_GREEN_MAP=29;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public static final long XA_RGB_RED_MAP=30;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public static final long XA_STRING=31;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public static final long XA_VISUALID=32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public static final long XA_WINDOW=33;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public static final long XA_WM_COMMAND=34;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public static final long XA_WM_HINTS=35;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public static final long XA_WM_CLIENT_MACHINE=36;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public static final long XA_WM_ICON_NAME=37;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    public static final long XA_WM_ICON_SIZE=38;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public static final long XA_WM_NAME=39;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public static final long XA_WM_NORMAL_HINTS=40;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public static final long XA_WM_SIZE_HINTS=41;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public static final long XA_WM_ZOOM_HINTS=42;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public static final long XA_MIN_SPACE=43;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public static final long XA_NORM_SPACE=44;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public static final long XA_MAX_SPACE=45;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public static final long XA_END_SPACE=46;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public static final long XA_SUPERSCRIPT_X=47;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public static final long XA_SUPERSCRIPT_Y=48;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public static final long XA_SUBSCRIPT_X=49;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public static final long XA_SUBSCRIPT_Y=50;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public static final long XA_UNDERLINE_POSITION=51;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public static final long XA_UNDERLINE_THICKNESS=52 ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public static final long XA_STRIKEOUT_ASCENT=53;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public static final long XA_STRIKEOUT_DESCENT=54;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public static final long XA_ITALIC_ANGLE=55;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public static final long XA_X_HEIGHT=56;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public static final long XA_QUAD_WIDTH=57;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public static final long XA_WEIGHT=58;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public static final long XA_POINT_SIZE=59;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public static final long XA_RESOLUTION=60;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public static final long XA_COPYRIGHT=61;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public static final long XA_NOTICE=62;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public static final long XA_FONT_NAME=63;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    public static final long XA_FAMILY_NAME=64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public static final long XA_FULL_NAME=65;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public static final long XA_CAP_HEIGHT=66;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public static final long XA_WM_CLASS=67;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public static final long XA_WM_TRANSIENT_FOR=68;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public static final long XA_LAST_PREDEFINED=68;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    static HashMap<Long, XAtom> atomToAtom = new HashMap<Long, XAtom>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    static HashMap<String, XAtom> nameToAtom = new HashMap<String, XAtom>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    static void register(XAtom at) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        if (at == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        synchronized (XAtom.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            if (at.atom != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                atomToAtom.put(Long.valueOf(at.atom), at);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            if (at.name != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                nameToAtom.put(at.name, at);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    static XAtom lookup(long atom) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        synchronized (XAtom.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            return atomToAtom.get(Long.valueOf(atom));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    static XAtom lookup(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        synchronized (XAtom.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            return nameToAtom.get(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * [das]Suggestion:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * 1.Make XAtom immutable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * 2.Replace public ctors with factory methods (e.g. get() below).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    static XAtom get(long atom) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        XAtom xatom = lookup(atom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        if (xatom == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            xatom = new XAtom(XToolkit.getDisplay(), atom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        return xatom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public static XAtom get(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        XAtom xatom = lookup(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        if (xatom == null) {
114
a777da6f3f55 6636368: XAtom contains unused code
son
parents: 2
diff changeset
   178
            xatom = new XAtom(XToolkit.getDisplay(), name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        return xatom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public final String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                this.name = XlibWrapper.XGetAtomName(display, atom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            register();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    static String asString(long atom) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        XAtom at = lookup(atom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if (at == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            return Long.toString(atom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            return at.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    void register() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        register(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        if (name != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            return name + ":" + atom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            return Long.toString(atom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /* interned value of Atom */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    long atom = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /* name of atom */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    /* display for X connection */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    long display;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    /**  This constructor will create and intern a new XAtom that is specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *  by the supplied name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @param display X display to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @param name name of the XAtom to create.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    private XAtom(long display, String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        this(display, name, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public XAtom(String name, boolean autoIntern) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        this(XToolkit.getDisplay(), name, autoIntern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    /**  This constructor will create an instance of XAtom that is specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *  by the predefined XAtom specified by u <code> latom </code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @param display X display to use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @param atom a predefined XAtom.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public XAtom(long display, long atom) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        this.atom = atom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        this.display = display;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        register();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    /**  This constructor will create the instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *  and if <code>autoIntern</code> is true intern a new XAtom that is specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *  by the supplied name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @param display X display to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @param name name of the XAtom to create.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
114
a777da6f3f55 6636368: XAtom contains unused code
son
parents: 2
diff changeset
   261
    private XAtom(long display, String name, boolean autoIntern) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        this.display = display;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        if (autoIntern) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                atom = XlibWrapper.InternAtom(display,name,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        register();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Creates uninitialized instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    public XAtom() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    /**  Sets the window property for the specified window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @param window window id to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @param str value to set to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    public void setProperty(long window, String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            XlibWrapper.SetProperty(display,window,atom,str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * Sets UTF8_STRING type property. Explicitly converts str to UTF-8 byte sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    public void setPropertyUTF8(long window, String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        XAtom XA_UTF8_STRING = XAtom.get("UTF8_STRING");   /* like STRING but encoding is UTF-8 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        byte[] bdata = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            bdata = str.getBytes("UTF-8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        } catch (java.io.UnsupportedEncodingException uee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            uee.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        if (bdata != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            setAtomData(window, XA_UTF8_STRING.atom, bdata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * Sets STRING/8 type property. Explicitly converts str to Latin-1 byte sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    public void setProperty8(long window, String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        byte[] bdata = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            bdata = str.getBytes("ISO-8859-1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        } catch (java.io.UnsupportedEncodingException uee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            uee.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        if (bdata != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            setAtomData(window, XA_STRING, bdata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    /**  Gets the window property for the specified window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * @param window window id to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @param str value to set to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @return string with the property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    public String getProperty(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            return XlibWrapper.GetProperty(display,window,atom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * Auxiliary function that returns the value of 'property' of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * 'property_type' on window 'window'.  Format of the property must be 32.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    public long get32Property(long window, long property_type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        WindowPropertyGetter getter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            new WindowPropertyGetter(window, this, 0, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                                     false, property_type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            int status = getter.execute();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 114
diff changeset
   373
            if (status != XConstants.Success || getter.getData() == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            if (getter.getActualType() != property_type || getter.getActualFormat() != 32) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            return Native.getCard32(getter.getData());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            getter.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     *  Returns value of property of type CARDINAL/32 of this window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    public long getCard32Property(XBaseWindow window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        return get32Property(window.getWindow(), XA_CARDINAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * Sets property of type CARDINAL on the window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    public void setCard32Property(long window, long value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            Native.putCard32(XlibWrapper.larg1, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 114
diff changeset
   404
                atom, XA_CARDINAL, 32, XConstants.PropModeReplace,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                XlibWrapper.larg1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * Sets property of type CARDINAL/32 on the window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    public void setCard32Property(XBaseWindow window, long value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        setCard32Property(window.getWindow(), value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * Gets uninterpreted set of data from property and stores them in data_ptr.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * Property type is the same as current atom, property is current atom.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * Property format is 32. Property 'delete' is false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * Returns boolean if requested type, format, length match returned values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * and returned data pointer is not null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    public boolean getAtomData(long window, long data_ptr, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        WindowPropertyGetter getter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            new WindowPropertyGetter(window, this, 0, (long)length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                                     false, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            int status = getter.execute();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 114
diff changeset
   435
            if (status != XConstants.Success || getter.getData() == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            if (getter.getActualType() != atom
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                || getter.getActualFormat() != 32
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                || getter.getNumberOfItems() != length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            XlibWrapper.memcpy(data_ptr, getter.getData(), length*getAtomSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            getter.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * Gets uninterpreted set of data from property and stores them in data_ptr.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * Property type is <code>type</code>, property is current atom.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * Property format is 32. Property 'delete' is false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * Returns boolean if requested type, format, length match returned values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * and returned data pointer is not null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    public boolean getAtomData(long window, long type, long data_ptr, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        WindowPropertyGetter getter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            new WindowPropertyGetter(window, this, 0, (long)length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                                     false, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            int status = getter.execute();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 114
diff changeset
   469
            if (status != XConstants.Success || getter.getData() == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            if (getter.getActualType() != type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                || getter.getActualFormat() != 32
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                || getter.getNumberOfItems() != length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            XlibWrapper.memcpy(data_ptr, getter.getData(), length*getAtomSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            getter.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * Sets uninterpreted set of data into property from data_ptr.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * Property type is the same as current atom, property is current atom.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * Property format is 32. Mode is PropModeReplace. length is a number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * of items pointer by data_ptr.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    public void setAtomData(long window, long data_ptr, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 114
diff changeset
   500
                atom, atom, 32, XConstants.PropModeReplace,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                data_ptr, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * Sets uninterpreted set of data into property from data_ptr.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * Property type is <code>type</code>, property is current atom.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * Property format is 32. Mode is PropModeReplace. length is a number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * of items pointer by data_ptr.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    public void setAtomData(long window, long type, long data_ptr, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 114
diff changeset
   521
                atom, type, 32, XConstants.PropModeReplace,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                data_ptr, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * Sets uninterpreted set of data into property from data_ptr.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * Property type is <code>type</code>, property is current atom.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * Property format is 8. Mode is PropModeReplace. length is a number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * of bytes pointer by data_ptr.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    public void setAtomData8(long window, long type, long data_ptr, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 114
diff changeset
   542
                atom, type, 8, XConstants.PropModeReplace,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                data_ptr, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * Deletes property specified by this item on the window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    public void DeleteProperty(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
             XlibWrapper.XDeleteProperty(XToolkit.getDisplay(), window, atom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * Deletes property specified by this item on the window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    public void DeleteProperty(XBaseWindow window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        checkWindow(window.getWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            XlibWrapper.XDeleteProperty(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                window.getWindow(), atom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    public void setAtomData(long window, long property_type, byte[] data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        long bdata = Native.toData(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            setAtomData8(window, property_type, bdata, data.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            unsafe.freeMemory(bdata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * Auxiliary function that returns the value of 'property' of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * 'property_type' on window 'window'.  Format of the property must be 8.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    public byte[] getByteArrayProperty(long window, long property_type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        WindowPropertyGetter getter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            new WindowPropertyGetter(window, this, 0, 0xFFFF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                                     false, property_type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            int status = getter.execute();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 114
diff changeset
   605
            if (status != XConstants.Success || getter.getData() == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            if (getter.getActualType() != property_type || getter.getActualFormat() != 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            byte[] res = XlibWrapper.getStringBytes(getter.getData());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            getter.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * Interns the XAtom
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    public void intern(boolean onlyIfExists) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            atom = XlibWrapper.InternAtom(display,name, onlyIfExists?1:0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        register();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    public boolean isInterned() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                atom = XlibWrapper.InternAtom(display, name, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                register();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    public void setValues(long display, String name, long atom) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        this.display = display;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        this.atom = atom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        register();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    static int getAtomSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        return Native.getLongSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * Returns the value of property ATOM[]/32 as array of XAtom objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * @return array of atoms, array of length 0 if the atom list is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     *         or has different format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    XAtom[] getAtomListProperty(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        WindowPropertyGetter getter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            new WindowPropertyGetter(window, this, 0, 0xFFFF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                                     false, XA_ATOM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            int status = getter.execute();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 114
diff changeset
   677
            if (status != XConstants.Success || getter.getData() == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                return emptyList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            if (getter.getActualType() != XA_ATOM || getter.getActualFormat() != 32) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                return emptyList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            int count = (int)getter.getNumberOfItems();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            if (count == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                return emptyList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            long list_atoms = getter.getData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            XAtom[] res = new XAtom[count];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            for (int index = 0; index < count; index++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                res[index] = XAtom.get(XAtom.getAtom(list_atoms+index*getAtomSize()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            getter.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * Returns the value of property of type ATOM[]/32 as XAtomList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * @return list of atoms, empty list if the atom list is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     *         or has different format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    XAtomList getAtomListPropertyList(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        return new XAtomList(getAtomListProperty(window));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    XAtomList getAtomListPropertyList(XBaseWindow window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        return getAtomListPropertyList(window.getWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    XAtom[] getAtomListProperty(XBaseWindow window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        return getAtomListProperty(window.getWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * Sets property value of type ATOM list to the list of atoms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    void setAtomListProperty(long window, XAtom[] atoms) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        long data = toData(atoms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        setAtomData(window, XAtom.XA_ATOM, data, atoms.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        unsafe.freeMemory(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * Sets property value of type ATOM list to the list of atoms specified by XAtomList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    void setAtomListProperty(long window, XAtomList atoms) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        long data = atoms.getAtomsData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        setAtomData(window, XAtom.XA_ATOM, data, atoms.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        unsafe.freeMemory(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * Sets property value of type ATOM list to the list of atoms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    public void setAtomListProperty(XBaseWindow window, XAtom[] atoms) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        setAtomListProperty(window.getWindow(), atoms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * Sets property value of type ATOM list to the list of atoms specified by XAtomList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    public void setAtomListProperty(XBaseWindow window, XAtomList atoms) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        setAtomListProperty(window.getWindow(), atoms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    long getAtom() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        return atom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    void putAtom(long ptr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        Native.putLong(ptr, atom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    static long getAtom(long ptr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        return Native.getLong(ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * Allocated memory to hold the list of native atom data and returns unsafe pointer to it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * Caller should free the memory by himself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    static long toData(XAtom[] atoms) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        long data = unsafe.allocateMemory(getAtomSize() * atoms.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        for (int i = 0; i < atoms.length; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            if (atoms[i] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                atoms[i].putAtom(data + i * getAtomSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        return data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    void checkWindow(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        if (window == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            throw new IllegalArgumentException("Window must not be zero");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    public boolean equals(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        if (!(o instanceof XAtom)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        XAtom ot = (XAtom)o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        return (atom == ot.atom && display == ot.display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        return (int)((atom ^ display)& 0xFFFFL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * Sets property on the <code>window</code> to the value <code>window_value</window>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * Property is assumed to be of type WINDOW/32
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    public void setWindowProperty(long window, long window_value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            Native.putWindow(XlibWrapper.larg1, window_value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 114
diff changeset
   800
                                    atom, XA_WINDOW, 32, XConstants.PropModeReplace,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                                    XlibWrapper.larg1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    public void setWindowProperty(XBaseWindow window, XBaseWindow window_value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        setWindowProperty(window.getWindow(), window_value.getWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * Gets property on the <code>window</code>. Property is assumed to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * of type WINDOW/32.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    public long getWindowProperty(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        WindowPropertyGetter getter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            new WindowPropertyGetter(window, this, 0, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                                     false, XA_WINDOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            int status = getter.execute();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 114
diff changeset
   824
            if (status != XConstants.Success || getter.getData() == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            if (getter.getActualType() != XA_WINDOW || getter.getActualFormat() != 32) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            return Native.getWindow(getter.getData());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
            getter.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
}