using System;
using System.Runtime.InteropServices;
using static Vanara.PInvoke.Ole32;
using static Vanara.PInvoke.Shell32;
namespace Vanara.PInvoke
{
public static partial class SearchApi
{
///
/// Exposes methods that create and modify search folders. The Set methods are called first to set up the parameters of the search.
/// When not called, default values will be used instead. ISearchFolderItemFactory::GetIDList and
/// ISearchFolderItemFactory::GetShellItem return the two forms of the search specified by these parameters.
///
/// To implement this interface use class ID CLSID_SearchFolderItemFactory.
// https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nn-shobjidl_core-isearchfolderitemfactory
[PInvokeData("shobjidl_core.h", MSDNShortId = "a684b373-6de4-4b4a-bbae-85e1c5a7e04a")]
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("a0ffbc28-5482-4366-be27-3e81e78e06c2"), CoClass(typeof(SearchFolderItemFactory))]
public interface ISearchFolderItemFactory
{
/// Sets the search folder display name, as specified.
///
/// Type: LPCWSTR
/// A pointer to a folder display name as a Unicode string.
///
/// Calling this method is required. A display name must be set.
// https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-isearchfolderitemfactory-setdisplayname
// HRESULT SetDisplayName( LPCWSTR pszDisplayName );
void SetDisplayName([MarshalAs(UnmanagedType.LPWStr)] string pszDisplayName);
/// Sets a search folder type ID, as specified.
///
/// Type: FOLDERTYPEID
/// The FOLDERTYPEID, which is a GUID used to identify folder types within the system. The default is FOLDERTYPID_Library
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-isearchfolderitemfactory-setfoldertypeid
// HRESULT SetFolderTypeID( FOLDERTYPEID ftid );
void SetFolderTypeID(Guid ftid);
///
/// Sets folder logical view mode. The default settings are based on the which is set by the
/// ISearchFolderItemFactory::SetFolderTypeID method.
///
///
/// Type: FOLDERLOGICALVIEWMODE
/// The FOLDERLOGICALVIEWMODE value.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-isearchfolderitemfactory-setfolderlogicalviewmode
// HRESULT SetFolderLogicalViewMode( FOLDERLOGICALVIEWMODE flvm );
void SetFolderLogicalViewMode(FOLDERLOGICALVIEWMODE flvm);
///
/// Sets the search folder icon size, as specified. The default settings are based on the which is set by the
/// ISearchFolderItemFactory::SetFolderTypeID method.
///
///
/// Type: int
/// The icon size.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-isearchfolderitemfactory-seticonsize
// HRESULT SetIconSize( int iIconSize );
void SetIconSize(int iIconSize);
///
/// Creates a new column list whose columns are all visible, given an array of PROPERTYKEY structures. The default is based on FolderTypeID.
///
///
/// Type: UINT
/// The number of array elements.
///
///
/// Type: const PROPERTYKEY*
/// A pointer to an array of PROPERTYKEY structures.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-isearchfolderitemfactory-setvisiblecolumns
// HRESULT SetVisibleColumns( UINT cVisibleColumns, const PROPERTYKEY *rgKey );
void SetVisibleColumns(uint cVisibleColumns, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] PROPERTYKEY[] rgKey);
/// Creates a list of sort column directions, as specified.
///
/// Type: UINT
/// The number of sort columns.
///
///
/// Type: SORTCOLUMN*
/// A pointer to an array of SORTCOLUMN structures containing sort direction. The default is PKEY_ItemNameDisplay.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-isearchfolderitemfactory-setsortcolumns
// HRESULT SetSortColumns( UINT cSortColumns, SORTCOLUMN *rgSortColumns );
void SetSortColumns(uint cSortColumns, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] SORTCOLUMN[] rgSortColumns);
/// Sets a group column, as specified. If no group column is specified, no grouping occurs.
///
/// Type: REFPROPERTYKEY
/// A reference to a group column PROPERTYKEY.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-isearchfolderitemfactory-setgroupcolumn
// HRESULT SetGroupColumn( REFPROPERTYKEY keyGroup );
void SetGroupColumn(in PROPERTYKEY keyGroup);
///
/// Creates a list of stack keys, as specified. If this method is not called, by default the folder will not be stacked.
///
///
/// Type: UINT
/// The number of stacks keys.
///
///
/// Type: PROPERTYKEY*
/// A pointer to an array of PROPERTYKEY structures containing stack key information.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-isearchfolderitemfactory-setstacks HRESULT
// SetStacks( UINT cStackKeys, PROPERTYKEY *rgStackKeys );
void SetStacks(uint cStackKeys, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] PROPERTYKEY[] rgStackKeys);
/// Sets search scope, as specified.
///
/// Type: IShellItemArray*
///
/// A pointer to the list of locations to search. The search will include this location and all its subcontainers. The default is FOLDERID_Profile
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-isearchfolderitemfactory-setscope HRESULT
// SetScope( IShellItemArray *psiaScope );
void SetScope([In] IShellItemArray psiaScope);
///
/// Sets the ICondition of the search. When this method is not called, the resulting search will have no filters applied.
///
///
/// Type: ICondition*
/// A pointer to an ICondition interface.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-isearchfolderitemfactory-setcondition
// HRESULT SetCondition( ICondition *pCondition );
void SetCondition([In] ICondition pCondition);
/// Gets the search folder as a IShellItem.
///
/// Type: REFIID
/// A reference to the desired IID.
///
/// The IShellItem interface pointer specified in riid.
/// When the retrieved IShellItem is enumerated, it returns the search results.
// https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-isearchfolderitemfactory-getshellitem
// HRESULT GetShellItem( REFIID riid, void **ppv );
[return: MarshalAs(UnmanagedType.IUnknown)]
object GetShellItem(in Guid riid);
/// Gets the search folder as an ITEMIDLIST.
///
/// Type: PIDLIST_ABSOLUTE*
/// When this method returns successfully, contains a PIDL.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nf-shobjidl_core-isearchfolderitemfactory-getidlist HRESULT
// GetIDList( PIDLIST_ABSOLUTE *ppidl );
PIDL GetIDList();
}
/// Extension method to simplify using the method.
/// Type of the interface to get.
/// An instance.
/// Receives the interface pointer requested in .
public static T GetShellItem(this ISearchFolderItemFactory sfif) where T : class => (T)sfif.GetShellItem(typeof(T).GUID);
/// CLSID_SearchFolderItemFactory
[PInvokeData("shobjidl_core.h", MSDNShortId = "a684b373-6de4-4b4a-bbae-85e1c5a7e04a")]
[ComImport, Guid("14010e02-bbbd-41f0-88e3-eda371216584"), ClassInterface(ClassInterfaceType.None)]
public class SearchFolderItemFactory { }
}
}