jdk/src/solaris/classes/sun/awt/X11/XFramePeer.java
author yan
Mon, 06 Oct 2008 16:45:00 +0400
changeset 1966 12a51fb0db0d
parent 449 7820f232278d
child 2453 35e5fab82613
permissions -rw-r--r--
5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif Summary: Does not work on Motif but works on XToolkit now; implemented using XQueryPointer. Reviewed-by: anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
     2
 * Copyright 2002-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    27
import java.awt.Color;
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    28
import java.awt.Dimension;
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    29
import java.awt.Font;
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    30
import java.awt.FontMetrics;
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    31
import java.awt.Frame;
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    32
import java.awt.Graphics;
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    33
import java.awt.Insets;
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    34
import java.awt.MenuBar;
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    35
import java.awt.Rectangle;
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    36
import java.awt.peer.FramePeer;
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    37
import java.util.logging.Level;
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
    38
import java.util.logging.Logger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 129
diff changeset
    40
class XFramePeer extends XDecoratedPeer implements FramePeer {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private static Logger log = Logger.getLogger("sun.awt.X11.XFramePeer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private static Logger stateLog = Logger.getLogger("sun.awt.X11.states");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private static Logger insLog = Logger.getLogger("sun.awt.X11.insets.XFramePeer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    XMenuBarPeer menubarPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    MenuBar menubar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    int state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private Boolean undecorated;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private static final int MENUBAR_HEIGHT_IF_NO_MENUBAR = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private int lastAppliedMenubarHeight = MENUBAR_HEIGHT_IF_NO_MENUBAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    XFramePeer(Frame target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        super(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    XFramePeer(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        super(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    void preInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        super.preInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        Frame target = (Frame)(this.target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        // set the window attributes for this Frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        winAttr.initialState = target.getExtendedState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        state = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        undecorated = Boolean.valueOf(target.isUndecorated());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        winAttr.nativeDecor = !target.isUndecorated();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        if (winAttr.nativeDecor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            winAttr.decorations = winAttr.AWT_DECOR_ALL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            winAttr.decorations = winAttr.AWT_DECOR_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        }
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 129
diff changeset
    74
        winAttr.functions = MWMConstants.MWM_FUNC_ALL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        winAttr.isResizable = true; // target.isResizable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        winAttr.title = target.getTitle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        winAttr.initialResizability = target.isResizable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        if (log.isLoggable(Level.FINE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            log.log(Level.FINE, "Frame''s initial attributes: decor {0}, resizable {1}, undecorated {2}, initial state {3}",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                     new Object[] {Integer.valueOf(winAttr.decorations), Boolean.valueOf(winAttr.initialResizability),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                                   Boolean.valueOf(!winAttr.nativeDecor), Integer.valueOf(winAttr.initialState)});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    void postInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        super.postInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        setupState(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
129
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 107
diff changeset
    90
    @Override
f995b9c9c5fa 6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents: 107
diff changeset
    91
    boolean isTargetUndecorated() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        if (undecorated != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            return undecorated.booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            return ((Frame)target).isUndecorated();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    void setupState(boolean onInit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        if (onInit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            state = winAttr.initialState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        if ((state & Frame.ICONIFIED) != 0) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 129
diff changeset
   104
            setInitialState(XUtilConstants.IconicState);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        } else {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 129
diff changeset
   106
            setInitialState(XUtilConstants.NormalState);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        setExtendedState(state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public void setMenuBar(MenuBar mb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        // state_lock should always be the second after awt_lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            synchronized(getStateLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                if (mb == menubar) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                if (mb == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                    if (menubar != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                        menubarPeer.xSetVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                        menubar = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                        menubarPeer.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                        menubarPeer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                    menubar = mb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                    menubarPeer = (XMenuBarPeer) mb.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                    if (menubarPeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                        menubarPeer.init((Frame)target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        reshapeMenubarPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    XMenuBarPeer getMenubarPeer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        return menubarPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    int getMenuBarHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        if (menubarPeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            return menubarPeer.getDesiredHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            return MENUBAR_HEIGHT_IF_NO_MENUBAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    void updateChildrenSizes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        super.updateChildrenSizes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        // XWindow.reshape calls XBaseWindow.xSetBounds, which acquires
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        // the AWT lock, so we have to acquire the AWT lock here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        // before getStateLock() to avoid a deadlock with the Toolkit thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        // when this method is called on the EDT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            synchronized(getStateLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                int width = dimensions.getClientSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                if (menubarPeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                    menubarPeer.reshape(0, 0, width, getMenuBarHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * In addition to reshaping menubarPeer (by using 'updateChildrenSizes')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * this method also performs some frame reaction on this (i.e. layouts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * other frame children, if required)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    final void reshapeMenubarPeer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        XToolkit.executeOnEventHandlerThread(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                    updateChildrenSizes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                    boolean heightChanged = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                    int height = getMenuBarHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                        // Neither 'XToolkit.awtLock()' nor 'getStateLock()'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                        // is acquired under this call, and it looks to run
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                        // thread-safely. I currently see no reason to move
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                        // it under following 'synchronized' clause.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                    synchronized(getStateLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                        if (height != lastAppliedMenubarHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                            lastAppliedMenubarHeight = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                            heightChanged = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                    if (heightChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                        // To make frame contents be re-layout (copied from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                        // 'XDecoratedPeer.revalidate()'). These are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                        // 'synchronized', because can recursively call client
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                        // methods, which are not supposed to be called with locks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                        // acquired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                        target.invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                        target.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public void setMaximizedBounds(Rectangle b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        if (insLog.isLoggable(Level.FINE)) insLog.fine("Setting maximized bounds to " + b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        if (b == null) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        maxBounds = new Rectangle(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            XSizeHints hints = getHints();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 129
diff changeset
   216
            hints.set_flags(hints.get_flags() | (int)XUtilConstants.PMaxSize);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            if (b.width != Integer.MAX_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                hints.set_max_width(b.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                hints.set_max_width((int)XlibWrapper.DisplayWidth(XToolkit.getDisplay(), XlibWrapper.DefaultScreen(XToolkit.getDisplay())));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            if (b.height != Integer.MAX_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                hints.set_max_height(b.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                hints.set_max_height((int)XlibWrapper.DisplayHeight(XToolkit.getDisplay(), XlibWrapper.DefaultScreen(XToolkit.getDisplay())));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            if (insLog.isLoggable(Level.FINER)) insLog.finer("Setting hints, flags " + XlibWrapper.hintsToString(hints.get_flags()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            XlibWrapper.XSetWMNormalHints(XToolkit.getDisplay(), window, hints.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public int getState() { return state; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public void setState(int newState) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        if (!isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            stateLog.finer("Frame is not showing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            state = newState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        changeState(newState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    void changeState(int newState) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        int changed = state ^ newState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        int changeIconic = changed & Frame.ICONIFIED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        boolean iconic = (newState & Frame.ICONIFIED) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        stateLog.log(Level.FINER, "Changing state, old state {0}, new state {1}(iconic {2})",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                     new Object[] {Integer.valueOf(state), Integer.valueOf(newState), Boolean.valueOf(iconic)});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        if (changeIconic != 0 && iconic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            if (stateLog.isLoggable(Level.FINER)) stateLog.finer("Iconifying shell " + getShell() + ", this " + this + ", screen " + getScreenNumber());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                int res = XlibWrapper.XIconifyWindow(XToolkit.getDisplay(), getShell(), getScreenNumber());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                if (stateLog.isLoggable(Level.FINER)) stateLog.finer("XIconifyWindow returned " + res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        if ((changed & ~Frame.ICONIFIED) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            setExtendedState(newState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        if (changeIconic != 0 && !iconic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            if (stateLog.isLoggable(Level.FINER)) stateLog.finer("DeIconifying " + this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            xSetVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    void setExtendedState(int newState) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        XWM.getWM().setExtendedState(this, newState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    public void handlePropertyNotify(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        super.handlePropertyNotify(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        XPropertyEvent ev = xev.get_xproperty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        log.log(Level.FINER, "Property change {0}", new Object[] {ev});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
         * Let's see if this is a window state protocol message, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
         * if it is - decode a new state in terms of java constants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
         */
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
   284
        if (!XWM.getWM().isStateChange(this, ev)) {
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
   285
            stateLog.finer("either not a state atom or state has not been changed");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
   289
        final int newState = XWM.getWM().getState(this);
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
   290
        int changed = state ^ newState;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        if (changed == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            stateLog.finer("State is the same: " + state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        int old_state = state;
107
ed0c7cfb3666 6632140: minor refactoring for XWM
son
parents: 2
diff changeset
   297
        state = newState;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        if ((changed & Frame.ICONIFIED) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            if ((state & Frame.ICONIFIED) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                stateLog.finer("Iconified");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                handleIconify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                stateLog.finer("DeIconified");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                content.purgeIconifiedExposeEvents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                handleDeiconify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        handleStateChange(old_state, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    public void handleStateChange(int oldState, int newState) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        super.handleStateChange(oldState, newState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        for (ToplevelStateListener topLevelListenerTmp : toplevelStateListeners) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            topLevelListenerTmp.stateChangedJava(oldState, newState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    public void setVisible(boolean vis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        if (vis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            setupState(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            if ((state & Frame.MAXIMIZED_BOTH) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                XWM.getWM().setExtendedState(this, state & ~Frame.MAXIMIZED_BOTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        super.setVisible(vis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        if (vis && maxBounds != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            setMaximizedBounds(maxBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    void setInitialState(int wm_state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            XWMHints hints = getWMHints();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 129
diff changeset
   339
            hints.set_flags((int)XUtilConstants.StateHint | hints.get_flags());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            hints.set_initial_state(wm_state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            if (stateLog.isLoggable(Level.FINE)) stateLog.fine("Setting initial WM state on " + this + " to " + wm_state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            XlibWrapper.XSetWMHints(XToolkit.getDisplay(), getWindow(), hints.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        if (menubarPeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            menubarPeer.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        super.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    boolean isMaximized() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        return (state & (Frame.MAXIMIZED_VERT  | Frame.MAXIMIZED_HORIZ)) != 0;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    static final int CROSSHAIR_INSET = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    static final int BUTTON_Y = CROSSHAIR_INSET + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    static final int BUTTON_W = 17;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    static final int BUTTON_H = 17;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    static final int SYS_MENU_X = CROSSHAIR_INSET + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    static final int SYS_MENU_CONTAINED_X = SYS_MENU_X + 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    static final int SYS_MENU_CONTAINED_Y = BUTTON_Y + 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    static final int SYS_MENU_CONTAINED_W = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    static final int SYS_MENU_CONTAINED_H = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    static final int MAXIMIZE_X_DIFF = CROSSHAIR_INSET + BUTTON_W;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    static final int MAXIMIZE_CONTAINED_X_DIFF = MAXIMIZE_X_DIFF - 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    static final int MAXIMIZE_CONTAINED_Y = BUTTON_Y + 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    static final int MAXIMIZE_CONTAINED_W = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    static final int MAXIMIZE_CONTAINED_H = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    static final int MINIMIZE_X_DIFF = MAXIMIZE_X_DIFF + BUTTON_W;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    static final int MINIMIZE_CONTAINED_X_DIFF = MINIMIZE_X_DIFF - 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    static final int MINIMIZE_CONTAINED_Y = BUTTON_Y + 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    static final int MINIMIZE_CONTAINED_W = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    static final int MINIMIZE_CONTAINED_H = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    static final int TITLE_X = SYS_MENU_X + BUTTON_W;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    static final int TITLE_W_DIFF = BUTTON_W * 3 + CROSSHAIR_INSET * 2 - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    static final int TITLE_MID_Y = BUTTON_Y + (BUTTON_H / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    static final int MENUBAR_X = CROSSHAIR_INSET + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    static final int MENUBAR_Y = BUTTON_Y + BUTTON_H;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    static final int HORIZ_RESIZE_INSET = CROSSHAIR_INSET + BUTTON_H;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    static final int VERT_RESIZE_INSET = CROSSHAIR_INSET + BUTTON_W;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * Print the native component by rendering the Motif look ourselves.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * We also explicitly print the MenuBar since a MenuBar isn't a subclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * of Component (and thus it has no "print" method which gets called by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * default).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    public void print(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        super.print(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        Frame f = (Frame)target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        Insets finsets = f.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        Dimension fsize = f.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        Color bg = f.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        Color fg = f.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        Color highlight = bg.brighter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        Color shadow = bg.darker();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        // Well, we could query for the currently running window manager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        // and base the look on that, or we could just always do dtwm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        // aim, tball, and levenson all agree we'll just do dtwm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        if (hasDecorations(XWindowAttributesData.AWT_DECOR_BORDER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            // top outer -- because we'll most likely be drawing on white paper,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            // for aesthetic reasons, don't make any part of the outer border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            // pure white
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            if (highlight.equals(Color.white)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                g.setColor(new Color(230, 230, 230));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            g.drawLine(0, 0, fsize.width, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            g.drawLine(0, 1, fsize.width - 1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            // left outer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            // if (highlight.equals(Color.white)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            //     g.setColor(new Color(230, 230, 230));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            // }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            // else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            //     g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            // }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            g.drawLine(0, 0, 0, fsize.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            g.drawLine(1, 0, 1, fsize.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            // bottom cross-hair
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            g.drawLine(CROSSHAIR_INSET + 1, fsize.height - CROSSHAIR_INSET,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                       fsize.width - CROSSHAIR_INSET,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                       fsize.height - CROSSHAIR_INSET);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            // right cross-hair
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            // g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            g.drawLine(fsize.width - CROSSHAIR_INSET, CROSSHAIR_INSET + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                       fsize.width - CROSSHAIR_INSET,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                       fsize.height - CROSSHAIR_INSET);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            // bottom outer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            g.drawLine(1, fsize.height, fsize.width, fsize.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            g.drawLine(2, fsize.height - 1, fsize.width, fsize.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            // right outer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            // g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            g.drawLine(fsize.width, 1, fsize.width, fsize.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            g.drawLine(fsize.width - 1, 2, fsize.width - 1, fsize.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            // top cross-hair
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            // g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            g.drawLine(CROSSHAIR_INSET, CROSSHAIR_INSET,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                       fsize.width - CROSSHAIR_INSET, CROSSHAIR_INSET);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            // left cross-hair
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            // g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            g.drawLine(CROSSHAIR_INSET, CROSSHAIR_INSET, CROSSHAIR_INSET,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                       fsize.height - CROSSHAIR_INSET);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        if (hasDecorations(XWindowAttributesData.AWT_DECOR_TITLE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            if (hasDecorations(XWindowAttributesData.AWT_DECOR_MENU)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                // system menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                g.setColor(bg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                g.fill3DRect(SYS_MENU_X, BUTTON_Y, BUTTON_W, BUTTON_H, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                g.fill3DRect(SYS_MENU_CONTAINED_X, SYS_MENU_CONTAINED_Y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                             SYS_MENU_CONTAINED_W, SYS_MENU_CONTAINED_H, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            // title bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            // g.setColor(bg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            g.fill3DRect(TITLE_X, BUTTON_Y, fsize.width - TITLE_W_DIFF, BUTTON_H,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                         true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            if (hasDecorations(XWindowAttributesData.AWT_DECOR_MINIMIZE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                // minimize button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                // g.setColor(bg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                g.fill3DRect(fsize.width - MINIMIZE_X_DIFF, BUTTON_Y, BUTTON_W,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                             BUTTON_H, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                g.fill3DRect(fsize.width - MINIMIZE_CONTAINED_X_DIFF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                             MINIMIZE_CONTAINED_Y, MINIMIZE_CONTAINED_W,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                             MINIMIZE_CONTAINED_H, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            if (hasDecorations(XWindowAttributesData.AWT_DECOR_MAXIMIZE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                // maximize button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                // g.setColor(bg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                g.fill3DRect(fsize.width - MAXIMIZE_X_DIFF, BUTTON_Y, BUTTON_W,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                             BUTTON_H, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                g.fill3DRect(fsize.width - MAXIMIZE_CONTAINED_X_DIFF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                             MAXIMIZE_CONTAINED_Y, MAXIMIZE_CONTAINED_W,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                             MAXIMIZE_CONTAINED_H, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            // title bar text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            g.setColor(fg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            Font sysfont = new Font(Font.SANS_SERIF, Font.PLAIN, 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            g.setFont(sysfont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            FontMetrics sysfm = g.getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            String ftitle = f.getTitle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            g.drawString(ftitle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                         ((TITLE_X + TITLE_X + fsize.width - TITLE_W_DIFF) / 2) -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                         (sysfm.stringWidth(ftitle) / 2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                         TITLE_MID_Y + sysfm.getMaxDescent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        if (f.isResizable() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            hasDecorations(XWindowAttributesData.AWT_DECOR_RESIZEH)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            // add resize cross hairs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            // upper-left horiz (shadow)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            g.drawLine(1, HORIZ_RESIZE_INSET, CROSSHAIR_INSET,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                       HORIZ_RESIZE_INSET);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            // upper-left vert (shadow)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            // g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            g.drawLine(VERT_RESIZE_INSET, 1, VERT_RESIZE_INSET, CROSSHAIR_INSET);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            // upper-right horiz (shadow)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            // g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            g.drawLine(fsize.width - CROSSHAIR_INSET + 1, HORIZ_RESIZE_INSET,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                       fsize.width, HORIZ_RESIZE_INSET);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            // upper-right vert (shadow)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            // g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            g.drawLine(fsize.width - VERT_RESIZE_INSET - 1, 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                       fsize.width - VERT_RESIZE_INSET - 1, CROSSHAIR_INSET + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            // lower-left horiz (shadow)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            // g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            g.drawLine(1, fsize.height - HORIZ_RESIZE_INSET - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                       CROSSHAIR_INSET, fsize.height - HORIZ_RESIZE_INSET - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            // lower-left vert (shadow)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            // g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            g.drawLine(VERT_RESIZE_INSET, fsize.height - CROSSHAIR_INSET + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                       VERT_RESIZE_INSET, fsize.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            // lower-right horiz (shadow)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            // g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            g.drawLine(fsize.width - CROSSHAIR_INSET + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                       fsize.height - HORIZ_RESIZE_INSET - 1, fsize.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                       fsize.height - HORIZ_RESIZE_INSET - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            // lower-right vert (shadow)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            // g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            g.drawLine(fsize.width - VERT_RESIZE_INSET - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                       fsize.height - CROSSHAIR_INSET + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                       fsize.width - VERT_RESIZE_INSET - 1, fsize.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            // upper-left horiz (highlight)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            g.drawLine(2, HORIZ_RESIZE_INSET + 1, CROSSHAIR_INSET,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                       HORIZ_RESIZE_INSET + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            // upper-left vert (highlight)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            // g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            g.drawLine(VERT_RESIZE_INSET + 1, 2, VERT_RESIZE_INSET + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                       CROSSHAIR_INSET);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            // upper-right horiz (highlight)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            // g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            g.drawLine(fsize.width - CROSSHAIR_INSET + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                       HORIZ_RESIZE_INSET + 1, fsize.width - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                       HORIZ_RESIZE_INSET + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            // upper-right vert (highlight)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            // g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            g.drawLine(fsize.width - VERT_RESIZE_INSET, 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                       fsize.width - VERT_RESIZE_INSET, CROSSHAIR_INSET);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            // lower-left horiz (highlight)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            // g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            g.drawLine(2, fsize.height - HORIZ_RESIZE_INSET, CROSSHAIR_INSET,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                       fsize.height - HORIZ_RESIZE_INSET);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            // lower-left vert (highlight)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            // g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            g.drawLine(VERT_RESIZE_INSET + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                       fsize.height - CROSSHAIR_INSET + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                       VERT_RESIZE_INSET + 1, fsize.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            // lower-right horiz (highlight)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            // g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            g.drawLine(fsize.width - CROSSHAIR_INSET + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                       fsize.height - HORIZ_RESIZE_INSET, fsize.width - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                       fsize.height - HORIZ_RESIZE_INSET);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            // lower-right vert (highlight)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            // g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            g.drawLine(fsize.width - VERT_RESIZE_INSET,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                       fsize.height - CROSSHAIR_INSET + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                       fsize.width - VERT_RESIZE_INSET, fsize.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        XMenuBarPeer peer = menubarPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            Insets insets = getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            Graphics ng = g.create();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            int menubarX = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            int menubarY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            if (hasDecorations(XWindowAttributesData.AWT_DECOR_BORDER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                menubarX += CROSSHAIR_INSET + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                    menubarY += CROSSHAIR_INSET + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            if (hasDecorations(XWindowAttributesData.AWT_DECOR_TITLE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                menubarY += BUTTON_H;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                ng.translate(menubarX, menubarY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                peer.print(ng);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                ng.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    public void setBoundsPrivate(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        setBounds(x, y, width, height, SET_BOUNDS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    public Rectangle getBoundsPrivate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        return getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
}