jdk/src/solaris/classes/sun/awt/X11/XMenuBarPeer.java
author darcy
Thu, 13 Mar 2014 12:40:27 -0700
changeset 23647 41d22f2dbeb5
parent 22584 eed64ee05369
child 24538 25bf8153fbfe
permissions -rw-r--r--
8033712: Fix more serial lint warnings in sun.awt Reviewed-by: alanb, serb, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 18178
diff changeset
     2
 * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    23
 * questions.
2
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.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.peer.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Vector;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
    32
import sun.util.logging.PlatformLogger;
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 10096
diff changeset
    33
import sun.awt.AWTAccessor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
public class XMenuBarPeer extends XBaseMenuWindow implements MenuBarPeer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
     * Data members
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
    43
    private static PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XMenuBarPeer");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * Primary members
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private XFramePeer framePeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private MenuBar menuBarTarget;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * Index of help menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private XMenuPeer helpMenu = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * dimension constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private final static int BAR_SPACING_TOP = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private final static int BAR_SPACING_BOTTOM = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private final static int BAR_SPACING_LEFT = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private final static int BAR_SPACING_RIGHT = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private final static int BAR_ITEM_SPACING = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private final static int BAR_ITEM_MARGIN_LEFT = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private final static int BAR_ITEM_MARGIN_RIGHT = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private final static int BAR_ITEM_MARGIN_TOP = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private final static int BAR_ITEM_MARGIN_BOTTOM = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * Mapping data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * XBaseMenuWindow's mappingData is extended with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * desired height of menu bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    static class MappingData extends XBaseMenuWindow.MappingData {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        int desiredHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        MappingData(XMenuItemPeer[] items, int desiredHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            super(items);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            this.desiredHeight = desiredHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
         * Constructs MappingData without items
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
         * This constructor should be used in case of errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        MappingData() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            this.desiredHeight = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        public int getDesiredHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            return this.desiredHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * Construction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    XMenuBarPeer(MenuBar menuBarTarget) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        this.menuBarTarget = menuBarTarget;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * Implementaion of interface methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * From MenuComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public void setFont(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        resetMapping();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        setItemsFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        postPaintEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * From MenuBarPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Functions addMenu, delMenu, addHelpMenu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * need to have somewhat strange behaivour
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * deduced from java.awt.MenuBar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * We can not get index of particular item in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * MenuBar.menus array, because MenuBar firstly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * performs array operations and then calls peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * So we need to synchronize indicies in 'items'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * array with MenuBar.menus. We have to follow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * these rules:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * 1. Menus are always added to the end of array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * even when helpMenu is present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * 2. Removal of any menu item acts as casual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * remove from array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * 3. MenuBar.setHelpMenu _firstly_ removes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * previous helpMenu by calling delMenu() if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * necessary, then it performs addMenu(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * and then - addHelpMenu().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * Note that these functions don't perform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * type checks and checks for nulls or duplicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public void addMenu(Menu m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        addItem(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        postPaintEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public void delMenu(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        synchronized(getMenuTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            XMenuItemPeer item = getItem(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            if (item != null && item == helpMenu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                helpMenu = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            delItem(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        postPaintEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public void addHelpMenu(Menu m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        XMenuPeer mp = (XMenuPeer)m.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        synchronized(getMenuTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            helpMenu = mp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        postPaintEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * Initialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * called from XFramePeer.setMenuBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public void init(Frame frame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        this.target = frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        this.framePeer = (XFramePeer)frame.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        XCreateWindowParams params = getDelayedParams();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        params.remove(DELAYED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        params.add(PARENT_WINDOW, framePeer.getShell());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        params.add(TARGET, frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        init(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * Overriden initialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    void postInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        super.postInit(params);
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 10096
diff changeset
   197
        // Get menus from the target.
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 10096
diff changeset
   198
        Vector targetMenuVector = AWTAccessor.getMenuBarAccessor()
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 10096
diff changeset
   199
                                      .getMenus(menuBarTarget);
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 10096
diff changeset
   200
        Menu targetHelpMenu = AWTAccessor.getMenuBarAccessor()
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 10096
diff changeset
   201
                                  .getHelpMenu(menuBarTarget);
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 10096
diff changeset
   202
        reloadItems(targetMenuVector);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        if (targetHelpMenu != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            addHelpMenu(targetHelpMenu);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        xSetVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        toFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * Implementation of abstract methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Menu bar is always root window in menu window's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    protected XBaseMenuWindow getParentMenuWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @see XBaseMenuWindow.map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    protected MappingData map() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        XMenuItemPeer[] itemVector = copyItems();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        int itemCnt = itemVector.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        XMenuItemPeer helpMenu = this.helpMenu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        int helpMenuPos = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        //find helpMenu and move it to the end of array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        if (helpMenu != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            //Fixed 6270847: PIT: HELP menu is not shown at the right place when normal menus added to MB are removed, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            for (int i = 0; i < itemCnt; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                if (itemVector[i] == helpMenu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    helpMenuPos = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            if (helpMenuPos != -1 && helpMenuPos != itemCnt - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                System.arraycopy(itemVector, helpMenuPos + 1, itemVector, helpMenuPos, itemCnt - 1 - helpMenuPos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                itemVector[itemCnt - 1] = helpMenu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        //We need maximum height before calculating item's bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        int maxHeight = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        XMenuItemPeer.TextMetrics[] itemMetrics = new XMenuItemPeer.TextMetrics[itemCnt];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        for (int i = 0; i < itemCnt; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            itemMetrics[i] = itemVector[i].getTextMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            Dimension dim = itemMetrics[i].getTextDimension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            if (dim != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                maxHeight = Math.max(maxHeight, dim.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        //Calculate bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        int nextOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        int itemHeight = BAR_ITEM_MARGIN_TOP + maxHeight + BAR_ITEM_MARGIN_BOTTOM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        int mappedCnt = itemCnt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        for (int i = 0; i < itemCnt; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            XMenuItemPeer item = itemVector[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            XMenuItemPeer.TextMetrics metrics = itemMetrics[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            Dimension dim = metrics.getTextDimension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            if (dim != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                int itemWidth = BAR_ITEM_MARGIN_LEFT + dim.width + BAR_ITEM_MARGIN_RIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                //Fix for 6270757: PIT: Menus and Sub-menus are shown outside the frame, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                //Cut-off items that don't fit in window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                //At least one item must remain in menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                if ((nextOffset + itemWidth > this.width) && (i > 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                    mappedCnt = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                //If this item is help menu, move it to the right edge
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                if ((i == itemCnt - 1) && helpMenuPos != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                    nextOffset = Math.max(nextOffset, this.width - itemWidth - BAR_SPACING_RIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                Rectangle bounds = new Rectangle(nextOffset, BAR_SPACING_TOP, itemWidth, itemHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                //text should be centered vertically in menu item's bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                int y = (maxHeight + dim.height) / 2  - metrics.getTextBaseline();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                Point textOrigin = new Point(nextOffset + BAR_ITEM_MARGIN_LEFT, BAR_SPACING_TOP + BAR_ITEM_MARGIN_TOP + y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                nextOffset += itemWidth + BAR_ITEM_SPACING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                item.map(bounds, textOrigin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                Rectangle bounds = new Rectangle(nextOffset, BAR_SPACING_TOP, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                Point textOrigin = new Point(nextOffset + BAR_ITEM_MARGIN_LEFT, BAR_SPACING_TOP + BAR_ITEM_MARGIN_TOP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        XMenuItemPeer mappedVector[] = new XMenuItemPeer[mappedCnt];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        System.arraycopy(itemVector, 0, mappedVector, 0, mappedCnt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        MappingData mappingData = new MappingData(mappedVector, BAR_SPACING_TOP + itemHeight + BAR_SPACING_BOTTOM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        return mappingData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @see XBaseMenuWindow.getSubmenuBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    protected Rectangle getSubmenuBounds(Rectangle itemBounds, Dimension windowSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        Rectangle globalBounds = toGlobal(itemBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        Rectangle res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        res = fitWindowBelow(globalBounds, windowSize, screenSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        res = fitWindowAbove(globalBounds, windowSize, screenSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        res = fitWindowRight(globalBounds, windowSize, screenSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        res = fitWindowLeft(globalBounds, windowSize, screenSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        return fitWindowToScreen(windowSize, screenSize);
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
     * This function is called when it's likely that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * size of items has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * Invokes framePeer's updateChildrenSizes()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    protected void updateSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        resetMapping();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        if (framePeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            framePeer.reshapeMenubarPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * Utility functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * Returns desired height of menu bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    int getDesiredHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        MappingData mappingData = (MappingData)getMappingData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        return mappingData.getDesiredHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * Returns true if framePeer is not null and is enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * Used to fix 6185057: Disabling a frame does not disable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * the menus on the frame, on solaris/linux
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    boolean isFramePeerEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        if (framePeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            return framePeer.isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * Overriden XBaseMenuWindow functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * @see XBaseMenuWindow.doDispose()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    protected void doDispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        super.doDispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        XToolkit.targetDisposedPeer(menuBarTarget, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * Overriden XWindow general-purpose functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * For menu bars this function is called from framePeer's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * reshape(...) and updateChildrenSizes()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    public void reshape(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        if ((width != this.width) || (height != this.height)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            resetMapping();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        super.reshape(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * Performs ungrabbing of input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @see XBaseWindow.ungrabInputImpl()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    void ungrabInputImpl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        selectItem(null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        super.ungrabInputImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        postPaintEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * Overriden XWindow painting & printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     ************************************************/
10096
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
   404
    public void paintPeer(Graphics g) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        resetColors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        /* Calculate menubar dimension. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        int width = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        int height = getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        //Fill background of rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        g.setColor(getBackgroundColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        g.fillRect(1, 1, width - 2, height - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        draw3DRect(g, 0, 0, width, height, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        //Paint menus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        MappingData mappingData = (MappingData)getMappingData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        XMenuItemPeer[] itemVector = mappingData.getItems();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        XMenuItemPeer selectedItem = getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        for (int i = 0; i < itemVector.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            XMenuItemPeer item = itemVector[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            //paint item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            g.setFont(item.getTargetFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            Rectangle bounds = item.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            Point textOrigin = item.getTextOrigin();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            if (item == selectedItem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                g.setColor(getSelectedColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                draw3DRect(g, bounds.x, bounds.y, bounds.width, bounds.height, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            if (isFramePeerEnabled() && item.isTargetItemEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                g.setColor(getForegroundColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                g.setColor(getDisabledColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            g.drawString(item.getTargetLabel(), textOrigin.x, textOrigin.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    static final int W_DIFF = (XFramePeer.CROSSHAIR_INSET + 1) * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    static final int H_DIFF = XFramePeer.BUTTON_Y + XFramePeer.BUTTON_H;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    void print(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        //TODO:Implement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * Overriden XBaseMenuWindow event handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    protected void handleEvent(AWTEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        // explicitly block all events except PaintEvent.PAINT for menus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        // that are in the modal blocked window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        if ((framePeer != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            (event.getID() != PaintEvent.PAINT))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            if (framePeer.isModalBlocked()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        switch(event.getID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        case MouseEvent.MOUSE_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        case MouseEvent.MOUSE_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        case MouseEvent.MOUSE_CLICKED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        case MouseEvent.MOUSE_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        case MouseEvent.MOUSE_ENTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        case MouseEvent.MOUSE_EXITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        case MouseEvent.MOUSE_DRAGGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            //Fix for 6185057: Disabling a frame does not disable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            //the menus on the frame, on solaris/linux
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            if (isFramePeerEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                doHandleJavaMouseEvent((MouseEvent)event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        case KeyEvent.KEY_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        case KeyEvent.KEY_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            //Fix for 6185057: Disabling a frame does not disable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            //the menus on the frame, on solaris/linux
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            if (isFramePeerEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                doHandleJavaKeyEvent((KeyEvent)event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            super.handleEvent(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * Overriden XWindow keyboard processing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * This function is called from XWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * @see XWindow.handleF10onEDT()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    void handleF10KeyPress(KeyEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        int keyState = event.getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        if (((keyState & InputEvent.ALT_MASK) != 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            ((keyState & InputEvent.SHIFT_MASK) != 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            ((keyState & InputEvent.CTRL_MASK) != 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        grabInput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        selectItem(getFirstSelectableItem(), 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
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * In previous version keys were handled in handleKeyPress.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * Now we override this function do disable F10 explicit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * processing. All processing is done using KeyEvent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    public void handleKeyPress(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        XKeyEvent xkey = xev.get_xkey();
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   522
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   523
            log.fine(xkey.toString());
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   524
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        if (isEventDisabled(xev)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        }
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 18178
diff changeset
   528
        final Component currentSource = getEventSource();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        //This is the only difference from XWindow.handleKeyPress
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        //Ancestor's function can invoke handleF10KeyPress here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        handleKeyPress(xkey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
} //class XMenuBarPeer