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

true;
      }
      control = parent;
    }
    return false;
  }
  
  boolean mnemonicMatch(char key)
  {
    char mnemonic = findMnemonic(getText());
    if (mnemonic == 0) {
      return false;
    }
    return Character.toUpperCase(key) == Character.toUpperCase(mnemonic);
  }
  
  void releaseWidget()
  {
    super.releaseWidget();
    text = null;
    image = null;
  }
  
  public void setAlignment(int alignment)
  {
    checkWidget();
    if ((style & 0x2) != 0) {
      return;
    }
    if ((alignment & 0x1024000) == 0) {
      return;
    }
    style &= 0xFEFDBFFF;
    style |= alignment & 0x1024000;
    int bits = OS.GetWindowLong(handle, -16);
    if ((bits & 0xD) != 13)
    {
      bits &= 0xFFFFFFF0;
      if ((style & 0x4000) != 0) {
        if ((style & 0x40) != 0) {
          bits |= 0x0;
        } else {
          bits |= 0xC;
        }
      }
      if ((style & 0x1000000) != 0) {
        bits |= 0x1;
      }
      if ((style & 0x20000) != 0) {
        bits |= 0x2;
      }
      OS.SetWindowLong(handle, -16, bits);
    }
    OS.InvalidateRect(handle, null, true);
  }
  
  public void setImage(Image image)
  {
    checkWidget();
    if ((style & 0x2) != 0) {
      return;
    }
    if ((image != null) && (image.isDisposed())) {
      error(5);
    }
    this.image = image;
    int bits = OS.GetWindowLong(handle, -16);
    if ((bits & 0xD) != 13)
    {
      bits &= 0xFFFFFFF0;
      bits |= 0xD;
      OS.SetWindowLong(handle, -16, bits);
    }
    OS.InvalidateRect(handle, null, true);
  }
  
  public void setText(String string)
  {
    checkWidget();
    if (string == null) {
      error(4);
    }
    if ((style & 0x2) != 0) {
      return;
    }
    if (string.equals(text)) {
      return;
    }
    text = string;
    if ((image == null) || (!IMAGE_AND_TEXT))
    {
      int oldBits = OS.GetWindowLong(handle, -16);int newBits = oldBits;
      newBits &= 0xFFFFFFF2;
      if ((style & 0x4000) != 0) {
        if ((style & 0x40) != 0) {
          newBits |= 0x0;
        } else {
          newBits |= 0xC;
        }
      }
      if ((style & 0x1000000) != 0) {
        newBits |= 0x1;
      }
      if ((style & 0x20000) != 0) {
        newBits |= 0x2;
      }
      if (oldBits != newBits) {
        OS.SetWindowLong(handle, -16, newBits);
      }
    }
    string = Display.withCrLf(string);
    TCHAR buffer = new TCHAR(getCodePage(), string, true);
    OS.SetWindowText(handle, buffer);
    if ((OS.COMCTL32_MAJOR < 6) && 
      (findImageControl() != null)) {
      OS.InvalidateRect(handle, null, true);
    }
  }
  
  int widgetExtStyle()
  {
    int bits = super.widgetExtStyle() & 0xFDFF;
    if ((style & 0x800) != 0) {
      return bits | 0x20000;
    }
    return bits;
  }
  
  int widgetStyle()
  {
    int bits = super.widgetStyle() | 0x100;
    if ((style & 0x2) != 0) {
      return bits | 0xD;
    }
    if ((OS.WIN32_VERSION >= OS.VERSION(5, 0)) && 
      ((style & 0x40) != 0)) {
      bits |= 0x2000;
    }
    if ((style & 0x1000000) != 0) {
      return bits | 0x1;
    }
    if ((style & 0x20000) != 0) {
      return bits | 0x2;
    }
    if ((style & 0x40) != 0) {
      return bits;
    }
    return bits | 0xC;
  }
  
  TCHAR windowClass()
  {
    return LabelClass;
  }
  
  int windowProc()
  {
    return LabelProc;
  }
  
  LRESULT WM_ERASEBKGND(int wParam, int lParam)
  {
    LRESULT result = super.WM_ERASEBKGND(wParam, lParam);
    if (result != null) {
      return result;
    }
    int bits = OS.GetWindowLong(handle, -16);
    if ((bits & 0xD) == 13) {
      return LRESULT.ONE;
    }
    if ((OS.COMCTL32_MAJOR < 6) && 
      (findImageControl() != null))
    {
      drawBackground(wParam);
      return LRESULT.ONE;
    }
    return result;
  }
  
  LRESULT WM_SIZE(int wParam, int lParam)
  {
    LRESULT result = super.WM_SIZE(wParam, lParam);
    if (isDisposed()) {
      return result;
    }
    if ((style & 0x2) != 0)
    {
      OS.InvalidateRect(handle, null, true);
      return result;
    }
    int bits = OS.GetWindowLong(handle, -16);
    if ((bits & 0xD) == 13)
    {
      OS.InvalidateRect(handle, null, true);
      return result;
    }
    if ((bits & 0xC) != 12)
    {
      OS.InvalidateRect(handle, null, true);
      return result;
    }
    return result;
  }
  
  LRESULT WM_UPDATEUISTATE(int wParam, int lParam)
  {
    LRESULT result = super.WM_UPDATEUISTATE(wParam, lParam);
    if (result != null) {
      return result;
    }
    boolean redraw = findImageControl() != null;
    if ((!redraw) && 
      ((state & 0x100) != 0) && 
      (OS.COMCTL32_MAJOR >= 6) && (OS.IsAppThemed())) {
      redraw = findThemeControl() != null;
    }
    if (redraw)
    {
      OS.InvalidateRect(handle, null, false);
      int code = OS.DefWindowProc(handle, 296, wParam, lParam);
      return new LRESULT(code);
    }
    return result;
  }
  
  LRESULT wmColorChild(int wParam, int lParam)
  {
    LRESULT result = super.wmColorChild(wParam, lParam);
    if (OS.COMCTL32_MAJOR < 6)
    {
      int bits = OS.GetWindowLong(handle, -16);
      if (((bits & 0xD) != 13) && 
        (findImageControl() != null))
      {
        OS.SetBkMode(wParam, 1);
        return new LRESULT(OS.GetStockObject(5));
      }
    }
    return result;
  }
  
  LRESULT WM_PAINT(int wParam, int lParam)
  {
    if (OS.IsWinCE)
    {
      boolean drawImage = image != null;
      boolean drawSeparator = ((style & 0x2) != 0) && ((style & 0x20) == 0);
      if ((drawImage) || (drawSeparator))
      {
        LRESULT result = null;
        PAINTSTRUCT ps = new PAINTSTRUCT();
        GCData data = new GCData();
        ps = ps;
        hwnd = handle;
        GC gc = new_GC(data);
        if (gc != null)
        {
          drawBackground(handle);
          RECT clientRect = new RECT();
          OS.GetClientRect(handle, clientRect);
          if (drawSeparator)
          {
            RECT rect = new RECT();
            int lineWidth = OS.GetSystemMetrics(5);
            int flags = (style & 0x4) != 0 ? 10 : 6;
            if ((style & 0x100) != 0)
            {
              int bottom = top + Math.max(lineWidth * 2, (bottom - top) / 2);
              OS.SetRect(rect, left, top, right, bottom);
              OS.DrawEdge(handle, rect, flags, 8);
            }
            else
            {
              int right = left + Math.max(lineWidth * 2, (right - left) / 2);
              OS.SetRect(rect, left, top, right, bottom);
              OS.DrawEdge(handle, rect, flags, 4);
            }
            result = LRESULT.ONE;
          }
          if (drawImage)
          {
            Rectangle imageBounds = image.getBounds();
            int x = 0;
            if ((style & 0x1000000) != 0) {
              x = Math.max(0, (right - width) / 2);
            } else if ((style & 0x20000) != 0) {
              x = Math.max(0, right - width);
            }
            gc.drawImage(image, x, Math.max(0, (bottom - height) / 2));
            result = LRESULT.ONE;
          }
          int width = right - left;
          int height = bottom - top;
          if ((width != 0) && (height != 0))
          {
            Event event = new Event();
            gc = gc;
            x = left;
            y = top;
            width = width;
            height = height;
            sendEvent(9, event);
            
            gc = null;
          }
          gc.dispose();
        }
        return result;
      }
    }
    return super.WM_PAINT(wParam, lParam);
  }
  
  LRESULT wmDrawChild(int wParam, int lParam)
  {
    DRAWITEMSTRUCT struct = new DRAWITEMSTRUCT();
    OS.MoveMemory(struct, lParam, DRAWITEMSTRUCT.sizeof);
    drawBackground(hDC);
    if ((style & 0x2) != 0)
    {
      if ((style & 0x20) != 0) {
        return null;
      }
      RECT rect = new RECT();
      int lineWidth = OS.GetSystemMetrics(5);
      int flags = (style & 0x4) != 0 ? 10 : 6;
      if ((style & 0x100) != 0)
      {
        int bottom = top + Math.max(lineWidth * 2, (bottom - top) / 2);
        OS.SetRect(rect, left, top, right, bottom);
        OS.DrawEdge(hDC, rect, flags, 8);
      }
      else
      {
        int right = left + Math.max(lineWidth * 2, (right - left) / 2);
        OS.SetRect(rect, left, top, right, bottom);
        OS.DrawEdge(hDC, rect, flags, 4);
      }
    }
    else
    {
      int width = right - left;
      int height = bottom - top;
      if ((width != 0) && (height != 0))
      {
        boolean drawImage = this.image != null;
        boolean drawText = (IMAGE_AND_TEXT) && (text.length() != 0);
        int margin = (drawText) && (drawImage) ? 4 : 0;
        int imageWidth = 0;int imageHeight = 0;
        if (drawImage)
        {
          Rectangle rect = this.image.getBounds();
          imageWidth = width;
          imageHeight = height;
        }
        RECT rect = null;
        TCHAR buffer = null;
        int textWidth = 0;int textHeight = 0;int flags = 0;
        if (drawText)
        {
          rect = new RECT();
          flags = 9280;
          if ((style & 0x4000) != 0) {
            flags |= 0x0;
          }
          if ((style & 0x1000000) != 0) {
            flags |= 0x1;
          }
          if ((style & 0x20000) != 0) {
            flags |= 0x2;
          }
          if ((style & 0x40) != 0)
          {
            flags |= 0x10;
            right = Math.max(0, width - imageWidth - margin);
          }
          buffer = new TCHAR(getCodePage(), text, true);
          OS.DrawText(hDC, buffer, -1, rect, flags);
          textWidth = right - left;
          textHeight = bottom - top;
        }
        int x = 0;
        if ((style & 0x1000000) != 0) {
          x = Math.max(0, (width - imageWidth - textWidth - margin) / 2);
        } else if ((style & 0x20000) != 0) {
          x = width - imageWidth - textWidth - margin;
        }
        if (drawImage)
        {
          GCData data = new GCData();
          device = display;
          GC gc = GC.win32_new(hDC, data);
          Image image = getEnabled() ? this.image : new Image(display, this.image, 1);
          gc.drawImage(image, x, Math.max(0, (height - imageHeight) / 2));
          if (image != this.image) {
            image.dispose();
          }
          gc.dispose();
          x += imageWidth + margin;
        }
        if (drawText)
        {
          flags &= 0xFBFF;
          left = x;
          right += left;
          top = Math.max(0, (height - textHeight) / 2);
          bottom += top;
          OS.DrawText(hDC, buffer, -1, rect, flags);
        }
      }
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.swt.widgets.Label
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.swt.widgets;

import org.eclipse.swt.graphics.Point;

public abstract class Layout
{
  protected abstract Point computeSize(Composite paramComposite, int paramInt1, int paramInt2, boolean paramBoolean);
  
  protected boolean flushCache(Control control)
  {
    return false;
  }
  
  protected abstract void layout(Composite paramComposite, boolean paramBoolean);
}

/* Location:
 * Qualified Name:     org.eclipse.swt.widgets.Layout
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.swt.widgets;

import org.eclipse.swt.accessibility.AccessibleAdapter;
import org.eclipse.swt.accessibility.AccessibleEvent;

class Link$1
  extends AccessibleAdapter
{
  final Link this$0;
  
  Link$1(Link paramLink)
  {
    this$0 = paramLink;
  }
  
  public void getName(AccessibleEvent e)
  {
    result = this$0.parse(this$0.text);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.swt.widgets.Link.1
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.swt.widgets;

import org.eclipse.swt.SWT;
import org.eclipse.swt.accessibility.AccessibleControlAdapter;
import org.eclipse.swt.accessibility.AccessibleControlEvent;
import org.eclipse.swt.graphics.Rectangle;

class Link$2
  extends AccessibleControlAdapter
{
  final Link this$0;
  
  Link$2(Link paramLink)
  {
    this$0 = paramLink;
  }
  
  public void getChildAtPoint(AccessibleControlEvent e)
  {
    childID = -1;
  }
  
  public void getLocation(AccessibleControlEvent e)
  {
    Rectangle rect = this$0.display.map(this$0.getParent(), null, this$0.getBounds());
    x = x;
    y = y;
    width = width;
    height = height;
  }
  
  public void getChildCount(AccessibleControlEvent e)
  {
    detail = 0;
  }
  
  public void getRole(AccessibleControlEvent e)
  {
    detail = 30;
  }
  
  public void getState(AccessibleControlEvent e)
  {
    detail = 1048576;
    if (this$0.hasFocus()) {
      detail |= 0x4;
    }
  }
  
  public void getDefaultAction(AccessibleControlEvent e)
  {
    result = SWT.getMessage("SWT_Press");
  }
  
  public void getSelection(AccessibleControlEvent e)
  {
    if (this$0.hasFocus()) {
      childID = -1;
    }
  }
  
  public void getFocus(AccessibleControlEvent e)
  {
    if (this$0.hasFocus()) {
      childID = -1;
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.swt.widgets.Link.2
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.swt.widgets;

import org.eclipse.swt.SWT;
import org.eclipse.swt.accessibility.Accessible;
import org.eclipse.swt.accessibility.AccessibleAdapter;
import org.eclipse.swt.accessibility.AccessibleControlAdapter;
import org.eclipse.swt.accessibility.AccessibleControlEvent;
import org.eclipse.swt.accessibility.AccessibleEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.GCData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.TextLayout;
import org.eclipse.swt.graphics.TextStyle;
import org.eclipse.swt.internal.win32.LITEM;
import org.eclipse.swt.internal.win32.LRESULT;
import org.eclipse.swt.internal.win32.NMHDR;
import org.eclipse.swt.internal.win32.NMLINK;
import org.eclipse.swt.internal.win32.OS;
import org.eclipse.swt.internal.win32.PAINTSTRUCT;
import org.eclipse.swt.internal.win32.RECT;
import org.eclipse.swt.internal.win32.TCHAR;
import org.eclipse.swt.internal.win32.TEXTMETRIC;
import org.eclipse.swt.internal.win32.TEXTMETRICA;
import org.eclipse.swt.internal.win32.TEXTMETRICW;
import org.eclipse.swt.internal.win32.WNDCLASS;

public class Link
  extends Control
{
  String text;
  TextLayout layout;
  Color linkColor;
  Color disabledColor;
  Point[] offsets;
  Point selection;
  String[] ids;
  int[] mnemonics;
  int focusIndex;
  int mouseDownIndex;
  int font;
  static final RGB LINK_FOREGROUND = new RGB(0, 51, 153);
  static final int LinkProc;
  static final TCHAR LinkClass = new TCHAR(0, "SysLink", true);
  
  static
  {
    if (OS.COMCTL32_MAJOR >= 6)
    {
      WNDCLASS lpWndClass = new WNDCLASS();
      OS.GetClassInfo(0, LinkClass, lpWndClass);
      LinkProc = lpfnWndProc;
      
      int hInstance = OS.GetModuleHandle(null);
      int hHeap = OS.GetProcessHeap();
      lpWndClass.hInstance = hInstance;
      style &= 0xBFFF;
      style |= 0x8;
      int byteCount = LinkClass.length() * TCHAR.sizeof;
      int lpszClassName = OS.HeapAlloc(hHeap, 8, byteCount);
      OS.MoveMemory(lpszClassName, LinkClass, byteCount);
      lpWndClass.lpszClassName = lpszClassName;
      OS.RegisterClass(lpWndClass);
      OS.HeapFree(hHeap, 0, lpszClassName);
    }
    else
    {
      LinkProc = 0;
    }
  }
  
  public Link(Composite parent, int style)
  {
    super(parent, style);
  }
  
  public void addSelectionListener(SelectionListener listener)
  {
    checkWidget();
    if (listener == null) {
      error(4);
    }
    TypedListener typedListener = new TypedListener(listener);
    addListener(13, typedListener);
    addListener(14, typedListener);
  }
  
  int callWindowProc(int hwnd, int msg, int wParam, int lParam)
  {
    if (handle == 0) {
      return 0;
    }
    if (LinkProc != 0)
    {
      switch (msg)
      {
      case 15: 
        if (wParam != 0)
        {
          OS.SendMessage(hwnd, 792, wParam, 0);
          return 0;
        }
        break;
      }
      return OS.CallWindowProc(LinkProc, hwnd, msg, wParam, lParam);
    }
    return OS.DefWindowProc(hwnd, msg, wParam, lParam);
  }
  
  public Point computeSize(int wHint, int hHint, boolean changed)
  {
    checkWidget();
    if ((wHint != -1) && (wHint < 0)) {
      wHint = 0;
    }
    if ((hHint != -1) && (hHint < 0)) {
      hHint = 0;
    }
    int width;
    int height;
    if (OS.COMCTL32_MAJOR >= 6)
    {
      int hDC = OS.GetDC(handle);
      int newFont = OS.SendMessage(handle, 49, 0, 0);
      int oldFont = OS.SelectObject(hDC, newFont);
      int height;
      int height;
      if (text.length() > 0)
      {
        TCHAR buffer = new TCHAR(getCodePage(), parse(text), false);
        RECT rect = new RECT();
        int flags = 3072;
        if (wHint != -1)
        {
          flags |= 0x10;
          right = wHint;
        }
        OS.DrawText(hDC, buffer, buffer.length(), rect, flags);
        int width = right - left;
        height = bottom;
      }
      else
      {
        TEXTMETRIC lptm = OS.IsUnicode ? new TEXTMETRICW() : new TEXTMETRICA();
        OS.GetTextMetrics(hDC, lptm);
        int width = 0;
        height = tmHeight;
      }
      if (newFont != 0) {
        OS.SelectObject(hDC, oldFont);
      }
      OS.ReleaseDC(handle, hDC);
    }
    else
    {
      int layoutWidth = layout.getWidth();
      int height;
      if (wHint == 0)
      {
        layout.setWidth(1);
        Rectangle rect = layout.getBounds();
        int width = 0;
        height = height;
      }
      else
      {
        layout.setWidth(wHint);
        Rectangle rect = layout.getBounds();
        width = width;
        height = height;
      }
      layout.setWidth(layoutWidth);
    }
    if (wHint != -1) {
      width = wHint;
    }
    if (hHint != -1) {
      height = hHint;
    }
    int border = getBorderWidth();
    width += border * 2;
    height += border * 2;
    return new Point(width, height);
  }
  
  void createHandle()
  {
    super.createHandle();
    state |= 0x100;
    if (OS.COMCTL32_MAJOR < 6)
    {
      layout = new TextLayout(display);
      if ((!OS.IsWinCE) && (OS.WIN32_VERSION >= OS.VERSION(4, 10))) {
        linkColor = Color.win32_new(display, OS.GetSysColor(OS.COLOR_HOTLIGHT));
      } else {
        linkColor = new Color(display, LINK_FOREGROUND);
      }
      disabledColor = Color.win32_new(display, OS.GetSysColor(OS.COLOR_GRAYTEXT));
      offsets = new Point[0];
      ids = new String[0];
      mnemonics = new int[0];
      selection = new Point(-1, -1);
      focusIndex = (mouseDownIndex = -1);
    }
  }
  
  void createWidget()
  {
    super.createWidget();
    text = "";
    if (OS.COMCTL32_MAJOR < 6)
    {
      if ((style & 0x8000000) != 0) {
        layout.setOrientation(67108864);
      }
      initAccessible();
    }
  }
  
  void drawWidget(GC gc, RECT rect)
  {
    drawBackground(handle, rect);
    int selStart = selection.x;
    int selEnd = selection.y;
    if (selStart > selEnd)
    {
      selStart = selection.y;
      selEnd = selection.x;
    }
    selStart = selEnd = -1;
    if (!OS.IsWindowEnabled(handle)) {
      gc.setForeground(disabledColor);
    }
    layout.draw(gc, 0, 0, selStart, selEnd, null, null);
    if ((hasFocus()) && (focusIndex != -1))
    {
      Rectangle[] rects = getRectangles(focusIndex);
      for (int i = 0; i < rects.length; i++)
      {
        Rectangle rectangle = rects[i];
        gc.drawFocus(x, y, width, height);
      }
    }
    if ((hooks(9)) || (filters(9)))
    {
      Event event = new Event();
      gc = gc;
      x = left;
      y = top;
      width = (right - left);
      height = (bottom - top);
      sendEvent(9, event);
      gc = null;
    }
  }
  
  void enableWidget(boolean enabled)
  {
    if (OS.COMCTL32_MAJOR >= 6)
    {
      LITEM item = new LITEM();
      mask = 3;
      stateMask = 2;
      state = (enabled ? 2 : 0);
      while (OS.SendMessage(handle, 1794, 0, item) != 0) {
        iLink += 1;
      }
    }
    else
    {
      TextStyle linkStyle = new TextStyle(null, enabled ? linkColor : disabledColor, null);
      underline = true;
      for (int i = 0; i < offsets.length; i++)
      {
        Point point = offsets[i];
        layout.setStyle(linkStyle, x, y);
      }
      redraw();
    }
    super.enableWidget(enabled);
  }
  
  void initAccessible()
  {
    Accessible accessible = getAccessible();
    accessible.addAccessibleListener(new AccessibleAdapter()
    {
      public void getName(AccessibleEvent e)
      {
        result = parse(text);
      }
    });
    accessible.addAccessibleControlListener(new AccessibleControlAdapter()
    {
      public void getChildAtPoint(AccessibleControlEvent e)
      {
        childID = -1;
      }
      
      public void getLocation(AccessibleControlEvent e)
      {
        Rectangle rect = display.map(getParent(), null, getBounds());
        x = x;
        y = y;
        width = width;
        height = height;
      }
      
      public void getChildCount(AccessibleControlEvent e)
      {
        detail = 0;
      }
      
      public void getRole(AccessibleControlEvent e)
      {
        detail = 30;
      }
      
      public void getState(AccessibleControlEvent e)
      {
        detail = 1048576;
        if (hasFocus()) {
          detail |= 0x4;
        }
      }
      
      public void getDefaultAction(AccessibleControlEvent e)
      {
        result = SWT.getMessage("SWT_Press");
      }
      
      public void getSelection(AccessibleControlEvent e)
      {
        if (hasFocus()) {
          childID = -1;
        }
      }
      
      public void getFocus(AccessibleControlEvent e)
      {
        if (hasFocus()) {
          childID = -1;
        }
      }
    });
  }
  
  String getNameText()
  {
    return getText();
  }
  
  Rectangle[] getRectangles(int linkIndex)
  {
    int lineCount = layout.getLineCount();
    Rectangle[] rects = new Rectangle[lineCount];
    int[] lineOffsets = layout.getLineOffsets();
    Point point = offsets[linkIndex];
    int lineStart = 1;
    while (x > lineOffsets[lineStart]) {
      lineStart++;
    }
    int lineEnd = 1;
    while (y > lineOffsets[lineEnd]) {
      lineEnd++;
    }
    int index = 0;
    if (lineStart == lineEnd)
    {
      rects[(index++)] = layout.getBounds(x, y);
    }
    else
    {
      rects[(index++)] = layout.getBounds(x, lineOffsets[lineStart] - 1);
      rects[(index++)] = layout.getBounds(lineOffsets[(lineEnd - 1)], y);
      if (lineEnd - lineStart > 1) {
        for (int i = lineStart; i < lineEnd - 1; i++) {
          rects[(index++)] = layout.getLineBounds(i);
        }
      }
    }
    if (rects.length != index)
    {
      Rectangle[] tmp = new Rectangle[index];
      System.arraycopy(rects, 0, tmp, 0, index);
      rects = tmp;
    }
    return rects;
  }
  
  public String getText()
  {
    checkWidget();
    return text;
  }
  
  boolean mnemonicHit(char key)
  {
    if (mnemonics != null)
    {
      char uckey = Character.toUpperCase(key);
      String parsedText = parse(text);
      for (int i = 0; i < mnemonics.length - 1; i++) {
        if (mnemonics[i] != -1)
        {
          char mnemonic = parsedText.charAt(mnemonics[i]);
          if (uckey == Character.toUpperCase(mnemonic))
          {
            if (!setFocus()) {
              return false;
            }
            if (OS.COMCTL32_MAJOR >= 6)
            {
              int bits = OS.GetWindowLong(handle, -16);
              LITEM item = new LITEM();
              mask = 3;
              stateMask = 1;
              while (iLink < mnemonics.length)
              {
                if (iLink != i) {
                  OS.SendMessage(handle, 1794, 0, item);
                }
                iLink += 1;
              }
              iLink = i;
              state = 1;
              OS.SendMessage(handle, 1794, 0, item);
              
              OS.SetWindowLong(handle, -16, bits);
            }
            else
            {
              focusIndex = i;
              redraw();
            }
            return true;
          }
        }
      }
    }
    return false;
  }
  
  boolean mnemonicMatch(char key)
  {
    if (mnemonics != null)
    {
      char uckey = Character.toUpperCase(key);
      String parsedText = parse(text);
      for (int i = 0; i < mnemonics.length - 1; i++) {
        if (mnemonics[i] != -1)
        {
          char mnemonic = parsedText.charAt(mnemonics[i]);
          if (uckey == Character.toUpperCase(mnemonic)) {
            return true;
          }
        }
      }
    }
    return false;
  }
  
  String parse(String string)
  {
    int length = string.length();
    offsets = new Point[length / 4];
    ids = new String[length / 4];
    mnemonics = new int[length / 4 + 1];
    StringBuffer result = new StringBuffer();
    char[] buffer = new char[length];
    string.getChars(0, string.length(), buffer, 0);
    int index = 0;int state = 0;int linkIndex = 0;
    int start = 0;int tagStart = 0;int linkStart = 0;int endtagStart = 0;int refStart = 0;
    while (index < length)
    {
      char c = Character.toLowerCase(buffer[index]);
      switch (state)
      {
      case 0: 
        if (c == '<')
        {
          tagStart = index;
          state++;
        }
        break;
      case 1: 
        if (c == 'a') {
          state++;
        }
        break;
      case 2: 
        switch (c)
        {
        case 'h': 
          state = 7;
          break;
        case '>': 
          linkStart = index + 1;
          state++;
          break;
        default: 
          if (!Character.isWhitespace(c)) {
            state = 13;
          }
          break;
        }
        break;
      case 3: 
        if (c == '<')
        {
          endtagStart = index;
          state++;
        }
        break;
      case 4: 
        state = c == '/' ? state + 1 : 3;
        break;
      case 5: 
        state = c == 'a' ? state + 1 : 3;
        break;
      case 6: 
        if (c == '>')
        {
          mnemonics[linkIndex] = parseMnemonics(buffer, start, tagStart, result);
          int offset = result.length();
          parseMnemonics(buffer, linkStart, endtagStart, result);
          offsets[linkIndex] = new Point(offset, result.length() - 1);
          if (ids[linkIndex] == null) {
            ids[linkIndex] = new String(buffer, linkStart, endtagStart - linkStart);
          }
          linkIndex++;
          start = tagStart = linkStart = endtagStart = refStart = index + 1;
          state = 0;
        }
        else
        {
          state = 3;
        }
        break;
      case 7: 
        state = c == 'r' ? state + 1 : 0;
        break;
      case 8: 
        state = c == 'e' ? state + 1 : 0;
        break;
      case 9: 
        state = c == 'f' ? state + 1 : 0;
        break;
      case 10: 
        state = c == '=' ? state + 1 : 0;
        break;
      case 11: 
        if (c == '"')
        {
          state++;
          refStart = index + 1;
        }
        else
        {
          state = 0;
        }
        break;
      case 12: 
        if (c == '"')
        {
          ids[linkIndex] = new String(buffer, refStart, index - refStart);
          state = 2;
        }
        break;
      case 13: 
        if (Character.isWhitespace(c)) {
          state = 0;
        } else if (c == '=') {
          state++;
        }
        break;
      case 14: 
        state = c == '"' ? state + 1 : 0;
        break;
      case 15: 
        if (c == '"') {
          state = 2;
        }
        break;
      default: 
        state = 0;
      }
      index++;
    }
    if (start < length)
    {
      int tmp = parseMnemonics(buffer, start, tagStart, result);
      int mnemonic = parseMnemonics(buffer, Math.max(tagStart, linkStart), length, result);
      if (mnemonic == -1) {
        mnemonic = tmp;
      }
      mnemonics[linkIndex] = mnemonic;
    }
    else
    {
      mnemonics[linkIndex] = -1;
    }
    if (offsets.length != linkIndex)
    {
      Point[] newOffsets = new Point[linkIndex];
      System.arraycopy(offsets, 0, newOffsets, 0, linkIndex);
      offsets = newOffsets;
      String[] newIDs = new String[linkIndex];
      System.arraycopy(ids, 0, newIDs, 0, linkIndex);
      ids = newIDs;
      int[] newMnemonics = new int[linkIndex + 1];
      System.arraycopy(mnemonics, 0, newMnemonics, 0, linkIndex + 1);
      mnemonics = newMnemonics;
    }
    return result.toString();
  }
  
  int parseMnemonics(char[] buffer, int start, int end, StringBuffer result)
  {
    int mnemonic = -1;int index = start;
    while (index < end)
    {
      if (buffer[index] == '&')
      {
        if ((index + 1 < end) && (buffer[(index + 1)] == '&'))
        {
          result.append(buffer[index]);
          index++;
        }
        else
        {
          mnemonic = result.length();
        }
      }
      else {
        result.append(buffer[index]);
      }
      index++;
    }
    return mnemonic;
  }
  
  void releaseWidget()
  {
    super.releaseWidget();
    if (layout != null) {
      layout.dispose();
    }
    layout = null;
    if (linkColor != null) {
      linkColor.dispose();
    }
    linkColor = null;
    disabledColor = null;
    offsets = null;
    ids = null;
    mnemonics = null;
    text = null;
  }
  
  public void removeSelectionListener(SelectionListener listener)
  {
    checkWidget();
    if (listener == null) {
      error(4);
    }
    if (eventTable == null) {
      return;
    }
    eventTable.unhook(13, listener);
    eventTable.unhook(14, listener);
  }
  
  public void setText(String string)
  {
    checkWidget();
    if (string == null) {
      error(4);
    }
    if (string.equals(text)) {
      return;
    }
    text = string;
    if (OS.COMCTL32_MAJOR >= 6)
    {
      boolean enabled = OS.IsWindowEnabled(handle);
      if (string.length() == 0) {
        string = " ";
      }
      TCHAR buffer = new TCHAR(getCodePage(), string, true);
      OS.SetWindowText(handle, buffer);
      parse(text);
      enableWidget(enabled);
    }
    else
    {
      layout.setText(parse(text));
      focusIndex = (offsets.length > 0 ? 0 : -1);
      selection.x = (selection.y = -1);
      int bits = OS.GetWindowLong(handle, -16);
      if (offsets.length > 0) {
        bits |= 0x10000;
      } else {
        bits &= 0xFFFEFFFF;
      }
      OS.SetWindowLong(handle, -16, bits);
      boolean enabled = OS.IsWindowEnabled(handle);
      TextStyle linkStyle = new TextStyle(null, enabled ? linkColor : disabledColor, null);
      underline = true;
      for (int i = 0; i < offsets.length; i++)
      {
        Point point = offsets[i];
        layout.setStyle(linkStyle, x, y);
      }
      TextStyle mnemonicStyle = new TextStyle(null, null, null);
      underline = true;
      for (int i = 0; i < mnemonics.length; i++)
      {
        int mnemonic = mnemonics[i];
        if (mnemonic != -1) {
          layout.setStyle(mnemonicStyle, mnemonic, mnemonic);
        }
      }
      redraw();
    }
  }
  
  int widgetStyle()
  {
    int bits = super.widgetStyle();
    return bits | 0x10000;
  }
  
  TCHAR windowClass()
  {
    return OS.COMCTL32_MAJOR >= 6 ? LinkClass : display.windowClass;
  }
  
  int windowProc()
  {
    return LinkProc != 0 ? LinkProc : display.windowProc;
  }
  
  LRESULT WM_CHAR(int wParam, int lParam)
  {
    LRESULT result = super.WM_CHAR(wParam, lParam);
    if (result != null) {
      return result;
    }
    if (OS.COMCTL32_MAJOR < 6)
    {
      if (focusIndex == -1) {
        return result;
      }
      switch (wParam)
      {
      case 13: 
      case 32: 
        Event event = new Event();
        text = ids[focusIndex];
        sendSelectionEvent(13, event, true);
        break;
      case 9: 
        boolean next = OS.GetKeyState(16) >= 0;
        if (next)
        {
          if (focusIndex < offsets.length - 1)
          {
            focusIndex += 1;
            redraw();
          }
        }
        else if (focusIndex > 0)
        {
          focusIndex -= 1;
          redraw();
        }
        break;
      }
    }
    else
    {
      switch (wParam)
      {
      case 9: 
      case 13: 
      case 32: 
        int code = callWindowProc(handle, 256, wParam, lParam);
        return new LRESULT(code);
      }
    }
    return result;
  }
  
  LRESULT WM_GETDLGCODE(int wParam, int lParam)
  {
    LRESULT result = super.WM_GETDLGCODE(wParam, lParam);
    if (result != null) {
      return result;
    }
    int code = 0;
    int index;
    int count;
    if (OS.COMCTL32_MAJOR >= 6)
    {
      LITEM item = new LITEM();
      mask = 3;
      stateMask = 1;
      int index = 0;
      while (OS.SendMessage(handle, 1795, 0, item) != 0)
      {
        if ((state & 0x1) != 0) {
          index = iLink;
        }
        iLink += 1;
      }
      int count = iLink;
      code = callWindowProc(handle, 135, wParam, lParam);
    }
    else
    {
      index = focusIndex;
      count = offsets.length;
    }
    if (count == 0) {
      return new LRESULT(code | 0x100);
    }
    boolean next = OS.GetKeyState(16) >= 0;
    if ((next) && (index < count - 1)) {
      return new LRESULT(code | 0x2);
    }
    if ((!next) && (index > 0)) {
      return new LRESULT(code | 0x2);
    }
    return result;
  }
  
  LRESULT WM_GETFONT(int wParam, int lParam)
  {
    LRESULT result = super.WM_GETFONT(wParam, lParam);
    if (result != null) {
      return result;
    }
    int code = callWindowProc(handle, 49, wParam, lParam);
    if (code != 0) {
      return new LRESULT(code);
    }
    if (font == 0) {
      font = defaultFont();
    }
    return new LRESULT(font);
  }
  
  LRESULT WM_KEYDOWN(int wParam, int lParam)
  {
    LRESULT result = super.WM_KEYDOWN(wParam, lParam);
    if (result != null) {
      return result;
    }
    if (OS.COMCTL32_MAJOR >= 6) {
      switch (wParam)
      {
      case 9: 
      case 13: 
      case 32: 
        return LRESULT.ZERO;
      }
    }
    return result;
  }
  
  LRESULT WM_KILLFOCUS(int wParam, int lParam)
  {
    LRESULT result = super.WM_KILLFOCUS(wParam, lParam);
    if (OS.COMCTL32_MAJOR < 6) {
      redraw();
    }
    return result;
  }
  
  LRESULT WM_LBUTTONDOWN(int wParam, int lParam)
  {
    LRESULT result = super.WM_LBUTTONDOWN(wParam, lParam);
    if (result == LRESULT.ZERO) {
      return result;
    }
    if (OS.COMCTL32_MAJOR < 6)
    {
      if (focusIndex != -1) {
        setFocus();
      }
      int x = OS.GET_X_LPARAM(lParam);
      int y = OS.GET_Y_LPARAM(lParam);
      int offset = layout.getOffset(x, y, null);
      int oldSelectionX = selection.x;
      int oldSelectionY = selection.y;
      selection.x = offset;
      selection.y = -1;
      if ((oldSelectionX != -1) && (oldSelectionY != -1))
      {
        if (oldSelectionX > oldSelectionY)
        {
          int temp = oldSelectionX;
          oldSelectionX = oldSelectionY;
          oldSelectionY = temp;
        }
        Rectangle rect = layout.getBounds(oldSelectionX, oldSelectionY);
        redraw(x, y, width, height, false);
      }
      for (int j = 0; j < offsets.length; j++)
      {
        Rectangle[] rects = getRectangles(j);
        for (int i = 0; i < rects.length; i++)
        {
          Rectangle rect = rects[i];
          if (rect.contains(x, y))
          {
            if (j != focusIndex) {
              redraw();
            }
            focusIndex = (mouseDownIndex = j);
            return result;
          }
        }
      }
    }
    return result;
  }
  
  LRESULT WM_LBUTTONUP(int wParam, int lParam)
  {
    LRESULT result = super.WM_LBUTTONUP(wParam, lParam);
    if (result == LRESULT.ZERO) {
      return result;
    }
    if (OS.COMCTL32_MAJOR < 6)
    {
      if (mouseDownIndex == -1) {
        return result;
      }
      int x = OS.GET_X_LPARAM(lParam);
      int y = OS.GET_Y_LPARAM(lParam);
      Rectangle[] rects = getRectangles(mouseDownIndex);
      for (int i = 0; i < rects.length; i++)
      {
        Rectangle rect = rects[i];
        if (rect.contains(x, y))
        {
          Event event = new Event();
          text = ids[mouseDownIndex];
          sendSelectionEvent(13, event, true);
          break;
        }
      }
    }
    mouseDownIndex = -1;
    return result;
  }
  
  LRESULT WM_NCHITTEST(int wParam, int lParam)
  {
    LRESULT result = super.WM_NCHITTEST(wParam, lParam);
    if (result != null) {
      return result;
    }
    if (OS.COMCTL32_MAJOR >= 6) {
      return new LRESULT(1);
    }
    return result;
  }
  
  LRESULT WM_MOUSEMOVE(int wParam, int lParam)
  {
    LRESULT result = super.WM_MOUSEMOVE(wParam, lParam);
    if (OS.COMCTL32_MAJOR < 6)
    {
      int x = OS.GET_X_LPARAM(lParam);
      int y = OS.GET_Y_LPARAM(lParam);
      if (OS.GetKeyState(1) < 0)
      {
        int oldSelection = selection.y;
        selection.y = layout.getOffset(x, y, null);
        if (selection.y != oldSelection)
        {
          int newSelection = selection.y;
          if (oldSelection > newSelection)
          {
            int temp = oldSelection;
            oldSelection = newSelection;
            newSelection = temp;
          }
          Rectangle rect = layout.getBounds(oldSelection, newSelection);
          redraw(x, y, width, height, false);
        }
      }
      else
      {
        for (int j = 0; j < offsets.length; j++)
        {
          Rectangle[] rects = getRectangles(j);
          for (int i = 0; i < rects.length; i++)
          {
            Rectangle rect = rects[i];
            if (rect.contains(x, y))
            {
              setCursor(display.getSystemCursor(21));
              return result;
            }
          }
        }
        setCursor(null);
      }
    }
    return result;
  }
  
  LRESULT WM_PAINT(int wParam, int lParam)
  {
    if (OS.COMCTL32_MAJOR >= 6) {
      return super.WM_PAINT(wParam, lParam);
    }
    PAINTSTRUCT ps = new PAINTSTRUCT();
    GCData data = new GCData();
    ps = ps;
    hwnd = handle;
    GC gc = new_GC(data);
    if (gc != null)
    {
      int width = right - left;
      int height = bottom - top;
      if ((width != 0) && (height != 0))
      {
        RECT rect = new RECT();
        OS.SetRect(rect, left, top, right, bottom);
        drawWidget(gc, rect);
      }
      gc.dispose();
    }
    return LRESULT.ZERO;
  }
  
  LRESULT WM_PRINTCLIENT(int wParam, int lParam)
  {
    LRESULT result = super.WM_PRINTCLIENT(wParam, lParam);
    if (OS.COMCTL32_MAJOR < 6)
    {
      RECT rect = new RECT();
      OS.GetClientRect(handle, rect);
      GCData data = new GCData();
      device = display;
      foreground = getForegroundPixel();
      GC gc = GC.win32_new(wParam, data);
      drawWidget(gc, rect);
      gc.dispose();
    }
    return result;
  }
  
  LRESULT WM_SETFOCUS(int wParam, int lParam)
  {
    LRESULT result = super.WM_SETFOCUS(wParam, lParam);
    if (OS.COMCTL32_MAJOR < 6) {
      redraw();
    }
    return result;
  }
  
  LRESULT WM_SETFONT(int wParam, int lParam)
  {
    if (OS.COMCTL32_MAJOR < 6) {
      layout.setFont(Font.win32_new(display, wParam));
    }
    if (lParam != 0) {
      OS.InvalidateRect(handle, null, true);
    }
    return super.WM_SETFONT(font = wParam, lParam);
  }
  
  LRESULT WM_SIZE(int wParam, int lParam)
  {
    LRESULT result = super.WM_SIZE(wParam, lParam);
    if (OS.COMCTL32_MAJOR < 6)
    {
      RECT rect = new RECT();
      OS.GetClientRect(handle, rect);
      layout.setWidth(right > 0 ? right : -1);
      redraw();
    }
    return result;
  }
  
  LRESULT wmColorChild(int wParam, int lParam)
  {
    LRESULT result = super.wmColorChild(wParam, lParam);
    if ((OS.COMCTL32_MAJOR >= 6) && 
      (!OS.IsWindowEnabled(handle)))
    {
      OS.SetText
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