示例#1
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*/ topHandle = topHandle();
   if (OS.GTK_WIDGET_SENSITIVE(topHandle) == enabled) return;
   OS.gtk_widget_set_sensitive(topHandle, enabled);
   if (enabled) {
     /*
      * Bug in GTK.  GtkButton requires an enter notify before it
      * allows the button to be pressed, but events are dropped when
      * widgets are insensitive.  The fix is to hide and show the
      * button if the pointer is within its bounds.
      */
     int[] x = new int[1], y = new int[1];
     OS.gdk_window_get_pointer(parent.paintWindow(), x, y, null);
     if (getBounds().contains(x[0], y[0])) {
       OS.gtk_widget_hide(handle);
       OS.gtk_widget_show(handle);
     }
   } else {
     /*
      * Bug in GTK. Starting with 2.14, if a button is disabled
      * through on a button press, the field which keeps track
      * whether the pointer is currently in the button is never updated.
      * As a result, when it is re-enabled it automatically enters
      * a PRELIGHT state. The fix is to set a NORMAL state.
      */
     if (OS.GTK_VERSION >= OS.VERSION(2, 14, 0)) {
       OS.gtk_widget_set_state(topHandle, OS.GTK_STATE_NORMAL);
     }
   }
 }
示例#2
0
 /**
  * Returns <code>true</code> if the receiver is enabled, and <code>false</code> otherwise. A
  * disabled control is typically not selectable from the user interface and draws with an inactive
  * or "grayed" look.
  *
  * @return the receiver's 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>
  *
  * @see #isEnabled
  */
 public boolean getEnabled() {
   checkWidget();
   long /*int*/ topHandle = topHandle();
   return OS.GTK_WIDGET_SENSITIVE(topHandle);
 }