TEditHost
Component
implementing IHTMLEditHost
Needs Internet Explorer 5.5 or
greater installed
IHTMLEditHost provides you a way to control how elements are
resized and moved when the user grabs and drags the handles on a control
element. For instance, you could cause an element to resize or move by
specific increments (a snap-to-grid feature), limit resizing to a minimum
or maximum size, or constrain the area to which an element can be moved.
Whenever the MSHTML Editor is activated, it looks to see if an IHTMLEditHost
is available. The Editor first asks the host application for an
IServiceProvider interface. If it finds IServiceProvider, it will
query for an IHTMLEditHost interface pointer.
In EmbeddedWB you can use OnQueryService to connect TEditHost:
function TForm1.EmbeddedWB1QueryService(const rsid, iid: TGUID;
out Obj: IUnknown): HRESULT;
begin
Result := S_OK;
if
IsEqualGUID(rsid, SID_SHTMLEDitHost) and (ActiveDesigner <> nil)
then
obj := EditHost1
else
result := E_NOTIMPL;
end;
|
The IHTMLEditHost interface will remain active until the Editor
is turned off or the WebBrowser navigates to a new page. At this
point, the Editor releases its pointer to any IHTMLEditHost
interface it holds.
TEditHost consists of one method, OnSnapRect. This method
has three arguments:
- pIElement: a pointer to an IHTMLElement interface for the
element that is being moved or resized.
- prcNew: a RECT which initially contains the element's size
and position. Use this RECT to control how MSHTML resizes or moves the
element.
- eHandle: an ELEMENT_CORNER enumeration value. The ELEMENT_CORNER
enumeration value tells you which handle the user has grabbed to
resize the element, if any. If no handle has been grabbed—if eHandle
is set to ELEMENT_CORNER_NONE—the element is being moved rather than
resized.
The following code demonstrates how to process each of the nine ELEMENT_CORNER
values:
function TForm1.EditHost1SnapRect(const pIElement: IHTMLElement;
var prcNew: tagRECT; eHandle: TOleEnum): HRESULT;
begin
case eHandle of
ELEMENT_CORNER_NONE: // Code for moving the element
ELEMENT_CORNER_TOP: // Code for resizing the element
ELEMENT_CORNER_LEFT: // Code for resizing the element
ELEMENT_CORNER_BOTTOM: // Code for resizing the element
ELEMENT_CORNER_RIGHT: // Code for resizing the element
ELEMENT_CORNER_TOPLEFT: // Code for resizing the element
ELEMENT_CORNER_TOPRIGHT: // Code for resizing the element
ELEMENT_CORNER_BOTTOMLEFT: // Code for resizing the element
ELEMENT_CORNER_BOTTOMRIGHT: // Code for resizing the element
end;
result := S_OK;
end;
|
Since IHTMLEditHost can't be "turned off" during the
editing, TEditHost has a propery Enabled that can be turned on and off. If
TEdithost is not Enabled the OnSnapRect Event is not called.
Edithost1.Enabled:=FALSE; |
LINKS:
Implementing IHTMLEditHost
IHTMLEditHost Interface
Using MSHTML Editing
Created and maintained by
Per Lindsø Larsen
Last Update: January 14, 2001
|