Exemplo n.º 1
0
  /**
   * This implementation of <code>nativeToJava</code> converts a platform specific representation of
   * a list of file names to a java <code>String[]</code>. Each String in the array contains the
   * absolute path for a single file or directory. For additional information see <code>
   * Transfer#nativeToJava</code>.
   *
   * @param transferData the platform specific representation of the data to be been converted
   * @return a java <code>String[]</code> containing a list of file names if the conversion was
   *     successful; otherwise null
   */
  public Object nativeToJava(TransferData transferData) {
    if (!isSupportedType(transferData) || transferData.pIDataObject == 0) return null;

    // get file names from IDataObject
    IDataObject dataObject = new IDataObject(transferData.pIDataObject);
    dataObject.AddRef();
    FORMATETC formatetc = new FORMATETC();
    formatetc.cfFormat = COM.CF_HDROP;
    formatetc.ptd = 0;
    formatetc.dwAspect = COM.DVASPECT_CONTENT;
    formatetc.lindex = -1;
    formatetc.tymed = COM.TYMED_HGLOBAL;
    STGMEDIUM stgmedium = new STGMEDIUM();
    stgmedium.tymed = COM.TYMED_HGLOBAL;
    transferData.result = dataObject.GetData(formatetc, stgmedium);
    dataObject.Release();
    if (transferData.result != COM.S_OK) return null;
    // How many files are there?
    int count = OS.DragQueryFile(stgmedium.unionField, 0xFFFFFFFF, null, 0);
    String[] fileNames = new String[count];
    for (int i = 0; i < count; i++) {
      // How long is the name ?
      int size = OS.DragQueryFile(stgmedium.unionField, i, null, 0) + 1;
      TCHAR lpszFile = new TCHAR(0, size);
      // Get file name and append it to string
      OS.DragQueryFile(stgmedium.unionField, i, lpszFile, size);
      fileNames[i] = lpszFile.toString(0, lpszFile.strlen());
    }
    OS.DragFinish(stgmedium.unionField); // frees data associated with HDROP data
    return fileNames;
  }
Exemplo n.º 2
0
 /**
  * This implementation of <code>javaToNative</code> converts a list of file names represented by a
  * java <code>String[]</code> to a platform specific representation. Each <code>String</code> in
  * the array contains the absolute path for a single file or directory. For additional information
  * see <code>Transfer#javaToNative</code>.
  *
  * @param object a java <code>String[]</code> containing the file names to be converted
  * @param transferData an empty <code>TransferData</code> object; this object will be filled in on
  *     return with the platform specific format of the data
  */
 public void javaToNative(Object object, TransferData transferData) {
   if (!checkFile(object) || !isSupportedType(transferData)) {
     DND.error(DND.ERROR_INVALID_DATA);
   }
   String[] fileNames = (String[]) object;
   StringBuffer allFiles = new StringBuffer();
   for (int i = 0; i < fileNames.length; i++) {
     allFiles.append(fileNames[i]);
     allFiles.append(CF_HDROP_SEPARATOR); // each name is null terminated
   }
   TCHAR buffer =
       new TCHAR(
           0, allFiles.toString(), true); // there is an extra null terminator at the very end
   DROPFILES dropfiles = new DROPFILES();
   dropfiles.pFiles = DROPFILES.sizeof;
   dropfiles.pt_x = dropfiles.pt_y = 0;
   dropfiles.fNC = 0;
   dropfiles.fWide = OS.IsUnicode ? 1 : 0;
   // Allocate the memory because the caller (DropTarget) has not handed it in
   // The caller of this method must release the data when it is done with it.
   int byteCount = buffer.length() * TCHAR.sizeof;
   int /*long*/ newPtr =
       OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, DROPFILES.sizeof + byteCount);
   OS.MoveMemory(newPtr, dropfiles, DROPFILES.sizeof);
   OS.MoveMemory(newPtr + DROPFILES.sizeof, buffer, byteCount);
   transferData.stgmedium = new STGMEDIUM();
   transferData.stgmedium.tymed = COM.TYMED_HGLOBAL;
   transferData.stgmedium.unionField = newPtr;
   transferData.stgmedium.pUnkForRelease = 0;
   transferData.result = COM.S_OK;
 }
 static String getCacheParentPath() {
   /* Use the character encoding for the default locale */
   TCHAR buffer = new TCHAR(0, OS.MAX_PATH);
   if (OS.SHGetFolderPath(0, OS.CSIDL_LOCAL_APPDATA, 0, OS.SHGFP_TYPE_CURRENT, buffer)
       == OS.S_OK) {
     return buffer.toString(0, buffer.strlen()) + Mozilla.SEPARATOR_OS + "eclipse"; // $NON-NLS-1$
   }
   return getProfilePath();
 }
Exemplo n.º 4
0
 public Point computeSize(int wHint, int hHint, boolean changed) {
   checkWidget();
   if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
   if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
   int width, height;
   if (OS.COMCTL32_MAJOR >= 6) {
     int /*long*/ hDC = OS.GetDC(handle);
     int /*long*/ newFont = OS.SendMessage(handle, OS.WM_GETFONT, 0, 0);
     int /*long*/ oldFont = OS.SelectObject(hDC, newFont);
     if (text.length() > 0) {
       TCHAR buffer = new TCHAR(getCodePage(), parse(text), false);
       RECT rect = new RECT();
       int flags = OS.DT_CALCRECT | OS.DT_NOPREFIX;
       if (wHint != SWT.DEFAULT) {
         flags |= OS.DT_WORDBREAK;
         rect.right = wHint;
       }
       OS.DrawText(hDC, buffer, buffer.length(), rect, flags);
       width = rect.right - rect.left;
       height = rect.bottom;
     } else {
       TEXTMETRIC lptm = OS.IsUnicode ? (TEXTMETRIC) new TEXTMETRICW() : new TEXTMETRICA();
       OS.GetTextMetrics(hDC, lptm);
       width = 0;
       height = lptm.tmHeight;
     }
     if (newFont != 0) OS.SelectObject(hDC, oldFont);
     OS.ReleaseDC(handle, hDC);
   } else {
     int layoutWidth = layout.getWidth();
     // TEMPORARY CODE
     if (wHint == 0) {
       layout.setWidth(1);
       Rectangle rect = layout.getBounds();
       width = 0;
       height = rect.height;
     } else {
       layout.setWidth(wHint);
       Rectangle rect = layout.getBounds();
       width = rect.width;
       height = rect.height;
     }
     layout.setWidth(layoutWidth);
   }
   if (wHint != SWT.DEFAULT) width = wHint;
   if (hHint != SWT.DEFAULT) height = hHint;
   int border = getBorderWidth();
   width += border * 2;
   height += border * 2;
   return new Point(width, height);
 }
 static String getProfilePath() {
   String baseDir;
   /* Use the character encoding for the default locale */
   TCHAR buffer = new TCHAR(0, OS.MAX_PATH);
   if (OS.SHGetFolderPath(0, OS.CSIDL_APPDATA, 0, OS.SHGFP_TYPE_CURRENT, buffer) == OS.S_OK) {
     baseDir = buffer.toString(0, buffer.strlen());
   } else {
     baseDir = System.getProperty("user.home"); // $NON-NLS-1$
   }
   return baseDir
       + Mozilla.SEPARATOR_OS
       + "Mozilla"
       + Mozilla.SEPARATOR_OS
       + "eclipse"; //$NON-NLS-1$ //$NON-NLS-2$
 }
Exemplo n.º 6
0
 static {
   WNDCLASS lpWndClass = new WNDCLASS();
   OS.GetClassInfo(0, ProgressBarClass, lpWndClass);
   ProgressBarProc = lpWndClass.lpfnWndProc;
   /*
    * Feature in Windows.  The progress bar window class
    * does not include CS_DBLCLKS.  This means that these
    * controls will not get double click messages such as
    * WM_LBUTTONDBLCLK.  The fix is to register a new
    * window class with CS_DBLCLKS.
    *
    * NOTE:  Screen readers look for the exact class name
    * of the control in order to provide the correct kind
    * of assistance.  Therefore, it is critical that the
    * new window class have the same name.  It is possible
    * to register a local window class with the same name
    * as a global class.  Since bits that affect the class
    * are being changed, it is possible that other native
    * code, other than SWT, could create a control with
    * this class name, and fail unexpectedly.
    */
   int /*long*/ hInstance = OS.GetModuleHandle(null);
   int /*long*/ hHeap = OS.GetProcessHeap();
   lpWndClass.hInstance = hInstance;
   lpWndClass.style &= ~OS.CS_GLOBALCLASS;
   lpWndClass.style |= OS.CS_DBLCLKS;
   int byteCount = ProgressBarClass.length() * TCHAR.sizeof;
   int /*long*/ lpszClassName = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
   OS.MoveMemory(lpszClassName, ProgressBarClass, byteCount);
   lpWndClass.lpszClassName = lpszClassName;
   OS.RegisterClass(lpWndClass);
   OS.HeapFree(hHeap, 0, lpszClassName);
 }
Exemplo n.º 7
0
  /**
   * Sets the receiver's text. The string may include the mnemonic character.
   *
   * <p>Mnemonics are indicated by an '&amp;' that causes the next character to be the mnemonic.
   * When the user presses a key sequence that matches the mnemonic, a selection event occurs. On
   * most platforms, the mnemonic appears underlined but may be emphasised in a platform specific
   * manner. The mnemonic indicator character '&amp;' can be escaped by doubling it in the string,
   * causing a single '&amp;' to be displayed.
   *
   * @param string the new text
   * @exception IllegalArgumentException
   *     <ul>
   *       <li>ERROR_NULL_ARGUMENT - if the text is null
   *     </ul>
   *
   * @exception SWTException
   *     <ul>
   *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
   *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
   *     </ul>
   */
  public void setText(String string) {
    checkWidget();
    if (string == null) error(SWT.ERROR_NULL_ARGUMENT);
    if ((style & SWT.SEPARATOR) != 0) return;
    if (string.equals(text)) return;
    super.setText(string);
    long /*int*/ hwnd = parent.handle;
    TBBUTTONINFO info = new TBBUTTONINFO();
    info.cbSize = TBBUTTONINFO.sizeof;
    info.dwMask = OS.TBIF_TEXT | OS.TBIF_STYLE;
    info.fsStyle = (byte) (widgetStyle() | OS.BTNS_AUTOSIZE);
    long /*int*/ hHeap = OS.GetProcessHeap(), pszText = 0;
    if (string.length() != 0) {
      info.fsStyle |= OS.BTNS_SHOWTEXT;
      TCHAR buffer = new TCHAR(parent.getCodePage(), string, true);
      int byteCount = buffer.length() * TCHAR.sizeof;
      pszText = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
      OS.MoveMemory(pszText, buffer, byteCount);
      info.pszText = pszText;
    }
    OS.SendMessage(hwnd, OS.TB_SETBUTTONINFO, id, info);
    if (pszText != 0) OS.HeapFree(hHeap, 0, pszText);

    /*
     * Bug in Windows.  For some reason, when the font is set
     * before any tool item has text, the tool items resize to
     * a very small size.  Also, a tool item will only show text
     * when text has already been set on one item and then a new
     * item is created.  The fix is to use WM_SETFONT to force
     * the tool bar to redraw and layout.
     */
    parent.setDropDownItems(false);
    long /*int*/ hFont = OS.SendMessage(hwnd, OS.WM_GETFONT, 0, 0);
    OS.SendMessage(hwnd, OS.WM_SETFONT, hFont, 0);
    parent.setDropDownItems(true);
    parent.layoutItems();
  }
Exemplo n.º 8
0
  /**
   * Sets the receiver's text. The string may include the mnemonic character and accelerator text.
   *
   * <p>Mnemonics are indicated by an '&amp;' that causes the next character to be the mnemonic.
   * When the user presses a key sequence that matches the mnemonic, a selection event occurs. On
   * most platforms, the mnemonic appears underlined but may be emphasised in a platform specific
   * manner. The mnemonic indicator character '&amp;' can be escaped by doubling it in the string,
   * causing a single '&amp;' to be displayed.
   *
   * <p>Accelerator text is indicated by the '\t' character. On platforms that support accelerator
   * text, the text that follows the '\t' character is displayed to the user, typically indicating
   * the key stroke that will cause the item to become selected. On most platforms, the accelerator
   * text appears right aligned in the menu. Setting the accelerator text does not install the
   * accelerator key sequence. The accelerator key sequence is installed using #setAccelerator.
   *
   * @param string the new text
   * @exception IllegalArgumentException
   *     <ul>
   *       <li>ERROR_NULL_ARGUMENT - if the text is null
   *     </ul>
   *
   * @exception SWTException
   *     <ul>
   *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
   *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
   *     </ul>
   *
   * @see #setAccelerator
   */
  public void setText(String string) {
    checkWidget();
    if (string == null) error(SWT.ERROR_NULL_ARGUMENT);
    if ((style & SWT.SEPARATOR) != 0) return;
    if (text.equals(string)) return;
    super.setText(string);
    long /*int*/ hHeap = OS.GetProcessHeap();
    long /*int*/ pszText = 0;
    boolean success = false;
    if ((OS.IsPPC || OS.IsSP) && parent.hwndCB != 0) {
      /*
       * Bug in WinCE PPC.  Tool items on the menubar don't resize
       * correctly when the character '&' is used (even when it
       * is a sequence '&&').  The fix is to remove all '&' from
       * the string.
       */
      if (string.indexOf('&') != -1) {
        int length = string.length();
        char[] text = new char[length];
        string.getChars(0, length, text, 0);
        int i = 0, j = 0;
        for (i = 0; i < length; i++) {
          if (text[i] != '&') text[j++] = text[i];
        }
        if (j < i) string = new String(text, 0, j);
      }
      /* Use the character encoding for the default locale */
      TCHAR buffer = new TCHAR(0, string, true);
      int byteCount = buffer.length() * TCHAR.sizeof;
      pszText = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
      OS.MoveMemory(pszText, buffer, byteCount);
      long /*int*/ hwndCB = parent.hwndCB;
      TBBUTTONINFO info2 = new TBBUTTONINFO();
      info2.cbSize = TBBUTTONINFO.sizeof;
      info2.dwMask = OS.TBIF_TEXT;
      info2.pszText = pszText;
      success = OS.SendMessage(hwndCB, OS.TB_SETBUTTONINFO, id, info2) != 0;
    } else {
      MENUITEMINFO info = new MENUITEMINFO();
      info.cbSize = MENUITEMINFO.sizeof;
      long /*int*/ hMenu = parent.handle;

      /* Use the character encoding for the default locale */
      TCHAR buffer = new TCHAR(0, string, true);
      int byteCount = buffer.length() * TCHAR.sizeof;
      pszText = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
      OS.MoveMemory(pszText, buffer, byteCount);
      /*
       * Bug in Windows 2000.  For some reason, when MIIM_TYPE is set
       * on a menu item that also has MIIM_BITMAP, the MIIM_TYPE clears
       * the MIIM_BITMAP style.  The fix is to use MIIM_STRING.
       */
      if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION(4, 10)) {
        info.fMask = OS.MIIM_STRING;
      } else {
        info.fMask = OS.MIIM_TYPE;
        info.fType = widgetStyle();
      }
      info.dwTypeData = pszText;
      success = OS.SetMenuItemInfo(hMenu, id, false, info);
    }
    if (pszText != 0) OS.HeapFree(hHeap, 0, pszText);
    if (!success) {
      int error = OS.GetLastError();
      SWT.error(
          SWT.ERROR_CANNOT_SET_TEXT,
          null,
          " [GetLastError=0x" + Integer.toHexString(error) + "]"); // $NON-NLS-1$ $NON-NLS-2$
    }
    parent.redraw();
  }