Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d90221c

Browse files
committed
Improve shadows
Adjust layout pixels // Commit a lot of old code changes, thanks to airline delay for more than 2 hours
1 parent e15d78e commit d90221c

File tree

17 files changed

+648
-181
lines changed

17 files changed

+648
-181
lines changed

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/internal/ResizeHandler.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,18 +186,17 @@ public void updateCentered() {
186186
public void updateCornered() {
187187
Rectangle clientArea = getClientArea();
188188
Point size = shell.getSize();
189-
int trimWidth = (shell.getStyle() & SWT.NO_TRIM) != 0 ? 0 : 4; // 4: shadow
190189
if ((status & SWT.TOP) != 0){
191190
if ((status & SWT.LEFT) != 0) {
192191
shell.setLocation(clientArea.x, clientArea.y);
193192
} else if ((status & SWT.RIGHT) != 0) {
194-
shell.setLocation(clientArea.width - size.x + trimWidth, clientArea.y);
193+
shell.setLocation(clientArea.width - size.x, clientArea.y);
195194
}
196195
} else if ((status & SWT.BOTTOM) != 0){
197196
if ((status & SWT.LEFT) != 0) {
198-
shell.setLocation(clientArea.x, clientArea.height - 2 - size.y + clientArea.y + trimWidth);
197+
shell.setLocation(clientArea.x, clientArea.height - size.y + clientArea.y);
199198
} else if ((status & SWT.RIGHT) != 0) {
200-
shell.setLocation(clientArea.width - size.x + trimWidth, clientArea.height - 2 - size.y + clientArea.y + trimWidth);
199+
shell.setLocation(clientArea.width - size.x, clientArea.height - size.y + clientArea.y);
201200
}
202201
}
203202
}

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/widgets/About.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,18 @@ public static void openAbout(Shell objShell) {
5252
}
5353
aboutShell.setText("About Java2Script");
5454

55+
String designer = null;
56+
/**
57+
* @j2sNative
58+
* designer = window["swt.designer.os"];
59+
* window["swt.designer.os"] = "win";
60+
*/ { designer = "win"; }
5561
createContents(aboutShell);
62+
if (designer != null)
63+
/**
64+
* @j2sNative
65+
* window["swt.designer.os"] = designer;
66+
*/ {}
5667
aboutShell.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
5768
final GridLayout gridLayout = new GridLayout();
5869
gridLayout.verticalSpacing = 0;

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/widgets/Button.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@
3737
height:100%;
3838
box-sizing: border-box !important;
3939
}
40-
40+
button.button-push div {
41+
background-color:transparent;
42+
}
43+
button.button-push {
44+
text-align:center;
45+
}
4146
* html .button-push {
4247
font-family:Tahoma, Arial, sans-serif;
4348
font-size:1em;

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/widgets/Control.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2435,7 +2435,11 @@ public void setFont (Font font) {
24352435
return;
24362436
}
24372437
if (font.data.name != null) {
2438-
handle.style.fontFamily = font.data.name;
2438+
if (!"Arial".equals(font.data.name)) {
2439+
handle.style.fontFamily = font.data.name + ", Arial, sans-serif";
2440+
} else {
2441+
handle.style.fontFamily = font.data.name;
2442+
}
24392443
}
24402444
String fontSize = font.data.height + "pt";
24412445
/**

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/widgets/Decorations.java

Lines changed: 205 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ public class Decorations extends Canvas {
148148
private Object hNoTextSelection;
149149
private DragAndDrop dnd;
150150

151+
private Element[] shadowEls;
152+
151153
int titleBarHeight;
152154

153155
/**
@@ -639,7 +641,7 @@ protected static void createResizeHandles(Element handle) {
639641
}
640642
}
641643

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) {
643645
String[] handles = new String[] {
644646
left && top ? "shadow-left-top" : null,
645647
right && top ? "shadow-right-top" : null,
@@ -651,9 +653,10 @@ protected static void appendShadowHandles(Element handle, boolean top, boolean r
651653
right && bottom ? "shadow-right-bottom" : null,
652654
bottom ? "shadow-center-bottom" : null
653655
};
656+
Element[] elements = new Element[handles.length];
654657
for (int i = 0; i < handles.length; i++) {
655658
if (handles[i] != null) {
656-
createCSSDiv(handle, handles[i]);
659+
elements[i] = createCSSDiv(handle, handles[i]);
657660
}
658661
}
659662
if (OS.isChrome10) {
@@ -662,17 +665,18 @@ protected static void appendShadowHandles(Element handle, boolean top, boolean r
662665
if (OS.isIE) {
663666
handle.style.filter = "";
664667
}
668+
return elements;
665669
}
666670

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);
669673
}
670674

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);
673677
}
674678

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) {
676680
String[] handles = new String[] {
677681
left && top ? "shadow-narrow-left-top" : null,
678682
right && top ? "shadow-narrow-right-top" : null,
@@ -684,9 +688,10 @@ protected static void appendNarrowShadowHandles(Element handle, boolean top, boo
684688
right && bottom ? "shadow-narrow-right-bottom" : null,
685689
bottom ? "shadow-narrow-center-bottom" : null
686690
};
691+
Element[] elements = new Element[handles.length];
687692
for (int i = 0; i < handles.length; i++) {
688693
if (handles[i] != null) {
689-
createCSSDiv(handle, handles[i]);
694+
elements[i] = createCSSDiv(handle, handles[i]);
690695
}
691696
}
692697
if (OS.isChrome10) {
@@ -695,6 +700,148 @@ protected static void appendNarrowShadowHandles(Element handle, boolean top, boo
695700
if (OS.isIE) {
696701
handle.style.filter = "";
697702
}
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+
}
698845
}
699846

700847
protected void createHandle() {
@@ -745,12 +892,18 @@ public void run() {
745892
createResizeHandles(handle);
746893
}
747894
boolean supportShadow = false;
895+
String defaultBGColor = null;
748896
/**
749897
* @j2sNative
750898
* supportShadow = window["swt.disable.shadow"] != true;
899+
* defaultBGColor = window["swt.default.window.background"];
751900
*/ {}
752901
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);
754907
}
755908
if ((style & SWT.NO_TRIM) == 0
756909
&& (style & (SWT.TITLE | SWT.MIN | SWT.MAX | SWT.CLOSE)) != 0) {
@@ -1535,8 +1688,38 @@ void saveFocus () {
15351688
*/
15361689
public void setBackground(Color color) {
15371690
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+
}
15401723
}
15411724
void setBounds (int x, int y, int width, int height, int flags, boolean defer) {
15421725
/*
@@ -2654,7 +2837,7 @@ protected boolean SetWindowPos(Object hWnd, Object hWndInsertAfter, int X, int Y
26542837
dh += mbh + 1;
26552838
tbh += mbh + 1;
26562839
}
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";
26582841
contentHandle.style.left = (((style & SWT.BORDER) != 0 ? 1 : 1) + 2) + "px";
26592842
contentHandle.style.height = ((height - dh >= 0) ? height - dh : 0) + "px";
26602843
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
26692852
if ((style & SWT.NO_TRIM) != 0) {
26702853
dw = 0;
26712854
dh = 0;
2855+
} else if ((style & 0x0fffff) == SWT.TOOL) {
2856+
dw = 2;
2857+
dh = 2;
26722858
} else if ((style & SWT.TOOL) != 0) {
26732859
dw = 4;
26742860
dh = 2;
@@ -2692,6 +2878,10 @@ protected boolean SetWindowPos(Object hWnd, Object hWndInsertAfter, int X, int Y
26922878
if ((style & SWT.BORDER) != 0) {
26932879
cx -= 6;
26942880
cy -= 4;
2881+
} else if ((style & 0x0fffff) == SWT.TOOL) {
2882+
// do nothing
2883+
cx -= 2;
2884+
cy -= 2;
26952885
} else if ((style & SWT.NO_TRIM) == 0) {
26962886
cx -= 2;
26972887
}
@@ -2712,6 +2902,9 @@ protected boolean SetWindowPos(Object hWnd, Object hWndInsertAfter, int X, int Y
27122902
el.style.top = Y + "px";
27132903
el.style.width = (cx > 0 ? cx : 0) + "px";
27142904
el.style.height = (cy > 0 ? cy : 0) + "px";
2905+
if (shadowEls != null) {
2906+
adjustShadowOnResize(shadowEls, cx, cy);
2907+
}
27152908

27162909
return true;
27172910
// return super.SetWindowPos(hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags);

0 commit comments

Comments
 (0)