Exemple #1
0
 public void setImage(Image image) {
   checkWidget();
   if ((style & SWT.SEPARATOR) != 0) return;
   super.setImage(image);
   if (image != null) {
     ImageList imageList = parent.imageList;
     if (imageList == null) imageList = parent.imageList = new ImageList();
     int imageIndex = imageList.indexOf(image);
     if (imageIndex == -1) {
       imageIndex = imageList.add(image);
     } else {
       imageList.put(imageIndex, image);
     }
     long /*int*/ pixbuf = imageList.getPixbuf(imageIndex);
     OS.gtk_image_set_from_pixbuf(imageHandle, pixbuf);
   } else {
     OS.gtk_image_set_from_pixbuf(imageHandle, 0);
   }
   /*
    * If Text/Image of a tool-item changes, then it is
    * required to reset the proxy menu. Otherwise, the
    * old menuItem appears in the overflow menu.
    */
   if ((style & SWT.DROP_DOWN) != 0) {
     proxyMenuItem = 0;
     proxyMenuItem = OS.gtk_tool_item_retrieve_proxy_menu_item(handle);
     OS.g_signal_connect(
         proxyMenuItem, OS.activate, ToolBar.menuItemSelectedFunc.getAddress(), handle);
   }
   parent.relayout();
 }
Exemple #2
0
 /**
  * Sets the receiver's image at a column.
  *
  * @param index the column index
  * @param image the new image
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_INVALID_ARGUMENT - if the image 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 setImage(int index, Image image) {
   checkWidget();
   if (image != null && image.isDisposed()) {
     error(SWT.ERROR_INVALID_ARGUMENT);
   }
   if (image != null && image.type == SWT.ICON) {
     if (image.equals(_getImage(index))) return;
   }
   int count = Math.max(1, parent.getColumnCount());
   if (0 > index || index > count - 1) return;
   int /*long*/ pixbuf = 0;
   if (image != null) {
     ImageList imageList = parent.imageList;
     if (imageList == null) imageList = parent.imageList = new ImageList();
     int imageIndex = imageList.indexOf(image);
     if (imageIndex == -1) imageIndex = imageList.add(image);
     pixbuf = imageList.getPixbuf(imageIndex);
   }
   int modelIndex =
       parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns[index].modelIndex;
   OS.gtk_list_store_set(parent.modelHandle, handle, modelIndex + Table.CELL_PIXBUF, pixbuf, -1);
   /*
    * Bug in GTK.  When using fixed-height-mode,
    * row changes do not cause the row to be repainted.  The fix is to
    * invalidate the row when it is cleared.
    */
   if ((parent.style & SWT.VIRTUAL) != 0) {
     if (OS.GTK_VERSION >= OS.VERSION(2, 3, 2) && OS.GTK_VERSION < OS.VERSION(2, 6, 3)) {
       redraw();
     }
   }
   /*
    * Bug in GTK.  When in fixed height mode, GTK does not recalculate the cell renderer width
    * when the image is changed in the model.  The fix is to force it to recalculate the width if
    * more space is required.
    */
   if ((parent.style & SWT.VIRTUAL) != 0 && parent.currentItem == null) {
     if (OS.GTK_VERSION >= OS.VERSION(2, 3, 2)) {
       if (image != null) {
         int /*long*/ parentHandle = parent.handle;
         int /*long*/ column = OS.gtk_tree_view_get_column(parentHandle, index);
         int[] w = new int[1];
         int /*long*/ pixbufRenderer = parent.getPixbufRenderer(column);
         OS.gtk_tree_view_column_cell_get_position(column, pixbufRenderer, null, w);
         if (w[0] < image.getBounds().width) {
           /*
            * There is no direct way to clear the cell renderer width so we
            * are relying on the fact that it is done as part of modifying
            * the style.
            */
           int /*long*/ style = OS.gtk_widget_get_modifier_style(parentHandle);
           parent.modifyStyle(parentHandle, style);
         }
       }
     }
   }
   cached = true;
 }
Exemple #3
0
 Image _getImage(int index) {
   int count = Math.max(1, parent.getColumnCount());
   if (0 > index || index > count - 1) return null;
   int /*long*/[] ptr = new int /*long*/[1];
   int modelIndex =
       parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns[index].modelIndex;
   OS.gtk_tree_model_get(parent.modelHandle, handle, modelIndex + Table.CELL_PIXBUF, ptr, -1);
   if (ptr[0] == 0) return null;
   ImageList imageList = parent.imageList;
   int imageIndex = imageList.indexOf(ptr[0]);
   if (imageIndex == -1) return null;
   return imageList.get(imageIndex);
 }
Exemple #4
0
 long /*int*/ gtk_enter_notify_event(long /*int*/ widget, long /*int*/ event) {
   parent.gtk_enter_notify_event(widget, event);
   drawHotImage = (parent.style & SWT.FLAT) != 0 && hotImage != null;
   if (drawHotImage) {
     ImageList imageList = parent.imageList;
     if (imageList != null) {
       int index = imageList.indexOf(hotImage);
       if (index != -1 && imageHandle != 0) {
         long /*int*/ pixbuf = imageList.getPixbuf(index);
         OS.gtk_image_set_from_pixbuf(imageHandle, pixbuf);
       }
     }
   }
   return 0;
 }
Exemple #5
0
 /**
  * Sets the receiver's hot image to the argument, which may be null indicating that no hot image
  * should be displayed.
  *
  * <p>The hot image is displayed when the mouse enters the receiver.
  *
  * @param image the hot image to display on the receiver (may be null)
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_INVALID_ARGUMENT - if the image 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 setHotImage(Image image) {
   checkWidget();
   if ((style & SWT.SEPARATOR) != 0) return;
   hotImage = image;
   if (image != null) {
     ImageList imageList = parent.imageList;
     if (imageList == null) imageList = parent.imageList = new ImageList();
     int imageIndex = imageList.indexOf(image);
     if (imageIndex == -1) {
       imageIndex = imageList.add(image);
     } else {
       imageList.put(imageIndex, image);
     }
   }
 }
 void releaseWidget() {
   super.releaseWidget();
   if (imageList != null) imageList.dispose();
   if (parent.lastFocus == this) parent.lastFocus = null;
   imageList = null;
   control = null;
 }
Exemple #7
0
 long /*int*/ gtk_leave_notify_event(long /*int*/ widget, long /*int*/ event) {
   parent.gtk_leave_notify_event(widget, event);
   if (drawHotImage) {
     drawHotImage = false;
     if (image != null) {
       ImageList imageList = parent.imageList;
       if (imageList != null) {
         int index = imageList.indexOf(image);
         if (index != -1 && imageHandle != 0) {
           long /*int*/ pixbuf = imageList.getPixbuf(index);
           OS.gtk_image_set_from_pixbuf(imageHandle, pixbuf);
         }
       }
     }
   }
   return 0;
 }
 public void setImage(Image image) {
   super.setImage(image);
   if (imageList != null) imageList.dispose();
   imageList = null;
   if (image != null) {
     if (image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
     imageList = new ImageList();
     int imageIndex = imageList.add(image);
     long /*int*/ pixbuf = imageList.getPixbuf(imageIndex);
     OS.gtk_image_set_from_pixbuf(imageHandle, pixbuf);
     if (text.length() == 0) OS.gtk_widget_hide(labelHandle);
     OS.gtk_widget_show(imageHandle);
   } else {
     OS.gtk_image_set_from_pixbuf(imageHandle, 0);
     OS.gtk_widget_show(labelHandle);
     OS.gtk_widget_hide(imageHandle);
   }
 }
 void releaseImages() {
   TBBUTTONINFO info = new TBBUTTONINFO();
   info.cbSize = TBBUTTONINFO.sizeof;
   info.dwMask = OS.TBIF_IMAGE | OS.TBIF_STYLE;
   long /*int*/ hwnd = parent.handle;
   OS.SendMessage(hwnd, OS.TB_GETBUTTONINFO, id, info);
   /*
    * Feature in Windows.  For some reason, a tool item that has
    * the style BTNS_SEP does not return I_IMAGENONE when queried
    * for an image index, despite the fact that no attempt has been
    * made to assign an image to the item.  As a result, operations
    * on an image list that use the wrong index cause random results.
    * The fix is to ensure that the tool item is not a separator
    * before using the image index.  Since separators cannot have
    * an image and one is never assigned, this is not a problem.
    */
   if ((info.fsStyle & OS.BTNS_SEP) == 0 && info.iImage != OS.I_IMAGENONE) {
     ImageList imageList = parent.getImageList();
     ImageList hotImageList = parent.getHotImageList();
     ImageList disabledImageList = parent.getDisabledImageList();
     if (imageList != null) imageList.put(info.iImage, null);
     if (hotImageList != null) hotImageList.put(info.iImage, null);
     if (disabledImageList != null) disabledImageList.put(info.iImage, null);
   }
 }
  /**
   * 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();
  }
 void releaseWidget() {
   super.releaseWidget();
   if (imageList != null) imageList.dispose();
   imageList = null;
 }
Exemple #12
0
  long /*int*/ gtk_create_menu_proxy(long /*int*/ widget) {
    /*
     * Feature in GTK. If the item is a radio/check button
     * with only image, then that image does not appear in
     * the overflow menu.
     * The fix is to create and use the proxy menu for the
     * items appearing in the overflow menu.
     */
    byte[] buffer = Converter.wcsToMbcs(null, "menu-id", true); // $NON-NLS-1$
    if (proxyMenuItem != 0) {
      /*
       * The menuItem to appear in the overflow menu is cached
       * for the tool-item. If the text/image of the item changes,
       * then the proxyMenu is reset.
       */
      OS.gtk_tool_item_set_proxy_menu_item(widget, buffer, proxyMenuItem);
      return 1;
    }

    if (image != null) {
      ImageList imageList = parent.imageList;
      if (imageList != null) {
        int index = imageList.indexOf(image);
        if (index != -1) {
          long /*int*/ pixbuf = imageList.getPixbuf(index);
          byte[] label = null;
          int[] showImages = new int[] {1};
          long /*int*/ settings = OS.gtk_settings_get_default();
          if (settings != 0) {
            long /*int*/ property =
                OS.g_object_class_find_property(
                    OS.G_OBJECT_GET_CLASS(settings), OS.gtk_menu_images);
            if (property != 0) OS.g_object_get(settings, OS.gtk_menu_images, showImages, 0);
          }

          /*
           * GTK tool items with only image appear as blank items
           * in overflow menu when the system property "gtk-menu-images"
           * is set to false. To avoid that, display the tooltip text
           * if available, in the overflow menu.
           * Feature in GTK. When the menuItem is initialised only
           * with the image, the overflow menu appears very sloppy.
           * The fix is to initialise menu item with empty string.
           */
          if (text == null || text.length() == 0) {
            if ((showImages[0] == 0) && (toolTipText != null))
              label = Converter.wcsToMbcs(null, toolTipText, true);
            else label = new byte[] {0};
          } else {
            label = Converter.wcsToMbcs(null, text, true);
          }
          long /*int*/ menuItem = OS.gtk_image_menu_item_new_with_label(label);
          long /*int*/ menuImage = OS.gtk_image_new_from_pixbuf(pixbuf);
          OS.gtk_image_menu_item_set_image(menuItem, menuImage);
          OS.gtk_tool_item_set_proxy_menu_item(widget, buffer, menuItem);
          /*
           * Since the arrow button does not appear in the drop_down
           * item, we request the menu-item and then, hook the
           * activate signal to send the Arrow selection signal.
           */
          proxyMenuItem = OS.gtk_tool_item_get_proxy_menu_item(widget, buffer);
          OS.g_signal_connect(
              menuItem, OS.activate, ToolBar.menuItemSelectedFunc.getAddress(), handle);
          return 1;
        }
      }
    }
    return 0;
  }
Exemple #13
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();
  }
  private void drag(Event dragEvent) {
    DNDEvent event = new DNDEvent();
    event.widget = this;
    event.x = dragEvent.x;
    event.y = dragEvent.y;
    event.time = OS.GetMessageTime();
    event.doit = true;
    notifyListeners(DND.DragStart, event);
    if (!event.doit || transferAgents == null || transferAgents.length == 0) return;

    int[] pdwEffect = new int[1];
    int operations = opToOs(getStyle());
    Display display = control.getDisplay();
    String key = "org.eclipse.swt.internal.win32.runMessagesInIdle"; // $NON-NLS-1$
    Object oldValue = display.getData(key);
    display.setData(key, Boolean.TRUE);
    ImageList imagelist = null;
    Image image = event.image;
    hwndDrag = 0;
    topControl = null;
    if (image != null) {
      imagelist = new ImageList(SWT.NONE);
      imagelist.add(image);
      topControl = control.getShell();
      /*
       * Bug in Windows. The image is inverted if the shell is RIGHT_TO_LEFT.
       * The fix is to create a transparent window that covers the shell client
       * area and use it during the drag to prevent the image from being inverted.
       * On XP if the shell is RTL, the image is not displayed.
       */
      int offsetX = event.offsetX;
      hwndDrag = topControl.handle;
      if ((topControl.getStyle() & SWT.RIGHT_TO_LEFT) != 0) {
        offsetX = image.getBounds().width - offsetX;
        RECT rect = new RECT();
        OS.GetClientRect(topControl.handle, rect);
        hwndDrag =
            OS.CreateWindowEx(
                OS.WS_EX_TRANSPARENT | OS.WS_EX_NOINHERITLAYOUT,
                WindowClass,
                null,
                OS.WS_CHILD | OS.WS_CLIPSIBLINGS,
                0,
                0,
                rect.right - rect.left,
                rect.bottom - rect.top,
                topControl.handle,
                0,
                OS.GetModuleHandle(null),
                null);
        OS.ShowWindow(hwndDrag, OS.SW_SHOW);
      }
      OS.ImageList_BeginDrag(imagelist.getHandle(), 0, offsetX, event.offsetY);
      /*
       * Feature in Windows. When ImageList_DragEnter() is called,
       * it takes a snapshot of the screen  If a drag is started
       * when another window is in front, then the snapshot will
       * contain part of the other window, causing pixel corruption.
       * The fix is to force all paints to be delivered before
       * calling ImageList_DragEnter().
       */
      if (OS.IsWinCE) {
        OS.UpdateWindow(topControl.handle);
      } else {
        int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN;
        OS.RedrawWindow(topControl.handle, null, 0, flags);
      }
      POINT pt = new POINT();
      pt.x = dragEvent.x;
      pt.y = dragEvent.y;
      OS.MapWindowPoints(control.handle, 0, pt, 1);
      RECT rect = new RECT();
      OS.GetWindowRect(hwndDrag, rect);
      OS.ImageList_DragEnter(hwndDrag, pt.x - rect.left, pt.y - rect.top);
    }
    int result = COM.DRAGDROP_S_CANCEL;
    try {
      result =
          COM.DoDragDrop(iDataObject.getAddress(), iDropSource.getAddress(), operations, pdwEffect);
    } finally {
      // ensure that we don't leave transparent window around
      if (hwndDrag != 0) {
        OS.ImageList_DragLeave(hwndDrag);
        OS.ImageList_EndDrag();
        imagelist.dispose();
        if (hwndDrag != topControl.handle) OS.DestroyWindow(hwndDrag);
        hwndDrag = 0;
        topControl = null;
      }
      display.setData(key, oldValue);
    }
    int operation = osToOp(pdwEffect[0]);
    if (dataEffect == DND.DROP_MOVE) {
      operation =
          (operation == DND.DROP_NONE || operation == DND.DROP_COPY)
              ? DND.DROP_TARGET_MOVE
              : DND.DROP_MOVE;
    } else {
      if (dataEffect != DND.DROP_NONE) {
        operation = dataEffect;
      }
    }
    event = new DNDEvent();
    event.widget = this;
    event.time = OS.GetMessageTime();
    event.doit = (result == COM.DRAGDROP_S_DROP);
    event.detail = operation;
    notifyListeners(DND.DragEnd, event);
    dataEffect = DND.DROP_NONE;
  }