Пример #1
0
  /**
   * Sets the maximum number of characters that the receiver is capable of holding to be the
   * argument.
   *
   * <p>Instead of trying to set the text limit to zero, consider creating a read-only text widget.
   *
   * <p>To reset this value to the default, use <code>setTextLimit(Text.LIMIT)</code>. Specifying a
   * limit value larger than <code>Text.LIMIT</code> sets the receiver's limit to <code>Text.LIMIT
   * </code>.
   *
   * @param limit new text limit
   * @exception IllegalArgumentException
   *     <ul>
   *       <li>ERROR_CANNOT_BE_ZERO - if the limit is zero
   *     </ul>
   *
   * @exception SWTException
   *     <ul>
   *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
   *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
   *     </ul>
   *
   * @see #LIMIT
   */
  public void setTextLimit(int limit) {
    checkWidget();
    if (limit == 0) {
      error(SWT.ERROR_CANNOT_BE_ZERO);
    }

    if (limit < 0 || limit > LIMIT) {
      limit = LIMIT;
    }

    if (variant == TextUtils.LINE_EDIT) {
      OS.QLineEdit_setMaxLength(topHandle, limit);
    } else {
      textLimit = limit;
      if (getCharCount() > limit) {
        OS.QTextEdit_setPlainText(topHandle, getText().substring(0, limit));
      }
    }
  }
Пример #2
0
  void createHandle_pp(int index) {
    if (variant == 0) {
      variant = ((getStyle() & SWT.SINGLE) != 0 ? TextUtils.LINE_EDIT : TextUtils.TEXT_EDIT);
    }

    int alignment = OS.QT_ALIGNLEFT;
    if ((style & SWT.CENTER) != 0) {
      alignment = OS.QT_ALIGNHCENTER;
    } else if ((style & SWT.RIGHT) != 0) {
      alignment = OS.QT_ALIGNRIGHT;
    }

    if (variant == TextUtils.LINE_EDIT) {

      scrollAreaHandle = 0;
      topHandle = handle = OS.QLineEdit_new();

      OS.QLineEdit_setAlignment(handle, alignment | OS.QT_ALIGNVCENTER);
      OS.QLineEdit_setMaxLength(handle, LIMIT);

      if ((style & SWT.PASSWORD) != 0) {
        OS.QLineEdit_setEchoMode(handle, OS.QLINEEDIT_ECHOMODE_PASSWORD);
      }

    } else {

      frameHandle = topHandle = scrollAreaHandle = OS.QTextEdit_new();
      handle = OS.QAbstractScrollArea_viewPort(scrollAreaHandle);

      OS.QTextEdit_setAlignment(scrollAreaHandle, alignment);

      forceTextLayout();
    }

    OS.QWidget_setGeometry(topHandle, 0, 0, 0, 0);

    state |= WidgetState.HANDLE;

    if ((style & SWT.READ_ONLY) != 0) {
      setEditable(false);
    }
  }