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