Skip to content

Commit 82d8350

Browse files
author
zhourenjian
committed
Enable scrollbar for scrollable widget
1 parent 5e03f0f commit 82d8350

File tree

13 files changed

+330
-22
lines changed

13 files changed

+330
-22
lines changed

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/browser/Browser.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,9 @@ public void setBounds(int x, int y, int width, int height) {
15171517
browserHandle.style.height = (height - 4 > 0 ? height - 4 : 0) + "px";
15181518
}
15191519
}
1520-
1521-
1520+
1521+
protected boolean useNativeScrollBar() {
1522+
return true;
1523+
}
1524+
15221525
}

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/custom/ScrolledComposite.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,4 +513,9 @@ protected void createHandle () {
513513
// };
514514

515515
}
516+
517+
protected boolean useNativeScrollBar() {
518+
return true;
519+
}
520+
516521
}

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/custom/StyledText.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7993,4 +7993,9 @@ void wordWrapResize(int oldClientAreaWidth) {
79937993
// word wrap may have changed on one of the visible lines
79947994
super.redraw();
79957995
}
7996+
7997+
protected boolean useNativeScrollBar() {
7998+
return true;
7999+
}
8000+
79968001
}

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/custom/TableTree.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,4 +811,9 @@ public void showSelection () {
811811
checkWidget();
812812
table.showSelection();
813813
}
814+
815+
protected boolean useNativeScrollBar() {
816+
return true;
817+
}
818+
814819
}

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,39 @@ private static void init() {
160160
}
161161
}
162162

163+
164+
private static int wScrollBar = -1;
165+
private static int hScrollBar = -1;
166+
167+
private static void checkScrollBar() {
168+
Element el = document.createElement("DIV");
169+
CSSStyle s = el.style;
170+
s.position = "absolute";
171+
s.left = "-4000px";
172+
s.top = "-1000px";
173+
s.overflow = "scroll";
174+
s.width = "324px";
175+
s.height = "324px";
176+
document.body.appendChild(el);
177+
wScrollBar = el.offsetWidth - el.clientWidth;
178+
hScrollBar = el.offsetHeight - el.clientHeight;
179+
document.body.removeChild(el);
180+
}
181+
182+
public static int getScrollBarWidth() {
183+
if (wScrollBar == -1) {
184+
checkScrollBar();
185+
}
186+
return wScrollBar;
187+
}
188+
189+
public static int getScrollBarHeight() {
190+
if (hScrollBar == -1) {
191+
checkScrollBar();
192+
}
193+
return hScrollBar;
194+
}
195+
163196
public static int getContainerWidth(Object container) {
164197
Element el = (Element) container;
165198
return Math.max(el.offsetWidth, Math.max(el.clientWidth, el.scrollWidth));

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
*******************************************************************************/
1212
package org.eclipse.swt.widgets;
1313

14-
import java.util.Date;
1514
import org.eclipse.swt.SWT;
1615
import org.eclipse.swt.SWTException;
1716
import org.eclipse.swt.graphics.Point;
1817
import org.eclipse.swt.graphics.Rectangle;
18+
import org.eclipse.swt.internal.browser.OS;
1919
import org.eclipse.swt.internal.struct.MESSAGE;
2020
import org.eclipse.swt.internal.struct.WINDOWPOS;
2121
import org.eclipse.swt.internal.xhtml.Element;
@@ -995,6 +995,7 @@ protected boolean SetWindowPos(Object hWnd, Object hWndInsertAfter, int X, int Y
995995
cx -= 4;
996996
cy -= 4;
997997
}
998+
998999
// if (!isLayoutDeferred()) {
9991000
// setLayoutDeferred(true);
10001001
// }
@@ -1011,9 +1012,29 @@ protected boolean SetWindowPos(Object hWnd, Object hWndInsertAfter, int X, int Y
10111012
el.style.top = Y + "px";
10121013
el.style.width = (cx > 0 ? cx : 0) + "px";
10131014
el.style.height = (cy > 0 ? cy : 0) + "px";
1015+
1016+
updateScrollBar(cx, cy);
10141017
return true;
10151018
// return super.SetWindowPos(hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags);
10161019
}
1020+
1021+
protected void updateScrollBar(int cx, int cy) {
1022+
int sbw = cx, sbh = cy;
1023+
if (verticalBar != null) { //if ((style & SWT.V_SCROLL) != 0) {
1024+
sbw -= OS.getScrollBarWidth();
1025+
}
1026+
if (horizontalBar != null) { //if ((style & SWT.H_SCROLL) != 0) {
1027+
sbh -= OS.getScrollBarHeight();
1028+
}
1029+
if (verticalBar != null) { //if ((style & SWT.V_SCROLL) != 0) {
1030+
verticalBar.outerHandle.style.left = ((sbw > 0 ? sbw : 0)) + "px";
1031+
verticalBar.updateSizeBinding(sbh);
1032+
}
1033+
if (horizontalBar != null) { //if ((style & SWT.H_SCROLL) != 0) {
1034+
horizontalBar.outerHandle.style.top = ((sbh > 0 ? sbh : 0)) + "px";
1035+
horizontalBar.updateSizeBinding(sbw);
1036+
}
1037+
}
10171038

10181039
void updateLayout (boolean resize, boolean all) {
10191040
if (isLayoutDeferred ()) return;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,6 +1654,10 @@ public void showSelection () {
16541654
OS.SendMessage (handle, OS.LB_SETTOPINDEX, newTop, 0);
16551655
*/
16561656
}
1657+
1658+
protected boolean useNativeScrollBar() {
1659+
return true;
1660+
}
16571661

16581662
/*
16591663
int widgetStyle () {

0 commit comments

Comments
 (0)