001: /*
002: * Copyright 2002-2007 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: package sun.awt.X11;
026:
027: import java.util.*;
028: import java.awt.*;
029: import java.awt.peer.*;
030: import java.awt.event.*;
031: import sun.awt.ComponentAccessor;
032:
033: import sun.awt.*;
034:
035: class XDialogPeer extends XDecoratedPeer implements DialogPeer {
036:
037: private Boolean undecorated;
038:
039: XDialogPeer(Dialog target) {
040: super (target);
041: }
042:
043: public void preInit(XCreateWindowParams params) {
044: super .preInit(params);
045:
046: Dialog target = (Dialog) (this .target);
047: undecorated = Boolean.valueOf(target.isUndecorated());
048: winAttr.nativeDecor = !target.isUndecorated();
049: if (winAttr.nativeDecor) {
050: winAttr.decorations = winAttr.AWT_DECOR_ALL;
051: } else {
052: winAttr.decorations = winAttr.AWT_DECOR_NONE;
053: }
054: winAttr.functions = MWM_FUNC_ALL;
055: winAttr.isResizable = true; //target.isResizable();
056: winAttr.initialResizability = target.isResizable();
057: winAttr.title = target.getTitle();
058: winAttr.initialState = XWindowAttributesData.NORMAL;
059: }
060:
061: public void setVisible(boolean vis) {
062: XToolkit.awtLock();
063: try {
064: Dialog target = (Dialog) this .target;
065: if (vis) {
066: if (target.getModalityType() != Dialog.ModalityType.MODELESS) {
067: if (!isModalBlocked()) {
068: XBaseWindow.ungrabInput();
069: }
070: }
071: } else {
072: restoreTransientFor(this );
073: prevTransientFor = null;
074: nextTransientFor = null;
075: }
076: } finally {
077: XToolkit.awtUnlock();
078: }
079:
080: super .setVisible(vis);
081: }
082:
083: protected Insets guessInsets() {
084: if (isTargetUndecorated()) {
085: return new Insets(0, 0, 0, 0);
086: } else {
087: return super .guessInsets();
088: }
089: }
090:
091: private boolean isTargetUndecorated() {
092: if (undecorated != null) {
093: return undecorated.booleanValue();
094: } else {
095: return ((Dialog) target).isUndecorated();
096: }
097: }
098:
099: int getDecorations() {
100: int d = super .getDecorations();
101: // remove minimize and maximize buttons for dialogs
102: if ((d & MWM_DECOR_ALL) != 0) {
103: d |= (MWM_DECOR_MINIMIZE | MWM_DECOR_MAXIMIZE);
104: } else {
105: d &= ~(MWM_DECOR_MINIMIZE | MWM_DECOR_MAXIMIZE);
106: }
107: return d;
108: }
109:
110: int getFunctions() {
111: int f = super .getFunctions();
112: // remove minimize and maximize functions for dialogs
113: if ((f & MWM_FUNC_ALL) != 0) {
114: f |= (MWM_FUNC_MINIMIZE | MWM_FUNC_MAXIMIZE);
115: } else {
116: f &= ~(MWM_FUNC_MINIMIZE | MWM_FUNC_MAXIMIZE);
117: }
118: return f;
119: }
120:
121: public void blockWindows(java.util.List<Window> toBlock) {
122: Vector<XWindowPeer> javaToplevels = null;
123: XToolkit.awtLock();
124: try {
125: javaToplevels = XWindowPeer.collectJavaToplevels();
126: for (Window w : toBlock) {
127: XWindowPeer wp = (XWindowPeer) ComponentAccessor
128: .getPeer(w);
129: if (wp != null) {
130: wp.setModalBlocked((Dialog) target, true,
131: javaToplevels);
132: }
133: }
134: } finally {
135: XToolkit.awtUnlock();
136: }
137: }
138:
139: /*
140: * WARNING: don't call client code in this method!
141: *
142: * The check is performed before the dialog is shown.
143: * The focused window can't be blocked at the time it's focused.
144: * Thus we don't have to perform any transitive (a blocker of a blocker) checks.
145: */
146: boolean isFocusedWindowModalBlocker() {
147: Window focusedWindow = XKeyboardFocusManagerPeer
148: .getCurrentNativeFocusedWindow();
149: XWindowPeer focusedWindowPeer = null;
150:
151: if (focusedWindow != null) {
152: focusedWindowPeer = (XWindowPeer) ComponentAccessor
153: .getPeer(focusedWindow);
154: } else {
155: /*
156: * For the case when a potential blocked window is not yet focused
157: * on the Java level (e.g. it's just been mapped) we're asking for the
158: * focused window on the native level.
159: */
160: focusedWindowPeer = getNativeFocusedWindowPeer();
161: }
162: synchronized (getStateLock()) {
163: if (focusedWindowPeer != null
164: && focusedWindowPeer.modalBlocker == target) {
165: return true;
166: }
167: }
168: return super.isFocusedWindowModalBlocker();
169: }
170: }
|