~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/xwt/Xwt.WPF/Xwt.WPFBackend.Interop/NativeMethods.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
Import upstream version 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// NativeMethods.cs
 
3
//  
 
4
// Author:
 
5
//       Eric Maupin <ermau@xamarin.com>
 
6
// 
 
7
// Copyright (c) 2012 Xamarin, Inc.
 
8
// 
 
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
10
// of this software and associated documentation files (the "Software"), to deal
 
11
// in the Software without restriction, including without limitation the rights
 
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
13
// copies of the Software, and to permit persons to whom the Software is
 
14
// furnished to do so, subject to the following conditions:
 
15
// 
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
// 
 
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
25
// THE SOFTWARE.
 
26
 
 
27
using System;
 
28
using System.Runtime.InteropServices;
 
29
using System.Windows;
 
30
using System.Windows.Interop;
 
31
using System.Windows.Media.Imaging;
 
32
 
 
33
namespace Xwt.WPFBackend.Interop
 
34
{
 
35
        internal static class NativeMethods
 
36
        {
 
37
                [StructLayout (LayoutKind.Sequential, CharSet = CharSet.Unicode)]
 
38
                struct StockIconInfo
 
39
                {
 
40
                        internal uint StructureSize;
 
41
                        internal IntPtr Handle;
 
42
                        internal int ImageIndex;
 
43
                        internal int Indentifier;
 
44
                        [MarshalAs (UnmanagedType.ByValTStr, SizeConst = 260)]
 
45
                        internal string Path;
 
46
                }
 
47
 
 
48
                [DllImport ("Shell32.dll", CharSet = CharSet.Unicode)]
 
49
                static extern int SHGetStockIconInfo (NativeStockIcon icon, NativeStockIconOptions options,
 
50
                                                               ref StockIconInfo info);
 
51
 
 
52
                [DllImport ("User32.dll", SetLastError = true)]
 
53
                static extern bool DestroyIcon (IntPtr handle);
 
54
 
 
55
                internal static BitmapSource GetImage (NativeStockIcon icon, NativeStockIconOptions options)
 
56
                {
 
57
                        options |= NativeStockIconOptions.Handle;
 
58
 
 
59
                        StockIconInfo info = new StockIconInfo();
 
60
                        info.StructureSize = (uint) Marshal.SizeOf (typeof (StockIconInfo));
 
61
 
 
62
                        int hresult = SHGetStockIconInfo (icon, options, ref info);
 
63
                        if (hresult < 0)
 
64
                                throw new COMException ("SHGetStockIconInfo failed", hresult);
 
65
 
 
66
                        BitmapSource bitmap;
 
67
                        try {
 
68
                                bitmap = Imaging.CreateBitmapSourceFromHIcon (info.Handle, Int32Rect.Empty, null);
 
69
                        }
 
70
                        finally {
 
71
                                DestroyIcon (info.Handle);
 
72
                        }
 
73
 
 
74
                        return bitmap;
 
75
                }
 
76
        }
 
77
}
 
 
b'\\ No newline at end of file'