Exemplo n.º 1
0
 /**
  * Returns the hue, saturation, and brightness of the color.
  *
  * @return color space values in float format (hue, saturation, brightness)
  * @since 3.2
  */
 public float[] getHSB() {
   float r = red / 255f;
   float g = green / 255f;
   float b = blue / 255f;
   float max = Math.max(Math.max(r, g), b);
   float min = Math.min(Math.min(r, g), b);
   float delta = max - min;
   float hue = 0;
   float brightness = max;
   float saturation = max == 0 ? 0 : (max - min) / max;
   if (delta != 0) {
     if (r == max) {
       hue = (g - b) / delta;
     } else {
       if (g == max) {
         hue = 2 + (b - r) / delta;
       } else {
         hue = 4 + (r - g) / delta;
       }
     }
     hue *= 60;
     if (hue < 0) hue += 360;
   }
   return new float[] {hue, saturation, brightness};
 }
Exemplo n.º 2
0
 static void drawTorus(float r, float R, int nsides, int rings) {
   float ringDelta = 2.0f * (float) Math.PI / rings;
   float sideDelta = 2.0f * (float) Math.PI / nsides;
   float theta = 0.0f, cosTheta = 1.0f, sinTheta = 0.0f;
   for (int i = rings - 1; i >= 0; i--) {
     float theta1 = theta + ringDelta;
     float cosTheta1 = (float) Math.cos(theta1);
     float sinTheta1 = (float) Math.sin(theta1);
     GL11.glBegin(GL11.GL_QUAD_STRIP);
     float phi = 0.0f;
     for (int j = nsides; j >= 0; j--) {
       phi += sideDelta;
       float cosPhi = (float) Math.cos(phi);
       float sinPhi = (float) Math.sin(phi);
       float dist = R + r * cosPhi;
       GL11.glNormal3f(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi);
       GL11.glVertex3f(cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi);
       GL11.glNormal3f(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi);
       GL11.glVertex3f(cosTheta * dist, -sinTheta * dist, r * sinPhi);
     }
     GL11.glEnd();
     theta = theta1;
     cosTheta = cosTheta1;
     sinTheta = sinTheta1;
   }
 }
Exemplo n.º 3
0
 Point minimumSize(int wHint, int hHint, boolean flushCache) {
   Control[] children = _getChildren();
   int width = 0, height = 0;
   for (int i = 0; i < children.length; i++) {
     Control child = children[i];
     int index = 0;
     int count = 0;
     long /*int*/ list = OS.gtk_container_get_children(handle);
     if (list != 0) {
       count = OS.g_list_length(list);
       OS.g_list_free(list);
     }
     while (index < count) {
       if (items[index].control == child) break;
       index++;
     }
     if (index == count) {
       Rectangle rect = child.getBounds();
       width = Math.max(width, rect.x + rect.width);
       height = Math.max(height, rect.y + rect.height);
     } else {
       Point size = child.computeSize(wHint, hHint, flushCache);
       width = Math.max(width, size.x);
       height = Math.max(height, size.y);
     }
   }
   return new Point(width, height);
 }
Exemplo n.º 4
0
 void updateBar(int selection, int minimum, int maximum, int thumb) {
   NSScroller widget = (NSScroller) view;
   selection = Math.max(minimum, Math.min(maximum - thumb, selection));
   float fraction =
       minimum == maximum ? 1 : (float) (selection - minimum) / (maximum - thumb - minimum);
   float knob = minimum == maximum ? 1 : (float) (thumb - minimum) / (maximum - minimum);
   widget.setFloatValue(fraction, knob);
 }
Exemplo n.º 5
0
 /**
  * Set the label's margins, in pixels.
  *
  * @param leftMargin the left margin.
  * @param topMargin the top margin.
  * @param rightMargin the right margin.
  * @param bottomMargin the bottom margin.
  * @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>
  *
  * @since 3.6
  */
 public void setMargins(int leftMargin, int topMargin, int rightMargin, int bottomMargin) {
   checkWidget();
   this.leftMargin = Math.max(0, leftMargin);
   this.topMargin = Math.max(0, topMargin);
   this.rightMargin = Math.max(0, rightMargin);
   this.bottomMargin = Math.max(0, bottomMargin);
   redraw();
 }
Exemplo n.º 6
0
 private void setHoverLocation(
     org.eclipse.swt.widgets.Shell shell, org.eclipse.swt.graphics.Point position) {
   org.eclipse.swt.graphics.Rectangle displayBounds = shell.getDisplay().getBounds();
   org.eclipse.swt.graphics.Rectangle shellBounds = shell.getBounds();
   shellBounds.x = Math.max(Math.min(position.x, displayBounds.width - shellBounds.width), 0);
   shellBounds.y =
       Math.max(Math.min(position.y + 16, displayBounds.height - shellBounds.height), 0);
   shell.setBounds(shellBounds);
 }
Exemplo n.º 7
0
 void setBounds(int x, int y, int width, int height) {
   /*
    * Feature in Motif.  Motif will not allow a window
    * to have a zero width or zero height.  The fix is
    * to ensure these values are never zero.
    */
   int newWidth = Math.max(width, 1), newHeight = Math.max(height, 1);
   OS.XtConfigureWidget(handle, x, y, newWidth, newHeight, 0);
 }
Exemplo n.º 8
0
 /**
  * Sets the minimum value. If this value is negative or greater than or equal to the maximum, the
  * value is ignored. If necessary, first the thumb and then the selection are adjusted to fit
  * within the new range.
  *
  * @param value the new minimum
  * @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 setMinimum(int value) {
   checkWidget();
   if (value < 0) return;
   if (value >= maximum) return;
   if (maximum - value < thumb) {
     thumb = maximum - value;
   }
   int selection = Math.min(maximum - thumb, Math.max(getSelection(), value));
   this.minimum = value;
   updateBar(selection, value, maximum, thumb);
 }
Exemplo n.º 9
0
 /**
  * Sets the maximum. If this value is negative or less than or equal to the minimum, the value is
  * ignored. If necessary, first the thumb and then the selection are adjusted to fit within the
  * new range.
  *
  * @param value the new maximum, which must be greater than the current minimum
  * @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 setMaximum(int value) {
   checkWidget();
   if (value < 0) return;
   if (value <= minimum) return;
   if (value - minimum < thumb) {
     thumb = value - minimum;
   }
   int selection = Math.max(minimum, Math.min(getSelection(), value - thumb));
   this.maximum = value;
   updateBar(selection, minimum, value, thumb);
 }
Exemplo n.º 10
0
 int XPointerMotion(int w, int client_data, int call_data, int continue_to_dispatch) {
   int result = super.XPointerMotion(w, client_data, call_data, continue_to_dispatch);
   if (result != 0) return result;
   XMotionEvent xEvent = new XMotionEvent();
   OS.memmove(xEvent, call_data, XMotionEvent.sizeof);
   if (!dragging || (xEvent.state & OS.Button1Mask) == 0) return result;
   short[] x_root = new short[1], y_root = new short[1];
   OS.XtTranslateCoords(handle, (short) 0, (short) 0, x_root, y_root);
   int eventX = xEvent.x_root - x_root[0], eventY = xEvent.y_root - y_root[0];
   int[] argList1 = {
     OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0
   };
   OS.XtGetValues(handle, argList1, argList1.length / 2);
   int border = argList1[9],
       x = ((short) argList1[1]) - border,
       y = ((short) argList1[3]) - border;
   int width = argList1[5] + (border * 2), height = argList1[7] + (border * 2);
   int[] argList2 = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
   OS.XtGetValues(parent.handle, argList2, argList2.length / 2);
   int parentBorder = argList2[5];
   int parentWidth = argList2[1] + (parentBorder * 2);
   int parentHeight = argList2[3] + (parentBorder * 2);
   int newX = lastX, newY = lastY;
   if ((style & SWT.VERTICAL) != 0) {
     newX = Math.min(Math.max(0, eventX + x - startX - parentBorder), parentWidth - width);
   } else {
     newY = Math.min(Math.max(0, eventY + y - startY - parentBorder), parentHeight - height);
   }
   if (newX == lastX && newY == lastY) return result;
   drawBand(lastX, lastY, width, height);
   Event event = new Event();
   event.time = xEvent.time;
   event.x = newX;
   event.y = newY;
   event.width = width;
   event.height = height;
   if ((style & SWT.SMOOTH) == 0) {
     event.detail = SWT.DRAG;
   }
   sendEvent(SWT.Selection, event);
   if (isDisposed()) return result;
   if (event.doit) {
     lastX = event.x;
     lastY = event.y;
   }
   parent.update(true);
   drawBand(lastX, lastY, width, height);
   if ((style & SWT.SMOOTH) != 0) {
     setBounds(lastX, lastY, width, height);
     // widget could be disposed at this point
   }
   return result;
 }
Exemplo n.º 11
0
 public Point computeSize(int wHint, int hHint, boolean changed) {
   checkWidget();
   Point size = super.computeSize(wHint, hHint, changed);
   if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
   if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
   boolean scrollable = OS.gtk_notebook_get_scrollable(handle);
   OS.gtk_notebook_set_scrollable(handle, false);
   Point notebookSize = computeNativeSize(handle, wHint, hHint, changed);
   OS.gtk_notebook_set_scrollable(handle, scrollable);
   size.x = Math.max(notebookSize.x, size.x);
   size.y = Math.max(notebookSize.y, size.y);
   return size;
 }
Exemplo n.º 12
0
 /**
  * Sets the width of the receiver.
  *
  * @param width the new width
  * @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 (width < 0) return;
   // TODO how to differentiate 0 and 1 cases?
   width = Math.max(0, width - Tree.CELL_GAP);
   nsColumn.setWidth(width);
 }
Exemplo n.º 13
0
  /**
   * Sets the font that the receiver will use to paint textual information for the specified cell in
   * this item to the font specified by the argument, or to the default font for that kind of
   * control if the argument is null.
   *
   * @param index the column index
   * @param font the new font (or null)
   * @exception IllegalArgumentException
   *     <ul>
   *       <li>ERROR_INVALID_ARGUMENT - if the argument 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>
   *
   * @since 3.0
   */
  public void setFont(int index, Font font) {
    checkWidget();
    if (font != null && font.isDisposed()) {
      SWT.error(SWT.ERROR_INVALID_ARGUMENT);
    }
    int count = Math.max(1, parent.getColumnCount());
    if (0 > index || index > count - 1) return;
    if (cellFont == null) {
      if (font == null) return;
      cellFont = new Font[count];
    }
    Font oldFont = cellFont[index];
    if (oldFont == font) return;
    cellFont[index] = font;
    if (oldFont != null && oldFont.equals(font)) return;

    int modelIndex =
        parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns[index].modelIndex;
    int /*long*/ fontHandle = font != null ? font.handle : 0;
    OS.gtk_list_store_set(parent.modelHandle, handle, modelIndex + Table.CELL_FONT, fontHandle, -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();
      }
    }
    cached = true;

    if (font != null) {
      boolean customDraw =
          (parent.columnCount == 0) ? parent.firstCustomDraw : parent.columns[index].customDraw;
      if (!customDraw) {
        if ((parent.style & SWT.VIRTUAL) == 0) {
          int /*long*/ parentHandle = parent.handle;
          int /*long*/ column = 0;
          if (parent.columnCount > 0) {
            column = parent.columns[index].handle;
          } else {
            column = OS.gtk_tree_view_get_column(parentHandle, index);
          }
          if (column == 0) return;
          int /*long*/ textRenderer = parent.getTextRenderer(column);
          int /*long*/ imageRenderer = parent.getPixbufRenderer(column);
          OS.gtk_tree_view_column_set_cell_data_func(
              column, textRenderer, display.cellDataProc, parentHandle, 0);
          OS.gtk_tree_view_column_set_cell_data_func(
              column, imageRenderer, display.cellDataProc, parentHandle, 0);
        }
        if (parent.columnCount == 0) {
          parent.firstCustomDraw = true;
        } else {
          parent.columns[index].customDraw = true;
        }
      }
    }
  }
Exemplo n.º 14
0
 /**
  * Sets the minimum value that the receiver will allow. This new value will be ignored if it is
  * negative or is not less than the receiver's current maximum value. If the new minimum is
  * applied then the receiver's selection value will be adjusted if necessary to fall within its
  * new range.
  *
  * @param value the new minimum, which must be nonnegative and less than the current maximum
  * @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 setMinimum(int value) {
   checkWidget();
   if (value < 0 || value >= maximum) return;
   minimum = value;
   selection = Math.max(selection, minimum);
   updateBar(selection, minimum, maximum);
 }
Exemplo n.º 15
0
 /**
  * Sets the size of the receiver's thumb relative to the difference between its maximum and
  * minimum values. This new value will be ignored if it is less than one, and will be clamped if
  * it exceeds the receiver's current range.
  *
  * @param value the new thumb value, which must be at least one and not larger than the size of
  *     the current range
  * @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 setThumb(int value) {
   checkWidget();
   if (value < 1) return;
   value = Math.min(value, maximum - minimum);
   this.thumb = value;
   updateBar(getSelection(), minimum, maximum, value);
 }
Exemplo n.º 16
0
 /**
  * Returns the font that the receiver will use to paint textual information for the specified cell
  * in this item.
  *
  * @param index the column index
  * @return the receiver's font
  * @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>
  *
  * @since 3.0
  */
 public Font getFont(int index) {
   checkWidget();
   if (!parent.checkData(this)) error(SWT.ERROR_WIDGET_DISPOSED);
   int count = Math.max(1, parent.columnCount);
   if (0 > index || index > count - 1) return getFont();
   if (cellFont == null || cellFont[index] == null) return getFont();
   return cellFont[index];
 }
Exemplo n.º 17
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;
 }
Exemplo n.º 18
0
 Color _getForeground(int index) {
   int count = Math.max(1, parent.columnCount);
   if (0 > index || index > count - 1) return _getForeground();
   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_FOREGROUND, ptr, -1);
   if (ptr[0] == 0) return _getForeground();
   GdkColor gdkColor = new GdkColor();
   OS.memmove(gdkColor, ptr[0], GdkColor.sizeof);
   return Color.gtk_new(display, gdkColor);
 }
Exemplo n.º 19
0
 void setBounds(int x, int y, int width, int height, boolean move, boolean size) {
   redraw();
   int headerHeight = parent.getBandHeight();
   if (move) {
     if (imageHeight > headerHeight) {
       y += (imageHeight - headerHeight);
     }
     this.x = x;
     this.y = y;
     redraw();
   }
   if (size) {
     this.width = width;
     this.height = height;
     redraw();
   }
   if (control != null && !control.isDisposed()) {
     if (move) control.setLocation(x + BORDER, y + headerHeight);
     if (size) control.setSize(Math.max(0, width - 2 * BORDER), Math.max(0, height - BORDER));
   }
 }
Exemplo n.º 20
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);
 }
Exemplo n.º 21
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;
  }
Exemplo n.º 22
0
 /**
  * Returns a rectangle describing the receiver's size and location relative to its parent.
  *
  * @return the receiver's bounding rectangle
  * @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 Rectangle getBounds() {
   checkWidget();
   parent.forceResize();
   long /*int*/ topHandle = topHandle();
   int x, y, width, height;
   x = OS.GTK_WIDGET_X(topHandle);
   y = OS.GTK_WIDGET_Y(topHandle);
   width = OS.GTK_WIDGET_WIDTH(topHandle);
   height = OS.GTK_WIDGET_HEIGHT(topHandle);
   if ((parent.style & SWT.MIRRORED) != 0) x = parent.getClientWidth() - width - x;
   if ((style & SWT.SEPARATOR) != 0 && control != null) height = Math.max(height, 23);
   return new Rectangle(x, y, width, height);
 }
Exemplo n.º 23
0
 /**
  * Sets the receiver's selection, minimum value, maximum value, thumb, increment and page
  * increment all at once.
  *
  * <p>Note: This is similar to setting the values individually using the appropriate methods, but
  * may be implemented in a more efficient fashion on some platforms.
  *
  * @param selection the new selection value
  * @param minimum the new minimum value
  * @param maximum the new maximum value
  * @param thumb the new thumb value
  * @param increment the new increment value
  * @param pageIncrement the new pageIncrement value
  * @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 setValues(
     int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) {
   checkWidget();
   if (minimum < 0) return;
   if (maximum < 0) return;
   if (thumb < 1) return;
   if (increment < 1) return;
   if (pageIncrement < 1) return;
   thumb = Math.min(thumb, maximum - minimum);
   this.increment = increment;
   this.pageIncrement = pageIncrement;
   updateBar(selection, minimum, maximum, thumb);
 }
 static int[] circle(int r, int offsetX, int offsetY) {
   int[] polygon = new int[8 * r + 4];
   // x^2 + y^2 = r^2
   for (int i = 0; i < 2 * r + 1; i++) {
     int x = i - r;
     int y = (int) Math.sqrt(r * r - x * x);
     polygon[2 * i] = offsetX + x;
     polygon[2 * i + 1] = offsetY + y;
     polygon[8 * r - 2 * i - 2] = offsetX + x;
     polygon[8 * r - 2 * i - 1] = offsetY - y;
   }
   return polygon;
 }
Exemplo n.º 25
0
 String _getText(int index) {
   int count = Math.max(1, parent.getColumnCount());
   if (0 > index || index > count - 1) return "";
   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_TEXT, ptr, -1);
   if (ptr[0] == 0) return "";
   int length = OS.strlen(ptr[0]);
   byte[] buffer = new byte[length];
   OS.memmove(buffer, ptr[0], length);
   OS.g_free(ptr[0]);
   return new String(Converter.mbcsToWcs(null, buffer));
 }
Exemplo n.º 26
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);
  }
Exemplo n.º 27
0
 public Path(Device device, Path path, float flatness) {
   super(device);
   if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
   if (path.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
   flatness = Math.max(0, flatness);
   if (flatness == 0) {
     handle = new NSBezierPath(path.handle.copy().id);
   } else {
     float defaultFlatness = NSBezierPath.defaultFlatness();
     NSBezierPath.setDefaultFlatness(flatness);
     handle = path.handle.bezierPathByFlatteningPath();
     NSBezierPath.setDefaultFlatness(defaultFlatness);
   }
   if (handle == null) SWT.error(SWT.ERROR_NO_HANDLES);
   init();
 }
Exemplo n.º 28
0
 LRESULT wmMeasureChild(long /*int*/ wParam, long /*int*/ lParam) {
   MEASUREITEMSTRUCT struct = new MEASUREITEMSTRUCT();
   OS.MoveMemory(struct, lParam, MEASUREITEMSTRUCT.sizeof);
   int width = 0, height = 0;
   if (image != null) {
     Rectangle rect = image.getBounds();
     width = rect.width;
     height = rect.height;
   } else {
     /*
      * Bug in Windows.  If a menu contains items that have
      * images and can be checked, Windows does not include
      * the width of the image and the width of the check when
      * computing the width of the menu.  When the longest item
      * does not have an image, the label and the accelerator
      * text can overlap.  The fix is to use SetMenuItemInfo()
      * to indicate that all items have a bitmap and then include
      * the width of the widest bitmap in WM_MEASURECHILD.
      */
     MENUINFO lpcmi = new MENUINFO();
     lpcmi.cbSize = MENUINFO.sizeof;
     lpcmi.fMask = OS.MIM_STYLE;
     long /*int*/ hMenu = parent.handle;
     OS.GetMenuInfo(hMenu, lpcmi);
     if ((lpcmi.dwStyle & OS.MNS_CHECKORBMP) == 0) {
       MenuItem[] items = parent.getItems();
       for (int i = 0; i < items.length; i++) {
         MenuItem item = items[i];
         if (item.image != null) {
           Rectangle rect = item.image.getBounds();
           width = Math.max(width, rect.width);
         }
       }
     }
   }
   if (width != 0 || height != 0) {
     struct.itemWidth = width + MARGIN_WIDTH * 2;
     struct.itemHeight = height + MARGIN_HEIGHT * 2;
     OS.MoveMemory(lParam, struct, MEASUREITEMSTRUCT.sizeof);
   }
   return null;
 }
Exemplo n.º 29
0
 /**
  * Sets the receiver's text at a column
  *
  * @param index the column index
  * @param string the new text
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_NULL_ARGUMENT - if the text is null
  *     </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 setText(int index, String string) {
   checkWidget();
   if (string == null) error(SWT.ERROR_NULL_ARGUMENT);
   if (_getText(index).equals(string)) return;
   int count = Math.max(1, parent.getColumnCount());
   if (0 > index || index > count - 1) return;
   byte[] buffer = Converter.wcsToMbcs(null, string, true);
   int modelIndex =
       parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns[index].modelIndex;
   OS.gtk_list_store_set(parent.modelHandle, handle, modelIndex + Table.CELL_TEXT, buffer, -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();
     }
   }
   cached = true;
 }
Exemplo n.º 30
0
  void resizeControl(int yScroll) {
    if (control != null && !control.isDisposed()) {
      boolean visible = OS.gtk_expander_get_expanded(handle);
      if (visible) {
        int x = OS.GTK_WIDGET_X(clientHandle);
        int y = OS.GTK_WIDGET_Y(clientHandle);
        if (x != -1 && y != -1) {
          int width = OS.GTK_WIDGET_WIDTH(clientHandle);
          int height = OS.GTK_WIDGET_HEIGHT(clientHandle);
          int[] property = new int[1];
          OS.gtk_widget_style_get(handle, OS.focus_line_width, property, 0);
          y += property[0] * 2;
          height -= property[0] * 2;

          /*
           * Feature in GTK. When the ExpandBar is resize too small the control
           * shows up on top of the vertical scrollbar. This happen because the
           * GtkExpander does not set the size of child smaller than the request
           * size of its parent and because the control is not parented in the
           * hierarchy of the GtkScrolledWindow.
           * The fix is calculate the width ourselves when the scrollbar is visible.
           */
          ScrollBar vBar = parent.verticalBar;
          if (vBar != null) {
            if (OS.GTK_WIDGET_VISIBLE(vBar.handle)) {
              width =
                  OS.GTK_WIDGET_WIDTH(parent.scrolledHandle)
                      - parent.vScrollBarWidth()
                      - 2 * parent.spacing;
            }
          }
          control.setBounds(x, y - yScroll, width, Math.max(0, height), true, true);
        }
      }
      control.setVisible(visible);
    }
  }