1 /*
2 * Copyright (c) 1996, 2014, 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
552 return null;
553 }
554 }
555
556 //Returns null for Components not yet added to a Container
557 public ColorModel getColorModel(int transparency) {
558 // return WToolkit.config.getColorModel(transparency);
559 GraphicsConfiguration gc = getGraphicsConfiguration();
560 if (gc != null) {
561 return gc.getColorModel(transparency);
562 }
563 else {
564 return null;
565 }
566 }
567
568 // fallback default font object
569 final static Font defaultFont = new Font(Font.DIALOG, Font.PLAIN, 12);
570
571 @Override
572 @SuppressWarnings("deprecation")
573 public Graphics getGraphics() {
574 if (isDisposed()) {
575 return null;
576 }
577
578 Component target = (Component)getTarget();
579 Window window = SunToolkit.getContainingWindow(target);
580 if (window != null) {
581 Graphics g =
582 ((WWindowPeer)window.getPeer()).getTranslucentGraphics();
583 // getTranslucentGraphics() returns non-null value for non-opaque windows only
584 if (g != null) {
585 // Non-opaque windows do not support heavyweight children.
586 // Redirect all painting to the Window's Graphics instead.
587 // The caller is responsible for calling the
588 // WindowPeer.updateWindow() after painting has finished.
589 int x = 0, y = 0;
590 for (Component c = target; c != window; c = c.getParent()) {
591 x += c.getX();
592 y += c.getY();
593 }
594
595 g.translate(x, y);
596 g.clipRect(0, 0, target.getWidth(), target.getHeight());
597
598 return g;
599 }
600 }
601
602 SurfaceData surfaceData = this.surfaceData;
668 public Color getBackgroundNoSync() {
669 return background;
670 }
671
672 private native void _setForeground(int rgb);
673 private native void _setBackground(int rgb);
674
675 @Override
676 public synchronized void setFont(Font f) {
677 font = f;
678 _setFont(f);
679 }
680 synchronized native void _setFont(Font f);
681 @Override
682 public void updateCursorImmediately() {
683 WGlobalCursorManager.getCursorManager().updateCursorImmediately();
684 }
685
686 // TODO: consider moving it to KeyboardFocusManagerPeerImpl
687 @Override
688 @SuppressWarnings("deprecation")
689 public boolean requestFocus(Component lightweightChild, boolean temporary,
690 boolean focusedWindowChangeAllowed, long time,
691 CausedFocusEvent.Cause cause)
692 {
693 if (WKeyboardFocusManagerPeer.
694 processSynchronousLightweightTransfer((Component)target, lightweightChild, temporary,
695 focusedWindowChangeAllowed, time))
696 {
697 return true;
698 }
699
700 int result = WKeyboardFocusManagerPeer
701 .shouldNativelyFocusHeavyweight((Component)target, lightweightChild,
702 temporary, focusedWindowChangeAllowed,
703 time, cause);
704
705 switch (result) {
706 case WKeyboardFocusManagerPeer.SNFH_FAILURE:
707 return false;
708 case WKeyboardFocusManagerPeer.SNFH_SUCCESS_PROCEED:
709 if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
710 focusLog.finer("Proceeding with request to " + lightweightChild + " in " + target);
711 }
712 Window parentWindow = SunToolkit.getContainingWindow((Component)target);
713 if (parentWindow == null) {
714 return rejectFocusRequestHelper("WARNING: Parent window is null");
715 }
716 WWindowPeer wpeer = (WWindowPeer)parentWindow.getPeer();
717 if (wpeer == null) {
718 return rejectFocusRequestHelper("WARNING: Parent window's peer is null");
719 }
720 boolean res = wpeer.requestWindowFocus(cause);
721
722 if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
723 focusLog.finer("Requested window focus: " + res);
724 }
725 // If parent window can be made focused and has been made focused(synchronously)
726 // then we can proceed with children, otherwise we retreat.
727 if (!(res && parentWindow.isFocused())) {
728 return rejectFocusRequestHelper("Waiting for asynchronous processing of the request");
729 }
730 return WKeyboardFocusManagerPeer.deliverFocus(lightweightChild,
731 (Component)target,
732 temporary,
733 focusedWindowChangeAllowed,
734 time, cause);
735
736 case WKeyboardFocusManagerPeer.SNFH_SUCCESS_HANDLED:
1087 // these problems are no longer present in Vista
1088 return !isTranslucent || Win32GraphicsEnvironment.isVistaOS();
1089 }
1090
1091 /**
1092 * Disables acceleration for this peer.
1093 */
1094 public void disableAcceleration() {
1095 isAccelCapable = false;
1096 }
1097
1098
1099 native void setRectangularShape(int lox, int loy, int hix, int hiy,
1100 Region region);
1101
1102
1103 // REMIND: Temp workaround for issues with using HW acceleration
1104 // in the browser on Vista when DWM is enabled.
1105 // @return true if the toplevel container is not an EmbeddedFrame or
1106 // if this EmbeddedFrame is acceleration capable, false otherwise
1107 @SuppressWarnings("deprecation")
1108 private static final boolean isContainingTopLevelAccelCapable(Component c) {
1109 while (c != null && !(c instanceof WEmbeddedFrame)) {
1110 c = c.getParent();
1111 }
1112 if (c == null) {
1113 return true;
1114 }
1115 return ((WEmbeddedFramePeer)c.getPeer()).isAccelCapable();
1116 }
1117
1118 /**
1119 * Applies the shape to the native component window.
1120 * @since 1.7
1121 */
1122 @Override
1123 @SuppressWarnings("deprecation")
1124 public void applyShape(Region shape) {
1125 if (shapeLog.isLoggable(PlatformLogger.Level.FINER)) {
1126 shapeLog.finer("*** INFO: Setting shape: PEER: " + this
1127 + "; TARGET: " + target
1128 + "; SHAPE: " + shape);
1129 }
1130
1131 if (shape != null) {
1132 setRectangularShape(shape.getLoX(), shape.getLoY(), shape.getHiX(), shape.getHiY(),
1133 (shape.isRectangular() ? null : shape));
1134 } else {
1135 setRectangularShape(0, 0, 0, 0, null);
1136 }
1137 }
1138
1139 /**
1140 * Lowers this component at the bottom of the above component. If the above parameter
1141 * is null then the method places this component at the top of the Z-order.
1142 */
1143 @Override
|
1 /*
2 * Copyright (c) 1996, 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
552 return null;
553 }
554 }
555
556 //Returns null for Components not yet added to a Container
557 public ColorModel getColorModel(int transparency) {
558 // return WToolkit.config.getColorModel(transparency);
559 GraphicsConfiguration gc = getGraphicsConfiguration();
560 if (gc != null) {
561 return gc.getColorModel(transparency);
562 }
563 else {
564 return null;
565 }
566 }
567
568 // fallback default font object
569 final static Font defaultFont = new Font(Font.DIALOG, Font.PLAIN, 12);
570
571 @Override
572 public Graphics getGraphics() {
573 if (isDisposed()) {
574 return null;
575 }
576
577 Component target = (Component)getTarget();
578 Window window = SunToolkit.getContainingWindow(target);
579 if (window != null) {
580 final WWindowPeer wpeer = AWTAccessor.getComponentAccessor()
581 .getPeer(window);
582 Graphics g = wpeer.getTranslucentGraphics();
583 // getTranslucentGraphics() returns non-null value for non-opaque windows only
584 if (g != null) {
585 // Non-opaque windows do not support heavyweight children.
586 // Redirect all painting to the Window's Graphics instead.
587 // The caller is responsible for calling the
588 // WindowPeer.updateWindow() after painting has finished.
589 int x = 0, y = 0;
590 for (Component c = target; c != window; c = c.getParent()) {
591 x += c.getX();
592 y += c.getY();
593 }
594
595 g.translate(x, y);
596 g.clipRect(0, 0, target.getWidth(), target.getHeight());
597
598 return g;
599 }
600 }
601
602 SurfaceData surfaceData = this.surfaceData;
668 public Color getBackgroundNoSync() {
669 return background;
670 }
671
672 private native void _setForeground(int rgb);
673 private native void _setBackground(int rgb);
674
675 @Override
676 public synchronized void setFont(Font f) {
677 font = f;
678 _setFont(f);
679 }
680 synchronized native void _setFont(Font f);
681 @Override
682 public void updateCursorImmediately() {
683 WGlobalCursorManager.getCursorManager().updateCursorImmediately();
684 }
685
686 // TODO: consider moving it to KeyboardFocusManagerPeerImpl
687 @Override
688 public boolean requestFocus(Component lightweightChild, boolean temporary,
689 boolean focusedWindowChangeAllowed, long time,
690 CausedFocusEvent.Cause cause)
691 {
692 if (WKeyboardFocusManagerPeer.
693 processSynchronousLightweightTransfer((Component)target, lightweightChild, temporary,
694 focusedWindowChangeAllowed, time))
695 {
696 return true;
697 }
698
699 int result = WKeyboardFocusManagerPeer
700 .shouldNativelyFocusHeavyweight((Component)target, lightweightChild,
701 temporary, focusedWindowChangeAllowed,
702 time, cause);
703
704 switch (result) {
705 case WKeyboardFocusManagerPeer.SNFH_FAILURE:
706 return false;
707 case WKeyboardFocusManagerPeer.SNFH_SUCCESS_PROCEED:
708 if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
709 focusLog.finer("Proceeding with request to " + lightweightChild + " in " + target);
710 }
711 Window parentWindow = SunToolkit.getContainingWindow((Component)target);
712 if (parentWindow == null) {
713 return rejectFocusRequestHelper("WARNING: Parent window is null");
714 }
715 final WWindowPeer wpeer = AWTAccessor.getComponentAccessor()
716 .getPeer(parentWindow);
717 if (wpeer == null) {
718 return rejectFocusRequestHelper("WARNING: Parent window's peer is null");
719 }
720 boolean res = wpeer.requestWindowFocus(cause);
721
722 if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
723 focusLog.finer("Requested window focus: " + res);
724 }
725 // If parent window can be made focused and has been made focused(synchronously)
726 // then we can proceed with children, otherwise we retreat.
727 if (!(res && parentWindow.isFocused())) {
728 return rejectFocusRequestHelper("Waiting for asynchronous processing of the request");
729 }
730 return WKeyboardFocusManagerPeer.deliverFocus(lightweightChild,
731 (Component)target,
732 temporary,
733 focusedWindowChangeAllowed,
734 time, cause);
735
736 case WKeyboardFocusManagerPeer.SNFH_SUCCESS_HANDLED:
1087 // these problems are no longer present in Vista
1088 return !isTranslucent || Win32GraphicsEnvironment.isVistaOS();
1089 }
1090
1091 /**
1092 * Disables acceleration for this peer.
1093 */
1094 public void disableAcceleration() {
1095 isAccelCapable = false;
1096 }
1097
1098
1099 native void setRectangularShape(int lox, int loy, int hix, int hiy,
1100 Region region);
1101
1102
1103 // REMIND: Temp workaround for issues with using HW acceleration
1104 // in the browser on Vista when DWM is enabled.
1105 // @return true if the toplevel container is not an EmbeddedFrame or
1106 // if this EmbeddedFrame is acceleration capable, false otherwise
1107 private static final boolean isContainingTopLevelAccelCapable(Component c) {
1108 while (c != null && !(c instanceof WEmbeddedFrame)) {
1109 c = c.getParent();
1110 }
1111 if (c == null) {
1112 return true;
1113 }
1114 final WEmbeddedFramePeer peer = AWTAccessor.getComponentAccessor()
1115 .getPeer(c);
1116 return peer.isAccelCapable();
1117 }
1118
1119 /**
1120 * Applies the shape to the native component window.
1121 * @since 1.7
1122 */
1123 @Override
1124 public void applyShape(Region shape) {
1125 if (shapeLog.isLoggable(PlatformLogger.Level.FINER)) {
1126 shapeLog.finer("*** INFO: Setting shape: PEER: " + this
1127 + "; TARGET: " + target
1128 + "; SHAPE: " + shape);
1129 }
1130
1131 if (shape != null) {
1132 setRectangularShape(shape.getLoX(), shape.getLoY(), shape.getHiX(), shape.getHiY(),
1133 (shape.isRectangular() ? null : shape));
1134 } else {
1135 setRectangularShape(0, 0, 0, 0, null);
1136 }
1137 }
1138
1139 /**
1140 * Lowers this component at the bottom of the above component. If the above parameter
1141 * is null then the method places this component at the top of the Z-order.
1142 */
1143 @Override
|