This is a version of the htmleditor that does not use the (large) primary interop dll.
If you want to use mshtml you still can, just cast the Document property or other objects to the mshtml versions.
This is for .NET 2.0.
History
12 June
Bugfixes, updated example app for toolstrip. Another go at unicode.
29 May 2006
Created Subversion repository at:
http://itwriting.com/repos/htmleditor/trunk
Added AcceptReturn and AcceptTab properties
26 May 2006
Fixed bug in GetHostInfo which was disabling internal context menu.
Added iMarkup.cs for IMarkup definitions.
23 May 2006
Fixed bug where mouse activation set focus to the editor but did not select it.
Added properties IsDivOnEnter, IsScrollBarShown, IsUrlDetectionEnabled.
Fixed bug where backspace deletes 2 characters and arrow keys move focus from control.
21 May 2006
Fixed some bugs and regressions. Amended keyboard handling so that Mshtml gets to handle WM_KEYDOWN; use TranslateAccelerator to customize this. You can also still use BeforeShortcut and BeforePaste.
Added IsTabToNextControl property. This is only effective in design mode. If set (the default) then pressing tab when the editor has focus will shift focus to the next control in the tab order. If false, then the focus will stay within the editor and the tab will be handled by Mshtml.
19 May 2005
Changed events implementation so that htmlsite now implements HTMLDocumentEvents2. Write code for the implementation to further customize behavior.
Re-org to slim down comsupport.cs and put interop definitions in a separate folder.
Fixed focus issue where control received focus but you couldn't type into MSHTML.
05 October 2003
Tidied up control, renamed public properties and methods so all start with upper case, added DefaultComposeSettings property so you can easily set the default font at design time.
04 October 2003
Many changes and improvements, incorporating new ideas along with most of the changes found in Jamie Hancock's "alternate" code.
01 October 2003
Amended document activation to use a timer if the control is not visible. This solves focus issues in certain scenarios, such as when the control is on an MDI child form.
10 May 2003
Added property isActiveContentEnabled. This is True by default. Set it False to disable scripts,
Java, ActiveX etc. If you would like a more fine-grained approach, see the setFlags method in
HtmlSite.cs.
I've also amended the utils class so that a mimimal inplementation of IOleClientSite turns off
scripts etc automatically. This is Microsoft's recommendation when using mshtml without a GUI
(as in the walkall sample).
2 May 20003
Slightly tweaked build, since there were circumstances in which the cleanup didn't get called.
22 April 2003
Fixed memory leak caused by setting up HtmlEvent handler. The fix is to release the IDispatch COM
references.
Restored LoadUrl to utils class.
NOTE: Project is now for .NET 1.1. It should be OK in VS.Net 2002 if you manually fix the project
file.
15 April 2003
Corrected interface definitions for IDocHostShowUI to cure exception thrown when ShowMessage is
called.
4 April 2003
Juggled with Encoding issues. New code:
- Strings are loaded with a Unicode stream on Win NT/2K/XP, and an Ansi stream on Win98
- Strings are decoded with the Windows current Encoding by default.
- On decoding, an attempt is made to detect if the string is Unicode. If it is Unicode, and the
default encoding would otherwise be used, then the encoding is forced to Unicode.
19 March 2003
Amended GetDocumentSource to use only one routine (in utils) rather than duplicating code.
Changed the default encoding to Windows; normally this means you get the extended
characters you expect. However you can also specify other encodings.
Implemented OnKeyDown event by subclassing the mshtml document's WndProc.
For some reason it doesn't get the Alt key, but it gets Ctrl and arrow
keys OK. I don't think there are any adverse side effects but let me know...
28 February 2003
Major reorganization, breaking down HtmlEditor.cs into several classes and
moving all the COM definitions and declarations into COMSupport.
Compared the code to Microsoft's Framer sample and added some stuff from there;
much of this doesn't appear to be needed for mshtml but might help a lot if
you wanted to adapt to work with other Active Documents.
Worked on dispose to try to get this as clean as possible. I don't think it's
quite there yet and would welcome suggestions.
26 February 2003
Fixed several bugs.
Changed mshtml init to occur OnParentChanged instead of OnHandleCreated
24 February 2003
Added WndProc override to detect WM_MOUSEACTIVATE. If detected, the control
checks to see where the focus came from, and if it was neither the control
container nor the document, it sends a WM_SETFOCUS message to the control.
The purpose of this is to support the .Net Leave/Validating system. If it
causes problems, simply remove the WndProc method from htmleditor.cs.
19 February 2003
Added fix for control grabbing focus (thanks Steven Wood)
Added implementation of IHTMLEditHost.
Changed isContextMenuEnabled property to IsContextMenuEnabled
Added control over the encoding used for reading the document source. Default
is UTF7Encoding. Set this in the DocumentEncoding property. Note it does not
make any difference to how content is loaded into the control.
Fixed incorrect memory allocation for reading size of document
27 December 2002
Added LoadUrl to Utils class for non-visual loading of an URL into the Mshtml DOM.
24 December 2002
Modified to enable easy setting of a ContextMenu.
Use the isContextMenuEnabled property to enable/disable context menu support.
Use the standard ContextMenu property to assign your own context menu.
If no Context Menu is assigned, and isContextMenuEnabled is set True, then
the IE default context menu will be used.
5 Dec 2002
Modified to add HTML event handling (thanks to Steven Wood).
Currently fires HTMLEvent onclick, onkeypress, onfocusin, onfocusout
see the source to modify
27 Nov 2002
Modifed to change declaration of ShowContextMenu. This now
fires correctly, and you can disable the built-in menu by
returning S_OK.
18 Nov 2002
Modified to fire HtmlKeyPress on all keystrokes in Design
mode.
Modified to inherit from Control instead of Panel.
Getting started
This download is aimed at users of Visual Studio .Net.
You can load the HtmlEditor.sln into VS.Net and try out
the demo app.
If you don't have VS.Net, you will find the demo exe and
DLL in the directory DemoHTmlApp\bin\Release. However,
note the following:
*The library requires the Microsoft.Mshtml.dll Primary
Interop Assembly*
If nothing works, the chances are you can't resolve the
reference to Microsoft.Mshtml.dll. In Visual Studio, you
should be able to sort this by Add Reference. If you have
difficulty, you should find the dll in
Program Files\Microsoft.Net\Primary Interop Assemblies.
If you don't have VS.Net, you'll still need this DLL. I've
not put it up for download because I'm worried about the
bandwidth (its 7MB). Can anyone help?
Warning
If you look at the SetDocEvents method in HtmlEditor.cs,
you'll see that it includes unreachable code. This is
because the control has a workaround. The unreachable code
shows the "correct" way to receive document events. However,
if you run it the control doesn't work; it can't accept
keyboard input. So I've used a workaround based on
SetPropertyNotifyEvent to get the most important events,
like ReadyStatechanged. I think this is a bug either in
mshtml or in the .Net Framework COM interop. It's been
reported, maybe it will start working sometime. In the
meantime, don't hook up document events this way, or if
you do, test it carefully.
Tim
tim@itwriting.com
http://www.itwriting.com/htmleditor/
November 2002