diff options
author | jfrijters <jfrijters> | 2010-06-09 16:26:28 +0400 |
---|---|---|
committer | jfrijters <jfrijters> | 2010-06-09 16:26:28 +0400 |
commit | 248559fb690c8c1c6c0c88cd428c57a56c62e091 (patch) | |
tree | 023902d4806bdd70265dbd9f9472a73cfd4aa4de | |
parent | 0c2fcdf9c898081640dfa68a44dec48c4b4ee25c (diff) |
Added "first-pass" build of IKVM.AWT.WinForms.dll and moved "native" AWT code from IKVM.Runtime.dll to IKVM.AWT.WinForms.dll.
-rw-r--r-- | awt/AssemblyInfo.cs.in (renamed from awt/AssemblyInfo.cs) | 12 | ||||
-rw-r--r-- | awt/awt.build | 29 | ||||
-rw-r--r-- | awt/native.cs | 470 | ||||
-rw-r--r-- | ikvm.build | 1 | ||||
-rw-r--r-- | openjdk/dependencies.txt | 1 | ||||
-rw-r--r-- | openjdk/openjdk.build | 1 | ||||
-rw-r--r-- | openjdk/response.txt | 1 | ||||
-rw-r--r-- | runtime/openjdk.cs | 440 |
8 files changed, 510 insertions, 445 deletions
diff --git a/awt/AssemblyInfo.cs b/awt/AssemblyInfo.cs.in index cba19967..19eefc6a 100644 --- a/awt/AssemblyInfo.cs +++ b/awt/AssemblyInfo.cs.in @@ -1,5 +1,5 @@ /* - Copyright (C) 2002, 2003, 2004, 2005 Jeroen Frijters + Copyright (C) 2002-2010 Jeroen Frijters This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -29,5 +29,11 @@ using System.Runtime.CompilerServices; // set of attributes. Change these attribute values to modify the information // associated with an assembly. // -[assembly: AssemblyTitle("")] -[assembly: AssemblyDescription("")] +[assembly: AssemblyTitle("IKVM.NET AWT Support")] +[assembly: AssemblyDescription("Winforms peers and 'native' code")] + +#if SIGNCODE +[assembly: InternalsVisibleTo("IKVM.OpenJDK.SwingAWT, PublicKey=@PUBLICKEY@")] +#else +[assembly: InternalsVisibleTo("IKVM.OpenJDK.SwingAWT")] +#endif diff --git a/awt/awt.build b/awt/awt.build index 96822361..d0d5ab6f 100644 --- a/awt/awt.build +++ b/awt/awt.build @@ -1,8 +1,32 @@ <?xml version="1.0"?> <project name="awt" default="awt"> - <target name="awt"> + <target name="AssemblyInfo.cs"> + <loadfile file="../tools/pubkey.txt" property="publickey" /> + <copy file="AssemblyInfo.cs.in" tofile="AssemblyInfo.cs" overwrite="true"> + <filterchain> + <replacetokens> + <token key="PUBLICKEY" value="${publickey}" /> + </replacetokens> + </filterchain> + </copy> + </target> + <target name="first-pass" depends="AssemblyInfo.cs"> + <property overwrite="false" name="signed" value="" /> + <csc target="library" output="../bin/IKVM.AWT.WinForms.dll" define="FIRST_PASS;${signed}" rebuild="true"> + <sources> + <include name="../CommonAssemblyInfo.cs" /> + <include name="AssemblyInfo.cs" /> + <include name="native.cs" /> + </sources> + <references> + <include name="System.Windows.Forms.dll" asis="true" /> + <include name="System.Drawing.dll" asis="true" /> + </references> + </csc> + </target> + <target name="awt" depends="AssemblyInfo.cs"> <property overwrite="false" name="signed" value="" /> - <csc target="library" output="../bin/IKVM.AWT.WinForms.dll" define="TRACE;${signed}"> + <csc target="library" output="../bin/IKVM.AWT.WinForms.dll" define="TRACE;${signed}" rebuild="true"> <sources> <include name="../CommonAssemblyInfo.cs" /> <include name="AssemblyInfo.cs" /> @@ -10,6 +34,7 @@ <include name="fonts-0.95.cs" /> <include name="graphics.cs" /> <include name="images.cs" /> + <include name="native.cs" /> <include name="printing.cs" /> <include name="robot.cs" /> <include name="toolkit-0.95.cs" /> diff --git a/awt/native.cs b/awt/native.cs new file mode 100644 index 00000000..82877e4f --- /dev/null +++ b/awt/native.cs @@ -0,0 +1,470 @@ +/* + Copyright (C) 2007, 2008, 2010 Jeroen Frijters + Copyright (C) 2009 Volker Berlin (i-net software) + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jeroen Frijters + jeroen@frijters.net + +*/ +using System; +using System.Runtime.InteropServices; +using System.Text; + +namespace IKVM.NativeCode.sun.awt +{ + static class KeyboardFocusManagerPeerImpl + { + public static object getNativeFocusedWindow() { return null; } + public static object getNativeFocusOwner() { return null; } + public static void clearNativeGlobalFocusOwner(object activeWindow) { } + } + + static class SunToolkit + { + public static void closeSplashScreen() { } + } +} + +namespace IKVM.NativeCode.sun.awt.shell +{ + /// <summary> + /// This class should use only on Windows that we can access shell32.dll + /// </summary> + static class Win32ShellFolder2 + { + private const uint SHGFI_LARGEICON = 0x0; + private const uint SHGFI_SMALLICON = 0x1; + private const uint SHGFI_ICON = 0x100; + private const uint SHGFI_TYPENAME = 0x400; + private const uint SHGFI_ATTRIBUTES = 0x800; + private struct SHFILEINFO + { + public IntPtr hIcon; + public IntPtr iIcon; + public uint dwAttributes; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] + public string szDisplayName; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)] + public string szTypeName; + }; + + [DllImport("msvcrt.dll", SetLastError = false)] + static extern IntPtr memcpy(IntPtr dest, IntPtr src, int count); + + [DllImport("gdi32.dll")] + static extern int GetDIBits(IntPtr hdc, IntPtr hbmp, uint uStartScan, + uint cScanLines, int[] lpvBits, ref BITMAPINFO lpbmi, uint uUsage); + + [DllImport("gdi32.dll")] + public static extern int BitBlt(IntPtr hdcDst, int xDst, int yDst, int w, int h, IntPtr hdcSrc, int xSrc, int ySrc, int rop); + + [DllImport("user32.dll")] + public static extern IntPtr GetDC(IntPtr hwnd); + + [DllImport("gdi32.dll")] + static extern int GetObject(IntPtr hgdiobj, int cbBuffer, ref BITMAPINFO lpvObject); + + [DllImport("gdi32.dll")] + public static extern IntPtr CreateCompatibleDC(IntPtr hdc); + + [DllImport("user32.dll")] + public static extern int ReleaseDC(IntPtr hwnd, IntPtr hdc); + + [DllImport("gdi32.dll")] + static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth, int nHeight); + + [DllImport("gdi32.dll")] + public static extern int DeleteDC(IntPtr hdc); + + [StructLayout(LayoutKind.Sequential)] + struct ICONINFO + { + public bool fIcon; // Specifies whether this structure defines an icon or a cursor. A value of TRUE specifies + // an icon; FALSE specifies a cursor. + public Int32 xHotspot; // Specifies the x-coordinate of a cursor's hot spot. If this structure defines an icon, the hot + // spot is always in the center of the icon, and this member is ignored. + public Int32 yHotspot; // Specifies the y-coordinate of the cursor's hot spot. If this structure defines an icon, the hot + // spot is always in the center of the icon, and this member is ignored. + public IntPtr hbmMask; // (HBITMAP) Specifies the icon bitmask bitmap. If this structure defines a black and white icon, + // this bitmask is formatted so that the upper half is the icon AND bitmask and the lower half is + // the icon XOR bitmask. Under this condition, the height should be an even multiple of two. If + // this structure defines a color icon, this mask only defines the AND bitmask of the icon. + public IntPtr hbmColor; // (HBITMAP) Handle to the icon color bitmap. This member can be optional if this + // structure defines a black and white icon. The AND bitmask of hbmMask is applied with the SRCAND + // flag to the destination; subsequently, the color bitmap is applied (using XOR) to the + // destination by using the SRCINVERT flag. + } + + [DllImport("user32.dll")] + static extern bool GetIconInfo(IntPtr hIcon, out ICONINFO piconinfo); + + [StructLayout(LayoutKind.Sequential)] + public struct BITMAPINFO + { + public uint biSize; + public int biWidth, biHeight; + public short biPlanes, biBitCount; + public uint biCompression, biSizeImage; + public int biXPelsPerMeter, biYPelsPerMeter; + public uint biClrUsed, biClrImportant; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)] + public uint[] cols; + } + + [DllImport("shell32.dll")] + private static extern int FindExecutable(string lpFile, string lpDirectory, StringBuilder lpResult); + + [DllImport("shell32.dll")] + private static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags); + + [DllImport("user32.dll", EntryPoint = "LoadImage")] + private static extern IntPtr LoadImageID(IntPtr hInstance, int uID, uint type, int width, int height, int load); + + [DllImport("user32.dll", EntryPoint = "LoadImage")] + private static extern IntPtr LoadImageName(IntPtr hInstance, string lpszName, uint type, int width, int height, int load); + + [DllImport("kernel32.dll")] + static extern IntPtr LoadLibrary(string Library); + + [DllImport("gdi32.dll", EntryPoint = "DeleteObject")] + public static extern bool DeleteObject(IntPtr hDc); + + private const uint IMAGE_BITMAP = 0; + private const uint IMAGE_ICON = 1; + + /// <summary> + /// Get the program to execute or open the file. If it is a exe then it is self + /// </summary> + /// <param name="path">path to the file</param> + /// <returns></returns> + public static string getExecutableType(string path) + { + StringBuilder objResultBuffer = new StringBuilder(1024); + int result = FindExecutable(path, path, objResultBuffer); + if (result >= 32) + { + return objResultBuffer.ToString(); + } + return null; + } + + /// <summary> + /// Get the type of a file or folder. On a file it depends on its extension. + /// </summary> + /// <param name="path"></param> + /// <returns></returns> + public static string getFolderType(string path) + { + SHFILEINFO shinfo = new SHFILEINFO(); + if (0 == SHGetFileInfo(path, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), SHGFI_TYPENAME).ToInt32()) + { + return null; + } + return shinfo.szTypeName; + } + + public static IntPtr getIcon(string path, bool getLargeIcon) + { + SHFILEINFO shinfo = new SHFILEINFO(); + if (0 == SHGetFileInfo(path, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), SHGFI_ICON | (getLargeIcon ? 0 : SHGFI_SMALLICON)).ToInt32()) + { + return IntPtr.Zero; + } + return shinfo.hIcon; + } + + public static int[] getIconBits(IntPtr hIcon, int iconSize) + { + ICONINFO iconInfo; + if (GetIconInfo(hIcon, out iconInfo)) + { + IntPtr hWnd = new IntPtr(0); + IntPtr dc = GetDC(hWnd); + BITMAPINFO bmi = new BITMAPINFO(); + bmi.biSize = 40; + bmi.biWidth = iconSize; + bmi.biHeight = -iconSize; + bmi.biPlanes = 1; + bmi.biBitCount = 32; + bmi.biCompression = 0; + int intArrSize = iconSize * iconSize; + int[] iconBits = new int[intArrSize]; + GetDIBits(dc, iconInfo.hbmColor, 0, (uint)iconSize, iconBits, ref bmi, 0); + bool hasAlpha = false; + bool isXP = (Environment.OSVersion.Version.Major >= 6) || (Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor >= 1); + if (isXP) + { + for (int i = 0; i < iconBits.Length; i++) + { + if ((iconBits[i] & 0xFF000000) != 0) + { + hasAlpha = true; + break; + } + } + } + if (!hasAlpha) + { + int[] maskBits = new int[intArrSize]; + GetDIBits(dc, iconInfo.hbmMask, 0, (uint)iconSize, maskBits, ref bmi, 0); + for (int i = 0; i < iconBits.Length; i++) + { + if (maskBits[i] == 0) + { + iconBits[i] = (int)((uint)iconBits[i] | 0xFF000000); + } + } + } + DeleteObject(iconInfo.hbmColor); + DeleteObject(iconInfo.hbmMask); + return iconBits; + } + return null; + } + + public static int getAttribute(string path) + { + SHFILEINFO shinfo = new SHFILEINFO(); + if (0 == SHGetFileInfo(path, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), SHGFI_ATTRIBUTES).ToInt32()) + { + return 0; + } + return (int)shinfo.dwAttributes; + } + + [System.Security.SecuritySafeCritical] + public static string getLinkLocation(string path) + { + using (ShellLink link = new ShellLink()) + { + link.Load(path); + return link.GetPath(); + } + } + + public static int[] getFileChooserBitmapHandle() + { + // Code copied from ShellFolder2.cpp Java_sun_awt_shell_Win32ShellFolder2_getFileChooserBitmapBits + IntPtr libShell32 = LoadLibrary("shell32.dll"); + // Get a handle to an icon. + bool isVista = Environment.OSVersion.Version.Major >= 6; + IntPtr hBitmap = isVista ? + LoadImageName(libShell32, "IDB_TB_SH_DEF_16", IMAGE_BITMAP, 0, 0, 0) : + LoadImageID(libShell32, 216, IMAGE_BITMAP, 0, 0, 0); + if (hBitmap.ToInt32() == 0) + { + IntPtr libComCtl32 = LoadLibrary("comctl32.dll"); + hBitmap = LoadImageID(libComCtl32, 124, IMAGE_BITMAP, 0, 0, 0); + } + if (hBitmap.ToInt32() == 0) + { + return new int[768 * 16]; + } + BITMAPINFO bmi = new BITMAPINFO(); + GetObject(hBitmap, Marshal.SizeOf(bmi), ref bmi); + int width = bmi.biWidth; + int height = bmi.biHeight; + bmi.biSize = 40; + bmi.biHeight = -bmi.biHeight; + bmi.biPlanes = 1; + bmi.biBitCount = 32; + bmi.biCompression = 0; + IntPtr hwnd = new IntPtr(0); + IntPtr dc = GetDC(hwnd); + int[] data = new int[width * height]; + GetDIBits(dc, hBitmap, (uint)0, (uint)height, data, ref bmi, 0); + DeleteObject(hBitmap); + ReleaseDC(hwnd, dc); + return data; + } + + public static IntPtr getIconResource(String libName, int iconID, int cxDesired, int cyDesired) + { + IntPtr hLibName = LoadLibrary(libName); + return LoadImageID(hLibName, iconID, IMAGE_ICON, cxDesired, cyDesired, 0); + } + } + + [System.Security.SecurityCritical] + class ShellLink : IDisposable + { + [ComImport] + [Guid("0000010B-0000-0000-C000-000000000046")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + internal interface IPersistFile + { + [PreserveSig] + void GetClassID(out Guid pClassID); + [PreserveSig] + void IsDirty(); + [PreserveSig] + void Load([MarshalAs(UnmanagedType.LPWStr)] string pszFileName, uint dwMode); + [PreserveSig] + void Save([MarshalAs(UnmanagedType.LPWStr)] string pszFileName, [MarshalAs(UnmanagedType.Bool)] bool fRemember); + [PreserveSig] + void SaveCompleted([MarshalAs(UnmanagedType.LPWStr)] string pszFileName); + [PreserveSig] + void GetCurFile([MarshalAs(UnmanagedType.LPWStr)] out string ppszFileName); + } + + [ComImport] + [Guid("000214F9-0000-0000-C000-000000000046")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + private interface IShellLinkW + { + void GetPath([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszFile, int cchMaxPath, IntPtr pfd, uint fFlags); + void GetIDList(out IntPtr ppidl); + void SetIDList(IntPtr pidl); + void GetDescription([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszFile, int cchMaxName); + void SetDescription([MarshalAs(UnmanagedType.LPWStr)] string pszName); + void GetWorkingDirectory([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszDir, int cchMaxPath); + void SetWorkingDirectory([MarshalAs(UnmanagedType.LPWStr)] string pszDir); + void GetArguments([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszArgs, int cchMaxPath); + void SetArguments([MarshalAs(UnmanagedType.LPWStr)] string pszArgs); + void GetHotkey(out short pwHotkey); + void SetHotkey(short pwHotkey); + void GetShowCmd(out uint piShowCmd); + void SetShowCmd(uint piShowCmd); + void GetIconLocation([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszIconPath, int cchIconPath, out int piIcon); + void SetIconLocation([MarshalAs(UnmanagedType.LPWStr)] string pszIconPath, int iIcon); + void SetRelativePath([MarshalAs(UnmanagedType.LPWStr)] string pszPathRel, uint dwReserved); + void Resolve(IntPtr hWnd, uint fFlags); + void SetPath([MarshalAs(UnmanagedType.LPWStr)] string pszFile); + } + + [Guid("00021401-0000-0000-C000-000000000046")] + [ClassInterfaceAttribute(ClassInterfaceType.None)] + [ComImport] + private class CShellLink { } + + [Flags] + public enum EShowWindowFlags : uint + { + SW_HIDE = 0, + SW_SHOWNORMAL = 1, + SW_NORMAL = 1, + SW_SHOWMINIMIZED = 2, + SW_SHOWMAXIMIZED = 3, + SW_MAXIMIZE = 3, + SW_SHOWNOACTIVATE = 4, + SW_SHOW = 5, + SW_MINIMIZE = 6, + SW_SHOWMINNOACTIVE = 7, + SW_SHOWNA = 8, + SW_RESTORE = 9, + SW_SHOWDEFAULT = 10, + SW_MAX = 10 + } + + private IShellLinkW linkW = (IShellLinkW)new CShellLink(); + + [System.Security.SecuritySafeCritical] + public void Dispose() + { + if (linkW != null) + { + Marshal.ReleaseComObject(linkW); + linkW = null; + } + } + + public void SetPath(string path) + { + linkW.SetPath(path); + } + + public void SetDescription(string description) + { + linkW.SetDescription(description); + } + + public void SetWorkingDirectory(string dir) + { + linkW.SetWorkingDirectory(dir); + } + + public void SetArguments(string args) + { + linkW.SetArguments(args); + } + + public void SetShowCmd(EShowWindowFlags cmd) + { + linkW.SetShowCmd((uint)cmd); + } + + public void Save(string linkFile) + { + ((IPersistFile)linkW).Save(linkFile, true); + } + + public void Load(string linkFile) + { + ((IPersistFile)linkW).Load(linkFile, 0); + } + + public string GetArguments() + { + StringBuilder sb = new StringBuilder(512); + linkW.GetArguments(sb, sb.Capacity); + return sb.ToString(); + } + + public string GetPath() + { + StringBuilder sb = new StringBuilder(512); + linkW.GetPath(sb, sb.Capacity, IntPtr.Zero, 0); + return sb.ToString(); + } + } +} + +namespace IKVM.NativeCode.sun.java2d +{ + static class DefaultDisposerRecord + { + public static void invokeNativeDispose(long disposerMethodPointer, long dataPointer) + { + throw new NotImplementedException(); + } + } + + static class Disposer + { + public static void initIDs() + { + } + } +} + +namespace IKVM.NativeCode.sun.java2d.pipe +{ + static class Region + { + public static void initIDs() { } + } + + static class RenderBuffer + { + public static void copyFromArray(object srcArray, long srcPos, long dstAddr, long length) + { + throw new NotImplementedException(); + } + } +} @@ -9,6 +9,7 @@ <target name="all"> <nant buildfile="tools/tools.build" /> <nant buildfile="runtime/runtime.build" target="first-pass" /> + <nant buildfile="awt/awt.build" target="first-pass" /> <nant buildfile="native/native.build" /> <nant buildfile="reflect/reflect.build" /> <nant buildfile="ikvmc/ikvmc.build" /> diff --git a/openjdk/dependencies.txt b/openjdk/dependencies.txt index 30d6f003..750277d8 100644 --- a/openjdk/dependencies.txt +++ b/openjdk/dependencies.txt @@ -71,6 +71,7 @@ IKVM.OpenJDK.XML.Crypto IKVM.OpenJDK.SwingAWT ->System.Drawing +->IKVM.AWT.WinForms ->IKVM.OpenJDK.Util ->IKVM.OpenJDK.Text ->IKVM.OpenJDK.XML.API diff --git a/openjdk/openjdk.build b/openjdk/openjdk.build index 8e167456..1b98c21f 100644 --- a/openjdk/openjdk.build +++ b/openjdk/openjdk.build @@ -166,6 +166,7 @@ <target name="core" depends="version response.gen.txt"> <copy file="../bin/IKVM.Runtime.dll" todir="." /> + <copy file="../bin/IKVM.AWT.WinForms.dll" todir="." /> <exec program="${project::get-base-directory()}/../bin/ikvmc.exe" useruntimeengine="true"> <arg value="-version:${VERSION}" /> <arg value="${signoption}" /> diff --git a/openjdk/response.txt b/openjdk/response.txt index d55c90cd..1b00bf1a 100644 --- a/openjdk/response.txt +++ b/openjdk/response.txt @@ -573,6 +573,7 @@ assembly.class -recurse:@OPENJDK@/build/linux-amd64/j2re-image/lib/resources.jar/javax/swing/* -recurse:resources.zip/com/sun/swing/internal/plaf/* -r:System.Drawing.dll + -r:IKVM.AWT.WinForms.dll ikvm/awt/*.class java/awt/*.class java/awt/image/*.class diff --git a/runtime/openjdk.cs b/runtime/openjdk.cs index fafbd9d4..5252f07e 100644 --- a/runtime/openjdk.cs +++ b/runtime/openjdk.cs @@ -5054,446 +5054,6 @@ namespace IKVM.NativeCode.java } } -namespace IKVM.NativeCode.sun.awt -{ - static class KeyboardFocusManagerPeerImpl - { - public static object getNativeFocusedWindow(){return null;} - public static object getNativeFocusOwner(){return null;} - public static void clearNativeGlobalFocusOwner(object activeWindow){ } - } - - static class SunToolkit - { - public static void closeSplashScreen() { } - } -} - -namespace IKVM.NativeCode.sun.awt.shell -{ - /// <summary> - /// This class should use only on Windows that we can access shell32.dll - /// </summary> - static class Win32ShellFolder2 - { - private const uint SHGFI_LARGEICON = 0x0; - private const uint SHGFI_SMALLICON = 0x1; - private const uint SHGFI_ICON = 0x100; - private const uint SHGFI_TYPENAME = 0x400; - private const uint SHGFI_ATTRIBUTES = 0x800; - private struct SHFILEINFO - { - public IntPtr hIcon; - public IntPtr iIcon; - public uint dwAttributes; - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] - public string szDisplayName; - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)] - public string szTypeName; - }; - - [DllImport("msvcrt.dll", SetLastError = false)] - static extern IntPtr memcpy(IntPtr dest, IntPtr src, int count); - - [DllImport("gdi32.dll")] - static extern int GetDIBits(IntPtr hdc, IntPtr hbmp, uint uStartScan, - uint cScanLines, int[] lpvBits, ref BITMAPINFO lpbmi, uint uUsage); - - [DllImport("gdi32.dll")] - public static extern int BitBlt(IntPtr hdcDst, int xDst, int yDst, int w, int h, IntPtr hdcSrc, int xSrc, int ySrc, int rop); - - [DllImport("user32.dll")] - public static extern IntPtr GetDC(IntPtr hwnd); - - [DllImport("gdi32.dll")] - static extern int GetObject(IntPtr hgdiobj, int cbBuffer, ref BITMAPINFO lpvObject); - - [DllImport("gdi32.dll")] - public static extern IntPtr CreateCompatibleDC(IntPtr hdc); - - [DllImport("user32.dll")] - public static extern int ReleaseDC(IntPtr hwnd, IntPtr hdc); - - [DllImport("gdi32.dll")] - static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth, int nHeight); - - [DllImport("gdi32.dll")] - public static extern int DeleteDC(IntPtr hdc); - - [StructLayout(LayoutKind.Sequential)] - struct ICONINFO - { - public bool fIcon; // Specifies whether this structure defines an icon or a cursor. A value of TRUE specifies - // an icon; FALSE specifies a cursor. - public Int32 xHotspot; // Specifies the x-coordinate of a cursor's hot spot. If this structure defines an icon, the hot - // spot is always in the center of the icon, and this member is ignored. - public Int32 yHotspot; // Specifies the y-coordinate of the cursor's hot spot. If this structure defines an icon, the hot - // spot is always in the center of the icon, and this member is ignored. - public IntPtr hbmMask; // (HBITMAP) Specifies the icon bitmask bitmap. If this structure defines a black and white icon, - // this bitmask is formatted so that the upper half is the icon AND bitmask and the lower half is - // the icon XOR bitmask. Under this condition, the height should be an even multiple of two. If - // this structure defines a color icon, this mask only defines the AND bitmask of the icon. - public IntPtr hbmColor; // (HBITMAP) Handle to the icon color bitmap. This member can be optional if this - // structure defines a black and white icon. The AND bitmask of hbmMask is applied with the SRCAND - // flag to the destination; subsequently, the color bitmap is applied (using XOR) to the - // destination by using the SRCINVERT flag. - } - - [DllImport("user32.dll")] - static extern bool GetIconInfo(IntPtr hIcon, out ICONINFO piconinfo); - - [StructLayout(LayoutKind.Sequential)] - public struct BITMAPINFO - { - public uint biSize; - public int biWidth, biHeight; - public short biPlanes, biBitCount; - public uint biCompression, biSizeImage; - public int biXPelsPerMeter, biYPelsPerMeter; - public uint biClrUsed, biClrImportant; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)] - public uint[] cols; - } - - [DllImport("shell32.dll")] - private static extern int FindExecutable(string lpFile, string lpDirectory, StringBuilder lpResult); - - [DllImport("shell32.dll")] - private static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags); - - [DllImport("user32.dll", EntryPoint = "LoadImage")] - private static extern IntPtr LoadImageID(IntPtr hInstance, int uID, uint type, int width, int height, int load); - - [DllImport("user32.dll", EntryPoint = "LoadImage")] - private static extern IntPtr LoadImageName(IntPtr hInstance, string lpszName, uint type, int width, int height, int load); - - [DllImport("kernel32.dll")] - static extern IntPtr LoadLibrary(string Library); - - [DllImport("gdi32.dll", EntryPoint = "DeleteObject")] - public static extern bool DeleteObject(IntPtr hDc); - - private const uint IMAGE_BITMAP = 0; - private const uint IMAGE_ICON = 1; - - /// <summary> - /// Get the program to execute or open the file. If it is a exe then it is self - /// </summary> - /// <param name="path">path to the file</param> - /// <returns></returns> - public static string getExecutableType(string path) - { - StringBuilder objResultBuffer = new StringBuilder(1024); - int result = FindExecutable(path, path, objResultBuffer); - if (result >= 32) - { - return objResultBuffer.ToString(); - } - return null; - } - - /// <summary> - /// Get the type of a file or folder. On a file it depends on its extension. - /// </summary> - /// <param name="path"></param> - /// <returns></returns> - public static string getFolderType(string path) - { - SHFILEINFO shinfo = new SHFILEINFO(); - if (0 == SHGetFileInfo(path, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), SHGFI_TYPENAME).ToInt32()) - { - return null; - } - return shinfo.szTypeName; - } - - public static IntPtr getIcon(string path, bool getLargeIcon) - { - SHFILEINFO shinfo = new SHFILEINFO(); - if (0 == SHGetFileInfo(path, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), SHGFI_ICON | (getLargeIcon ? 0 : SHGFI_SMALLICON)).ToInt32()) - { - return IntPtr.Zero; - } - return shinfo.hIcon; - } - - public static int[] getIconBits(IntPtr hIcon, int iconSize) - { - ICONINFO iconInfo; - if (GetIconInfo(hIcon, out iconInfo)) - { - IntPtr hWnd = new IntPtr(0); - IntPtr dc = GetDC(hWnd); - BITMAPINFO bmi = new BITMAPINFO(); - bmi.biSize = 40; - bmi.biWidth = iconSize; - bmi.biHeight = -iconSize; - bmi.biPlanes = 1; - bmi.biBitCount = 32; - bmi.biCompression = 0; - int intArrSize = iconSize * iconSize; - int[] iconBits = new int[intArrSize]; - GetDIBits(dc, iconInfo.hbmColor, 0, (uint)iconSize, iconBits, ref bmi, 0); - bool hasAlpha = false; - bool isXP = (Environment.OSVersion.Version.Major >= 6) || (Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor>=1); - if (isXP) { - for (int i = 0; i < iconBits.Length; i++) - { - if ((iconBits[i] & 0xFF000000) != 0) - { - hasAlpha = true; - break; - } - } - } - if (!hasAlpha) - { - int[] maskBits = new int[intArrSize]; - GetDIBits(dc, iconInfo.hbmMask, 0, (uint)iconSize, maskBits, ref bmi, 0); - for (int i = 0; i < iconBits.Length; i++) - { - if (maskBits[i] == 0) { - iconBits[i] = (int)((uint)iconBits[i] | 0xFF000000); - } - } - } - DeleteObject(iconInfo.hbmColor); - DeleteObject(iconInfo.hbmMask); - return iconBits; - } - return null; - } - - public static int getAttribute(string path) - { - SHFILEINFO shinfo = new SHFILEINFO(); - if (0 == SHGetFileInfo(path, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), SHGFI_ATTRIBUTES).ToInt32()) - { - return 0; - } - return (int)shinfo.dwAttributes; - } - - [System.Security.SecuritySafeCritical] - public static string getLinkLocation(string path) - { - using (ShellLink link = new ShellLink()) - { - link.Load(path); - return link.GetPath(); - } - } - - public static int[] getFileChooserBitmapHandle() - { - // Code copied from ShellFolder2.cpp Java_sun_awt_shell_Win32ShellFolder2_getFileChooserBitmapBits - IntPtr libShell32 = LoadLibrary("shell32.dll"); - // Get a handle to an icon. - bool isVista = Environment.OSVersion.Version.Major >= 6; - IntPtr hBitmap = isVista ? - LoadImageName(libShell32, "IDB_TB_SH_DEF_16", IMAGE_BITMAP, 0, 0, 0) : - LoadImageID(libShell32, 216, IMAGE_BITMAP, 0, 0, 0); - if (hBitmap.ToInt32() == 0) - { - IntPtr libComCtl32 = LoadLibrary("comctl32.dll"); - hBitmap = LoadImageID(libComCtl32, 124, IMAGE_BITMAP, 0, 0, 0); - } - if (hBitmap.ToInt32() == 0) - { - return new int[768*16]; - } - BITMAPINFO bmi = new BITMAPINFO(); - GetObject(hBitmap, Marshal.SizeOf(bmi), ref bmi); - int width = bmi.biWidth; - int height = bmi.biHeight; - bmi.biSize = 40; - bmi.biHeight = -bmi.biHeight; - bmi.biPlanes = 1; - bmi.biBitCount = 32; - bmi.biCompression = 0; - IntPtr hwnd = new IntPtr(0); - IntPtr dc = GetDC(hwnd); - int[] data = new int[width*height]; - GetDIBits(dc, hBitmap, (uint)0, (uint)height, data, ref bmi, 0); - DeleteObject(hBitmap); - ReleaseDC(hwnd, dc); - return data; - } - - public static IntPtr getIconResource(String libName, int iconID, int cxDesired, int cyDesired) - { - IntPtr hLibName = LoadLibrary(libName); - return LoadImageID(hLibName, iconID, IMAGE_ICON, cxDesired, cyDesired, 0); - } - } - - [System.Security.SecurityCritical] - class ShellLink : IDisposable - { - [ComImport] - [Guid("0000010B-0000-0000-C000-000000000046")] - [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] - internal interface IPersistFile - { - [PreserveSig] - void GetClassID(out Guid pClassID); - [PreserveSig] - void IsDirty(); - [PreserveSig] - void Load([MarshalAs(UnmanagedType.LPWStr)] string pszFileName, uint dwMode); - [PreserveSig] - void Save([MarshalAs(UnmanagedType.LPWStr)] string pszFileName, [MarshalAs(UnmanagedType.Bool)] bool fRemember); - [PreserveSig] - void SaveCompleted([MarshalAs(UnmanagedType.LPWStr)] string pszFileName); - [PreserveSig] - void GetCurFile([MarshalAs(UnmanagedType.LPWStr)] out string ppszFileName); - } - - [ComImport] - [Guid("000214F9-0000-0000-C000-000000000046")] - [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] - private interface IShellLinkW - { - void GetPath([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszFile, int cchMaxPath, IntPtr pfd, uint fFlags); - void GetIDList(out IntPtr ppidl); - void SetIDList(IntPtr pidl); - void GetDescription([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszFile, int cchMaxName); - void SetDescription([MarshalAs(UnmanagedType.LPWStr)] string pszName); - void GetWorkingDirectory([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszDir, int cchMaxPath); - void SetWorkingDirectory([MarshalAs(UnmanagedType.LPWStr)] string pszDir); - void GetArguments([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszArgs, int cchMaxPath); - void SetArguments([MarshalAs(UnmanagedType.LPWStr)] string pszArgs); - void GetHotkey(out short pwHotkey); - void SetHotkey(short pwHotkey); - void GetShowCmd(out uint piShowCmd); - void SetShowCmd(uint piShowCmd); - void GetIconLocation([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszIconPath, int cchIconPath, out int piIcon); - void SetIconLocation([MarshalAs(UnmanagedType.LPWStr)] string pszIconPath, int iIcon); - void SetRelativePath([MarshalAs(UnmanagedType.LPWStr)] string pszPathRel, uint dwReserved); - void Resolve(IntPtr hWnd, uint fFlags); - void SetPath([MarshalAs(UnmanagedType.LPWStr)] string pszFile); - } - - [Guid("00021401-0000-0000-C000-000000000046")] - [ClassInterfaceAttribute(ClassInterfaceType.None)] - [ComImport] - private class CShellLink { } - - [Flags] - public enum EShowWindowFlags : uint - { - SW_HIDE = 0, - SW_SHOWNORMAL = 1, - SW_NORMAL = 1, - SW_SHOWMINIMIZED = 2, - SW_SHOWMAXIMIZED = 3, - SW_MAXIMIZE = 3, - SW_SHOWNOACTIVATE = 4, - SW_SHOW = 5, - SW_MINIMIZE = 6, - SW_SHOWMINNOACTIVE = 7, - SW_SHOWNA = 8, - SW_RESTORE = 9, - SW_SHOWDEFAULT = 10, - SW_MAX = 10 - } - - private IShellLinkW linkW = (IShellLinkW)new CShellLink(); - - [System.Security.SecuritySafeCritical] - public void Dispose() - { - if (linkW != null) - { - Marshal.ReleaseComObject(linkW); - linkW = null; - } - } - - public void SetPath(string path) - { - linkW.SetPath(path); - } - - public void SetDescription(string description) - { - linkW.SetDescription(description); - } - - public void SetWorkingDirectory(string dir) - { - linkW.SetWorkingDirectory(dir); - } - - public void SetArguments(string args) - { - linkW.SetArguments(args); - } - - public void SetShowCmd(EShowWindowFlags cmd) - { - linkW.SetShowCmd((uint)cmd); - } - - public void Save(string linkFile) - { - ((IPersistFile)linkW).Save(linkFile, true); - } - - public void Load(string linkFile) - { - ((IPersistFile)linkW).Load(linkFile, 0); - } - - public string GetArguments() - { - StringBuilder sb = new StringBuilder(512); - linkW.GetArguments(sb, sb.Capacity); - return sb.ToString(); - } - - public string GetPath() - { - StringBuilder sb = new StringBuilder(512); - linkW.GetPath(sb, sb.Capacity, IntPtr.Zero, 0); - return sb.ToString(); - } - } -} - -namespace IKVM.NativeCode.sun.java2d -{ - static class DefaultDisposerRecord - { - public static void invokeNativeDispose(long disposerMethodPointer, long dataPointer) - { - throw new NotImplementedException(); - } - } - - static class Disposer - { - public static void initIDs() - { - } - } -} - -namespace IKVM.NativeCode.sun.java2d.pipe -{ - static class Region - { - public static void initIDs(){ } - } - - static class RenderBuffer - { - public static void copyFromArray(object srcArray, long srcPos, long dstAddr, long length){ - throw new NotImplementedException(); - } - } -} - namespace IKVM.NativeCode.sun.misc { static class GC |