Changeset 231 for trunk/src


Ignore:
Timestamp:
Nov 20, 2009, 4:27:07 PM (16 years ago)
Author:
lpino
Message:
  • Misc. fixes
File:
1 edited

Legend:

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

    r226 r231  
    11package org.eclipse.swt.widgets;
     2
     3/*
     4 * OS/2 version.
     5 * Copyright (c) 2002, 2009 EclipseOS2 Team.
     6 */
    27
    38/*
     
    9499public Text (Composite parent, int style) {
    95100        super (parent, checkStyle (style));
    96         if ((style & SWT.SINGLE) != 0)
    97             textLimit = 32;
    98101}
    99102
     
    108111void createHandle () {
    109112        super.createHandle ();
     113        if ((style & SWT.MULTI) != 0) OS.WinSendMsg (handle, OS.MLM_SETTEXTLIMIT, -1, 0);
     114        else OS.WinSendMsg (handle, OS.EM_SETTEXTLIMIT, LIMIT, 0);
    110115}
    111116
     
    296301public Point computeSize (int wHint, int hHint, boolean changed) {
    297302        checkWidget ();
    298         Point size = new Point (0, 0);
    299         int count = ((style & SWT.MULTI) != 0)?OS.WinSendMsg (handle, OS.MLM_QUERYLINECOUNT, 0, 0):1;
     303        int count = getLineCount();
    300304        int hps = this.hps;
    301305        if (hps == 0) hps = OS.WinGetPS (handle);
    302         FONTMETRICS fm = new FONTMETRICS();
    303         OS.GpiQueryFontMetrics (hps, FONTMETRICS.sizeof, fm);
    304         int height = count * fm.lEmHeight, width = 0;
    305 
     306        int height = count * getLineHeight (), width = 0;
    306307        boolean wrap = (style & SWT.MULTI) != 0 && (style & SWT.WRAP) != 0;
    307 
    308 /*      int[] pts = new int[8];
    309         OS.WinSendMsg (handle, OS.MLM_QUERYFORMATRECT, pts, OS.MLFFMTRECT_MATCHWINDOW);
    310  */       
    311         int length = OS.WinQueryWindowTextLength (handle);
    312         System.out.println("Text::computeSize -> text = " + getText());
    313         System.out.println("Text::computeSize -> lineas = " + count);
    314         System.out.println("Text::computeSize -> handle = " + Integer.toHex);
     308       
     309        int length = ((style & SWT.MULTI) != 0)?OS.WinSendMsg (handle, OS.MLM_QUERYTEXTLENGTH, 0, 0):OS.WinQueryWindowTextLength (handle);
     310//      System.out.println("Text::computeSize -> height = " + height);
     311//      System.out.println("Text::computeSize -> lineas = " + count);
    315312        byte[] text = null;
    316         if (length != 0) {
    317             RECTL rect = new RECTL();
    318             text = getText().getBytes();
    319             int[] pnts = new int [OS.TXTBOX_COUNT * 2];
    320             /*
    321              *  Feature in OS/2. The maximum length of the string in string-related
    322              *  GPI functions is 512 chars. Do the cycle to handle larger strings.
    323              */
    324             int extX = 0, dx = 0;
    325             int is = 0;
    326             while (is < length) {
    327     //@@TODO (dmik): Unicode   
    328     //                int ie = is + 256;
    329                 int ie = is + 512;
    330                 if (ie > length) ie = length;
    331                 if (is != 0) {
    332                     System.arraycopy (text, is, text, 0, ie - is); 
    333                 }
    334     //@@TODO (dmik): Unicode   
    335     //                OS.GpiQueryTextBox (hps, (ie - is) << 1, text, OS.TXTBOX_COUNT, pnts);
    336                 OS.GpiQueryTextBox (hps, ie - is, text, OS.TXTBOX_COUNT, pnts);
    337                 extX += pnts [8];
    338                 dx = pnts [4];
    339                 if (dx < pnts [8]) dx = pnts [8];
    340                 dx = dx - pnts [8];
    341                 is = ie;
    342             }
    343             size.x = extX + dx;
    344         }
    345         width += size.x;
    346         System.out.println("Text::computeSize -> ancho = " + width);
     313        text = getText().getBytes();
     314        int[] pnts = new int [OS.TXTBOX_COUNT * 2];
     315        OS.GpiQueryTextBox (hps, length, text, OS.TXTBOX_COUNT, pnts);
     316        width = Math.max (width, pnts[4] - pnts[0]);
     317//      System.out.println("Text::computeSize -> ancho = " + width);
    347318        if (this.hps == 0) OS.WinReleasePS (hps);
    348 //      if (wrap && hHint == SWT.DEFAULT) {
    349 //              int newHeight = rect.bottom - rect.top;
    350 //              if (newHeight != 0) height = newHeight;
    351 //      }
    352 //      if (newFont != 0) OS.SelectObject (hDC, oldFont);
    353 //      OS.ReleaseDC (handle, hDC);
     319        if (wrap && hHint == SWT.DEFAULT) {
     320                int newHeight = pnts[1] - pnts[3];
     321                if (newHeight != 0) height = newHeight;
     322        }
    354323       
    355324        if (width == 0) width = DEFAULT_WIDTH;
     
    357326        if (wHint != SWT.DEFAULT) width = wHint;
    358327        if (hHint != SWT.DEFAULT) height = hHint;
    359 //
    360 //      /* Calculate the margin width */
    361 //      int margins = OS.SendMessage(handle, OS.EM_GETMARGINS, 0, 0);
    362 //      int marginWidth = (margins & 0xFFFF) + ((margins >> 16) & 0xFFFF);
    363 //      width += marginWidth;
    364 //     
    365 //      /*
    366 //      * The preferred height of a single-line text widget
    367 //      * has been hand-crafted to be the same height as
    368 //      * the single-line text widget in an editable combo
    369 //      * box.
    370 //      */
    371 //      width += editRect.left * 2;
    372 //      height += editRect.top * 2;
     328
    373329        if ((style & SWT.V_SCROLL) != 0) {
    374330                width += OS.WinQuerySysValue (OS.HWND_DESKTOP, OS.SV_CXVSCROLL);
     
    600556public char getEchoChar () {
    601557        checkWidget ();
    602         //@@TODO(lpino): Find out how to implement this. Maybe there is no need
    603 //      char echo = (char) OS.SendMessage (handle, OS.EM_GETPASSWORDCHAR, 0, 0);
    604 //      if (echo != 0 && (echo = mbcsToWcs (echo, getCodePage ())) == 0) echo = '*';
    605 //      return echo;
    606         return '*';
     558         return '*';
    607559}
    608560
     
    669621public int getLineHeight () {
    670622        checkWidget ();
    671 //      int newFont, oldFont = 0;
    672 //      int hDC = OS.GetDC (handle);
    673 //      newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
    674 //      if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
    675 //      TEXTMETRIC tm = new TEXTMETRIC ();
    676 //      OS.GetTextMetrics (hDC, tm);
    677 //      if (newFont != 0) OS.SelectObject (hDC, oldFont);
    678 //      OS.ReleaseDC (handle, hDC);
    679 //      return tm.tmHeight;
    680        
    681         //@@TODO(lpino): Implement MLM_QUERYFONT
    682 //        if ((style & SWT.MULTI) != 0){
    683 //            FATTRS hFont;
    684 //            OS.WinSendMsg (handle, OS.MLM_QUERYFONT, hFont, 0);
    685 //        }else{
     623        if ((style & SWT.MULTI) != 0){
     624            FATTRS hFont = new FATTRS();
     625            OS.WinSendMsg (handle, OS.MLM_QUERYFONT, hFont, 0);
     626            return hFont.lMaxBaselineExt + 4;
     627        }else{
    686628            int hps = this.hps;
    687629            if (hps == 0) hps = OS.WinGetPS (handle);
    688630            FONTMETRICS fm = new FONTMETRICS();
    689631            OS.GpiQueryFontMetrics (hps, FONTMETRICS.sizeof, fm);
    690             return fm.lEmHeight;
    691 //        }
    692 //        return 0;
     632            OS.WinReleasePS(hps);
     633            return fm.lMaxBaselineExt + 4;
     634        }
    693635}
    694636
     
    784726        int hps = this.hps;
    785727        if (hps == 0) hps = OS.WinGetPS (handle);
    786         int extX = 0, dx = 0;
     728        int dx = 0;
    787729        int[] pnts = new int [OS.TXTBOX_COUNT * 2];
    788 //        byte[] text = (new String(" ")).getBytes();
    789730        PSZ buffer = new PSZ (" ");
    790731        OS.GpiQueryTextBox (hps, 1, buffer.getBytes(), OS.TXTBOX_COUNT, pnts);
    791         extX += pnts [8];
    792         dx = pnts [4];
    793         if (dx < pnts [8]) dx = pnts [8];
    794         dx = dx - pnts [8];
    795 //        System.out.println("TOTAL = " + (extX + dx));
    796 //        for(int i=0;i<OS.TXTBOX_COUNT * 2;i++){
    797 //            System.out.println("Punto " + i + "=" + pnts[i]);
    798 //        }
    799         return extX + dx;
     732        dx = pnts [4]-pnts [0];
     733        OS.WinReleasePS(hps);
     734        return dx;
    800735}
    801736
     
    815750public String getText () {
    816751        checkWidget ();
    817         int length = OS.WinQueryWindowTextLength (handle);
     752        int length = ((style & SWT.MULTI) != 0)?OS.WinSendMsg (handle, OS.MLM_QUERYTEXTLENGTH, 0, 0):OS.WinQueryWindowTextLength (handle);
    818753        if (length == 0) return "";
    819754        PSZ buffer = new PSZ(length);
     
    13061241        checkWidget ();
    13071242        super.setFont (font);
    1308 //      setTabStops (tabs);
     1243        setTabStops (tabs);
    13091244}
    13101245
     
    14881423        if ((style & SWT.MULTI) != 0){
    14891424            OS.WinSendMsg(handle, OS.MLM_INSERT, buffer, 0);
     1425            /* SWT places the I-beam before the inserted text */
     1426            OS.WinSendMsg(handle, OS.MLM_SETSEL, 0, 0);
    14901427        }
    14911428        else{
    14921429            OS.WinSetWindowText(handle, buffer);
     1430            /* SWT places the I-beam before the inserted text */
     1431            OS.WinSendMsg (handle, OS.EM_SETSEL, OS.MPFROM2SHORT((short)0, (short)0), 0);
    14931432        }
    14941433}
     
    15771516public void showSelection () {
    15781517        checkWidget ();
    1579 //      OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0);
     1518        int pos = OS.WinSendMsg (handle, OS.MLM_QUERYSEL, OS.MLFQS_ANCHORSEL , 0);
     1519        OS.WinSendMsg (handle, OS.MLM_SETSEL, pos, pos);
    15801520}
    15811521
     
    16651605            if ((style & SWT.H_SCROLL) != 0) bits |= OS.MLS_HSCROLL;
    16661606            if ((style & SWT.BORDER) != 0) bits |= OS.MLS_BORDER;
    1667             return bits | OS.WS_VISIBLE;
     1607            return bits | OS.WS_VISIBLE | OS.WS_GROUP | OS.WS_TABSTOP;
    16681608        }
    16691609        else{
     
    16711611            if ((style & SWT.READ_ONLY) != 0) bits |= OS.ES_READONLY;
    16721612            if ((style & SWT.BORDER) != 0) bits |= OS.ES_MARGIN;
    1673             return bits | OS.WS_VISIBLE | OS.ES_AUTOSCROLL;
     1613            return bits | OS.WS_VISIBLE | OS.ES_AUTOSCROLL | OS.ES_LEFT | OS.WS_TABSTOP;
    16741614        }
    16751615}
     
    17461686//      return result;
    17471687//}
    1748 //
    1749 //LRESULT WM_GETDLGCODE (int wParam, int lParam) {
    1750 //      LRESULT result = super.WM_GETDLGCODE (wParam, lParam);
    1751 //      if (result != null) return result;
    1752 //      /*
    1753 //      * Feature in Windows.  Despite the fact that the
    1754 //      * text control is read only, it still returns a
    1755 //      * dialog code indicating that it wants keys.  The
    1756 //      * fix is to detect this case and clear the bits.
    1757 //      */
    1758 //      if ((style & SWT.READ_ONLY) != 0) {
    1759 //              int code = callWindowProc (OS.WM_GETDLGCODE, wParam, lParam);
    1760 //              code &= ~(OS.DLGC_WANTALLKEYS | OS.DLGC_WANTTAB | OS.DLGC_WANTARROWS);
    1761 //              return new LRESULT (code);
    1762 //      }
    1763 //      return null;
    1764 //}
    1765 //
    17661688//LRESULT WM_IME_CHAR (int wParam, int lParam) {
    17671689//
     
    19421864}
    19431865
    1944 //MRESULT wmCommandChild (int mp1, int mp2) {
    1945 //      int code = mp1 >> 16;
    1946 //      switch (code) {
    1947 //              case OS.EN_CHANGE:
    1948 //                      /*
    1949 //                      * It is possible (but unlikely), that application
    1950 //                      * code could have disposed the widget in the modify
    1951 //                      * event.  If this happens, end the processing of the
    1952 //                      * Windows message by returning zero as the result of
    1953 //                      * the window proc.
    1954 //                      */
    1955 //                      sendEvent (SWT.Modify);
    1956 //                      if (isDisposed ()) return MRESULT.ZERO;
    1957 //                      break;
    1958 //      }
    1959 //      return super.wmCommandChild (mp1, mp2);
    1960 //}
    1961 
    19621866MRESULT wmScroll (int msg, int mp1, int mp2) {
    19631867        int code = callWindowProc (msg, mp1, mp2);
Note: See TracChangeset for help on using the changeset viewer.