6441N/A * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * The abstract class XBaseMenuWindow is the superclass 0N/A * of all menu windows. 0N/A /************************************************ 0N/A ************************************************/ 0N/A * Colors are calculated using MotifColorUtilities class 0N/A * from backgroundColor and are contained in these vars. 0N/A * Index of selected item in array of items 0N/A * Specifies currently showing submenu. 0N/A * Static synchronizational object. 0N/A * Following operations should be synchronized 0N/A * using this object: 0N/A * 1. Access to items vector 0N/A * 2. Access to selection 0N/A * 3. Access to showing menu window member 0N/A * This is lowest level lock, 0N/A * no other locks should be taken when 0N/A * thread own this lock. 0N/A /************************************************ 0N/A ************************************************/ 0N/A * If mouse button is clicked on item showing submenu 0N/A * we have to hide its submenu. 0N/A * And if mouse button is pressed on such item and 0N/A * dragged to another, getShowingSubmenu() is changed. 0N/A * So this member saves the item that the user 0N/A * presses mouse button on _only_ if it's showing submenu. 0N/A * If the PopupMenu is invoked as a result of right button click 0N/A * first mouse event after grabInput would be MouseReleased. 0N/A * We need to check if the user has moved mouse after input grab. 0N/A * If yes - hide the PopupMenu. If no - do nothing 0N/A /************************************************ 0N/A ************************************************/ 0N/A * Mapping data that is filled in getMappedItems function 0N/A * and reset in resetSize function. It contains array of 0N/A * items in order that they appear on screen and may contain 0N/A * additional data defined by descendants. 0N/A * Array of item in order that they appear on screen 0N/A * Constructs MappingData object with list 0N/A * Constructs MappingData without items 0N/A * This constructor should be used in case of errors 0N/A /************************************************ 0N/A ************************************************/ 0N/A /************************************************ 0N/A ************************************************/ 0N/A * Returns parent menu window (not the X-heirarchy parent window) 0N/A * Performs mapping of items in window. 0N/A * This function creates and fills specific 0N/A * descendant of MappingData 0N/A * and sets mapping coordinates of items 0N/A * This function should return default menu data 0N/A * Calculates placement of submenu window 0N/A * given bounds of item with submenu and 0N/A * size of submenu window. Returns suggested 0N/A * rectangle for submenu window in global coordinates 0N/A * @param itemBounds the bounding rectangle of item 0N/A * in local coordinates 0N/A * @param windowSize the desired size of submenu's window 0N/A * This function is to be called if it's likely that size 0N/A * of items was changed. It can be called from any thread 0N/A * in any locked state, so it should not take locks 0N/A /************************************************ 0N/A ************************************************/ 0N/A * Overrides XBaseWindow.instantPreInit 0N/A /************************************************ 0N/A * General-purpose functions 0N/A ************************************************/ 0N/A * Returns static lock used for menus 0N/A * This function is called to clear all saved 0N/A * Invokes repaint procedure on eventHandlerThread 0N/A /************************************************ 0N/A * Utility functions for manipulating items 0N/A ************************************************/ 0N/A * Thread-safely returns item at specified index 0N/A * @param index the position of the item to be returned. 0N/A * Thread-safely creates a copy of the items vector 0N/A * Thread-safely returns selected item 0N/A * Returns showing submenu, if any 0N/A * Adds item to end of items vector. 0N/A * Note that this function does not perform 0N/A * check for adding duplicate items 0N/A * @param item item to add 0N/A log.
fine(
"WARNING: Attempt to add menu item without a peer");
0N/A * Removes item at the specified index from items vector. 0N/A * @param index the position of the item to be removed 0N/A * Clears items vector and loads specified vector 0N/A * @param items vector to be loaded 0N/A * We can not select by index, so we need to select by ref. 0N/A * @param item the item to be selected, null to clear selection 0N/A * @param showWindowIfMenu if the item is XMenuPeer then its 0N/A * Performs hiding of currently showing submenu 0N/A * and showing of submenuToShow. 0N/A * This function should be executed on eventHandlerThread 0N/A * @param submenuToShow submenu to be shown or null 0N/A * to hide currently showing submenu 0N/A //Window.getGraphicsConfiguration() 0N/A //that tries to obtain Component.AWTTreeLock. 0N/A //So it should be called outside awtLock() 0N/A /************************************************ 0N/A * Utility functions for manipulating mapped items 0N/A ************************************************/ 0N/A * Returns array of mapped items, null if error 0N/A * This function has to be not synchronized 0N/A * and we have to guarantee that we return 0N/A * some MappingData to user. It's OK if 0N/A * this.mappingData is replaced meanwhile 0N/A * returns item thats mapped coordinates contain 0N/A * specified point, null of none. 0N/A * @param pt the point in this window's coordinate system 0N/A for (
int i =
0; i <
cnt; i++) {
0N/A * Returns first item after currently selected 0N/A * item that can be selected according to mapping array. 0N/A * (no separators and no disabled items). 0N/A * Currently selected item if it's only selectable, 0N/A * null if no item can be selected 0N/A //Find index of selected item 0N/A for (
int i =
0; i <
cnt; i++) {
0N/A //cycle through mappedItems to find selectable item 0N/A //beginning from the next item and moving to the 0N/A //beginning of array when end is reached. 0N/A //Cycle is finished on selected item itself 0N/A for (
int i =
0; i <
cnt; i++) {
0N/A //return null if no selectable item was found 0N/A * Returns first item before currently selected 0N/A * see getNextSelectableItem() for comments 0N/A //Find index of selected item 0N/A for (
int i =
0; i <
cnt; i++) {
0N/A //cycle through mappedItems to find selectable item 0N/A for (
int i =
0; i <
cnt; i++) {
0N/A //return null if no selectable item was found 0N/A * Returns first selectable item 0N/A * This function is intended for clearing selection 0N/A for (
int i =
0; i <
cnt; i++) {
0N/A /************************************************ 0N/A * Utility functions for manipulating 0N/A * hierarchy of windows 0N/A ************************************************/ 0N/A * returns leaf menu window or 0N/A * this if no children are showing 0N/A * returns root menu window 0N/A * or this if this window is topmost 0N/A * Returns window that contains pt. 0N/A * search is started from leaf window 0N/A * to return first window in Z-order 0N/A * @param pt point in global coordinates 0N/A /************************************************ 0N/A * Primitives for getSubmenuBounds 0N/A * These functions are invoked from getSubmenuBounds 0N/A * implementations in different order. They check if window 0N/A * of size windowSize fits to the specified edge of 0N/A * rectangle itemBounds on the screen of screenSize. 0N/A * Return rectangle that occupies the window if it fits or null. 0N/A ************************************************/ 0N/A * Checks if window fits below specified item 0N/A * returns rectangle that the window fits to or null. 0N/A * @param itemBounds rectangle of item in global coordinates 0N/A * @param windowSize size of submenu window to fit 0N/A * @param screenSize size of screen 0N/A //Fix for 6267162: PIT: Popup Menu gets hidden below the screen when opened 0N/A //near the periphery of the screen, XToolkit 0N/A //Window should be moved if it's outside top-left screen bounds 0N/A //move it to the left if needed 0N/A * Checks if window fits above specified item 0N/A * returns rectangle that the window fits to or null. 0N/A * @param itemBounds rectangle of item in global coordinates 0N/A * @param windowSize size of submenu window to fit 0N/A * @param screenSize size of screen 0N/A //Fix for 6267162: PIT: Popup Menu gets hidden below the screen when opened 0N/A //near the periphery of the screen, XToolkit 0N/A //Window should be moved if it's outside bottom-left screen bounds 0N/A //move it to the left if needed 0N/A * Checks if window fits to the right specified item 0N/A * returns rectangle that the window fits to or null. 0N/A * @param itemBounds rectangle of item in global coordinates 0N/A * @param windowSize size of submenu window to fit 0N/A * @param screenSize size of screen 0N/A //Fix for 6267162: PIT: Popup Menu gets hidden below the screen when opened 0N/A //near the periphery of the screen, XToolkit 0N/A //Window should be moved if it's outside top-left screen bounds 0N/A //move it to the top if needed 0N/A * Checks if window fits to the left specified item 0N/A * returns rectangle that the window fits to or null. 0N/A * @param itemBounds rectangle of item in global coordinates 0N/A * @param windowSize size of submenu window to fit 0N/A * @param screenSize size of screen 0N/A //Fix for 6267162: PIT: Popup Menu gets hidden below the screen when opened 0N/A //near the periphery of the screen, XToolkit 0N/A //Window should be moved if it's outside top-right screen bounds 0N/A //move it to the top if needed 0N/A * The last thing we can do with the window 0N/A * to fit it on screen - move it to the 0N/A * top-left edge and cut by screen dimensions 0N/A * @param windowSize size of submenu window to fit 0N/A * @param screenSize size of screen 0N/A /************************************************ 0N/A * Utility functions for manipulating colors 0N/A ************************************************/ 0N/A * This function is called before every painting. 0N/A * TODO:It would be better to add PropertyChangeListener 0N/A * to target component 0N/A * TODO:It would be better to access background color 0N/A * not invoking user-overridable function 0N/A * Calculates colors of various elements given 0N/A * background color. Uses MotifColorUtilities 0N/A * @param backgroundColor the color of menu window's 0N/A /************************************************ 0N/A * Painting utility functions 0N/A ************************************************/ 0N/A * Draws raised or sunken rectangle on specified graphics 0N/A * @param g the graphics on which to draw 0N/A * @param x the coordinate of left edge in coordinates of graphics 0N/A * @param y the coordinate of top edge in coordinates of graphics 0N/A * @param width the width of rectangle 0N/A * @param height the height of rectangle 0N/A * @param raised true to draw raised rectangle, false to draw sunken 0N/A /************************************************ 0N/A * Overriden utility functions of XWindow 0N/A ************************************************/ 0N/A * Invokes disposal procedure on eventHandlerThread 0N/A * Performs disposal of menu window. 0N/A * Should be called only on eventHandlerThread 0N/A * Invokes event processing on eventHandlerThread 0N/A * This function needs to be overriden since 0N/A * XBaseMenuWindow has no corresponding component 0N/A * so events can not be processed using standart means 0N/A * The implementation of base window performs processing 0N/A * of paint events only. This behaviour is changed in 0N/A * Save location of pointer for further use 0N/A * then invoke superclass 0N/A //Mouse pointer is on the same display 0N/A /************************************************ 0N/A * Overridable event processing functions 0N/A ************************************************/ 0N/A * Performs repainting 0N/A /************************************************ 0N/A * User input handling utility functions 0N/A ************************************************/ 0N/A * Performs handling of java mouse event 0N/A * Note that this function should be invoked 0N/A * only from root of menu window's hierarchy 0N/A * that grabs input focus 0N/A //Window that owns input 0N/A //Point of mouse event in global coordinates 0N/A //Fix for 6301307: NullPointerException while dispatching mouse events, XToolkit 0N/A //Z-order first descendant of current menu window 0N/A //hierarchy that contain mouse point 0N/A //Item in wnd that contains mouse point, if any 0N/A //Currently showing leaf window 0N/A //This line is to get rid of possible problems 0N/A //That may occur if mouse events are lost 0N/A //Menus grab input and the user 0N/A //presses mouse button outside 0N/A //Menus grab input OR mouse is pressed on menu window 0N/A //Button is pressed on enabled item 0N/A //Button is pressed on item that shows 0N/A //submenu. We have to hide its submenu 0N/A //if user clicks on it 0N/A //Button is pressed on disabled item or empty space 0N/A //Note that if item is not null, wnd has to be not null 0N/A //User clicks on item that shows submenu. 0N/A //Invoke action event 0N/A //Mouse is released outside menu items 0N/A //Mouse is dragged over menu window 0N/A //Move selection to item under cursor 0N/A //Mouse is dragged outside menu windows 0N/A //clear selection in leaf to reflect it 0N/A * Performs handling of java keyboard event 0N/A * Note that this function should be invoked 0N/A * only from root of menu window's hierarchy 0N/A * that grabs input focus 0N/A //If active window is not menu bar, 0N/A //If active window is menu bar show current submenu 0N/A //move selection down 0N/A //leaf window is menu bar 0N/A //select previous item 0N/A //leaf window is direct child of menu bar 0N/A //select previous item of menu bar 0N/A //and show its submenu 0N/A //hide leaf moving focus to its parent 0N/A //(equvivalent of pressing ESC) 0N/A //Fix for 6272952: PIT: Pressing LEFT ARROW on a popup menu throws NullPointerException, XToolkit 0N/A //leaf window is menu bar 0N/A //current item is menu, show its window 0N/A //(equivalent of ENTER) 0N/A //if this is menu bar (not popup menu) 0N/A //and the user presses RIGHT on item (not submenu) 0N/A //select next top-level menu 0N/A //If the current item has submenu show it 0N/A //Perform action otherwise 0N/A //If current window is menu bar or its child - close it 0N/A //If current window is popup menu - close it 0N/A //go one level up otherwise 0N/A //Fixed 6266513: Incorrect key handling in XAWT popup menu 0N/A //Popup menu should be closed on 'ESC' 0N/A //Fixed 6266513: Incorrect key handling in XAWT popup menu 0N/A //All menus should be closed on 'F10' 0N/A}
//class XBaseMenuWindow