Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikita Nemkin2019-06-15 05:25:41 -0400
committerNikita Nemkin2019-06-24 06:37:48 -0400
commit3ea1785e69c0316c40441a9b7b5e2d99051e1642 (patch)
treeb15b700610c62ff66725ea0f3c81e8b90f181c31
parent96a9932d41e2c04c2c3641f524dde87704e4982b (diff)
downloadeclipse.platform.swt-3ea1785e69c0316c40441a9b7b5e2d99051e1642.tar.gz
eclipse.platform.swt-3ea1785e69c0316c40441a9b7b5e2d99051e1642.tar.xz
eclipse.platform.swt-3ea1785e69c0316c40441a9b7b5e2d99051e1642.zip
Bug 548384 - [Win32] Simplify directory handling in TaskBar
Use Java IO instead of IFileOperation to create and clear the directory that stores JumpList icons. Change-Id: I784f4272ccfeafe845d66a794719e3f2d922a940 Signed-off-by: Nikita Nemkin <nikita@nemkin.ru>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os.c47
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_stats.c2
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_stats.h2
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java19
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TaskBar.java159
5 files changed, 25 insertions, 204 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os.c b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os.c
index 4b69c77525..859652e700 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os.c
@@ -7988,53 +7988,6 @@ fail:
}
#endif
-#ifndef NO_SHCreateItemFromRelativeName
-JNIEXPORT jint JNICALL OS_NATIVE(SHCreateItemFromRelativeName)
- (JNIEnv *env, jclass that, jlong arg0, jcharArray arg1, jlong arg2, jbyteArray arg3, jlongArray arg4)
-{
- jchar *lparg1=NULL;
- jbyte *lparg3=NULL;
- jlong *lparg4=NULL;
- jint rc = 0;
- OS_NATIVE_ENTER(env, that, SHCreateItemFromRelativeName_FUNC);
- if (arg1) if ((lparg1 = (*env)->GetCharArrayElements(env, arg1, NULL)) == NULL) goto fail;
- if (arg3) if ((lparg3 = (*env)->GetByteArrayElements(env, arg3, NULL)) == NULL) goto fail;
- if (arg4) if ((lparg4 = (*env)->GetLongArrayElements(env, arg4, NULL)) == NULL) goto fail;
- rc = (jint)SHCreateItemFromRelativeName((IShellItem *)arg0, lparg1, (IBindCtx *)arg2, (REFIID)lparg3, (void **)lparg4);
-fail:
- if (arg4 && lparg4) (*env)->ReleaseLongArrayElements(env, arg4, lparg4, 0);
- if (arg3 && lparg3) (*env)->ReleaseByteArrayElements(env, arg3, lparg3, 0);
- if (arg1 && lparg1) (*env)->ReleaseCharArrayElements(env, arg1, lparg1, 0);
- OS_NATIVE_EXIT(env, that, SHCreateItemFromRelativeName_FUNC);
- return rc;
-}
-#endif
-
-#ifndef NO_SHCreateItemInKnownFolder
-JNIEXPORT jint JNICALL OS_NATIVE(SHCreateItemInKnownFolder)
- (JNIEnv *env, jclass that, jbyteArray arg0, jint arg1, jcharArray arg2, jbyteArray arg3, jlongArray arg4)
-{
- jbyte *lparg0=NULL;
- jchar *lparg2=NULL;
- jbyte *lparg3=NULL;
- jlong *lparg4=NULL;
- jint rc = 0;
- OS_NATIVE_ENTER(env, that, SHCreateItemInKnownFolder_FUNC);
- if (arg0) if ((lparg0 = (*env)->GetByteArrayElements(env, arg0, NULL)) == NULL) goto fail;
- if (arg2) if ((lparg2 = (*env)->GetCharArrayElements(env, arg2, NULL)) == NULL) goto fail;
- if (arg3) if ((lparg3 = (*env)->GetByteArrayElements(env, arg3, NULL)) == NULL) goto fail;
- if (arg4) if ((lparg4 = (*env)->GetLongArrayElements(env, arg4, NULL)) == NULL) goto fail;
- rc = (jint)SHCreateItemInKnownFolder((REFKNOWNFOLDERID)lparg0, arg1, lparg2, (REFIID)lparg3, (void **)lparg4);
-fail:
- if (arg4 && lparg4) (*env)->ReleaseLongArrayElements(env, arg4, lparg4, 0);
- if (arg3 && lparg3) (*env)->ReleaseByteArrayElements(env, arg3, lparg3, 0);
- if (arg2 && lparg2) (*env)->ReleaseCharArrayElements(env, arg2, lparg2, 0);
- if (arg0 && lparg0) (*env)->ReleaseByteArrayElements(env, arg0, lparg0, 0);
- OS_NATIVE_EXIT(env, that, SHCreateItemInKnownFolder_FUNC);
- return rc;
-}
-#endif
-
#ifndef NO_SHDRAGIMAGE_1sizeof
JNIEXPORT jint JNICALL OS_NATIVE(SHDRAGIMAGE_1sizeof)
(JNIEnv *env, jclass that)
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_stats.c b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_stats.c
index 19436deac3..3b814c2ff7 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_stats.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_stats.c
@@ -598,8 +598,6 @@ char * OS_nativeFunctionNames[] = {
"SCROLLINFO_1sizeof",
"SHBrowseForFolder",
"SHCreateItemFromParsingName",
- "SHCreateItemFromRelativeName",
- "SHCreateItemInKnownFolder",
"SHDRAGIMAGE_1sizeof",
"SHELLEXECUTEINFO_1sizeof",
"SHFILEINFO_1sizeof",
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_stats.h
index 24475d8d6d..4efa95d342 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_stats.h
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_stats.h
@@ -608,8 +608,6 @@ typedef enum {
SCROLLINFO_1sizeof_FUNC,
SHBrowseForFolder_FUNC,
SHCreateItemFromParsingName_FUNC,
- SHCreateItemFromRelativeName_FUNC,
- SHCreateItemInKnownFolder_FUNC,
SHDRAGIMAGE_1sizeof_FUNC,
SHELLEXECUTEINFO_1sizeof_FUNC,
SHFILEINFO_1sizeof_FUNC,
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java
index f8f55a8145..e2f3dffefc 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java
@@ -505,7 +505,6 @@ public class OS extends C {
public static final int FCONTROL = 0x8;
public static final int FE_FONTSMOOTHINGCLEARTYPE = 0x0002;
public static final int FEATURE_DISABLE_NAVIGATION_SOUNDS = 21;
- public static final int FILE_ATTRIBUTE_DIRECTORY = 0x00000010;
public static final int FILE_ATTRIBUTE_NORMAL = 0x00000080;
public static final int FILE_MAP_READ = 4;
public static final int FLICKDIRECTION_RIGHT = 0;
@@ -519,11 +518,6 @@ public class OS extends C {
public static final int FLICKDIRECTION_INVALID = 8;
public static final int FNERR_INVALIDFILENAME = 0x3002;
public static final int FNERR_BUFFERTOOSMALL = 0x3003;
- public static final int FOF_SILENT = 0x0004;
- public static final int FOF_NOCONFIRMATION = 0x0010;
- public static final int FOF_NOCONFIRMMKDIR = 0x0200;
- public static final int FOF_NOERRORUI = 0x0400;
- public static final int FOF_NO_UI = (FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NOCONFIRMMKDIR);
public static final int FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100;
public static final int FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000;
public static final int FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200;
@@ -4473,19 +4467,6 @@ public static final native int SHGetMalloc (long [] ppMalloc);
*/
public static final native boolean SHGetPathFromIDList (long pidl, char [] pszPath);
/**
- * @param kfid cast=(REFKNOWNFOLDERID)
- * @param riid cast=(REFIID)
- * @param ppv cast=(void **)
- */
-public static final native int SHCreateItemInKnownFolder (byte [] kfid, int dwKFFlags, char [] pszItem, byte [] riid, long [] ppv);
-/**
- * @param psiParent cast=(IShellItem *)
- * @param pbc cast=(IBindCtx *)
- * @param riid cast=(REFIID)
- * @param ppv cast=(void **)
- */
-public static final native int SHCreateItemFromRelativeName (long psiParent, char [] pszName, long pbc, byte [] riid, long [] ppv);
-/**
* @param pbc cast=(IBindCtx *)
* @param riid cast=(REFIID)
* @param ppv cast=(void **)
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TaskBar.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TaskBar.java
index 406c1bf00f..369eeddaee 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TaskBar.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TaskBar.java
@@ -15,6 +15,8 @@
package org.eclipse.swt.widgets;
+import java.io.*;
+
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.internal.*;
@@ -41,9 +43,9 @@ public class TaskBar extends Widget {
int itemCount;
TaskItem [] items = new TaskItem [4];
long mTaskbarList3;
+ String iconsDir;
static final char [] EXE_PATH;
- static final char [] ICO_DIR = {'i','c','o','_','d','i','r','\0'};
static final PROPERTYKEY PKEY_Title = new PROPERTYKEY ();
static final PROPERTYKEY PKEY_AppUserModel_IsDestListSeparator = new PROPERTYKEY ();
static final String EXE_PATH_KEY = "org.eclipse.swt.win32.taskbar.executable"; //$NON-NLS-1$
@@ -54,7 +56,6 @@ public class TaskBar extends Widget {
static final byte [] CLSID_DestinationList = new byte[16];
static final byte [] CLSID_EnumerableObjectCollection = new byte[16];
static final byte [] CLSID_ShellLink = new byte[16];
- static final byte [] CLSID_FileOperation = new byte [16];
static final byte [] IID_ITaskbarList3 = new byte [16];
static final byte [] IID_ICustomDestinationList = new byte[16];
static final byte [] IID_IObjectArray = new byte[16];
@@ -62,14 +63,11 @@ public class TaskBar extends Widget {
static final byte [] IID_IShellLinkW = new byte[16];
static final byte [] IID_IPropertyStore = new byte[16];
static final byte [] IID_IShellItem = new byte [16];
- static final byte [] IID_IFileOperation = new byte [16];
- static final byte [] FOLDERID_LocalAppData = new byte [16];
static {
OS.IIDFromString ("{56FDF344-FD6D-11d0-958A-006097C9A090}\0".toCharArray (), CLSID_TaskbarList); //$NON-NLS-1$
OS.IIDFromString ("{77f10cf0-3db5-4966-b520-b7c54fd35ed6}\0".toCharArray (), CLSID_DestinationList); //$NON-NLS-1$
OS.IIDFromString ("{2d3468c1-36a7-43b6-ac24-d3f02fd9607a}\0".toCharArray (), CLSID_EnumerableObjectCollection); //$NON-NLS-1$
OS.IIDFromString ("{00021401-0000-0000-C000-000000000046}\0".toCharArray (), CLSID_ShellLink); //$NON-NLS-1$
- OS.IIDFromString ("{3ad05575-8857-4850-9277-11b85bdb8e09}\0".toCharArray (), CLSID_FileOperation);
OS.IIDFromString ("{EA1AFB91-9E28-4B86-90E9-9E9F8A5EEFAF}\0".toCharArray (), IID_ITaskbarList3); //$NON-NLS-1$
OS.IIDFromString ("{6332debf-87b5-4670-90c0-5e57b408a49e}\0".toCharArray (), IID_ICustomDestinationList); //$NON-NLS-1$
OS.IIDFromString ("{92CA9DCD-5622-4bba-A805-5E9F541BD8C9}\0".toCharArray (), IID_IObjectArray); //$NON-NLS-1$
@@ -77,8 +75,6 @@ public class TaskBar extends Widget {
OS.IIDFromString ("{000214F9-0000-0000-C000-000000000046}\0".toCharArray (), IID_IShellLinkW); //$NON-NLS-1$
OS.IIDFromString ("{886d8eeb-8cf2-4446-8d02-cdba1dbdcf99}\0".toCharArray (), IID_IPropertyStore); //$NON-NLS-1$
OS.IIDFromString ("{43826d1e-e718-42ee-bc55-a1e261c37bfe}\0".toCharArray (), IID_IShellItem); //$NON-NLS-1$
- OS.IIDFromString ("{947aab5f-0a5c-4c13-b4d6-4bf7836fc9f8}\0".toCharArray (), IID_IFileOperation); //$NON-NLS-1$
- OS.IIDFromString ("{F1B32785-6FBA-4FCF-9D55-7B8E7F157091}\0".toCharArray (), FOLDERID_LocalAppData); //$NON-NLS-1$
OS.PSPropertyKeyFromString ("{F29F85E0-4FF9-1068-AB91-08002B27B3D9} 2\0".toCharArray (), PKEY_Title); //$NON-NLS-1$
OS.PSPropertyKeyFromString ("{9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3}, 6\0".toCharArray (), PKEY_AppUserModel_IsDestListSeparator); //$NON-NLS-1$
char [] buffer = new char [OS.MAX_PATH];
@@ -121,7 +117,7 @@ void createItems () {
getItem (null);
}
-long createShellLink (MenuItem item, String directory) {
+long createShellLink (MenuItem item) {
int style = item.getStyle ();
if ((style & SWT.CASCADE) != 0) return 0;
long [] ppv = new long [1];
@@ -186,9 +182,11 @@ long createShellLink (MenuItem item, String directory) {
text = (String)item.getData (ICON_INDEX_KEY);
if (text != null) index = Integer.parseInt (text);
} else {
+ String directory = null;
Image image = item.getImage ();
- if (image != null && directory != null) {
- icon = directory + "\\menu" + item.id + ".ico" ;
+ if (image != null) directory = getIconsDir ();
+ if (directory != null) {
+ icon = directory + "\\" + "menu" + item.id + ".ico";
ImageData data;
if (item.hBitmap != 0) {
Image image2 = Image.win32_new (display, SWT.BITMAP, item.hBitmap);
@@ -228,7 +226,7 @@ long createShellLink (MenuItem item, String directory) {
return pLink;
}
-long createShellLinkArray (MenuItem [] items, String directory) {
+long createShellLinkArray (MenuItem [] items) {
if (items == null) return 0;
if (items.length == 0) return 0;
long [] ppv = new long [1];
@@ -236,7 +234,7 @@ long createShellLinkArray (MenuItem [] items, String directory) {
if (hr != OS.S_OK) error (SWT.ERROR_NO_HANDLES);
long pObjColl = ppv [0];
for (int i = 0; i < items.length; i++) {
- long pLink = createShellLink (items[i], directory);
+ long pLink = createShellLink (items[i]);
if (pLink != 0) {
/*IObjectCollection::AddObject*/
hr = OS.VtblCall (5, pObjColl, pLink);
@@ -265,108 +263,20 @@ void destroyItem (TaskItem item) {
items [itemCount] = null;
}
-String getDirectory (char[] appName) {
- char [] appDir = new char [appName.length];
- for (int i = 0; i < appName.length; i++) {
- char c = appName [i];
- switch (c) {
- case '\\':
- case '/':
- case ':':
- case '*':
- case '?':
- case '\"':
- case '<':
- case '>':
- case '|':
- appDir [i] = '_';
- break;
- default:
- appDir [i] = c;
- }
- }
- String result = null;
- long [] ppv = new long [1];
- int hr = OS.SHCreateItemInKnownFolder (FOLDERID_LocalAppData, 0, null, IID_IShellItem, ppv);
- if (hr == OS.S_OK) {
- long psiRoot = ppv [0];
- hr = OS.CoCreateInstance (CLSID_FileOperation, 0, OS.CLSCTX_INPROC_SERVER, IID_IFileOperation, ppv);
- if (hr == OS.S_OK) {
- long pfo = ppv [0];
- /*IFileOperation.SetOperationFlags*/
- hr = OS.VtblCall (5, pfo, OS.FOF_NO_UI);
- if (hr == OS.S_OK) {
- long psiAppDir = getDirectory (psiRoot, pfo, appDir, false);
- if (psiAppDir != 0) {
- long psiIcoDir = getDirectory (psiAppDir, pfo, ICO_DIR, true);
- if (psiIcoDir != 0) {
- /*IShellItem::GetDisplayName*/
- hr = OS.VtblCall (5, psiIcoDir, OS.SIGDN_FILESYSPATH, ppv);
- if (hr == OS.S_OK) {
- long wstr = ppv [0];
- int length = OS.wcslen (wstr);
- char [] buffer = new char [length];
- OS.MoveMemory (buffer, wstr, length * 2);
- result = new String (buffer);
- OS.CoTaskMemFree (wstr);
- }
- /*IUnknown::Release*/
- OS.VtblCall (2, psiIcoDir);
- }
- /*IUnknown::Release*/
- OS.VtblCall (2, psiAppDir);
- }
- }
- /*IUnknown::Release*/
- OS.VtblCall(2, pfo);
- }
- /*IUnknown::Release*/
- OS.VtblCall (2, psiRoot);
- }
- return result;
-}
-
-long getDirectory (long parent, long pfo, char [] name, boolean delete) {
- long [] ppv = new long [1];
- int hr = OS.SHCreateItemFromRelativeName (parent, name, 0, IID_IShellItem, ppv);
- if (hr == OS.S_OK) {
- if (delete) {
- /*IFileOperation.Delete*/
- hr = OS.VtblCall (18, pfo, ppv [0], 0);
- /*IUnknown::Release*/
- OS.VtblCall (2, ppv [0]);
- if (hr == OS.S_OK) {
- /*IFileOperation.NewItem */
- hr = OS.VtblCall (20, pfo, parent, OS.FILE_ATTRIBUTE_DIRECTORY, name, null, 0);
- if (hr == OS.S_OK) {
- /*IFileOperation.PerformOperations */
- hr = OS.VtblCall (21, pfo);
- if (hr == OS.S_OK) {
- hr = OS.SHCreateItemFromRelativeName (parent, name, 0, IID_IShellItem, ppv);
- if (hr == OS.S_OK) {
- return ppv [0];
- }
- }
- }
- }
- } else {
- return ppv [0];
- }
- } else {
- /*IFileOperation.NewItem */
- hr = OS.VtblCall (20, pfo, parent, OS.FILE_ATTRIBUTE_DIRECTORY, name, null, 0);
- if (hr == OS.S_OK) {
- /*IFileOperation.PerformOperations */
- hr = OS.VtblCall (21, pfo);
- if (hr == OS.S_OK) {
- hr = OS.SHCreateItemFromRelativeName (parent, name, 0, IID_IShellItem, ppv);
- if (hr == OS.S_OK) {
- return ppv [0];
- }
- }
- }
+String getIconsDir() {
+ if (iconsDir != null) return iconsDir;
+ String appData = System.getenv("LOCALAPPDATA");
+ String appName = Display.APP_NAME;
+ if (appData == null || appName == null) return null;
+ appName = appName.replaceAll("[\\\\/:*?\"<>|]", "_");
+ File dir = new File(appData + "\\" + appName + "\\ico_dir");
+ if (dir.exists()) {
+ // remove old icons
+ for (File file : dir.listFiles()) file.delete();
+ } else if (!dir.mkdirs()) {
+ return null;
}
- return 0;
+ return iconsDir = dir.getPath();
}
/**
@@ -509,20 +419,10 @@ void setMenu (Menu menu) {
buffer = new char [length + 1];
appName.getChars (0, length, buffer, 0);
}
-
MenuItem [] items = null;
if (menu != null && (items = menu.getItems ()).length != 0) {
- String directory = null;
- for (int i = 0; i < items.length; i++) {
- MenuItem item = items [i];
- if (item.getImage () != null && item.getData (ICON_KEY) == null) {
- directory = getDirectory (buffer);
- break;
- }
- }
- long poa = createShellLinkArray (items, directory);
+ long poa = createShellLinkArray (items);
if (poa != 0) {
-
/*ICustomDestinationList::SetAppID*/
hr = OS.VtblCall (3, pDestList, buffer);
if (hr != OS.S_OK) error (SWT.ERROR_INVALID_ARGUMENT);
@@ -548,16 +448,7 @@ void setMenu (Menu menu) {
Menu subMenu = item.getMenu ();
if (subMenu != null) {
MenuItem [] subItems = subMenu.getItems ();
- if (directory == null) {
- for (int j = 0; j < subItems.length; j++) {
- MenuItem subItem = subItems [j];
- if (subItem.getImage () != null && subItem.getData (ICON_KEY) == null) {
- directory = getDirectory (buffer);
- break;
- }
- }
- }
- long poa2 = createShellLinkArray (subItems, directory);
+ long poa2 = createShellLinkArray (subItems);
if (poa2 != 0) {
/*IObjectArray::GetCount*/
OS.VtblCall (3, poa2, count);

Back to the top