Esempio n. 1
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;
        }
      }
    }
  }
Esempio n. 2
0
 /**
  * Sets the receiver's image at a column.
  *
  * @param index the column index
  * @param image the new image
  * @exception IllegalArgumentException
  *     <ul>
  *       <li>ERROR_INVALID_ARGUMENT - if the image has been disposed
  *     </ul>
  *
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  */
 public void setImage(int index, Image image) {
   checkWidget();
   if (image != null && image.isDisposed()) {
     error(SWT.ERROR_INVALID_ARGUMENT);
   }
   if (image != null && image.type == SWT.ICON) {
     if (image.equals(_getImage(index))) return;
   }
   int count = Math.max(1, parent.getColumnCount());
   if (0 > index || index > count - 1) return;
   int /*long*/ pixbuf = 0;
   if (image != null) {
     ImageList imageList = parent.imageList;
     if (imageList == null) imageList = parent.imageList = new ImageList();
     int imageIndex = imageList.indexOf(image);
     if (imageIndex == -1) imageIndex = imageList.add(image);
     pixbuf = imageList.getPixbuf(imageIndex);
   }
   int modelIndex =
       parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns[index].modelIndex;
   OS.gtk_list_store_set(parent.modelHandle, handle, modelIndex + Table.CELL_PIXBUF, pixbuf, -1);
   /*
    * Bug in GTK.  When using fixed-height-mode,
    * row changes do not cause the row to be repainted.  The fix is to
    * invalidate the row when it is cleared.
    */
   if ((parent.style & SWT.VIRTUAL) != 0) {
     if (OS.GTK_VERSION >= OS.VERSION(2, 3, 2) && OS.GTK_VERSION < OS.VERSION(2, 6, 3)) {
       redraw();
     }
   }
   /*
    * Bug in GTK.  When in fixed height mode, GTK does not recalculate the cell renderer width
    * when the image is changed in the model.  The fix is to force it to recalculate the width if
    * more space is required.
    */
   if ((parent.style & SWT.VIRTUAL) != 0 && parent.currentItem == null) {
     if (OS.GTK_VERSION >= OS.VERSION(2, 3, 2)) {
       if (image != null) {
         int /*long*/ parentHandle = parent.handle;
         int /*long*/ column = OS.gtk_tree_view_get_column(parentHandle, index);
         int[] w = new int[1];
         int /*long*/ pixbufRenderer = parent.getPixbufRenderer(column);
         OS.gtk_tree_view_column_cell_get_position(column, pixbufRenderer, null, w);
         if (w[0] < image.getBounds().width) {
           /*
            * There is no direct way to clear the cell renderer width so we
            * are relying on the fact that it is done as part of modifying
            * the style.
            */
           int /*long*/ style = OS.gtk_widget_get_modifier_style(parentHandle);
           parent.modifyStyle(parentHandle, style);
         }
       }
     }
   }
   cached = true;
 }
Esempio n. 3
0
 Color _getForeground() {
   int /*long*/[] ptr = new int /*long*/[1];
   OS.gtk_tree_model_get(parent.modelHandle, handle, Table.FOREGROUND_COLUMN, ptr, -1);
   if (ptr[0] == 0) return parent.getForeground();
   GdkColor gdkColor = new GdkColor();
   OS.memmove(gdkColor, ptr[0], GdkColor.sizeof);
   return Color.gtk_new(display, gdkColor);
 }
Esempio n. 4
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];
 }
Esempio n. 5
0
 TableItem(Table parent, int style, int index, boolean create) {
   super(parent, style);
   this.parent = parent;
   if (create) {
     parent.createItem(this, index);
   } else {
     handle = OS.g_malloc(OS.GtkTreeIter_sizeof());
     OS.gtk_tree_model_iter_nth_child(parent.modelHandle, handle, 0, index);
   }
 }
Esempio n. 6
0
 /**
  * Returns a rectangle describing the size and location relative to its parent of an image at a
  * column in the table. An empty rectangle is returned if index exceeds the index of the table's
  * last column.
  *
  * @param index the index that specifies the column
  * @return the receiver's bounding image 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 getImageBounds(int index) {
   checkWidget();
   if (!parent.checkData(this)) error(SWT.ERROR_WIDGET_DISPOSED);
   int /*long*/ parentHandle = parent.handle;
   int /*long*/ column = 0;
   if (index >= 0 && index < parent.columnCount) {
     column = parent.columns[index].handle;
   } else {
     column = OS.gtk_tree_view_get_column(parentHandle, index);
   }
   if (column == 0) return new Rectangle(0, 0, 0, 0);
   int /*long*/ pixbufRenderer = parent.getPixbufRenderer(column);
   if (pixbufRenderer == 0) return new Rectangle(0, 0, 0, 0);
   GdkRectangle rect = new GdkRectangle();
   int /*long*/ path = OS.gtk_tree_model_get_path(parent.modelHandle, handle);
   OS.gtk_widget_realize(parentHandle);
   OS.gtk_tree_view_get_cell_area(parentHandle, path, column, rect);
   OS.gtk_tree_path_free(path);
   if ((parent.getStyle() & SWT.MIRRORED) != 0)
     rect.x = parent.getClientWidth() - rect.width - rect.x;
   /*
    * The OS call gtk_cell_renderer_get_size() provides the width of image to be drawn
    * by the cell renderer.  If there is no image in the cell, the width is zero.  If the table contains
    * images of varying widths, gtk_cell_renderer_get_size() will return the width of the image,
    * not the width of the area in which the image is drawn.
    * New API was added in GTK 2.1.3 for determining the full width of the renderer area.
    * For earlier versions of GTK, the result is only correct if all rows have images of the same
    * width.
    */
   if (OS.GTK_VERSION >= OS.VERSION(2, 1, 3)) {
     int[] x = new int[1], w = new int[1];
     OS.gtk_tree_view_column_cell_get_position(column, pixbufRenderer, x, w);
     rect.x += x[0];
     rect.width = w[0];
   } else {
     int[] w = new int[1];
     OS.gtk_tree_view_column_cell_set_cell_data(column, parent.modelHandle, handle, false, false);
     OS.gtk_cell_renderer_get_size(pixbufRenderer, parentHandle, null, null, null, w, null);
     rect.width = w[0];
   }
   int width = OS.gtk_tree_view_column_get_visible(column) ? rect.width : 0;
   return new Rectangle(rect.x, rect.y, width, rect.height + 1);
 }
Esempio n. 7
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);
 }
Esempio n. 8
0
  /**
   * Returns a rectangle describing the receiver's size and location relative to its parent at a
   * column in the table.
   *
   * @param index the index that specifies the column
   * @return the receiver's bounding column 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(int index) {
    checkWidget();
    if (!parent.checkData(this)) error(SWT.ERROR_WIDGET_DISPOSED);
    int /*long*/ parentHandle = parent.handle;
    int /*long*/ column = 0;
    if (index >= 0 && index < parent.columnCount) {
      column = parent.columns[index].handle;
    } else {
      column = OS.gtk_tree_view_get_column(parentHandle, index);
    }
    if (column == 0) return new Rectangle(0, 0, 0, 0);
    int /*long*/ path = OS.gtk_tree_model_get_path(parent.modelHandle, handle);
    OS.gtk_widget_realize(parentHandle);
    GdkRectangle rect = new GdkRectangle();
    OS.gtk_tree_view_get_cell_area(parentHandle, path, column, rect);
    OS.gtk_tree_path_free(path);
    if ((parent.getStyle() & SWT.MIRRORED) != 0)
      rect.x = parent.getClientWidth() - rect.width - rect.x;

    if (index == 0 && (parent.style & SWT.CHECK) != 0) {
      if (OS.GTK_VERSION >= OS.VERSION(2, 1, 3)) {
        int[] x = new int[1], w = new int[1];
        OS.gtk_tree_view_column_cell_get_position(column, parent.checkRenderer, x, w);
        rect.x += x[0] + w[0];
        rect.width -= x[0] + w[0];
      } else {
        int[] w = new int[1];
        OS.gtk_cell_renderer_get_size(
            parent.checkRenderer, parentHandle, null, null, null, w, null);
        int[] buffer = new int[1];
        OS.gtk_widget_style_get(parentHandle, OS.horizontal_separator, buffer, 0);
        rect.x += w[0] + buffer[0];
        rect.width -= w[0] + buffer[0];
      }
    }
    int width = OS.gtk_tree_view_column_get_visible(column) ? rect.width + 1 : 0;
    return new Rectangle(rect.x, rect.y, width, rect.height + 1);
  }
Esempio n. 9
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));
 }
Esempio n. 10
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;
 }
Esempio n. 11
0
 /**
  * Returns the font that the receiver will use to paint textual information for this item.
  *
  * @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() {
   checkWidget();
   if (!parent.checkData(this)) error(SWT.ERROR_WIDGET_DISPOSED);
   return font != null ? font : parent.getFont();
 }
Esempio n. 12
0
  /**
   * Returns a rectangle describing the size and location relative to its parent of the text at a
   * column in the table. An empty rectangle is returned if index exceeds the index of the table's
   * last column.
   *
   * @param index the index that specifies the column
   * @return the receiver's bounding text 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>
   *
   * @since 3.3
   */
  public Rectangle getTextBounds(int index) {
    checkWidget();
    if (!parent.checkData(this)) error(SWT.ERROR_WIDGET_DISPOSED);
    int count = Math.max(1, parent.getColumnCount());
    if (0 > index || index > count - 1) return new Rectangle(0, 0, 0, 0);
    // TODO fully test on early and later versions of GTK
    // shifted a bit too far right on later versions of GTK - however, old Tree also had this
    // problem
    int /*long*/ parentHandle = parent.handle;
    int /*long*/ column = 0;
    if (index >= 0 && index < parent.columnCount) {
      column = parent.columns[index].handle;
    } else {
      column = OS.gtk_tree_view_get_column(parentHandle, index);
    }
    if (column == 0) return new Rectangle(0, 0, 0, 0);
    int /*long*/ textRenderer = parent.getTextRenderer(column);
    int /*long*/ pixbufRenderer = parent.getPixbufRenderer(column);
    if (textRenderer == 0 || pixbufRenderer == 0) return new Rectangle(0, 0, 0, 0);

    int /*long*/ path = OS.gtk_tree_model_get_path(parent.modelHandle, handle);
    OS.gtk_widget_realize(parentHandle);

    boolean isExpander = OS.gtk_tree_model_iter_n_children(parent.modelHandle, handle) > 0;
    boolean isExpanded = OS.gtk_tree_view_row_expanded(parentHandle, path);
    OS.gtk_tree_view_column_cell_set_cell_data(
        column, parent.modelHandle, handle, isExpander, isExpanded);

    GdkRectangle rect = new GdkRectangle();
    OS.gtk_tree_view_get_cell_area(parentHandle, path, column, rect);
    OS.gtk_tree_path_free(path);
    if ((parent.getStyle() & SWT.MIRRORED) != 0)
      rect.x = parent.getClientWidth() - rect.width - rect.x;
    int right = rect.x + rect.width;

    int[] x = new int[1], w = new int[1];
    parent.ignoreSize = true;
    OS.gtk_cell_renderer_get_size(textRenderer, parentHandle, null, null, null, w, null);
    parent.ignoreSize = false;
    int[] buffer = new int[1];
    if (OS.gtk_tree_view_get_expander_column(parentHandle) == column) {
      OS.gtk_widget_style_get(parentHandle, OS.expander_size, buffer, 0);
      rect.x += buffer[0] + TreeItem.EXPANDER_EXTRA_PADDING;
    }
    OS.gtk_widget_style_get(parentHandle, OS.horizontal_separator, buffer, 0);
    int horizontalSeparator = buffer[0];
    rect.x += horizontalSeparator;

    if (OS.GTK_VERSION >= OS.VERSION(2, 1, 3)) {
      OS.gtk_tree_view_column_cell_get_position(column, textRenderer, x, null);
      rect.x += x[0];
    } else {
      if ((parent.style & SWT.CHECK) != 0) {
        OS.gtk_cell_renderer_get_size(
            parent.checkRenderer, parentHandle, null, null, null, w, null);
        rect.x += w[0] + horizontalSeparator;
      }
      OS.gtk_cell_renderer_get_size(pixbufRenderer, parentHandle, null, null, null, w, null);
      rect.x += w[0] + horizontalSeparator;
    }
    if (parent.columnCount > 0) {
      if (rect.x + rect.width > right) {
        rect.width = Math.max(0, right - rect.x);
      }
    }
    int width = OS.gtk_tree_view_column_get_visible(column) ? rect.width + 1 : 0;
    return new Rectangle(rect.x, rect.y, width, rect.height + 1);
  }
Esempio n. 13
0
 /**
  * Returns the text stored at the given column index in the receiver, or empty string if the text
  * has not been set.
  *
  * @param index the column index
  * @return the text stored at the given column index in the receiver
  * @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 String getText(int index) {
   checkWidget();
   if (!parent.checkData(this)) error(SWT.ERROR_WIDGET_DISPOSED);
   return _getText(index);
 }
Esempio n. 14
0
 /**
  * Gets the image indent.
  *
  * @return the indent
  * @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 int getImageIndent() {
   checkWidget();
   if (!parent.checkData(this)) error(SWT.ERROR_WIDGET_DISPOSED);
   /* Image indent is not supported on GTK */
   return 0;
 }
Esempio n. 15
0
 /**
  * Returns the image stored at the given column index in the receiver, or null if the image has
  * not been set or if the column does not exist.
  *
  * @param index the column index
  * @return the image stored at the given column index in the receiver
  * @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 Image getImage(int index) {
   checkWidget();
   if (!parent.checkData(this)) error(SWT.ERROR_WIDGET_DISPOSED);
   return _getImage(index);
 }
Esempio n. 16
0
 /**
  * Returns <code>true</code> if the receiver is grayed, and false otherwise. When the parent does
  * not have the <code>CHECK</code> style, return false.
  *
  * @return the grayed state of the checkbox
  * @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 boolean getGrayed() {
   checkWidget();
   if (!parent.checkData(this)) error(SWT.ERROR_WIDGET_DISPOSED);
   if ((parent.style & SWT.CHECK) == 0) return false;
   return grayed;
 }
Esempio n. 17
0
 /**
  * Returns the foreground color at the given column index in the receiver.
  *
  * @param index the column index
  * @return the foreground color
  * @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 Color getForeground(int index) {
   checkWidget();
   if (!parent.checkData(this)) error(SWT.ERROR_WIDGET_DISPOSED);
   return _getForeground(index);
 }
Esempio n. 18
0
 /**
  * Returns the receiver's background color.
  *
  * @return the background color
  * @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 2.0
  */
 public Color getBackground() {
   checkWidget();
   if (!parent.checkData(this)) error(SWT.ERROR_WIDGET_DISPOSED);
   return _getBackground();
 }
Esempio n. 19
0
 void destroyWidget() {
   parent.destroyItem(this);
   releaseHandle();
 }