示例#1
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);
 }
示例#2
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);
  }
 long /*int*/ childStyle() {
   long /*int*/ rcStyle = OS.gtk_widget_get_modifier_style(handle);
   if ((OS.gtk_rc_style_get_color_flags(rcStyle, 0) & OS.GTK_RC_BG) != 0) return 0;
   OS.gtk_widget_realize(handle);
   return OS.gtk_widget_get_style(handle);
 }
示例#4
0
  /**
   * Create a GLCanvas widget using the attributes described in the GLData object provided.
   *
   * @param parent a composite widget
   * @param style the bitwise OR'ing of widget styles
   * @param data the requested attributes of the GLCanvas
   * @exception IllegalArgumentException
   *     <ul>
   *       <li>ERROR_NULL_ARGUMENT when the data is null
   *       <li>ERROR_UNSUPPORTED_DEPTH when the requested attributes cannot be provided
   *     </ul>
   *     </ul>
   */
  public GLCanvas(Composite parent, int style, GLData data) {
    super(parent, style);
    if (data == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
    int glxAttrib[] = new int[MAX_ATTRIBUTES];
    int pos = 0;
    glxAttrib[pos++] = GLX.GLX_RGBA;
    if (data.doubleBuffer) glxAttrib[pos++] = GLX.GLX_DOUBLEBUFFER;
    if (data.stereo) glxAttrib[pos++] = GLX.GLX_STEREO;
    if (data.redSize > 0) {
      glxAttrib[pos++] = GLX.GLX_RED_SIZE;
      glxAttrib[pos++] = data.redSize;
    }
    if (data.greenSize > 0) {
      glxAttrib[pos++] = GLX.GLX_GREEN_SIZE;
      glxAttrib[pos++] = data.greenSize;
    }
    if (data.blueSize > 0) {
      glxAttrib[pos++] = GLX.GLX_BLUE_SIZE;
      glxAttrib[pos++] = data.blueSize;
    }
    if (data.alphaSize > 0) {
      glxAttrib[pos++] = GLX.GLX_ALPHA_SIZE;
      glxAttrib[pos++] = data.alphaSize;
    }
    if (data.depthSize > 0) {
      glxAttrib[pos++] = GLX.GLX_DEPTH_SIZE;
      glxAttrib[pos++] = data.depthSize;
    }
    if (data.stencilSize > 0) {
      glxAttrib[pos++] = GLX.GLX_STENCIL_SIZE;
      glxAttrib[pos++] = data.stencilSize;
    }
    if (data.accumRedSize > 0) {
      glxAttrib[pos++] = GLX.GLX_ACCUM_RED_SIZE;
      glxAttrib[pos++] = data.accumRedSize;
    }
    if (data.accumGreenSize > 0) {
      glxAttrib[pos++] = GLX.GLX_ACCUM_GREEN_SIZE;
      glxAttrib[pos++] = data.accumGreenSize;
    }
    if (data.accumBlueSize > 0) {
      glxAttrib[pos++] = GLX.GLX_ACCUM_BLUE_SIZE;
      glxAttrib[pos++] = data.accumBlueSize;
    }
    if (data.accumAlphaSize > 0) {
      glxAttrib[pos++] = GLX.GLX_ACCUM_ALPHA_SIZE;
      glxAttrib[pos++] = data.accumAlphaSize;
    }
    if (data.sampleBuffers > 0) {
      glxAttrib[pos++] = GLX.GLX_SAMPLE_BUFFERS;
      glxAttrib[pos++] = data.sampleBuffers;
    }
    if (data.samples > 0) {
      glxAttrib[pos++] = GLX.GLX_SAMPLES;
      glxAttrib[pos++] = data.samples;
    }
    glxAttrib[pos++] = 0;
    OS.gtk_widget_realize(handle);
    int /*long*/ window = OS.GTK_WIDGET_WINDOW(handle);
    int /*long*/ xDisplay = OS.gdk_x11_drawable_get_xdisplay(window);
    int /*long*/ infoPtr = GLX.glXChooseVisual(xDisplay, OS.XDefaultScreen(xDisplay), glxAttrib);
    if (infoPtr == 0) {
      dispose();
      SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
    }
    vinfo = new XVisualInfo();
    GLX.memmove(vinfo, infoPtr, XVisualInfo.sizeof);
    OS.XFree(infoPtr);
    int /*long*/ screen = OS.gdk_screen_get_default();
    int /*long*/ gdkvisual = OS.gdk_x11_screen_lookup_visual(screen, vinfo.visualid);
    // FIXME- share lists
    // context = GLX.glXCreateContext (xDisplay, info, share == null ? 0 : share.context, true);
    context = GLX.glXCreateContext(xDisplay, vinfo, 0, true);
    if (context == 0) SWT.error(SWT.ERROR_NO_HANDLES);
    GdkWindowAttr attrs = new GdkWindowAttr();
    attrs.width = 1;
    attrs.height = 1;
    attrs.event_mask =
        OS.GDK_KEY_PRESS_MASK
            | OS.GDK_KEY_RELEASE_MASK
            | OS.GDK_FOCUS_CHANGE_MASK
            | OS.GDK_POINTER_MOTION_MASK
            | OS.GDK_BUTTON_PRESS_MASK
            | OS.GDK_BUTTON_RELEASE_MASK
            | OS.GDK_ENTER_NOTIFY_MASK
            | OS.GDK_LEAVE_NOTIFY_MASK
            | OS.GDK_EXPOSURE_MASK
            | OS.GDK_VISIBILITY_NOTIFY_MASK
            | OS.GDK_POINTER_MOTION_HINT_MASK;
    attrs.window_type = OS.GDK_WINDOW_CHILD;
    attrs.visual = gdkvisual;
    glWindow = OS.gdk_window_new(window, attrs, OS.GDK_WA_VISUAL);
    OS.gdk_window_set_user_data(glWindow, handle);
    if ((style & SWT.NO_BACKGROUND) != 0) OS.gdk_window_set_back_pixmap(window, 0, false);
    xWindow = OS.gdk_x11_drawable_get_xid(glWindow);
    OS.gdk_window_show(glWindow);

    Listener listener =
        new Listener() {
          public void handleEvent(Event event) {
            switch (event.type) {
              case SWT.Paint:
                /**
                 * Bug in MESA. MESA does some nasty sort of polling to try and ensure that their
                 * buffer sizes match the current X state. This state can be updated using
                 * glViewport(). FIXME: There has to be a better way of doing this.
                 */
                int[] viewport = new int[4];
                GLX.glGetIntegerv(GLX.GL_VIEWPORT, viewport);
                GLX.glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
                break;
              case SWT.Resize:
                Rectangle clientArea = getClientArea();
                OS.gdk_window_move(glWindow, clientArea.x, clientArea.y);
                OS.gdk_window_resize(glWindow, clientArea.width, clientArea.height);
                break;
              case SWT.Dispose:
                int /*long*/ window = OS.GTK_WIDGET_WINDOW(handle);
                int /*long*/ xDisplay = OS.gdk_x11_drawable_get_xdisplay(window);
                if (context != 0) {
                  if (GLX.glXGetCurrentContext() == context) {
                    GLX.glXMakeCurrent(xDisplay, 0, 0);
                  }
                  GLX.glXDestroyContext(xDisplay, context);
                  context = 0;
                }
                if (glWindow != 0) {
                  OS.gdk_window_destroy(glWindow);
                  glWindow = 0;
                }
                break;
            }
          }
        };
    addListener(SWT.Resize, listener);
    addListener(SWT.Paint, listener);
    addListener(SWT.Dispose, listener);
  }
示例#5
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);
  }