Пример #1
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 (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
   if ((style & SWT.SEPARATOR) != 0) return;
   hotImage = image;
   if ((parent.style & SWT.FLAT) != 0) redraw();
 }
Пример #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());
 }
Пример #3
0
 /**
  * Sets the receiver's disabled image to the argument, which may be null indicating that no
  * disabled image should be displayed.
  *
  * <p>The disabled image is displayed when the receiver is disabled.
  *
  * @param image the disabled 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 setDisabledImage(Image image) {
   checkWidget();
   if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
   if ((style & SWT.SEPARATOR) != 0) return;
   disabledImage = image;
   if (!getEnabled()) redraw();
 }
Пример #4
0
 public void setImage(Image image) {
   checkWidget();
   if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
   if ((style & SWT.SEPARATOR) != 0) return;
   super.setImage(image);
   parent.relayout();
   redraw();
 }
Пример #5
0
 void releaseWidget() {
   super.releaseWidget();
   releaseImages();
   control = null;
   toolTipText = null;
   disabledImage = hotImage = null;
   if (disabledImage2 != null) disabledImage2.dispose();
   disabledImage2 = null;
 }
Пример #6
0
  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new GridLayout(2, false));

    final Text text = new Text(shell, SWT.SEARCH | SWT.ICON_CANCEL);
    Image image = null;
    if ((text.getStyle() & SWT.ICON_CANCEL) == 0) {
      image = display.getSystemImage(SWT.ICON_ERROR);
      ToolBar toolBar = new ToolBar(shell, SWT.FLAT);
      ToolItem item = new ToolItem(toolBar, SWT.PUSH);
      item.setImage(image);
      item.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              text.setText("");
              System.out.println("Search cancelled");
            }
          });
    }
    text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    text.setText("Search text");
    text.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetDefaultSelected(SelectionEvent e) {
            if (e.detail == SWT.CANCEL) {
              System.out.println("Search cancelled");
            } else {
              System.out.println("Searching for: " + text.getText() + "...");
            }
          }
        });

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    if (image != null) image.dispose();
    display.dispose();
  }
Пример #7
0
 public void setImage(Image image) {
   checkWidget();
   if (image != null && image.isDisposed()) {
     error(SWT.ERROR_INVALID_ARGUMENT);
   }
   super.setImage(image);
   NSTableHeaderView headerView = ((NSOutlineView) parent.view).headerView();
   if (headerView == null) return;
   int index = parent.indexOf(nsColumn);
   NSRect rect = headerView.headerRectOfColumn(index);
   headerView.setNeedsDisplayInRect(rect);
 }
Пример #8
0
 LRESULT wmDrawChild(long /*int*/ wParam, long /*int*/ lParam) {
   DRAWITEMSTRUCT struct = new DRAWITEMSTRUCT();
   OS.MoveMemory(struct, lParam, DRAWITEMSTRUCT.sizeof);
   if (image != null) {
     GCData data = new GCData();
     data.device = display;
     GC gc = GC.win32_new(struct.hDC, data);
     /*
      * Bug in Windows.  When a bitmap is included in the
      * menu bar, the HDC seems to already include the left
      * coordinate.  The fix is to ignore this value when
      * the item is in a menu bar.
      */
     int x = (parent.style & SWT.BAR) != 0 ? MARGIN_WIDTH * 2 : struct.left;
     Image image = getEnabled() ? this.image : new Image(display, this.image, SWT.IMAGE_DISABLE);
     gc.drawImage(image, x, struct.top + MARGIN_HEIGHT);
     if (this.image != image) image.dispose();
     gc.dispose();
   }
   if (parent.foreground != -1) OS.SetTextColor(struct.hDC, parent.foreground);
   return null;
 }
Пример #9
0
 /**
  * Sets the receiver's image to the argument, which may be <code>null</code> indicating that no
  * image should be displayed.
  *
  * <p>Note that a Button can display an image and text simultaneously on Windows (starting with
  * XP), GTK+ and OSX. On other platforms, a Button that has an image and text set into it will
  * display the image or text that was set most recently.
  *
  * @param image the image to display on the receiver (may be <code>null</code>)
  * @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(Image image) {
   checkWidget();
   if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
   if ((style & SWT.ARROW) != 0) return;
   this.image = image;
   OS.Image_Source(imageHandle, image != null ? image.handle : 0);
   OS.UIElement_Visibility(
       imageHandle, image != null ? OS.Visibility_Visible : OS.Visibility_Collapsed);
   OS.UIElement_Visibility(
       textHandle,
       image != null && text.length() == 0 ? OS.Visibility_Collapsed : OS.Visibility_Visible);
   int spacing = image != null && text.length() != 0 ? 3 : 0;
   int margin = OS.gcnew_Thickness(0, 0, spacing, 0);
   if (margin == 0) error(SWT.ERROR_NO_HANDLES);
   OS.FrameworkElement_Margin(imageHandle, margin);
   OS.GCHandle_Free(margin);
 }
Пример #10
0
  /** Compute the minimum size. */
  private Point getTotalSize(Image image, String text) {
    Point size = new Point(0, 0);

    if (image != null) {
      Rectangle r = image.getBounds();
      size.x += r.width;
      size.y += r.height;
    }

    GC gc = new GC(this);
    if (text != null && text.length() > 0) {
      Point e = gc.textExtent(text, DRAW_FLAGS);
      size.x += e.x;
      size.y = Math.max(size.y, e.y);
      if (image != null) size.x += GAP;
    } else {
      size.y = Math.max(size.y, gc.getFontMetrics().getHeight());
    }
    gc.dispose();

    return size;
  }
Пример #11
0
  int XmNexposureCallback(int w, int client_data, int call_data) {
    if ((style & SWT.SEPARATOR) != 0) return 0;
    int xDisplay = OS.XtDisplay(handle);
    if (xDisplay == 0) return 0;
    int xWindow = OS.XtWindow(handle);
    if (xWindow == 0) return 0;
    int[] argList = {
      OS.XmNcolormap, 0,
      OS.XmNwidth, 0,
      OS.XmNheight, 0,
    };
    OS.XtGetValues(handle, argList, argList.length / 2);
    int width = argList[3], height = argList[5];

    Image currentImage = image;
    boolean enabled = getEnabled();

    if ((parent.style & SWT.FLAT) != 0) {
      boolean hasCursor = hasCursor();

      /* Set the shadow thickness */
      int thickness = 0;
      if (set || (hasCursor && enabled)) {
        thickness = Math.min(2, display.buttonShadowThickness);
      }
      argList = new int[] {OS.XmNshadowThickness, thickness};
      OS.XtSetValues(handle, argList, argList.length / 2);

      /* Determine if hot image should be used */
      if (enabled && hasCursor && hotImage != null) {
        currentImage = hotImage;
      }
    }

    GCData data = new GCData();
    data.device = display;
    data.display = xDisplay;
    data.drawable = xWindow;
    data.font = parent.font;
    data.colormap = argList[1];
    int xGC = OS.XCreateGC(xDisplay, xWindow, 0, null);
    if (xGC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
    GC gc = GC.motif_new(xGC, data);

    XmAnyCallbackStruct cb = new XmAnyCallbackStruct();
    OS.memmove(cb, call_data, XmAnyCallbackStruct.sizeof);
    if (cb.event != 0) {
      XExposeEvent xEvent = new XExposeEvent();
      OS.memmove(xEvent, cb.event, XExposeEvent.sizeof);
      Rectangle rect = new Rectangle(xEvent.x, xEvent.y, xEvent.width, xEvent.height);
      gc.setClipping(rect);
    }

    if (!enabled) {
      currentImage = disabledImage;
      if (currentImage == null && image != null) {
        currentImage = new Image(display, image, SWT.IMAGE_DISABLE);
      }
      Color disabledColor = display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
      gc.setForeground(disabledColor);
    } else {
      gc.setForeground(parent.getForeground());
    }
    gc.setBackground(parent.getBackground());

    int textX = 0, textY = 0, textWidth = 0, textHeight = 0;
    if (text.length() != 0) {
      int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC;
      Point textExtent = gc.textExtent(text, flags);
      textWidth = textExtent.x;
      textHeight = textExtent.y;
    }
    int imageX = 0, imageY = 0, imageWidth = 0, imageHeight = 0;
    if (currentImage != null) {
      Rectangle imageBounds = currentImage.getBounds();
      imageWidth = imageBounds.width;
      imageHeight = imageBounds.height;
    }

    int spacing = 0;
    if (textWidth != 0 && imageWidth != 0) spacing = 2;
    if ((parent.style & SWT.RIGHT) != 0) {
      imageX = (width - imageWidth - textWidth - spacing) / 2;
      imageY = (height - imageHeight) / 2;
      textX = spacing + imageX + imageWidth;
      textY = (height - textHeight) / 2;
    } else {
      imageX = (width - imageWidth) / 2;
      imageY = (height - imageHeight - textHeight - spacing) / 2;
      textX = (width - textWidth) / 2;
      textY = spacing + imageY + imageHeight;
    }

    if ((style & SWT.DROP_DOWN) != 0) {
      textX -= 6;
      imageX -= 6;
    }
    if (textWidth > 0) {
      int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC | SWT.DRAW_TRANSPARENT;
      gc.drawText(text, textX, textY, flags);
    }
    if (imageWidth > 0) gc.drawImage(currentImage, imageX, imageY);
    if ((style & SWT.DROP_DOWN) != 0) {
      int startX = width - 12, startY = (height - 2) / 2;
      int[] arrow = {startX, startY, startX + 3, startY + 3, startX + 6, startY};
      gc.setBackground(parent.getForeground());
      gc.fillPolygon(arrow);
      gc.drawPolygon(arrow);
    }
    gc.dispose();
    OS.XFreeGC(xDisplay, xGC);

    if (!enabled && disabledImage == null) {
      if (currentImage != null) currentImage.dispose();
    }
    return 0;
  }
Пример #12
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();
  }
Пример #13
0
 void paint(Event event) {
   if (row == null) return;
   int columnIndex = column == null ? 0 : table.indexOf(column);
   GC gc = event.gc;
   gc.setBackground(getBackground());
   gc.setForeground(getForeground());
   gc.fillRectangle(event.x, event.y, event.width, event.height);
   int x = 0;
   Point size = getSize();
   Image image = row.getImage(columnIndex);
   if (image != null) {
     Rectangle imageSize = image.getBounds();
     int imageY = (size.y - imageSize.height) / 2;
     gc.drawImage(image, x, imageY);
     x += imageSize.width;
   }
   String text = row.getText(columnIndex);
   if (text.length() > 0) {
     Rectangle bounds = row.getBounds(columnIndex);
     Point extent = gc.stringExtent(text);
     // Temporary code - need a better way to determine table trim
     String platform = SWT.getPlatform();
     if ("win32".equals(platform)) { // $NON-NLS-1$
       if (table.getColumnCount() == 0 || columnIndex == 0) {
         x += 2;
       } else {
         int alignmnent = column.getAlignment();
         switch (alignmnent) {
           case SWT.LEFT:
             x += 6;
             break;
           case SWT.RIGHT:
             x = bounds.width - extent.x - 6;
             break;
           case SWT.CENTER:
             x += (bounds.width - x - extent.x) / 2;
             break;
         }
       }
     } else {
       if (table.getColumnCount() == 0) {
         x += 5;
       } else {
         int alignmnent = column.getAlignment();
         switch (alignmnent) {
           case SWT.LEFT:
             x += 5;
             break;
           case SWT.RIGHT:
             x = bounds.width - extent.x - 2;
             break;
           case SWT.CENTER:
             x += (bounds.width - x - extent.x) / 2 + 2;
             break;
         }
       }
     }
     int textY = (size.y - extent.y) / 2;
     gc.drawString(text, x, textY);
   }
   if (isFocusControl()) {
     Display display = getDisplay();
     gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
     gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
     gc.drawFocus(0, 0, size.x, size.y);
   }
 }
Пример #14
0
  void onPaint(PaintEvent event) {
    Rectangle rect = getClientArea();
    if (rect.width == 0 || rect.height == 0) return;

    boolean shortenText = false;
    String t = text;
    Image img = image;
    int availableWidth = Math.max(0, rect.width - (leftMargin + rightMargin));
    Point extent = getTotalSize(img, t);
    if (extent.x > availableWidth) {
      img = null;
      extent = getTotalSize(img, t);
      if (extent.x > availableWidth) {
        shortenText = true;
      }
    }

    GC gc = event.gc;
    String[] lines = text == null ? null : splitString(text);

    // shorten the text
    if (shortenText) {
      extent.x = 0;
      for (int i = 0; i < lines.length; i++) {
        Point e = gc.textExtent(lines[i], DRAW_FLAGS);
        if (e.x > availableWidth) {
          lines[i] = shortenText(gc, lines[i], availableWidth);
          extent.x = Math.max(extent.x, getTotalSize(null, lines[i]).x);
        } else {
          extent.x = Math.max(extent.x, e.x);
        }
      }
      if (appToolTipText == null) {
        super.setToolTipText(text);
      }
    } else {
      super.setToolTipText(appToolTipText);
    }

    // determine horizontal position
    int x = rect.x + leftMargin;
    if (align == SWT.CENTER) {
      x = (rect.width - extent.x) / 2;
    }
    if (align == SWT.RIGHT) {
      x = rect.width - rightMargin - extent.x;
    }

    // draw a background image behind the text
    try {
      if (backgroundImage != null) {
        // draw a background image behind the text
        Rectangle imageRect = backgroundImage.getBounds();
        // tile image to fill space
        gc.setBackground(getBackground());
        gc.fillRectangle(rect);
        int xPos = 0;
        while (xPos < rect.width) {
          int yPos = 0;
          while (yPos < rect.height) {
            gc.drawImage(backgroundImage, xPos, yPos);
            yPos += imageRect.height;
          }
          xPos += imageRect.width;
        }
      } else if (gradientColors != null) {
        // draw a gradient behind the text
        final Color oldBackground = gc.getBackground();
        if (gradientColors.length == 1) {
          if (gradientColors[0] != null) gc.setBackground(gradientColors[0]);
          gc.fillRectangle(0, 0, rect.width, rect.height);
        } else {
          final Color oldForeground = gc.getForeground();
          Color lastColor = gradientColors[0];
          if (lastColor == null) lastColor = oldBackground;
          int pos = 0;
          for (int i = 0; i < gradientPercents.length; ++i) {
            gc.setForeground(lastColor);
            lastColor = gradientColors[i + 1];
            if (lastColor == null) lastColor = oldBackground;
            gc.setBackground(lastColor);
            if (gradientVertical) {
              final int gradientHeight = (gradientPercents[i] * rect.height / 100) - pos;
              gc.fillGradientRectangle(0, pos, rect.width, gradientHeight, true);
              pos += gradientHeight;
            } else {
              final int gradientWidth = (gradientPercents[i] * rect.width / 100) - pos;
              gc.fillGradientRectangle(pos, 0, gradientWidth, rect.height, false);
              pos += gradientWidth;
            }
          }
          if (gradientVertical && pos < rect.height) {
            gc.setBackground(getBackground());
            gc.fillRectangle(0, pos, rect.width, rect.height - pos);
          }
          if (!gradientVertical && pos < rect.width) {
            gc.setBackground(getBackground());
            gc.fillRectangle(pos, 0, rect.width - pos, rect.height);
          }
          gc.setForeground(oldForeground);
        }
        gc.setBackground(oldBackground);
      } else {
        if (background != null || (getStyle() & SWT.DOUBLE_BUFFERED) == 0) {
          gc.setBackground(getBackground());
          gc.fillRectangle(rect);
        }
      }
    } catch (SWTException e) {
      if ((getStyle() & SWT.DOUBLE_BUFFERED) == 0) {
        gc.setBackground(getBackground());
        gc.fillRectangle(rect);
      }
    }

    // draw border
    int style = getStyle();
    if ((style & SWT.SHADOW_IN) != 0 || (style & SWT.SHADOW_OUT) != 0) {
      paintBorder(gc, rect);
    }

    /*
     * Compute text height and image height. If image height is more than
     * the text height, draw image starting from top margin. Else draw text
     * starting from top margin.
     */
    Rectangle imageRect = null;
    int lineHeight = 0, textHeight = 0, imageHeight = 0;

    if (img != null) {
      imageRect = img.getBounds();
      imageHeight = imageRect.height;
    }
    if (lines != null) {
      lineHeight = gc.getFontMetrics().getHeight();
      textHeight = lines.length * lineHeight;
    }

    int imageY = 0, midPoint = 0, lineY = 0;
    if (imageHeight > textHeight) {
      if (topMargin == DEFAULT_MARGIN && bottomMargin == DEFAULT_MARGIN)
        imageY = rect.y + (rect.height - imageHeight) / 2;
      else imageY = topMargin;
      midPoint = imageY + imageHeight / 2;
      lineY = midPoint - textHeight / 2;
    } else {
      if (topMargin == DEFAULT_MARGIN && bottomMargin == DEFAULT_MARGIN)
        lineY = rect.y + (rect.height - textHeight) / 2;
      else lineY = topMargin;
      midPoint = lineY + textHeight / 2;
      imageY = midPoint - imageHeight / 2;
    }

    // draw the image
    if (img != null) {
      gc.drawImage(
          img, 0, 0, imageRect.width, imageHeight, x, imageY, imageRect.width, imageHeight);
      x += imageRect.width + GAP;
      extent.x -= imageRect.width + GAP;
    }

    // draw the text
    if (lines != null) {
      gc.setForeground(getForeground());
      for (int i = 0; i < lines.length; i++) {
        int lineX = x;
        if (lines.length > 1) {
          if (align == SWT.CENTER) {
            int lineWidth = gc.textExtent(lines[i], DRAW_FLAGS).x;
            lineX = x + Math.max(0, (extent.x - lineWidth) / 2);
          }
          if (align == SWT.RIGHT) {
            int lineWidth = gc.textExtent(lines[i], DRAW_FLAGS).x;
            lineX = Math.max(x, rect.x + rect.width - rightMargin - lineWidth);
          }
        }
        gc.drawText(lines[i], lineX, lineY, DRAW_FLAGS);
        lineY += lineHeight;
      }
    }
  }