Esempio n. 1
0
 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;
 }
 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);
 }
Esempio n. 3
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);
  }