org.eclipse.swt.win32.win32.x86_3.7.2.v3740f

(CTabFolder2Listener listener)
  {
    checkWidget();
    if (listener == null) {
      SWT.error(4);
    }
    CTabFolder2Listener[] newListeners = new CTabFolder2Listener[folderListeners.length + 1];
    System.arraycopy(folderListeners, 0, newListeners, 0, folderListeners.length);
    folderListeners = newListeners;
    folderListeners[(folderListeners.length - 1)] = listener;
  }
  
  /**
   * @deprecated
   */
  public void addCTabFolderListener(CTabFolderListener listener)
  {
    checkWidget();
    if (listener == null) {
      SWT.error(4);
    }
    CTabFolderListener[] newTabListeners = new CTabFolderListener[tabListeners.length + 1];
    System.arraycopy(tabListeners, 0, newTabListeners, 0, tabListeners.length);
    tabListeners = newTabListeners;
    tabListeners[(tabListeners.length - 1)] = listener;
    if (!showClose)
    {
      showClose = true;
      updateItems();
      redraw();
    }
  }
  
  public void addSelectionListener(SelectionListener listener)
  {
    checkWidget();
    if (listener == null) {
      SWT.error(4);
    }
    TypedListener typedListener = new TypedListener(listener);
    addListener(13, typedListener);
    addListener(14, typedListener);
  }
  
  public Rectangle computeTrim(int x, int y, int width, int height)
  {
    checkWidget();
    return renderer.computeTrim(-1, 0, x, y, width, height);
  }
  
  void createItem(CTabItem item, int index)
  {
    if ((index < 0) || (index > getItemCount())) {
      SWT.error(6);
    }
    parent = this;
    CTabItem[] newItems = new CTabItem[items.length + 1];
    System.arraycopy(items, 0, newItems, 0, index);
    newItems[index] = item;
    System.arraycopy(items, index, newItems, index + 1, items.length - index);
    items = newItems;
    if (selectedIndex >= index) {
      selectedIndex += 1;
    }
    int[] newPriority = new int[priority.length + 1];
    int next = 0;int priorityIndex = priority.length;
    for (int i = 0; i < priority.length; i++)
    {
      if ((!mru) && (priority[i] == index)) {
        priorityIndex = next++;
      }
      newPriority[(next++)] = (priority[i] >= index ? priority[i] + 1 : priority[i]);
    }
    newPriority[priorityIndex] = index;
    priority = newPriority;
    if (items.length == 1)
    {
      if (!updateTabHeight(false)) {
        updateItems();
      }
      redraw();
    }
    else
    {
      updateItems();
      redrawTabs();
    }
  }
  
  void destroyItem(CTabItem item)
  {
    if (inDispose) {
      return;
    }
    int index = indexOf(item);
    if (index == -1) {
      return;
    }
    if (items.length == 1)
    {
      items = new CTabItem[0];
      priority = new int[0];
      firstIndex = -1;
      selectedIndex = -1;
      
      Control control = item.getControl();
      if ((control != null) && (!control.isDisposed())) {
        control.setVisible(false);
      }
      setToolTipText(null);
      GC gc = new GC(this);
      setButtonBounds(gc);
      gc.dispose();
      redraw();
      return;
    }
    CTabItem[] newItems = new CTabItem[items.length - 1];
    System.arraycopy(items, 0, newItems, 0, index);
    System.arraycopy(items, index + 1, newItems, index, items.length - index - 1);
    items = newItems;
    
    int[] newPriority = new int[priority.length - 1];
    int next = 0;
    for (int i = 0; i < priority.length; i++) {
      if (priority[i] != index) {
        newPriority[(next++)] = (priority[i] > index ? priority[i] - 1 : priority[i]);
      }
    }
    priority = newPriority;
    if (selectedIndex == index)
    {
      Control control = item.getControl();
      selectedIndex = -1;
      int nextSelection = mru ? priority[0] : Math.max(0, index - 1);
      setSelection(nextSelection, true);
      if ((control != null) && (!control.isDisposed())) {
        control.setVisible(false);
      }
    }
    else if (selectedIndex > index)
    {
      selectedIndex -= 1;
    }
    updateItems();
    redrawTabs();
  }
  
  public boolean getBorderVisible()
  {
    checkWidget();
    return borderVisible;
  }
  
  public Rectangle getClientArea()
  {
    checkWidget();
    Rectangle trim = renderer.computeTrim(-1, 0, 0, 0, 0, 0);
    if (minimized) {
      return new Rectangle(-x, -y, 0, 0);
    }
    Point size = getSize();
    int width = x - width;
    int height = y - height;
    return new Rectangle(-x, -y, width, height);
  }
  
  public CTabItem getItem(int index)
  {
    if ((index < 0) || (index >= items.length)) {
      SWT.error(6);
    }
    return items[index];
  }
  
  public CTabItem getItem(Point pt)
  {
    if (items.length == 0) {
      return null;
    }
    Point size = getSize();
    Rectangle trim = renderer.computeTrim(-3, 0, 0, 0, 0, 0);
    if (x <= width) {
      return null;
    }
    if ((showChevron) && (chevronRect.contains(pt))) {
      return null;
    }
    for (int i = 0; i < priority.length; i++)
    {
      CTabItem item = items[priority[i]];
      Rectangle rect = item.getBounds();
      if (rect.contains(pt)) {
        return item;
      }
    }
    return null;
  }
  
  public int getItemCount()
  {
    return items.length;
  }
  
  public CTabItem[] getItems()
  {
    CTabItem[] tabItems = new CTabItem[items.length];
    System.arraycopy(items, 0, tabItems, 0, items.length);
    return tabItems;
  }
  
  char _findMnemonic(String string)
  {
    if (string == null) {
      return '\000';
    }
    int index = 0;
    int length = string.length();
    do
    {
      while ((index < length) && (string.charAt(index) != '&')) {
        index++;
      }
      index++;
      if (index >= length) {
        return '\000';
      }
      if (string.charAt(index) != '&') {
        return Character.toLowerCase(string.charAt(index));
      }
      index++;
    } while (index < length);
    return '\000';
  }
  
  String stripMnemonic(String string)
  {
    int index = 0;
    int length = string.length();
    do
    {
      while ((index < length) && (string.charAt(index) != '&')) {
        index++;
      }
      index++;
      if (index >= length) {
        return string;
      }
      if (string.charAt(index) != '&') {
        return string.substring(0, index - 1) + string.substring(index, length);
      }
      index++;
    } while (index < length);
    return string;
  }
  
  public boolean getMinimized()
  {
    checkWidget();
    return minimized;
  }
  
  public boolean getMinimizeVisible()
  {
    checkWidget();
    return showMin;
  }
  
  public int getMinimumCharacters()
  {
    checkWidget();
    return minChars;
  }
  
  public boolean getMaximized()
  {
    checkWidget();
    return maximized;
  }
  
  public boolean getMaximizeVisible()
  {
    checkWidget();
    return showMax;
  }
  
  public boolean getMRUVisible()
  {
    checkWidget();
    return mru;
  }
  
  public CTabFolderRenderer getRenderer()
  {
    checkWidget();
    return renderer;
  }
  
  int getRightItemEdge(GC gc)
  {
    Rectangle trim = renderer.computeTrim(-3, 0, 0, 0, 0, 0);
    int x = getSizex - (width + x) - 3;
    if (showMin) {
      x -= renderer.computeSize(-6, 0, gc, -1, -1).x;
    }
    if (showMax) {
      x -= renderer.computeSize(-5, 0, gc, -1, -1).x;
    }
    if (showChevron) {
      x -= renderer.computeSize(-7, 0, gc, -1, -1).x;
    }
    if ((topRight != null) && (topRightAlignment != 4))
    {
      Point rightSize = topRight.computeSize(-1, -1);
      x -= x + 3;
    }
    return Math.max(0, x);
  }
  
  public CTabItem getSelection()
  {
    if (selectedIndex == -1) {
      return null;
    }
    return items[selectedIndex];
  }
  
  public Color getSelectionBackground()
  {
    checkWidget();
    return selectionBackground;
  }
  
  public Color getSelectionForeground()
  {
    checkWidget();
    return selectionForeground;
  }
  
  public int getSelectionIndex()
  {
    return selectedIndex;
  }
  
  public boolean getSimple()
  {
    checkWidget();
    return simple;
  }
  
  public boolean getSingle()
  {
    checkWidget();
    return single;
  }
  
  public int getStyle()
  {
    int style = super.getStyle();
    style &= 0xFB7F;
    style |= (onBottom ? 1024 : 128);
    style &= 0xFFFFFFF9;
    style |= (single ? 4 : 2);
    if (borderVisible) {
      style |= 0x800;
    }
    style &= 0xFFFFFFBF;
    if (showClose) {
      style |= 0x40;
    }
    return style;
  }
  
  public int getTabHeight()
  {
    checkWidget();
    if (fixedTabHeight != -1) {
      return fixedTabHeight;
    }
    return tabHeight - 1;
  }
  
  public int getTabPosition()
  {
    checkWidget();
    return onBottom ? 1024 : 128;
  }
  
  public Control getTopRight()
  {
    checkWidget();
    return topRight;
  }
  
  public int getTopRightAlignment()
  {
    checkWidget();
    return topRightAlignment;
  }
  
  public boolean getUnselectedCloseVisible()
  {
    checkWidget();
    return showUnselectedClose;
  }
  
  public boolean getUnselectedImageVisible()
  {
    checkWidget();
    return showUnselectedImage;
  }
  
  public int indexOf(CTabItem item)
  {
    checkWidget();
    if (item == null) {
      SWT.error(4);
    }
    for (int i = 0; i < items.length; i++) {
      if (items[i] == item) {
        return i;
      }
    }
    return -1;
  }
  
  void initAccessible()
  {
    Accessible accessible = getAccessible();
    accessible.addAccessibleListener(new AccessibleAdapter()
    {
      public void getName(AccessibleEvent e)
      {
        String name = null;
        int childID = childID;
        if ((childID >= 0) && (childID < items.length)) {
          name = stripMnemonic(items[childID].getText());
        } else if (childID == items.length + 0) {
          name = SWT.getMessage("SWT_ShowList");
        } else if (childID == items.length + 1) {
          name = minimized ? SWT.getMessage("SWT_Restore") : SWT.getMessage("SWT_Minimize");
        } else if (childID == items.length + 2) {
          name = maximized ? SWT.getMessage("SWT_Restore") : SWT.getMessage("SWT_Maximize");
        }
        result = name;
      }
      
      public void getHelp(AccessibleEvent e)
      {
        String help = null;
        int childID = childID;
        if (childID == -1) {
          help = getToolTipText();
        } else if ((childID >= 0) && (childID < items.length)) {
          help = items[childID].getToolTipText();
        }
        result = help;
      }
      
      public void getKeyboardShortcut(AccessibleEvent e)
      {
        String shortcut = null;
        int childID = childID;
        if ((childID >= 0) && (childID < items.length))
        {
          String text = items[childID].getText();
          if (text != null)
          {
            char mnemonic = _findMnemonic(text);
            if (mnemonic != 0) {
              shortcut = "Alt+" + mnemonic;
            }
          }
        }
        if (childID == -1) {
          shortcut = "Ctrl+PageDown";
        }
        result = shortcut;
      }
    });
    accessible.addAccessibleControlListener(new AccessibleControlAdapter()
    {
      public void getChildAtPoint(AccessibleControlEvent e)
      {
        Point testPoint = toControl(x, y);
        int childID = -2;
        for (int i = 0; i < items.length; i++) {
          if (items[i].getBounds().contains(testPoint))
          {
            childID = i;
            break;
          }
        }
        if (childID == -2) {
          if ((showChevron) && (chevronRect.contains(testPoint)))
          {
            childID = items.length + 0;
          }
          else if ((showMin) && (minRect.contains(testPoint)))
          {
            childID = items.length + 1;
          }
          else if ((showMax) && (maxRect.contains(testPoint)))
          {
            childID = items.length + 2;
          }
          else
          {
            Rectangle location = getBounds();
            x = (y = 0);
            height -= getClientArea().height;
            if (location.contains(testPoint)) {
              childID = -1;
            }
          }
        }
        childID = childID;
      }
      
      public void getLocation(AccessibleControlEvent e)
      {
        Rectangle location = null;
        Point pt = null;
        int childID = childID;
        if (childID == -1)
        {
          location = getBounds();
          pt = getParent().toDisplay(x, y);
        }
        else
        {
          if ((childID >= 0) && (childID < items.length) && (items[childID].isShowing())) {
            location = items[childID].getBounds();
          } else if ((showChevron) && (childID == items.length + 0)) {
            location = chevronRect;
          } else if ((showMin) && (childID == items.length + 1)) {
            location = minRect;
          } else if ((showMax) && (childID == items.length + 2)) {
            location = maxRect;
          }
          if (location != null) {
            pt = toDisplay(x, y);
          }
        }
        if ((location != null) && (pt != null))
        {
          x = x;
          y = y;
          width = width;
          height = height;
        }
      }
      
      public void getChildCount(AccessibleControlEvent e)
      {
        detail = (items.length + 3);
      }
      
      public void getDefaultAction(AccessibleControlEvent e)
      {
        String action = null;
        int childID = childID;
        if ((childID >= 0) && (childID < items.length)) {
          action = SWT.getMessage("SWT_Switch");
        }
        if ((childID >= items.length) && (childID < items.length + 3)) {
          action = SWT.getMessage("SWT_Press");
        }
        result = action;
      }
      
      public void getFocus(AccessibleControlEvent e)
      {
        int childID = -2;
        if (isFocusControl()) {
          if (selectedIndex == -1) {
            childID = -1;
          } else {
            childID = selectedIndex;
          }
        }
        childID = childID;
      }
      
      public void getRole(AccessibleControlEvent e)
      {
        int role = 0;
        int childID = childID;
        if (childID == -1) {
          role = 60;
        } else if ((childID >= 0) && (childID < items.length)) {
          role = 37;
        } else if ((childID >= items.length) && (childID < items.length + 3)) {
          role = 43;
        }
        detail = role;
      }
      
      public void getSelection(AccessibleControlEvent e)
      {
        childID = (selectedIndex == -1 ? -2 : selectedIndex);
      }
      
      public void getState(AccessibleControlEvent e)
      {
        int state = 0;
        int childID = childID;
        if (childID == -1)
        {
          state = 0;
        }
        else if ((childID >= 0) && (childID < items.length))
        {
          state = 2097152;
          if (isFocusControl()) {
            state |= 0x100000;
          }
          if (selectedIndex == childID)
          {
            state |= 0x2;
            if (isFocusControl()) {
              state |= 0x4;
            }
          }
        }
        else if (childID == items.length + 0)
        {
          state = showChevron ? 0 : 32768;
        }
        else if (childID == items.length + 1)
        {
          state = showMin ? 0 : 32768;
        }
        else if (childID == items.length + 2)
        {
          state = showMax ? 0 : 32768;
        }
        detail = state;
      }
      
      public void getChildren(AccessibleControlEvent e)
      {
        int childIdCount = items.length + 3;
        Object[] children = new Object[childIdCount];
        for (int i = 0; i < childIdCount; i++) {
          children[i] = new Integer(i);
        }
        children = children;
      }
    });
    addListener(13, new Listener()
    {
      private final Accessible val$accessible;
      
      public void handleEvent(Event event)
      {
        if (isFocusControl()) {
          if (selectedIndex == -1) {
            val$accessible.setFocus(-1);
          } else {
            val$accessible.setFocus(selectedIndex);
          }
        }
      }
    });
    addListener(15, new Listener()
    {
      private final Accessible val$accessible;
      
      public void handleEvent(Event event)
      {
        if (selectedIndex == -1) {
          val$accessible.setFocus(-1);
        } else {
          val$accessible.setFocus(selectedIndex);
        }
      }
    });
  }
  
  void onKeyDown(Event event)
  {
    switch (keyCode)
    {
    case 16777219: 
    case 16777220: 
      int count = items.length;
      if (count == 0) {
        return;
      }
      if (selectedIndex == -1) {
        return;
      }
      int leadKey = (getStyle() & 0x4000000) != 0 ? 16777220 : 16777219;
      int offset = keyCode == leadKey ? -1 : 1;
      int index;
      if (!mru)
      {
        index = selectedIndex + offset;
      }
      else
      {
        int[] visible = new int[items.length];
        int idx = 0;
        int current = -1;
        for (int i = 0; i < items.length; i++) {
          if (items[i].showing)
          {
            if (i == selectedIndex) {
              current = idx;
            }
            visible[(idx++)] = i;
          }
        }
        int index;
        if ((current + offset >= 0) && (current + offset < idx))
        {
          index = visible[(current + offset)];
        }
        else
        {
          if (showChevron)
          {
            CTabFolderEvent e = new CTabFolderEvent(this);
            widget = this;
            time = time;
            x = chevronRect.x;
            y = chevronRect.y;
            width = chevronRect.width;
            height = chevronRect.height;
            doit = true;
            for (int i = 0; i < folderListeners.length; i++) {
              folderListeners[i].showList(e);
            }
            if ((doit) && (!isDisposed())) {
              showList(chevronRect);
            }
          }
          return;
        }
      }
      int index;
      if ((index < 0) || (index >= count)) {
        return;
      }
      setSelection(index, true);
      forceFocus();
    }
  }
  
  void onDispose(Event event)
  {
    removeListener(12, listener);
    notifyListeners(12, event);
    type = 0;
    
    inDispose = true;
    if ((showMenu != null) && (!showMenu.isDisposed()))
    {
      showMenu.dispose();
      showMenu = null;
    }
    int length = items.length;
    for (int i = 0; i < length; i++) {
      if (items[i] != null) {
        items[i].dispose();
      }
    }
    selectionGradientColors = null;
    selectionGradientPercents = null;
    selectionBgImage = null;
    
    selectionBackground = null;
    selectionForeground = null;
    if (renderer != null) {
      renderer.dispose();
    }
    renderer = null;
  }
  
  void onDragDetect(Event event)
  {
    boolean consume = false;
    if ((chevronRect.contains(x, y)) || 
      (minRect.contains(x, y)) || 
      (maxRect.contains(x, y))) {
      consume = true;
    } else {
      for (int i = 0; i < items.length; i++) {
        if (items[i].closeRect.contains(x, y))
        {
          consume = true;
          break;
        }
      }
    }
    if (consume) {
      type = 0;
    }
  }
  
  void onFocus(Event event)
  {
    checkWidget();
    if (selectedIndex >= 0) {
      redraw();
    } else {
      setSelection(0, true);
    }
  }
  
  boolean onMnemonic(Event event, boolean doit)
  {
    char key = character;
    for (int i = 0; i < items.length; i++) {
      if (items[i] != null)
      {
        char mnemonic = _findMnemonic(items[i].getText());
        if ((mnemonic != 0) && 
          (Character.toLowerCase(key) == mnemonic))
        {
          if (doit)
          {
            setSelection(i, true);
            forceFocus();
          }
          return true;
        }
      }
    }
    return false;
  }
  
  void onMouseDoubleClick(Event event)
  {
    if ((button != 1) || 
      ((stateMask & 0x100000) != 0) || 
      ((stateMask & 0x200000) != 0)) {
      return;
    }
    Event e = new Event();
    item = getItem(new Point(x, y));
    if (item != null) {
      notifyListeners(14, e);
    }
  }
  
  void onMouse(Event event)
  {
    int x = x;int y = y;
    switch (type)
    {
    case 6: 
      setToolTipText(null);
      break;
    case 7: 
      if (minImageState != 0)
      {
        minImageState = 0;
        redraw(minRect.x, minRect.y, minRect.width, minRect.height, false);
      }
      if (maxImageState != 0)
      {
        maxImageState = 0;
        redraw(maxRect.x, maxRect.y, maxRect.width, maxRect.height, false);
      }
      if (chevronImageState != 0)
      {
        chevronImageState = 0;
        redraw(chevronRect.x, chevronRect.y, chevronRect.width, chevronRect.height, false);
      }
      for (int i = 0; i < items.length; i++)
      {
        CTabItem item = items[i];
        if ((i != selectedIndex) && (closeImageState != 8))
        {
          closeImageState = 8;
          redraw(closeRect.x, closeRect.y, closeRect.width, closeRect.height, false);
        }
        if ((state & 0x20) != 0)
        {
          state &= 0xFFFFFFDF;
          redraw(x, y, width, height, false);
        }
        if ((i == selectedIndex) && (closeImageState != 0))
        {
          closeImageState = 0;
          redraw(closeRect.x, closeRect.y, closeRect.width, closeRect.height, false);
        }
      }
      break;
    case 3: 
      if (button != 1) {
        return;
      }
      if (minRect.contains(x, y))
      {
        minImageState = 2;
        redraw(minRect.x, minRect.y, minRect.width, minRect.height, false);
        update();
        return;
      }
      if (maxRect.contains(x, y))
      {
        maxImageState = 2;
        redraw(maxRect.x, maxRect.y, maxRect.width, maxRect.height, false);
        update();
        return;
      }
      if (chevronRect.contains(x, y))
      {
        if (chevronImageState != 32) {
          chevronImageState = 32;
        } else {
          chevronImageState = 2;
        }
        redraw(chevronRect.x, chevronRect.y, chevronRect.width, chevronRect.height, false);
        update();
        return;
      }
      CTabItem item = null;
      if (single)
      {
        if (selectedIndex != -1)
        {
          Rectangle bounds = items[selectedIndex].getBounds();
          if (bounds.contains(x, y)) {
            item = items[selectedIndex];
          }
        }
      }
      else {
        for (int i = 0; i < items.length; i++)
        {
          Rectangle bounds = items[i].getBounds();
          if (bounds.contains(x, y)) {
            item = items[i];
          }
        }
      }
      if (item != null)
      {
        if (closeRect.contains(x, y))
        {
          closeImageState = 2;
          redraw(closeRect.x, closeRect.y, closeRect.width, closeRect.height, false);
          update();
          return;
        }
        int index = indexOf(item);
        if (showing)
        {
          int oldSelectedIndex = selectedIndex;
          setSelection(index, true);
          if (oldSelectedIndex == selectedIndex) {
            forceFocus();
          }
        }
        return;
      }
      break;
    case 5: 
      _setToolTipText(x, y);
      boolean close = false;boolean minimize = false;boolean maximize = false;boolean chevron = false;
      if (minRect.contains(x, y))
      {
        minimize = true;
        if ((minImageState != 2) && (minImageState != 32))
        {
          minImageState = 32;
          redraw(minRect.x, minRect.y, minRect.width, minRect.height, false);
        }
      }
      if (maxRect.contains(x, y))
      {
        maximize = true;
        if ((maxImageState != 2) && (maxImageState != 32))
        {
          maxImageState = 32;
          redraw(maxRect.x, maxRect.y, maxRect.width, maxRect.height, false);
        }
      }
      if (chevronRect.contains(x, y))
      {
        chevron = true;
        if ((chevronImageState != 2) && (chevronImageState != 32))
        {
          chevronImageState = 32;
          redraw(chevronRect.x, chevronRect.y, chevronRect.width, chevronRect.height, false);
        }
      }
      if ((minImageState != 0) && (!minimize))
      {
        minImageState = 0;
        redraw(minRect.x, minRect.y, minRect.width, minRect.height, false);
      }
      if ((maxImageState != 0) && (!maximize))
      {
        maxImageState = 0;
        redraw(maxRect.x, maxRect.y, maxRect.width, maxRect.height, false);
      }
      if ((chevronImageState != 0) && (!chevron))
      {
        chevronImageState = 0;
        redraw(chevronRect.x, chevronRect.y, chevronRect.width, chevronRect.height, false);
      }
      for (int i = 0; i < items.length; i++)
      {
        CTabItem item = items[i];
        close = false;
        if (item.getBounds().contains(x, y))
        {
          close = true;
          if (closeRect.contains(x, y))
          {
            if ((closeImageState != 2) && (closeImageState != 32))
            {
              closeImageState = 32;
              redraw(closeRect.x, closeRect.y, closeRect.width, closeRect.height, false);
            }
          }
          else if (closeImageState != 0)
          {
            closeImageState = 0;
            redraw(closeRect.x, closeRect.y, closeRect.width, closeRect.height, false);
          }
          if ((state & 0x20) == 0)
          {
            state |= 0x20;
            redraw(x, y, width, height, false);
          }
        }
        if ((i != selectedIndex) && (closeImageState != 8) && (!close))
        {
          closeImageState = 8;
          redraw(closeRect.x, closeRect.y, closeRect.width, closeRect.height, false);
        }
        if (((state & 0x20) != 0) && (!close))
        {
          state &= 0xFFFFFFDF;
          redraw(x, y, width, height, false);
        }
        if ((i == selectedIndex) && (closeImageState != 0) && (!close))
        {
          closeImageState = 0;
          redraw(closeRect.x, closeRect.y, closeRect.width, closeRect.height, false);
        }
      }
      break;
    case 4: 
      if (button != 1) {
        return;
      }
      if (chevronRect.contains(x, y))
      {
        boolean selected = chevronImageState == 2;
        if (!selected) {
          return;
        }
        CTabFolderEvent e = new CTabFolderEvent(this);
        widget = this;
        time = time;
        x = chevronRect.x;
        y = chevronRect.y;
        width = chevronRect.width;
        height = chevronRect.height;
        doit = true;
        for (int i = 0; i < folderListeners.length; i++) {
          folderListeners[i].showList(e);
        }
        if ((doit) && (!isDisposed())) {
          showList(chevronRect);
        }
        return;
      }
      if (minRect.contains(x, y))
      {
        boolean selected = minImageState == 2;
        minImageState = 32;
        redraw(minRect.x, minRect.y, minRect.width, minRect.height, false);
        if (!selected) {
          return;
        }
        CTabFolderEvent e = new CTabFolderEvent(this);
        widget = this;
        time = time;
        for (int i = 0; i < folderListeners.length; i++) {
          if (minimized) {
            folderListeners[i].restore(e);
          } else {
            folderListeners[i].minimize(e);
          }
        }
        return;
      }
      if (maxRect.contains(x, y))
      {
        boolean selected = maxImageState == 2;
        maxImageState = 32;
        redraw(maxRect.x, maxRect.y, maxRect.width, maxRect.height, false);
        if (!selected) {
          return;
        }
        CTabFolderEvent e = new CTabFolderEvent(this);
        widget = this;
        time = time;
        for (int i = 0; i < folderListeners.length; i++) {
          if (maximized) {
            folderListeners[i].restore(e);
          } else {
            folderListeners[i].maximize(e);
          }
        }
        return;
      }
      CTabItem item = null;
      if (single)
      {
        if (selectedIndex != -1)
        {
          Rectangle bounds = items[selectedIndex].getBounds();
          if (bounds.contains(x, y)) {
            item = items[selectedIndex];
          }
        }
      }
      else {
        for (int i = 0; i < items.length; i++)
        {
          Rectangle bounds = items[i].getBounds();
          if (bounds.contains(x, y)) {
            item = items[i];
          }
        }
      }
      if ((item != null) && 
        (closeRect.contains(x, y)))
      {
        boolean selected = closeImageState == 2;
        closeImageState = 32;
        redraw(closeRect.x, closeRect.y, closeRect.width, closeRect.height, false);
        if (!selected) {
          return;
        }
        CTabFolderEvent e = new CTabFolderEvent(this);
        widget = this;
        time = time;
        item = item;
        doit = true;
        for (int j = 0; j < folderListeners.length; j++)
        {
          CTabFolder2Listener listener = folderListeners[j];
          listener.close(e);
        }
        for (int j = 0; j < tabListeners.length; j++)
        {
          CTabFolderListener listener = tabListeners[j];
          listener.itemClosed(e);
        }
        if (doit) {
          item.dispose();
        }
        if ((!isDisposed()) && (item.isDisposed()))
        {
          Display display = getDisplay();
          Point pt = display.getCursorLocation();
          pt = display.map(null, this, x, y);
          CTabItem nextItem = getItem(pt);
          if (nextItem != null) {
            if (closeRect.contains(pt))
            {
              if ((closeImageState != 2) && (closeImageState != 32))
              {
                closeImageState = 32;
                redraw(closeRect.x, closeRect.y, closeRect.width, closeRect.height, false);
              }
            }
            else if (closeImageState != 0)
            {
              closeImageState = 0;
              redraw(closeRect.x, closeRect.y, closeRect.width, closeRect.height, false);
            }
          }
        }
        return;
      }
      break;
    }
  }
  
  void onPageTraversal(Event event)
  {
    int count = items.length;
    if (count == 0) {
      return;
    }
    int index = selectedIndex;
    if (index == -1)
    {
      index = 0;
    }
    else
    {
      int offset = detail == 512 ? 1 : -1;
      if (!mru)
      {
        index = (selectedIndex + offset + count) % count;
      }
      else
      {
        int[] visible = new int[items.length];
        int idx = 0;
        int current = -1;
        for (int i = 0; i < items.length; i++) {
          if (items[i].showing)
          {
            if (i == selectedIndex) {
              current = idx;
            }
            visible[(idx++)] = i;
          }
        }
        if ((current + offset >= 0) && (current + offset < idx))
        {
          index = visible[(current + offset)];
        }
        else if (showChevron)
        {
          CTabFolderEvent e = new CTabFolderEvent(this);
          widget = this;
          time = time;
          x = chevronRect.x;
          y = chevronRect.y;
          width = chevronRect.width;
          height = chevronRect.height;
          doit = true;
          for (int i = 0; i < folderListeners.length; i++) {
            folderListeners[i].showList(e);
          }
          if ((doit) && (!isDisposed())) {
            showList(chevronRect);
          }
        }
      }
    }
    setSelection(index, true);
  }
  
  void onPaint(Event event)
  {
    if (inDispose) {
      return;
    }
    Font font = getFont();
    if ((oldFont == null) || (!oldFont.equals(font)))
    {
      oldFont = font;
      if (!updateTabHeight(false))
      {
        updateItems();
        redraw();
        return;
      }
    }
    GC gc = gc;
    Font gcFont = gc.getFont();
    Color gcBackground = gc.getBackground();
    Color gcForeground = gc.getForeground();
    
    Point size = getSize();
    Rectangle bodyRect = new Rectangle(0, 0, x, y);
    renderer.draw(-1, 24, bodyRect, gc);
    
    gc.setFont(gcFont);
    gc.setForeground(gcForeground);
    gc.setBackground(gcBackground);
    
    renderer.draw(-2, 24, bodyRect, gc);
    
    gc.setFont(gcFont);
    gc.setForeground(gcForeground);
    gc.setBackground(gcBackground);
    if (!single) {
      for (int i = 0; i < items.length; i++)
      {
        Rectangle itemBounds = items[i].getBounds();
        if ((i != selectedIndex) && (event.getBounds().intersects(itemBounds))) {
          renderer.draw(i, 0x18 | items[i].state, itemBounds, gc);
        }
      }
    }
    gc.setFont(gcFont);
    gc.setForeground(gcForeground);
    gc.setBackground(gcBackground);
    if (selectedIndex != -1) {
      renderer.draw(selectedIndex, items[selectedIndex].state | 0x8 | 0x10, items[selectedIndex].getBounds(), gc);
    }
    gc.setFont(gcFont);
    gc.setForeground(gcForeground);
    gc.setBackground(gcBackground);
    
    renderer.draw(-5, maxImageState, maxRect, gc);
    renderer.draw(-6, minImageState, minRect, gc);
    renderer.draw(-7, chevronImageState, chevronRect, gc);
    
    gc.setFont(gcFont);
    gc.setForeground(gcForeground);
    gc.setBackground(gcBackground);
  }
  
  void onResize()
  {
    if (updateItems()) {
      redrawTabs();
    }
    Point size = getSize();
    if (oldSize == null)
    {
      redraw();
    }
    else if ((onBottom) && (y != oldSize.y))
    {
      redraw();
    }
    else
    {
      int x1 = Math.min(x, oldSize.x);
      Rectangle trim = renderer.computeTrim(-1, 0, 0, 0, 0, 0);
      if (x != oldSize.x) {
        x1 -= width + x - marginWidth + 2;
      }
      if (!simple) {
        x1 -= 5;
      }
      int y1 = Math.min(y, oldSize.y);
      if (y != oldSize.y) {
        y1 -= height + y - marginHeight;
      }
      int x2 = Math.max(x, oldSize.x);
      int y2 = Math.max(y, oldSize.y);
      redraw(0, y1, x2, y2 - y1, false);
      redraw(x1, 0, x2 - x1, y2, false);
    }
    oldSize = size;
  }
  
  void onTraverse(Event event)
  {
    if (ignoreTraverse) {
      return;
    }
    switch (detail)
    {
    case 2: 
    case 4: 
    case 8: 
    case 16: 
      Control focusControl = getDisplay().getFocusControl();
      if (focusControl == this) {
        doit = true;
      }
      break;
    case 128: 
      doit = onMnemonic(event, false);
      break;
    case 256: 
    case 512: 
      doit = (items.length > 0);
    }
    ignoreTraverse = true;
    notifyListeners(31, event);
    ignoreTraverse = false;
    type = 0;
    if (isDisposed()) {
      return;
    }
    if (!doit) {
      return;
    }
    switch (detail)
    {
    case 128: 
      onMnemonic(event, true);
      detail = 0;
      break;
    case 256: 
    case 512: 
      onPageTraversal(event);
      detail = 0;
    }
  }
  
  void redrawTabs()
  {
    Point size = getSize();
    Rectangle trim = renderer.computeTrim(-1, 0, 0, 0, 0, 0);
    if (onBottom)
    {
      int h = height + y - marginHeight;
      redraw(0, y - h - 1, x, h + 1, false);
    }
    else
    {
      redraw(0, 0, x, -y - marginHeight + 1, false);
    }
  }
  
  public void removeCTabFolder2Listener(CTabFolder2Listener listener)
  {
    checkWidget();
    if (listener == null) {
      SWT.error(4);
    }
    if (folderListeners.length == 0) {
      return;
    }
    int index = -1;
    for (int i = 0; i < folderListeners.length; i++) {
      if (listener == folderListeners[i])
      {
        index = i;
        break;
      }
    }
    if (index == -1) {
      return;
    }
    if (folderListeners.length == 1)
    {
      folderListeners = new CTabFolder2Listener[0];
      return;
    }
    CTabFolder2Listener[] newTabListeners = new CTabFolder2Listener[folderListeners.length - 1];
    System.arraycopy(folderListeners, 0, newTabListeners, 0, index);
    System.arraycopy(folderListeners, index + 1, newTabListeners, index, folderListeners.length - index - 1);
    folderListeners = newTabListeners;
  }
  
  /**
   * @deprecated
   */
  public void removeCTabFolderListener(CTabFolderListener listener)
  {
    checkWidget();
    if (listener == null) {
      SWT.error(4);
    }
    if (tabListeners.length == 0) {
      return;
    }
    int index = -1;
    for (int i = 0; i < tabListeners.length; i++) {
      if (listener == tabListeners[i])
      {
        index = i;
        break;
      }
    }
    if (index == -1) {
      return;
    }
    if (tabListeners.length == 1)
    {
      tabListeners = new CTabFolderListener[0];
      return;
    }
    CTabFolderListener[] newTabListeners = new CTabFolderListener[tabListeners.length - 1];
    System.arraycopy(tabListeners, 0, newTabListeners, 0, index);
    System.arraycopy(tabListeners, index + 1, newTabListeners, index, tabListeners.length - index - 1);
    tabListeners = newTabListeners;
  }
  
  public void removeSelectionListener(SelectionListener listener)
  {
    checkWidget();
    if (listener == null) {
      SWT.error(4);
    }
    removeListener(13, listener);
    removeListener(14, listener);
  }
  
  public void reskin(int flags)
  {
    super.reskin(flags);
    for (int i = 0; i < items.length; i++) {
      items[i].reskin(flags);
    }
  }
  
  public void setBackground(Color color)
  {
    super.setBackground(color);
    renderer.createAntialiasColors();
    redraw();
  }
  
  public void setBackground(Color[] colors, int[] percents)
  {
    setBackground(colors, percents, false);
  }
  
  public void setBackground(Color[] colors, int[] percents, boolean vertical)
  {
    checkWidget();
    if (colors != null)
    {
      if ((percents == null) || (percents.length != colors.length - 1)) {
        SWT.error(5);
      }
      for (int i = 0; i < percents.length; i++)
      {
        if ((percents[i] < 0) || (percents[i] > 100)) {
          SWT.error(5);
        }
        if ((i > 0) && (percents[i] < percents[(i - 1)])) {
          SWT.error(5);
        }
      }
      if (getDisplay().getDepth() < 15)
      {
        colors = new Color[] { colors[(colors.length - 1)] };
        percents = new int[0];
      }
    }
    if ((gradientColors != null) && (colors != null) && 
      (gradientColors.length == colors.length))
    {
      boolean same = false;
      for (int i = 0; i < gradientColors.length; i++)
      {
        if (gradientColors[i] == null) {
          same = colors[i] == null;
        } else {
          same = gradientColors[i].equals(colors[i]);
        }
        if (!same) {
          break;
        }
      }
      if (same) {
        for (int i = 0; i < gradientPercents.length; i++)
        {
          same = gradientPercents[i] == percents[i];
          if (!same) {
            break;
          }
        }
      }
      if ((same) && (gradientVertical == vertical)) {
        return;
      }
    }
    if (colors == null)
    {
      gradientColors = null;
      gradientPercents = null;
      gradientVertical = false;
      setBackground(null);
    }
    else
    {
      gradientColors = new Color[colors.length];
      for (int i = 0; i < colors.length; i++) {
        gradientColors[i] = colors[i];
      }
      gradientPercents = new int[percents.length];
      for (int i = 0; i < percents.length; i++) {
        gradientPercents[i] = percents[i];
      }
      gradientVertical = vertical;
      setBackground(gradientColors[(gradientColors.length - 1)]);
    }
    redraw();
  }
  
  public void setBackgroundImage(Image image)
  {
    super.setBackgroundImage(image);
    renderer.createAntialiasColors();
    redraw();
  }
  
  public void setBorderVisible(boolean show)
  {
    checkWidget();
    if (borderVisible == show) {
      return;
    }
    borderVisible = show;
    Rectangle rectBefore = getClientArea();
    updateItems();
    Rectangle rectAfter = getClientArea();
    if (!rectBefore.equals(rectAfter)) {
      notifyListeners(11, new Event());
    }
    redraw();
  }
  
  void setButtonBounds(GC gc)
  {
    Point size = getSize();
    
    Rectangle trim = renderer.computeTrim(-3, 0, 0, 0, 0, 0);
    int borderRight = width + x;
    int borderLeft = -x;
    int borderBottom = height + y;
    int borderTop = -y;
    
    int oldX = maxRect.x;
    int oldY = maxRect.y
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd