Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiraj Modi2019-08-09 04:12:02 -0400
committerNiraj Modi2019-08-12 02:56:36 -0400
commit00b8a6b3ce979bf00109c9597563c22ab7fd7e3d (patch)
treeb949ca4094ed3d42fe050573c1986546a25d5105
parentd715c62e7f7fd8f9e3bc00393a3a5514c554dc02 (diff)
downloadeclipse.platform.swt-00b8a6b3ce979bf00109c9597563c22ab7fd7e3d.tar.gz
eclipse.platform.swt-00b8a6b3ce979bf00109c9597563c22ab7fd7e3d.tar.xz
eclipse.platform.swt-00b8a6b3ce979bf00109c9597563c22ab7fd7e3d.zip
Bug 549913 - [win32][extract method] Extract "readRegistryDword" method
from Display to OS Change-Id: I2c0a08dcb8aef2e34ad43ffee618369f182654ed Signed-off-by: Niraj Modi <niraj.modi@in.ibm.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java17
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java31
2 files changed, 28 insertions, 20 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 3d77d71682..007cb0504d 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
@@ -2248,6 +2248,23 @@ public static final boolean OpenPrinter (TCHAR pPrinterName, long [] phPrinter,
return OpenPrinter (pPrinterName1, phPrinter, pDefault);
}
+public static final int readRegistryDword(int hkeyLocation, String key, String valueName) throws Exception {
+ if (key == null || valueName == null) throw new Exception("Registry key/valueName is null.");
+ long [] phkResult = new long [1];
+ TCHAR regKey = new TCHAR (0, key, true);
+ TCHAR lpValueName = new TCHAR (0, valueName, true);
+ if (OS.RegOpenKeyEx(hkeyLocation, regKey, 0, OS.KEY_READ, phkResult) == 0) {
+ int[] lpcbData = new int[] { 4 };
+ int[] lpData = new int[1];
+ int result = OS.RegQueryValueEx(phkResult[0], lpValueName, 0, null, lpData, lpcbData);
+ OS.RegCloseKey(phkResult[0]);
+ if (result == 0) {
+ return lpData[0];
+ }
+ }
+ throw new Exception("Registry entry not found.");
+}
+
public static final int RegCreateKeyEx (long hKey, TCHAR lpSubKey, int Reserved, TCHAR lpClass, int dwOptions, int samDesired, long lpSecurityAttributes, long[] phkResult, long[] lpdwDisposition) {
char [] lpClass1 = lpClass == null ? null : lpClass.chars;
char [] lpSubKey1 = lpSubKey == null ? null : lpSubKey.chars;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
index 8cdf2c1466..3dff3a5f75 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
@@ -2038,17 +2038,12 @@ public static boolean isSystemDarkTheme () {
* Win10 onwards we can read the Dark Theme from the OS registry.
*/
if (OS.WIN32_VERSION >= OS.VERSION (10, 0)) {
- TCHAR key = new TCHAR (0, "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", true); //$NON-NLS-1$
- long [] phkResult = new long [1];
- if (OS.RegOpenKeyEx(OS.HKEY_CURRENT_USER, key, 0, OS.KEY_READ, phkResult) == 0) {
- int[] lpcbData = new int[] { 4 };
- TCHAR buffer = new TCHAR(0, "AppsUseLightTheme", true); //$NON-NLS-1$
- int[] lpData = new int[1];
- int result = OS.RegQueryValueEx(phkResult[0], buffer, 0, null, lpData, lpcbData);
- if (result == 0) {
- isDarkTheme = (lpData[0] == 0);
- }
- OS.RegCloseKey(phkResult[0]);
+ try {
+ int result = OS.readRegistryDword(OS.HKEY_CURRENT_USER,
+ "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", "AppsUseLightTheme");
+ isDarkTheme = (result == 0);
+ } catch (Exception e) {
+ // Registry entry not found
}
}
return isDarkTheme;
@@ -2783,15 +2778,11 @@ boolean isXMouseActive () {
* NOTE: X-Mouse is active when bit 1 of the UserPreferencesMask is set.
*/
boolean xMouseActive = false;
- TCHAR key = new TCHAR (0, "Control Panel\\Desktop", true); //$NON-NLS-1$
- long [] phKey = new long [1];
- int result = OS.RegOpenKeyEx (OS.HKEY_CURRENT_USER, key, 0, OS.KEY_READ, phKey);
- if (result == 0) {
- TCHAR lpValueName = new TCHAR (0, "UserPreferencesMask", true); //$NON-NLS-1$
- int [] lpcbData = new int [] {4}, lpData = new int [1];
- result = OS.RegQueryValueEx (phKey [0], lpValueName, 0, null, lpData, lpcbData);
- if (result == 0) xMouseActive = (lpData [0] & 0x01) != 0;
- OS.RegCloseKey (phKey [0]);
+ try {
+ int result = OS.readRegistryDword(OS.HKEY_CURRENT_USER, "Control Panel\\Desktop", "UserPreferencesMask");
+ xMouseActive = (result & 0x01) != 0;
+ } catch (Exception e) {
+ // Registry entry not found
}
return xMouseActive;
}

Back to the top