Ejemplo n.º 1
0
  /**
   * Sets the selection state of the receiver.
   *
   * <p>When the receiver is of type <code>CHECK</code> or <code>RADIO</code>, it is selected when
   * it is checked (which some platforms draw as a pushed in button).
   *
   * @param selected the new selection 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 setSelection(boolean selected) {
    checkWidget();
    if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return;
    long /*int*/ hwnd = parent.handle;
    int fsState = (int) /*64*/ OS.SendMessage(hwnd, OS.TB_GETSTATE, id, 0);
    /*
     * Feature in Windows.  When TB_SETSTATE is used to set the
     * state of a tool item, the item redraws even when the state
     * has not changed.  The fix is to detect this case and avoid
     * setting the state.
     */
    if (((fsState & OS.TBSTATE_CHECKED) != 0) == selected) return;
    if (selected) {
      fsState |= OS.TBSTATE_CHECKED;
    } else {
      fsState &= ~OS.TBSTATE_CHECKED;
    }
    OS.SendMessage(hwnd, OS.TB_SETSTATE, id, fsState);

    /*
     * Bug in Windows.  When a tool item with the style
     * BTNS_CHECK or BTNS_CHECKGROUP is selected and then
     * disabled, the item does not draw using the disabled
     * image.  The fix is to use the disabled image in all
     * image lists for the item.
     *
     * NOTE: This means that the image list must be updated
     * when the selection changes in a disabled tool item.
     */
    if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
      if (!getEnabled() || !parent.getEnabled()) {
        updateImages(false);
      }
    }
  }
Ejemplo n.º 2
0
 public void setImage(Image image) {
   checkWidget();
   if ((style & SWT.SEPARATOR) != 0) return;
   if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
   super.setImage(image);
   updateImages(getEnabled() && parent.getEnabled());
 }
Ejemplo n.º 3
0
 /**
  * Enables the receiver if the argument is <code>true</code>, and disables it otherwise.
  *
  * <p>A disabled control is typically not selectable from the user interface and draws with an
  * inactive or "grayed" look.
  *
  * @param enabled the new enabled 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 setEnabled(boolean enabled) {
   checkWidget();
   OS.UIElement_IsEnabled(handle, enabled);
   updateImages(enabled && parent.getEnabled());
   if (arrowHandle != 0) {
     OS.UIElement_Opacity(arrowHandle, enabled ? 1 : 0.4);
   }
 }
Ejemplo n.º 4
0
 /**
  * Enables the receiver if the argument is <code>true</code>, and disables it otherwise.
  *
  * <p>A disabled control is typically not selectable from the user interface and draws with an
  * inactive or "grayed" look.
  *
  * @param enabled the new enabled 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 setEnabled(boolean enabled) {
   checkWidget();
   long /*int*/ hwnd = parent.handle;
   int fsState = (int) /*64*/ OS.SendMessage(hwnd, OS.TB_GETSTATE, id, 0);
   /*
    * Feature in Windows.  When TB_SETSTATE is used to set the
    * state of a tool item, the item redraws even when the state
    * has not changed.  The fix is to detect this case and avoid
    * setting the state.
    */
   if (((fsState & OS.TBSTATE_ENABLED) != 0) == enabled) return;
   if (enabled) {
     fsState |= OS.TBSTATE_ENABLED;
     state &= ~DISABLED;
   } else {
     fsState &= ~OS.TBSTATE_ENABLED;
     state |= DISABLED;
   }
   OS.SendMessage(hwnd, OS.TB_SETSTATE, id, fsState);
   if ((style & SWT.SEPARATOR) == 0) {
     if (image != null) updateImages(enabled && parent.getEnabled());
   }
 }
Ejemplo n.º 5
0
 void HandleMouseLeave(int sender, int e) {
   if (!checkEvent(e)) return;
   updateImages(getEnabled() && parent.getEnabled());
 }