Changeset 206 for trunk/src


Ignore:
Timestamp:
Oct 17, 2009, 2:40:58 AM (16 years ago)
Author:
lpino
Message:
  • Fixing the sizing of controls
Location:
trunk/src/plugins/org.eclipse.swt/Eclipse SWT/pm/org/eclipse/swt/widgets
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plugins/org.eclipse.swt/Eclipse SWT/pm/org/eclipse/swt/widgets/Combo.java

    r14 r206  
    274274         * the SWT style.
    275275         */
    276 //      style &= ~(SWT.H_SCROLL | SWT.V_SCROLL);
    277 //      style = checkBits (style, SWT.DROP_DOWN, SWT.SIMPLE, 0, 0, 0, 0);
    278 //      if ((style & SWT.SIMPLE) != 0) return style & ~SWT.READ_ONLY;
     276        style &= ~(SWT.H_SCROLL | SWT.V_SCROLL);
     277        style = checkBits (style, SWT.DROP_DOWN, SWT.SIMPLE, 0, 0, 0, 0);
     278        if ((style & SWT.SIMPLE) != 0) return style & ~SWT.READ_ONLY;
    279279        return style;
    280280}
     
    302302}
    303303
    304 //public Point computeSize (int wHint, int hHint, boolean changed) {
    305 //      checkWidget ();
    306 //      int count = OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0);
    307 //      int itemHeight = OS.SendMessage (handle, OS.CB_GETITEMHEIGHT, 0, 0);
    308 //      int width = 0, height = 0;
    309 //      if ((style & SWT.SIMPLE) != 0) height = count * itemHeight;
    310 //      int newFont, oldFont = 0;
    311 //      int hDC = OS.GetDC (handle);
    312 //      newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
    313 //      if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
    314 //      RECT rect = new RECT ();
    315 //      int flags = OS.DT_CALCRECT | OS.DT_NOPREFIX;
    316 //      int length = OS.GetWindowTextLength (handle);
    317 //      int cp = getCodePage ();
    318 //      TCHAR buffer = new TCHAR (cp, length + 1);
    319 //      OS.GetWindowText (handle, buffer, length);
    320 //      OS.DrawText (hDC, buffer, length, rect, flags);
    321 //      width = Math.max (width, rect.right - rect.left);
    322 //      for (int i=0; i<count; i++) {
    323 //              length = OS.SendMessage (handle, OS.CB_GETLBTEXTLEN, i, 0);
    324 //              if (length != OS.CB_ERR) {
    325 //                      if (length + 1 > buffer.length ()) buffer = new TCHAR (cp, length + 1);
    326 //                      int result = OS.SendMessage (handle, OS.CB_GETLBTEXT, i, buffer);
    327 //                      if (result != OS.CB_ERR) {
    328 //                              OS.DrawText (hDC, buffer, length, rect, flags);
    329 //                              width = Math.max (width, rect.right - rect.left);
    330 //                      }
    331 //              }
    332 //      }       
    333 //      if (newFont != 0) OS.SelectObject (hDC, oldFont);
    334 //      OS.ReleaseDC (handle, hDC);
    335 //      if (width == 0) width = DEFAULT_WIDTH;
    336 //      if (height == 0) height = DEFAULT_HEIGHT;
    337 //      if (wHint != SWT.DEFAULT) width = wHint;
    338 //      if (hHint != SWT.DEFAULT) height = hHint;
    339 //      int textHeight = OS.SendMessage (handle, OS.CB_GETITEMHEIGHT, -1, 0);
     304public Point computeSize (int wHint, int hHint, boolean changed) {
     305        checkWidget ();
     306        int count = OS.WinSendMsg (handle, OS.LM_QUERYITEMCOUNT, 0, 0);
     307        int itemHeight = getItemHeight();
     308        int width = 0, height = 0;
     309        if ((style & SWT.SIMPLE) != 0) height = count * itemHeight;
     310        int hps = this.hps;
     311        if (hps == 0) hps = OS.WinGetPS (handle);
     312        PSZ buffer = new PSZ(64+1);
     313        int[] pnts = new int [OS.TXTBOX_COUNT * 2];
     314        for (int i=0; i<count; i++) {
     315                int length = OS.WinSendMsg (handle, OS.LM_QUERYITEMTEXTLENGTH,(short)i, 0);
     316                if (length != OS.LIT_ERROR) {
     317                        if (length + 1 > buffer.length()) {
     318                                buffer = new PSZ( length + 1);
     319                        }
     320                        int result = OS.WinSendMsg (handle, OS.LM_QUERYITEMTEXT, OS.MPFROM2SHORT((short)i,(short)length), buffer);
     321                        if (result != 0) {
     322                                OS.GpiQueryTextBox (hps, length, buffer.getBytes(), OS.TXTBOX_COUNT, pnts);
     323                                width = Math.max (width, pnts[4] - pnts[0]);
     324
     325                        }
     326                }
     327        }       
     328        if (this.hps == 0) OS.WinReleasePS (hps);
     329        if (width == 0) width = DEFAULT_WIDTH;
     330        if (height == 0) height = DEFAULT_HEIGHT;
     331        if (wHint != SWT.DEFAULT) width = wHint;
     332        if (hHint != SWT.DEFAULT) height = hHint;
     333        int textHeight = getItemHeight();
     334        width += OS.WinQuerySysValue (OS.HWND_DESKTOP, OS.SV_CXVSCROLL) + 8;
    340335//      width += OS.GetSystemMetrics (OS.SM_CXVSCROLL) + 8;
    341 //      if ((style & SWT.DROP_DOWN) != 0) {
    342 //              height = textHeight + 6;
    343 //      } else {
    344 //              height += textHeight + 10;
    345 //      }
    346 //      return new Point (width, height);
    347 //}
     336        if ((style & SWT.DROP_DOWN) != 0) {
     337                height = textHeight + 6;
     338        } else {
     339                height += textHeight + 10;
     340        }
     341        return new Point (width, height);
     342}
    348343
    349344void createHandle () {
     
    404399}
    405400
    406 //boolean getEditable () {
    407 //      int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
    408 //      return (bits & 0x0F) == OS.CBS_DROPDOWNLIST;
    409 //}
     401boolean getEditable () {
     402        int bits = OS.WinQueryWindowULong (handle, OS.QWL_STYLE);
     403        if ((bits & OS.CBS_DROPDOWNLIST ) != 0)
     404                return false;
     405        return true;
     406}
    410407
    411408/**
     
    741738public void remove (int index) {
    742739        checkWidget ();
    743         PSZ buffer = null;
    744         if ((style & SWT.H_SCROLL) != 0) {
    745                 int length = OS.WinSendMsg (handle, OS.LM_QUERYITEMTEXTLENGTH,(short)index, 0);
    746                 if (length == OS.LIT_ERROR) error (SWT.ERROR_ITEM_NOT_REMOVED);
    747                 buffer = new PSZ (length + 1);
    748                 int result = OS.WinSendMsg (handle, OS.LM_QUERYITEMTEXT, OS.MPFROM2SHORT((short)length,(short)index), buffer);
    749                 if (result <= 0) error (SWT.ERROR_ITEM_NOT_REMOVED);
    750         }
    751         int topIndex = OS.WinSendMsg (handle, OS.LM_QUERYTOPINDEX, 0, 0);
    752         int result = OS.WinSendMsg (handle, OS.LM_DELETEITEM,(short) index, 0);
    753         if (result <= 0) {
    754                 int count = OS.WinSendMsg (handle, OS.LM_QUERYITEMCOUNT, 0, 0);
    755                 if (0 <= index && index < count) error (SWT.ERROR_ITEM_NOT_REMOVED);
    756                 error (SWT.ERROR_INVALID_RANGE);
    757         }
    758 //@@TODO(lpino):
    759 //      if ((style & SWT.H_SCROLL) != 0) setScrollWidth (buffer, false);
    760         if (index < topIndex) {
    761                 OS.WinSendMsg (handle, OS.LM_SETTOPINDEX, (short)(topIndex-1), 0);
    762         }
     740
     741        int length = OS.WinSendMsg (handle, OS.LM_QUERYITEMTEXTLENGTH,(short)index, 0);
     742        if (length == OS.LIT_ERROR) error (SWT.ERROR_ITEM_NOT_REMOVED);
     743       
     744        int count = OS.WinSendMsg (handle, OS.LM_QUERYITEMCOUNT, 0, 0);
     745        if (index <0 || index > count) error (SWT.ERROR_INVALID_RANGE);
     746       
     747        int leftCount = OS.WinSendMsg (handle, OS.LM_DELETEITEM,(short) index, 0);
     748
     749        if (leftCount == count) error (SWT.ERROR_ITEM_NOT_REMOVED);
     750       
     751        /*
     752        * It is possible (but unlikely), that application
     753        * code could have disposed the widget in the modify
     754        * event.  If this happens, just return.
     755        */
    763756        sendEvent (SWT.Modify);
     757        if (isDisposed ()) return;
     758        /*
     759        * Bug in Windows.  When the combo box is read only
     760        * with exactly one item that is currently selected
     761        * and that item is removed, the combo box does not
     762        * redraw to clear the text area.  The fix is to
     763        * force a redraw.
     764        */
     765        //@@TODO(lpino): Do we need to consider this case in OS/2
     766//      if ((style & SWT.READ_ONLY) != 0) {             
     767//              int count = OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0);
     768//              if (count == 0) OS.InvalidateRect (handle, null, false);
     769//      }
    764770}
    765771
  • trunk/src/plugins/org.eclipse.swt/Eclipse SWT/pm/org/eclipse/swt/widgets/List.java

    r196 r206  
    188188        checkWidget ();
    189189        int count = OS.WinSendMsg (handle, OS.LM_QUERYITEMCOUNT, 0, 0);
    190         //@@TODO(lpino): Implement
    191 //        int rc = wmMeasureItem(OS.WM_MEASUREITEM, handle, 0);
    192 //        System.out.println("Alto = " + OS.SHORT1FROMMP (rc));
    193 //        System.out.println("Ancho = " + OS.SHORT2FROMMP (rc));
    194        
     190        //@@TODO(lpino): Implement WM_MEASUREITEM when necessary
    195191        int itemHeight = getItemHeight();
    196192        int width = 0, height = count * itemHeight;
    197193        int hps = this.hps;
    198194        if (hps == 0) hps = OS.WinGetPS (handle);
    199         RECTL rcl = new RECTL();
    200         int flags = OS.DT_QUERYEXTENT | OS.DT_TEXTATTRS;
    201195        PSZ buffer = new PSZ(64+1);
    202196        int[] pnts = new int [OS.TXTBOX_COUNT * 2];
     
    211205                                OS.GpiQueryTextBox (hps, length, buffer.getBytes(), OS.TXTBOX_COUNT, pnts);
    212206                                width = Math.max (width, pnts[4] - pnts[0]);
    213 //                              System.out.println("List::computeSize -> pto 1 = " + pnts[0] + "," + pnts[1]);
    214 //                              System.out.println("List::computeSize -> pto 2 = " + pnts[2] + "," + pnts[3]);
    215 //                              System.out.println("List::computeSize -> pto 3 = " + pnts[4] + "," + pnts[5]);
    216 //                              System.out.println("List::computeSize -> pto 4 = " + pnts[6] + "," + pnts[7]);
    217207
    218208                        }
     
    227217        width += border * 2 + 3;
    228218        height += border * 2;
    229         if ((style & SWT.V_SCROLL) != 0) {
    230         System.out.println("List::computeSize -> width antes de = " + width);
    231                 width += OS.WinQuerySysValue (handle, OS.SV_CXVSCROLL);
    232         System.out.println("List::computeSize -> width despues de = " + width);
    233         }
     219        //
     220//      if ((style & SWT.V_SCROLL) != 0) {
     221                width += OS.WinQuerySysValue (OS.HWND_DESKTOP, OS.SV_CXVSCROLL);
     222//      }
    234223        if ((style & SWT.H_SCROLL) != 0) {
    235                 height += OS.WinQuerySysValue (handle, OS.SV_CYHSCROLL);
     224                height += OS.WinQuerySysValue (OS.HWND_DESKTOP, OS.SV_CYHSCROLL);
    236225        }
    237226        return new Point (width, height);
     
    754743        int hps = this.hps;
    755744        RECTL rcl = null;
    756 //      RECT rect = null;
    757 //      int hDC = 0, oldFont = 0, newFont = 0, newWidth = 0;
    758745        if ((style & SWT.H_SCROLL) != 0) {
    759746                rcl = new RECTL ();
     
    777764                        }
    778765                        int result =  OS.WinSendMsg (handle, OS.LM_DELETEITEM, index, 0);
    779 //                      if (result == OS.LB_ERR) break;
    780766                        if ((style & SWT.H_SCROLL) != 0) {
    781767                                int flags = OS.DT_QUERYEXTENT | OS.DT_TEXTATTRS;
     
    789775        }
    790776        if ((style & SWT.H_SCROLL) != 0) {
    791 //              if (newFont != 0) OS.SelectObject (hDC, oldFont);
    792777                if (this.hps == 0) OS.WinReleasePS (hps);
    793778                setScrollWidth (newWidth, false);
     
    11301115        checkWidget ();
    11311116        super.setFont (font);
    1132 //@@TODO(lpino): Implement setScrollWidth ()
    11331117        if ((style & SWT.H_SCROLL) != 0) setScrollWidth ();
    11341118}
     
    12511235        int hps = this.hps;
    12521236        if (hps == 0) hps = OS.WinGetPS (handle);
    1253         RECTL rcl = new RECTL();
    12541237        int count = OS.WinSendMsg (handle, OS.LM_QUERYITEMCOUNT, 0, 0);
    1255         int flags = OS.DT_QUERYEXTENT | OS.DT_TEXTATTRS;
     1238        int[] pnts = new int [OS.TXTBOX_COUNT * 2];
    12561239        for (int i=0; i<count; i++) {
    12571240                int length = OS.WinSendMsg (handle, OS.LM_QUERYITEMTEXTLENGTH,(short)i, 0);
     
    12601243                        int result = OS.WinSendMsg (handle, OS.LM_QUERYITEMTEXT, OS.MPFROM2SHORT((short)i,(short)length), buffer);
    12611244                        if (result != 0) {
    1262                                 OS.WinDrawText (hps, -1, buffer.getBytes(), rcl, 0, 0, flags);
    1263                                 newWidth = Math.max (newWidth, rcl.xRight - rcl.xLeft);
     1245                                OS.GpiQueryTextBox (hps, length, buffer.getBytes(), OS.TXTBOX_COUNT, pnts);
     1246                                newWidth = Math.max (newWidth, pnts[4] - pnts[0]);
    12641247                        }
    12651248                }
     
    12671250        if (this.hps == 0) OS.WinReleasePS (hps);
    12681251        OS.WinSendMsg (handle, OS.LM_SETITEMWIDTH, newWidth, 0);
    1269 
    1270 //      RECT rect = new RECT ();
    1271 //      int newFont, oldFont = 0;
    1272 //      int hDC = OS.GetDC (handle);
    1273 //      newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
    1274 //      if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
    1275 //      int cp = getCodePage ();
    1276 //      int count = OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
    1277 //      int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX;
    1278 //      for (int i=0; i<count; i++) {
    1279 //              int length = OS.SendMessage (handle, OS.LB_GETTEXTLEN, i, 0);
    1280 //              if (length != OS.LB_ERR) {
    1281 //                      TCHAR buffer = new TCHAR (cp, length + 1);
    1282 //                      int result = OS.SendMessage (handle, OS.LB_GETTEXT, i, buffer);
    1283 //                      if (result != OS.LB_ERR) {
    1284 //                              OS.DrawText (hDC, buffer, -1, rect, flags);
    1285 //                              newWidth = Math.max (newWidth, rect.right - rect.left);
    1286 //                      }
    1287 //              }
    1288 //      }
    1289 //      if (newFont != 0) OS.SelectObject (hDC, oldFont);
    1290 //      OS.ReleaseDC (handle, hDC);
    12911252//      OS.SendMessage (handle, OS.LB_SETHORIZONTALEXTENT, newWidth + 3, 0);
    12921253}
    1293 //@@TODO(lpino): Implement ?
     1254
    12941255void setScrollWidth (PSZ buffer, boolean grow) {
    1295         RECTL rcl = new RECTL ();
    1296 //      int newFont, oldFont = 0;
    1297 //      int hDC = OS.GetDC (handle);
    12981256        int hps = this.hps;
    12991257        if (hps == 0) hps = OS.WinGetPS (handle);
    1300 //      newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
    1301 //      if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
    1302 //      int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX;
    1303         int flags = OS.DT_QUERYEXTENT | OS.DT_TEXTATTRS;
    1304         OS.WinDrawText (hps, -1, buffer.getBytes(), rcl, 0, 0, flags);
     1258        int[] pnts = new int [OS.TXTBOX_COUNT * 2];
     1259        OS.GpiQueryTextBox (hps, buffer.length(), buffer.getBytes(), OS.TXTBOX_COUNT, pnts);
    13051260        if (this.hps == 0) OS.WinReleasePS (hps);
    1306 //      OS.DrawText (hDC, buffer, -1, rect, flags);
    1307 //      if (newFont != 0) OS.SelectObject (hDC, oldFont);
    1308 //      OS.ReleaseDC (handle, hDC);
    1309         setScrollWidth (rcl.xRight - rcl.xLeft, grow);
     1261        setScrollWidth (pnts[4] - pnts[0], grow);
    13101262}
    13111263
     
    15061458
    15071459int widgetStyle () {
    1508         int bits = super.widgetStyle ();
    1509         if ((style & SWT.SINGLE) != 0) return bits;
     1460        //@@INFO(lpino): LS_NOADJUSTPOS doesn't honor the sizes as are calculated
     1461        int bits = super.widgetStyle ();// | OS.LS_NOADJUSTPOS;
     1462//      if ((style & SWT.SINGLE) != 0) return bits;
    15101463        if ((style & SWT.MULTI) != 0) {
    15111464                if ((style & SWT.SIMPLE) != 0)
    1512                     return bits |= OS.LS_MULTIPLESEL;
    1513                 return bits |= OS.LS_EXTENDEDSEL | OS.LS_EXTENDEDSEL;
     1465                        bits |= OS.LS_MULTIPLESEL;
     1466                else
     1467                        bits |= OS.LS_EXTENDEDSEL | OS.LS_EXTENDEDSEL;
    15141468        }
    15151469        if ((style & SWT.H_SCROLL) != 0)
Note: See TracChangeset for help on using the changeset viewer.