diff options
author | Nikita Nemkin | 2018-02-18 17:03:53 +0000 |
---|---|---|
committer | Lars Vogel | 2018-04-05 17:46:44 +0000 |
commit | b33183ce0dec18efde020735ad580baed707c824 (patch) | |
tree | 933633de6c9092954ae271397e3b7996fb2053ff | |
parent | 1462f91af5e84d5f520979d0b4b9b048f3f3841b (diff) | |
download | eclipse.platform.swt-b33183ce0dec18efde020735ad580baed707c824.tar.gz eclipse.platform.swt-b33183ce0dec18efde020735ad580baed707c824.tar.xz eclipse.platform.swt-b33183ce0dec18efde020735ad580baed707c824.zip |
Bug 531097 - [Win32] Remove unnecessary string manipulation
Given a module handle, ActivateActCtx() can load manifest from a dll
already present in memory. Since SWT dll is already present and its
handle is readily available, constructing the path to SWT dll is
unnecesary.
Some controls re-register their window class locally to adjust class
style bits. Since the class name doesn't change, there's no need to set
it explicitly after the call to GetClassInfo().
Change-Id: Ic5ed78ddfef6e1ac9e2bf694cdbe216efc570569
Signed-off-by: Nikita Nemkin <nikita@nemkin.ru>
5 files changed, 10 insertions, 55 deletions
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 ffc7ce7a1b..0f6fd03e7b 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 @@ -29,12 +29,11 @@ public class OS extends C { public static final String NO_MANIFEST = "org.eclipse.swt.internal.win32.OS.NO_MANIFEST"; /* Forward references */ - public static final int HEAP_ZERO_MEMORY = 0x8; public static final int ACTCTX_FLAG_RESOURCE_NAME_VALID = 0x00000008; public static final int ACTCTX_FLAG_SET_PROCESS_DEFAULT = 0x00000010; + public static final int ACTCTX_FLAG_HMODULE_VALID = 0x00000080; public static final int MANIFEST_RESOURCE_ID = 2; public static final int SM_IMMENABLED = 0x52; - public static final int MAX_PATH = 260; static { /* Get the Windows version */ @@ -43,22 +42,12 @@ public class OS extends C { /* Load the manifest to force the XP Theme */ if (System.getProperty (NO_MANIFEST) == null) { - TCHAR buffer = new TCHAR (0, MAX_PATH); - long /*int*/ hModule = OS.GetLibraryHandle (); - while (OS.GetModuleFileName (hModule, buffer, buffer.length ()) == buffer.length ()) { - buffer = new TCHAR (0, buffer.length () + MAX_PATH); - } - long /*int*/ hHeap = OS.GetProcessHeap (); - int byteCount = buffer.length () * 2; - long /*int*/ pszText = OS.HeapAlloc (hHeap, HEAP_ZERO_MEMORY, byteCount); - OS.MoveMemory (pszText, buffer, byteCount); ACTCTX pActCtx = new ACTCTX (); pActCtx.cbSize = ACTCTX.sizeof; - pActCtx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID | ACTCTX_FLAG_SET_PROCESS_DEFAULT; - pActCtx.lpSource = pszText; + pActCtx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID | ACTCTX_FLAG_HMODULE_VALID | ACTCTX_FLAG_SET_PROCESS_DEFAULT; + pActCtx.hModule = OS.GetLibraryHandle (); pActCtx.lpResourceName = MANIFEST_RESOURCE_ID; long /*int*/ hActCtx = OS.CreateActCtx (pActCtx); - if (pszText != 0) OS.HeapFree (hHeap, 0, pszText); long /*int*/ [] lpCookie = new long /*int*/ [1]; OS.ActivateActCtx (hActCtx, lpCookie); /* @@ -667,7 +656,7 @@ public class OS extends C { public static final int HDS_HOTTRACK = 0x4; public static final int HDS_NOSIZING = 0x800; public static final int HDS_OVERFLOW = 0x1000; -// public static final int HEAP_ZERO_MEMORY = 0x8; + public static final int HEAP_ZERO_MEMORY = 0x8; public static final int HELPINFO_MENUITEM = 0x2; public static final int HHT_ONDIVIDER = 0x4; public static final int HHT_ONDIVOPEN = 0x8; @@ -938,6 +927,7 @@ public class OS extends C { public static final int LWA_COLORKEY = 0x00000001; public static final int LWA_ALPHA = 0x00000002; public static final int MAX_LINKID_TEXT = 48; + public static final int MAX_PATH = 260; public static final int MA_NOACTIVATE = 0x3; public static final int MB_ABORTRETRYIGNORE = 0x2; public static final int MB_APPLMODAL = 0x0; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/DateTime.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/DateTime.java index 6d53fd8f0b..5b61b7a51f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/DateTime.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/DateTime.java @@ -81,17 +81,10 @@ public class DateTime extends Composite { * code, other than SWT, could create a control with * this class name, and fail unexpectedly. */ - long /*int*/ hInstance = OS.GetModuleHandle (null); - long /*int*/ hHeap = OS.GetProcessHeap (); - lpWndClass.hInstance = hInstance; + lpWndClass.hInstance = OS.GetModuleHandle (null); lpWndClass.style &= ~OS.CS_GLOBALCLASS; lpWndClass.style |= OS.CS_DBLCLKS; - int byteCount = DateTimeClass.length () * TCHAR.sizeof; - long /*int*/ lpszClassName = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); - OS.MoveMemory (lpszClassName, DateTimeClass, byteCount); - lpWndClass.lpszClassName = lpszClassName; OS.RegisterClass (lpWndClass); - OS.HeapFree (hHeap, 0, lpszClassName); } static { WNDCLASS lpWndClass = new WNDCLASS (); @@ -114,17 +107,10 @@ public class DateTime extends Composite { * code, other than SWT, could create a control with * this class name, and fail unexpectedly. */ - long /*int*/ hInstance = OS.GetModuleHandle (null); - long /*int*/ hHeap = OS.GetProcessHeap (); - lpWndClass.hInstance = hInstance; + lpWndClass.hInstance = OS.GetModuleHandle (null); lpWndClass.style &= ~OS.CS_GLOBALCLASS; lpWndClass.style |= OS.CS_DBLCLKS; - int byteCount = CalendarClass.length () * TCHAR.sizeof; - long /*int*/ lpszClassName = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); - OS.MoveMemory (lpszClassName, CalendarClass, byteCount); - lpWndClass.lpszClassName = lpszClassName; OS.RegisterClass (lpWndClass); - OS.HeapFree (hHeap, 0, lpszClassName); } static final char SINGLE_QUOTE = '\''; //$NON-NLS-1$ short date format may include quoted text static final char DAY_FORMAT_CONSTANT = 'd'; //$NON-NLS-1$ 1-4 lowercase 'd's represent day diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Link.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Link.java index 215a624b31..8c26ac846f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Link.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Link.java @@ -75,17 +75,10 @@ public class Link extends Control { * code, other than SWT, could create a control with * this class name, and fail unexpectedly. */ - long /*int*/ hInstance = OS.GetModuleHandle (null); - long /*int*/ hHeap = OS.GetProcessHeap (); - lpWndClass.hInstance = hInstance; + lpWndClass.hInstance = OS.GetModuleHandle (null); lpWndClass.style &= ~OS.CS_GLOBALCLASS; lpWndClass.style |= OS.CS_DBLCLKS; - int byteCount = LinkClass.length () * TCHAR.sizeof; - long /*int*/ lpszClassName = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); - OS.MoveMemory (lpszClassName, LinkClass, byteCount); - lpWndClass.lpszClassName = lpszClassName; OS.RegisterClass (lpWndClass); - OS.HeapFree (hHeap, 0, lpszClassName); } /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ProgressBar.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ProgressBar.java index 9504cae0e0..8d489e2c10 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ProgressBar.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ProgressBar.java @@ -61,17 +61,10 @@ public class ProgressBar extends Control { * code, other than SWT, could create a control with * this class name, and fail unexpectedly. */ - long /*int*/ hInstance = OS.GetModuleHandle (null); - long /*int*/ hHeap = OS.GetProcessHeap (); - lpWndClass.hInstance = hInstance; + lpWndClass.hInstance = OS.GetModuleHandle (null); lpWndClass.style &= ~OS.CS_GLOBALCLASS; lpWndClass.style |= OS.CS_DBLCLKS; - int byteCount = ProgressBarClass.length () * TCHAR.sizeof; - long /*int*/ 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); } /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scale.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scale.java index 3ed4e60b9b..c7f0fcad5f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scale.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scale.java @@ -64,17 +64,10 @@ public class Scale extends Control { * code, other than SWT, could create a control with * this class name, and fail unexpectedly. */ - long /*int*/ hInstance = OS.GetModuleHandle (null); - long /*int*/ hHeap = OS.GetProcessHeap (); - lpWndClass.hInstance = hInstance; + lpWndClass.hInstance = OS.GetModuleHandle (null); lpWndClass.style &= ~OS.CS_GLOBALCLASS; lpWndClass.style |= OS.CS_DBLCLKS; - int byteCount = TrackBarClass.length () * TCHAR.sizeof; - long /*int*/ lpszClassName = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); - OS.MoveMemory (lpszClassName, TrackBarClass, byteCount); - lpWndClass.lpszClassName = lpszClassName; OS.RegisterClass (lpWndClass); - OS.HeapFree (hHeap, 0, lpszClassName); } /** |