Skip to content

Commit 312959a

Browse files
author
zhourenjian
committed
Add shadow to Shell, Menu, Task bar, Quick launch bar
Fix Shell's layout/size bug
1 parent 0a6072d commit 312959a

File tree

13 files changed

+186
-23
lines changed

13 files changed

+186
-23
lines changed

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

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -566,13 +566,14 @@ Image createIcon (Image image) {
566566
return null;
567567
}
568568

569-
private Element createCSSDiv(String css) {
569+
private static Element createCSSDiv(Element handle, String css) {
570570
Element el = document.createElement("DIV");
571571
el.className = css;
572572
handle.appendChild(el);
573573
return el;
574574
}
575-
private void createResizeHandles() {
575+
576+
protected static void createResizeHandles(Element handle) {
576577
String[] handles = new String[] {
577578
"shell-left-top",
578579
"shell-right-top",
@@ -585,7 +586,27 @@ private void createResizeHandles() {
585586
"shell-center-bottom"
586587
};
587588
for (int i = 0; i < handles.length; i++) {
588-
createCSSDiv(handles[i]);
589+
createCSSDiv(handle, handles[i]);
590+
}
591+
}
592+
593+
protected static void createShadowHandles(Element handle) {
594+
String[] handles = new String[] {
595+
"shadow-left-top",
596+
"shadow-right-top",
597+
"shadow-center-top",
598+
"shadow-left-middle",
599+
"shadow-right-middle",
600+
"shadow-center-middle",
601+
"shadow-left-bottom",
602+
"shadow-right-bottom",
603+
"shadow-center-bottom"
604+
};
605+
for (int i = 0; i < handles.length; i++) {
606+
createCSSDiv(handle, handles[i]);
607+
}
608+
if (OS.isChrome) {
609+
handle.style.opacity = "1";
589610
}
590611
}
591612

@@ -628,7 +649,21 @@ public void run() {
628649
// }
629650
getMonitor().handle.appendChild(handle);
630651
if ((style & SWT.NO_TRIM) == 0 && (style & SWT.RESIZE) != 0) {
631-
createResizeHandles();
652+
createResizeHandles(handle);
653+
}
654+
boolean supportShadow = false;
655+
/**
656+
* @j2sNative
657+
* supportShadow = window["swt.shell.shadow"];
658+
*/ {}
659+
if (supportShadow) {
660+
if (OS.isIE) {
661+
if (!OS.isIE50 && !OS.isIE55 && OS.isIE60) {
662+
createShadowHandles(handle);
663+
}
664+
} else {
665+
createShadowHandles(handle);
666+
}
632667
}
633668
if ((style & SWT.NO_TRIM) == 0
634669
&& (style & (SWT.TITLE | SWT.MIN | SWT.MAX | SWT.CLOSE)) != 0) {
@@ -638,7 +673,7 @@ public void run() {
638673
if ((style & SWT.TOOL) != 0) {
639674
contentCSS += " shell-tool";
640675
}
641-
contentHandle = createCSSDiv(contentCSS);
676+
contentHandle = createCSSDiv(handle, contentCSS);
642677
if (DragAndDrop.class != null) {
643678
DragAndDrop dnd = new DragAndDrop();
644679
shellFrameDND = new ShellFrameDND() {
@@ -947,7 +982,7 @@ public Rectangle getClientArea () {
947982
int h = height;
948983
if ((style & (SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX)) != 0) {
949984
//h -= 20;
950-
h -= Math.max(OS.getContainerHeight(titleBar), 19);
985+
h -= Math.max(OS.getContainerHeight(titleBar), 19) + 2;
951986
w -= 8;
952987
//h -= 8;
953988
h -= 5;
@@ -2364,10 +2399,7 @@ protected boolean SetWindowPos(Object hWnd, Object hWndInsertAfter, int X, int Y
23642399
cy = h;
23652400
}
23662401
}
2367-
if ((style & SWT.NO_TRIM) != 0) {
2368-
contentHandle.style.height = height + "px";
2369-
contentHandle.style.width = width + "px";
2370-
} else if (titleBar != null) {
2402+
if (titleBar != null) {
23712403
int dw = 8;
23722404
//int dh = 28;
23732405
int tbh = OS.getContainerHeight(titleBar);
@@ -2377,7 +2409,7 @@ protected boolean SetWindowPos(Object hWnd, Object hWndInsertAfter, int X, int Y
23772409
if (OS.isIE && (tbh == 19)) {
23782410
tbh = 21;
23792411
}
2380-
int dh = 5 + tbh;
2412+
int dh = 5 + tbh + 2;
23812413
int dww = 8;
23822414
if ((style & SWT.BORDER) != 0) {
23832415
dw += 4;
@@ -2395,24 +2427,28 @@ protected boolean SetWindowPos(Object hWnd, Object hWndInsertAfter, int X, int Y
23952427
dh += mbh + 1;
23962428
tbh += mbh + 1;
23972429
}
2398-
contentHandle.style.top = (((style & SWT.BORDER) != 0 ? 1 : 1) + tbh) + "px";
2430+
contentHandle.style.top = (((style & SWT.BORDER) != 0 ? 1 : 1) + tbh + 2) + "px";
2431+
contentHandle.style.left = (((style & SWT.BORDER) != 0 ? 1 : 1) + 2) + "px";
23992432
contentHandle.style.height = ((height - dh >= 0) ? height - dh : 0) + "px";
24002433
contentHandle.style.width = ((width - dw) > 0 ? width - dw : 0) + "px";
24012434
titleBar.style.width = ((width - dww) > 0 ? width - dww : 0) + "px";
24022435
updateShellTitle(width - dww + 8);
24032436
} else {
2437+
contentHandle.style.top = "0px";
2438+
contentHandle.style.left = "0px";
24042439
int dw = 8;
24052440
int dh = 8;
2406-
if ((style & SWT.TOOL) != 0 || style == SWT.NONE) {
2441+
if ((style & SWT.NO_TRIM) != 0) {
24072442
dw = 0;
24082443
dh = 0;
2409-
contentHandle.style.top = "0px";
2410-
contentHandle.style.left = "0px";
2444+
} else if ((style & SWT.TOOL) != 0) {
2445+
dw = 4;
2446+
dh = 2;
24112447
cx -= 2;
24122448
cy -= 2;
24132449
} else {
2414-
contentHandle.style.top = 3 + "px";
2415-
contentHandle.style.left = 1 + "px";
2450+
dw = 6;
2451+
dh = 4;
24162452
cx -= 4;
24172453
cy -= 4;
24182454
}
@@ -2426,7 +2462,7 @@ protected boolean SetWindowPos(Object hWnd, Object hWndInsertAfter, int X, int Y
24262462
if ((style & SWT.BORDER) != 0) {
24272463
cx -= 6;
24282464
cy -= 4;
2429-
} else {
2465+
} else if ((style & SWT.NO_TRIM) == 0) {
24302466
cx -= 2;
24312467
}
24322468
Element el = (Element) hWnd;

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,20 @@ void createHandle () {
430430
} else {
431431
document.body.appendChild(handle);
432432
handle.className = "menu-default";
433+
boolean supportShadow = false;
434+
/**
435+
* @j2sNative
436+
* supportShadow = window["swt.shell.shadow"];
437+
*/ {}
438+
if (supportShadow) {
439+
if (OS.isIE) {
440+
if (!OS.isIE50 && !OS.isIE55 && OS.isIE60) {
441+
Decorations.createShadowHandles(handle);
442+
}
443+
} else {
444+
Decorations.createShadowHandles(handle);
445+
}
446+
}
433447
}
434448

435449
btnFocus = document.createElement("BUTTON");

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,16 @@ public void run() {
118118
}
119119

120120
};
121+
122+
boolean supportShadow = false;
123+
/**
124+
* @j2sNative
125+
* supportShadow = window["swt.shell.shadow"];
126+
*/ {}
127+
if (supportShadow) {
128+
Decorations.createShadowHandles(handle);
129+
}
130+
121131
Element[] childNodes = document.body.childNodes;
122132
Element[] children = new Element[childNodes.length];
123133
for (int i = 0; i < childNodes.length; i++) {
@@ -292,6 +302,15 @@ public Element addShortcut(String name, String icon, Object clickFun) {
292302
itemDiv.title = name;
293303
document.body.appendChild (itemDiv);
294304
itemDiv.onmouseover = this.handle.onmouseover;
305+
306+
boolean supportShadow = false;
307+
/**
308+
* @j2sNative
309+
* supportShadow = window["swt.shell.shadow"];
310+
*/ {}
311+
if (supportShadow && !OS.isIE) {
312+
Decorations.createShadowHandles(itemDiv);
313+
}
295314

296315
this.shortcutItems[this.shortcutCount] = itemDiv;
297316
this.shortcutCount++;

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

Lines changed: 79 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
/*top:0;
2121
left:0;*/
2222
background-color:buttonface;
23-
overflow:hidden;
23+
/*overflow:hidden;*/
2424
font-size:0;
2525
text-align:left;
2626
color:black;
@@ -32,9 +32,6 @@
3232
position:absolute;
3333
left:0;
3434
top:23px;
35-
margin:3px;
36-
margin-top:1px;
37-
margin-right:2px;
3835
overflow:hidden;
3936
background-color:buttonface;
4037
/*background-color:navy;*/
@@ -76,7 +73,6 @@
7673

7774
.shell-center-top, .shell-left-middle, .shell-right-middle, .shell-center-bottom {
7875
position:absolute;
79-
/*background-color:#7777ff;*/
8076
z-index:0;
8177
}
8278
.shell-center-top {
@@ -108,6 +104,84 @@
108104
bottom:0;
109105
}
110106

107+
/* Begin of Shell Shadow */
108+
.shadow-left-top, .shadow-right-top, .shadow-left-bottom, .shadow-right-bottom {
109+
position:absolute;
110+
width:16px;
111+
height:16px;
112+
z-index:1;
113+
}
114+
.shadow-left-top {
115+
left:-16px;
116+
top:-16px;
117+
background-image: url('images/top-left.png');
118+
background-position: right bottom;
119+
background-repeat: no-repeat;
120+
}
121+
.shadow-right-top {
122+
right:-16px;
123+
top:-16px;
124+
background-image: url('images/top-right.png');
125+
background-position: left bottom;
126+
background-repeat: no-repeat;
127+
}
128+
.shadow-left-bottom {
129+
left:-16px;
130+
bottom:-16px;
131+
background-image: url('images/bottom-left.png');
132+
background-position: right top;
133+
background-repeat: no-repeat;
134+
}
135+
.shadow-right-bottom {
136+
right:-16px;
137+
bottom:-16px;
138+
background-image: url('images/bottom-right.png');
139+
background-position: left top;
140+
background-repeat: no-repeat;
141+
}
142+
143+
.shadow-center-top, .shadow-left-middle, .shadow-right-middle, .shadow-center-bottom {
144+
position:absolute;
145+
z-index:0;
146+
}
147+
.shadow-center-top {
148+
width:100%;
149+
height:16px;
150+
left:0;
151+
top:-16px;
152+
background-image: url('images/top.png');
153+
background-position: center bottom;
154+
background-repeat: repeat-x;
155+
}
156+
.shadow-left-middle {
157+
left:-16px;
158+
top:0;
159+
width:16px;
160+
height:100%;
161+
background-image: url('images/left.png');
162+
background-position: right center;
163+
background-repeat: repeat-y;
164+
}
165+
.shadow-right-middle {
166+
right:-16px;
167+
top:0;
168+
width:16px;
169+
height:100%;
170+
background-image: url('images/right.png');
171+
background-position: left center;
172+
background-repeat: repeat-y;
173+
}
174+
.shadow-center-bottom {
175+
width:100%;
176+
height:16px;
177+
left:0;
178+
bottom:-16px;
179+
background-image: url('images/bottom.png');
180+
background-position: center top;
181+
background-repeat: repeat-x;
182+
}
183+
/* End of Shell Shadow */
184+
111185
.shell-title-bar {
112186
position:absolute;
113187
left:0;

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,16 @@ public void run() {
192192
};
193193
}
194194
this.items[this.items.length] = new TaskItem(shell, text, si, div, icon);
195+
196+
boolean supportShadow = false;
197+
/**
198+
* @j2sNative
199+
* supportShadow = window["swt.shell.shadow"];
200+
*/ {}
201+
if (supportShadow && !OS.isIE) {
202+
Decorations.createShadowHandles(si);
203+
}
204+
195205
this.updateItems();
196206
}
197207

@@ -445,6 +455,16 @@ public void run() {
445455

446456
};
447457
this.barEl.title = "Doubleclick to set taskbar auto-hide";
458+
459+
boolean supportShadow = false;
460+
/**
461+
* @j2sNative
462+
* supportShadow = window["swt.shell.shadow"];
463+
*/ {}
464+
if (supportShadow && !OS.isIE) {
465+
Decorations.createShadowHandles(barEl);
466+
}
467+
448468
}
449469

450470
/**
379 Bytes
Loading
376 Bytes
Loading
147 Bytes
Loading
118 Bytes
Loading
118 Bytes
Loading

0 commit comments

Comments
 (0)