void computeSize(Control control, int wHint, int hHint, boolean flushCache) {
   if (cacheWidth != -1 && cacheHeight != -1) return;
   if (wHint == this.widthHint && hHint == this.heightHint) {
     if (defaultWidth == -1
         || defaultHeight == -1
         || wHint != defaultWhint
         || hHint != defaultHhint) {
       Point size = control.computeSize(wHint, hHint, flushCache);
       defaultWhint = wHint;
       defaultHhint = hHint;
       defaultWidth = size.x;
       defaultHeight = size.y;
     }
     cacheWidth = defaultWidth;
     cacheHeight = defaultHeight;
     return;
   }
   if (currentWidth == -1
       || currentHeight == -1
       || wHint != currentWhint
       || hHint != currentHhint) {
     Point size = control.computeSize(wHint, hHint, flushCache);
     currentWhint = wHint;
     currentHhint = hHint;
     currentWidth = size.x;
     currentHeight = size.y;
   }
   cacheWidth = currentWidth;
   cacheHeight = currentHeight;
 }
Beispiel #2
0
  /* (non-Javadoc)
   * @see org.eclipse.swt.widgets.Layout#computeSize(org.eclipse.swt.widgets.Composite, int, int, boolean)
   */
  @Override
  protected Point computeSize(Composite composite, int whint, int hhint, boolean flushCache) {
    int minX = Integer.MAX_VALUE;
    int minY = Integer.MAX_VALUE;
    int maxX = Integer.MIN_VALUE;
    int maxY = Integer.MIN_VALUE;

    for (Control kid : composite.getChildren()) {
      Point kidSize = kid.computeSize(-1, -1);
      Point kidOffs = kid.getLocation();
      if (kidOffs.x < minX) minX = kidOffs.x;
      if (kidOffs.y < minY) minY = kidOffs.y;
      if (kidOffs.x + kidSize.x > maxX) maxX = kidOffs.x + kidSize.x;
      if (kidOffs.y + kidSize.y > maxY) maxY = kidOffs.y + kidSize.y;
    }

    if (whint > 0) {
      if (whint + minX > maxX) maxX = whint + minX;
    }
    if (hhint > 0) {
      if (hhint + minY > maxY) maxY = hhint + minY;
    }

    return new Point(maxX - minX, maxY - minY);
  }
  private void turnToPage(SelectionEvent event) {
    final TabItem item = (TabItem) event.item;
    TabFolder folder = item.getParent();

    SearchPageDescriptor descriptor =
        (SearchPageDescriptor) item.getData("descriptor"); // $NON-NLS-1$

    if (item.getControl() == null) {
      item.setControl(createPageControl(folder, descriptor));
    }

    Control oldControl = folder.getItem(fCurrentIndex).getControl();
    Point oldSize = oldControl.getSize();
    Control newControl = item.getControl();
    Point newSize = newControl.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    resizeDialogIfNeeded(oldSize, newSize);

    ISearchPage oldPage = fCurrentPage;
    if (oldPage != null) {
      oldPage.setVisible(false);
    }

    fCurrentPage = descriptor.getPage();
    fDialogSettings.put(STORE_PREVIOUS_PAGE, descriptor.getId());
    fCurrentIndex = folder.getSelectionIndex();

    setPerformActionEnabled(fCurrentPage != null);
    if (fCurrentPage != null) {
      fCurrentPage.setVisible(true);
      Control pageControl = fCurrentPage.getControl();
      if (pageControl instanceof Composite) ((Composite) pageControl).layout(false, true);
    }
    fReplaceButton.setVisible(fCurrentPage instanceof IReplacePage);
    notifyPageChanged();
  }
Beispiel #4
0
 protected Point getObjectSize(Hashtable resourceTable, int wHint) {
   Control control = getControl(resourceTable);
   if (control == null) return new Point(0, 0);
   int realWhint = FormUtil.getWidthHint(wHint, control);
   Point size = control.computeSize(realWhint, SWT.DEFAULT);
   if (realWhint != SWT.DEFAULT && fill) size.x = Math.max(size.x, realWhint);
   if (width != SWT.DEFAULT) size.x = width;
   if (height != SWT.DEFAULT) size.y = height;
   return size;
 }
Beispiel #5
0
 /**
  * Computes the ideal render widths of non-{@link ChatLine}s and returns the maximum.
  *
  * @return the maximum ideal render width of all non-{@link ChatLine}s
  */
 protected int computeMaxNonChatLineWidth() {
   int maxNonChatLineWidth = 0;
   for (Control chatItem : getChatItems()) {
     if (!(chatItem instanceof ChatLine)) {
       int currentNonChatLineWidth = chatItem.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
       maxNonChatLineWidth = Math.max(currentNonChatLineWidth, maxNonChatLineWidth);
     }
   }
   return maxNonChatLineWidth;
 }
 private void setFont(Composite composite, Font font) {
   for (Control control : composite.getChildren()) {
     if (control instanceof Composite) {
       setFont((Composite) control, font);
     } else {
       control.setFont(font);
       control.setSize(control.computeSize(SWT.DEFAULT, SWT.DEFAULT));
     }
   }
 }
 // Debugging utilities for widget trees.
 public static void check(Control control) {
   String name = control.getClass().getSimpleName();
   if (control.isDisposed()) {
     System.err.println(name + " disposed!");
     return;
   }
   if (control instanceof Composite) {
     ((Composite) control).layout(true);
   }
   control.computeSize(SWT.DEFAULT, SWT.DEFAULT);
   Point sz = control.getSize();
   if (sz.x == 0 || sz.y == 0) System.err.println(name + " zero size!");
 }
  /**
   * Get an Image of the page. The Image is build from the Control.
   *
   * @param The IPage for which an Image is requested.
   * @return The Image of the page, or null if no Image can be built.
   */
  public static Image getPageImage(IPage page) {
    Rectangle size;
    Control control = page.getControl();

    size = control.getBounds();
    if (size.width == 0 && size.height == 0) {
      Point pt = control.computeSize(SWT.DEFAULT, SWT.DEFAULT);
      size = new Rectangle(0, 0, pt.x, pt.y);
    }

    Image image = new Image(control.getDisplay(), size);
    GC gc = new GC(image);

    boolean success = control.print(gc);
    gc.dispose();
    if (!success) {
      image.dispose();
      return null;
    }

    return image;
  }
Beispiel #9
0
  /**
   * Evaluates each of the controls and determines the largest width. Then sets each control with
   * the largest width. Each control must have a GridData as its layout data
   *
   * @param controls
   */
  public static void resizeControlWidthInGrid(Collection<Control> controls) {
    int largestWidth = SWT.DEFAULT;
    List<GridData> gridDatas = new ArrayList<GridData>();
    for (Control control : controls) {
      Object layoutData = control.getLayoutData();
      if (layoutData instanceof GridData) {
        GridData gridData = (GridData) layoutData;
        gridDatas.add(gridData);

        if (gridData.widthHint > largestWidth) {
          largestWidth = gridData.widthHint;
        } else {
          int preferredX = control.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
          if (preferredX > largestWidth) {
            largestWidth = preferredX;
          }
        }
      }
    }

    for (GridData gridData : gridDatas) {
      gridData.widthHint = largestWidth;
    }
  }
Beispiel #10
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);
  }
Beispiel #11
0
 protected Point getSize(Control control, boolean flushCache) {
   return control.computeSize(SWT.DEFAULT, SWT.DEFAULT, flushCache);
 }
Beispiel #12
0
 /**
  * Calculates and sets the size of the given cool item.
  *
  * @param item item of cool bar
  */
 private void calcSize(final CoolItem item) {
   final Control control = item.getControl();
   Point pt = control.computeSize(SWT.DEFAULT, SWT.DEFAULT);
   pt = item.computeSize(pt.x, pt.y);
   item.setSize(pt);
 }
Beispiel #13
0
 public Dimension getPreferredSize(int wHint, int hHint) {
   Point p = control.computeSize(wHint, hHint);
   return new Dimension(p.x, p.y);
 }
 public static void resize(Control ctrl) {
   Point ns = ctrl.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
   Point cs = ctrl.getSize();
   if (!cs.equals(ns)) ctrl.setSize(ns);
 }
 /**
  * Computes the width required by control.
  *
  * @param control The control to compute width
  * @return int The width required
  */
 protected int computeWidth(final Control control) {
   return control.computeSize(100, 20, true).x;
 }