Esempio n. 1
0
 void drawWidget(GC gc, RECT rect) {
   drawBackground(gc.handle, rect);
   int selStart = selection.x;
   int selEnd = selection.y;
   if (selStart > selEnd) {
     selStart = selection.y;
     selEnd = selection.x;
   }
   // temporary code to disable text selection
   selStart = selEnd = -1;
   if (!OS.IsWindowEnabled(handle)) gc.setForeground(disabledColor);
   layout.draw(gc, 0, 0, selStart, selEnd, null, null);
   if (hasFocus() && focusIndex != -1) {
     Rectangle[] rects = getRectangles(focusIndex);
     for (int i = 0; i < rects.length; i++) {
       Rectangle rectangle = rects[i];
       gc.drawFocus(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
     }
   }
   if (hooks(SWT.Paint) || filters(SWT.Paint)) {
     Event event = new Event();
     event.gc = gc;
     event.x = rect.left;
     event.y = rect.top;
     event.width = rect.right - rect.left;
     event.height = rect.bottom - rect.top;
     sendEvent(SWT.Paint, event);
     event.gc = null;
   }
 }
Esempio n. 2
0
 /**
  * Shorten the given text <code>t</code> so that its length doesn't exceed the given width. The
  * default implementation replaces characters in the center of the original string with an
  * ellipsis ("..."). Override if you need a different strategy.
  *
  * @param gc the gc to use for text measurement
  * @param t the text to shorten
  * @param width the width to shorten the text to, in pixels
  * @return the shortened text
  */
 protected String shortenText(GC gc, String t, int width) {
   if (t == null) return null;
   int w = gc.textExtent(ELLIPSIS, DRAW_FLAGS).x;
   if (width <= w) return t;
   int l = t.length();
   int max = l / 2;
   int min = 0;
   int mid = (max + min) / 2 - 1;
   if (mid <= 0) return t;
   TextLayout layout = new TextLayout(getDisplay());
   layout.setText(t);
   mid = validateOffset(layout, mid);
   while (min < mid && mid < max) {
     String s1 = t.substring(0, mid);
     String s2 = t.substring(validateOffset(layout, l - mid), l);
     int l1 = gc.textExtent(s1, DRAW_FLAGS).x;
     int l2 = gc.textExtent(s2, DRAW_FLAGS).x;
     if (l1 + w + l2 > width) {
       max = mid;
       mid = validateOffset(layout, (max + min) / 2);
     } else if (l1 + w + l2 < width) {
       min = mid;
       mid = validateOffset(layout, (max + min) / 2);
     } else {
       min = max;
     }
   }
   String result =
       mid == 0
           ? t
           : t.substring(0, mid) + ELLIPSIS + t.substring(validateOffset(layout, l - mid), l);
   layout.dispose();
   return result;
 }
 public void mouseMove(MouseEvent e) {
   if ((e.stateMask & SWT.BUTTON1) == 0) return;
   GC gc = new GC((Canvas) e.widget);
   gc.drawLine(p.x, p.y, e.x, e.y);
   gc.dispose();
   updatePoint(e);
 }
Esempio n. 4
0
  private void drawBevelRect(GC gc, int x, int y, int w, int h, Color topleft, Color bottomright) {
    gc.setForeground(topleft);
    gc.drawLine(x, y, x + w - 1, y);
    gc.drawLine(x, y, x, y + h - 1);

    gc.setForeground(bottomright);
    gc.drawLine(x + w, y, x + w, y + h);
    gc.drawLine(x, y + h, x + w, y + h);
  }
Esempio n. 5
0
 LRESULT WM_PRINTCLIENT(int /*long*/ wParam, int /*long*/ lParam) {
   LRESULT result = super.WM_PRINTCLIENT(wParam, lParam);
   if (OS.COMCTL32_MAJOR < 6) {
     RECT rect = new RECT();
     OS.GetClientRect(handle, rect);
     GCData data = new GCData();
     data.device = display;
     data.foreground = getForegroundPixel();
     GC gc = GC.win32_new(wParam, data);
     drawWidget(gc, rect);
     gc.dispose();
   }
   return result;
 }
Esempio n. 6
0
 /** Sets or clears the caret in the "Example" widget. */
 void setCaret() {
   Caret oldCaret = canvas.getCaret();
   if (caretButton.getSelection()) {
     Caret newCaret = new Caret(canvas, SWT.NONE);
     Font font = canvas.getFont();
     newCaret.setFont(font);
     GC gc = new GC(canvas);
     gc.setFont(font);
     newCaret.setBounds(1, 1, 1, gc.getFontMetrics().getHeight());
     gc.dispose();
     canvas.setCaret(newCaret);
     canvas.setFocus();
   } else {
     canvas.setCaret(null);
   }
   if (oldCaret != null) oldCaret.dispose();
 }
Esempio n. 7
0
  void paint(PaintEvent event) {
    GC gc = event.gc;
    Display disp = getDisplay();

    Rectangle rect = getClientArea();
    gc.fillRectangle(rect);
    if (showBorder) {
      drawBevelRect(
          gc,
          rect.x,
          rect.y,
          rect.width - 1,
          rect.height - 1,
          disp.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW),
          disp.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
    }

    paintStripes(gc);
  }
Esempio n. 8
0
 int getPreferredWidth(GC gc) {
   int width = ExpandItem.TEXT_INSET * 2 + ExpandItem.CHEVRON_SIZE;
   if (image != null) {
     width += ExpandItem.TEXT_INSET + imageWidth;
   }
   if (text.length() > 0) {
     width += gc.stringExtent(text).x;
   }
   return width;
 }
  public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Widget");

    final Table table = new Table(shell, SWT.MULTI);
    table.setLinesVisible(true);
    table.setBounds(10, 10, 100, 100);
    for (int i = 0; i < 9; i++) {
      new TableItem(table, SWT.NONE).setText("item" + i);
    }

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Capture");
    button.pack();
    button.setLocation(10, 140);
    button.addListener(
        SWT.Selection,
        event -> {
          Point tableSize = table.getSize();
          GC gc = new GC(table);
          final Image image = new Image(display, tableSize.x, tableSize.y);
          gc.copyArea(image, 0, 0);
          gc.dispose();

          Shell popup = new Shell(shell);
          popup.setText("Image");
          popup.addListener(SWT.Close, e -> image.dispose());

          Canvas canvas = new Canvas(popup, SWT.NONE);
          canvas.setBounds(10, 10, tableSize.x + 10, tableSize.y + 10);
          canvas.addPaintListener(e -> e.gc.drawImage(image, 0, 0));
          popup.pack();
          popup.open();
        });
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }
Esempio n. 10
0
 /**
  * Returns <code>true</code> if the specified point is contained by the receiver and false
  * otherwise.
  *
  * <p>If outline is <code>true</code>, the point (x, y) checked for containment in the receiver's
  * outline. If outline is <code>false</code>, the point is checked to see if it is contained
  * within the bounds of the (closed) area covered by the receiver.
  *
  * @param x the x coordinate of the point to test for containment
  * @param y the y coordinate of the point to test for containment
  * @param gc the GC to use when testing for containment
  * @param outline controls whether to check the outline or contained area of the path
  * @return <code>true</code> if the path contains the point and <code>false</code> otherwise
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the gc is null
  *       <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
  *     </ul>
  */
 public boolean contains(float x, float y, GC gc, boolean outline) {
   if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
   if (gc == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   if (gc.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   //	gc.checkGC(GC.LINE_CAP | GC.LINE_JOIN | GC.LINE_STYLE | GC.LINE_WIDTH);
   // TODO outline
   NSPoint point = new NSPoint();
   point.x = x;
   point.y = y;
   return handle.containsPoint(point);
 }
Esempio n. 11
0
 @Override
 void drawWidget(GC gc) {
   int selStart = selection.x;
   int selEnd = selection.y;
   if (selStart > selEnd) {
     selStart = selection.y;
     selEnd = selection.x;
   }
   // temporary code to disable text selection
   selStart = selEnd = -1;
   if ((state & DISABLED) != 0) gc.setForeground(disabledColor);
   layout.draw(gc, 0, 0, selStart, selEnd, null, null);
   if (hasFocus() && focusIndex != -1) {
     Rectangle[] rects = getRectangles(focusIndex);
     for (int i = 0; i < rects.length; i++) {
       Rectangle rect = rects[i];
       gc.drawFocus(rect.x, rect.y, rect.width, rect.height);
     }
   }
 }
Esempio n. 12
0
 LRESULT WM_PAINT(int /*long*/ wParam, int /*long*/ lParam) {
   if (OS.COMCTL32_MAJOR >= 6) {
     return super.WM_PAINT(wParam, lParam);
   }
   PAINTSTRUCT ps = new PAINTSTRUCT();
   GCData data = new GCData();
   data.ps = ps;
   data.hwnd = handle;
   GC gc = new_GC(data);
   if (gc != null) {
     int width = ps.right - ps.left;
     int height = ps.bottom - ps.top;
     if (width != 0 && height != 0) {
       RECT rect = new RECT();
       OS.SetRect(rect, ps.left, ps.top, ps.right, ps.bottom);
       drawWidget(gc, rect);
     }
     gc.dispose();
   }
   return LRESULT.ZERO;
 }
Esempio n. 13
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;
  }
Esempio n. 14
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;
 }
Esempio n. 15
0
 void drawChevron(GC gc, int x, int y) {
   int[] polyline1, polyline2;
   if (expanded) {
     int px = x + 4 + 5;
     int py = y + 4 + 7;
     polyline1 =
         new int[] {
           px, py, px + 1, py, px + 1, py - 1, px + 2, py - 1, px + 2, py - 2, px + 3, py - 2,
           px + 3, py - 3, px + 3, py - 2, px + 4, py - 2, px + 4, py - 1, px + 5, py - 1, px + 5,
           py, px + 6, py
         };
     py += 4;
     polyline2 =
         new int[] {
           px, py, px + 1, py, px + 1, py - 1, px + 2, py - 1, px + 2, py - 2, px + 3, py - 2,
           px + 3, py - 3, px + 3, py - 2, px + 4, py - 2, px + 4, py - 1, px + 5, py - 1, px + 5,
           py, px + 6, py
         };
   } else {
     int px = x + 4 + 5;
     int py = y + 4 + 4;
     polyline1 =
         new int[] {
           px, py, px + 1, py, px + 1, py + 1, px + 2, py + 1, px + 2, py + 2, px + 3, py + 2,
           px + 3, py + 3, px + 3, py + 2, px + 4, py + 2, px + 4, py + 1, px + 5, py + 1, px + 5,
           py, px + 6, py
         };
     py += 4;
     polyline2 =
         new int[] {
           px, py, px + 1, py, px + 1, py + 1, px + 2, py + 1, px + 2, py + 2, px + 3, py + 2,
           px + 3, py + 3, px + 3, py + 2, px + 4, py + 2, px + 4, py + 1, px + 5, py + 1, px + 5,
           py, px + 6, py
         };
   }
   gc.setForeground(display.getSystemColor(SWT.COLOR_TITLE_FOREGROUND));
   gc.drawPolyline(polyline1);
   gc.drawPolyline(polyline2);
 }
Esempio n. 16
0
 public static void main(String[] args) {
   final Display display = new Display();
   final Image image = new Image(display, 16, 16);
   GC gc = new GC(image);
   gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
   gc.fillRectangle(image.getBounds());
   gc.dispose();
   final Shell shell = new Shell(display);
   shell.setText("Lazy Table");
   shell.setLayout(new FillLayout());
   final Table table = new Table(shell, SWT.BORDER | SWT.MULTI);
   table.setSize(200, 200);
   Thread thread =
       new Thread() {
         @Override
         public void run() {
           for (int i = 0; i < 20000; i++) {
             if (table.isDisposed()) return;
             final int[] index = new int[] {i};
             display.syncExec(
                 () -> {
                   if (table.isDisposed()) return;
                   TableItem item = new TableItem(table, SWT.NONE);
                   item.setText("Table Item " + index[0]);
                   item.setImage(image);
                 });
           }
         }
       };
   thread.start();
   shell.setSize(200, 200);
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   image.dispose();
   display.dispose();
 }
 /**
  * Constructs a new Pattern that represents a linear, two color gradient. Drawing with the pattern
  * will cause the resulting area to be tiled with the gradient specified by the arguments.
  *
  * <p>This operation requires the operating system's advanced graphics subsystem which may not be
  * available on some platforms.
  *
  * @param device the device on which to allocate the pattern
  * @param x1 the x coordinate of the starting corner of the gradient
  * @param y1 the y coordinate of the starting corner of the gradient
  * @param x2 the x coordinate of the ending corner of the gradient
  * @param y2 the y coordinate of the ending corner of the gradient
  * @param color1 the starting color of the gradient
  * @param alpha1 the starting alpha value of the gradient
  * @param color2 the ending color of the gradient
  * @param alpha2 the ending alpha value of the gradient
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device, or if
  *           either color1 or color2 is null
  *       <li>ERROR_INVALID_ARGUMENT - if either color1 or color2 has been disposed
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available
  *     </ul>
  *
  * @exception SWTError
  *     <ul>
  *       <li>ERROR_NO_HANDLES if a handle for the pattern could not be obtained
  *     </ul>
  *
  * @see #dispose()
  * @since 3.2
  */
 public Pattern(
     Device device,
     float x1,
     float y1,
     float x2,
     float y2,
     Color color1,
     int alpha1,
     Color color2,
     int alpha2) {
   super(device);
   if (color1 == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   if (color1.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   if (color2 == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   if (color2.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   this.device.checkCairo();
   handle = Cairo.cairo_pattern_create_linear(x1, y1, x2, y2);
   if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
   GC.setCairoPatternColor(handle, 0, color1, alpha1);
   GC.setCairoPatternColor(handle, 1, color2, alpha2);
   Cairo.cairo_pattern_set_extend(handle, Cairo.CAIRO_EXTEND_REPEAT);
   init();
 }
Esempio n. 18
0
  /**
   * Causes the receiver to be resized to its preferred size. For a composite, this involves
   * computing the preferred size from its layout, if there is one.
   *
   * @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 pack() {
    checkWidget();

    int width = 0;

    /* compute header width */
    NSTableHeaderCell headerCell = nsColumn.headerCell();
    NSSize size = headerCell.cellSize();
    width += Math.ceil(size.width);
    if (image != null) {
      NSSize imageSize = image.handle.size();
      width += Math.ceil(imageSize.width) + MARGIN;
    }
    if (parent.sortColumn == this && parent.sortDirection != SWT.NONE) {
      NSRect sortRect = headerCell.sortIndicatorRectForBounds(new NSRect());
      width += Math.ceil(sortRect.width + 2 * MARGIN);
    }

    /* compute item widths down column */
    GC gc = new GC(parent);
    width = Math.max(width, parent.calculateWidth(parent.items, parent.indexOf(this), gc, true));
    gc.dispose();
    setWidth(width);
  }
Esempio n. 19
0
  /** Paint the Label's border. */
  private void paintBorder(GC gc, Rectangle r) {
    Display disp = getDisplay();

    Color c1 = null;
    Color c2 = null;

    int style = getStyle();
    if ((style & SWT.SHADOW_IN) != 0) {
      c1 = disp.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
      c2 = disp.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW);
    }
    if ((style & SWT.SHADOW_OUT) != 0) {
      c1 = disp.getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW);
      c2 = disp.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
    }

    if (c1 != null && c2 != null) {
      gc.setLineWidth(1);
      drawBevelRect(gc, r.x, r.y, r.width - 1, r.height - 1, c1, c2);
    }
  }
Esempio n. 20
0
  void paintStripes(GC gc) {

    if (!showStripes) return;

    Rectangle rect = getClientArea();
    // Subtracted border painted by paint.
    rect = new Rectangle(rect.x + 2, rect.y + 2, rect.width - 4, rect.height - 4);

    gc.setLineWidth(2);
    gc.setClipping(rect);
    Color color = getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION);
    gc.setBackground(color);
    gc.fillRectangle(rect);
    gc.setForeground(this.getBackground());
    int step = 12;
    int foregroundValue = value == 0 ? step - 2 : value - 2;
    if (orientation == SWT.HORIZONTAL) {
      int y = rect.y - 1;
      int w = rect.width;
      int h = rect.height + 2;
      for (int i = 0; i < w; i += step) {
        int x = i + foregroundValue;
        gc.drawLine(x, y, x, h);
      }
    } else {
      int x = rect.x - 1;
      int w = rect.width + 2;
      int h = rect.height;

      for (int i = 0; i < h; i += step) {
        int y = i + foregroundValue;
        gc.drawLine(x, y, w, y);
      }
    }

    if (active) {
      value = (value + 2) % step;
    }
  }
 /**
  * Add a stop to the collection of stops defining the color and alpha blending of this SVG style
  * linear or radial gradient.
  *
  * <p>For linear gradients, the stops represent locations along the gradient vector. For radial
  * gradients, they represent locations from the focal point (fx,fy) to the edge of the
  * outermost/largest circle.
  *
  * @param color the color to use at that gradient stop
  * @param offset a number between 0.0 and 1.0 which indicates the location of the gradient stop.
  *     For linear gradients, the �offset� attribute represents a location along the gradient
  *     vector. For radial gradients, it represents a percentage distance from (fx,fy) to the edge
  *     of the outermost/largest circle
  * @param alpha the alpha value of the gradient at this stop location (from 0 to 255)
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if color is null
  *       <li>ERROR_INVALID_ARGUMENT - if color has been disposed
  *     </ul>
  */
 public void addStop(Color color, float /*double*/ offset, int alpha) {
   GC.setCairoPatternColor(handle, offset, color, alpha);
 }
  private static void paintImage(GC gc, Point size) {
    gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    gc.fillRectangle(0, 0, size.x, size.y);

    gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_LIST_SELECTION));
    gc.fillRoundRectangle(0, 0, size.x - 1, size.y - 1, 10, 10);

    gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    gc.drawRoundRectangle(0, 0, size.x - 1, size.y - 1, 10, 10);
    gc.drawText(gc.getFont().getFontData()[0].toString(), 10, 10, true);
  }
  @Override
  void draw(Theme theme, GC gc, Rectangle bounds) {
    if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed()) {
      // TODO - drawScale not done
      int style = this.style;
      int minimum = this.minimum;
      int maximum = this.maximum;
      int selection = this.selection;
      int pageIncrement = this.pageIncrement;
      long /*int*/ hTheme = OS.OpenThemeData(0, getClassId());
      RECT rect = new RECT();
      rect.left = bounds.x;
      rect.right = rect.left + bounds.width;
      rect.top = bounds.y;
      rect.bottom = rect.top + bounds.height;
      SIZE size = new SIZE();
      if ((style & SWT.VERTICAL) != 0) {
        OS.GetThemePartSize(hTheme, gc.handle, OS.TKP_TRACKVERT, 0, null, OS.TS_TRUE, size);
        int trackWidth = size.cx - 1;
        OS.GetThemePartSize(hTheme, gc.handle, OS.TKP_THUMBVERT, 0, null, OS.TS_TRUE, size);
        int thumbWidth = size.cx, thumbHeight = size.cy;
        OS.GetThemePartSize(hTheme, gc.handle, OS.TKP_TICS, 0, rect, OS.TS_TRUE, size);
        int ticWidth = size.cx;
        int marginX = (thumbWidth - trackWidth) / 2;
        int marginY = marginX;
        marginX += TICS_MARGIN;
        rect.left += marginX;
        rect.top += marginY;
        rect.right = rect.left + trackWidth;
        rect.bottom -= marginY;
        int trackHeight = rect.bottom - rect.top;
        OS.DrawThemeBackground(hTheme, gc.handle, OS.TKP_TRACKVERT, 0, rect, null);
        rect.top +=
            ((trackHeight - thumbHeight) * (selection - minimum)) / Math.max(1, maximum - minimum);
        rect.left -= (thumbWidth - trackWidth) / 2;
        rect.right = rect.left + thumbWidth;
        rect.bottom = rect.top + thumbHeight;
        OS.DrawThemeBackground(hTheme, gc.handle, OS.TKP_THUMBVERT, 0, rect, null);
        rect.top = bounds.y + marginY + thumbHeight / 2;
        rect.bottom = rect.top + 1;
        for (int sel = minimum; sel <= maximum; sel += pageIncrement) {
          rect.left = bounds.x + TICS_MARGIN / 2;
          rect.right = rect.left + ticWidth;
          if (sel != minimum && sel != maximum) rect.left++;
          rect.top = bounds.y + marginY + thumbHeight / 2;
          rect.top +=
              ((trackHeight - thumbHeight) * (sel - minimum)) / Math.max(1, maximum - minimum);
          rect.bottom = rect.top + 1;
          // TODO - why tics are ot drawn
          OS.DrawThemeBackground(hTheme, gc.handle, OS.TKP_TICSVERT, 1, rect, null);
          gc.drawLine(rect.left, rect.top, rect.right, rect.top);
          rect.left = bounds.x + TICS_MARGIN + thumbWidth + 1;
          rect.right = rect.left + ticWidth;
          if (sel != minimum && sel != maximum) rect.right--;
          // TODO - why tics are ot drawn
          OS.DrawThemeBackground(hTheme, gc.handle, OS.TKP_TICSVERT, 1, rect, null);
          gc.drawLine(rect.left, rect.top, rect.right, rect.top);
        }
      } else {

      }
      OS.CloseThemeData(hTheme);
    }
  }
Esempio n. 24
0
 Point computeSize(GC gc) {
   int width = 0, height = 0;
   if ((style & SWT.SEPARATOR) != 0) {
     if ((parent.style & SWT.HORIZONTAL) != 0) {
       width = getWidth();
       height = DEFAULT_HEIGHT;
     } else {
       width = DEFAULT_WIDTH;
       height = getWidth();
     }
     if (control != null) {
       height = Math.max(height, control.getMinimumHeight());
     }
     return new Point(width, height);
   }
   int[] argList = {
     OS.XmNmarginHeight, 0,
     OS.XmNmarginWidth, 0,
     OS.XmNshadowThickness, 0,
   };
   OS.XtGetValues(handle, argList, argList.length / 2);
   int marginHeight = argList[1], marginWidth = argList[3];
   int shadowThickness = argList[5];
   if ((parent.style & SWT.FLAT) != 0) {
     shadowThickness = Math.min(2, display.buttonShadowThickness);
   }
   if (text.length() != 0 || image != null) {
     int 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 imageWidth = 0, imageHeight = 0;
     if (image != null) {
       Rectangle rect = image.getBounds();
       imageWidth = rect.width;
       imageHeight = rect.height;
     }
     if ((parent.style & SWT.RIGHT) != 0) {
       width = imageWidth + textWidth;
       height = Math.max(imageHeight, textHeight);
       if (imageWidth != 0 && textWidth != 0) width += 2;
     } else {
       height = imageHeight + textHeight;
       if (imageHeight != 0 && textHeight != 0) height += 2;
       width = Math.max(imageWidth, textWidth);
     }
   } else {
     width = DEFAULT_WIDTH;
     height = DEFAULT_HEIGHT;
   }
   if ((style & SWT.DROP_DOWN) != 0) {
     width += 12;
   }
   if (width != 0) {
     width += (marginWidth + shadowThickness) * 2 + 2;
   } else {
     width = DEFAULT_WIDTH;
   }
   if (height != 0) {
     height += (marginHeight + shadowThickness) * 2 + 2;
   } else {
     height = DEFAULT_HEIGHT;
   }
   return new Point(width, height);
 }
Esempio n. 25
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;
  }
Esempio n. 26
0
  protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
    CTabFolder folder = (CTabFolder) composite;
    CTabItem[] items = folder.items;
    CTabFolderRenderer renderer = folder.renderer;
    // preferred width of tab area to show all tabs
    int tabW = 0;
    int selectedIndex = folder.selectedIndex;
    if (selectedIndex == -1) selectedIndex = 0;
    GC gc = new GC(folder);
    for (int i = 0; i < items.length; i++) {
      if (folder.single) {
        tabW =
            Math.max(tabW, renderer.computeSize(i, SWT.SELECTED, gc, SWT.DEFAULT, SWT.DEFAULT).x);
      } else {
        int state = 0;
        if (i == selectedIndex) state |= SWT.SELECTED;
        tabW += renderer.computeSize(i, state, gc, SWT.DEFAULT, SWT.DEFAULT).x;
      }
    }
    tabW += 3;

    if (folder.showMax)
      tabW +=
          renderer.computeSize(
                  CTabFolderRenderer.PART_MAX_BUTTON, SWT.NONE, gc, SWT.DEFAULT, SWT.DEFAULT)
              .x;
    if (folder.showMin)
      tabW +=
          renderer.computeSize(
                  CTabFolderRenderer.PART_MIN_BUTTON, SWT.NONE, gc, SWT.DEFAULT, SWT.DEFAULT)
              .x;
    if (folder.single)
      tabW +=
          renderer.computeSize(
                  CTabFolderRenderer.PART_CHEVRON_BUTTON, SWT.NONE, gc, SWT.DEFAULT, SWT.DEFAULT)
              .x;
    if (folder.topRight != null) {
      Point pt = folder.topRight.computeSize(SWT.DEFAULT, folder.tabHeight, flushCache);
      tabW += 3 + pt.x;
    }

    gc.dispose();

    int controlW = 0;
    int controlH = 0;
    // preferred size of controls in tab items
    for (int i = 0; i < items.length; i++) {
      Control control = items[i].getControl();
      if (control != null && !control.isDisposed()) {
        Point size = control.computeSize(wHint, hHint, flushCache);
        controlW = Math.max(controlW, size.x);
        controlH = Math.max(controlH, size.y);
      }
    }

    int minWidth = Math.max(tabW, controlW);
    int minHeight = (folder.minimized) ? 0 : controlH;
    if (minWidth == 0) minWidth = CTabFolder.DEFAULT_WIDTH;
    if (minHeight == 0) minHeight = CTabFolder.DEFAULT_HEIGHT;

    if (wHint != SWT.DEFAULT) minWidth = wHint;
    if (hHint != SWT.DEFAULT) minHeight = hHint;

    return new Point(minWidth, minHeight);
  }
  private static void paintImage2(GC gc, Point size, int f) {
    gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    gc.fillRectangle(0, 0, size.x, size.y);

    // Scale line width, corner roundness, and font size.
    // Caveat: line width expands in all directions, so the origin also has to move.

    gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_LIST_SELECTION));
    gc.fillRoundRectangle(f / 2, f / 2, size.x - f, size.y - f, 10 * f, 10 * f);

    gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    gc.setLineWidth(f);
    gc.drawRoundRectangle(f / 2, f / 2, size.x - f, size.y - f, 10 * f, 10 * f);
    FontData fontData = gc.getFont().getFontData()[0];
    fontData.setHeight(fontData.getHeight() * f);
    Font font = new Font(gc.getDevice(), fontData);
    try {
      gc.setFont(font);
      gc.drawText(fontData.toString(), 10 * f, 10 * f, true);
    } finally {
      font.dispose();
    }
  }
  public static void main(String[] args) {
    final ImageFileNameProvider filenameProvider =
        new ImageFileNameProvider() {
          @Override
          public String getImagePath(int zoom) {
            switch (zoom) {
              case 150:
                return IMAGE_PATH_150;
              case 200:
                return IMAGE_PATH_200;
              default:
                return IMAGE_PATH_100;
            }
          }
        };
    final ImageDataProvider imageDataProvider =
        new ImageDataProvider() {
          @Override
          public ImageData getImageData(int zoom) {
            switch (zoom) {
              case 150:
                return new ImageData(IMAGE_PATH_150);
              case 200:
                return new ImageData(IMAGE_PATH_200);
              default:
                return new ImageData(IMAGE_PATH_100);
            }
          }
        };

    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new GridLayout(2, false));

    new Label(shell, SWT.NONE).setText(IMAGE_200 + ":");
    new Label(shell, SWT.NONE).setImage(new Image(display, IMAGE_PATH_200));

    new Label(shell, SWT.NONE).setText(IMAGE_150 + ":");
    new Label(shell, SWT.NONE).setImage(new Image(display, IMAGE_PATH_150));

    new Label(shell, SWT.NONE).setText(IMAGE_100 + ":");
    new Label(shell, SWT.NONE).setImage(new Image(display, IMAGE_PATH_100));

    new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL)
        .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));

    new Label(shell, SWT.NONE).setText("ImageFileNameProvider:");
    new Label(shell, SWT.NONE).setImage(new Image(display, filenameProvider));

    new Label(shell, SWT.NONE).setText("ImageDataProvider:");
    new Label(shell, SWT.NONE).setImage(new Image(display, imageDataProvider));

    new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL)
        .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));

    new Label(shell, SWT.NONE).setText("Canvas\n(PaintListener)");
    final Point size = new Point(550, 35);
    final Canvas canvas = new Canvas(shell, SWT.NONE);
    canvas.addPaintListener(
        new PaintListener() {
          @Override
          public void paintControl(PaintEvent e) {
            Point size = canvas.getSize();
            paintImage(e.gc, size);
          }
        });
    canvas.setLayoutData(new GridData(size.x, size.y));

    new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL)
        .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));

    new Label(shell, SWT.NONE).setText("Painted image\n (default resolution)");
    Image image = new Image(display, size.x, size.y);
    GC gc = new GC(image);
    try {
      paintImage(gc, size);
    } finally {
      gc.dispose();
    }
    new Label(shell, SWT.NONE).setImage(image);

    new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL)
        .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));

    new Label(shell, SWT.NONE).setText("Painted image\n(multi-res, unzoomed paint)");
    new Label(shell, SWT.NONE)
        .setImage(
            new Image(
                display,
                new ImageDataProvider() {
                  @Override
                  public ImageData getImageData(int zoom) {
                    Image temp = new Image(display, size.x * zoom / 100, size.y * zoom / 100);
                    GC gc = new GC(temp);
                    try {
                      paintImage(gc, size);
                      return temp.getImageData();
                    } finally {
                      gc.dispose();
                      temp.dispose();
                    }
                  }
                }));

    new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL)
        .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));

    new Label(shell, SWT.NONE).setText("Painted image\n(multi-res, zoomed paint)");
    new Label(shell, SWT.NONE)
        .setImage(
            new Image(
                display,
                new ImageDataProvider() {
                  @Override
                  public ImageData getImageData(int zoom) {
                    Image temp = new Image(display, size.x * zoom / 100, size.y * zoom / 100);
                    GC gc = new GC(temp);
                    try {
                      paintImage2(
                          gc, new Point(size.x * zoom / 100, size.y * zoom / 100), zoom / 100);
                      return temp.getImageData();
                    } finally {
                      gc.dispose();
                      temp.dispose();
                    }
                  }
                }));

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }
 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);
   }
 }
Esempio n. 30
0
 void drawItem(GC gc, boolean drawFocus) {
   int headerHeight = parent.getBandHeight();
   Display display = getDisplay();
   gc.setForeground(display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND));
   gc.setBackground(display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT));
   gc.fillGradientRectangle(x, y, width, headerHeight, true);
   if (expanded) {
     gc.setForeground(display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT));
     gc.drawLine(x, y + headerHeight, x, y + headerHeight + height - 1);
     gc.drawLine(x, y + headerHeight + height - 1, x + width - 1, y + headerHeight + height - 1);
     gc.drawLine(x + width - 1, y + headerHeight + height - 1, x + width - 1, y + headerHeight);
   }
   int drawX = x;
   if (image != null) {
     drawX += ExpandItem.TEXT_INSET;
     if (imageHeight > headerHeight) {
       gc.drawImage(image, drawX, y + headerHeight - imageHeight);
     } else {
       gc.drawImage(image, drawX, y + (headerHeight - imageHeight) / 2);
     }
     drawX += imageWidth;
   }
   if (text.length() > 0) {
     drawX += ExpandItem.TEXT_INSET;
     Point size = gc.stringExtent(text);
     gc.setForeground(parent.getForeground());
     gc.drawString(text, drawX, y + (headerHeight - size.y) / 2, true);
   }
   int chevronSize = ExpandItem.CHEVRON_SIZE;
   drawChevron(gc, x + width - chevronSize, y + (headerHeight - chevronSize) / 2);
   if (drawFocus) {
     gc.drawFocus(x + 1, y + 1, width - 2, headerHeight - 2);
   }
 }