1
//Copyright (c) Microsoft Corporation. All rights reserved.
4
using System.Runtime.InteropServices;
5
using Microsoft.WindowsAPICodePack.Controls;
6
using Microsoft.WindowsAPICodePack.Controls.WindowsForms;
8
namespace MS.WindowsAPICodePack.Internal
11
/// This provides a connection point container compatible dispatch interface for
12
/// hooking into the ExplorerBrowser view.
15
[ClassInterface(ClassInterfaceType.AutoDual)]
16
public class ExplorerBrowserViewEvents : IDisposable
18
#region implementation
19
private uint viewConnectionPointCookie;
20
private object viewDispatch;
22
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2006:UseSafeHandleToEncapsulateNativeResources")]
23
private IntPtr nullPtr = IntPtr.Zero;
25
private Guid IID_DShellFolderViewEvents = new Guid(ExplorerBrowserIIDGuid.DShellFolderViewEvents);
26
private Guid IID_IDispatch = new Guid(ExplorerBrowserIIDGuid.IDispatch);
27
private ExplorerBrowser parent;
32
/// Default constructor for ExplorerBrowserViewEvents
34
public ExplorerBrowserViewEvents() : this(null) { }
36
internal ExplorerBrowserViewEvents(ExplorerBrowser parent)
43
internal void ConnectToView(IShellView psv)
47
HResult hr = psv.GetItemObject(
48
ShellViewGetItemObject.Background,
54
hr = ExplorerBrowserNativeMethods.ConnectToConnectionPoint(
56
ref IID_DShellFolderViewEvents,
59
ref viewConnectionPointCookie,
64
Marshal.ReleaseComObject(viewDispatch);
69
internal void DisconnectFromView()
71
if (viewDispatch != null)
73
ExplorerBrowserNativeMethods.ConnectToConnectionPoint(
75
ref IID_DShellFolderViewEvents,
78
ref viewConnectionPointCookie,
81
Marshal.ReleaseComObject(viewDispatch);
83
viewConnectionPointCookie = 0;
88
#region IDispatch events
89
// These need to be public to be accessible via AutoDual reflection
92
/// The view selection has changed
94
[DispId(ExplorerBrowserViewDispatchIds.SelectionChanged)]
95
public void ViewSelectionChanged()
97
parent.FireSelectionChanged();
101
/// The contents of the view have changed
103
[DispId(ExplorerBrowserViewDispatchIds.ContentsChanged)]
104
public void ViewContentsChanged()
106
parent.FireContentChanged();
110
/// The enumeration of files in the view is complete
112
[DispId(ExplorerBrowserViewDispatchIds.FileListEnumDone)]
113
public void ViewFileListEnumDone()
115
parent.FireContentEnumerationComplete();
119
/// The selected item in the view has changed (not the same as the selection has changed)
121
[DispId(ExplorerBrowserViewDispatchIds.SelectedItemChanged)]
122
public void ViewSelectedItemChanged()
124
parent.FireSelectedItemChanged();
129
/// Finalizer for ExplorerBrowserViewEvents
131
~ExplorerBrowserViewEvents()
136
#region IDisposable Members
139
/// Disconnects and disposes object.
141
public void Dispose()
144
GC.SuppressFinalize(this);
148
/// Disconnects and disposes object.
150
/// <param name="disposed"></param>
151
protected virtual void Dispose(bool disposed)
155
DisconnectFromView();