HtmlEditor :  Phorum 5 The fastest message board... ever.

This is the discussion forum for the HtmlEditor. See also the HtmlEditor home page, where you can download the control, and the Documentation Wiki, a collaborative project for documenting the control.

Goto Thread: PreviousNext
Goto: Forum ListMessage ListNew TopicSearchLog In
Go to Page: 123Next
Current Page: 1 of 3
how to manipulate the darg and drop of the webbrowser editor!!
Posted by: zhuiqiu111 (211.97.62.---)
Date: Friday, 14-Mar-2003, 09:13:56

i do a html editor ,and i want support the drag and drop . when i drag something out the webbrowser editor , i want get the dorp event .
can anyone help me

Re: how to manipulate the darg and drop of the webbrowser editor!!
Posted by: Kushan Ratnayake (203.115.18.---)
Date: Monday, 17-Mar-2003, 03:21:20

Implement IDropTarget and IDocHostUIHandler interfaces.
Return your IDropTarget implementation in IDocHostUIHandler::GetDropTarget() method.

Re: how to manipulate the darg and drop of the webbrowser editor!!
Posted by: Rob Cowell (---.pearson.com)
Date: Friday, 28-Mar-2003, 15:29:34

I too am looking to be able to drag and drop things into the HTML control. I've seen the method GetDropTarget in the HTMLSite class, and I'm guessing I need to put some implementation in here. I initially added a Debug.Writeline in here just to check when the method is being hit, and it seems to fire way before I get as far as dragging anything into the control, then never fires as I drag stuff over the control, which leads me to believe its not right place.

Can anyone provide a code snippet (smiles hopefully at Tim and James) that gives a basic example of drag-drop to the HTML editor. Something to get me started, so I can build on it, doesn't need to be too complex.

Thanks,

Rob.

Re: how to manipulate the darg and drop of the webbrowser editor!!
Posted by: Tim Anderson (---.server.ntl.com)
Date: Sunday, 30-Mar-2003, 20:06:10

Kushan is correct. GetDropTarget isn't something that gets called when you drop something on the control. It's called by mshtml to ask if you want to implement a custom IDropTarget interface. If GetDropTarget doesn't offer an alternative IDropTarget, then mshtml uses its own implementation.

Another idea would be to try to handle the document's ondragend event. I'm sorry I've not done any experimentation in this area.

Tim

Re: how to manipulate the darg and drop of the webbrowser editor!!
Posted by: Rob Cowell (---.pearson.com)
Date: Monday, 31-Mar-2003, 09:39:26

Monday morning, back at work. Gonna try that OnDragEnd event, thanks for the tip Tim.

Re: how to manipulate the darg and drop of the webbrowser editor!!
Posted by: Kushan Ratnayake (203.115.18.---)
Date: Monday, 31-Mar-2003, 11:35:06

Well if you are going in implementing your own IDropTarget following code will help you.

You will have to handle data in IDataObject and more marshalling stuff smiling smiley.

Kushan
-------------------------------------------------------------------------------------------

public class YourIdochostUIHandler
{
// implement IDocHostUIHandler here, OR
// You can include following code in HTMLSite class
// and return the pointer to this object in GetDropTarget()
public int GetDropTarget(WebIT.Native.Interfaces.IDropTarget pDropTarget, out WebIT.Native.Interfaces.IDropTarget ppDropTarget)
{
//ppDropTarget = null;
//return HRESULT.E_NOTIMPL;
ppDropTarget = (IDropTarget)this;//null;
return HRESULT.S_OK;
}

#region "IDropTarget implementation"

public void DragEnter( IDataObject pDataObj , System.Int32 grfKeyState , System.Int32 ptX , System.Int32 ptY , ref DROPEFFECTS pdwEffect )
{
}

public void DragLeave()
{
}
public void DragOver( System.Int32 grfKeyState , System.Int32 ptX , System.Int32 ptY , ref DROPEFFECTS pdwEffect )
{
}

public void Drop( IDataObject pDataObj , System.Int32 grfKeyState , System.Int32 ptX , System.Int32 ptY , ref DROPEFFECTS pdwEffect )
{
}

#endregion
}

public enum DATADIR
{
DATADIR_GET = 1,

DATADIR_SET = 2,

}
public enum DVASPECT
{
DVASPECT_CONTENT = 1,

DVASPECT_THUMBNAIL = 2,

DVASPECT_ICON = 4,

DVASPECT_DOCPRINT = 8,

DVASPECT_OPAQUE = 16,

DVASPECT_TRANSPARENT = 32,

}
public enum TYMED
{
TYMED_HGLOBAL = 1,

TYMED_FILE = 2,

TYMED_ISTREAM = 4,

TYMED_ISTORAGE = 8,

TYMED_GDI = 16,

TYMED_MFPICT = 32,

TYMED_ENHMF = 64,

TYMED_NULL = 0,

}

[StructLayoutAttribute(LayoutKind.Sequential, Pack=4, Size=0)]
public struct STGMEDIUM
{
public TYMED TYMED;

public int data;

public int pUnkForRelease;

}

[StructLayoutAttribute(LayoutKind.Sequential, Pack=4, Size=0)]
public struct FORMATETC
{
public short cfFormat;

public int pDVTARGETDEVICE;

public DVASPECT dwAspect;

public int lindex;

public TYMED TYMED;

}


public enum OLECONTF
{
OLECONTF_EMBEDDINGS = 1,
OLECONTF_LINKS = 2,
OLECONTF_OTHERS = 4,
OLECONTF_ONLYUSER = 8,
OLECONTF_ONLYIFRUNNING = 16,
}


public enum DROPEFFECTS
{
DROPEFFECT_NONE = 0,

DROPEFFECT_COPY = 1,

DROPEFFECT_MOVE = 2,

DROPEFFECT_LINK = 4,

DROPEFFECT_SCROLL = int.MinValue,

}


[InterfaceTypeAttribute(1)]
[GuidAttribute("0000010E-0000-0000-C000-000000000046")]
[ComImportAttribute()]
public interface IDataObject
{

int GetData(ref FORMATETC pformatetcIn, ref STGMEDIUM pmedium);

void GetDataHere(ref FORMATETC pformatetc, ref STGMEDIUM pmedium);

int QueryGetData(ref FORMATETC pformatetc);

void GetCanonicalFormatEtc(ref FORMATETC pformatectIn, ref FORMATETC pformatetcOut);

void SetData(ref FORMATETC pformatetc, ref STGMEDIUM pmedium, [ComAliasNameAttribute("olelib.BOOL")] int fRelease);

[return: MarshalAs(UnmanagedType.Interface)]
IEnumFORMATETC EnumFormatEtc(DATADIR dwDirection);

void DAdvise(ref FORMATETC pformatetc, int ADVF, int pAdvSink, ref int pdwConnection);

void DUnadvise(int dwConnection);

void EnumDAdvise(ref int pIEnumAdvise);
}


[GuidAttribute("00000122-0000-0000-C000-000000000046")]
[InterfaceTypeAttribute(1)]
[ComImportAttribute()]
public interface IDropTarget
{

void DragEnter([MarshalAs(UnmanagedType.Interface)] IDataObject pDataObj, int grfKeyState, int ptX, int ptY, ref DROPEFFECTS pdwEffect);

void DragOver(int grfKeyState, int ptX, int ptY, ref DROPEFFECTS pdwEffect);

void DragLeave();

void Drop([MarshalAs(UnmanagedType.Interface)] IDataObject pDataObj, int grfKeyState, int ptX, int ptY, ref DROPEFFECTS pdwEffect);
}

Re: how to manipulate the darg and drop of the webbrowser editor!!
Posted by: Rob Cowell (---.pearson.com)
Date: Monday, 31-Mar-2003, 13:13:41

Thanks Kushan, will give it a try. While my C#.Net isn't too bad, my COM knowledge is really lacking, so your contribution is a great help.

Rob.

Re: how to manipulate the darg and drop of the webbrowser editor!!
Posted by: Rob Cowell (---.pearson.com)
Date: Wednesday, 02-Apr-2003, 13:22:21

Still not quite sure how to implement this one.

I added the COM Interface for IDropTarget as shown in the example above, and added IDropTarget to the list of interfaces that HTMLSite implements (including simple Debug.Writeline stuff for the implementation so I can see when events get triggered).

All I am seeing when I try to drag stuff onto the HTML Editor now is System.ExecutionEngineException.

If someone is feeling very benevolent and can throw together a little sample app that perhaps throws up a message box saying "Drop event fired!" or something, I will make them Supreme Overlord of all things COM, Dictator for Life, and one other title of their choosing.... :-)

Rob.

Re: how to manipulate the darg and drop of the webbrowser editor!!
Posted by: Kushan Ratnayake (203.115.18.---)
Date: Thursday, 03-Apr-2003, 04:23:49

Well make sure u have the correct IDocHostUIHandler definition.

it should be :


[return: MarshalAs(UnmanagedType.I4)][PreserveSig]
int GetDropTarget([In, MarshalAs(UnmanagedType.Interface)] IDropTarget
pDropTarget, [Out, MarshalAs(UnmanagedType.Interface)] out IDropTarget
ppDropTarget);


also verify IDataObject used here is not the System.Windows.Forms.IDataObject (we have defined it).

I assume u have defined HTMLSite as implementing IDropTarget.

Kushan

Re: how to manipulate the darg and drop of the webbrowser editor!!
Posted by: Rob Cowell (---.pearson.com)
Date: Thursday, 03-Apr-2003, 10:43:58

Kushan,

Thanks for the further feedback. :-)

My GetDropTarget definition had Object as in and out parameters instead of IDropTarget, so I changed those. You also correctly guessed that my IDataObject was the System.Windows.Forms one.

However, on trying to add the IDataObject shown in your example above, it was unable to find the IEnumFORMATETC interface - do you have a C# version of this interface at all?

Thanks,

Rob.

Re: how to manipulate the darg and drop of the webbrowser editor!!
Posted by: Rob Cowell (---.pearson.com)
Date: Thursday, 03-Apr-2003, 10:45:12

Ok, don't worry, I found an example :-


[
ComImport(),
Guid("00000103-0000-0000-C000-000000000046"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)
]
interface IEnumFORMATETC
{
[PreserveSig()]
uint Next(uint celt,
[In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex=0)]
FORMATETC[] rgelt,
out uint pceltFetched);
void Skip(uint celt);
void Reset();
IEnumFORMATETC Clone();
}

Re: how to manipulate the darg and drop of the webbrowser editor!!
Posted by: Rob Cowell (---.pearson.com)
Date: Friday, 04-Apr-2003, 11:30:38

Making some great progress now, thanks to Kushan's patience with my questions :-) Managed to get HTMLSite to respond to DragEnter and DragLeave events now, still working on DragOver and Drop.

Am I right in thinking that if I want to drag a custom object (ie, an object not of a base type) to the control, then it needs to be of a type that implements IDataObject? If so, I got a whole bunch of methods to be working on....DAdvise, DUnadvise, and more.

Rob.

Re: how to manipulate the darg and drop of the webbrowser editor!!
Posted by: Rob Cowell (---.pearson.com)
Date: Friday, 04-Apr-2003, 13:03:41

Test post, ignore me smiling smiley



------------------------------------------------------------------------
C# coder with nothing better to do? Try helping out with
DeVolution! [projects.sourecforge.net]

Re: how to manipulate the darg and drop of the webbrowser editor!!
Posted by: Rob Cowell (---.pearson.com)
Date: Monday, 07-Apr-2003, 11:31:08

Another question for anyone thats feeling benevolent this morning :-)

In order to implement dragdrop on the HTML Control, does my item that I wish to drag need to implement IDropSource as well as IDataObject ?

Rob



------------------------------------------------------------------------
C# coder with nothing better to do? Try helping out with
DeVolution! [projects.sourecforge.net]

Re: how to manipulate the darg and drop of the webbrowser editor!!
Posted by: Rob Cowell (---.pearson.com)
Date: Thursday, 10-Apr-2003, 09:52:04

Ok, I found the answer - seems like I do need IDropSource...

Anyone else working on the drag and drop problem here? Might be useful to compare notes...

Rob.



------------------------------------------------------------------------
C# coder with nothing better to do? Try helping out with
DeVolution! [projects.sourecforge.net]

Re: how to manipulate the darg and drop of the webbrowser editor!!
Posted by: kannan chandrasekaran (203.124.157.---)
Date: Monday, 29-Nov-2004, 06:47:30

hi Rob Cowell

i just used ur "IEnumFORMATETC" interface but it is giving some bug like the following

"Inconsistent accessibility: return type 'onlyconnect.IEnumFORMATETC' is less accessible than method 'onlyconnect.IDataObject.EnumFormatEtc(onlyconnect.DATADIR)' ".

can u give me some idea.

thanks
kannan.chandrasekaran

Re: how to manipulate the darg and drop of the webbrowser editor!!
Posted by: Tim (---.gotadsl.co.uk)
Date: Monday, 29-Nov-2004, 07:33:04

The accessibility issue is because in the code Rob posted the interfaces are not declared public, whereas others you are using it with are. Add public to all the interfaces and it will work.

Tim

Re: how to manipulate the darg and drop of the webbrowser editor!!
Posted by: kannan chandrasekaran (203.124.157.---)
Date: Monday, 29-Nov-2004, 07:57:09

Hi Tim.

i just fixed that one and it is working fine for me. also the drag and drop is restricted from out side. but if i drag it from instide it get strucked. the selected text is still selected even i deselect that. Even i typed some thing then looks like selected.

do u have any idea regarding this?

thanks
kannan.c

Re: how to manipulate the darg and drop of the webbrowser editor!!
Posted by: kannan chandrasekaran (203.124.157.---)
Date: Monday, 29-Nov-2004, 09:32:08

Hi

is there any way to restrict the drag and drop inside the mshtml?

thanks
kannan.c

Re: how to manipulate the darg and drop of the webbrowser editor!!
Posted by: Tomcat (80.231.145.---)
Date: Tuesday, 30-Nov-2004, 11:12:53

my this will help you , this my implementation of IDropTarget
#region "IDropTarget Definition"

[System.Runtime.InteropServices.ComImport()]
[System.Runtime.InteropServices.InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
[System.Runtime.InteropServices.GuidAttribute("00000122-0000-0000-C000-000000000046")]
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
public interface IOleDropTarget

{
#region Methods
[System.Runtime.InteropServices.PreserveSig()] int OleDragEnter (IntPtr pDataObj, [System.Runtime.InteropServices.MarshalAs(UnmanagedType.U4)] int grfKeyState, [System.Runtime.InteropServices.MarshalAs(UnmanagedType.U8)] long pt, ref int pdwEffect);
[System.Runtime.InteropServices.PreserveSig()] int OleDragOver (int grfKeyState, [System.Runtime.InteropServices.MarshalAs(UnmanagedType.Struct)] mshtml.tagPOINT pt, ref int pdwEffect);
[System.Runtime.InteropServices.PreserveSig()] int OleDragLeave ();
[System.Runtime.InteropServices.PreserveSig()] int OleDrop (IntPtr pDataObj, [System.Runtime.InteropServices.MarshalAs(UnmanagedType.U4)] int grfKeyState, [System.Runtime.InteropServices.MarshalAs(UnmanagedType.Struct)] mshtml.tagPOINT pt, ref int pdwEffect);
#endregion
}



#region IDocHostUIHandler Implementation

public int GetDropTarget( ComInterop.IOleDropTarget pDropTarget,out ComInterop.IOleDropTarget ppDropTarget)
{
HtmlEditor theHtmlEditor;
DragLoadConverter theDataObjectConverter;
if (this._dropTarget == null)
{
theHtmlEditor = (this._parent as HtmlEditor);
if (theHtmlEditor != null)
{
theDataObjectConverter = theHtmlEditor.DataObjectConverter;
if (theDataObjectConverter != null)
{
this._dropTarget = new DropTarget(theHtmlEditor,theDataObjectConverter, pDropTarget);
}
}
}

ppDropTarget = ((ComInterop.IOleDropTarget) this._dropTarget);
if (this._dropTarget == null)
{
return ComInterop.HRESULT.S_FALSE;
}

return ComInterop.HRESULT.S_OK;
}


#region "IDropTarget Implementation"
private sealed class DropTarget : BPMDesigner.Interop.ComInterop.IOleDropTarget

{
#region Fields
private DragLoadConverter _converter;
private DragLoadInfo _converterInfo;
private DataObject _currentDataObj;
private IntPtr _currentDataObjPtr;
private ComInterop.IOleDropTarget _originalDropTarget;
private BaseEditor _owner;

#endregion

#region Constructors

public DropTarget (BaseEditor owner, DragLoadConverter converter, ComInterop.IOleDropTarget originalDropTarget)

{
this._owner = owner;
this._converter = converter;
this._originalDropTarget = originalDropTarget;
}

#endregion

#region Methods

public int OleDragEnter (IntPtr pDataObj, int grfKeyState, long pt, ref int pdwEffect)
{
object theObject;
DataObject theDataObject;
IntPtr theIntPtr;
Guid theGuid;
theObject = Marshal.GetObjectForIUnknown (pDataObj);
theDataObject = new DataObject (theObject);
this._converterInfo = this._converter.CanConvertToHtml (theDataObject);

if (this._converterInfo == DragLoadInfo.CanConvert)
{
this._currentDataObj = new DataObject (DataFormats.Html, string.Empty);
theIntPtr = Marshal.GetIUnknownForObject (this._currentDataObj);
theGuid = new Guid ("0000010E-0000-0000-C000-000000000046");
Marshal.QueryInterface (theIntPtr, ref theGuid, out this._currentDataObjPtr);
Marshal.Release (theIntPtr);

return this._originalDropTarget.OleDragEnter (this._currentDataObjPtr, grfKeyState, pt, ref pdwEffect);
}
if (this._converterInfo == DragLoadInfo.Disabled)
{
pdwEffect = 0;
return 0;
}
if (this._converterInfo != DragLoadInfo.Unhandled)
{
return 0;
}

return this._originalDropTarget.OleDragEnter (pDataObj, grfKeyState, pt, ref pdwEffect);
}


public int OleDragLeave ()

{
this._converterInfo = DragLoadInfo.Disabled;
if (this._currentDataObj == null)
{
return 0;
}

this._currentDataObj = ((DataObject) null);
Marshal.Release (this._currentDataObjPtr);
this._currentDataObjPtr = IntPtr.Zero;
return this._originalDropTarget.OleDragLeave ();

}

public int OleDragOver (int grfKeyState, mshtml.tagPOINT pt, ref int pdwEffect)
{
if (this._converterInfo != DragLoadInfo.Disabled)
return this._originalDropTarget.OleDragOver(grfKeyState, pt,ref pdwEffect);

return 0;
}

public int OleDrop (IntPtr pDataObj, int grfKeyState, mshtml.tagPOINT pt, ref int pdwEffect)
{
int hr;
Control host;
Form parent;
object theObject;
DataObject theDataObject;
bool flag;
IntPtr pUnk;
Guid sid;

theObject = Marshal.GetObjectForIUnknown(pDataObj);
theDataObject = new DataObject(theObject);
hr = 0;
host = this._owner;
while (host != null)
{
try
{
parent =(Form) host.Parent;

if (parent == null)
continue;
parent.BringToFront();
break;
}
catch(Exception)
{
break;
}

}
if (this._converterInfo == DragLoadInfo.CanConvert )
{
theObject = Marshal.GetObjectForIUnknown(pDataObj);
theDataObject = new DataObject(theObject);

flag = this._converter.ConvertToHtml(theDataObject, this._currentDataObj ,point);

if (flag)
{
pUnk = Marshal.GetIUnknownForObject(this._currentDataObj);
sid = new Guid("0000010E-0000-0000-C000-000000000046");
Marshal.QueryInterface(pUnk, ref sid, out this._currentDataObjPtr);

hr = this._originalDropTarget.OleDrop( this._currentDataObjPtr, grfKeyState, pt, ref pdwEffect);

Marshal.Release(this._currentDataObjPtr);
this._currentDataObj = null;
this._currentDataObjPtr = IntPtr.Zero;
}
}
else if (this._converterInfo == DragLoadInfo.Unhandled)
hr = this._originalDropTarget.OleDrop(pDataObj, grfKeyState, pt,ref pdwEffect);

return hr;
}

#endregion
}

#endregion


public class DragLoadConverter

{


#region Constructors

public DragLoadConverter ()
{

}

#endregion

#region Methods

public virtual DragLoadInfo CanConvertToHtml (DataObject dataObject)
{

//Check that the draged data is of desired format and return DragLoadInfo.CanConvert
foreach (string format in dataObject.GetFormats())
{
if(format == typeof(//DesiredType Like ToolboxItem).ToString())
{
return DragLoadInfo.CanConvert;
}
}
return DragLoadInfo.Unhandled;
}


public virtual bool ConvertToHtml (DataObject originalDataObject, DataObject newDataObject,System.Drawing.Point pt)
{



foreach (string format in originalDataObject.GetFormats())
{
if(format == typeof(//DesiredType Like ToolboxItem).ToString())
{
found = true;
break;
}
}

if(!found) return false;


//convert the droped type into its Html representation and set the data
newDataObject.SetData(DataFormats.Html ,"<B> Something is Dropped");
return true;
}

#endregion
}



[System.Serializable()]
public enum DragLoadInfo

{
Disabled = 0,
CanConvert = 1,
Unhandled = 2,
}


add this public property to HtmlEditor Control

public DragLoadConverter DataObjectConverter
{
get
{
return this._dataObjectConverter;
}
set
{
this._dataObjectConverter = value;
}
}


private DragLoadConverter _dataObjectConverter;

and in the appropriate constructor create an instance of DragLoadConverter
this._dataObjectConverter = new DragLoadConverter();

Go to Page: 123Next
Current Page: 1 of 3


Your Name: 
Your Email: 
Subject: 
Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically.
vuMPu
This is a moderated forum. Your message will remain hidden until it has been approved by a moderator or administrator
This forum powered by Phorum.