| /******************************************************************************* |
| * Copyright (c) 2000, 2009 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * IBM Corporation - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.swt.widgets; |
| |
| import org.eclipse.swt.internal.photon.*; |
| import org.eclipse.swt.graphics.*; |
| import org.eclipse.swt.events.*; |
| import org.eclipse.swt.*; |
| |
| /** |
| * Instances of this class are selectable user interface |
| * objects that allow the user to enter and modify numeric |
| * values. |
| * <p> |
| * Note that although this class is a subclass of <code>Composite</code>, |
| * it does not make sense to add children to it, or set a layout on it. |
| * </p><p> |
| * <dl> |
| * <dt><b>Styles:</b></dt> |
| * <dd>READ_ONLY, WRAP</dd> |
| * <dt><b>Events:</b></dt> |
| * <dd>Selection, Modify, Verify</dd> |
| * </dl> |
| * </p><p> |
| * IMPORTANT: This class is <em>not</em> intended to be subclassed. |
| * </p> |
| * |
| * @see <a href="http://www.eclipse.org/swt/snippets/#spinner">Spinner snippets</a> |
| * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a> |
| * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> |
| * |
| * @since 3.1 |
| * @noextend This class is not intended to be subclassed by clients. |
| */ |
| public class Spinner extends Composite { |
| /** |
| * the operating system limit for the number of characters |
| * that the text field in an instance of this class can hold |
| * |
| * @since 3.4 |
| */ |
| public static final int LIMIT; |
| |
| /* |
| * These values can be different on different platforms. |
| * Therefore they are not initialized in the declaration |
| * to stop the compiler from inlining. |
| */ |
| static { |
| LIMIT = 0x7FFF; |
| } |
| |
| /** |
| * Constructs a new instance of this class given its parent |
| * and a style value describing its behavior and appearance. |
| * <p> |
| * The style value is either one of the style constants defined in |
| * class <code>SWT</code> which is applicable to instances of this |
| * class, or must be built by <em>bitwise OR</em>'ing together |
| * (that is, using the <code>int</code> "|" operator) two or more |
| * of those <code>SWT</code> style constants. The class description |
| * lists the style constants that are applicable to the class. |
| * Style bits are also inherited from superclasses. |
| * </p> |
| * |
| * @param parent a composite control which will be the parent of the new instance (cannot be null) |
| * @param style the style of control to construct |
| * |
| * @exception IllegalArgumentException <ul> |
| * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> |
| * </ul> |
| * @exception SWTException <ul> |
| * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> |
| * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> |
| * </ul> |
| * |
| * @see SWT#READ_ONLY |
| * @see SWT#WRAP |
| * @see Widget#checkSubclass |
| * @see Widget#getStyle |
| */ |
| public Spinner (Composite parent, int style) { |
| super (parent, checkStyle (style)); |
| } |
| |
| static int checkStyle (int style) { |
| /* |
| * Even though it is legal to create this widget |
| * with scroll bars, they serve no useful purpose |
| * because they do not automatically scroll the |
| * widget's client area. The fix is to clear |
| * the SWT style. |
| */ |
| return style & ~(SWT.H_SCROLL | SWT.V_SCROLL); |
| } |
| |
| protected void checkSubclass () { |
| if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); |
| } |
| |
| void createHandle (int index) { |
| state |= HANDLE; |
| int parentHandle = parent.parentingHandle (); |
| boolean hasBorder = (style & SWT.BORDER) != 0; |
| int textFlags = (style & SWT.READ_ONLY) != 0 ? 0 : OS.Pt_EDITABLE; |
| boolean wrap = (style & SWT.WRAP) != 0; |
| int [] args = new int [] { |
| OS.Pt_ARG_RESIZE_FLAGS, 0, OS.Pt_RESIZE_XY_BITS, |
| OS.Pt_ARG_NUMERIC_INCREMENT, 1, 0, |
| OS.Pt_ARG_NUMERIC_MIN, 0, 0, |
| OS.Pt_ARG_NUMERIC_MAX, 100, 0, |
| OS.Pt_ARG_TEXT_FLAGS, textFlags, OS.Pt_EDITABLE, |
| OS.Pt_ARG_FLAGS, hasBorder ? OS.Pt_HIGHLIGHTED : 0, OS.Pt_HIGHLIGHTED, |
| OS.Pt_ARG_NUMERIC_FLAGS, wrap ? OS.Pt_NUMERIC_WRAP : 0, OS.Pt_NUMERIC_WRAP, |
| }; |
| handle = OS.PtCreateWidget (display.PtNumericInteger, parentHandle, args.length / 3, args); |
| if (handle == 0) error (SWT.ERROR_NO_HANDLES); |
| |
| } |
| |
| /** |
| * Adds the listener to the collection of listeners who will |
| * be notified when the receiver's text is modified, by sending |
| * it one of the messages defined in the <code>ModifyListener</code> |
| * interface. |
| * |
| * @param listener the listener which should be notified |
| * |
| * @exception IllegalArgumentException <ul> |
| * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> |
| * </ul> |
| * @exception SWTException <ul> |
| * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
| * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
| * </ul> |
| * |
| * @see ModifyListener |
| * @see #removeModifyListener |
| */ |
| public void addModifyListener (ModifyListener listener) { |
| checkWidget (); |
| if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); |
| TypedListener typedListener = new TypedListener (listener); |
| addListener (SWT.Modify, typedListener); |
| } |
| |
| /** |
| * Adds the listener to the collection of listeners who will |
| * be notified when the control is selected by the user, by sending |
| * it one of the messages defined in the <code>SelectionListener</code> |
| * interface. |
| * <p> |
| * <code>widgetSelected</code> is not called for texts. |
| * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed in a single-line text. |
| * </p> |
| * |
| * @param listener the listener which should be notified when the control is selected by the user |
| * |
| * @exception IllegalArgumentException <ul> |
| * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> |
| * </ul> |
| * @exception SWTException <ul> |
| * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
| * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
| * </ul> |
| * |
| * @see SelectionListener |
| * @see #removeSelectionListener |
| * @see SelectionEvent |
| */ |
| public void addSelectionListener(SelectionListener listener) { |
| checkWidget (); |
| if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); |
| TypedListener typedListener = new TypedListener (listener); |
| addListener (SWT.Selection,typedListener); |
| addListener (SWT.DefaultSelection,typedListener); |
| } |
| |
| /** |
| * Adds the listener to the collection of listeners who will |
| * be notified when the receiver's text is verified, by sending |
| * it one of the messages defined in the <code>VerifyListener</code> |
| * interface. |
| * |
| * @param listener the listener which should be notified |
| * |
| * @exception IllegalArgumentException <ul> |
| * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> |
| * </ul> |
| * @exception SWTException <ul> |
| * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
| * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
| * </ul> |
| * |
| * @see VerifyListener |
| * @see #removeVerifyListener |
| */ |
| void addVerifyListener (VerifyListener listener) { |
| checkWidget(); |
| if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); |
| TypedListener typedListener = new TypedListener (listener); |
| addListener (SWT.Verify, typedListener); |
| } |
| |
| public Point computeSize (int wHint, int hHint, boolean changed) { |
| checkWidget (); |
| int [] args = new int [] { |
| OS.Pt_ARG_TEXT_FONT, 0, 0, |
| OS.Pt_ARG_NUMERIC_MAX, 0, 0, |
| OS.Pt_ARG_NUMERIC_UPDOWN_WIDTH, 0, 0, |
| }; |
| OS.PtGetResources (handle, args.length / 3, args); |
| int width = wHint; |
| int height = hHint; |
| if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) { |
| int ptr = args [1]; |
| int length = OS.strlen (ptr); |
| byte [] font = new byte [length + 1]; |
| OS.memmove (font, ptr, length); |
| String string = String.valueOf (args [4]); |
| PhRect_t rect = new PhRect_t (); |
| int size = string.length (); |
| char [] buffer = new char [size]; |
| string.getChars (0, size, buffer, 0); |
| OS.PfExtentWideText (rect, null, font, buffer, size * 2); |
| if (wHint == SWT.DEFAULT) width = rect.lr_x - rect.ul_x + 1; |
| if (hHint == SWT.DEFAULT) height = rect.lr_y - rect.ul_y + 1; |
| } |
| Rectangle trim = computeTrim (0, 0, width, height); |
| if (hHint == SWT.DEFAULT) { |
| trim.height = Math.max (trim.height, args [7] * 2); |
| } |
| return new Point (trim.width, trim.height); |
| } |
| |
| public Rectangle computeTrim(int x, int y, int width, int height) { |
| int border = getBorderWidth (); |
| x -= border; |
| y -= border; |
| width += 2 * border; |
| height += 2 * border; |
| int [] args = new int [] { |
| OS.Pt_ARG_NUMERIC_SPACING, 0, 0, // 1 |
| OS.Pt_ARG_NUMERIC_UPDOWN_WIDTH, 0, 0, // 4 |
| // OS.Pt_ARG_NUMERIC_TEXT_BORDER, 0, 0, // 7 |
| }; |
| OS.PtGetResources (handle, args.length / 3, args); |
| |
| /* |
| * Note: Pt_ARG_NUMERIC_TEXT_BORDER is defined in the |
| * documentation (default value 2) but is not defined |
| * in the include files on QNX 6.2.1. |
| */ |
| int textBorder = 2; |
| width += args [1] + args [4] + 2 * textBorder; |
| height += 2 * textBorder; |
| int textHandle = OS.PtWidgetChildBack (handle); |
| args = new int [] { |
| OS.Pt_ARG_MARGIN_WIDTH, 0, 0, // 1 |
| OS.Pt_ARG_MARGIN_LEFT, 0, 0, // 4 |
| OS.Pt_ARG_MARGIN_RIGHT, 0, 0, // 7 |
| OS.Pt_ARG_TEXT_CURSOR_WIDTH, 0, 0, // 10 |
| }; |
| OS.PtGetResources (textHandle, args.length / 3, args); |
| width += args [1] + args [4] + args [7] + args [10]; |
| return new Rectangle (x, y, width, height); |
| } |
| |
| /** |
| * Copies the selected text. |
| * <p> |
| * The current selection is copied to the clipboard. |
| * </p> |
| * |
| * @exception SWTException <ul> |
| * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
| * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
| * </ul> |
| */ |
| public void copy () { |
| checkWidget (); |
| int textHandle = OS.PtWidgetChildBack (handle); |
| if (textHandle != 0) { |
| int [] start = new int [1], end = new int [1]; |
| int length = OS.PtTextGetSelection (textHandle, start, end); |
| if (length <= 0) return; |
| int [] args = {OS.Pt_ARG_TEXT_STRING, 0, 0}; |
| OS.PtGetResources (textHandle, args.length / 3, args); |
| byte[] buffer = new byte[length + 1]; |
| OS.memmove (buffer, args [1] + start [0], length); |
| int ig = OS.PhInputGroup (0); |
| OS.PhClipboardCopyString((short)ig, buffer); |
| } |
| } |
| |
| /** |
| * Cuts the selected text. |
| * <p> |
| * The current selection is first copied to the |
| * clipboard and then deleted from the widget. |
| * </p> |
| * |
| * @exception SWTException <ul> |
| * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
| * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
| * </ul> |
| */ |
| public void cut () { |
| checkWidget (); |
| if ((style & SWT.READ_ONLY) != 0) return; |
| int textHandle = OS.PtWidgetChildBack (handle); |
| if (textHandle != 0) { |
| int [] start = new int [1], end = new int [1]; |
| int length = OS.PtTextGetSelection (textHandle, start, end); |
| if (length <= 0) return; |
| int [] args = {OS.Pt_ARG_TEXT_STRING, 0, 0}; |
| OS.PtGetResources (textHandle, args.length / 3, args); |
| byte[] buffer = new byte[length + 1]; |
| OS.memmove (buffer, args [1] + start [0], length); |
| int ig = OS.PhInputGroup (0); |
| OS.PhClipboardCopyString((short)ig, buffer); |
| buffer = new byte[0]; |
| OS.PtTextModifyText (textHandle, start [0], end [0], start [0], buffer, buffer.length); |
| } |
| } |
| |
| void deregister () { |
| super.deregister (); |
| int textHandle = OS.PtWidgetChildBack (handle); |
| WidgetTable.remove (textHandle); |
| } |
| |
| int defaultBackground () { |
| return display.TEXT_BACKGROUND; |
| } |
| |
| int defaultForeground () { |
| return display.TEXT_FOREGROUND; |
| } |
| |
| /** |
| * Returns the number of decimal places used by the receiver. |
| * |
| * @return the digits |
| * |
| * @exception SWTException <ul> |
| * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
| * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
| * </ul> |
| */ |
| public int getDigits () { |
| checkWidget (); |
| return 0; |
| } |
| |
| /** |
| * Returns the amount that the receiver's value will be |
| * modified by when the up/down arrows are pressed. |
| * |
| * @return the increment |
| * |
| * @exception SWTException <ul> |
| * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
| * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
| * </ul> |
| */ |
| public int getIncrement () { |
| checkWidget (); |
| int [] args = {OS.Pt_ARG_NUMERIC_INCREMENT, 0, 0}; |
| OS.PtGetResources (handle, args.length / 3, args); |
| return args [1]; |
| } |
| |
| /** |
| * Returns the maximum value which the receiver will allow. |
| * |
| * @return the maximum |
| * |
| * @exception SWTException <ul> |
| * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
| * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
| * </ul> |
| */ |
| public int getMaximum () { |
| checkWidget (); |
| int [] args = {OS.Pt_ARG_NUMERIC_MAX, 0, 0}; |
| OS.PtGetResources (handle, args.length / 3, args); |
| return args [1]; |
| } |
| |
| /** |
| * Returns the minimum value which the receiver will allow. |
| * |
| * @return the minimum |
| * |
| * @exception SWTException <ul> |
| * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
| * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
| * </ul> |
| */ |
| public int getMinimum () { |
| checkWidget (); |
| int [] args = {OS.Pt_ARG_NUMERIC_MIN, 0, 0}; |
| OS.PtGetResources (handle, args.length / 3, args); |
| return args [1]; |
| } |
| |
| /** |
| * Returns the amount that the receiver's position will be |
| * modified by when the page up/down keys are pressed. |
| * |
| * @return the page increment |
| * |
| * @exception SWTException <ul> |
| * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
| * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
| * </ul> |
| */ |
| public int getPageIncrement () { |
| checkWidget (); |
| return 0; |
| } |
| |
| /** |
| * Returns the <em>selection</em>, which is the receiver's position. |
| * |
| * @return the selection |
| * |
| * @exception SWTException <ul> |
| * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
| * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
| * </ul> |
| */ |
| public int getSelection () { |
| checkWidget (); |
| int [] args = {OS.Pt_ARG_NUMERIC_VALUE, 0, 0}; |
| OS.PtGetResources (handle, args.length / 3, args); |
| return args [1]; |
| } |
| |
| /** |
| * Returns a string containing a copy of the contents of the |
| * receiver's text field, or an empty string if there are no |
| * contents. |
| * |
| * @return the receiver's text |
| * |
| * @exception SWTException <ul> |
| * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
| * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
| * </ul> |
| * |
| * @since 3.4 |
| */ |
| public String getText () { |
| checkWidget (); |
| return ""; |
| } |
| |
| /** |
| * Returns the maximum number of characters that the receiver's |
| * text field is capable of holding. If this has not been changed |
| * by <code>setTextLimit()</code>, it will be the constant |
| * <code>Spinner.LIMIT</code>. |
| * |
| * @return the text limit |
| * |
| * @exception SWTException <ul> |
| * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
| * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
| * </ul> |
| * |
| * @see #LIMIT |
| * |
| * @since 3.4 |
| */ |
| public int getTextLimit () { |
| checkWidget (); |
| return LIMIT; |
| } |
| |
| boolean hasFocus () { |
| return OS.PtIsFocused (handle) != 0; |
| } |
| |
| void hookEvents () { |
| super.hookEvents (); |
| int windowProc = display.windowProc; |
| OS.PtAddCallback (handle, OS.Pt_CB_NUMERIC_CHANGED, windowProc, OS.Pt_CB_NUMERIC_CHANGED); |
| } |
| |
| /** |
| * Pastes text from clipboard. |
| * <p> |
| * The selected text is deleted from the widget |
| * and new text inserted from the clipboard. |
| * </p> |
| * |
| * @exception SWTException <ul> |
| * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
| * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
| * </ul> |
| */ |
| public void paste () { |
| checkWidget (); |
| if ((style & SWT.READ_ONLY) != 0) return; |
| int textHandle = OS.PtWidgetChildBack (handle); |
| if (textHandle != 0) { |
| int ig = OS.PhInputGroup (0); |
| int ptr = OS.PhClipboardPasteString((short)ig); |
| if (ptr == 0) return; |
| int length = OS.strlen (ptr); |
| int [] start = new int [1], end = new int [1]; |
| OS.PtTextGetSelection (textHandle, start, end); |
| if (start [0] == -1) { |
| int [] args = {OS.Pt_ARG_CURSOR_POSITION, 0, 0}; |
| OS.PtGetResources (textHandle, args.length / 3, args); |
| start [0] = end [0] = args [1]; |
| } |
| OS.PtTextModifyText (textHandle, start [0], end [0], end [0], ptr, length); |
| OS.free(ptr); |
| } |
| } |
| |
| int Pt_CB_NUMERIC_CHANGED (int widget, int info) { |
| if (info == 0) return OS.Pt_END; |
| PtCallbackInfo_t cbinfo = new PtCallbackInfo_t (); |
| OS.memmove (cbinfo, info, PtCallbackInfo_t.sizeof); |
| if (cbinfo.event == 0) return OS.Pt_END; |
| switch (cbinfo.reason_subtype) { |
| case OS.Pt_NUMERIC_CHANGED: |
| sendEvent (SWT.Modify); |
| break; |
| case OS.Pt_NUMERIC_UPDOWN_ACTIVATE: |
| case OS.Pt_NUMERIC_UPDOWN_REPEAT: |
| sendEvent (SWT.Selection); |
| break; |
| } |
| return OS.Pt_CONTINUE; |
| } |
| |
| void register () { |
| super.register (); |
| int textHandle = OS.PtWidgetChildBack (handle); |
| WidgetTable.put (textHandle, this); |
| } |
| |
| /** |
| * Removes the listener from the collection of listeners who will |
| * be notified when the receiver's text is modified. |
| * |
| * @param listener the listener which should no longer be notified |
| * |
| * @exception IllegalArgumentException <ul> |
| * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> |
| * </ul> |
| * @exception SWTException <ul> |
| * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
| * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
| * </ul> |
| * |
| * @see ModifyListener |
| * @see #addModifyListener |
| */ |
| public void removeModifyListener (ModifyListener listener) { |
| checkWidget (); |
| if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); |
| if (eventTable == null) return; |
| eventTable.unhook (SWT.Modify, listener); |
| } |
| |
| /** |
| * Removes the listener from the collection of listeners who will |
| * be notified when the control is selected by the user. |
| * |
| * @param listener the listener which should no longer be notified |
| * |
| * @exception IllegalArgumentException <ul> |
| * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> |
| * </ul> |
| * @exception SWTException <ul> |
| * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
| * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
| * </ul> |
| * |
| * @see SelectionListener |
| * @see #addSelectionListener |
| */ |
| public void removeSelectionListener(SelectionListener listener) { |
| checkWidget (); |
| if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); |
| if (eventTable == null) return; |
| eventTable.unhook (SWT.Selection, listener); |
| eventTable.unhook (SWT.DefaultSelection,listener); |
| } |
| |
| /** |
| * Removes the listener from the collection of listeners who will |
| * be notified when the control is verified. |
| * |
| * @param listener the listener which should be notified |
| * |
| * @exception IllegalArgumentException <ul> |
| * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> |
| * </ul> |
| * @exception SWTException <ul> |
| * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
| * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
| * </ul> |
| * |
| * @see VerifyListener |
| * @see #addVerifyListener |
| */ |
| void removeVerifyListener (VerifyListener listener) { |
| checkWidget (); |
| if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); |
| if (eventTable == null) return; |
| eventTable.unhook (SWT.Verify, listener); |
| } |
| |
| /** |
| * Sets the number of decimal places used by the receiver. |
| * <p> |
| * The digit setting is used to allow for floating point values in the receiver. |
| * For example, to set the selection to a floating point value of 1.37 call setDigits() with |
| * a value of 2 and setSelection() with a value of 137. Similarly, if getDigits() has a value |
| * of 2 and getSelection() returns 137 this should be interpreted as 1.37. This applies to all |
| * numeric APIs. |
| * </p> |
| * |
| * @param value the new digits (must be greater than or equal to zero) |
| * |
| * @exception IllegalArgumentException <ul> |
| * <li>ERROR_INVALID_ARGUMENT - if the value is less than zero</li> |
| * </ul> |
| * @exception SWTException <ul> |
| * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
| * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
| * </ul> |
| */ |
| public void setDigits (int value) { |
| checkWidget (); |
| } |
| |
| /** |
| * Sets the amount that the receiver's value will be |
| * modified by when the up/down arrows are pressed to |
| * the argument, which must be at least one. |
| * |
| * @param value the new increment (must be greater than zero) |
| * |
| * @exception SWTException <ul> |
| * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
| * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
| * </ul> |
| */ |
| public void setIncrement (int value) { |
| checkWidget (); |
| if (value < 1) return; |
| OS.PtSetResource (handle, OS.Pt_ARG_NUMERIC_INCREMENT, value, 0); |
| } |
| |
| /** |
| * Sets the maximum value that the receiver will allow. This new |
| * value will be ignored if it is less than the receiver's current |
| * minimum value. If the new maximum is applied then the receiver's |
| * selection value will be adjusted if necessary to fall within its new range. |
| * |
| * @param value the new maximum, which must be greater than or equal to the current minimum |
| * |
| * @exception SWTException <ul> |
| * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
| * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
| * </ul> |
| */ |
| public void setMaximum (int value) { |
| checkWidget (); |
| if (value < 0) return; |
| OS.PtSetResource (handle, OS.Pt_ARG_NUMERIC_MAX, value, 0); |
| } |
| |
| /** |
| * Sets the minimum value that the receiver will allow. This new |
| * value will be ignored if it is greater than the receiver's |
| * current maximum value. If the new minimum is applied then the receiver's |
| * selection value will be adjusted if necessary to fall within its new range. |
| * |
| * @param value the new minimum, which must be less than or equal to the current maximum |
| * |
| * @exception SWTException <ul> |
| * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
| * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
| * </ul> |
| */ |
| public void setMinimum (int value) { |
| checkWidget (); |
| if (value < 0) return; |
| OS.PtSetResource (handle, OS.Pt_ARG_NUMERIC_MIN, value, 0); |
| } |
| |
| /** |
| * Sets the amount that the receiver's position will be |
| * modified by when the page up/down keys are pressed |
| * to the argument, which must be at least one. |
| * |
| * @param value the page increment (must be greater than zero) |
| * |
| * @exception SWTException <ul> |
| * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
| * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
| * </ul> |
| */ |
| public void setPageIncrement (int value) { |
| checkWidget (); |
| if (value < 1) return; |
| } |
| |
| /** |
| * Sets the <em>selection</em>, which is the receiver's |
| * position, to the argument. If the argument is not within |
| * the range specified by minimum and maximum, it will be |
| * adjusted to fall within this range. |
| * |
| * @param value the new selection (must be zero or greater) |
| * |
| * @exception SWTException <ul> |
| * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
| * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
| * </ul> |
| */ |
| public void setSelection (int value) { |
| checkWidget (); |
| OS.PtSetResource (handle, OS.Pt_ARG_NUMERIC_VALUE, value, 0); |
| } |
| |
| /** |
| * Sets the maximum number of characters that the receiver's |
| * text field is capable of holding to be the argument. |
| * <p> |
| * To reset this value to the default, use <code>setTextLimit(Spinner.LIMIT)</code>. |
| * Specifying a limit value larger than <code>Spinner.LIMIT</code> sets the |
| * receiver's limit to <code>Spinner.LIMIT</code>. |
| * </p> |
| * @param limit new text limit |
| * |
| * @exception IllegalArgumentException <ul> |
| * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li> |
| * </ul> |
| * @exception SWTException <ul> |
| * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
| * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
| * </ul> |
| * |
| * @see #LIMIT |
| * |
| * @since 3.4 |
| */ |
| public void setTextLimit (int limit) { |
| checkWidget (); |
| if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO); |
| } |
| |
| /** |
| * Sets the receiver's selection, minimum value, maximum |
| * value, digits, increment and page increment all at once. |
| * <p> |
| * Note: This is similar to setting the values individually |
| * using the appropriate methods, but may be implemented in a |
| * more efficient fashion on some platforms. |
| * </p> |
| * |
| * @param selection the new selection value |
| * @param minimum the new minimum value |
| * @param maximum the new maximum value |
| * @param digits the new digits value |
| * @param increment the new increment value |
| * @param pageIncrement the new pageIncrement value |
| * |
| * @exception SWTException <ul> |
| * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
| * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
| * </ul> |
| * |
| * @since 3.2 |
| */ |
| public void setValues (int selection, int minimum, int maximum, int digits, int increment, int pageIncrement) { |
| checkWidget (); |
| if (minimum < 0) return; |
| if (maximum <= minimum) return; |
| if (digits < 0) return; |
| if (increment < 1) return; |
| if (pageIncrement < 1) return; |
| selection = Math.min (Math.max (minimum, selection), maximum); |
| int [] args = new int [] { |
| OS.Pt_ARG_NUMERIC_INCREMENT, increment, 0, |
| OS.Pt_ARG_NUMERIC_MIN, minimum, 0, |
| OS.Pt_ARG_NUMERIC_MAX, maximum, 0, |
| OS.Pt_ARG_NUMERIC_VALUE, selection, 0 |
| }; |
| OS.PtSetResources (handle, args.length / 3, args); |
| } |
| |
| boolean translateTraversal (int key_sym, PhKeyEvent_t phEvent) { |
| boolean translated = super.translateTraversal (key_sym, phEvent); |
| if (!translated && key_sym == OS.Pk_Return) { |
| postEvent (SWT.DefaultSelection); |
| return false; |
| } |
| return translated; |
| } |
| |
| int widgetClass () { |
| return OS.PtNumericInteger (); |
| } |
| |
| } |