Example #1
0
		void DelayTimer_Tick(object sender, EventArgs e) {
			_DelayTimer.Stop();

			var t = new Thread(() => {
				var clonedCurrentItem = this.CurrentItem.Clone();
				var tooltip = clonedCurrentItem.ToolTipText;
				if (String.IsNullOrEmpty(tooltip) && Type == 1) {
					Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (ThreadStart)(this.Hide));
					return;
				}
				Contents = Type == 0 ? $"{clonedCurrentItem.DisplayName}\r\n{clonedCurrentItem.ToolTipText}" : clonedCurrentItem.ToolTipText;
				RaisePropertyChanged("Contents");

				// BE-557: clonedCurrentItem.GetPropertyValue returned VT_EMPTY, edge case included to handle this
				var perceivedTypeProperty = clonedCurrentItem.GetPropertyValue(
					SystemProperties.PerceivedType,
					typeof(PerceivedType));
				if (perceivedTypeProperty.VarType != VarEnum.VT_EMPTY
					&& ((PerceivedType)perceivedTypeProperty.Value) == PerceivedType.Image && !clonedCurrentItem.IsFolder)
				{
					var image = clonedCurrentItem.ThumbnailSource(
						350,
						ShellThumbnailFormatOption.Default,
						ShellThumbnailRetrievalOption.Default);
					image.Freeze();
					this.Image = image;
					RaisePropertyChanged("Image");
					this.FileNameWidth = this.Image.Width - 110;
					RaisePropertyChanged("FileNameWidth");

					try
					{
						var ratingValue = clonedCurrentItem.GetPropertyValue(MediaProperties.Rating, typeof(Double)).Value;
						var rating = ratingValue == null ? 0 : Convert.ToDouble(ratingValue) / 20D;
						this.Rating = rating;
						RaisePropertyChanged("Rating");
						this.Dimentions =
							((Math.Ceiling(
									Convert.ToDouble(clonedCurrentItem.GetPropertyValue(SystemProperties.FileSize, typeof(double)).Value))
								/ 1024).ToString("# ### ### ##0") + " KB ("
								+ clonedCurrentItem.GetPropertyValue(MediaProperties.Dimensions, typeof(String)).Value.ToString()
								+ " px )").Trim();
						RaisePropertyChanged("Dimentions");
					}
					catch (NullReferenceException)
					{
					}
					this.FileName = Path.GetFileName(clonedCurrentItem.ParsingName)?.Trim();
					RaisePropertyChanged("FileName");
				}
				else
				{
					var image = clonedCurrentItem.ThumbnailSource(
						64,
						ShellThumbnailFormatOption.Default,
						ShellThumbnailRetrievalOption.Default);
					image.Freeze();
					this.Image = image;
					RaisePropertyChanged("Image");
				}


				Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (ThreadStart)(() => {
					var lvi = new LVITEMINDEX();
					lvi.iItem = this.ItemIndex;
					lvi.iGroup = this._View.GetGroupIndex(this.ItemIndex);
					var bounds = new User32.RECT();
					User32.SendMessage(this._View.LVHandle, MSG.LVM_GETITEMINDEXRECT, ref lvi, ref bounds);
					var rect = new System.Drawing.Rectangle(bounds.Left, bounds.Top, bounds.Right - bounds.Left, bounds.Bottom - bounds.Top);
					var posm = User32.GetCursorPosition();
					var mousePos = this._View.PointToClient(posm);
					var isInsideItem = rect.Contains(mousePos);

					if (isInsideItem)
						this.Show();
					else
						this.Hide();

				}));
			});
			t.SetApartmentState(ApartmentState.STA);
			t.Start();
		}
Example #2
0
        public HResult ExtractAndDrawThumbnail(IntPtr hdc, uint iconSize, out WTS_CACHEFLAGS flags, User32.RECT iconBounds, out bool retrieved, bool isHidden, bool isRefresh = false)
        {
            HResult       res = HResult.S_OK;
            ISharedBitmap bmp = null;

            flags = WTS_CACHEFLAGS.WTS_DEFAULT;
            WTS_THUMBNAILID thumbId = new WTS_THUMBNAILID();

            try
            {
                retrieved = false;
                res       = ThumbnailCache.GetThumbnail(this._Item.ComInterface, iconSize, isRefresh ? (WTS_FLAGS.WTS_FORCEEXTRACTION | WTS_FLAGS.WTS_SCALETOREQUESTEDSIZE) : (WTS_FLAGS.WTS_INCACHEONLY | WTS_FLAGS.WTS_SCALETOREQUESTEDSIZE), out bmp, flags, thumbId);
                IntPtr hBitmap = IntPtr.Zero;
                if (bmp != null)
                {
                    bmp.GetSharedBitmap(out hBitmap);
                    retrieved = true;

                    int width;
                    int height;
                    Gdi32.ConvertPixelByPixel(hBitmap, out width, out height);
                    Gdi32.NativeDraw(hdc, hBitmap, iconBounds.Left + (iconBounds.Right - iconBounds.Left - width) / 2, iconBounds.Top + (iconBounds.Bottom - iconBounds.Top - height) / 2, width, height, isHidden);
                    Gdi32.DeleteObject(hBitmap);
                }
            }
            finally
            {
                if (bmp != null)
                {
                    Marshal.ReleaseComObject(bmp);
                }
            }
            return(res);
        }
Example #3
0
    private void Column_OnClick(Int32 iItem) {
      var rect = new User32.RECT();
      IntPtr headerhandle = User32.SendMessage(this.LVHandle, MSG.LVM_GETHEADER, 0, 0);

      if (User32.SendMessage(headerhandle, MSG.HDM_GETITEMDROPDOWNRECT, iItem, ref rect) == 0) throw new Win32Exception();
      var pt = this.PointToScreen(new DPoint(rect.Left, rect.Bottom));
      this.OnListViewColumnDropDownClicked?.Invoke(this.Collumns[iItem], new ListViewColumnDropDownArgs(iItem, pt));
    }
Example #4
0
    private void ProcessCustomDrawPostPaint(ref Message m, User32.NMLVCUSTOMDRAW nmlvcd, Int32 index, IntPtr hdc, IListItemEx sho, Color? textColor) {
      if (nmlvcd.clrTextBk != 0 && nmlvcd.dwItemType == 0 && this._CurrentDrawIndex == -1) {
        //var perceivedType = (PerceivedType)sho.GetPropertyValue(SystemProperties.PerceivedType, typeof(PerceivedType)).Value;
        this._CurrentDrawIndex = index;
        var itemBounds = nmlvcd.nmcd.rc;
        var lvi = new LVITEMINDEX();
        lvi.iItem = index;
        lvi.iGroup = this.GetGroupIndex(index);
        var iconBounds = new User32.RECT() { Left = 1 };
        User32.SendMessage(this.LVHandle, MSG.LVM_GETITEMINDEXRECT, ref lvi, ref iconBounds);
        var lvItem = new LVITEM() {
          iItem = index,
          iGroupId = lvi.iGroup,
          iGroup = lvi.iGroup,
          mask = LVIF.LVIF_STATE,
          stateMask = LVIS.LVIS_SELECTED
        };
        var lvItemImageMask = new LVITEM() {
          iItem = index,
          iGroupId = lvi.iGroup,
          iGroup = lvi.iGroup,
          mask = LVIF.LVIF_STATE,
          stateMask = LVIS.LVIS_STATEIMAGEMASK
        };

        if (sho != null) {
          var cutFlag = (User32.SendMessage(this.LVHandle, MSG.LVM_GETITEMSTATE, index, LVIS.LVIS_CUT) & LVIS.LVIS_CUT) ==
                                                                  LVIS.LVIS_CUT;
          if (this.IconSize == 16) {
            this.SmallImageList.DrawIcon(hdc, index, sho, iconBounds,
                    sho.IsHidden || cutFlag || this._CuttedIndexes.Contains(index), (nmlvcd.nmcd.uItemState & CDIS.HOT) == CDIS.HOT);
          } else {
            this.LargeImageList.DrawIcon(hdc, index, sho, iconBounds,
                    sho.IsHidden || cutFlag || this._CuttedIndexes.Contains(index), (nmlvcd.nmcd.uItemState & CDIS.HOT) == CDIS.HOT);
          }

          if (!sho.IsInitialised) sho.IsInitialised = true;
        }
        m.Result = (IntPtr)CustomDraw.CDRF_SKIPDEFAULT;
      } else {
        m.Result = IntPtr.Zero;
      }

      this._CurrentDrawIndex = -1;
    }
Example #5
0
    public void RedrawItem(Int32 index, Int32 delay = -1) {
      if (delay > -1) {
        Thread.Sleep(delay);
      }
      var itemBounds = new User32.RECT() { Left = 1 };
      var lvi = new LVITEMINDEX() { iItem = index, iGroup = this.GetGroupIndex(index) };
      User32.SendMessage(this.LVHandle, MSG.LVM_GETITEMINDEXRECT, ref lvi, ref itemBounds);
      itemBounds.Left -= 2;
      itemBounds.Top -= 2;
      itemBounds.Bottom += 2;
      itemBounds.Right += 2;
      this.Invoke(new MethodInvoker(() => this._IIListView.RedrawItems(index, index)));

      //TODO: Find out why we have this loop
      for (Int32 i = 0; i < 1; i++) {
        if (IsGroupsEnabled) RedrawWindow(itemBounds);
      }
    }
Example #6
0
    private async void RetrieveThumbnailByIndex(Int32 index) {
      await Task.Run(() => {
        if (this.IsCancelRequested) return;

        //F.Application.DoEvents();
        var itemBounds = new User32.RECT();
        var lvi = new LVITEMINDEX() { iItem = index, iGroup = this.GetGroupIndex(index) };
        User32.SendMessage(this.LVHandle, MSG.LVM_GETITEMINDEXRECT, ref lvi, ref itemBounds);

        var r = new Rectangle(itemBounds.Left, itemBounds.Top, itemBounds.Right - itemBounds.Left, itemBounds.Bottom - itemBounds.Top);

        if (r.IntersectsWith(this.ClientRectangle)) {
          var sho = Items[index];
          var icon = sho.GetHBitmap(IconSize, true, true);
          sho.IsThumbnailLoaded = true;
          sho.IsNeedRefreshing = false;
          if (icon != IntPtr.Zero) {
            Int32 width = 0, height = 0;
            Gdi32.ConvertPixelByPixel(icon, out width, out height);
            sho.IsOnlyLowQuality = (width > height && width != IconSize) || (width < height && height != IconSize) || (width == height && width != IconSize);
            Gdi32.DeleteObject(icon);
            this.RedrawItem(index);
          }
        }
      });
    }