예제 #1
0
 void releaseWidget() {
   super.releaseWidget();
   releaseImages();
   control = null;
   toolTipText = null;
   disabledImage = hotImage = null;
   if (disabledImage2 != null) disabledImage2.dispose();
   disabledImage2 = null;
 }
예제 #2
0
 /**
  * This implementation of <code>nativeToJava</code> converts a platform specific representation of
  * an image to java <code>ImageData</code>.
  *
  * @param transferData the platform specific representation of the data to be converted
  * @return a java <code>ImageData</code> of the image if the conversion was successful; otherwise
  *     null
  * @see Transfer#javaToNative
  */
 public Object nativeToJava(TransferData transferData) {
   ImageData imgData = null;
   if (transferData.length > 0) {
     long /*int*/ loader = OS.gdk_pixbuf_loader_new();
     try {
       OS.gdk_pixbuf_loader_write(loader, transferData.pValue, transferData.length, null);
       OS.gdk_pixbuf_loader_close(loader, null);
       long /*int*/ pixbuf = OS.gdk_pixbuf_loader_get_pixbuf(loader);
       if (pixbuf != 0) {
         Image img = Image.gtk_new_from_pixbuf(Display.getCurrent(), SWT.BITMAP, pixbuf);
         imgData = img.getImageData();
         img.dispose();
       }
     } finally {
       OS.g_object_unref(loader);
     }
   }
   return imgData;
 }
예제 #3
0
  /**
   * This implementation of <code>javaToNative</code> converts an ImageData object represented by
   * java <code>ImageData</code> to a platform specific representation.
   *
   * @param object a java <code>ImageData</code> containing the ImageData to be converted
   * @param transferData an empty <code>TransferData</code> object that will be filled in on return
   *     with the platform specific format of the data
   * @see Transfer#nativeToJava
   */
  public void javaToNative(Object object, TransferData transferData) {
    if (!checkImage(object) || !isSupportedType(transferData)) {
      DND.error(DND.ERROR_INVALID_DATA);
    }
    if (OS.GTK_VERSION < OS.VERSION(2, 4, 0)) return;

    ImageData imgData = (ImageData) object;
    if (imgData == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
    Image image = new Image(Display.getCurrent(), imgData);
    long /*int*/ pixbuf = ImageList.createPixbuf(image);
    if (pixbuf != 0) {
      String typeStr = "";
      if (transferData.type == JPEG_ID) typeStr = "jpeg";
      else if (transferData.type == PNG_ID) typeStr = "png";
      else if (transferData.type == BMP_ID) typeStr = "bmp";
      else if (transferData.type == EPS_ID) typeStr = "eps";
      else if (transferData.type == PCX_ID) typeStr = "pcx";
      else if (transferData.type == PPM_ID) typeStr = "ppm";
      else if (transferData.type == RGB_ID) typeStr = "rgb";
      else if (transferData.type == TGA_ID) typeStr = "tga";
      else if (transferData.type == XBM_ID) typeStr = "xbm";
      else if (transferData.type == XPM_ID) typeStr = "xpm";
      else if (transferData.type == XV_ID) typeStr = "xv";
      byte[] type = Converter.wcsToMbcs(null, typeStr, true);
      long /*int*/[] buffer = new long /*int*/[1];
      long /*int*/[] len = new long /*int*/[1];
      if (type == null) return;
      OS.gdk_pixbuf_save_to_bufferv(pixbuf, buffer, len, type, null, null, null);
      OS.g_object_unref(pixbuf);
      transferData.pValue = buffer[0];
      transferData.length = (int) (len[0] + 3) / 4 * 4;
      transferData.result = 1;
      transferData.format = 32;
    }
    image.dispose();
  }
예제 #4
0
  void updateImages(boolean enabled) {
    if ((style & SWT.SEPARATOR) != 0) return;
    long /*int*/ hwnd = parent.handle;
    TBBUTTONINFO info = new TBBUTTONINFO();
    info.cbSize = TBBUTTONINFO.sizeof;
    info.dwMask = OS.TBIF_IMAGE;
    OS.SendMessage(hwnd, OS.TB_GETBUTTONINFO, id, info);
    if (info.iImage == OS.I_IMAGENONE && image == null) return;
    ImageList imageList = parent.getImageList();
    ImageList hotImageList = parent.getHotImageList();
    ImageList disabledImageList = parent.getDisabledImageList();
    if (info.iImage == OS.I_IMAGENONE) {
      Rectangle bounds = image.getBounds();
      int listStyle = parent.style & SWT.RIGHT_TO_LEFT;
      if (imageList == null) {
        imageList = display.getImageListToolBar(listStyle, bounds.width, bounds.height);
      }
      if (disabledImageList == null) {
        disabledImageList =
            display.getImageListToolBarDisabled(listStyle, bounds.width, bounds.height);
      }
      if (hotImageList == null) {
        hotImageList = display.getImageListToolBarHot(listStyle, bounds.width, bounds.height);
      }
      Image disabled = disabledImage;
      if (disabledImage == null) {
        if (disabledImage2 != null) disabledImage2.dispose();
        disabledImage2 = null;
        disabled = image;
        if (!enabled) {
          disabled = disabledImage2 = new Image(display, image, SWT.IMAGE_DISABLE);
        }
      }
      /*
       * 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 assign the disabled image in
       * all image lists.
       */
      Image image2 = image, hot = hotImage;
      if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
        if (!enabled) image2 = hot = disabled;
      }
      info.iImage = imageList.add(image2);
      disabledImageList.add(disabled);
      hotImageList.add(hot != null ? hot : image2);
      parent.setImageList(imageList);
      parent.setDisabledImageList(disabledImageList);
      parent.setHotImageList(hotImageList);
    } else {
      Image disabled = null;
      if (disabledImageList != null) {
        if (image != null) {
          if (disabledImage2 != null) disabledImage2.dispose();
          disabledImage2 = null;
          disabled = disabledImage;
          if (disabledImage == null) {
            disabled = image;
            if (!enabled) {
              disabled = disabledImage2 = new Image(display, image, SWT.IMAGE_DISABLE);
            }
          }
        }
        disabledImageList.put(info.iImage, disabled);
      }
      /*
       * 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.
       */
      Image image2 = image, hot = hotImage;
      if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
        if (!enabled) image2 = hot = disabled;
      }
      if (imageList != null) imageList.put(info.iImage, image2);
      if (hotImageList != null) {
        hotImageList.put(info.iImage, hot != null ? hot : image2);
      }
      if (image == null) info.iImage = OS.I_IMAGENONE;
    }

    /*
     * Bug in Windows.  If the width of an item has already been
     * calculated, the tool bar control will not recalculate it to
     * include the space for the image.  The fix is to set the width
     * to zero, forcing the control recalculate the width for the item.
     */
    info.dwMask |= OS.TBIF_SIZE;
    info.cx = 0;
    OS.SendMessage(hwnd, OS.TB_SETBUTTONINFO, id, info);
    long /*int*/ hFont = OS.SendMessage(hwnd, OS.WM_GETFONT, 0, 0);
    OS.SendMessage(hwnd, OS.WM_SETFONT, hFont, 0);
    parent.layoutItems();
  }