/******************************************************************************* * Copyright (c) 2000, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.swt.internal.win32; import org.eclipse.swt.internal.*; public class OS extends Platform { static { Library.loadLibrary ("swt"); //$NON-NLS-1$ } /* * SWT Windows flags */ public static final boolean IsWin32s; public static final boolean IsWin95; public static final boolean IsWinNT; public static final boolean IsWinCE; public static final boolean IsPPC; public static final boolean IsHPC; public static final boolean IsSP; public static final boolean IsDBLocale; public static final boolean IsUnicode; public static final int WIN32_MAJOR, WIN32_MINOR, WIN32_VERSION; public static final int COMCTL32_MAJOR, COMCTL32_MINOR, COMCTL32_VERSION; public static final int SHELL32_MAJOR, SHELL32_MINOR, SHELL32_VERSION; /* * Flags for Window API GetVersionEx() */ public static final int VER_PLATFORM_WIN32s = 0; public static final int VER_PLATFORM_WIN32_WINDOWS = 1; public static final int VER_PLATFORM_WIN32_NT = 2; public static final int VER_PLATFORM_WIN32_CE = 3; /* Get the Windows version and the flags */ static { /* * Try the UNICODE version of GetVersionEx first * and then the ANSI version. The UNICODE version * is present on all versions of Windows but is not * implemented on Win95/98/ME. * * NOTE: The value of OSVERSIONINFO.sizeof cannot * be static final because it relies on the Windows * platform version to be initialized and IsUnicode * has not been calculated. It must be initialized * here, after the platform is determined in order * for the value to be correct. */ OSVERSIONINFO info = new OSVERSIONINFOW (); info.dwOSVersionInfoSize = OSVERSIONINFOW.sizeof; if (!OS.GetVersionExW ((OSVERSIONINFOW)info)) { info = new OSVERSIONINFOA (); info.dwOSVersionInfoSize = OSVERSIONINFOA.sizeof; OS.GetVersionExA ((OSVERSIONINFOA)info); } OSVERSIONINFO.sizeof = info.dwOSVersionInfoSize; IsWin32s = info.dwPlatformId == VER_PLATFORM_WIN32s; IsWin95 = info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS; IsWinNT = info.dwPlatformId == VER_PLATFORM_WIN32_NT; IsWinCE = info.dwPlatformId == VER_PLATFORM_WIN32_CE; IsSP = IsSP(); IsPPC = IsPPC(); IsHPC = IsWinCE && !IsPPC && !IsSP; WIN32_MAJOR = info.dwMajorVersion; WIN32_MINOR = info.dwMinorVersion; WIN32_VERSION = VERSION (WIN32_MAJOR, WIN32_MINOR); IsUnicode = !IsWin32s && !IsWin95; /* Load the manifest to force the XP Theme */ if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) { TCHAR buffer = new TCHAR (0, OS.MAX_PATH); int hModule = OS.GetLibraryHandle (); while (OS.GetModuleFileName (hModule, buffer, buffer.length ()) == buffer.length ()) { buffer = new TCHAR (0, buffer.length () + OS.MAX_PATH); } int hHeap = OS.GetProcessHeap (); int byteCount = buffer.length () * TCHAR.sizeof; int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); OS.MoveMemory (pszText, buffer, byteCount); ACTCTX pActCtx = new ACTCTX (); pActCtx.cbSize = ACTCTX.sizeof; pActCtx.dwFlags = OS.ACTCTX_FLAG_RESOURCE_NAME_VALID | OS.ACTCTX_FLAG_SET_PROCESS_DEFAULT; pActCtx.lpSource = pszText; pActCtx.lpResourceName = OS.MANIFEST_RESOURCE_ID; int hActCtx = OS.CreateActCtx (pActCtx); if (pszText != 0) OS.HeapFree (hHeap, 0, pszText); int [] lpCookie = new int [1]; OS.ActivateActCtx (hActCtx, lpCookie); /* * NOTE: A single activation context is created and activated * for the entire lifetime of the program. It is deactivated * and released by Windows when the program exits. */ } /* Get the DBCS flag */ boolean dbcsEnabled = OS.GetSystemMetrics (OS.SM_DBCSENABLED) != 0; boolean immEnabled = OS.GetSystemMetrics (OS.SM_IMMENABLED) != 0; IsDBLocale = dbcsEnabled || immEnabled; /* * Bug in Windows. On Korean Windows XP when the Text * Services Framework support for legacy applications * is enabled, certain legacy calls segment fault. * For example, when ImmSetCompositionWindow() is used * to move the composition window outside of the client * area, Windows crashes. The fix is to disable legacy * support. * * Note: The bug is fixed in Service Pack 2. */ if (!OS.IsWinCE && OS.WIN32_VERSION == OS.VERSION (5, 1)) { short langID = OS.GetSystemDefaultUILanguage (); short primaryLang = OS.PRIMARYLANGID (langID); if (primaryLang == OS.LANG_KOREAN) { OSVERSIONINFOEX infoex = IsUnicode ? (OSVERSIONINFOEX)new OSVERSIONINFOEXW () : (OSVERSIONINFOEX)new OSVERSIONINFOEXA (); infoex.dwOSVersionInfoSize = OSVERSIONINFOEX.sizeof; OS.GetVersionEx (infoex); if (infoex.wServicePackMajor < 2) { OS.ImmDisableTextFrameService (0); } } } } /* Get the COMCTL32.DLL version */ static { DLLVERSIONINFO dvi = new DLLVERSIONINFO (); dvi.cbSize = DLLVERSIONINFO.sizeof; dvi.dwMajorVersion = 4; dvi.dwMinorVersion = 0; TCHAR lpLibFileName = new TCHAR (0, "comctl32.dll", true); //$NON-NLS-1$ int hModule = OS.LoadLibrary (lpLibFileName); if (hModule != 0) { String name = "DllGetVersion\0"; //$NON-NLS-1$ byte [] lpProcName = new byte [name.length ()]; for (int i=0; i