Skip to content

Commit fd6b829

Browse files
author
soheil_h_y
committed
1 parent b8b8ece commit fd6b829

9 files changed

Lines changed: 1818 additions & 1514 deletions

File tree

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

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public class Combo extends Composite {
6868
selectInput;
6969
private boolean selectShown;
7070
private boolean isSimple;
71+
private int itemCount;
7172

7273
/**
7374
* the operating system limit for the number of characters
@@ -138,7 +139,7 @@ public class Combo extends Composite {
138139
*/
139140
public Combo (Composite parent, int style) {
140141
super (parent, checkStyle (style));
141-
142+
itemCount = 0;
142143
}
143144

144145
/**
@@ -167,8 +168,9 @@ public void add (String string) {
167168
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
168169
*/
169170
if (selectInput != null) {
170-
selectInput.options[selectInput.options.length] = new Option(string, string);
171-
}
171+
selectInput.options[itemCount] = new Option(string, string);
172+
}
173+
itemCount++;
172174
}
173175

174176
/**
@@ -198,7 +200,7 @@ public void add (String string, int index) {
198200
checkWidget ();
199201
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
200202

201-
int count = selectInput.options.length;
203+
int count = itemCount;
202204
if (!(0 <= index && index <= count)) {
203205
error (SWT.ERROR_INVALID_RANGE);
204206
}
@@ -383,7 +385,8 @@ public Point computeSize (int wHint, int hHint, boolean changed) {
383385

384386
if(selectInput != null){
385387
Option[] options = selectInput.options;
386-
for(int i = 0; i < options.length; i++){
388+
int length = itemCount;
389+
for(int i = 0; i < length; i++){
387390
width = Math.max(width, OS.getStringPlainWidth(options[i].value));
388391
}
389392
} else{
@@ -723,6 +726,7 @@ public void deselectAll () {
723726
checkWidget ();
724727
//OS.SendMessage (handle, OS.CB_SETCURSEL, -1, 0);
725728
selectInput.selectedIndex = -1;
729+
setText("", false);
726730
sendEvent (SWT.Modify);
727731
// widget could be disposed at this point
728732
}
@@ -756,8 +760,7 @@ public String getItem (int index) {
756760
if (0 <= index && index < count) error (SWT.ERROR_CANNOT_GET_ITEM);
757761
error (SWT.ERROR_INVALID_RANGE);
758762
*/
759-
Option[] options = selectInput.options;
760-
if(index < 0 || index > (options.length - 1))
763+
if(index < 0 || index > (itemCount - 1))
761764
error(SWT.ERROR_INVALID_RANGE);
762765
return selectInput.options[index].value;
763766
}
@@ -779,7 +782,7 @@ public int getItemCount () {
779782
if (count == OS.CB_ERR) error (SWT.ERROR_CANNOT_GET_COUNT);
780783
return count;
781784
*/
782-
return selectInput.options.length;
785+
return this.itemCount;
783786
}
784787

785788
/**
@@ -1183,6 +1186,7 @@ public void remove (int index) {
11831186
System.arraycopy(oldOptions,0, newOptions, 0, index);
11841187
System.arraycopy(oldOptions, index + 1, newOptions, index, oldOptions.length - index - 1);
11851188
selectInput.options = newOptions;
1189+
itemCount--;
11861190
}
11871191

11881192
/**
@@ -1242,6 +1246,7 @@ public void remove (int start, int end) {
12421246
System.arraycopy(oldOptions,0, newOptions, 0, start);
12431247
System.arraycopy(oldOptions, end + 1, newOptions, start, oldOptions.length - end - 1);
12441248
selectInput.options = newOptions;
1249+
itemCount -= (end - start + 1);
12451250
}
12461251

12471252
/**
@@ -1284,6 +1289,8 @@ public void removeAll () {
12841289
* @j2sNative
12851290
* this.selectInput.options.length = 0;
12861291
*/{}
1292+
itemCount = 0;
1293+
textInput.value = "";
12871294
sendEvent (SWT.Modify);
12881295
// widget could be disposed at this point
12891296
}
@@ -1475,9 +1482,10 @@ public void select (int index) {
14751482
}
14761483
}
14771484
*/
1478-
if(index >= 0 && index < selectInput.options.length){
1485+
if(index >= 0 && index < itemCount){
14791486
selectInput.selectedIndex = index;
14801487
}
1488+
setText(getItem(index));
14811489
}
14821490
/*
14831491
void setBackgroundPixel (int pixel) {
@@ -1782,6 +1790,10 @@ public void setSelection (Point selection) {
17821790
* </ul>
17831791
*/
17841792
public void setText (String string) {
1793+
setText(string, true);
1794+
}
1795+
1796+
public void setText (String string, boolean modify) {
17851797
checkWidget ();
17861798
if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
17871799
if ((style & SWT.READ_ONLY) != 0) {
@@ -1794,7 +1806,9 @@ public void setText (String string) {
17941806
textInput.readOnly = (style & SWT.READ_ONLY) != 0;
17951807
// TCHAR buffer = new TCHAR (getCodePage (), string, true);
17961808
// if (OS.SetWindowText (handle, buffer)) {
1809+
if(modify){
17971810
sendEvent (SWT.Modify);
1811+
}
17981812
// widget could be disposed at this point
17991813
// }
18001814
}

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

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,14 @@ public Composite (Composite parent, int style) {
137137
Control [] _getTabList () {
138138
if (tabList == null) return tabList;
139139
int count = 0;
140-
for (int i=0; i<tabList.length; i++) {
140+
int length = tabList.length;
141+
for (int i=0; i<length; i++) {
141142
if (!tabList [i].isDisposed ()) count++;
142143
}
143-
if (count == tabList.length) return tabList;
144+
if (count == length) return tabList;
144145
Control [] newList = new Control [count];
145146
int index = 0;
146-
for (int i=0; i<tabList.length; i++) {
147+
for (int i=0; i<length; i++) {
147148
if (!tabList [i].isDisposed ()) {
148149
newList [index++] = tabList [i];
149150
}
@@ -174,7 +175,8 @@ public Composite (Composite parent, int style) {
174175
public void changed (Control[] changed) {
175176
checkWidget ();
176177
if (changed == null) error (SWT.ERROR_INVALID_ARGUMENT);
177-
for (int i=0; i<changed.length; i++) {
178+
int length = changed.length;
179+
for (int i=0; i< length; i++) {
178180
Control control = changed [i];
179181
if (control == null) error (SWT.ERROR_INVALID_ARGUMENT);
180182
if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
@@ -187,7 +189,7 @@ public void changed (Control[] changed) {
187189
}
188190
if (!ancestor) error (SWT.ERROR_INVALID_PARENT);
189191
}
190-
for (int i=0; i<changed.length; i++) {
192+
for (int i=0; i< length; i++) {
191193
Control child = changed [i];
192194
Composite composite = child.parent;
193195
while (child != this) {
@@ -279,6 +281,7 @@ protected void createHandle () {
279281
if (control == this) return new Menu [0];
280282
Menu result [] = super.findMenus (control);
281283
Control [] children = _getChildren ();
284+
282285
for (int i=0; i<children.length; i++) {
283286
Control child = children [i];
284287
Menu [] menuList = child.findMenus (control);
@@ -295,14 +298,16 @@ protected void createHandle () {
295298
void fixChildren (Shell newShell, Shell oldShell, Decorations newDecorations, Decorations oldDecorations, Menu [] menus) {
296299
super.fixChildren (newShell, oldShell, newDecorations, oldDecorations, menus);
297300
Control [] children = _getChildren ();
298-
for (int i=0; i<children.length; i++) {
301+
int length = children.length;
302+
for (int i=0; i< length; i++) {
299303
children [i].fixChildren (newShell, oldShell, newDecorations, oldDecorations, menus);
300304
}
301305
}
302306
void fixChildrenList (Control control) {
303-
if (children == null || children.length == 0) return;
307+
int length = children.length;
308+
if (children == null || length == 0) return;
304309
Control[] newChildren = new Control[0];
305-
for (int i = 0; i < children.length; i++) {
310+
for (int i = 0; i < length; i++) {
306311
Control child = children[i];
307312
if (child != null && child != control) {
308313
newChildren[newChildren.length] = child;
@@ -380,7 +385,7 @@ int getChildrenCount () {
380385
*/
381386
// TODO: search the children and filter out the essential children
382387
// return count;
383-
return children.length;
388+
return _getChildren().length;
384389
}
385390

386391
/**
@@ -417,12 +422,13 @@ public Layout getLayout () {
417422
if (tabList == null) {
418423
int count = 0;
419424
Control [] list =_getChildren ();
420-
for (int i=0; i<list.length; i++) {
425+
int length = list.length;
426+
for (int i=0; i< length; i++) {
421427
if (list [i].isTabGroup ()) count++;
422428
}
423429
tabList = new Control [count];
424430
int index = 0;
425-
for (int i=0; i<list.length; i++) {
431+
for (int i=0; i< length; i++) {
426432
if (list [i].isTabGroup ()) {
427433
tabList [index++] = list [i];
428434
}
@@ -591,8 +597,9 @@ public void layout (Control [] changed) {
591597
checkWidget ();
592598
System.out.print("control");
593599
if (changed == null) error (SWT.ERROR_INVALID_ARGUMENT);
594-
Date d = new Date();
595-
for (int i=0; i<changed.length; i++) {
600+
Date d = new Date();
601+
int length = changed.length;
602+
for (int i=0; i< length; i++) {
596603
Control control = changed [i];
597604
if (control == null) error (SWT.ERROR_INVALID_ARGUMENT);
598605
if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
@@ -609,7 +616,7 @@ public void layout (Control [] changed) {
609616
d = new Date();
610617
int updateCount = 0;
611618
Composite [] update = new Composite [16];
612-
for (int i=0; i<changed.length; i++) {
619+
for (int i=0; i< length; i++) {
613620
Control child = changed [i];
614621
Composite composite = child.parent;
615622
while (child != this) {
@@ -643,8 +650,9 @@ void markLayout (boolean changed, boolean all) {
643650
if (changed) state |= LAYOUT_CHANGED;
644651
}
645652
if (all) {
646-
Control [] children = _getChildren ();
647-
for (int i=0; i<children.length; i++) {
653+
Control [] children = _getChildren ();
654+
int length = children.length;
655+
for (int i=0; i< length; i++) {
648656
children [i].markLayout (changed, all);
649657
}
650658
}
@@ -654,7 +662,8 @@ Point minimumSize (int wHint, int hHint, boolean changed) {
654662
Control [] children = _getChildren ();
655663
//System.out.println("minimumSize@Composite");
656664
int width = 0, height = 0;
657-
for (int i=0; i<children.length; i++) {
665+
int length = children.length;
666+
for (int i=0; i< length; i++) {
658667
//System.out.println(i + "..." + children [i]);
659668
Rectangle rect = children [i].getBounds ();
660669
width = Math.max (width, rect.x + rect.width);
@@ -668,7 +677,8 @@ Point minimumSize (int wHint, int hHint, boolean changed) {
668677

669678
void releaseChildren () {
670679
Control [] children = _getChildren ();
671-
for (int i=0; i<children.length; i++) {
680+
int length = children.length;
681+
for (int i=0; i<length; i++) {
672682
Control child = children [i];
673683
if (!child.isDisposed ()) child.releaseResources ();
674684
}
@@ -692,7 +702,8 @@ protected void releaseWidget () {
692702
layout = null;
693703
tabList = null;
694704
if (lpwp != null) {
695-
for (int i = 0; i < lpwp.length; i++) {
705+
int length = lpwp.length;
706+
for (int i = 0; i < length; i++) {
696707
lpwp[i].hwnd = null;
697708
lpwp[i].hwndInsertAfter = null;
698709
}
@@ -724,7 +735,8 @@ boolean resizeChildren (boolean defer, WINDOWPOS [] pwp) {
724735
//hdwp = OS.BeginDeferWindowPos (pwp.length);
725736
if (hdwp == 0) return false;
726737
}
727-
for (int i=0; i<pwp.length; i++) {
738+
int length = pwp.length;
739+
for (int i=0; i<length; i++) {
728740
WINDOWPOS wp = pwp [i];
729741
if (wp != null) {
730742
/*
@@ -775,11 +787,12 @@ void resizeEmbeddedHandle(int embeddedHandle, int width, int height) {
775787
boolean setFixedFocus () {
776788
checkWidget ();
777789
Control [] children = _getChildren ();
778-
for (int i=0; i<children.length; i++) {
790+
int length = children.length;
791+
for (int i=0; i<length; i++) {
779792
Control child = children [i];
780793
if (child.setRadioFocus ()) return true;
781794
}
782-
for (int i=0; i<children.length; i++) {
795+
for (int i=0; i<length; i++) {
783796
Control child = children [i];
784797
if (child.setFixedFocus ()) return true;
785798
}
@@ -789,11 +802,12 @@ boolean setFixedFocus () {
789802
public boolean setFocus () {
790803
checkWidget ();
791804
Control [] children = _getChildren ();
792-
for (int i=0; i<children.length; i++) {
805+
int length = children.length;
806+
for (int i=0; i<length; i++) {
793807
Control child = children [i];
794808
if (child.setRadioFocus ()) return true;
795809
}
796-
for (int i=0; i<children.length; i++) {
810+
for (int i=0; i<length; i++) {
797811
Control child = children [i];
798812
if (child.setFocus ()) return true;
799813
}
@@ -865,14 +879,15 @@ public void setLayoutDeferred (boolean defer) {
865879
public void setTabList (Control [] tabList) {
866880
checkWidget ();
867881
if (tabList != null) {
868-
for (int i=0; i<tabList.length; i++) {
882+
int length = tabList.length;
883+
for (int i=0; i<length; i++) {
869884
Control control = tabList [i];
870885
if (control == null) error (SWT.ERROR_INVALID_ARGUMENT);
871886
if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
872887
if (control.parent != this) error (SWT.ERROR_INVALID_PARENT);
873888
}
874-
Control [] newList = new Control [tabList.length];
875-
System.arraycopy (tabList, 0, newList, 0, tabList.length);
889+
Control [] newList = new Control [length];
890+
System.arraycopy (tabList, 0, newList, 0, length);
876891
tabList = newList;
877892
}
878893
this.tabList = tabList;
@@ -898,11 +913,12 @@ boolean setTabGroupFocus () {
898913
}
899914
if (takeFocus && setTabItemFocus ()) return true;
900915
Control [] children = _getChildren ();
901-
for (int i=0; i<children.length; i++) {
916+
int length = children.length;
917+
for (int i=0; i<length; i++) {
902918
Control child = children [i];
903919
if (child.isTabItem () && child.setRadioFocus ()) return true;
904920
}
905-
for (int i=0; i<children.length; i++) {
921+
for (int i=0; i<length; i++) {
906922
Control child = children [i];
907923
if (child.isTabItem () && child.setTabItemFocus ()) return true;
908924
}
@@ -992,12 +1008,16 @@ void updateLayout (boolean resize, boolean all) {
9921008
boolean changed = (state & LAYOUT_CHANGED) != 0;
9931009
state &= ~(LAYOUT_NEEDED | LAYOUT_CHANGED);
9941010
if (resize) setResizeChildren (false);
995-
layout.layout (this, changed);
1011+
// layout.layout (this, changed);
1012+
display.sendMessage(new MESSAGE(this, MESSAGE.CONTROL_LAYOUT, new boolean[] {resize, all}));
9961013
if (resize) setResizeChildren (true);
9971014
}
1015+
1016+
9981017
if (all) {
9991018
Control [] children = _getChildren ();
1000-
for (int i=0; i<children.length; i++) {
1019+
int length = children.length;
1020+
for (int i=0; i<length; i++) {
10011021
// children [i].updateLayout (resize, all);
10021022
if (children[i] instanceof Composite) {
10031023
// System.out.println("update Layout " + children[i]);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,8 @@ protected void forceResize () {
686686
if (parent == null) return;
687687
WINDOWPOS [] lpwp = parent.lpwp;
688688
if (lpwp == null) return;
689-
for (int i=0; i<lpwp.length; i++) {
689+
int length = lpwp.length;
690+
for (int i=0; i<length; i++) {
690691
WINDOWPOS wp = lpwp [i];
691692
if (wp != null && wp.hwnd == handle) {
692693
/*

0 commit comments

Comments
 (0)