@@ -76,8 +76,11 @@ public class Combo extends Composite {
7676 textInput ,
7777 selectInput ;
7878 private boolean selectShown ;
79+ private boolean visibleCountIsSet = false ;
7980 private boolean isSimple ;
8081 private int itemCount ;
82+ private int maxWidth = 0 ;
83+
8184
8285 /**
8386 * the operating system limit for the number of characters
@@ -180,6 +183,10 @@ public void add (String string) {
180183 selectInput .options [itemCount ] = new Option (string , string );
181184 }
182185 itemCount ++;
186+ if (!visibleCountIsSet )
187+ visibleCount = Math .max (itemCount , 5 );
188+
189+ maxWidth = Math .max (maxWidth , OS .getStringStyledWidth (string , "combo-input-box" , null ));
183190}
184191
185192/**
@@ -223,6 +230,8 @@ public void add (String string, int index) {
223230 if (selectInput != null ) {
224231 selectInput .options [index ] = new Option (string , string );
225232 }
233+ if (!visibleCountIsSet )
234+ visibleCount = Math .max (itemCount , 5 );
226235}
227236
228237/**
@@ -391,15 +400,16 @@ public Point computeSize (int wHint, int hHint, boolean changed) {
391400 checkWidget ();
392401 int width = 0 , height = 0 ;
393402 if (wHint == SWT .DEFAULT ) {
394- if (selectInput != null ){
395- Option [] options = selectInput .options ;
396- int length = itemCount ;
397- for (int i = 0 ; i < length ; i ++){
398- width = Math .max (width , OS .getStringStyledWidth (options [i ].value , "combo-input-box" , null ));
399- }
400- } else {
403+ // if(selectInput != null){
404+ //// Option[] options = selectInput.options;
405+ //// int length = itemCount;
406+ // width = maxWidth;
407+ //// for(int i = 0; i < length; i++){
408+ //// width = Math.max(width, OS.getStringStyledWidth(options[i].value, "combo-input-box", null));
409+ //// }
410+ // } else{
401411 width = DEFAULT_WIDTH ;
402- }
412+ // }
403413 /*
404414 int newFont, oldFont = 0;
405415 int hDC = OS.GetDC (handle);
@@ -474,7 +484,7 @@ public Point computeSize (int wHint, int hHint, boolean changed) {
474484 } else {
475485 int border = 2 ; // OS.GetSystemMetrics (OS.SM_CXEDGE);
476486 width += 16 + border * 2 ; // OS.GetSystemMetrics (OS.SM_CXVSCROLL) + border * 2;
477- int textHeight = OS .getStringStyledHeight ("A " , "combo-input-box" , null ); //OS.SendMessage (handle, OS.CB_GETITEMHEIGHT, -1, 0);
487+ int textHeight = OS .getStringStyledHeight ("M " , "combo-input-box" , null ); //OS.SendMessage (handle, OS.CB_GETITEMHEIGHT, -1, 0);
478488 if ((style & SWT .DROP_DOWN ) != 0 ) {
479489 height = textHeight + 6 ;
480490 } else {
@@ -686,7 +696,8 @@ void show(){
686696 selectInput .style .overflow = "auto" ;
687697 selectInput .style .height = "auto" ;
688698 }
689- int w = OS .getContainerWidth (handle );
699+ selectInput .size = visibleCount ;
700+ int w = Math .max (maxWidth , OS .getContainerWidth (handle ));
690701 int h = OS .getContainerHeight (handle );
691702 if (OS .isFirefox ) {
692703 coordinate .x += 1 ;
@@ -714,6 +725,7 @@ void show(){
714725 selectInput .style .overflow = "scroll" ;
715726 selectInput .style .height = bounds .height + "px" ;
716727 }
728+ selectInput .style .width = bounds .width +"px" ;
717729 try {
718730 selectInput .focus ();
719731 } catch (Throwable e ) {
@@ -1266,6 +1278,8 @@ public void remove (int index) {
12661278 System .arraycopy (oldOptions , index + 1 , newOptions , index , oldOptions .length - index - 1 );
12671279 selectInput .options = newOptions ;
12681280 itemCount --;
1281+ if (!visibleCountIsSet )
1282+ visibleCount = Math .max (itemCount , 5 );
12691283
12701284}
12711285
@@ -1330,6 +1344,8 @@ public void remove (int start, int end) {
13301344 System .arraycopy (oldOptions , end + 1 , newOptions , start , oldOptions .length - end - 1 );
13311345 selectInput .options = newOptions ;
13321346 itemCount -= (end - start + 1 );
1347+ if (!visibleCountIsSet )
1348+ visibleCount = Math .max (5 , itemCount );
13331349}
13341350
13351351/**
@@ -1379,6 +1395,9 @@ public void removeAll () {
13791395 itemCount = 0 ;
13801396 textInput .value = "" ;
13811397 sendEvent (SWT .Modify );
1398+ itemCount = 0 ;
1399+ if (!visibleCountIsSet )
1400+ visibleCount = 5 ;
13821401 // widget could be disposed at this point
13831402}
13841403
@@ -2001,6 +2020,7 @@ public void setVisibleItemCount (int count) {
20012020 checkWidget ();
20022021 if (count < 0 ) return ;
20032022 visibleCount = count ;
2023+ visibleCountIsSet = true ;
20042024 selectInput .size = count ;
20052025 if ((style & SWT .DROP_DOWN ) != 0 ) {
20062026 forceResize ();
0 commit comments