Exemplo n.º 1
0
 /**
  * Sets the width of the receiver, for <code>SEPARATOR</code> ToolItems.
  *
  * @param width the new width. If the new value is <code>SWT.DEFAULT</code>, the width is a
  *     fixed-width area whose amount is determined by the platform. If the new value is 0 a
  *     vertical or horizontal line will be drawn, depending on the setting of the corresponding
  *     style bit (<code>SWT.VERTICAL</code> or <code>SWT.HORIZONTAL</code>). If the new value is
  *     <code>SWT.SEPARATOR_FILL</code> a variable-width space is inserted that acts as a spring
  *     between the two adjoining items which will push them out to the extent of the containing
  *     ToolBar.
  * @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 setWidth(int width) {
   checkWidget();
   if ((style & SWT.SEPARATOR) == 0) return;
   if (width < 0) return;
   long /*int*/ hwnd = parent.handle;
   TBBUTTONINFO info = new TBBUTTONINFO();
   info.cbSize = TBBUTTONINFO.sizeof;
   info.dwMask = OS.TBIF_SIZE;
   info.cx = cx = (short) width;
   OS.SendMessage(hwnd, OS.TB_SETBUTTONINFO, id, info);
   parent.layoutItems();
 }
Exemplo n.º 2
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();
  }