Skip to content

Commit b39758b

Browse files
author
jossonsmith
committed
Support SWT.INDETERMINATE and non-SWT.SMOOTH in ProgressBar
1 parent edf4130 commit b39758b

2 files changed

Lines changed: 121 additions & 26 deletions

File tree

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/swt-default.css

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,16 +1567,21 @@ input.text-border {
15671567
margin:0;
15681568
padding:0;
15691569
border:1px inset white;
1570+
overflow:hidden;
15701571
}
15711572
.progress-bar-horizontal {
1572-
background-color:blue;
1573-
height:100%;
1573+
background-color:highlight;
15741574
width:0;
1575+
position:absolute;
1576+
top:1px;
1577+
left:1px;
15751578
}
15761579
.progress-bar-vertical {
1577-
background-color:blue;
1580+
background-color:highlight;
15781581
height:0;
1579-
width:100%;
1582+
position:absolute;
1583+
bottom:1px;
1584+
left:1px;
15801585
}
15811586

15821587
.sash-horizontal-default {

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

Lines changed: 112 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.eclipse.swt.SWT;
1515
import org.eclipse.swt.SWTException;
1616
import org.eclipse.swt.graphics.Point;
17+
import org.eclipse.swt.internal.browser.OS;
1718
import org.eclipse.swt.internal.xhtml.Element;
1819
import org.eclipse.swt.internal.xhtml.document;
1920

@@ -78,7 +79,8 @@ public class ProgressBar extends Control {
7879
private int minimum;
7980
private int maximum;
8081
private int selection;
81-
private Element innerHandle;
82+
private Element[] innerHandles;
83+
private Runnable timer;
8284

8385
/**
8486
* Constructs a new instance of this class given its parent
@@ -182,16 +184,30 @@ void createHandle () {
182184
parentHandle.appendChild(handle);
183185
}
184186
}
185-
186-
innerHandle = document.createElement("DIV");
187-
handle.appendChild(innerHandle);
187+
innerHandles = new Element[1];
188+
innerHandles[0] = document.createElement("DIV");
189+
handle.appendChild(innerHandles[0]);
188190
if ((style & SWT.HORIZONTAL) != 0) {
189-
innerHandle.className = "progress-bar-horizontal";
191+
innerHandles[0].className = "progress-bar-horizontal";
190192
} else {
191-
innerHandle.className = "progress-bar-vertical";
193+
innerHandles[0].className = "progress-bar-vertical";
192194
}
193195
startTimer ();
194196
}
197+
198+
/* (non-Javadoc)
199+
* @see org.eclipse.swt.widgets.Control#releaseHandle()
200+
*/
201+
protected void releaseHandle() {
202+
if (innerHandles != null) {
203+
for (int i = 0; i < innerHandles.length; i++) {
204+
OS.destroyHandle(innerHandles[i]);
205+
innerHandles[i] = null;
206+
}
207+
//innerHandles = new Element[0];
208+
}
209+
super.releaseHandle();
210+
}
195211

196212
//int defaultForeground () {
197213
// return OS.GetSysColor (OS.COLOR_HIGHLIGHT);
@@ -252,14 +268,19 @@ void releaseWidget () {
252268

253269
void startTimer () {
254270
if ((style & SWT.INDETERMINATE) != 0) {
255-
/*
256-
int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
257-
if (OS.COMCTL32_MAJOR < 6 || (bits & OS.PBS_MARQUEE) == 0) {
258-
OS.SetTimer (handle, TIMER_ID, DELAY, 0);
259-
} else {
260-
OS.SendMessage (handle, OS.PBM_SETMARQUEE, 1, DELAY);
261-
}
262-
*/
271+
timer = new Runnable() {
272+
int timerSelection = selection;
273+
public void run() {
274+
int range = maximum - minimum;
275+
timerSelection += Math.round(range / 10);
276+
if (timerSelection > maximum) {
277+
timerSelection = minimum;
278+
}
279+
updateSelection(timerSelection);
280+
display.timerExec(100, this);
281+
}
282+
};
283+
display.timerExec(100, timer);
263284
}
264285
}
265286

@@ -272,7 +293,10 @@ void stopTimer () {
272293
} else {
273294
OS.SendMessage (handle, OS.PBM_SETMARQUEE, 0, 0);
274295
}
275-
*/
296+
*/
297+
if (timer != null) {
298+
display.timerExec(-1, timer);
299+
}
276300
}
277301
}
278302

@@ -368,13 +392,82 @@ public void setSelection (int value) {
368392
} else {
369393
selection = value;
370394
}
371-
if ((style & SWT.HORIZONTAL) != 0) {
372-
innerHandle.style.width = Math.round(getSize().x * selection / maximum) + "px";
395+
updateSelection(selection);
396+
}
397+
398+
protected void updateSelection(int selection) {
399+
int blockSize = 9;
400+
int w = ((style & SWT.HORIZONTAL) != 0) ? width : height;
401+
w = Math.round((w - 2) * selection / maximum);
402+
if ((style & SWT.SMOOTH) != 0) {
403+
if ((style & SWT.HORIZONTAL) != 0) {
404+
innerHandles[0].style.width = w + "px";
405+
innerHandles[0].style.height = (height - 2) + "px";
406+
} else {
407+
innerHandles[0].style.width = (width - 2) + "px";
408+
innerHandles[0].style.height = w + "px";
409+
}
373410
} else {
374-
innerHandle.style.height = Math.round(getSize().y * selection / maximum) + "px";
411+
int blocks = (int) Math.round(w / (blockSize + 2) + 0.5);
412+
if (w == 0) {
413+
blocks = 0;
414+
}
415+
for (int i = blocks; i < innerHandles.length; i++) {
416+
if (innerHandles[i] != null) {
417+
innerHandles[i].style.display = "none";
418+
}
419+
}
420+
for (int i = 0; i < blocks; i++) {
421+
Element el = innerHandles[i];
422+
if (el == null) {
423+
el = document.createElement("DIV");
424+
handle.appendChild(el);
425+
if ((style & SWT.HORIZONTAL) != 0) {
426+
el.className = "progress-bar-horizontal";
427+
el.style.left = (i * (blockSize + 2) + 1) + "px";
428+
} else {
429+
el.className = "progress-bar-vertical";
430+
el.style.bottom = (i * (blockSize + 2) + 1) + "px";
431+
}
432+
innerHandles[i] = el;
433+
} else {
434+
innerHandles[i].style.display = "block";
435+
}
436+
if ((style & SWT.HORIZONTAL) != 0) {
437+
el.style.height = (height - 2) + "px";
438+
if ((i + 1) * (blockSize + 2) <= width - 2) {
439+
el.style.width = blockSize + "px";
440+
} else {
441+
el.style.width = (w - i * (blockSize + 2)) + "px";
442+
}
443+
} else {
444+
el.style.width = (width - 2) + "px";
445+
if ((i + 1) * (blockSize + 2) <= height - 2) {
446+
el.style.height = blockSize + "px";
447+
} else {
448+
el.style.height = (w - i * (blockSize + 2)) + "px";
449+
}
450+
}
451+
}
375452
}
376453
}
377454

455+
/* (non-Javadoc)
456+
* @see org.eclipse.swt.widgets.Widget#SetWindowPos(java.lang.Object, java.lang.Object, int, int, int, int, int)
457+
*/
458+
boolean SetWindowPos(Object hWnd, Object hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags) {
459+
cx -= 2;
460+
cy -= 2;
461+
462+
Element el = (Element) hWnd;
463+
el.style.left = X + "px";
464+
el.style.top = Y + "px";
465+
el.style.width = (cx > 0 ? cx : 0) + "px";
466+
el.style.height = (cy > 0 ? cy : 0) + "px";
467+
return true;
468+
// return super.SetWindowPos(hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags);
469+
}
470+
378471
/*
379472
int widgetStyle () {
380473
int bits = super.widgetStyle ();
@@ -383,14 +476,11 @@ int widgetStyle () {
383476
if ((style & SWT.INDETERMINATE) != 0) bits |= OS.PBS_MARQUEE;
384477
return bits;
385478
}
386-
*/
387479
388480
String windowClass () {
389-
// return ProgressBarClass;
390-
return "DIV";
481+
return ProgressBarClass;
391482
}
392483
393-
/*
394484
int windowProc () {
395485
return ProgressBarProc;
396486
}

0 commit comments

Comments
 (0)