Exemplo n.º 1
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.º 2
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.º 3
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.º 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];
 }
Exemplo n.º 5
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.º 6
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.º 7
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.º 8
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.º 9
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.º 10
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.º 11
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.º 12
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);
    }
  }
Exemplo n.º 13
0
 void scrollInPixels(int destX, int destY, int x, int y, int width, int height, boolean all) {
   forceResize();
   boolean isFocus = caret != null && caret.isFocusCaret();
   if (isFocus) caret.killFocus();
   RECT sourceRect = new RECT();
   OS.SetRect(sourceRect, x, y, x + width, y + height);
   RECT clientRect = new RECT();
   OS.GetClientRect(handle, clientRect);
   if (OS.IntersectRect(clientRect, sourceRect, clientRect)) {
     if (OS.IsWinCE) {
       OS.UpdateWindow(handle);
     } else {
       int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN;
       OS.RedrawWindow(handle, null, 0, flags);
     }
   }
   int deltaX = destX - x, deltaY = destY - y;
   if (findImageControl() != null) {
     if (OS.IsWinCE) {
       OS.InvalidateRect(handle, sourceRect, true);
     } else {
       int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE;
       if (all) flags |= OS.RDW_ALLCHILDREN;
       OS.RedrawWindow(handle, sourceRect, 0, flags);
     }
     OS.OffsetRect(sourceRect, deltaX, deltaY);
     if (OS.IsWinCE) {
       OS.InvalidateRect(handle, sourceRect, true);
     } else {
       int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE;
       if (all) flags |= OS.RDW_ALLCHILDREN;
       OS.RedrawWindow(handle, sourceRect, 0, flags);
     }
   } else {
     int flags = OS.SW_INVALIDATE | OS.SW_ERASE;
     /*
      * Feature in Windows.  If any child in the widget tree partially
      * intersects the scrolling rectangle, Windows moves the child
      * and copies the bits that intersect the scrolling rectangle but
      * does not redraw the child.
      *
      * Feature in Windows.  When any child in the widget tree does not
      * intersect the scrolling rectangle but the parent does intersect,
      * Windows does not move the child.  This is the documented (but
      * strange) Windows behavior.
      *
      * The fix is to not use SW_SCROLLCHILDREN and move the children
      * explicitly after scrolling.
      */
     //		if (all) flags |= OS.SW_SCROLLCHILDREN;
     OS.ScrollWindowEx(handle, deltaX, deltaY, sourceRect, null, 0, null, flags);
   }
   if (all) {
     Control[] children = _getChildren();
     for (int i = 0; i < children.length; i++) {
       Control child = children[i];
       Rectangle rect = child.getBoundsInPixels();
       if (Math.min(x + width, rect.x + rect.width) >= Math.max(x, rect.x)
           && Math.min(y + height, rect.y + rect.height) >= Math.max(y, rect.y)) {
         child.setLocationInPixels(rect.x + deltaX, rect.y + deltaY);
       }
     }
   }
   if (isFocus) caret.setFocus();
 }
Exemplo n.º 14
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);
  }