< prev index next >

src/java.desktop/unix/classes/sun/awt/X11/XMenuBarPeer.java

Print this page


   1 /*
   2  * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 270                 int itemWidth = BAR_ITEM_MARGIN_LEFT + dim.width + BAR_ITEM_MARGIN_RIGHT;
 271                 //Fix for 6270757: PIT: Menus and Sub-menus are shown outside the frame, XToolkit
 272                 //Cut-off items that don't fit in window
 273                 //At least one item must remain in menu
 274                 if ((nextOffset + itemWidth > this.width) && (i > 0)) {
 275                     mappedCnt = i;
 276                     break;
 277                 }
 278                 //If this item is help menu, move it to the right edge
 279                 if ((i == itemCnt - 1) && helpMenuPos != -1) {
 280                     nextOffset = Math.max(nextOffset, this.width - itemWidth - BAR_SPACING_RIGHT);
 281                 }
 282                 Rectangle bounds = new Rectangle(nextOffset, BAR_SPACING_TOP, itemWidth, itemHeight);
 283                 //text should be centered vertically in menu item's bounds
 284                 int y = (maxHeight + dim.height) / 2  - metrics.getTextBaseline();
 285                 Point textOrigin = new Point(nextOffset + BAR_ITEM_MARGIN_LEFT, BAR_SPACING_TOP + BAR_ITEM_MARGIN_TOP + y);
 286                 nextOffset += itemWidth + BAR_ITEM_SPACING;
 287                 item.map(bounds, textOrigin);
 288             }
 289         }
 290         XMenuItemPeer mappedVector[] = new XMenuItemPeer[mappedCnt];
 291         System.arraycopy(itemVector, 0, mappedVector, 0, mappedCnt);
 292         MappingData mappingData = new MappingData(mappedVector, BAR_SPACING_TOP + itemHeight + BAR_SPACING_BOTTOM);
 293         return mappingData;
 294     }
 295 
 296     /**
 297      * @see XBaseMenuWindow#getSubmenuBounds
 298      */
 299     protected Rectangle getSubmenuBounds(Rectangle itemBounds, Dimension windowSize) {
 300         Rectangle globalBounds = toGlobal(itemBounds);
 301         Rectangle screenBounds = getCurrentGraphicsConfiguration().getBounds();
 302         Rectangle res;
 303         res = fitWindowBelow(globalBounds, windowSize, screenBounds);
 304         if (res != null) {
 305             return res;
 306         }
 307         res = fitWindowAbove(globalBounds, windowSize, screenBounds);
 308         if (res != null) {
 309             return res;
 310         }


   1 /*
   2  * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 270                 int itemWidth = BAR_ITEM_MARGIN_LEFT + dim.width + BAR_ITEM_MARGIN_RIGHT;
 271                 //Fix for 6270757: PIT: Menus and Sub-menus are shown outside the frame, XToolkit
 272                 //Cut-off items that don't fit in window
 273                 //At least one item must remain in menu
 274                 if ((nextOffset + itemWidth > this.width) && (i > 0)) {
 275                     mappedCnt = i;
 276                     break;
 277                 }
 278                 //If this item is help menu, move it to the right edge
 279                 if ((i == itemCnt - 1) && helpMenuPos != -1) {
 280                     nextOffset = Math.max(nextOffset, this.width - itemWidth - BAR_SPACING_RIGHT);
 281                 }
 282                 Rectangle bounds = new Rectangle(nextOffset, BAR_SPACING_TOP, itemWidth, itemHeight);
 283                 //text should be centered vertically in menu item's bounds
 284                 int y = (maxHeight + dim.height) / 2  - metrics.getTextBaseline();
 285                 Point textOrigin = new Point(nextOffset + BAR_ITEM_MARGIN_LEFT, BAR_SPACING_TOP + BAR_ITEM_MARGIN_TOP + y);
 286                 nextOffset += itemWidth + BAR_ITEM_SPACING;
 287                 item.map(bounds, textOrigin);
 288             }
 289         }
 290         XMenuItemPeer[] mappedVector = new XMenuItemPeer[mappedCnt];
 291         System.arraycopy(itemVector, 0, mappedVector, 0, mappedCnt);
 292         MappingData mappingData = new MappingData(mappedVector, BAR_SPACING_TOP + itemHeight + BAR_SPACING_BOTTOM);
 293         return mappingData;
 294     }
 295 
 296     /**
 297      * @see XBaseMenuWindow#getSubmenuBounds
 298      */
 299     protected Rectangle getSubmenuBounds(Rectangle itemBounds, Dimension windowSize) {
 300         Rectangle globalBounds = toGlobal(itemBounds);
 301         Rectangle screenBounds = getCurrentGraphicsConfiguration().getBounds();
 302         Rectangle res;
 303         res = fitWindowBelow(globalBounds, windowSize, screenBounds);
 304         if (res != null) {
 305             return res;
 306         }
 307         res = fitWindowAbove(globalBounds, windowSize, screenBounds);
 308         if (res != null) {
 309             return res;
 310         }


< prev index next >