1 /* 2 * Copyright (c) 2005, 2015, 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 23 * questions. 24 */ 25 package sun.awt.X11; 26 27 import java.awt.*; 28 import java.awt.peer.*; 29 import java.awt.event.*; 30 import java.awt.image.ColorModel; 31 32 import sun.awt.*; 33 34 import java.util.ArrayList; 35 import java.util.Vector; 36 import sun.util.logging.PlatformLogger; 37 import sun.java2d.SurfaceData; 38 import sun.java2d.SunGraphics2D; 39 40 /** 41 * The abstract class XBaseMenuWindow is the superclass 42 * of all menu windows. 43 */ 44 public abstract class XBaseMenuWindow extends XWindow { 45 46 /************************************************ 47 * 48 * Data members 49 * 50 ************************************************/ 51 52 private static PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XBaseMenuWindow"); 53 54 /* 55 * Colors are calculated using MotifColorUtilities class 56 * from backgroundColor and are contained in these vars. 57 */ 58 private Color backgroundColor; 639 return t; 640 } 641 t = t.getParentMenuWindow(); 642 } 643 return null; 644 } 645 } 646 647 /************************************************ 648 * 649 * Primitives for getSubmenuBounds 650 * 651 * These functions are invoked from getSubmenuBounds 652 * implementations in different order. They check if window 653 * of size windowSize fits to the specified edge of 654 * rectangle itemBounds on the screen of screenSize. 655 * Return rectangle that occupies the window if it fits or null. 656 * 657 ************************************************/ 658 659 /** 660 * Checks if window fits below specified item 661 * returns rectangle that the window fits to or null. 662 * @param itemBounds rectangle of item in global coordinates 663 * @param windowSize size of submenu window to fit 664 * @param screenSize size of screen 665 */ 666 Rectangle fitWindowBelow(Rectangle itemBounds, Dimension windowSize, Dimension screenSize) { 667 int width = windowSize.width; 668 int height = windowSize.height; 669 //Fix for 6267162: PIT: Popup Menu gets hidden below the screen when opened 670 //near the periphery of the screen, XToolkit 671 //Window should be moved if it's outside top-left screen bounds 672 int x = (itemBounds.x > 0) ? itemBounds.x : 0; 673 int y = (itemBounds.y + itemBounds.height > 0) ? itemBounds.y + itemBounds.height : 0; 674 if (y + height <= screenSize.height) { 675 //move it to the left if needed 676 if (width > screenSize.width) { 677 width = screenSize.width; 678 } 679 if (x + width > screenSize.width) { 680 x = screenSize.width - width; 681 } 682 return new Rectangle(x, y, width, height); 683 } else { 684 return null; 685 } 686 } 687 688 /** 689 * Checks if window fits above specified item 690 * returns rectangle that the window fits to or null. 691 * @param itemBounds rectangle of item in global coordinates 692 * @param windowSize size of submenu window to fit 693 * @param screenSize size of screen 694 */ 695 Rectangle fitWindowAbove(Rectangle itemBounds, Dimension windowSize, Dimension screenSize) { 696 int width = windowSize.width; 697 int height = windowSize.height; 698 //Fix for 6267162: PIT: Popup Menu gets hidden below the screen when opened 699 //near the periphery of the screen, XToolkit 700 //Window should be moved if it's outside bottom-left screen bounds 701 int x = (itemBounds.x > 0) ? itemBounds.x : 0; 702 int y = (itemBounds.y > screenSize.height) ? screenSize.height - height : itemBounds.y - height; 703 if (y >= 0) { 704 //move it to the left if needed 705 if (width > screenSize.width) { 706 width = screenSize.width; 707 } 708 if (x + width > screenSize.width) { 709 x = screenSize.width - width; 710 } 711 return new Rectangle(x, y, width, height); 712 } else { 713 return null; 714 } 715 } 716 717 /** 718 * Checks if window fits to the right specified item 719 * returns rectangle that the window fits to or null. 720 * @param itemBounds rectangle of item in global coordinates 721 * @param windowSize size of submenu window to fit 722 * @param screenSize size of screen 723 */ 724 Rectangle fitWindowRight(Rectangle itemBounds, Dimension windowSize, Dimension screenSize) { 725 int width = windowSize.width; 726 int height = windowSize.height; 727 //Fix for 6267162: PIT: Popup Menu gets hidden below the screen when opened 728 //near the periphery of the screen, XToolkit 729 //Window should be moved if it's outside top-left screen bounds 730 int x = (itemBounds.x + itemBounds.width > 0) ? itemBounds.x + itemBounds.width : 0; 731 int y = (itemBounds.y > 0) ? itemBounds.y : 0; 732 if (x + width <= screenSize.width) { 733 //move it to the top if needed 734 if (height > screenSize.height) { 735 height = screenSize.height; 736 } 737 if (y + height > screenSize.height) { 738 y = screenSize.height - height; 739 } 740 return new Rectangle(x, y, width, height); 741 } else { 742 return null; 743 } 744 } 745 746 /** 747 * Checks if window fits to the left specified item 748 * returns rectangle that the window fits to or null. 749 * @param itemBounds rectangle of item in global coordinates 750 * @param windowSize size of submenu window to fit 751 * @param screenSize size of screen 752 */ 753 Rectangle fitWindowLeft(Rectangle itemBounds, Dimension windowSize, Dimension screenSize) { 754 int width = windowSize.width; 755 int height = windowSize.height; 756 //Fix for 6267162: PIT: Popup Menu gets hidden below the screen when opened 757 //near the periphery of the screen, XToolkit 758 //Window should be moved if it's outside top-right screen bounds 759 int x = (itemBounds.x < screenSize.width) ? itemBounds.x - width : screenSize.width - width; 760 int y = (itemBounds.y > 0) ? itemBounds.y : 0; 761 if (x >= 0) { 762 //move it to the top if needed 763 if (height > screenSize.height) { 764 height = screenSize.height; 765 } 766 if (y + height > screenSize.height) { 767 y = screenSize.height - height; 768 } 769 return new Rectangle(x, y, width, height); 770 } else { 771 return null; 772 } 773 } 774 775 /** 776 * The last thing we can do with the window 777 * to fit it on screen - move it to the 778 * top-left edge and cut by screen dimensions 779 * @param windowSize size of submenu window to fit 780 * @param screenSize size of screen 781 */ 782 Rectangle fitWindowToScreen(Dimension windowSize, Dimension screenSize) { 783 int width = (windowSize.width < screenSize.width) ? windowSize.width : screenSize.width; 784 int height = (windowSize.height < screenSize.height) ? windowSize.height : screenSize.height; 785 return new Rectangle(0, 0, width, height); 786 } 787 788 789 /************************************************ 790 * 791 * Utility functions for manipulating colors 792 * 793 ************************************************/ 794 795 /** 796 * This function is called before every painting. 797 * TODO:It would be better to add PropertyChangeListener 798 * to target component 799 * TODO:It would be better to access background color 800 * not invoking user-overridable function 801 */ 802 void resetColors() { 803 replaceColors((target == null) ? SystemColor.window : target.getBackground()); 804 } 805 | 1 /* 2 * Copyright (c) 2005, 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 23 * questions. 24 */ 25 package sun.awt.X11; 26 27 import java.awt.*; 28 import java.awt.event.*; 29 30 import sun.awt.*; 31 32 import java.awt.peer.ComponentPeer; 33 import java.util.ArrayList; 34 import java.util.Vector; 35 import sun.util.logging.PlatformLogger; 36 import sun.java2d.SurfaceData; 37 38 /** 39 * The abstract class XBaseMenuWindow is the superclass 40 * of all menu windows. 41 */ 42 public abstract class XBaseMenuWindow extends XWindow { 43 44 /************************************************ 45 * 46 * Data members 47 * 48 ************************************************/ 49 50 private static PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XBaseMenuWindow"); 51 52 /* 53 * Colors are calculated using MotifColorUtilities class 54 * from backgroundColor and are contained in these vars. 55 */ 56 private Color backgroundColor; 637 return t; 638 } 639 t = t.getParentMenuWindow(); 640 } 641 return null; 642 } 643 } 644 645 /************************************************ 646 * 647 * Primitives for getSubmenuBounds 648 * 649 * These functions are invoked from getSubmenuBounds 650 * implementations in different order. They check if window 651 * of size windowSize fits to the specified edge of 652 * rectangle itemBounds on the screen of screenSize. 653 * Return rectangle that occupies the window if it fits or null. 654 * 655 ************************************************/ 656 657 GraphicsConfiguration getCurrentGraphicsConfiguration() { 658 Component hw = SunToolkit.getHeavyweightComponent(target); 659 XWindow peer = AWTAccessor.getComponentAccessor().getPeer(hw); 660 if (peer != null && peer.graphicsConfig != null) { 661 return peer.graphicsConfig; 662 } 663 return graphicsConfig; 664 } 665 666 /** 667 * Checks if window fits below specified item 668 * returns rectangle that the window fits to or null. 669 * @param itemBounds rectangle of item in global coordinates 670 * @param windowSize size of submenu window to fit 671 * @param screenBounds size of screen 672 */ 673 Rectangle fitWindowBelow(Rectangle itemBounds, Dimension windowSize, Rectangle screenBounds) { 674 int width = windowSize.width; 675 int height = windowSize.height; 676 //Fix for 6267162: PIT: Popup Menu gets hidden below the screen when opened 677 //near the periphery of the screen, XToolkit 678 //Window should be moved if it's outside top-left screen bounds 679 int x = (itemBounds.x > screenBounds.x) ? itemBounds.x : screenBounds.x; 680 int y = (itemBounds.y + itemBounds.height > screenBounds.y) ? itemBounds.y + itemBounds.height : screenBounds.y; 681 if (y + height <= screenBounds.y + screenBounds.height) { 682 //move it to the left if needed 683 if (width > screenBounds.width) { 684 width = screenBounds.width; 685 } 686 if (x + width > screenBounds.x + screenBounds.width) { 687 x = screenBounds.x + screenBounds.width - width; 688 } 689 return new Rectangle(x, y, width, height); 690 } else { 691 return null; 692 } 693 } 694 695 /** 696 * Checks if window fits above specified item 697 * returns rectangle that the window fits to or null. 698 * @param itemBounds rectangle of item in global coordinates 699 * @param windowSize size of submenu window to fit 700 * @param screenBounds size of screen 701 */ 702 Rectangle fitWindowAbove(Rectangle itemBounds, Dimension windowSize, Rectangle screenBounds) { 703 int width = windowSize.width; 704 int height = windowSize.height; 705 //Fix for 6267162: PIT: Popup Menu gets hidden below the screen when opened 706 //near the periphery of the screen, XToolkit 707 //Window should be moved if it's outside bottom-left screen bounds 708 int x = (itemBounds.x > screenBounds.x) ? itemBounds.x : screenBounds.x; 709 int y = (itemBounds.y > screenBounds.y + screenBounds.height) ? screenBounds.y + screenBounds.height - height : itemBounds.y - height; 710 if (y >= screenBounds.y) { 711 //move it to the left if needed 712 if (width > screenBounds.width) { 713 width = screenBounds.width; 714 } 715 if (x + width > screenBounds.x + screenBounds.width) { 716 x = screenBounds.x + screenBounds.width - width; 717 } 718 return new Rectangle(x, y, width, height); 719 } else { 720 return null; 721 } 722 } 723 724 /** 725 * Checks if window fits to the right specified item 726 * returns rectangle that the window fits to or null. 727 * @param itemBounds rectangle of item in global coordinates 728 * @param windowSize size of submenu window to fit 729 * @param screenBounds size of screen 730 */ 731 Rectangle fitWindowRight(Rectangle itemBounds, Dimension windowSize, Rectangle screenBounds) { 732 int width = windowSize.width; 733 int height = windowSize.height; 734 //Fix for 6267162: PIT: Popup Menu gets hidden below the screen when opened 735 //near the periphery of the screen, XToolkit 736 //Window should be moved if it's outside top-left screen bounds 737 int x = (itemBounds.x + itemBounds.width > screenBounds.x) ? itemBounds.x + itemBounds.width : screenBounds.x; 738 int y = (itemBounds.y > screenBounds.y) ? itemBounds.y : screenBounds.y; 739 if (x + width <= screenBounds.x + screenBounds.width) { 740 //move it to the top if needed 741 if (height > screenBounds.height) { 742 height = screenBounds.height; 743 } 744 if (y + height > screenBounds.y + screenBounds.height) { 745 y = screenBounds.y + screenBounds.height - height; 746 } 747 return new Rectangle(x, y, width, height); 748 } else { 749 return null; 750 } 751 } 752 753 /** 754 * Checks if window fits to the left specified item 755 * returns rectangle that the window fits to or null. 756 * @param itemBounds rectangle of item in global coordinates 757 * @param windowSize size of submenu window to fit 758 * @param screenBounds size of screen 759 */ 760 Rectangle fitWindowLeft(Rectangle itemBounds, Dimension windowSize, Rectangle screenBounds) { 761 int width = windowSize.width; 762 int height = windowSize.height; 763 //Fix for 6267162: PIT: Popup Menu gets hidden below the screen when opened 764 //near the periphery of the screen, XToolkit 765 //Window should be moved if it's outside top-right screen bounds 766 int x = (itemBounds.x < screenBounds.x + screenBounds.width) ? itemBounds.x - width : screenBounds.x + screenBounds.width - width; 767 int y = (itemBounds.y > screenBounds.y) ? itemBounds.y : screenBounds.y; 768 if (x >= screenBounds.x) { 769 //move it to the top if needed 770 if (height > screenBounds.height) { 771 height = screenBounds.height; 772 } 773 if (y + height > screenBounds.y + screenBounds.height) { 774 y = screenBounds.y + screenBounds.height - height; 775 } 776 return new Rectangle(x, y, width, height); 777 } else { 778 return null; 779 } 780 } 781 782 /** 783 * The last thing we can do with the window 784 * to fit it on screen - move it to the 785 * top-left edge and cut by screen dimensions 786 * @param windowSize size of submenu window to fit 787 * @param screenBounds size of screen 788 */ 789 Rectangle fitWindowToScreen(Dimension windowSize, Rectangle screenBounds) { 790 int width = (windowSize.width < screenBounds.width) ? windowSize.width : screenBounds.width; 791 int height = (windowSize.height < screenBounds.height) ? windowSize.height : screenBounds.height; 792 return new Rectangle(screenBounds.x, screenBounds.y, width, height); 793 } 794 795 796 /************************************************ 797 * 798 * Utility functions for manipulating colors 799 * 800 ************************************************/ 801 802 /** 803 * This function is called before every painting. 804 * TODO:It would be better to add PropertyChangeListener 805 * to target component 806 * TODO:It would be better to access background color 807 * not invoking user-overridable function 808 */ 809 void resetColors() { 810 replaceColors((target == null) ? SystemColor.window : target.getBackground()); 811 } 812 |