~ubuntu-branches/ubuntu/vivid/monodevelop/vivid-proposed

« back to all changes in this revision

Viewing changes to src/addins/WindowsPlatform/WindowsAPICodePack/Shell/ExplorerBrowser/ExplorerBrowserViewEvents.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2014-10-09 14:09:23 UTC
  • mfrom: (10.3.5)
  • Revision ID: package-import@ubuntu.com-20141009140923-s0d22u5f9kg8jvds
Tags: 5.5.0.227-1
* [b2c8331] Imported Upstream version 5.5.0.227 (Closes: #754316)
* [d210995] Delete obsolete patches
* [1b59ae1] Clear patch fizz, via quilt refresh
* [3dd147d] Fix error in configure.in which applies for tarball builds but 
  not git builds when running autoreconf
* [21c2a57] Remove Metacity references for good
* [3331661] Ensure NUnit 2.6.3 is installed
* [fd85c88] Build-depend on NuGet
* [a1ae116] Add WebKit to build dependencies, for Xwt moduleref resolution
* [9b4cf12] Since the GDB addin is integrated now, declare it in 
  debian/control
* [6231562] Correct NUnit links
* [3d2b693] Fix NuGet addin, by copying libs locally
* [74bf9a8] Don't symlink unused Mocks NUnit assembly
* [ade52b2] Ensure IKVM.Reflection is built with default (4.5) profile

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//Copyright (c) Microsoft Corporation.  All rights reserved.
 
2
 
 
3
using System;
 
4
using System.Runtime.InteropServices;
 
5
using Microsoft.WindowsAPICodePack.Controls;
 
6
using Microsoft.WindowsAPICodePack.Controls.WindowsForms;
 
7
 
 
8
namespace MS.WindowsAPICodePack.Internal
 
9
{
 
10
    /// <summary>
 
11
    /// This provides a connection point container compatible dispatch interface for
 
12
    /// hooking into the ExplorerBrowser view.
 
13
    /// </summary>    
 
14
    [ComVisible(true)]
 
15
    [ClassInterface(ClassInterfaceType.AutoDual)]
 
16
    public class ExplorerBrowserViewEvents : IDisposable
 
17
    {
 
18
        #region implementation
 
19
        private uint viewConnectionPointCookie;
 
20
        private object viewDispatch;
 
21
 
 
22
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2006:UseSafeHandleToEncapsulateNativeResources")]
 
23
        private IntPtr nullPtr = IntPtr.Zero;
 
24
 
 
25
        private Guid IID_DShellFolderViewEvents = new Guid(ExplorerBrowserIIDGuid.DShellFolderViewEvents);
 
26
        private Guid IID_IDispatch = new Guid(ExplorerBrowserIIDGuid.IDispatch);
 
27
        private ExplorerBrowser parent;
 
28
        #endregion
 
29
 
 
30
        #region contstruction
 
31
        /// <summary>
 
32
        /// Default constructor for ExplorerBrowserViewEvents
 
33
        /// </summary>
 
34
        public ExplorerBrowserViewEvents() : this(null) { }
 
35
 
 
36
        internal ExplorerBrowserViewEvents(ExplorerBrowser parent)
 
37
        {
 
38
            this.parent = parent;
 
39
        }
 
40
        #endregion
 
41
 
 
42
        #region operations
 
43
        internal void ConnectToView(IShellView psv)
 
44
        {
 
45
            DisconnectFromView();
 
46
 
 
47
            HResult hr = psv.GetItemObject(
 
48
                ShellViewGetItemObject.Background,
 
49
                ref IID_IDispatch,
 
50
                out viewDispatch);
 
51
 
 
52
            if (hr == HResult.Ok)
 
53
            {
 
54
                hr = ExplorerBrowserNativeMethods.ConnectToConnectionPoint(
 
55
                    this,
 
56
                    ref IID_DShellFolderViewEvents,
 
57
                    true,
 
58
                    viewDispatch,
 
59
                    ref viewConnectionPointCookie,
 
60
                    ref nullPtr);
 
61
 
 
62
                if (hr != HResult.Ok)
 
63
                {
 
64
                    Marshal.ReleaseComObject(viewDispatch);
 
65
                }
 
66
            }
 
67
        }
 
68
 
 
69
        internal void DisconnectFromView()
 
70
        {
 
71
            if (viewDispatch != null)
 
72
            {
 
73
                ExplorerBrowserNativeMethods.ConnectToConnectionPoint(
 
74
                    IntPtr.Zero,
 
75
                    ref IID_DShellFolderViewEvents,
 
76
                    false,
 
77
                    viewDispatch,
 
78
                    ref viewConnectionPointCookie,
 
79
                    ref nullPtr);
 
80
 
 
81
                Marshal.ReleaseComObject(viewDispatch);
 
82
                viewDispatch = null;
 
83
                viewConnectionPointCookie = 0;
 
84
            }
 
85
        }
 
86
        #endregion
 
87
 
 
88
        #region IDispatch events
 
89
        // These need to be public to be accessible via AutoDual reflection
 
90
 
 
91
        /// <summary>
 
92
        /// The view selection has changed
 
93
        /// </summary>
 
94
        [DispId(ExplorerBrowserViewDispatchIds.SelectionChanged)]
 
95
        public void ViewSelectionChanged()
 
96
        {
 
97
            parent.FireSelectionChanged();
 
98
        }
 
99
 
 
100
        /// <summary>
 
101
        /// The contents of the view have changed
 
102
        /// </summary>
 
103
        [DispId(ExplorerBrowserViewDispatchIds.ContentsChanged)]
 
104
        public void ViewContentsChanged()
 
105
        {
 
106
            parent.FireContentChanged();
 
107
        }
 
108
 
 
109
        /// <summary>
 
110
        /// The enumeration of files in the view is complete
 
111
        /// </summary>
 
112
        [DispId(ExplorerBrowserViewDispatchIds.FileListEnumDone)]
 
113
        public void ViewFileListEnumDone()
 
114
        {
 
115
            parent.FireContentEnumerationComplete();
 
116
        }
 
117
 
 
118
        /// <summary>
 
119
        /// The selected item in the view has changed (not the same as the selection has changed)
 
120
        /// </summary>
 
121
        [DispId(ExplorerBrowserViewDispatchIds.SelectedItemChanged)]
 
122
        public void ViewSelectedItemChanged()
 
123
        {
 
124
            parent.FireSelectedItemChanged();
 
125
        }
 
126
        #endregion
 
127
 
 
128
        /// <summary>
 
129
        /// Finalizer for ExplorerBrowserViewEvents
 
130
        /// </summary>
 
131
        ~ExplorerBrowserViewEvents()
 
132
        {
 
133
            Dispose(false);
 
134
        }
 
135
 
 
136
        #region IDisposable Members
 
137
 
 
138
        /// <summary>
 
139
        /// Disconnects and disposes object.
 
140
        /// </summary>        
 
141
        public void Dispose()
 
142
        {
 
143
            Dispose(true);
 
144
            GC.SuppressFinalize(this);
 
145
        }
 
146
 
 
147
        /// <summary>
 
148
        /// Disconnects and disposes object.
 
149
        /// </summary>
 
150
        /// <param name="disposed"></param>
 
151
        protected virtual void Dispose(bool disposed)
 
152
        {
 
153
            if (disposed)
 
154
            {
 
155
                DisconnectFromView();
 
156
            }
 
157
        }
 
158
 
 
159
        #endregion
 
160
    }
 
161
}