Example #1
0
        public static void SetDropDescription(System.Windows.IDataObject dataObject, DropImageType type, string format, string insert)
        {
            if (format != null && format.Length > 259)
            {
                throw new ArgumentException("Format string exceeds the maximum allowed length of 259.", "format");
            }
            if (insert != null && insert.Length > 259)
            {
                throw new ArgumentException("Insert string exceeds the maximum allowed length of 259.", "insert");
            }
            DropDescription dropDescription;

            dropDescription.type      = type;
            dropDescription.szMessage = format;
            dropDescription.szInsert  = insert;
            SetDropDescription(dataObject, dropDescription);
        }
Example #2
0
        /// <summary>
        /// Sets the drop description for the drag image manager.
        /// </summary>
        /// <param name="dataObject">The DataObject to set.</param>
        /// <param name="type">The type of the drop image.</param>
        /// <param name="format">The format string for the description.</param>
        /// <param name="insert">The parameter for the drop description.</param>
        /// <remarks>
        /// When setting the drop description, the text can be set in two part,
        /// which will be rendered slightly differently to distinguish the description
        /// from the subject. For example, the format can be set as "Move to %1" and
        /// the insert as "Temp". When rendered, the "%1" in format will be replaced
        /// with "Temp", but "Temp" will be rendered slightly different from "Move to ".
        /// </remarks>
        public static void SetDropDescription(this IDataObject dataObject, DropImageType type, string format, string insert)
        {
            if (format != null && format.Length > 259)
            {
                throw new ArgumentException("Format string exceeds the maximum allowed length of 259.", "format");
            }
            if (insert != null && insert.Length > 259)
            {
                throw new ArgumentException("Insert string exceeds the maximum allowed length of 259.", "insert");
            }

            // Fill the structure
            DropDescription dd;

            dd.type      = (int)type;
            dd.szMessage = format;
            dd.szInsert  = insert;

            ComDataObjectExtensions.SetDropDescription((ComIDataObject)dataObject, dd);
        }
Example #3
0
        /// <summary>
        /// Update the displayed drag drop effects
        /// </summary>
        /// <param name="effects">Drag & Drop effect to be applied</param>
        /// <param name="type">DropImageType effect to be used</param>
        /// <param name="format">format to be displayed on the icon</param>
        /// <param name="destination">drop destination name</param>
        public void UpdateEffects(DragDropEffects effects, DropImageType type, string format, string destination)
        {
            Effects = effects;
            if (ComData != null)
            {
                // Size of insert is limited to 259
                if (destination != null && destination.Length > 259)
                {
                    destination = destination.Substring(255) + "...";
                }

                // C# format to C format
                format = format?.Replace("{0}", "%1");

                // All these steps are required to update the Drop-description
                ComDataObject.SetDropDescription(ComData, type, format, destination);
                ComDataObject.InvalidateDragImage(ComData);
                UpdatePosition();                 // force a DDHelper.DragOver call
            }
        }
Example #4
0
        /// <summary>
        /// Sets a drop description.
        /// </summary>
        public static void SetDropDescription(IComDataObject data, DropImageType dragDropEffects, string format, string insert)
        {
            if (format != null && format.Length > 259)
            {
                throw new ArgumentException("Format string exceeds the maximum allowed length of 259.", "format");
            }
            if (insert != null && insert.Length > 259)
            {
                throw new ArgumentException("Insert string exceeds the maximum allowed length of 259.", "insert");
            }

            // Fill the structure
            DropDescription dd;

            dd.type      = dragDropEffects;
            dd.szMessage = format;
            dd.szInsert  = insert;

            data.SetData("DropDescription", dd);
        }
Example #5
0
        public static void SetDescription(IDataObject dataObject, DropImageType type, string message, string insert)
        {
            var formatETC = new FORMATETC
            {
                cfFormat = (short)RegisterClipboardFormat("DropDescription"),
                dwAspect = DVASPECT.DVASPECT_CONTENT,
                lindex   = -1,
                ptd      = IntPtr.Zero,
                tymed    = TYMED.TYMED_HGLOBAL
            };

            var dropDescription = new DROPDESCRIPTION
            {
                type      = (int)type,
                szMessage = message,
                szInsert  = insert,
            };

            var pointer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DROPDESCRIPTION)));

            try
            {
                Marshal.StructureToPtr(dropDescription, pointer, false);

                var medium = new STGMEDIUM
                {
                    pUnkForRelease = null,
                    tymed          = TYMED.TYMED_HGLOBAL,
                    unionmember    = pointer,
                };

                dataObject.SetData(ref formatETC, ref medium, true);
            }
            catch
            {
                Marshal.FreeHGlobal(pointer);
                // throw;
            }
        }
Example #6
0
 public static void SetDropDescription(this System.Windows.IDataObject dataObject, DropImageType type, string format, string insert)
 {
     if (format != null && format.Length > 259)
         throw new ArgumentException("Format string exceeds the maximum allowed length of 259.", "format");
     if (insert != null && insert.Length > 259)
         throw new ArgumentException("Insert string exceeds the maximum allowed length of 259.", "insert");
     DropDescription dropDescription;
     dropDescription.type = type;
     dropDescription.szMessage = format;
     dropDescription.szInsert = insert;
     DataObjectExtensions.SetDropDescription(dataObject, dropDescription);
 }
Example #7
0
        /// <summary>
        /// Sets a drop description.
        /// </summary>
        public static void SetDropDescription(IComDataObject data, DropImageType dragDropEffects, string format, string insert)
        {
            if (format != null && format.Length > 259)
                throw new ArgumentException("Format string exceeds the maximum allowed length of 259.", "format");
            if (insert != null && insert.Length > 259)
                throw new ArgumentException("Insert string exceeds the maximum allowed length of 259.", "insert");

            // Fill the structure
            DropDescription dd;
            dd.type = dragDropEffects;
            dd.szMessage = format;
            dd.szInsert = insert;

            data.SetData("DropDescription", dd);
        }
Example #8
0
        /// <summary>
        /// Sets the drop description for the drag image manager.
        /// </summary>
        /// <param name="dataObject">The DataObject to set.</param>
        /// <param name="type">The type of the drop image.</param>
        /// <param name="format">The format string for the description.</param>
        /// <param name="insert">The parameter for the drop description.</param>
        /// <remarks>
        /// When setting the drop description, the text can be set in two part,
        /// which will be rendered slightly differently to distinguish the description
        /// from the subject. For example, the format can be set as "Move to %1" and
        /// the insert as "Temp". When rendered, the "%1" in format will be replaced
        /// with "Temp", but "Temp" will be rendered slightly different from "Move to ".
        /// </remarks>
        public static void SetDropDescription(this IDataObject dataObject, DropImageType type, string format,
            string insert)
        {
            if (format != null && format.Length > 259)
                throw new ArgumentException("Format string exceeds the maximum allowed length of 259.", "format");
            if (insert != null && insert.Length > 259)
                throw new ArgumentException("Insert string exceeds the maximum allowed length of 259.", "insert");

            // Fill the structure
            DropDescription dd;
            dd.type = (int) type;
            dd.szMessage = format;
            dd.szInsert = insert;

            ComDataObjectExtensions.SetDropDescription((ComIDataObject) dataObject, dd);
        }
Example #9
0
        /// <summary>
        /// Provides a default GiveFeedback event handler for drag sources.
        /// </summary>
        /// <param name="data">The associated data object for the event.</param>
        /// <param name="e">The event arguments.</param>
        public static void DefaultGiveFeedback(IDataObject data, GiveFeedbackEventArgs e)
        {
            // For drop targets that don't set the drop description, we'll
            // set a default one. Drop targets that do set drop descriptions
            // should set an invalid drop description during DragLeave.
            bool          setDefaultDropDesc = false;
            bool          isDefaultDropDesc  = IsDropDescriptionDefault(data);
            DropImageType currentType        = DropImageType.Invalid;

            if (!IsDropDescriptionValid(data) || isDefaultDropDesc)
            {
                currentType        = GetDropImageType(data);
                setDefaultDropDesc = true;
            }

            if (IsShowingLayered(data))
            {
                // The default drag source implementation uses drop descriptions,
                // so we won't use default cursors.
                e.UseDefaultCursors = false;
                Cursor.Current      = Cursors.Arrow;
            }
            else
            {
                e.UseDefaultCursors = true;
            }

            // We need to invalidate the drag image to refresh the drop description.
            // This is tricky to implement correctly, but we try to mimic the Windows
            // Explorer behavior. We internally use a flag to tell us to invalidate
            // the drag image, so if that is set, we'll invalidate. Otherwise, we
            // always invalidate if the drop description was set by the drop target,
            // *or* if the current drop image is not None. So if we set a default
            // drop description to anything but None, we'll always invalidate.
            if (InvalidateRequired(data) || !isDefaultDropDesc || currentType != DropImageType.None)
            {
                InvalidateDragImage(data);

                // The invalidate required flag only lasts for one invalidation
                SetInvalidateRequired(data, false);
            }

            // If the drop description is currently invalid, or if it is a default
            // drop description already, we should check about re-setting it.
            if (setDefaultDropDesc)
            {
                // Only change if the effect changed
                if ((DropImageType)e.Effect != currentType)
                {
                    if (e.Effect == DragDropEffects.Copy)
                    {
                        data.SetDropDescription(DropImageType.Copy, "Copy", "");
                    }
                    else if (e.Effect == DragDropEffects.Link)
                    {
                        data.SetDropDescription(DropImageType.Link, "Link", "");
                    }
                    else if (e.Effect == DragDropEffects.Move)
                    {
                        data.SetDropDescription(DropImageType.Move, "Move", "");
                    }
                    else if (e.Effect == DragDropEffects.None)
                    {
                        data.SetDropDescription(DropImageType.None, null, null);
                    }
                    SetDropDescriptionIsDefault(data, true);

                    // We can't invalidate now, because the drag image manager won't
                    // pick it up... so we set this flag to invalidate on the next
                    // GiveFeedback event.
                    SetInvalidateRequired(data, true);
                }
            }
        }
Example #10
0
 public static void SetDescription(System.Windows.IDataObject dataObject, DropImageType type, string message, string insert = null)
 {
     SetDescription((IDataObject)dataObject, type, message, insert);
 }