001: /*
002: * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: /**
027: * This class is a placeholder for all internal static objects that represent
028: * system state. We keep our representation up-to-date with actual system
029: * state by tracking events, such as X Focus, Component under cursor etc.
030: * All attributes should be static private with accessors to simpify change
031: * tracking.
032: */package sun.awt.X11;
033:
034: import java.awt.Component;
035: import java.lang.ref.WeakReference;
036:
037: class XAwtState {
038: /**
039: * The mouse is over this component.
040: * If the component is not disabled, it received MOUSE_ENTERED but no MOUSE_EXITED.
041: */
042: private static WeakReference componentMouseEnteredRef = null;
043:
044: static void setComponentMouseEntered(Component component) {
045: XToolkit.awtLock();
046: try {
047: if (component == null) {
048: componentMouseEnteredRef = null;
049: return;
050: }
051: if (component != getComponentMouseEntered()) {
052: componentMouseEnteredRef = new WeakReference(component);
053: }
054: } finally {
055: XToolkit.awtUnlock();
056: }
057: }
058:
059: static Component getComponentMouseEntered() {
060: XToolkit.awtLock();
061: try {
062: if (componentMouseEnteredRef == null) {
063: return null;
064: }
065: return (Component) componentMouseEnteredRef.get();
066: } finally {
067: XToolkit.awtUnlock();
068: }
069: }
070:
071: /**
072: * The XBaseWindow is created with OwnerGrabButtonMask
073: * (see X vol. 1, 8.3.3.2) so inside the app Key, Motion, and Button events
074: * are received by the window they actualy happened on, not the grabber.
075: * Then XBaseWindow dispatches them to the grabber. As a result
076: * XAnyEvent.get_window() returns actual window the event is originated,
077: * though the event is dispatched by the grabber.
078: */
079: private static boolean inManualGrab = false;
080:
081: static boolean isManualGrab() {
082: return inManualGrab;
083: }
084:
085: private static WeakReference grabWindowRef = null;
086:
087: /**
088: * The X Active Grab overrides any other active grab by the same
089: * client see XGrabPointer, XGrabKeyboard
090: */
091: static void setGrabWindow(XBaseWindow grabWindow) {
092: setGrabWindow(grabWindow, false);
093: }
094:
095: /**
096: * Automatic passive grab doesn't override active grab see XGrabButton
097: */
098: static void setAutoGrabWindow(XBaseWindow grabWindow) {
099: setGrabWindow(grabWindow, true);
100: }
101:
102: private static void setGrabWindow(XBaseWindow grabWindow,
103: boolean isAutoGrab) {
104: XToolkit.awtLock();
105: try {
106: if (inManualGrab && isAutoGrab) {
107: return;
108: }
109: inManualGrab = grabWindow != null && !isAutoGrab;
110: if (grabWindow == null) {
111: grabWindowRef = null;
112: return;
113: }
114: if (grabWindow != getGrabWindow()) {
115: grabWindowRef = new WeakReference(grabWindow);
116: }
117: } finally {
118: XToolkit.awtUnlock();
119: }
120: }
121:
122: static XBaseWindow getGrabWindow() {
123: XToolkit.awtLock();
124: try {
125: if (grabWindowRef == null) {
126: return null;
127: }
128: XBaseWindow xbw = (XBaseWindow) grabWindowRef.get();
129: if (xbw != null && xbw.isDisposed()) {
130: xbw = null;
131: grabWindowRef = null;
132: } else if (xbw == null) {
133: grabWindowRef = null;
134: }
135: return xbw;
136: } finally {
137: XToolkit.awtUnlock();
138: }
139: }
140: }
|