@@ -148,6 +148,8 @@ public class Decorations extends Canvas {
148
148
private Object hNoTextSelection ;
149
149
private DragAndDrop dnd ;
150
150
151
+ private Element [] shadowEls ;
152
+
151
153
int titleBarHeight ;
152
154
153
155
/**
@@ -639,7 +641,7 @@ protected static void createResizeHandles(Element handle) {
639
641
}
640
642
}
641
643
642
- protected static void appendShadowHandles (Element handle , boolean top , boolean right , boolean bottom , boolean left ) {
644
+ protected static Element [] appendShadowHandles (Element handle , boolean top , boolean right , boolean bottom , boolean left ) {
643
645
String [] handles = new String [] {
644
646
left && top ? "shadow-left-top" : null ,
645
647
right && top ? "shadow-right-top" : null ,
@@ -651,9 +653,10 @@ protected static void appendShadowHandles(Element handle, boolean top, boolean r
651
653
right && bottom ? "shadow-right-bottom" : null ,
652
654
bottom ? "shadow-center-bottom" : null
653
655
};
656
+ Element [] elements = new Element [handles .length ];
654
657
for (int i = 0 ; i < handles .length ; i ++) {
655
658
if (handles [i ] != null ) {
656
- createCSSDiv (handle , handles [i ]);
659
+ elements [ i ] = createCSSDiv (handle , handles [i ]);
657
660
}
658
661
}
659
662
if (OS .isChrome10 ) {
@@ -662,17 +665,18 @@ protected static void appendShadowHandles(Element handle, boolean top, boolean r
662
665
if (OS .isIE ) {
663
666
handle .style .filter = "" ;
664
667
}
668
+ return elements ;
665
669
}
666
670
667
- protected static void createShadowHandles (Element handle ) {
668
- appendShadowHandles (handle , true , true , true , true );
671
+ protected static Element [] createShadowHandles (Element handle ) {
672
+ return appendShadowHandles (handle , true , true , true , true );
669
673
}
670
674
671
- protected static void createNarrowShadowHandles (Element handle ) {
672
- appendNarrowShadowHandles (handle , true , true , true , true );
675
+ protected static Element [] createNarrowShadowHandles (Element handle ) {
676
+ return appendNarrowShadowHandles (handle , true , true , true , true );
673
677
}
674
678
675
- protected static void appendNarrowShadowHandles (Element handle , boolean top , boolean right , boolean bottom , boolean left ) {
679
+ protected static Element [] appendNarrowShadowHandles (Element handle , boolean top , boolean right , boolean bottom , boolean left ) {
676
680
String [] handles = new String [] {
677
681
left && top ? "shadow-narrow-left-top" : null ,
678
682
right && top ? "shadow-narrow-right-top" : null ,
@@ -684,9 +688,10 @@ protected static void appendNarrowShadowHandles(Element handle, boolean top, boo
684
688
right && bottom ? "shadow-narrow-right-bottom" : null ,
685
689
bottom ? "shadow-narrow-center-bottom" : null
686
690
};
691
+ Element [] elements = new Element [handles .length ];
687
692
for (int i = 0 ; i < handles .length ; i ++) {
688
693
if (handles [i ] != null ) {
689
- createCSSDiv (handle , handles [i ]);
694
+ elements [ i ] = createCSSDiv (handle , handles [i ]);
690
695
}
691
696
}
692
697
if (OS .isChrome10 ) {
@@ -695,6 +700,148 @@ protected static void appendNarrowShadowHandles(Element handle, boolean top, boo
695
700
if (OS .isIE ) {
696
701
handle .style .filter = "" ;
697
702
}
703
+ return elements ;
704
+ }
705
+
706
+ protected static void adjustShadowOnCreated (Element [] elements , String defaultColor ) {
707
+ int shadowDepth = 16 ;
708
+ int verticalOffset = 8 ;
709
+ int horizontalDelta = 4 ;
710
+ /**
711
+ * @j2sNative
712
+ * if (window["swt.shadow.vertical.offset"] != null) {
713
+ * verticalOffset = window["swt.shadow.vertical.offset"];
714
+ * }
715
+ * if (window["swt.shadow.horizontal.delta"] != null) {
716
+ * horizontalDelta = window["swt.shadow.horizontal.delta"];
717
+ * }
718
+ */ { verticalOffset = 0 ; horizontalDelta = 0 ; }
719
+ if (verticalOffset > 0 || horizontalDelta > 0 ) {
720
+ adjustShadowDepth (elements , shadowDepth , verticalOffset , horizontalDelta , defaultColor );
721
+ }
722
+ }
723
+
724
+ protected static void adjustNarrowShadowOnCreated (Element [] elements , String defaultColor ) {
725
+ int shadowDepth = 8 ;
726
+ int verticalOffset = 4 ;
727
+ int horizontalDelta = 2 ;
728
+ /**
729
+ * @j2sNative
730
+ * if (window["swt.shadow.vertical.offset"] != null) {
731
+ * verticalOffset = window["swt.shadow.narrow.vertical.offset"];
732
+ * }
733
+ * if (window["swt.shadow.horizontal.delta"] != null) {
734
+ * horizontalDelta = window["swt.shadow.narrow.horizontal.delta"];
735
+ * }
736
+ */ { verticalOffset = 0 ; horizontalDelta = 0 ; }
737
+ if (verticalOffset > 0 || horizontalDelta > 0 ) {
738
+ adjustShadowDepth (elements , shadowDepth , verticalOffset , horizontalDelta , defaultColor );
739
+ }
740
+ }
741
+
742
+ protected static void adjustShadowDepth (Element [] shadowEls , int shadowDepth , int verticalOffset , int horizontalDelta ,
743
+ String defaultColor ) {
744
+ Element shadowEl = shadowEls [0 ]; // left-top
745
+ if (shadowEl != null ) {
746
+ if (horizontalDelta > 0 ) shadowEl .style .left = (horizontalDelta - shadowDepth ) + "px" ;
747
+ if (verticalOffset > 0 ) shadowEl .style .top = (verticalOffset - shadowDepth ) + "px" ;
748
+ }
749
+ shadowEl = shadowEls [1 ]; // right-top
750
+ if (shadowEl != null ) {
751
+ if (horizontalDelta > 0 ) shadowEl .style .right = (horizontalDelta - shadowDepth ) + "px" ;
752
+ if (verticalOffset > 0 ) shadowEl .style .top = (verticalOffset - shadowDepth ) + "px" ;
753
+ }
754
+ shadowEl = shadowEls [2 ]; // center-top
755
+ if (shadowEl != null ) {
756
+ if (horizontalDelta > 0 ) shadowEl .style .left = (shadowEls [3 ] == null ? 0 : horizontalDelta ) + "px" ;
757
+ if (verticalOffset > 0 ) shadowEl .style .top = (verticalOffset - shadowDepth ) + "px" ;
758
+ }
759
+ shadowEl = shadowEls [3 ]; // left-middle
760
+ if (shadowEl != null ) {
761
+ if (horizontalDelta > 0 ) shadowEl .style .left = (horizontalDelta - shadowDepth ) + "px" ;
762
+ if (verticalOffset > 0 ) shadowEl .style .top = verticalOffset + "px" ;
763
+ }
764
+ shadowEl = shadowEls [4 ]; // right-middle
765
+ if (shadowEl != null ) {
766
+ if (horizontalDelta > 0 ) shadowEl .style .right = (horizontalDelta - shadowDepth ) + "px" ;
767
+ if (verticalOffset > 0 ) shadowEl .style .top = verticalOffset + "px" ;
768
+ }
769
+ shadowEl = shadowEls [5 ]; // center-bottom
770
+ if (shadowEl != null && defaultColor != null && defaultColor .length () > 0 ) {
771
+ shadowEl .style .backgroundColor = defaultColor ; // default background-color
772
+ }
773
+ shadowEl = shadowEls [6 ]; // left-bottom
774
+ if (shadowEl != null ) {
775
+ if (horizontalDelta > 0 ) shadowEl .style .left = (horizontalDelta - shadowDepth ) + "px" ;
776
+ }
777
+ shadowEl = shadowEls [7 ]; // right-bottom
778
+ if (shadowEl != null ) {
779
+ if (horizontalDelta > 0 ) shadowEl .style .right = (horizontalDelta - shadowDepth ) + "px" ;
780
+ }
781
+ shadowEl = shadowEls [8 ]; // center-bottom
782
+ if (shadowEl != null ) {
783
+ if (horizontalDelta > 0 ) shadowEl .style .left = (shadowEls [3 ] == null ? 0 : horizontalDelta ) + "px" ;
784
+ }
785
+ }
786
+
787
+ protected static void adjustShadowOnResize (Element [] shadowEls , int cx , int cy ) {
788
+ int verticalOffset = 8 ;
789
+ int horizontalDelta = 4 ;
790
+ /**
791
+ * @j2sNative
792
+ * if (window["swt.shadow.vertical.offset"] != null) {
793
+ * verticalOffset = window["swt.shadow.vertical.offset"];
794
+ * }
795
+ * if (window["swt.shadow.horizontal.delta"] != null) {
796
+ * horizontalDelta = window["swt.shadow.horizontal.delta"];
797
+ * }
798
+ */ { verticalOffset = 0 ; horizontalDelta = 0 ; }
799
+ if (verticalOffset > 0 || horizontalDelta > 0 ) {
800
+ adjustShadowDimension (shadowEls , cx , cy , verticalOffset , horizontalDelta );
801
+ }
802
+ }
803
+
804
+ protected static void adjustNarrowShadowOnResize (Element [] shadowEls , int cx , int cy ) {
805
+ int verticalOffset = 4 ;
806
+ int horizontalDelta = 2 ;
807
+ /**
808
+ * @j2sNative
809
+ * if (window["swt.shadow.narrow.vertical.offset"] != null) {
810
+ * verticalOffset = window["swt.shadow.narrow.vertical.offset"];
811
+ * }
812
+ * if (window["swt.shadow.narrow.horizontal.delta"] != null) {
813
+ * horizontalDelta = window["swt.shadow.narrow.horizontal.delta"];
814
+ * }
815
+ */ { verticalOffset = 0 ; horizontalDelta = 0 ; }
816
+ if (verticalOffset > 0 || horizontalDelta > 0 ) {
817
+ adjustShadowDimension (shadowEls , cx , cy , verticalOffset , horizontalDelta );
818
+ }
819
+ }
820
+
821
+ protected static void adjustShadowDimension (Element [] shadowEls , int cx , int cy , int verticalOffset , int horizontalDelta ) {
822
+ int sides = 2 ;
823
+ if (shadowEls [3 ] == null ) {
824
+ sides --;
825
+ }
826
+ if (shadowEls [4 ] == null ) {
827
+ sides --;
828
+ }
829
+ Element shadowEl = shadowEls [2 ]; // center-top
830
+ if (shadowEl != null && cx > 0 ) {
831
+ if (horizontalDelta > 0 ) shadowEl .style .width = (cx - horizontalDelta * sides > 0 ? cx - horizontalDelta * sides : 0 ) + "px" ;
832
+ }
833
+ shadowEl = shadowEls [3 ]; // left-middle
834
+ if (shadowEl != null && cy > 0 ) {
835
+ if (horizontalDelta > 0 ) shadowEl .style .height = (cy - verticalOffset > 0 ? cy - verticalOffset : 0 ) + "px" ;
836
+ }
837
+ shadowEl = shadowEls [4 ]; // right-middle
838
+ if (shadowEl != null && cy > 0 ) {
839
+ if (horizontalDelta > 0 ) shadowEl .style .height = (cy - verticalOffset > 0 ? cy - verticalOffset : 0 ) + "px" ;
840
+ }
841
+ shadowEl = shadowEls [8 ]; // center-bottom
842
+ if (shadowEl != null && cx > 0 ) {
843
+ if (horizontalDelta > 0 ) shadowEl .style .width = (cx - horizontalDelta * sides > 0 ? cx - horizontalDelta * sides : 0 ) + "px" ;
844
+ }
698
845
}
699
846
700
847
protected void createHandle () {
@@ -745,12 +892,18 @@ public void run() {
745
892
createResizeHandles (handle );
746
893
}
747
894
boolean supportShadow = false ;
895
+ String defaultBGColor = null ;
748
896
/**
749
897
* @j2sNative
750
898
* supportShadow = window["swt.disable.shadow"] != true;
899
+ * defaultBGColor = window["swt.default.window.background"];
751
900
*/ {}
752
901
if (supportShadow && (style & SWT .NO_TRIM ) == 0 ) {
753
- createShadowHandles (handle );
902
+ shadowEls = createShadowHandles (handle );
903
+ if (defaultBGColor == null || defaultBGColor .length () == 0 ) {
904
+ defaultBGColor = "buttonface" ;
905
+ }
906
+ adjustShadowOnCreated (shadowEls , defaultBGColor );
754
907
}
755
908
if ((style & SWT .NO_TRIM ) == 0
756
909
&& (style & (SWT .TITLE | SWT .MIN | SWT .MAX | SWT .CLOSE )) != 0 ) {
@@ -1535,8 +1688,38 @@ void saveFocus () {
1535
1688
*/
1536
1689
public void setBackground (Color color ) {
1537
1690
checkWidget ();
1538
- if (color != null )
1539
- contentHandle .style .backgroundColor = color .getCSSHandle ();
1691
+ if (color != null ) {
1692
+ String cssHandle = color .getCSSHandle ();
1693
+ contentHandle .style .backgroundColor = cssHandle ;
1694
+ if (shadowEls != null && shadowEls [5 ] != null ) {
1695
+ int verticalOffset = 8 ;
1696
+ int horizontalDelta = 4 ;
1697
+ /**
1698
+ * @j2sNative
1699
+ * if (window["swt.shadow.vertical.offset"] != null) {
1700
+ * verticalOffset = window["swt.shadow.vertical.offset"];
1701
+ * }
1702
+ * if (window["swt.shadow.horizontal.delta"] != null) {
1703
+ * horizontalDelta = window["swt.shadow.horizontal.delta"];
1704
+ * }
1705
+ */ { verticalOffset = 0 ; horizontalDelta = 0 ; }
1706
+ if (verticalOffset > 0 || horizontalDelta > 0 ) {
1707
+ if ("transparent" .equals (cssHandle )) {
1708
+ String defaultBGColor = null ;
1709
+ /**
1710
+ * @j2sNative
1711
+ * defaultBGColor = window["swt.default.window.background"];
1712
+ */ { }
1713
+ if (defaultBGColor == null || defaultBGColor .length () == 0 ) {
1714
+ defaultBGColor = "buttonface" ;
1715
+ }
1716
+ shadowEls [5 ].style .backgroundColor = defaultBGColor ;
1717
+ } else {
1718
+ shadowEls [5 ].style .backgroundColor = cssHandle ;
1719
+ }
1720
+ }
1721
+ }
1722
+ }
1540
1723
}
1541
1724
void setBounds (int x , int y , int width , int height , int flags , boolean defer ) {
1542
1725
/*
@@ -2654,7 +2837,7 @@ protected boolean SetWindowPos(Object hWnd, Object hWndInsertAfter, int X, int Y
2654
2837
dh += mbh + 1 ;
2655
2838
tbh += mbh + 1 ;
2656
2839
}
2657
- contentHandle .style .top = (((style & SWT .BORDER ) != 0 ? 1 : 1 ) + tbh + 2 ) + "px" ;
2840
+ contentHandle .style .top = (((style & SWT .BORDER ) != 0 ? 2 : 2 ) + tbh + 2 ) + "px" ;
2658
2841
contentHandle .style .left = (((style & SWT .BORDER ) != 0 ? 1 : 1 ) + 2 ) + "px" ;
2659
2842
contentHandle .style .height = ((height - dh >= 0 ) ? height - dh : 0 ) + "px" ;
2660
2843
contentHandle .style .width = ((width - dw ) > 0 ? width - dw : 0 ) + "px" ;
@@ -2669,6 +2852,9 @@ protected boolean SetWindowPos(Object hWnd, Object hWndInsertAfter, int X, int Y
2669
2852
if ((style & SWT .NO_TRIM ) != 0 ) {
2670
2853
dw = 0 ;
2671
2854
dh = 0 ;
2855
+ } else if ((style & 0x0fffff ) == SWT .TOOL ) {
2856
+ dw = 2 ;
2857
+ dh = 2 ;
2672
2858
} else if ((style & SWT .TOOL ) != 0 ) {
2673
2859
dw = 4 ;
2674
2860
dh = 2 ;
@@ -2692,6 +2878,10 @@ protected boolean SetWindowPos(Object hWnd, Object hWndInsertAfter, int X, int Y
2692
2878
if ((style & SWT .BORDER ) != 0 ) {
2693
2879
cx -= 6 ;
2694
2880
cy -= 4 ;
2881
+ } else if ((style & 0x0fffff ) == SWT .TOOL ) {
2882
+ // do nothing
2883
+ cx -= 2 ;
2884
+ cy -= 2 ;
2695
2885
} else if ((style & SWT .NO_TRIM ) == 0 ) {
2696
2886
cx -= 2 ;
2697
2887
}
@@ -2712,6 +2902,9 @@ protected boolean SetWindowPos(Object hWnd, Object hWndInsertAfter, int X, int Y
2712
2902
el .style .top = Y + "px" ;
2713
2903
el .style .width = (cx > 0 ? cx : 0 ) + "px" ;
2714
2904
el .style .height = (cy > 0 ? cy : 0 ) + "px" ;
2905
+ if (shadowEls != null ) {
2906
+ adjustShadowOnResize (shadowEls , cx , cy );
2907
+ }
2715
2908
2716
2909
return true ;
2717
2910
// return super.SetWindowPos(hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags);
0 commit comments