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

trDefExt = 0;
    if (save)
    {
      lpstrDefExt = OS.HeapAlloc(hHeap, 8, TCHAR.sizeof);
      lpstrDefExt = lpstrDefExt;
    }
    Dialog oldModal = null;
    Display display = parent.getDisplay();
    if ((style & 0x30000) != 0)
    {
      oldModal = display.getModalDialog();
      display.setModalDialog(this);
    }
    boolean oldRunMessagesInIdle = runMessagesInIdle;
    runMessagesInIdle = (!OS.IsWin95);
    
    boolean success = save ? OS.GetSaveFileName(struct) : OS.GetOpenFileName(struct);
    switch (OS.CommDlgExtendedError())
    {
    case 12290: 
      OS.MoveMemory(lpstrFile, new TCHAR(0, "", true), TCHAR.sizeof);
      success = save ? OS.GetSaveFileName(struct) : OS.GetOpenFileName(struct);
      break;
    case 12291: 
      USE_HOOK = true;
    }
    runMessagesInIdle = oldRunMessagesInIdle;
    if ((style & 0x30000) != 0) {
      display.setModalDialog(oldModal);
    }
    if (callback != null) {
      callback.dispose();
    }
    lpstrFile = lpstrFile;
    
    fileNames = new String[0];
    String fullPath = null;
    if (success)
    {
      TCHAR buffer = new TCHAR(0, nMaxFile);
      int byteCount1 = buffer.length() * TCHAR.sizeof;
      OS.MoveMemory(buffer, lpstrFile, byteCount1);
      
      int nFileOffset = nFileOffset;
      if ((OS.IsWinCE) && (nFileOffset == 0))
      {
        int index = 0;
        while (index < buffer.length())
        {
          int ch = buffer.tcharAt(index);
          if (ch == 0) {
            break;
          }
          if (ch == 92) {
            nFileOffset = index + 1;
          }
          index++;
        }
      }
      if (nFileOffset > 0)
      {
        TCHAR prefix = new TCHAR(0, nFileOffset - 1);
        int byteCount2 = prefix.length() * TCHAR.sizeof;
        OS.MoveMemory(prefix, lpstrFile, byteCount2);
        filterPath = prefix.toString(0, prefix.length());
        
        int count = 0;
        fileNames = new String[(style & 0x2) != 0 ? 4 : 1];
        int start = nFileOffset;
        do
        {
          int end = start;
          while ((end < buffer.length()) && (buffer.tcharAt(end) != 0)) {
            end++;
          }
          String string = buffer.toString(start, end - start);
          start = end;
          if (count == fileNames.length)
          {
            String[] newFileNames = new String[fileNames.length + 4];
            System.arraycopy(fileNames, 0, newFileNames, 0, fileNames.length);
            fileNames = newFileNames;
          }
          fileNames[(count++)] = string;
          if ((style & 0x2) == 0) {
            break;
          }
          start++;
        } while ((start < buffer.length()) && (buffer.tcharAt(start) != 0));
        if (fileNames.length > 0) {
          fileName = fileNames[0];
        }
        String separator = "";
        int length = filterPath.length();
        if ((length > 0) && (filterPath.charAt(length - 1) != '\\')) {
          separator = "\\";
        }
        fullPath = filterPath + separator + fileName;
        if (count < fileNames.length)
        {
          String[] newFileNames = new String[count];
          System.arraycopy(fileNames, 0, newFileNames, 0, count);
          fileNames = newFileNames;
        }
      }
      filterIndex = (nFilterIndex - 1);
    }
    OS.HeapFree(hHeap, 0, lpstrFile);
    OS.HeapFree(hHeap, 0, lpstrFilter);
    OS.HeapFree(hHeap, 0, lpstrInitialDir);
    OS.HeapFree(hHeap, 0, lpstrTitle);
    if (lpstrDefExt != 0) {
      OS.HeapFree(hHeap, 0, lpstrDefExt);
    }
    if (hwndParent != hwndOwner)
    {
      if (enabled) {
        OS.EnableWindow(hwndParent, true);
      }
      OS.SetActiveWindow(hwndParent);
      OS.DestroyWindow(hwndOwner);
    }
    return fullPath;
  }
  
  public void setFileName(String string)
  {
    fileName = string;
  }
  
  public void setFilterExtensions(String[] extensions)
  {
    filterExtensions = extensions;
  }
  
  public void setFilterIndex(int index)
  {
    filterIndex = index;
  }
  
  public void setFilterNames(String[] names)
  {
    filterNames = names;
  }
  
  public void setFilterPath(String string)
  {
    filterPath = string;
  }
  
  public void setOverwrite(boolean overwrite)
  {
    this.overwrite = overwrite;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.swt.widgets.FileDialog
 * 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.graphics.FontData;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.internal.win32.CHOOSEFONT;
import org.eclipse.swt.internal.win32.LOGFONT;
import org.eclipse.swt.internal.win32.LOGFONTA;
import org.eclipse.swt.internal.win32.LOGFONTW;
import org.eclipse.swt.internal.win32.OS;
import org.eclipse.swt.internal.win32.TEXTMETRIC;
import org.eclipse.swt.internal.win32.TEXTMETRICA;
import org.eclipse.swt.internal.win32.TEXTMETRICW;

public class FontDialog
  extends Dialog
{
  FontData fontData;
  RGB rgb;
  
  public FontDialog(Shell parent)
  {
    this(parent, 65536);
  }
  
  public FontDialog(Shell parent, int style)
  {
    super(parent, checkStyle(parent, style));
    checkSubclass();
  }
  
  /**
   * @deprecated
   */
  public FontData getFontData()
  {
    return fontData;
  }
  
  public FontData[] getFontList()
  {
    if (fontData == null) {
      return null;
    }
    FontData[] result = new FontData[1];
    result[0] = fontData;
    return result;
  }
  
  public RGB getRGB()
  {
    return rgb;
  }
  
  public FontData open()
  {
    if (OS.IsWinCE) {
      SWT.error(20);
    }
    int hwndOwner = parent.handle;
    int hwndParent = parent.handle;
    
    boolean enabled = false;
    if ((!OS.IsWinCE) && (OS.WIN32_VERSION >= OS.VERSION(4, 10)))
    {
      int dialogOrientation = style & 0x6000000;
      int parentOrientation = parent.style & 0x6000000;
      if (dialogOrientation != parentOrientation)
      {
        int exStyle = 1048576;
        if (dialogOrientation == 67108864) {
          exStyle |= 0x400000;
        }
        hwndOwner = OS.CreateWindowEx(
          exStyle, 
          Shell.DialogClass, 
          null, 
          0, 
          Integer.MIN_VALUE, 0, Integer.MIN_VALUE, 0, 
          hwndParent, 
          0, 
          OS.GetModuleHandle(null), 
          null);
        enabled = OS.IsWindowEnabled(hwndParent);
        if (enabled) {
          OS.EnableWindow(hwndParent, false);
        }
      }
    }
    int hHeap = OS.GetProcessHeap();
    CHOOSEFONT lpcf = new CHOOSEFONT();
    lStructSize = CHOOSEFONT.sizeof;
    hwndOwner = hwndOwner;
    Flags = 257;
    int lpLogFont = OS.HeapAlloc(hHeap, 8, LOGFONT.sizeof);
    if ((fontData != null) && (fontData.data != null))
    {
      LOGFONT logFont = fontData.data;
      int lfHeight = lfHeight;
      int hDC = OS.GetDC(0);
      int pixels = -(int)(0.5F + fontData.height * OS.GetDeviceCaps(hDC, 90) / 72.0F);
      OS.ReleaseDC(0, hDC);
      lfHeight = pixels;
      Flags |= 0x40;
      OS.MoveMemory(lpLogFont, logFont, LOGFONT.sizeof);
      lfHeight = lfHeight;
    }
    lpLogFont = lpLogFont;
    if (rgb != null)
    {
      int red = rgb.red & 0xFF;
      int green = rgb.green << 8 & 0xFF00;
      int blue = rgb.blue << 16 & 0xFF0000;
      rgbColors = (red | green | blue);
    }
    Dialog oldModal = null;
    Display display = null;
    if ((style & 0x30000) != 0)
    {
      display = parent.getDisplay();
      oldModal = display.getModalDialog();
      display.setModalDialog(this);
    }
    boolean success = OS.ChooseFont(lpcf);
    if ((style & 0x30000) != 0) {
      display.setModalDialog(oldModal);
    }
    if (success)
    {
      LOGFONT logFont = OS.IsUnicode ? new LOGFONTW() : new LOGFONTA();
      OS.MoveMemory(logFont, lpLogFont, LOGFONT.sizeof);
      
      int hDC = OS.GetDC(0);
      int logPixelsY = OS.GetDeviceCaps(hDC, 90);
      int pixels = 0;
      if (lfHeight > 0)
      {
        int hFont = OS.CreateFontIndirect(logFont);
        int oldFont = OS.SelectObject(hDC, hFont);
        TEXTMETRIC lptm = OS.IsUnicode ? new TEXTMETRICW() : new TEXTMETRICA();
        OS.GetTextMetrics(hDC, lptm);
        OS.SelectObject(hDC, oldFont);
        OS.DeleteObject(hFont);
        pixels = lfHeight - tmInternalLeading;
      }
      else
      {
        pixels = -lfHeight;
      }
      OS.ReleaseDC(0, hDC);
      
      float points = pixels * 72.0F / logPixelsY;
      fontData = FontData.win32_new(logFont, points);
      int red = rgbColors & 0xFF;
      int green = rgbColors >> 8 & 0xFF;
      int blue = rgbColors >> 16 & 0xFF;
      rgb = new RGB(red, green, blue);
    }
    if (lpLogFont != 0) {
      OS.HeapFree(hHeap, 0, lpLogFont);
    }
    if (hwndParent != hwndOwner)
    {
      if (enabled) {
        OS.EnableWindow(hwndParent, true);
      }
      OS.SetActiveWindow(hwndParent);
      OS.DestroyWindow(hwndOwner);
    }
    if (!success) {
      return null;
    }
    return fontData;
  }
  
  /**
   * @deprecated
   */
  public void setFontData(FontData fontData)
  {
    this.fontData = fontData;
  }
  
  public void setFontList(FontData[] fontData)
  {
    if ((fontData != null) && (fontData.length > 0)) {
      this.fontData = fontData[0];
    } else {
      this.fontData = null;
    }
  }
  
  public void setRGB(RGB rgb)
  {
    this.rgb = rgb;
  }
}

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

import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.internal.win32.LRESULT;
import org.eclipse.swt.internal.win32.OS;
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.WINDOWPOS;
import org.eclipse.swt.internal.win32.WNDCLASS;

public class Group
  extends Composite
{
  String text = "";
  static final int CLIENT_INSET = 3;
  static final int GroupProc;
  static final TCHAR GroupClass = new TCHAR(0, OS.IsWinCE ? "BUTTON" : "SWT_GROUP", true);
  
  static
  {
    WNDCLASS lpWndClass = new WNDCLASS();
    if (OS.IsWinCE)
    {
      OS.GetClassInfo(0, GroupClass, lpWndClass);
      GroupProc = lpfnWndProc;
    }
    else
    {
      TCHAR WC_BUTTON = new TCHAR(0, "BUTTON", true);
      OS.GetClassInfo(0, WC_BUTTON, lpWndClass);
      GroupProc = lpfnWndProc;
      int hInstance = OS.GetModuleHandle(null);
      if (!OS.GetClassInfo(hInstance, GroupClass, lpWndClass))
      {
        int hHeap = OS.GetProcessHeap();
        lpWndClass.hInstance = hInstance;
        style &= 0xFFFFFFFC;
        int byteCount = GroupClass.length() * TCHAR.sizeof;
        int lpszClassName = OS.HeapAlloc(hHeap, 8, byteCount);
        OS.MoveMemory(lpszClassName, GroupClass, byteCount);
        lpWndClass.lpszClassName = lpszClassName;
        OS.RegisterClass(lpWndClass);
        OS.HeapFree(hHeap, 0, lpszClassName);
      }
    }
  }
  
  public Group(Composite parent, int style)
  {
    super(parent, checkStyle(style));
  }
  
  int callWindowProc(int hwnd, int msg, int wParam, int lParam)
  {
    if (handle == 0) {
      return 0;
    }
    switch (msg)
    {
    case 513: 
    case 515: 
      return OS.DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return OS.CallWindowProc(GroupProc, hwnd, msg, wParam, lParam);
  }
  
  static int checkStyle(int style)
  {
    style |= 0x80000;
    
    return style & 0xFCFF;
  }
  
  protected void checkSubclass()
  {
    if (!isValidSubclass()) {
      error(43);
    }
  }
  
  public Point computeSize(int wHint, int hHint, boolean changed)
  {
    checkWidget();
    Point size = super.computeSize(wHint, hHint, changed);
    int length = text.length();
    if (length != 0)
    {
      String string = text;
      if (((style & 0x4000000) != 0) && (
        (OS.COMCTL32_MAJOR < 6) || (!OS.IsAppThemed()))) {
        string = " " + string + " ";
      }
      TCHAR buffer = new TCHAR(getCodePage(), string, true);
      int oldFont = 0;
      int hDC = OS.GetDC(handle);
      int newFont = OS.SendMessage(handle, 49, 0, 0);
      if (newFont != 0) {
        oldFont = OS.SelectObject(hDC, newFont);
      }
      RECT rect = new RECT();
      int flags = 1056;
      OS.DrawText(hDC, buffer, -1, rect, flags);
      if (newFont != 0) {
        OS.SelectObject(hDC, oldFont);
      }
      OS.ReleaseDC(handle, hDC);
      int offsetY = (OS.COMCTL32_MAJOR >= 6) && (OS.IsAppThemed()) ? 0 : 1;
      x = Math.max(x, right - left + 18 + offsetY);
    }
    return size;
  }
  
  public Rectangle computeTrim(int x, int y, int width, int height)
  {
    checkWidget();
    Rectangle trim = super.computeTrim(x, y, width, height);
    int oldFont = 0;
    int hDC = OS.GetDC(handle);
    int newFont = OS.SendMessage(handle, 49, 0, 0);
    if (newFont != 0) {
      oldFont = OS.SelectObject(hDC, newFont);
    }
    TEXTMETRIC tm = OS.IsUnicode ? new TEXTMETRICW() : new TEXTMETRICA();
    OS.GetTextMetrics(hDC, tm);
    if (newFont != 0) {
      OS.SelectObject(hDC, oldFont);
    }
    OS.ReleaseDC(handle, hDC);
    int offsetY = (OS.COMCTL32_MAJOR >= 6) && (OS.IsAppThemed()) ? 0 : 1;
    x -= 3;
    y -= tmHeight + offsetY;
    width += 6;
    height += tmHeight + 3 + offsetY;
    return trim;
  }
  
  void createHandle()
  {
    parent.state |= 0x100000;
    super.createHandle();
    parent.state &= 0xFFEFFFFF;
    state |= 0x200;
    state &= 0xFFFFFFFD;
  }
  
  void enableWidget(boolean enabled)
  {
    super.enableWidget(enabled);
    if (((style & 0x4000000) != 0) && (
      (OS.COMCTL32_MAJOR < 6) || (!OS.IsAppThemed())))
    {
      String string = " " + text + " ";
      TCHAR buffer = new TCHAR(getCodePage(), string, true);
      OS.SetWindowText(handle, buffer);
    }
  }
  
  public Rectangle getClientArea()
  {
    checkWidget();
    forceResize();
    RECT rect = new RECT();
    OS.GetClientRect(handle, rect);
    int oldFont = 0;
    int hDC = OS.GetDC(handle);
    int newFont = OS.SendMessage(handle, 49, 0, 0);
    if (newFont != 0) {
      oldFont = OS.SelectObject(hDC, newFont);
    }
    TEXTMETRIC tm = OS.IsUnicode ? new TEXTMETRICW() : new TEXTMETRICA();
    OS.GetTextMetrics(hDC, tm);
    if (newFont != 0) {
      OS.SelectObject(hDC, oldFont);
    }
    OS.ReleaseDC(handle, hDC);
    int offsetY = (OS.COMCTL32_MAJOR >= 6) && (OS.IsAppThemed()) ? 0 : 1;
    int x = 3;int y = tmHeight + offsetY;
    int width = Math.max(0, right - 6);
    int height = Math.max(0, bottom - y - 3);
    return new Rectangle(x, y, width, height);
  }
  
  String getNameText()
  {
    return getText();
  }
  
  public String getText()
  {
    checkWidget();
    return text;
  }
  
  boolean mnemonicHit(char key)
  {
    return setFocus();
  }
  
  boolean mnemonicMatch(char key)
  {
    char mnemonic = findMnemonic(getText());
    if (mnemonic == 0) {
      return false;
    }
    return Character.toUpperCase(key) == Character.toUpperCase(mnemonic);
  }
  
  void printWidget(int hwnd, int hdc, GC gc)
  {
    boolean success = false;
    if (OS.GetDeviceCaps(handle, 2) != 2)
    {
      int bits = OS.GetWindowLong(hwnd, -16);
      if ((bits & 0x10000000) == 0) {
        OS.ShowWindow(hwnd, 5);
      }
      success = OS.PrintWindow(hwnd, hdc, 0);
      if ((bits & 0x10000000) == 0) {
        OS.ShowWindow(hwnd, 0);
      }
    }
    if (!success)
    {
      int flags = 14;
      OS.SendMessage(hwnd, 791, hdc, flags);
      int nSavedDC = OS.SaveDC(hdc);
      Control[] children = _getChildren();
      Rectangle rect = getBounds();
      OS.IntersectClipRect(hdc, 0, 0, width, height);
      for (int i = children.length - 1; i >= 0; i--)
      {
        Point location = children[i].getLocation();
        int graphicsMode = OS.GetGraphicsMode(hdc);
        if (graphicsMode == 2)
        {
          float[] lpXform = { 1.0F, 0.0F, 0.0F, 1.0F, x, y };
          OS.ModifyWorldTransform(hdc, lpXform, 2);
        }
        else
        {
          OS.SetWindowOrgEx(hdc, -x, -y, null);
        }
        int topHandle = children[i].topHandle();
        int bits = OS.GetWindowLong(topHandle, -16);
        if ((bits & 0x10000000) != 0) {
          children[i].printWidget(topHandle, hdc, gc);
        }
        if (graphicsMode == 2)
        {
          float[] lpXform = { 1.0F, 0.0F, 0.0F, 1.0F, -x, -y };
          OS.ModifyWorldTransform(hdc, lpXform, 2);
        }
      }
      OS.RestoreDC(hdc, nSavedDC);
    }
  }
  
  void releaseWidget()
  {
    super.releaseWidget();
    text = null;
  }
  
  public void setFont(Font font)
  {
    checkWidget();
    Rectangle oldRect = getClientArea();
    super.setFont(font);
    Rectangle newRect = getClientArea();
    if (!oldRect.equals(newRect)) {
      sendResize();
    }
  }
  
  public void setText(String string)
  {
    checkWidget();
    if (string == null) {
      error(4);
    }
    text = string;
    if (((style & 0x4000000) != 0) && 
      ((OS.COMCTL32_MAJOR < 6) || (!OS.IsAppThemed())) && 
      (!OS.IsWindowEnabled(handle)) && 
      (string.length() != 0)) {
      string = " " + string + " ";
    }
    TCHAR buffer = new TCHAR(getCodePage(), string, true);
    OS.SetWindowText(handle, buffer);
  }
  
  int widgetStyle()
  {
    return super.widgetStyle() | 0x7 | 0x2000000 | 0x4000000;
  }
  
  TCHAR windowClass()
  {
    return GroupClass;
  }
  
  int windowProc()
  {
    return GroupProc;
  }
  
  LRESULT WM_ERASEBKGND(int wParam, int lParam)
  {
    LRESULT result = super.WM_ERASEBKGND(wParam, lParam);
    if (result != null) {
      return result;
    }
    drawBackground(wParam);
    return LRESULT.ONE;
  }
  
  LRESULT WM_NCHITTEST(int wParam, int lParam)
  {
    LRESULT result = super.WM_NCHITTEST(wParam, lParam);
    if (result != null) {
      return result;
    }
    int code = callWindowProc(handle, 132, wParam, lParam);
    if (code == -1) {
      code = 1;
    }
    return new LRESULT(code);
  }
  
  LRESULT WM_MOUSEMOVE(int wParam, int lParam)
  {
    LRESULT result = super.WM_MOUSEMOVE(wParam, lParam);
    if (result != null) {
      return result;
    }
    return LRESULT.ZERO;
  }
  
  LRESULT WM_PRINTCLIENT(int wParam, int lParam)
  {
    LRESULT result = super.WM_PRINTCLIENT(wParam, lParam);
    if (result != null) {
      return result;
    }
    if ((OS.COMCTL32_MAJOR >= 6) && (OS.IsAppThemed()))
    {
      int nSavedDC = OS.SaveDC(wParam);
      int code = callWindowProc(handle, 792, wParam, lParam);
      OS.RestoreDC(wParam, nSavedDC);
      return new LRESULT(code);
    }
    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)
    {
      if (((state & 0x100) != 0) && 
        (OS.COMCTL32_MAJOR >= 6) && (OS.IsAppThemed())) {
        redraw = findThemeControl() != null;
      }
      if (!redraw) {
        redraw = findBackgroundControl() != null;
      }
    }
    if (redraw)
    {
      OS.InvalidateRect(handle, null, false);
      int code = OS.DefWindowProc(handle, 296, wParam, lParam);
      return new LRESULT(code);
    }
    return result;
  }
  
  LRESULT WM_WINDOWPOSCHANGING(int wParam, int lParam)
  {
    LRESULT result = super.WM_WINDOWPOSCHANGING(wParam, lParam);
    if (result != null) {
      return result;
    }
    if (OS.IsWinCE) {
      return result;
    }
    if (!OS.IsWindowVisible(handle)) {
      return result;
    }
    WINDOWPOS lpwp = new WINDOWPOS();
    OS.MoveMemory(lpwp, lParam, WINDOWPOS.sizeof);
    if ((flags & 0x9) != 0) {
      return result;
    }
    RECT rect = new RECT();
    OS.SetRect(rect, 0, 0, cx, cy);
    OS.SendMessage(handle, 131, 0, rect);
    int newWidth = right - left;
    int newHeight = bottom - top;
    OS.GetClientRect(handle, rect);
    int oldWidth = right - left;
    int oldHeight = bottom - top;
    if ((newWidth == oldWidth) && (newHeight == oldHeight)) {
      return result;
    }
    if (newWidth != oldWidth)
    {
      int left = oldWidth;
      if (newWidth < oldWidth) {
        left = newWidth;
      }
      OS.SetRect(rect, left - 3, 0, newWidth, newHeight);
      OS.InvalidateRect(handle, rect, true);
    }
    if (newHeight != oldHeight)
    {
      int bottom = oldHeight;
      if (newHeight < oldHeight) {
        bottom = newHeight;
      }
      if (newWidth < oldWidth) {
        oldWidth -= 3;
      }
      OS.SetRect(rect, 0, bottom - 3, oldWidth, newHeight);
      OS.InvalidateRect(handle, rect, true);
    }
    return result;
  }
}

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

import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.TextStyle;
import org.eclipse.swt.internal.win32.LRESULT;
import org.eclipse.swt.internal.win32.OS;
import org.eclipse.swt.internal.win32.TCHAR;
import org.eclipse.swt.internal.win32.TF_DA_COLOR;
import org.eclipse.swt.internal.win32.TF_DISPLAYATTRIBUTE;

public class IME
  extends Widget
{
  Canvas parent;
  int caretOffset;
  int startOffset;
  int commitCount;
  String text;
  int[] ranges;
  TextStyle[] styles;
  static final int WM_MSIME_MOUSE = OS.RegisterWindowMessage(new TCHAR(0, "MSIMEMouseOperation", true));
  static final byte[] IID_ITfInputProcessorProfiles = new byte[16];
  static final byte[] IID_ITfDisplayAttributeProvider = new byte[16];
  static final byte[] CLSID_TF_InputProcessorProfiles = new byte[16];
  static final byte[] GUID_TFCAT_TIP_KEYBOARD = new byte[16];
  static final int UNDERLINE_IME_DOT = 65536;
  static final int UNDERLINE_IME_DASH = 131072;
  static final int UNDERLINE_IME_THICK = 196608;
  
  static
  {
    OS.IIDFromString("{1F02B6C5-7842-4EE6-8A0B-9A24183A95CA}\000".toCharArray(), IID_ITfInputProcessorProfiles);
    OS.IIDFromString("{fee47777-163c-4769-996a-6e9c50ad8f54}\000".toCharArray(), IID_ITfDisplayAttributeProvider);
    OS.IIDFromString("{33C53A50-F456-4884-B049-85FD643ECFED}\000".toCharArray(), CLSID_TF_InputProcessorProfiles);
    OS.IIDFromString("{34745C63-B2F0-4784-8B67-5E12C8701A31}\000".toCharArray(), GUID_TFCAT_TIP_KEYBOARD);
  }
  
  IME() {}
  
  public IME(Canvas parent, int style)
  {
    super(parent, style);
    this.parent = parent;
    createWidget();
  }
  
  void createWidget()
  {
    text = "";
    startOffset = -1;
    if (parent.getIME() == null) {
      parent.setIME(this);
    }
  }
  
  public int getCaretOffset()
  {
    checkWidget();
    return startOffset + caretOffset;
  }
  
  public int getCommitCount()
  {
    checkWidget();
    return commitCount;
  }
  
  public int getCompositionOffset()
  {
    checkWidget();
    return startOffset;
  }
  
  TF_DISPLAYATTRIBUTE getDisplayAttribute(short langid, int attInfo)
  {
    int[] pProfiles = new int[1];
    int hr = OS.CoCreateInstance(CLSID_TF_InputProcessorProfiles, 0, 1, IID_ITfInputProcessorProfiles, pProfiles);
    TF_DISPLAYATTRIBUTE pda = null;
    if (hr == 0)
    {
      byte[] pclsid = new byte[16];
      byte[] pguidProfile = new byte[16];
      
      hr = OS.VtblCall(8, pProfiles[0], langid, GUID_TFCAT_TIP_KEYBOARD, pclsid, pguidProfile);
      if (hr == 0)
      {
        int[] pProvider = new int[1];
        hr = OS.CoCreateInstance(pclsid, 0, 1, IID_ITfDisplayAttributeProvider, pProvider);
        if (hr == 0)
        {
          int[] pEnum = new int[1];
          
          hr = OS.VtblCall(3, pProvider[0], pEnum);
          if (hr == 0)
          {
            int[] pDispInfo = new int[1];
            TF_DISPLAYATTRIBUTE tempPda = new TF_DISPLAYATTRIBUTE();
            while ((hr = OS.VtblCall(4, pEnum[0], 1, pDispInfo, null)) == 0)
            {
              OS.VtblCall(5, pDispInfo[0], tempPda);
              
              OS.VtblCall(2, pDispInfo[0]);
              if (bAttr == attInfo)
              {
                pda = tempPda;
                break;
              }
            }
            hr = OS.VtblCall(2, pEnum[0]);
          }
          hr = OS.VtblCall(2, pProvider[0]);
        }
      }
      hr = OS.VtblCall(2, pProfiles[0]);
    }
    if (pda == null)
    {
      pda = new TF_DISPLAYATTRIBUTE();
      switch (attInfo)
      {
      case 0: 
        lsStyle = 4;
        break;
      case 1: 
      case 2: 
        lsStyle = 1;
        fBoldLine = (attInfo == 1);
      }
    }
    return pda;
  }
  
  public int[] getRanges()
  {
    checkWidget();
    if (ranges == null) {
      return new int[0];
    }
    int[] result = new int[ranges.length];
    for (int i = 0; i < result.length; i++) {
      result[i] = (ranges[i] + startOffset);
    }
    return result;
  }
  
  public TextStyle[] getStyles()
  {
    checkWidget();
    if (styles == null) {
      return new TextStyle[0];
    }
    TextStyle[] result = new TextStyle[styles.length];
    System.arraycopy(styles, 0, result, 0, styles.length);
    return result;
  }
  
  public String getText()
  {
    checkWidget();
    return text;
  }
  
  public boolean getWideCaret()
  {
    checkWidget();
    int layout = OS.GetKeyboardLayout(0);
    short langID = (short)OS.LOWORD(layout);
    return OS.PRIMARYLANGID(langID) == 18;
  }
  
  boolean isInlineEnabled()
  {
    if ((OS.IsWinCE) || (OS.WIN32_VERSION < OS.VERSION(5, 1))) {
      return false;
    }
    return (OS.IsDBLocale) && (hooks(43));
  }
  
  void releaseParent()
  {
    super.releaseParent();
    if (this == parent.getIME()) {
      parent.setIME(null);
    }
  }
  
  void releaseWidget()
  {
    super.releaseWidget();
    parent = null;
    text = null;
    styles = null;
    ranges = null;
  }
  
  public void setCompositionOffset(int offset)
  {
    checkWidget();
    if (offset < 0) {
      return;
    }
    if (startOffset != -1) {
      startOffset = offset;
    }
  }
  
  LRESULT WM_IME_COMPOSITION(int wParam, int lParam)
  {
    if (!isInlineEnabled()) {
      return null;
    }
    ranges = null;
    styles = null;
    caretOffset = (commitCount = 0);
    int hwnd = parent.handle;
    int hIMC = OS.ImmGetContext(hwnd);
    int codePage = parent.getCodePage();
    if (hIMC != 0)
    {
      TCHAR buffer = null;
      if ((lParam & 0x800) != 0)
      {
        int length = OS.ImmGetCompositionString(hIMC, 2048, null, 0);
        if (length > 0)
        {
          buffer = new TCHAR(codePage, length / TCHAR.sizeof);
          OS.ImmGetCompositionString(hIMC, 2048, buffer, length);
          if (startOffset == -1)
          {
            Event event = new Event();
            detail = 3;
            sendEvent(43, event);
            startOffset = start;
          }
          Event event = new Event();
          detail = 1;
          start = startOffset;
          end = (startOffset + text.length());
          text = (text = buffer != null ? buffer.toString() : "");
          commitCount = text.length();
          sendEvent(43, event);
          String chars = text;
          text = "";
          startOffset = -1;
          commitCount = 0;
          if (doit)
          {
            Display display = this.display;
            lastKey = 0;
            lastVirtual = (lastNull = lastDead = 0);
            length = chars.length();
            for (int i = 0; i < length; i++)
            {
              char c = chars.charAt(i);
              lastAscii = c;
              event = new Event();
              character = c;
              parent.sendEvent(1, event);
            }
          }
        }
        if ((lParam & 0x8) == 0) {
          return LRESULT.ONE;
        }
      }
      buffer = null;
      if ((lParam & 0x8) != 0)
      {
        int length = OS.ImmGetCompositionString(hIMC, 8, null, 0);
        if (length > 0)
        {
          buffer = new TCHAR(codePage, length / TCHAR.sizeof);
          OS.ImmGetCompositionString(hIMC, 8, buffer, length);
          if ((lParam & 0x80) != 0) {
            caretOffset = OS.ImmGetCompositionString(hIMC, 128, null, 0);
          }
          int[] clauses = (int[])null;
          if ((lParam & 0x20) != 0)
          {
            length = OS.ImmGetCompositionString(hIMC, 32, null, 0);
            if (length > 0)
            {
              clauses = new int[length / 4];
              OS.ImmGetCompositionString(hIMC, 32, clauses, length);
            }
          }
          if (((lParam & 0x10) != 0) && (clauses != null))
          {
            length = OS.ImmGetCompositionString(hIMC, 16, null, 0);
            if (length > 0)
            {
              byte[] attrs = new byte[length];
              OS.ImmGetCompositionString(hIMC, 16, attrs, length);
              length = clauses.length - 1;
              ranges = new int[length * 2];
              styles = new TextStyle[length];
              int layout = OS.GetKeyboardLayout(0);
              short langID = (short)OS.LOWORD(layout);
              TF_DISPLAYATTRIBUTE attr = null;
              TextStyle style = null;
              for (int i = 0; i < length; i++)
              {
                ranges[(i * 2)] = clauses[i];
                ranges[(i * 2 + 1)] = (clauses[(i + 1)] - 1);
                styles[i] = (style = new TextStyle());
                attr = getDisplayAttribute(langID, attrs[clauses[i]]);
                if (attr != null)
                {
                  switch (crText.type)
                  {
                  case 2: 
                    foreground = Color.win32_new(this.display, crText.cr);
                    break;
                  case 1: 
                    int colorRef = OS.GetSysColor(crText.cr);
                    foreground = Color.win32_new(this.display, colorRef);
                  }
                  switch (crBk.type)
                  {
                  case 2: 
                    background = Color.win32_new(this.display, crBk.cr);
                    break;
                  case 1: 
                    int colorRef = OS.GetSysColor(crBk.cr);
                    background = Color.win32_new(this.display, colorRef);
                  }
                  switch (crLine.type)
                  {
                  case 2: 
                    underlineColor = Color.win32_new(this.display, crLine.cr);
                    break;
                  case 1: 
                    int colorRef = OS.GetSysColor(crLine.cr);
                    underlineColor = Color.win32_new(this.display, colorRef);
                  }
                  underline = (lsStyle != 0);
                  switch (lsStyle)
                  {
                  case 4: 
                    underlineStyle = 3;
                    break;
                  case 3: 
                    underlineStyle = 131072;
                    break;
                  case 2: 
                    underlineStyle = 65536;
                    break;
                  case 1: 
                    underlineStyle = (fBoldLine ? 196608 : 0);
                  }
                }
              }
            }
          }
        }
        OS.ImmReleaseContext(hwnd, hIMC);
      }
      int end = startOffset + text.length();
      if (startOffset == -1)
      {
        Event event = new Event();
        detail = 3;
        sendEvent(43, event);
        startOffset = start;
        end = end;
      }
      Event event = new Event();
      detail = 1;
      start = startOffset;
      end = end;
      text = (text = buffer != null ? buffer.toString() : "");
      sendEvent(43, event);
      if (text.length() == 0)
      {
        startOffset = -1;
        ranges = null;
        styles = null;
      }
    }
    return LRESULT.ONE;
  }
  
  LRESULT WM_IME_COMPOSITION_START(int wParam, int lParam)
  {
    return isInlineEnabled() ? LRESULT.ONE : null;
  }
  
  LRESULT WM_IME_ENDCOMPOSITION(int wParam, int lParam)
  {
    return isInlineEnabled() ? LRESULT.ONE : null;
  }
  
  LRESULT WM_KILLFOCUS(int wParam, int lParam)
  {
    if (!isInlineEnabled()) {
      return null;
    }
    int hwnd = parent.handle;
    int hIMC = OS.ImmGetContext(hwnd);
    if (hIMC != 0)
    {
      if (OS.ImmGetOpenStatus(hIMC)) {
        OS.ImmNotifyIME(hIMC, 21, 1, 0);
      }
      OS.ImmReleaseContext(hwnd, hIMC);
    }
    return null;
  }
  
  LRESULT WM_LBUTTONDOWN(int wParam, int lParam)
  {
    if (!isInlineEnabled()) {
      return null;
    }
    int hwnd = parent.handle;
    int hIMC = OS.ImmGetContext(hwnd);
    if (hIMC != 0)
    {
      if ((OS.ImmGetOpenStatus(hIMC)) && 
        (OS.ImmGetCompositionString(hIMC, 8, null, 0) > 0))
      {
        Event event = new Event();
        detail = 2;
        x = OS.GET_X_LPARAM(lParam);
        y = OS.GET_Y_LPARAM(lParam);
        sendEvent(43, event);
        int offset = index;
        int length = text.length();
        if ((offset != -1) && (startOffset != -1) && (startOffset <= offset) && (offset < startOffset + length))
        {
          int imeWnd = OS.ImmGetDefaultIMEWnd(hwnd);
          offset = index + count - startOffset;
          int trailing = count > 0 ? 1 : 2;
          int param = OS.MAKEWPARAM(OS.MAKEWORD(1, trailing), offset);
          OS.SendMessage(imeWnd, WM_MSIME_MOUSE, param, hIMC);
        }
        else
        {
          OS.ImmNotifyIME(hIMC, 21, 1, 0);
        }
      }
      OS.ImmReleaseContext(hwnd, hIMC);
    }
    return null;
  }
}

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

import org.eclipse.swt.graphics.Image;

public abstract class Item
  extends Widget
{
  String text;
  Image image;
  
  public Item(Widget parent, int style)
  {
    super(parent, style);
    text = "";
  }
  
  public Item(Widget parent, int style, int index)
  {
    this(parent, style);
  }
  
  protected void checkSubclass() {}
  
  public Image getImage()
  {
    checkWidget();
    return image;
  }
  
  String getNameText()
  {
    return getText();
  }
  
  public String getText()
  {
    checkWidget();
    return text;
  }
  
  void releaseWidget()
  {
    super.releaseWidget();
    text = null;
    image = null;
  }
  
  public void setImage(Image image)
  {
    checkWidget();
    if ((image != null) && (image.isDisposed())) {
      error(5);
    }
    this.image = image;
  }
  
  public void setText(String string)
  {
    checkWidget();
    if (string == null) {
      error(4);
    }
    text = string;
  }
}

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

import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.GCData;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.internal.win32.DRAWITEMSTRUCT;
import org.eclipse.swt.internal.win32.LRESULT;
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 Label
  extends Control
{
  String text = "";
  Image image;
  static final int MARGIN = 4;
  static boolean IMAGE_AND_TEXT = false;
  static final int LabelProc;
  static final TCHAR LabelClass = new TCHAR(0, "STATIC", true);
  
  static
  {
    WNDCLASS lpWndClass = new WNDCLASS();
    OS.GetClassInfo(0, LabelClass, lpWndClass);
    LabelProc = lpfnWndProc;
  }
  
  public Label(Composite parent, int style)
  {
    super(parent, checkStyle(style));
  }
  
  int callWindowProc(int hwnd, int msg, int wParam, int lParam)
  {
    if (handle == 0) {
      return 0;
    }
    if ((!OS.IsWinCE) && (OS.WIN32_VERSION >= OS.VERSION(6, 1))) {
      switch (msg)
      {
      case 515: 
        return OS.DefWindowProc(hwnd, msg, wParam, lParam);
      }
    }
    return OS.CallWindowProc(LabelProc, hwnd, msg, wParam, lParam);
  }
  
  static int checkStyle(int style)
  {
    style |= 0x80000;
    if ((style & 0x2) != 0)
    {
      style = checkBits(style, 512, 256, 0, 0, 0, 0);
      return checkBits(style, 8, 4, 32, 0, 0, 0);
    }
    return checkBits(style, 16384, 16777216, 131072, 0, 0, 0);
  }
  
  public Point computeSize(int wHint, int hHint, boolean changed)
  {
    checkWidget();
    int width = 0;int height = 0;int border = getBorderWidth();
    if ((style & 0x2) != 0)
    {
      int lineWidth = OS.GetSystemMetrics(5);
      if ((style & 0x100) != 0)
      {
        width = 64;height = lineWidth * 2;
      }
      else
      {
        width = lineWidth * 2;height = 64;
      }
      if (wHint != -1) {
        width = wHint;
      }
      if (hHint != -1) {
        height = hHint;
      }
      width += border * 2;height += border * 2;
      return new Point(width, height);
    }
    int bits = OS.GetWindowLong(handle, -16);
    boolean drawText = true;
    boolean drawImage = (bits & 0xD) == 13;
    if ((drawImage) && 
      (image != null))
    {
      Rectangle rect = image.getBounds();
      width += width;
      height += height;
      if (IMAGE_AND_TEXT)
      {
        if (text.length() != 0) {
          width += 4;
        }
      }
      else {
        drawText = false;
      }
    }
    if (drawText)
    {
      int hDC = OS.GetDC(handle);
      int newFont = OS.SendMessage(handle, 49, 0, 0);
      int oldFont = OS.SelectObject(hDC, newFont);
      int length = OS.GetWindowTextLength(handle);
      if (length == 0)
      {
        TEXTMETRIC tm = OS.IsUnicode ? new TEXTMETRICW() : new TEXTMETRICA();
        OS.GetTextMetrics(hDC, tm);
        height = Math.max(height, tmHeight);
      }
      else
      {
        RECT rect = new RECT();
        int flags = 9280;
        if (((style & 0x40) != 0) && (wHint != -1))
        {
          flags |= 0x10;
          right = Math.max(0, wHint - width);
        }
        TCHAR buffer = new TCHAR(getCodePage(), length + 1);
        OS.GetWindowText(handle, buffer, length + 1);
        OS.DrawText(hDC, buffer, length, rect, flags);
        width += right - left;
        height = Math.max(height, bottom - top);
      }
      if (newFont != 0) {
        OS.SelectObject(hDC, oldFont);
      }
      OS.ReleaseDC(handle, hDC);
    }
    if (wHint != -1) {
      width = wHint;
    }
    if (hHint != -1) {
      height = hHint;
    }
    width += border * 2;
    height += border * 2;
    if ((OS.IsWinCE) && (!drawImage)) {
      width += 2;
    }
    return new Point(width, height);
  }
  
  void createHandle()
  {
    super.createHandle();
    state |= 0x100;
  }
  
  public int getAlignment()
  {
    checkWidget();
    if ((style & 0x2) != 0) {
      return 0;
    }
    if ((style & 0x4000) != 0) {
      return 16384;
    }
    if ((style & 0x1000000) != 0) {
      return 16777216;
    }
    if ((style & 0x20000) != 0) {
      return 131072;
    }
    return 16384;
  }
  
  public Image getImage()
  {
    checkWidget();
    return image;
  }
  
  String getNameText()
  {
    return getText();
  }
  
  public String getText()
  {
    checkWidget();
    if ((style & 0x2) != 0) {
      return "";
    }
    return text;
  }
  
  boolean mnemonicHit(char key)
  {
    Composite control = parent;
    while (control != null)
    {
      Control[] children = control._getChildren();
      int index = 0;
      while (index < children.length)
      {
        if (children[index] == this) {
          break;
        }
        index++;
      }
      index++;
      if ((index < children.length) && 
        (children[index].setFocus())) {
        return 
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