private FolderView(ExplorerBrowserBase explorerBrowser) { Contract.Requires <ArgumentNullException>(explorerBrowser != null); this.explorerBrowser = explorerBrowser; this.folderViewNative = Create(); }
internal int GetSelectedItemsCount() { int itemsCount = 0; IFolderView2 iFV2 = GetFolderView2(); if (iFV2 != null) { try { HResult hr = iFV2.ItemCount((uint)ShellViewGetItemObject.Selection, out itemsCount); if (hr != HResult.Ok && hr != HResult.ElementNotFound && hr != HResult.Fail) { throw new CommonControlException(LocalizedMessages.ExplorerBrowserSelectedItemCount, hr); } } finally { Marshal.ReleaseComObject(iFV2); iFV2 = null; } } return(itemsCount); }
/// <summary> /// Gets the items in the ExplorerBrowser as an IShellItemArray /// </summary> /// <returns></returns> internal IShellItemArray GetItemsArray() { IShellItemArray iArray = null; IFolderView2 iFV2 = GetFolderView2(); if (iFV2 != null) { try { Guid iidShellItemArray = new Guid(ShellIIDGuid.IShellItemArray); object oArray = null; HResult hr = iFV2.Items((uint)ShellViewGetItemObject.AllView, ref iidShellItemArray, out oArray); if (hr != HResult.Ok && hr != HResult.Fail && hr != HResult.ElementNotFound && hr != HResult.InvalidArguments) { throw new CommonControlException(LocalizedMessages.ExplorerBrowserViewItems, hr); } iArray = oArray as IShellItemArray; } finally { Marshal.ReleaseComObject(iFV2); iFV2 = null; } } return(iArray); }
/// <summary> /// Gets the items in the ExplorerBrowser as an IShellItemArray /// </summary> /// <returns></returns> internal IShellItemArray GetItemsArray() { IShellItemArray iArray = null; IFolderView2 iFV2 = GetFolderView2(); if (iFV2 != null) { try { Guid iidShellItemArray = new Guid(ShellIIDGuid.IShellItemArray); object oArray = null; HRESULT hr = iFV2.Items((uint)SVGIO.SVGIO_ALLVIEW, ref iidShellItemArray, out oArray); if (hr != HRESULT.S_OK && hr != HRESULT.E_FAIL && hr != HRESULT.E_ELEMENTNOTFOUND && hr != HRESULT.E_INVALIDARG) { throw new COMException("unexpected error retrieving view items", (int)hr); } iArray = oArray as IShellItemArray; } finally { Marshal.ReleaseComObject(iFV2); iFV2 = null; } } return(iArray); }
internal int GetSelectedItemsCount() { int itemsCount = 0; IFolderView2 iFV2 = GetFolderView2(); if (iFV2 != null) { try { HRESULT hr = iFV2.ItemCount((uint)SVGIO.SVGIO_SELECTION, out itemsCount); if (hr != HRESULT.S_OK && hr != HRESULT.E_ELEMENTNOTFOUND && hr != HRESULT.E_FAIL) { throw new COMException("unexpected error retrieving selected item count", (int)hr); } } finally { Marshal.ReleaseComObject(iFV2); iFV2 = null; } } return(itemsCount); }
public static IShellItem GetShellItem(this IFolderView2 pfv, int iItem = -1) { if (iItem == -1 && pfv.GetSelectedItem(-1, out iItem).Failed) { return(null); } return(pfv.GetItem <IShellItem>(iItem)); }
public void SetEmptyText(string text) { if (this.ShellView != null) { IntPtr pdf; Guid gFV = NsExtension.IID_IFolderView2; IntPtr ppv = Marshal.GetComInterfaceForObject(this.ShellView, typeof(IShellView)); Marshal.QueryInterface(ppv, ref gFV, out pdf); IFolderView2 pFV2 = (IFolderView2)Marshal.GetObjectForIUnknown(pdf); pFV2.SetText(0, text); Marshal.ReleaseComObject(pFV2); } }
protected virtual void Dispose(bool disposing) { if (!this.disposed) { if (disposing) { } if (this.folderViewNative != null) { Marshal.ReleaseComObject(this.folderViewNative); this.folderViewNative = null; } this.disposed = true; } }
/// <summary> /// Returns the current view mode of the browser /// </summary> /// <returns></returns> internal FolderViewMode GetCurrentViewMode() { IFolderView2 ifv2 = GetFolderView2(); uint viewMode = 0; if (ifv2 != null) { try { HResult hr = ifv2.GetCurrentViewMode(out viewMode); if (hr != HResult.Ok) { throw new ShellException(hr); } } finally { Marshal.ReleaseComObject(ifv2); ifv2 = null; } } return((FolderViewMode)viewMode); }
public void EnableHeaderInAllViews() { IShellView ppshv = null; try { if (shellBrowser.QueryActiveShellView(out ppshv) == 0) { IFolderView2 view2 = ppshv as IFolderView2; if (view2 != null) { view2.SetCurrentFolderFlags(FWF.NOHEADERINALLVIEWS, 0); } } } finally { if (ppshv != null) { Marshal.ReleaseComObject(ppshv); } } }
/// <summary> /// Returns the current view mode of the browser /// </summary> /// <returns></returns> internal FOLDERVIEWMODE GetCurrentViewMode() { IFolderView2 ifv2 = GetFolderView2(); uint viewMode = 0; if (ifv2 != null) { try { HRESULT hr = ifv2.GetCurrentViewMode(out viewMode); if (hr != HRESULT.S_OK) { throw Marshal.GetExceptionForHR((int)hr); } } finally { Marshal.ReleaseComObject(ifv2); ifv2 = null; } } return((FOLDERVIEWMODE)viewMode); }
private static extern void SetSortColumns(IFolderView2 view, int count, [MarshalAs(UnmanagedType.LPArray)] SORTCOLUMN[] pk);
private static extern IntPtr GetItemName(IFolderView2 view, int index);
private static extern bool IsItemFolder(IFolderView2 view, int index);
protected override void WndProc(ref Message m) { if (m.Msg == (int)WindowsAPI.WndMsg.WM_CONTEXTMENU) { this.Browser.IsRenameStarted = true; ShellObject[] dirs = this.Browser.SelectedItems.ToArray(); ContextShellMenu cm1 = new ContextShellMenu(this.Browser, this.Browser.SelectedItems.Count > 0 ? ShellViewGetItemObject.Selection : ShellViewGetItemObject.Background); cm1.ShowContextMenu(Cursor.Position);//new System.Drawing.Point(GetCursorPosition().X, GetCursorPosition().Y)); return; } if (m.Msg == (int)WindowsAPI.WndMsg.WM_EXITMENULOOP) { //this.IsRenameStarted = false; } if (m.Msg == 78) { //var r = (WindowsAPI.NMHDR*)(IntPtr)lParam; WindowsAPI.NMHDR nmhdr = new WindowsAPI.NMHDR(); nmhdr = (WindowsAPI.NMHDR)m.GetLParam(nmhdr.GetType()); switch ((int)nmhdr.code) { case WNM.LVN_GETINFOTIP: //TODO: Write here the code for the tooltip flyout break; case WNM.NM_CUSTOMDRAW: if (!this.Browser.NavigationLog.CurrentLocation.IsSearchFolder) { if (nmhdr.hwndFrom == this.SysListviewhandle) { var nmlvcd = WindowsAPI.PtrToStructure <WindowsAPI.NMLVCUSTOMDRAW>(m.LParam); var index = (int)nmlvcd.nmcd.dwItemSpec; var hdc = nmlvcd.nmcd.hdc; Guid IIFV2 = typeof(IShellItem).GUID; IFolderView2 fv2 = this.Browser.GetFolderView2(); IShellItem item = null; try { fv2.GetItem(index, ref IIFV2, out item); } catch (Exception) { } object ext = null; ShellObject itemobj = null; if (item != null) { itemobj = ShellObjectFactory.Create(item); ext = itemobj.Properties.System.FileExtension.Value; } Color?textColor = null; if (this.Browser.LVItemsColorCodes != null && this.Browser.LVItemsColorCodes.Count > 0) { if (ext != null) { var extItemsAvailable = this.Browser.LVItemsColorCodes.Where(c => c.ExtensionList.Contains(ext.ToString())).Count() > 0; if (extItemsAvailable) { var color = this.Browser.LVItemsColorCodes.Where(c => c.ExtensionList.ToLowerInvariant().Contains(ext.ToString().ToLowerInvariant())).Select(c => c.TextColor).SingleOrDefault(); textColor = color; } } } switch (nmlvcd.nmcd.dwDrawStage) { case CDDS_PREPAINT: m.Result = (IntPtr)CDRF_NOTIFYITEMDRAW; break; case CDDS_ITEMPREPAINT: // call default procedure in case system might do custom drawing and set special colors if (textColor != null) { nmlvcd.clrText = ColorTranslator.ToWin32(textColor.Value); Marshal.StructureToPtr(nmlvcd, m.LParam, false); m.Result = (IntPtr)(CDRF_NEWFONT | CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYSUBITEMDRAW); } else { m.Result = (IntPtr)(CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYSUBITEMDRAW); } break; case CDDS_ITEMPREPAINT | CDDS_SUBITEM: // before a subitem drawn if ((nmlvcd.nmcd.uItemState & (WindowsAPI.CDIS.HOT | WindowsAPI.CDIS.DROPHILITED)) != 0 || 0 != WindowsAPI.SendMessage(this.SysListviewhandle, WindowsAPI.LVM.GETITEMSTATE, index, (int)WindowsAPI.LVIS.LVIS_SELECTED)) { // hot, drophilited or selected. if (nmlvcd.iSubItem == 0) { // do default to draw hilite bar m.Result = (IntPtr)CDRF_DODEFAULT; } else { // remaining region of a hilted item need to be drawn m.Result = (IntPtr)CDRF_NOTIFYPOSTPAINT; } } else if ((nmlvcd.iSubItem == 0 && nmlvcd.nmcd.uItemState.HasFlag(WindowsAPI.CDIS.FOCUS))) { // if the subitem in selected column, or first item with focus m.Result = (IntPtr)CDRF_NOTIFYPOSTPAINT; } else { if (textColor != null) { nmlvcd.clrText = ColorTranslator.ToWin32(textColor.Value); Marshal.StructureToPtr(nmlvcd, m.LParam, false); m.Result = (IntPtr)CDRF_NEWFONT; } else { m.Result = (IntPtr)CDRF_DODEFAULT; } } break; case CDDS_ITEMPOSTPAINT: //base.WndProc(ref m); if (nmlvcd.clrTextBk != 0) { var iconBounds = new WindowsAPI.RECT(); iconBounds.Left = 1; WindowsAPI.SendMessage(this.SysListviewhandle, WindowsAPI.LVM.GETITEMRECT, index, ref iconBounds); //using (Graphics graphics = Graphics.FromHdc(nmlvcd.nmcd.hdc)) //{ // graphics.Clip = new Region(iconBounds.ToRectangle()); ; // graphics.FillRectangle(Brushes.Black, new Rectangle(iconBounds.left, iconBounds.bottom - 20, 20, 20)); //} if (itemobj.IsShared) { if (this.Browser.ContentOptions.ViewMode == ExplorerBrowserViewMode.Details || this.Browser.ContentOptions.ViewMode == ExplorerBrowserViewMode.List || this.Browser.ContentOptions.ViewMode == ExplorerBrowserViewMode.SmallIcon) { small.DrawOverlay(hdc, 1, new Point(iconBounds.Left, iconBounds.Bottom - 16)); } else { if (this.Browser.ContentOptions.ThumbnailSize > 180) { jumbo.DrawOverlay(hdc, 1, new Point(iconBounds.Left, iconBounds.Bottom - this.Browser.ContentOptions.ThumbnailSize / 3), this.Browser.ContentOptions.ThumbnailSize / 3); } else if (this.Browser.ContentOptions.ThumbnailSize > 64) { extra.DrawOverlay(hdc, 1, new Point(iconBounds.Left + 10, iconBounds.Bottom - 50)); } else { large.DrawOverlay(hdc, 1, new Point(iconBounds.Left + 10, iconBounds.Bottom - 32)); } } } } m.Result = (IntPtr)CDRF_SKIPDEFAULT; break; } if (itemobj != null) { itemobj.Dispose(); } return; } } break; } //base.WndProc(ref m); } //return; // Perform whatever custom processing you must have for this message //System.Diagnostics.Debug.WriteLine(m.ToString()); // forward message to base WndProc base.WndProc(ref m); }