jdk/src/java.desktop/unix/classes/sun/awt/X11/XMenuBarPeer.java
author darcy
Mon, 15 Dec 2014 17:20:17 -0800
changeset 28231 b608ffcaed74
parent 25859 3317bb8137f4
child 30469 bac0a7ff7e1e
permissions -rw-r--r--
8066621: Suppress deprecation warnings in java.desktop module Reviewed-by: prr, alanb, ptbrunet
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
28231
b608ffcaed74 8066621: Suppress deprecation warnings in java.desktop module
darcy
parents: 25859
diff changeset
   166
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public void addHelpMenu(Menu m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        XMenuPeer mp = (XMenuPeer)m.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        synchronized(getMenuTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            helpMenu = mp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        postPaintEvent();
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
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * Initialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * called from XFramePeer.setMenuBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     */
28231
b608ffcaed74 8066621: Suppress deprecation warnings in java.desktop module
darcy
parents: 25859
diff changeset
   183
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    public void init(Frame frame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        this.target = frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        this.framePeer = (XFramePeer)frame.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        XCreateWindowParams params = getDelayedParams();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        params.remove(DELAYED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        params.add(PARENT_WINDOW, framePeer.getShell());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        params.add(TARGET, frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        init(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Overriden initialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    void postInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        super.postInit(params);
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 10096
diff changeset
   199
        // Get menus from the target.
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22584
diff changeset
   200
        Vector<Menu> targetMenuVector = AWTAccessor.getMenuBarAccessor()
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22584
diff changeset
   201
                                                   .getMenus(menuBarTarget);
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 10096
diff changeset
   202
        Menu targetHelpMenu = AWTAccessor.getMenuBarAccessor()
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 22584
diff changeset
   203
                                         .getHelpMenu(menuBarTarget);
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 10096
diff changeset
   204
        reloadItems(targetMenuVector);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (targetHelpMenu != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            addHelpMenu(targetHelpMenu);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        xSetVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        toFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * Implementation of abstract methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * Menu bar is always root window in menu window's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    protected XBaseMenuWindow getParentMenuWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @see XBaseMenuWindow.map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    protected MappingData map() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        XMenuItemPeer[] itemVector = copyItems();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        int itemCnt = itemVector.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        XMenuItemPeer helpMenu = this.helpMenu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        int helpMenuPos = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        //find helpMenu and move it to the end of array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        if (helpMenu != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            //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
   237
            for (int i = 0; i < itemCnt; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                if (itemVector[i] == helpMenu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    helpMenuPos = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            if (helpMenuPos != -1 && helpMenuPos != itemCnt - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                System.arraycopy(itemVector, helpMenuPos + 1, itemVector, helpMenuPos, itemCnt - 1 - helpMenuPos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                itemVector[itemCnt - 1] = helpMenu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        //We need maximum height before calculating item's bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        int maxHeight = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        XMenuItemPeer.TextMetrics[] itemMetrics = new XMenuItemPeer.TextMetrics[itemCnt];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        for (int i = 0; i < itemCnt; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            itemMetrics[i] = itemVector[i].getTextMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            Dimension dim = itemMetrics[i].getTextDimension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            if (dim != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                maxHeight = Math.max(maxHeight, dim.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        //Calculate bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        int nextOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        int itemHeight = BAR_ITEM_MARGIN_TOP + maxHeight + BAR_ITEM_MARGIN_BOTTOM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        int mappedCnt = itemCnt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        for (int i = 0; i < itemCnt; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            XMenuItemPeer item = itemVector[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            XMenuItemPeer.TextMetrics metrics = itemMetrics[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            Dimension dim = metrics.getTextDimension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            if (dim != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                int itemWidth = BAR_ITEM_MARGIN_LEFT + dim.width + BAR_ITEM_MARGIN_RIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                //Fix for 6270757: PIT: Menus and Sub-menus are shown outside the frame, XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                //Cut-off items that don't fit in window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                //At least one item must remain in menu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                if ((nextOffset + itemWidth > this.width) && (i > 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                    mappedCnt = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                //If this item is help menu, move it to the right edge
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                if ((i == itemCnt - 1) && helpMenuPos != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                    nextOffset = Math.max(nextOffset, this.width - itemWidth - BAR_SPACING_RIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                Rectangle bounds = new Rectangle(nextOffset, BAR_SPACING_TOP, itemWidth, itemHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                //text should be centered vertically in menu item's bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                int y = (maxHeight + dim.height) / 2  - metrics.getTextBaseline();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                Point textOrigin = new Point(nextOffset + BAR_ITEM_MARGIN_LEFT, BAR_SPACING_TOP + BAR_ITEM_MARGIN_TOP + y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                nextOffset += itemWidth + BAR_ITEM_SPACING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                item.map(bounds, textOrigin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                Rectangle bounds = new Rectangle(nextOffset, BAR_SPACING_TOP, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                Point textOrigin = new Point(nextOffset + BAR_ITEM_MARGIN_LEFT, BAR_SPACING_TOP + BAR_ITEM_MARGIN_TOP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        XMenuItemPeer mappedVector[] = new XMenuItemPeer[mappedCnt];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        System.arraycopy(itemVector, 0, mappedVector, 0, mappedCnt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        MappingData mappingData = new MappingData(mappedVector, BAR_SPACING_TOP + itemHeight + BAR_SPACING_BOTTOM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        return mappingData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @see XBaseMenuWindow.getSubmenuBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    protected Rectangle getSubmenuBounds(Rectangle itemBounds, Dimension windowSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        Rectangle globalBounds = toGlobal(itemBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        Rectangle res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        res = fitWindowBelow(globalBounds, windowSize, screenSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        res = fitWindowAbove(globalBounds, windowSize, screenSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        res = fitWindowRight(globalBounds, windowSize, screenSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        res = fitWindowLeft(globalBounds, windowSize, screenSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        if (res != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        return fitWindowToScreen(windowSize, screenSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * This function is called when it's likely that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * size of items has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * Invokes framePeer's updateChildrenSizes()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    protected void updateSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        resetMapping();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        if (framePeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            framePeer.reshapeMenubarPeer();
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
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * Utility functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * Returns desired height of menu bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    int getDesiredHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        MappingData mappingData = (MappingData)getMappingData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        return mappingData.getDesiredHeight();
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
     * Returns true if framePeer is not null and is enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * Used to fix 6185057: Disabling a frame does not disable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * the menus on the frame, on solaris/linux
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    boolean isFramePeerEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        if (framePeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            return framePeer.isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        return false;
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
     * Overriden XBaseMenuWindow functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * @see XBaseMenuWindow.doDispose()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    protected void doDispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        super.doDispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        XToolkit.targetDisposedPeer(menuBarTarget, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * Overriden XWindow general-purpose functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * For menu bars this function is called from framePeer's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * reshape(...) and updateChildrenSizes()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    public void reshape(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        if ((width != this.width) || (height != this.height)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            resetMapping();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        super.reshape(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * Performs ungrabbing of input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @see XBaseWindow.ungrabInputImpl()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    void ungrabInputImpl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        selectItem(null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        super.ungrabInputImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        postPaintEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * Overriden XWindow painting & printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     ************************************************/
10096
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
   406
    public void paintPeer(Graphics g) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        resetColors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        /* Calculate menubar dimension. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        int width = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        int height = getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        //Fill background of rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        g.setColor(getBackgroundColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        g.fillRect(1, 1, width - 2, height - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        draw3DRect(g, 0, 0, width, height, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        //Paint menus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        MappingData mappingData = (MappingData)getMappingData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        XMenuItemPeer[] itemVector = mappingData.getItems();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        XMenuItemPeer selectedItem = getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        for (int i = 0; i < itemVector.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            XMenuItemPeer item = itemVector[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            //paint item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            g.setFont(item.getTargetFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            Rectangle bounds = item.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            Point textOrigin = item.getTextOrigin();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            if (item == selectedItem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                g.setColor(getSelectedColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                draw3DRect(g, bounds.x, bounds.y, bounds.width, bounds.height, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            if (isFramePeerEnabled() && item.isTargetItemEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                g.setColor(getForegroundColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                g.setColor(getDisabledColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            g.drawString(item.getTargetLabel(), textOrigin.x, textOrigin.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    static final int W_DIFF = (XFramePeer.CROSSHAIR_INSET + 1) * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    static final int H_DIFF = XFramePeer.BUTTON_Y + XFramePeer.BUTTON_H;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    void print(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        //TODO:Implement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * Overriden XBaseMenuWindow event handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    protected void handleEvent(AWTEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        // explicitly block all events except PaintEvent.PAINT for menus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        // that are in the modal blocked window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        if ((framePeer != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            (event.getID() != PaintEvent.PAINT))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            if (framePeer.isModalBlocked()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        switch(event.getID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        case MouseEvent.MOUSE_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        case MouseEvent.MOUSE_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        case MouseEvent.MOUSE_CLICKED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        case MouseEvent.MOUSE_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        case MouseEvent.MOUSE_ENTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        case MouseEvent.MOUSE_EXITED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        case MouseEvent.MOUSE_DRAGGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            //Fix for 6185057: Disabling a frame does not disable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            //the menus on the frame, on solaris/linux
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            if (isFramePeerEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                doHandleJavaMouseEvent((MouseEvent)event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        case KeyEvent.KEY_PRESSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        case KeyEvent.KEY_RELEASED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            //Fix for 6185057: Disabling a frame does not disable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            //the menus on the frame, on solaris/linux
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            if (isFramePeerEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                doHandleJavaKeyEvent((KeyEvent)event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            super.handleEvent(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            break;
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
    /************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * Overriden XWindow keyboard processing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     ************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * This function is called from XWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * @see XWindow.handleF10onEDT()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    void handleF10KeyPress(KeyEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        int keyState = event.getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        if (((keyState & InputEvent.ALT_MASK) != 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            ((keyState & InputEvent.SHIFT_MASK) != 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            ((keyState & InputEvent.CTRL_MASK) != 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        grabInput();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        selectItem(getFirstSelectableItem(), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * In previous version keys were handled in handleKeyPress.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * Now we override this function do disable F10 explicit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * processing. All processing is done using KeyEvent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    public void handleKeyPress(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        XKeyEvent xkey = xev.get_xkey();
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   524
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   525
            log.fine(xkey.toString());
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   526
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        if (isEventDisabled(xev)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        }
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 18178
diff changeset
   530
        final Component currentSource = getEventSource();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        //This is the only difference from XWindow.handleKeyPress
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        //Ancestor's function can invoke handleF10KeyPress here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        handleKeyPress(xkey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
} //class XMenuBarPeer