6441N/A * Copyright (c) 2003, 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// FIXME: tab traversal should be disabled when mouse is captured (4816336) 0N/A// FIXME: key and mouse events should not be delivered to listeners when the Choice is unfurled. Must override handleNativeKey/MouseEvent (4816336) 0N/A// FIXME: account for unfurling at the edge of the screen 0N/A// Note: can't set x,y on layout(), 'cause moving the top-level to the 0N/A// edge of the screen won't call layout(). Just do it on paint, I guess 0N/A// TODO: make painting more efficient (i.e. when down arrow is pressed, only two items should need to be repainted. 0N/A // items to be displayed 0N/A // Description of these constants in ListHelper 0N/A // FIXME: Motif uses a different focus color for the item within 0N/A // the unfurled Choice list and for when the Choice itself is focused and 0N/A // TODO: there is a time value that the mouse is held down. If short 0N/A // enough, the Choice stays popped down. If long enough, Choice 0N/A // is furled when the mouse is released 0N/A private boolean unfurled =
false;
// Choice list is popped down 0N/A private boolean dragging =
false;
// Mouse was pressed and is being 0N/A // dragged over the (unfurled) 0N/A private boolean mouseInSB =
false;
// Mouse is interacting with the 0N/A // furled Choice so we 0N/A // not need to furl the 0N/A // Choice when MOUSE_RELEASED occured 0N/A // 6425067. Mouse was pressed on furled choice and dropdown list appeared over Choice itself 0N/A // and then there were no mouse movements until MOUSE_RELEASE. 0N/A // This scenario leads to ItemStateChanged as the choice logic uses 0N/A // MouseReleased event to send ItemStateChanged. To prevent it we should 0N/A // use a combination of firstPress and wasDragged variables. 0N/A // The only difference in dragging and wasDragged is: last one will not 0N/A // set to false on mouse ungrab. It become false after MouseRelased() finishes. 0N/A // TODO: Choice remembers where it was scrolled to when unfurled - it's not 0N/A // always to the currently selected item. 0N/A // Indicates whether or not to paint selected item in the choice. 0N/A // Default is to paint 0N/A // If set, indicates components under which choice popup should be showed. 0N/A // The choice's popup width and location should be adjust to appear 0N/A // under both choice and alignUnder component. 0N/A // If cursor is outside of an unfurled Choice when the mouse is 0N/A // released, Choice item should NOT be updated. Remember the proper index. 0N/A // Holds the listener (XFileDialogPeer) which the processing events from the choice 0N/A // See 6240074 for more information 0N/A // 6399679. check if super.setBounds() actually changes the size of the 0N/A // component and then compare current Choice size with a new one. If 0N/A // they differs then hide dropdown menu 0N/A // TODO: only need to paint the focus bit 0N/A * Fix for 6246503 : Disabling a choice after selection locks keyboard, mouse and makes the system unusable, Xtoolkit 0N/A * if setEnabled(false) invoked we should close opened choice in 0N/A // TODO: only need to paint the focus bit? 0N/A // UP & DOWN are same if furled or unfurled 0N/A //This also happens on 0N/A // - MouseButton2,3, etc. press 0N/A }
else {
//KeyEvent.VK_ENTER: 0N/A // See 6240074 for more information 0N/A * fix for 5003166: a Choice on XAWT shouldn't react to any 0N/A * mouse button presses except left. This involves presses on 0N/A * Choice but not on opened part of choice. 0N/A //fix 6259328: PIT: Choice scrolls when dragging the parent frame while drop-down is active, XToolkit 0N/A // Press on unfurled Choice. Highlight the item under the cursor, 0N/A // but don't send item event or set the text on the button yet 0N/A // Choice is up - unfurl it 0N/A * helper method for mouseReleased routine 0N/A // We pressed and dragged onto the Choice, or, this is the 0N/A // second release after clicking to make the Choice "stick" 0N/A // release was over the unfurled Choice. 0N/A // Fix for 6239944 : Choice shouldn't close its 0N/A // pop-down menu if user presses Mouse on Choice's Scrollbar 0N/A // some additional cases like releasing mouse outside 0N/A // of Choice are considered too 0N/A // Fixed 6318746: REG: File Selection is failing 0N/A // We shouldn't restore the selected item 0N/A // if the mouse was dragged outside the drop-down choice area 0N/A // Set the selected item back how it was. 0N/A // Choice must be closed if user releases mouse on 0N/A // pop-down menu on the second click 0N/A // Choice must be closed if user releases mouse 0N/A // outside of Choice's pop-down menu on the second click 0N/A //if user drags Mouse on pop-down menu, Scrollbar or 0N/A // outside the Choice 0N/A /* this could happen when user has opened a Choice and 0N/A * released mouse button. Then he drags mouse on the 0N/A * Scrollbar and releases mouse again. 0N/A // Only update the Choice if the mouse button is released 0N/A // over the list of items. 0N/A // Update the selected item in the target now that 0N/A // the mouse selection is complete. 0N/A // NOTE: We get a repaint when Choice.select() 0N/A // calls our peer.select(). 0N/A /*fix for 6239941 : Choice triggers ItemEvent when selecting an item with right mouse button, Xtoolkit 0N/A * We should generate ItemEvent if only 0N/A * LeftMouseButton used */ 0N/A // see 6240074 for more information 0N/A // See 6243382 for more information 0N/A * fix for 5003166. On Motif user are unable to drag 0N/A * mouse inside opened Choice if he drags the mouse with 0N/A * different from LEFT mouse button ( e.g. RIGHT or MIDDLE). 0N/A * This fix make impossible to drag mouse inside opened choice 0N/A * with other mouse buttons rather then LEFT one. 0N/A // Stolen from TinyChoicePeer 0N/A // TODO: move this impl into ListHelper? 0N/A Dimension size = target.getSize(); 0N/A Font f = target.getFont(); 0N/A FontMetrics fm = target.getFontMetrics(f); 0N/A String text = ((Choice)target).getLabel(); 0N/A textRect.height = fm.getHeight(); 0N/A checkBoxSize = getChoiceSize(fm); 0N/A // Note - Motif appears to use an left inset that is slightly 0N/A cbX = borderInsets.left + checkBoxInsetFromText; 0N/A cbY = size.height / 2 - checkBoxSize / 2; 0N/A int minTextX = borderInsets.left + 2 * checkBoxInsetFromText + checkBoxSize; 0N/A // FIXME: will need to account for alignment? 0N/A // FIXME: call layout() on alignment changes 0N/A //textRect.width = fm.stringWidth(text); 0N/A textRect.width = fm.stringWidth(text == null ? "" : text); 0N/A textRect.x = Math.max(minTextX, size.width / 2 - textRect.width / 2); 0N/A textRect.y = size.height / 2 - textRect.height / 2 + borderInsets.top; 0N/A focusRect.x = focusInsets.left; 0N/A focusRect.y = focusInsets.top; 0N/A focusRect.width = size.width-(focusInsets.left+focusInsets.right)-1; 0N/A focusRect.height = size.height-(focusInsets.top+focusInsets.bottom)-1; 0N/A myCheckMark = AffineTransform.getScaleInstance((double)target.getFont().getSize() / MASTER_SIZE, (double)target.getFont().getSize() / MASTER_SIZE).createTransformedShape(MASTER_CHECKMARK); 0N/A // TODO: when mouse is down over button, widget should be drawn depressed 0N/A int x,
int y,
int w,
int h) {
0N/A * ChoicePeer methods stolen from TinyChoicePeer 0N/A * After removing the item of the choice we need to reshape unfurled choice 0N/A * in order to keep actual bounds of the choice 0N/A * condition added only for performance 0N/A // Fix 6292186: PIT: Choice is not refreshed properly when the last item gets removed, XToolkit 0N/A // We should take into account that there is no 'select' invoking (hence 'repaint') 0N/A // if the choice is empty (see Choice.java method removeNoInvalidate()) 0N/A // The condition isn't 'visibled' since it would be cause of the twice repainting 0N/A * condition added only for performance 0N/A * the count of the visible items changed 0N/A * condition added only for performance 0N/A * the structure of visible items changed 0N/A * if removable item is non visible and non selected then there is no repaint 0N/A * After removing the item of the choice we need to reshape unfurled choice 0N/A * in order to keep actual bounds of the choice 0N/A * DEPRECATED: Replaced by add(String, int). 0N/A // see 6240074 for more information 0N/A // see 6240074 for more information 0N/A /* fix for 6261352. We should detect if current parent Window (containing a Choice) become iconified and hide pop-down menu with grab release. 0N/A * In this case we should hide pop-down menu. 0N/A //calls from XWindowPeer. Could accept X-styled state events 0N/A //calls from XFramePeer. Could accept Frame's states. 0N/A /**************************************************************************/ 0N/A /* Common functionality between List & Choice 0N/A /**************************************************************************/ 0N/A * Inner class for the unfurled Choice list 0N/A * Much, much more docs 0N/A // First try - use Choice as the target 0N/A // Override so we can do our own create() 0N/A // A parent of this window is the target, at this point: wrong. 0N/A // Remove parent window; in the following preInit() call we'll calculate as a default 0N/A // a correct root window which is the proper parent for override redirect. 0N/A // Reset bounds(we'll set them later), set overrideRedirect 0N/A // Generally, bounds should be: 0N/A // y = target.y + target.height 0N/A // w = Max(target.width, getLongestItemWidth) + possible vertScrollbar 0N/A // h = Min(MAX_UNFURLED_ITEMS, target.getItemCount()) * itemHeight 0N/A // Motif paints an empty Choice the same size as a single item 0N/A // we've got the left and width, calculate top and height 0N/A // Don't run off the edge of the screen 0N/A // see 6240074 for more information 0N/A * Track a MouseEvent (either a drag or a press) and paint a new 0N/A * selected item, if necessary. 0N/A // FIXME: first unfurl after move is not at edge of the screen onto second monitor doesn't 0N/A // track mouse correctly. Problem is w/ UnfurledChoice coords 0N/A // Event coords are relative to the button, so translate a bit 0N/A // If x,y is over unfurled Choice, 0N/A // highlight item under cursor 0N/A // FIXME: If the Choice is unfurled and the mouse is pressed 0N/A // outside of the Choice, the mouse should ungrab on the 0N/A // the press, not the release 0N/A // See 6243382 for more information 0N/A trackSelection(local.x, local.y); 0N/A // See 6243382 for more information 0N/A // FIXME: If dragged off top or bottom, scroll if there's a vsb 0N/A // (ICK - we'll need a timer or our own event or something) 0N/A * fillRect with current Background color on the whole dropdown list. 0N/A * 6405689. In some cases we should erase background to eliminate painting 0N/A //System.out.println("UC.paint()"); 0N/A * Return a MouseEvent's Point in coordinates relative to the 0N/A // Event coords are relative to the button, so translate a bit 0N/A /* Returns true if the MouseEvent coords (which are based on the Choice) 0N/A * are inside of the UnfurledChoice. 0N/A * Tests if the mouse cursor is in the Unfurled Choice, yet not 0N/A * in the vertical scrollbar 0N/A * Overridden from XWindow() because we don't want to send 0N/A * fix for 6239938 : Choice drop-down does not disappear when it loses 0N/A * focus, on XToolkit 0N/A * We are able to handle all _Key_ events received by Choice when 0N/A * it is in opened state without sending it to EventQueue. 0N/A * If Choice is in closed state we should behave like before: send 0N/A * all events to EventQueue. 0N/A * To be compatible with Motif we should handle all KeyEvents in 0N/A * Choice if it is opened. KeyEvents should be sent into Java if Choice is not opened. 0N/A // fix for 6253211: PIT: MouseWheel events not triggered for Choice drop down in XAWT 0N/A //fix 6252982: PIT: Keyboard FocusTraversal not working when choice's drop-down is visible, on XToolkit 0N/A // notify XWindow that this event had been already handled and no need to post it again 0N/A // Fix for 6240046 : REG:Choice's Drop-down does not disappear when clicking somewhere, after popup menu is disposed 0N/A // if user presses Right Mouse Button on opened (unfurled) 0N/A // Choice then we mustn't open a popup menu. We could filter 0N/A // Mouse Events and handle them in XChoicePeer if Choice 0N/A // currently in opened state. 0N/A // fix 6251983: PIT: MouseDragged events not triggered 0N/A // fix 6251988: PIT: Choice consumes MouseReleased, MouseClicked events when clicking it with left button, 0N/A // MouseMoved events should be fired in Choice's comp if it's not opened 0N/A // Shouldn't generate Moved Events. CR : 6251995 0N/A //fix for 6272965: PIT: Choice triggers MousePressed when pressing mouse outside comp while drop-down is active, XTkt 0N/A //do not generate this kind of Events 0N/A /* Returns true if the MouseEvent coords 0N/A * are inside of the Choice itself (it doesnt's depends on 0N/A * if this choice opened or not). 0N/A * The listener interface for receiving "interesting" for XFileDialogPeer 0N/A * choice events (opening, closing). 0N/A * The listener added by means of the method addXChoicePeerListener 0N/A * A opening choice event is generated when the invoking unfurledChoice.toFront() 0N/A * A closing choice event is generated at the time of the processing the mouse releasing 0N/A * and the Enter pressing. 0N/A * see 6240074 for more information