jdk/src/solaris/classes/sun/awt/X11/XContentWindow.java
author dcherepanov
Mon, 07 Dec 2009 13:43:04 +0300
changeset 4371 dc9dcb8b0ae7
parent 4214 0fa32d38146b
child 5506 202f599c92aa
permissions -rw-r--r--
6823138: Need to replace ComponentAccessor with AWTAccessor Reviewed-by: art, anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
115
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
     2
 * Copyright 2003-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.event.ComponentEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 439
diff changeset
    33
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4214
diff changeset
    35
import sun.awt.AWTAccessor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * This class implements window which serves as content window for decorated frames.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * Its purpose to provide correct events dispatching for the complex
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * constructs such as decorated frames.
115
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
    41
 *
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
    42
 * It should always be located at (- left inset, - top inset) in the associated
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
    43
 * decorated window.  So coordinates in it would be the same as java coordinates.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 115
diff changeset
    45
public final class XContentWindow extends XWindow {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 439
diff changeset
    46
    private static PlatformLogger insLog = PlatformLogger.getLogger("sun.awt.X11.insets.XContentWindow");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
115
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
    48
    static XContentWindow createContent(XDecoratedPeer parentFrame) {
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
    49
        final WindowDimensions dims = parentFrame.getDimensions();
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
    50
        Rectangle rec = dims.getBounds();
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
    51
        // Fix for  - set the location of the content window to the (-left inset, -top inset)
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
    52
        Insets ins = dims.getInsets();
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
    53
        if (ins != null) {
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
    54
            rec.x = -ins.left;
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
    55
            rec.y = -ins.top;
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
    56
        } else {
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
    57
            rec.x = 0;
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
    58
            rec.y = 0;
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
    59
        }
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
    60
        final XContentWindow cw = new XContentWindow(parentFrame, rec);
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
    61
        cw.xSetVisible(true);
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
    62
        return cw;
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
    63
    }
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
    64
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
    65
    private final XDecoratedPeer parentFrame;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    // A list of expose events that come when the parentFrame is iconified
115
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
    68
    private final java.util.List<SavedExposeEvent> iconifiedExposeEvents =
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
    69
            new java.util.ArrayList<SavedExposeEvent>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
115
e270c597a3ad 6645885: small refactoring for XContentWindow
son
parents: 2
diff changeset
    71
    private XContentWindow(XDecoratedPeer parentFrame, Rectangle bounds) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        super((Component)parentFrame.getTarget(), parentFrame.getShell(), bounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        this.parentFrame = parentFrame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    void preInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        super.preInit(params);
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 115
diff changeset
    78
        params.putIfNull(BIT_GRAVITY, Integer.valueOf(XConstants.NorthWestGravity));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        Long eventMask = (Long)params.get(EVENT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        if (eventMask != null) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 115
diff changeset
    81
            eventMask = eventMask & ~(XConstants.StructureNotifyMask);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            params.put(EVENT_MASK, eventMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    protected String getWMName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        return "Content window";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    protected boolean isEventDisabled(XEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        switch (e.get_type()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
          // Override parentFrame to receive MouseEnter/Exit
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 115
diff changeset
    92
          case XConstants.EnterNotify:
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 115
diff changeset
    93
          case XConstants.LeaveNotify:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
              return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
          // We handle ConfigureNotify specifically in XDecoratedPeer
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 115
diff changeset
    96
          case XConstants.ConfigureNotify:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
              return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
          // We don't want SHOWN/HIDDEN on content window since it will duplicate XDecoratedPeer
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 115
diff changeset
    99
          case XConstants.MapNotify:
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 115
diff changeset
   100
          case XConstants.UnmapNotify:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
              return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
              return super.isEventDisabled(e) || parentFrame.isEventDisabled(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    // Coordinates are that of the shell
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    void setContentBounds(WindowDimensions dims) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            // Bounds of content window are of the same size as bounds of Java window and with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            // location as -(insets)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            Rectangle newBounds = dims.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            Insets in = dims.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            if (in != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                newBounds.setLocation(-in.left, -in.top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            }
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 439
diff changeset
   118
            if (insLog.isLoggable(PlatformLogger.FINE)) insLog.fine("Setting content bounds {0}, old bounds {1}",
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 439
diff changeset
   119
                                                                    newBounds, getBounds());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            // Fix for 5023533:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            // Change in the size of the content window means, well, change of the size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            // Change in the location of the content window means change in insets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            boolean needHandleResize = !(newBounds.equals(getBounds()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            reshape(newBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            if (needHandleResize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                insLog.fine("Sending RESIZED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                handleResize(newBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        validateSurface();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public void handleResize(Rectangle bounds) {
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4214
diff changeset
   138
        AWTAccessor.getComponentAccessor().setSize((Component)target, bounds.width, bounds.height);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        postEvent(new ComponentEvent(target, ComponentEvent.COMPONENT_RESIZED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public void handleExposeEvent(Component target, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        // TODO: ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        // get rid of 'istanceof' by subclassing:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        // XContentWindow -> XFrameContentWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        // Expose event(s) that result from deiconification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        // come before a deicinofication notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        // We reorder these events by saving all expose events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        // that come when the frame is iconified. Then we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        // actually handle saved expose events on deiconification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        if (parentFrame instanceof XFramePeer &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                (((XFramePeer)parentFrame).getState() & java.awt.Frame.ICONIFIED) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            // Save expose events if the frame is iconified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            // in order to handle them on deiconification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            iconifiedExposeEvents.add(new SavedExposeEvent(target, x, y, w, h));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            // Normal case: [it is not a frame or] the frame is not iconified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            super.handleExposeEvent(target, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    void purgeIconifiedExposeEvents() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        for (SavedExposeEvent evt : iconifiedExposeEvents) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            super.handleExposeEvent(evt.target, evt.x, evt.y, evt.w, evt.h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        iconifiedExposeEvents.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    private static class SavedExposeEvent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        Component target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        int x, y, w, h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        SavedExposeEvent(Component target, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            this.target = target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            this.x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            this.y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            this.w = w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            this.h = h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        return getClass().getName() + "[" + getBounds() + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
}