/** * Sets the zero-relative index of the line which is currently at the top of the receiver. This * index can change when lines are scrolled or new lines are added and removed. * * @param index the index of the top item * @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> */ public void setTopIndex(int index) { checkWidget(); if (variant == TextUtils.TEXT_EDIT) { index = Math.min(Math.max(index, 0), OS.QTextEdit_swt_getLineCount(topHandle) - 1); OS.QTextEdit_swt_setTopIndex(topHandle, index); } }
/** * Returns the height of a line. * * @return the height of a row of text * @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> */ public int getLineHeight() { checkWidget(); if (variant == TextUtils.LINE_EDIT) { return OS.QWidget_QFontMetrics_lineSpacing(topHandle); } else { return OS.QTextEdit_swt_getLineHeight(topHandle); } }
/** * Returns the top pixel. * * <p>The top pixel is the pixel position of the line that is currently at the top of the widget. * On some platforms, a text widget can be scrolled by pixels instead of lines so that a partial * line is displayed at the top of the widget. * * <p>The top pixel changes when the widget is scrolled. The top pixel does not include the widget * trimming. * * @return the pixel position of the top line * @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> */ public int getTopPixel() { checkWidget(); if (variant == TextUtils.LINE_EDIT) { return 0; } else { return OS.QScrollBar_value(OS.QAbstractScrollArea_verticalScrollBar(scrollAreaHandle)); } }
/** * Sets the contents of the receiver to the given string. If the receiver has style SINGLE and the * argument contains multiple lines of text, the result of this operation is undefined and may * vary from platform to platform. * * @param string the new text * @exception IllegalArgumentException * <ul> * <li>ERROR_NULL_ARGUMENT - if the string is null * </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> */ public void setText(String string) { checkWidget(); TextUtils.setText(variant, topHandle, string, textLimit, this); if (isDisposed()) return; if (variant == TextUtils.TEXT_EDIT) { OS.QScrollBar_setValue(OS.QAbstractScrollArea_verticalScrollBar(scrollAreaHandle), 0); } }
/** * Marks the receiver as visible if the argument is <code>true</code>, and marks it invisible * otherwise. * * <p>If one of the receiver's ancestors is not visible or some other condition makes the receiver * not visible, marking it visible may not actually cause it to be displayed. * * @param visible the new visibility state * @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> */ public void setVisible(boolean visible) { checkWidget(); if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return; if (visible) { OS.QMenu_popup(handle, x, y, 0); } else { OS.QWidget_setVisible(handle, visible); } }
/** * Sets the default menu item to the argument or removes the default emphasis when the argument is * <code>null</code>. * * @param item the default menu item or null * @exception IllegalArgumentException * <ul> * <li>ERROR_INVALID_ARGUMENT - if the menu item has been disposed * </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> */ public void setDefaultItem(MenuItem item) { checkWidget(); if (item != null) { if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); if (item.parent != this) return; OS.QMenu_setDefaultAction(handle, item.handle); } else { OS.QMenu_setDefaultAction(handle, 0); } }
void hookEvents_pp() { super.hookEvents_pp(); if ((style & SWT.BAR) == 0) { int aboutToHideProxy = OS.SignalHandler_new(handle, OS.QSIGNAL_ABOUTTOHIDE); OS.QObject_connectOrThrow( handle, "aboutToHide()", aboutToHideProxy, "widgetSignal()", OS.QT_AUTOCONNECTION); int aboutToShowProxy = OS.SignalHandler_new(handle, OS.QSIGNAL_ABOUTTOSHOW); OS.QObject_connectOrThrow( handle, "aboutToShow()", aboutToShowProxy, "widgetSignal()", OS.QT_AUTOCONNECTION); } }
void createHandle_pp(int index) { if ((style & SWT.BAR) != 0) { handle = OS.QMenuBar_new(parent.topHandle); } else { handle = OS.QMenu_new(parent.handle); } if ((style & SWT.RIGHT_TO_LEFT) != 0) { OS.QWidget_setLayoutDirection(handle, OS.QT_RIGHTTOLEFT); } else { OS.QWidget_setLayoutDirection(handle, OS.QT_LEFTTORIGHT); } topHandle = handle; state |= WidgetState.HANDLE; }
void forceTextLayout() { // Hack: Qt does not do the layouting of the QTextDocument until QTextEdit comes visible on the // screen. // Need to force the layouting of the invisible QTextEdit/QTextDocument here by changing the // line wrap mode. // (Qt's default is QTEXTEDIT_WIDGETWIDTH). // This is needed in order that method's like getLineHeight(), getCaretLineNumber(), // getCaretLocation(), // setTopIndex, etc. work correctly also for invisble text widgets. if (isVisible()) return; OS.QTextEdit_setLineWrapMode(scrollAreaHandle, OS.QTEXTEDIT_NOWRAP); if ((style & SWT.WRAP) != 0) { OS.QTextEdit_setLineWrapMode(scrollAreaHandle, OS.QTEXTEDIT_WIDGETWIDTH); } }
/* * Gets the preferred size for QLineEdit client area */ private Point getPreferredSingleLineClientAreaSize() { Point size = OS.QLineEdit_swt_preferredClientSize(topHandle); if (size == null) return new Point(WidgetConstant.DEFAULT_WIDTH, WidgetConstant.DEFAULT_HEIGHT); if (size.x < 0) size.x = WidgetConstant.DEFAULT_WIDTH; if (size.y < 0) size.y = WidgetConstant.DEFAULT_HEIGHT; return size; }
/** * Sets the echo character. * * <p>The echo character is the character that is displayed when the user enters text or the text * is changed by the programmer. Setting the echo character to '\0' clears the echo character and * redraws the original text. If for any reason the echo character is invalid, or if the platform * does not allow modification of the echo character, the default echo character for the platform * is used. * * @param echo the new echo character * @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> */ public void setEchoChar(char echo) { checkWidget(); if (variant == TextUtils.LINE_EDIT) { int echoMode = (echo == '\0') ? OS.QLINEEDIT_ECHOMODE_NORMAL : OS.QLINEEDIT_ECHOMODE_PASSWORD; OS.QLineEdit_setEchoMode(topHandle, echoMode); } }
public int getBorderWidth() { checkWidget(); if (variant == TextUtils.LINE_EDIT) { return (style & SWT.BORDER) != 0 ? OS.QLineEdit_swt_getBorderWidth(topHandle) : 0; } else { return super.getBorderWidth(); } }
/** * Returns the zero-relative index of the line which is currently at the top of the receiver. * * <p>This index can change when lines are scrolled or new lines are added or removed. * * @return the index of the top line * @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> */ public int getTopIndex() { checkWidget(); if (variant == TextUtils.LINE_EDIT) { return 0; } else { return OS.QTextEdit_swt_getTopIndex(topHandle); } }
void setBackground_pp() { // MULTI uses QLineEdit and might have modified viewport background brush // that needs to be restored to default. if ((style & SWT.MULTI) != 0) { OS.QWidget_swt_unsetPalette(handle); } super.setBackground_pp(); }
/** * Returns the maximum number of characters that the receiver is capable of holding. * * <p>If this has not been changed by <code>setTextLimit()</code>, it will be the constant <code> * Text.LIMIT</code>. * * @return the text limit * @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 int getTextLimit() { checkWidget(); if (variant == TextUtils.LINE_EDIT) { return OS.QLineEdit_maxLength(topHandle); } else { return textLimit > 0 ? textLimit : LIMIT; } }
/** * Returns the line number of the caret. * * <p>The line number of the caret is returned. * * @return the line number * @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> */ public int getCaretLineNumber() { checkWidget(); if (variant == TextUtils.LINE_EDIT) { return 0; } else { return OS.QTextEdit_swt_getCaretLineNumber(topHandle); } }
/** * Returns the number of lines. * * @return the number of lines in the widget * @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> */ public int getLineCount() { checkWidget(); if (variant == TextUtils.LINE_EDIT) { return 1; } else { forceTextLayout(); return OS.QTextEdit_swt_getLineCount(topHandle); } }
/** * Returns the default menu item or null if none has been previously set. * * @return the default menu item. * </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> */ public MenuItem getDefaultItem() { checkWidget(); int actionHandle = OS.QMenu_defaultAction(handle); Widget widget = Display.getWidget(actionHandle); if (widget != null) { if (MenuItem.class.isInstance(widget)) return (MenuItem) widget; } return null; }
/** * Returns a point describing the receiver's location relative to its parent (or its display if * its parent is null). * * <p>The location of the caret is returned. * * @return a point, the location of the caret * @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> */ public Point getCaretLocation() { checkWidget(); if (variant == TextUtils.LINE_EDIT) { // Not supported in Qt return new Point(0, 0); } else { Rectangle cursorRect = OS.QTextEdit_cursorRect(topHandle); return new Point(cursorRect.x, cursorRect.y); } }
/** * 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)); } } }
void hookEvents_pp() { super.hookEvents_pp(); int textChangedProxy = OS.SignalHandler_new(topHandle, OS.QSIGNAL_TEXT_CHANGED); if (variant == TextUtils.LINE_EDIT) { OS.QObject_connectOrThrow( topHandle, "textChanged(const QString&)", textChangedProxy, "widgetSignal(const QString&)", OS.QT_AUTOCONNECTION); int returnPressedProxy = OS.SignalHandler_new(topHandle, OS.QSIGNAL_RETURN_PRESSED); OS.QObject_connectOrThrow( topHandle, "returnPressed()", returnPressedProxy, "widgetSignal()", OS.QT_AUTOCONNECTION); } else { OS.QObject_connectOrThrow( topHandle, "textChanged()", textChangedProxy, "widgetSignal()", OS.QT_AUTOCONNECTION); } }
/** * Returns the echo character. * * <p>The echo character is the character that is displayed when the user enters text or the text * is changed by the programmer. * * @return the echo character * @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 #setEchoChar */ public char getEchoChar() { checkWidget(); if (variant == TextUtils.LINE_EDIT) { int echoMode = OS.QLineEdit_echoMode(topHandle); if (echoMode == OS.QLINEEDIT_ECHOMODE_PASSWORD || echoMode == OS.QLINEEDIT_ECHOMODE_PASSWORDECHOONEDIT) { return '*'; } } return '\0'; }
void backgroundImageApplied_pp(Image image) { // There's a problem with scrolling QTextEdit when non-single-color // backgrounds are used. Background can't be scrolled but needs to be // redrawn. To fix this we detect when background image is taken into use // with QTextEdit and temporarily set null background brush to viewport. // Viewport will inherit the background from its parent and whole area is // updated correctly. // Only MULTI uses QLineEdit if ((style & SWT.MULTI) == 0) return; int textPalette = 0; try { textPalette = OS.QWidget_swt_palette_new(handle); int[] bkRoles = getBackgroundImageRoles(); for (int i = 0; i < bkRoles.length; ++i) { OS.QPalette_swt_setBrush(textPalette, bkRoles[i], 0); } OS.QWidget_setPalette(handle, textPalette); } finally { OS.QPalette_delete(textPalette); } }
public Rectangle computeTrim(int x, int y, int width, int height) { checkWidget(); if (variant == TextUtils.LINE_EDIT) { if ((style & SWT.BORDER) != 0) { int border = OS.QLineEdit_swt_getBorderWidth(topHandle); x -= border; y -= border; width += 2 * border; height += 2 * border; } return new Rectangle(x, y, width, height); } else { return super.computeTrim(x, y, width, height); } }
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); } }
/** * Returns the item at the given, zero-relative index in the receiver. Throws an exception if the * index is out of range. * * @param index the index of the item to return * @return the item at the given index * @exception IllegalArgumentException * <ul> * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the * list minus 1 (inclusive) * </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> */ public MenuItem getItem(int index) { checkWidget(); if (index < 0) error(SWT.ERROR_INVALID_RANGE); int[] actions = OS.QWidget_actions(handle); int indexOfLastMenuItem = -1; MenuItem itemAtIndex = null; for (int i = 0; i < actions.length; ++i) { Widget widget = Display.getWidget(actions[i]); if (widget != null && widget instanceof MenuItem) { if (++indexOfLastMenuItem == index) { itemAtIndex = (MenuItem) widget; break; } } } if (index > indexOfLastMenuItem) { error(SWT.ERROR_INVALID_RANGE); } return itemAtIndex; }
/** * Returns a (possibly empty) array of <code>MenuItem</code>s which are the items in the receiver. * * <p>Note: This is not the actual structure used by the receiver to maintain its list of items, * so modifying the array will not affect the receiver. * * @return the items in the receiver * @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> */ public MenuItem[] getItems() { checkWidget(); int[] handles = OS.QWidget_actions(handle); int count = handles.length; if (count == 0) return new MenuItem[0]; MenuItem[] children = new MenuItem[count]; int items = 0; for (int i = 0; i < count; ++i) { int handle = handles[i]; if (handle != 0) { Widget widget = Display.getWidget(handle); if (widget != null && widget != this) { if (widget instanceof MenuItem) { children[items++] = (MenuItem) widget; } } } } if (items == count) return children; MenuItem[] newChildren = new MenuItem[items]; System.arraycopy(children, 0, newChildren, 0, items); return newChildren; }
public Point computeSize(int wHint, int hHint, boolean changed) { checkWidget(); if (changed) { OS.QWidget_updateGeometry(topHandle); } if (wHint != SWT.DEFAULT && wHint < 0) wHint = SWT.DEFAULT; if (hHint != SWT.DEFAULT && hHint < 0) hHint = SWT.DEFAULT; Point preferredSize; if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT) { preferredSize = new Point(wHint, hHint); } else if (variant == TextUtils.LINE_EDIT) { if (wHint == SWT.DEFAULT && hHint == SWT.DEFAULT) { preferredSize = getPreferredSingleLineClientAreaSize(); } else if (hHint == SWT.DEFAULT) { preferredSize = new Point(wHint, getPreferredSingleLineClientAreaSize().y); } else { preferredSize = new Point(getPreferredSingleLineClientAreaSize().x, hHint); } } else { if (wHint == SWT.DEFAULT && hHint == SWT.DEFAULT) { preferredSize = getPreferredClientAreaSize(-1); } else if (hHint == SWT.DEFAULT) { preferredSize = new Point(wHint, getPreferredClientAreaSize(wHint).y); } else { preferredSize = new Point(getPreferredClientAreaSize(hHint).y, hHint); } } Rectangle trim = computeTrim(0, 0, preferredSize.x, preferredSize.y); return new Point(trim.width, trim.height); }
void checkBorder_pp() { super.checkBorder_pp(); if (variant == TextUtils.LINE_EDIT) { OS.QLineEdit_setFrame(topHandle, (style & SWT.BORDER) != 0); } }
/** * Shows the selection. * * <p>If the selection is already showing in the receiver, this method simply returns. Otherwise, * lines are scrolled until the selection is visible. * * @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> */ public void showSelection() { checkWidget(); if (variant == TextUtils.TEXT_EDIT) { OS.QTextEdit_ensureCursorVisible(topHandle); } }