{ EmbeddedED ver 1.21 (Jan. 19, 2004) } { } { For Delphi 4, 5, 6 and 7 } { } { Copyright (C) 1999-2004, Kurt Senfer. } { All Rights Reserved. } { } { Support@ks.helpware.net } { } { Documentation and updated versions: } { } { http://KS.helpware.net } { } { ********************************************* } { This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA This unit forms the basic core of a MSHTML Edit component witch can be used as the starting point for a full blown WYSIWYG HTML Editor. Don't change this unit, but subclass it in order to build your own advanced HTML Editor on top of it. If you change the unit you'll run into unnecessary troubles when official updates of this unit is released. If you build a subclassed editor you can benefit from new versions of the EmbeddedED unit without the need of changing your own code. If you find bugs or have ideas / wishes for new features that either should be incorporated into the EmbeddedED unit or cant be placed in a subclassed unit, then please let me know and I'll try to keep EmbeddedED updated at any time. ---------------------------------------------------------------------- Once I tried to get an HTML editor written as OSP. When it didn't succeeded I tried to get different groups of people to share the workload of writing a good HTML editor around the MSHTML engine - no succeed either. Then I finally had to do everything myself and finally I decided only to make parts of my source public. If you ever need to do more than the basic editing that the EmbeddedED unit will give you, you need to write some code yourself, or you might chose to acquire some of the code I wrote - check out my site at http://KS.helpware.net. The power of all units are compiled into the KsDHTMLEDLib.ocx witch you can use free of charge. } (* NOTE: Modified by K. Toppenberg (marked by //kt) *) unit EmbeddedED; //core VCL HTML edit component {.$DEFINE EDOCX} //unit not included {.$DEFINE EDTABLE} //unit not included {.$DEFINE EDUNDO} //unit not included {.$DEFINE EDMONIKER} //unit not included {.$DEFINE EDGLYPHS} //unit not included {.$DEFINE EDLIB} //unit not included {.$DEFINE EDPARSER} //unit not included {.$DEFINE EDDRAGDROP} //unit not included {.$DEFINE EDZINDEX} //unit not included {.$DEFINE EDDESIGNER} //unit not included {.$DEFINE EDPRINT} //unit not included { $DEFINE DEBUG } //kt removed. {$I KSED.INC} //Compiler version directives interface uses Windows, Classes, ActiveX, Forms, //ktMSHTML_TLB, MSHTML_EWB, //kt AXCtrls, menus, Controls, messages, URLMon, {$IFDEF D6D7} Variants, {$ENDIF} {$IFDEF EDPRINT} EDPrint, {$ENDIF} IEConst, EmbedEDconst, KS_Lib, SHDocVw; type TDHTMLEDITAPPEARANCE = (DEAPPEARANCE_FLAT, DEAPPEARANCE_3D); TUserInterfaceOption = (NoBorder, NoScrollBar, FlatScrollBar, DivBlockOnReturn); TUserInterfaceOptions = set of TUserInterfaceOption; TDHTMLEditShowContextMenu = procedure(Sender: TObject; xPos: Integer; yPos: Integer) of object; TDHTMLEditContextMenuAction = procedure(Sender: TObject; itemIndex: Integer) of object; TQueryServiceEvent = function(const rsid, iid: TGuid; out Obj: IUnknown): HResult of object; TShowContextMenuEvent = function(const dwID: DWORD; const ppt: PPOINT; const pcmdtReserved: IUnknown; const pdispReserved: IDispatch): HRESULT of object; TShowContextMenuEventEx = procedure(Sender: TObject; xPos, yPos: Integer) of object; TTranslateURLEvent = procedure(Sender: TObject; var URL: string; var Changed: Boolean) of object; TMessageEventEx = procedure(Sender: TObject; var msg: LongWord; var wParam: SYSINT; var lParam: SYSINT; var Result: SYSINT) of object; TEditDesignerEvent = procedure(Sender: TObject; inEvtDispId: Integer; const pIEventObj: IHTMLEventObj; var Result: HResult) of object; TNotifyEventEx2 = procedure(Sender: TObject; NewFile: String) of object; TNotifyEventEx4 = procedure(Sender: TObject; var S: String) of object; //kt TSnapRect = procedure(Sender: TObject; const pIElement: IHTMLElement; var prcNew: tagRECT; eHandle: _ELEMENT_CORNER; var Result: HResult) of object; TNotifyEventEx = procedure(Sender: TObject; var Cancel: Boolean) of object; TNotifyEventEx8 = procedure(Sender: TObject; var Key: Integer; const pEvtObj: IHTMLEventObj) of object; TNotifyProcedureEvent = procedure of object; TRefreshEvent = procedure(Sender: TObject; CmdID: Integer; var Cancel: Boolean) of object; TMouseEventEx = procedure(Sender: TObject; const pEvtObj: IHTMLEventObj; X, Y: Integer; var Cancel: Boolean) of object; {$IFNDEF EDPRINT} TPrintSetup = array[0..8] of string; //Dummy type - if EDPRINT is undefines {$ENDIF} TEmbeddedED = class(TWebbrowser, IDocHostUIHandler, IDispatch, //invoke ~ general event sink IServiceProvider, IOleControlSite, IPropertyNotifySink, {$IFDEF EDDRAGDROP} IDropTarget, {$ENDIF} IOleCommandTarget, ISimpleFrameSite ) private FOnQueryService: TQueryServiceEvent; FOnDisplayChanged: TNotifyEvent; FOnShowContextMenu: TShowcontextmenuEvent; FOnShowContextmenuEx: TShowContextMenuEventEx; FOnTranslateURL: TTranslateURLEvent; FOnDocumentComplete: TNotifyEvent; FWaitMessage: Boolean; DWEBbrowserEvents2Cookie: Integer; //event sink stuff FReadyState: Integer; FShowDetails: Boolean; FIEVersion: String; FIE6: boolean; FMSHTMLDropTarget: IDropTarget; FInternalStyles: String; FExternalStyles: String; FStylesRefreshed: Boolean; FStyles: TStringList; FFonts: TStringList; FHTMLImage: String; //Source image of the current page as opened / last saved FDebug: Boolean; DebugBool: Boolean; //used to test any Boolean value DebugString: String; //used to test any string value DebugElement: IHTMLElement; DummyString: String; FSetInitialFocus: Boolean; FEDMessageHandler: TMessageEvent; FMessageHandler: TMessageEventEx; FUserInterfaceValue: DWORD; FDownloadControlValue: Integer; FPrintFinished: Boolean; // IHTMLEditHost FSnapEnabled: Boolean; FGridX: Integer; FGridY: Integer; //ktFExtSnapRect: TSnapRect; FOnPreDrag: TNotifyEventEx; FPreHandleEvent: TEditDesignerEvent; FPostHandleEvent: TEditDesignerEvent; FEDTranslateAccelerator: TEditDesignerEvent; FPostEditorEventNotify: TEditDesignerEvent; FOleInPlaceActiveObject: IOleInPlaceActiveObject; //kt .. moved to protected section .. FmsHTMLwinHandle: Hwnd; FLocalUndo: WordBool; //we handle UNDO and REDO ourselves FTUndo: Pointer; //we cant use TUndo heir, it will cause a Circular reference FTZindex: pointer; //we cant use TZindex ........ FTtable: pointer; //we cant use TTable ........ FEdit: pointer; //we cant use TEditDesigner ........ FEditHost: pointer; //we cant use TEditHost ........ FDestroyng: Boolean; FContextMenu: TPopupMenu; FCreateBakUp: Boolean; FActualTxtRange: IHTMLTxtRange; FActualControlRange: IHTMLControlRange; FSelectionType: string; FActualElement: IHTMLElement; FActualRangeIsText: Boolean; FSelection: Boolean; //There is a selection FHighlight: IHighlightRenderingServices; FHighlightSegment: IHighlightSegment; FRenderStyle: IHTMLRenderStyle; FDisplayPointerStart: IDisplayPointer; FDisplayPointerEnd: IDisplayPointer; FLoadFromString: Boolean; FParamLoad: Boolean; FRefreshing: Boolean; FUserInterfaceOptions: TUserInterfaceOptions; FBeforeSaveFile: TNotifyEvent; FAfterSaveFile: TNotifyEvent; FAfterSaveFileAs: TNotifyEvent; FAfterLoadFile: TNotifyEventEx2; FonAfterPrint: TNotifyEventEx; FonBeforePrint: TNotifyEventEx; FOnUnloadDoc: TNotifyEventEx; FOnRefreshBegin: TRefreshEvent; FOnRefreshEnd: TNotifyEvent; FBaseURL: String; {$IFNDEF EDMONIKER} FDummyString: String; {$ENDIF} FBaseTagInDoc: Boolean; FLiveResize: Boolean; F2DPosition: Boolean; FShowZeroBorderAtDesignTime: Boolean; FConstrain : boolean; EDMessageHandlerPtr: Pointer; FOnMouseUp: TMouseEventEx; FOnMouseDown: TMouseEventEx; FOnDblClick: TNotifyEvent; FOnClick: TNotifyEvent; FOnKeyUp: TNotifyEventEx8; FOnKeyDown: TNotifyEventEx8; FOnKeyPress: TKeyPressEvent; FOnMouseMove: TMouseEventEx; FOnmouseout: TNotifyEvent; FOnmouseover: TNotifyEvent; FOnBlur: TNotifyEvent; FAbsoluteDropMode: Boolean; FShowBorders: Boolean; FCurrentDocumentPath: String; FOnReadystatechange: TNotifyEvent; KeepLI: boolean; FLength: Integer; //number of selected elements FFirstElement: Integer; FLastElement: Integer; FStartElementSourceIndex: Integer; FEndElementSourceIndex: Integer; FElementCollection: IHTMLElementCollection; FTagNumber: Integer; //actual tagnumber in a GetFirts GetNext sequence FMarkUpServices: IMarkupServices; FMarkupPointerStart: IMarkupPointer; FMarkupPointerEnd: IMarkupPointer; FOnInitialize: TNotifyEventEx4; FAXCtrl: Pointer; // pointer to TActiveXControl (KsDHTMLEDLib.ocx) FGenerator: String; FSkipDirtyCheck: Boolean; FWarmingUp: Boolean; //true while MSHTML is initialised FSettingBaseURL: Boolean; FkeepPath: Boolean; FOnContextMenuAction: TDHTMLEditContextMenuAction; // IDOCHOSTUIHANDLER function ShowContextMenu(const dwID: DWORD; const ppt: PPOINT; const pcmdtReserved: IUnknown; const pdispReserved: IDispatch): HRESULT; stdcall; function GetHostInfo(var pInfo: TDOCHOSTUIINFO): HRESULT; stdcall; function ShowUI(const dwID: DWORD; const pActiveObject: IOleInPlaceActiveObject; const pCommandTarget: IOleCommandTarget; const pFrame: IOleInPlaceFrame; const pDoc: IOleInPlaceUIWindow): HRESULT; stdcall; function HideUI: HRESULT; stdcall; function UpdateUI: HRESULT; stdcall; function EnableModeless(const fEnable: BOOL): HRESULT; stdcall; function OnDocWindowActivate(const fActivate: BOOL): HRESULT; stdcall; function OnFrameWindowActivate(const fActivate: BOOL): HRESULT; stdcall; function ResizeBorder(const prcBorder: PRECT; const pUIWindow: IOleInPlaceUIWindow; const FrameWindow: BOOL): HRESULT; stdcall; function TranslateAccelerator(const lpMsg: PMSG; const pguidCmdGroup: PGUID; const nCmdID: DWORD): HRESULT; stdcall; function GetOptionKeyPath(var pchKey: POLESTR; const dw: DWORD): HRESULT; stdcall; function GetDropTarget(const pDropTarget: IDropTarget; out ppDropTarget: IDropTarget): HRESULT; stdcall; function GetExternal(out ppDispatch: IDispatch): HRESULT; stdcall; function TranslateUrl(const dwTranslate: DWORD; const pchURLIn: POLESTR; var ppchURLOut: POLESTR): HRESULT; stdcall; function FilterDataObject(const pDO: IDataObject; out ppDORet: IDataObject): HRESULT; stdcall; // IDOCHOSTUIHANDLER END // IDispatch function GetTypeInfoCount(out Count: Integer): HResult; stdcall; function GetTypeInfo(Index, LocaleID: Integer; out TypeInfo): HResult; stdcall; function GetIDsOfNames(const IID: TGUID; Names: Pointer; NameCount, LocaleID: Integer; DispIDs: Pointer): HResult; stdcall; function Invoke(DispID: Integer; const IID: TGUID; LocaleID: Integer; Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer): HResult; stdcall; // IServiceProvider function QueryService(const rsid, iid: TGuid; out Obj): HResult; stdcall; // IServiceProvider END // IOleControlSite function OnControlInfoChanged: HResult; stdcall; function LockInPlaceActive(fLock: BOOL): HResult; stdcall; function GetExtendedControl(out disp: IDispatch): HResult; stdcall; function TransformCoords(var ptlHimetric: TPoint; var ptfContainer: TPointF; flags: Longint): HResult; stdcall; function IOleControlSite.TranslateAccelerator = OleControlSite_TranslateAccelerator; function OleControlSite_TranslateAccelerator(msg: PMsg; grfModifiers: Longint): HResult; stdcall; function OnFocus(fGotFocus: BOOL): HResult; stdcall; function ShowPropertyFrame: HResult; stdcall; // IOleControlSite END {$IFDEF EDDRAGDROP} // IDropTarget function DragEnter(const dataObj: IDataObject; grfKeyState: Longint; pt: TPoint; var dwEffect: Longint): HResult; stdcall; function IDropTarget.DragOver = _DragOver; function _DragOver(grfKeyState: Longint; pt: TPoint; var dwEffect: Longint): HResult; stdcall; function DragLeave: HResult; stdcall; function Drop(const dataObj: IDataObject; grfKeyState: Longint; pt: TPoint; var dwEffect: Longint): HResult; stdcall; // IDropTarget END {$ENDIF} // IOleCommandTarget function IOleCommandTarget.QueryStatus = _QueryStatus; function _QueryStatus(CmdGroup: PGUID; cCmds: Cardinal; prgCmds: POleCmd; CmdText: POleCmdText): HResult; stdcall; function Exec(CmdGroup: PGUID; nCmdID, nCmdexecopt: DWORD; const vaIn: OleVariant; var vaOut: OleVariant): HResult; stdcall; // IOleCommandTarget END function GetOleobject: IOleobject; function GetBaseURL: String; procedure SetBaseURL(const Value: String); {$IFNDEF EDMONIKER} function LoadFromIStream(aIStream: IStream): HResult; {$ENDIF} Procedure GetSourceSnapShot; function GetCharset: string; function EmptyDoc: String; procedure SubClassMsHTML; procedure UnSubClassMsHTML; function GetWebBrowserConnectionPoint(var CP: ICOnnectionPoint): boolean; procedure EDOnMouseOver(const pEvtObj: IHTMLEventObj); procedure WaitAsyncMessage(var Msg: Tmessage); message WaitAsync_MESSAGE; function OpenChangeLog: HResult; function LoadFromStrings(aStrings: TStrings): HResult; function LoadFromString(aString: String): HResult; function Get_Busy: Boolean; procedure SetShowDetails(vIn: Boolean); Function GetBackup: Boolean; function CreateBackUp: Boolean; procedure SetDocumentHTML(NewHTML: String); procedure EDOnDownloadComplete(Sender: TObject); procedure HookEvents; function GetActualAppName: string; procedure SetActualAppName(const Value: string); procedure SetBrowseMode(const Value: WordBool); function GetBrowseMode: WordBool; procedure SetDirty(_dirty: boolean); function GetDirty: boolean; function GetDocTitle: String; procedure SetDocTitle(NewTitle: string); function GetDOC: IHTMLDocument2; function GetCmdTarget: IOleCommandTarget; function GetPersistStream: IPersistStreamInit; function GetPersistFile: IPersistFile; procedure SetLiveResize(const Value: Boolean); procedure Set2DPosition(const Value: Boolean); function GetBaseElement(var aBaseElement: IHTMLBaseElement): boolean; function GetActualElement: IHTMLElement; function GetActualTxtRange: IHTMLTxtRange; function GetActualControlRange: IHTMLControlRange; function GetSelLength: Integer; Procedure GetSelStartElement; Procedure GetSelEndElement; function GetElementNr(ElementNumber: Integer): IHTMLElement; function _GetNextItem(const aTag: String = ''): IHTMLElement; procedure EDBeforePrint(Sender: TObject; const pEvtObj: IHTMLEventObj); procedure EDAfterPrint(Sender: TObject; const pEvtObj: IHTMLEventObj); procedure EDOnUnloadDoc(Sender: TObject; const pEvtObj: IHTMLEventObj); procedure EDOnDocBlur(Sender: TObject; const pEvtObj: IHTMLEventObj); procedure EDBeforeDragStart(Sender: TObject; const pEvtObj: IHTMLEventObj); function GetLastError: string; function KSTEst(var pInVar, pOutVar: OleVariant): HResult; function Get_AbsoluteDropMode: Boolean; function Get_Scrollbars: WordBool; function Get_ShowBorders: WordBool; procedure Set_AbsoluteDropMode(const Value: Boolean); procedure Set_Appearance(const Value: TDHTMLEDITAPPEARANCE); function GetAppearance(aType: TUserInterfaceOption): TDHTMLEDITAPPEARANCE; function Get_Appearance: TDHTMLEDITAPPEARANCE; procedure Set_ScrollbarAppearance(const Value: TDHTMLEDITAPPEARANCE); function Get_ScrollbarAppearance: TDHTMLEDITAPPEARANCE; procedure Set_Scrollbars(const Value: WordBool); procedure Set_ShowBorders(const Value: WordBool); function Get_UseDivOnCarriageReturn: WordBool; procedure Set_UseDivOnCarriageReturn(const Value: WordBool); procedure FContextMenuClicked(Sender: TObject); procedure SetGridX(const Value: integer); procedure SetGridY(const Value: integer); procedure SetSnapEnabled(const Value: Boolean); procedure SetUserInterfaceValue; procedure Accept(const URL:String;var Accept:Boolean); procedure Set_LocalUndo(const Value: WordBool); function GetPrintFileName: String; function ISEmptyParam(value: Olevariant): Boolean; protected KeyPressTime : FILETIME; //kt FEditMode: Boolean; FmsHTMLwinPtr: Pointer; //saved pointer to a subclassed MSHTML window FmsHTMLwinHandle: Hwnd; //kt moved here from private section. FMainWinHandle: Hwnd; //the "Shell Embedding" window FScrollTop: Integer; //saved WYSIWYG scroll position FBeforeCloseFile: TNotifyEventEx2; FCurBackFile: String; FCaret: IHTMLCaret; //kt moved from Private --> protected section FTMGDisplayPointer: IDisplayPointer; //kt // IPropertyNotifySink function OnChanged(dispid: TDispID): HResult; override; stdcall; function OnRequestEdit(dispid: TDispID): HResult; override; stdcall; // IPropertyNotifySink END procedure SubMessageHandler(var Message: TMessage); Virtual; function SubFocusHandler(fGotFocus: BOOL): HResult; virtual; //kt procedure EDMessageHandler(var Message: TMessage); procedure OpenPointers; //kt added procedure DocumentComplete(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant; var HandlingComplete: Boolean); virtual; function _DoSaveFile: HResult; Virtual; function DoSaveFile: HResult; function DoSaveFileAs(aFile: String): HResult; Virtual; procedure AfterFileSaved; Virtual; procedure loaded; override; procedure Set_Generator(const Value: String); Virtual; procedure _UpdateUI; //back door for derived component function GetDocumentHTML: string; function ComponentInDesignMode: Boolean; Virtual; function EndCurrentDocDialog(var mr: Integer; CancelPosible: Boolean = False; SkipDirtyCheck: Boolean = False): HResult; function DocIsPersist: boolean; function _LoadFile(aFileName: String): HResult; Virtual; function _CurDir: string; function _CurFileName: string; procedure NotImplemented(S: String); procedure _GetBuildInStyles; procedure EditInitialize; function GetSelStartEnd(Var SelStart, SelEnd: Integer): boolean; function SetSelStartEnd(SelStart, SelEnd: Integer): boolean; public property Onmouseover: TNotifyEvent read FOnmouseover write FOnmouseover; property OnReadystatechange: TNotifyEvent read FOnReadystatechange write FOnReadystatechange; {$IFDEF EDOCX} property AXCtrl: Pointer read FAXCtrl write FAXCtrl; {$ENDIF} // the folowing is for internal use (but need to be public), constructor Create(Owner: TComponent); override; destructor Destroy; override; procedure ShowHighlight(pIRange: IHTMLTxtRange = nil); procedure HideHighlight; function GetInPlaceActiveObject: IOleInPlaceActiveObject; function DocumentIsAssigned: Boolean; procedure ShowCaret; procedure _CheckGenerator(MainCheck: Boolean = true); Virtual; procedure GetBaseTag(var BaseTagInDoc: Boolean; var BaseUrl: String); property Debug: Boolean read FDebug; property EDReadyState: Integer read FReadyState write FReadyState; property CurrentDocumentPath: string read FCurrentDocumentPath; property ExternalStyles: String read FExternalStyles write FExternalStyles; property Styles: TStringlist read FStyles; property MSHTMLDropTarget: IDropTarget read FMSHTMLDropTarget write FMSHTMLDropTarget; property LocalUndo: WordBool read FLocalUndo write FLocalUndo; property CmdTarget: IOleCommandTarget read GetCmdTarget; property PersistStream: IPersistStreamInit read GetPersistStream; property ScrollTop: Integer write FScrollTop; property PrintFinished: Boolean read FPrintFinished write FPrintFinished; property PersistFile: IPersistFile read GetPersistFile; property HTMLImage: String read FHTMLImage; function EndUndoBlock(aResult: HResult): HResult; function ClearUndoStack: HResult; procedure WaitAsync; function GetGenerator: string; virtual; function CmdSet(cmdID: CMDID; var pInVar: OleVariant): HResult; overload; virtual; //VCL versions that isn't exposed by the OCX function DoCommand(cmdID: CMDID): HResult; overload; function DoCommand(cmdID: CMDID; cmdexecopt: OLECMDEXECOPT): HResult; overload; function DoCommand(cmdID: CMDID; cmdexecopt: OLECMDEXECOPT; var pInVar: OleVariant): HResult; overload; function DoCommand(cmdID: CMDID; cmdexecopt: OLECMDEXECOPT; var pInVar, pOutVar: OleVariant): HResult; overload; function CmdSet(cmdID: CMDID): HResult; overload; virtual; function CmdGet(cmdID: CMDID): OleVariant; overload; function GetSaveFileName(var aFile: string): HResult; function SaveFile: HResult; virtual; function SaveFileAs(aFile: string = ''): HResult; virtual; property CurDir: string read _CurDir; property CurFileName: string read _CurFileName; function WaitForDocComplete: Boolean; property DocumentTitle: string read GetDocTitle Write SetDocTitle; procedure ScrollDoc(Pos: Integer); procedure SetFocusToDoc; function GetMSHTMLwinHandle: Hwnd; Function CaretIsVisible: Boolean; procedure SetMouseElement(P: Tpoint; aWinHandle: Hwnd = 0); procedure MakeSelElementVisible(Show: boolean); Function RemoveElementID(const TagID: String): Boolean; Procedure SetDebug(value: Boolean); property CreateBakUp: Boolean read FCreateBakUp write FCreateBakUp; property LastError: string read GetLastError; property SkipDirtyCheck: Boolean read FSkipDirtyCheck write FSkipDirtyCheck; //Old DHTMLEdit stuff function ExecCommand(cmdID: CMDID; cmdexecopt: OLECMDEXECOPT; var pInVar: OleVariant): OleVariant; procedure SetContextMenu(var menuStrings: OleVariant; var menuStates: OleVariant); procedure LoadDocument(var pathIn: OleVariant; var promptUser: OleVariant); procedure SaveDocument(var pathIn: OleVariant; var promptUser: OleVariant); property ShowBorders: WordBool read Get_ShowBorders write Set_ShowBorders; property ActualTextRange: IHTMLTxtRange read FActualTxtRange; //this is the general interface function NewDocument: HResult; virtual; procedure AssignDocument; procedure LoadURL(url: String); function Go(Url: String): HResult; function LoadFile(var aFileName: String; PromptUser: Boolean): HResult; overload; virtual; function LoadFile(var aFileName: String): HResult; overload; virtual; function EndCurrentDoc(CancelPosible: Boolean = False; SkipDirtyCheck: Boolean = False): HResult; virtual; Function GetPersistedFile: String; property IsDirty: Boolean read GetDirty write SetDirty; property DOC: IHTMLDocument2 read GetDOC; property DOM: IHTMLDocument2 read GetDOC; //just to enable old coding style function CmdGet(cmdID: CMDID; pInVar: OleVariant): OleVariant; overload; function CmdSet_B(cmdID: CMDID; pIn: Boolean): HResult; overload; virtual; function CmdSet_S(cmdID: CMDID; pIn: String): HResult; overload; virtual; function CmdSet_I(cmdID: CMDID; pIn: Integer): HResult; overload; virtual; function QueryStatus(cmdID: CMDID): OLECMDF; virtual; function QueryEnabled(cmdID: CMDID): Boolean; virtual; function QueryLatched(cmdID: CMDID): Boolean; function BeginUndoUnit(aTitle: String = 'Default'): HResult; function EndUndoUnit: HResult; procedure Refresh; property DocumentHTML: String read GetDocumentHTML write SetDocumentHTML; property Busy: Boolean read Get_Busy; function GetStyles: String; function GetBuildInStyles: String; function GetExternalStyles: String; function SetStyle(aStyleName: string): HResult; safecall; function GetStylesIndex: Integer; overload; safecall; function GetStylesIndex(aList: String): Integer; overload; safecall; function GetFonts: String; function GetFontSizeIndex(const aList: String; var Changed: String): Integer; safecall; function GetFontNameIndex(aList: String): Integer; safecall; function GetCurrentFontName: string; function SelectedDocumentHTML(var SelStart, SelEnd: Integer): String; procedure SyncDOC(HTML: string; SelStart, SelEnd: Integer); function Print(value: TPrintSetup; Showdlg: boolean = false): Boolean; function PrintEx(value: Olevariant; Showdlg: boolean): HResult; overload; function PrintPreview(value: Olevariant): HResult; overload; function PrintPreview(value: TPrintSetup): Boolean; overload; procedure PrintDocument(var withUI: OleVariant); property ActualAppName: string read GetActualAppName write SetActualAppName; property ActualTxtRange: IHTMLTxtRange read GetActualTxtRange; property ActualControlRange: IHTMLControlRange read GetActualControlRange; property ActualElement: IHTMLElement read GetActualElement; property ActualRangeIsText: Boolean read FActualRangeIsText; function IsSelElementLocked: boolean; Function GetFirstSelElement(const aTag: String = ''): IHTMLElement; Function GetNextSelElement(const aTag: String = ''): IHTMLElement; procedure GetSelParentElement; function GetSelParentElementType(const aType: string; aMessage: string = ''): IHTMLElement; Function IsSelType(aType: string): boolean; Function IsSelElementID(const ID: String): Boolean; Function IsSelElementClassName(const ClassName: String): Boolean; Function IsSelElementTagName(const TagName: String): Boolean; Function IsSelElementInVisible: Boolean; function IsSelElementAbsolute: boolean; Function GetSelText: String; procedure TrimSelection; procedure SelectActualTextrange; procedure SelectElement(aElement: IhtmlElement); function SetCursorAtElement(aElement: IhtmlElement; ADJACENCY:_ELEMENT_ADJACENCY): Boolean; procedure CollapseActualTextrange(Start: boolean); procedure KeepSelectionVisible; procedure GetElementUnderCaret;// Refresh Selection function MovePointersToRange(const aRange: IHTMLTxtRange): HResult; function MovePointersToSel: HResult; function CreateElement(const tagID: _ELEMENT_TAG_ID; var NewElement: IHTMLElement; const aTxtRange: IHTMLTxtRange = nil; const Attributes: string = ''): HResult; function InsertElementAtCursor(var aElement: IHTMLElement; const aTxtRange: IHTMLTxtRange = nil): HResult; function MoveTextRangeToPointer(aTxtRange: IHTMLTxtRange = nil): IHTMLTxtRange ; function CreateMetaTag(var aMetaElement: IHTMLMetaElement): HResult; property SelNumberOfElements: Integer read GetSelLength; property Selection: Boolean read FSelection; published // EditDesigner property OnPreHandleEvent: TEditDesignerEvent read FPreHandleEvent write FPreHandleEvent; property OnPostHandleEvent: TEditDesignerEvent read FPostHandleEvent write FPostHandleEvent; property OnPostEditorEventNotify: TEditDesignerEvent read FPostEditorEventNotify write FPostEditorEventNotify; property OnTranslateAccelerator: TEditDesignerEvent read FEDTranslateAccelerator write FEDTranslateAccelerator; property OnKeyDown: TNotifyEventEx8 read FOnKeyDown write FOnKeyDown; property OnKeyPress: TKeyPressEvent read FOnKeyPress write FOnKeyPress; property OnKeyUp: TNotifyEventEx8 read FOnKeyUp write FOnKeyUp; property OnClick: TNotifyEvent read FOnClick write FOnClick; property OnDblClick: TNotifyEvent read FOnDblClick write FOnDblClick; property OnMouseDown: TMouseEventEx read FOnMouseDown write FOnMouseDown; property OnMouseMove: TMouseEventEx read FOnMouseMove write FOnMouseMove; property OnMouseUp: TMouseEventEx read FOnMouseUp write FOnMouseUp; property Onmouseout: TNotifyEvent read FOnmouseout write FOnmouseout; property LocalUndoManager: WordBool read FLocalUndo write Set_LocalUndo; property Generator: String read GetGenerator write Set_Generator; //grid stuff property SnapToGridX: Integer read FGridX write SetGridX default 50; property SnapToGridY: Integer read FGridY write SetGridY default 50; property SnapToGrid: Boolean read FSnapEnabled write SetSnapEnabled Default true; //ktproperty OnSnapRect: TSnapRect read FExtSnapRect write FExtSnapRect; property BrowseMode: WordBool read GetBrowseMode write SetBrowseMode; property ShowDetails: boolean read FShowDetails write SetShowDetails; property UseDivOnCarriageReturn: WordBool read Get_UseDivOnCarriageReturn write Set_UseDivOnCarriageReturn; property OnContextMenuAction: TDHTMLEditContextMenuAction read FOnContextMenuAction write FOnContextMenuAction; property OnDisplayChanged: TNotifyEvent read FOnDisplayChanged write FOnDisplayChanged; // IDOCHOSTUIHANDLER property OnShowContextMenu: TShowContextMenuEvent read FOnShowContextmenu write FOnShowContextmenu; property OnShowContextMenuEx: TShowContextMenuEventEx read FOnShowContextmenuEx write FOnShowContextmenuEx; property OnQueryService: TQueryServiceEvent read FOnQueryService write FOnQueryService; property OnPreDrag: TNotifyEventEx read FOnPreDrag write FOnPreDrag; property OnTranslateURL: TTranslateURLEvent read FOnTranslateURL write FOnTranslateURL; property OnBeforeCloseFile: TNotifyEventEx2 read FBeforeCloseFile write FBeforeCloseFile; property OnBeforeSaveFile: TNotifyEvent read FBeforeSaveFile write FBeforeSaveFile; property OnAfterSaveFile: TNotifyEvent read FAfterSaveFile write FAfterSaveFile; property OnAfterSaveFileAs: TNotifyEvent read FAfterSaveFileAs write FAfterSaveFileAs; property OnAfterLoadFile: TNotifyEventEx2 read FAfterLoadFile write FAfterLoadFile; property OnEDMessageHandler: TMessageEvent read FEDMessageHandler write FEDMessageHandler; property OnMessageHandler: TMessageEventEx read FMessageHandler write FMessageHandler; property OnBlur: TNotifyEvent read FOnBlur write FOnBlur; Property OnInitialize: TNotifyEventEx4 read FOnInitialize write FOnInitialize; property OnBeforePrint: TNotifyEventEx read FonBeforePrint write FonBeforePrint; property OnAfterPrint: TNotifyEventEx read FonAfterPrint write FonAfterPrint; property OnUnloadDoc: TNotifyEventEx read FOnUnloadDoc write FOnUnloadDoc; property OnRefreshBegin: TRefreshEvent read FOnRefreshBegin write FOnRefreshBegin; property OnRefreshEnd: TNotifyEvent read FOnRefreshEnd write FOnRefreshEnd; property OnDocumentComplete: TNotifyEvent read FOnDocumentComplete write FOnDocumentComplete; property Appearance: TDHTMLEDITAPPEARANCE read Get_Appearance write Set_Appearance; property BaseURL: String read GetBaseURL write SetBaseURL; property Scrollbars: WordBool read Get_Scrollbars write Set_Scrollbars default true; property ScrollbarAppearance: TDHTMLEDITAPPEARANCE read Get_ScrollbarAppearance write Set_ScrollbarAppearance; property AbsoluteDropMode: Boolean read Get_AbsoluteDropMode write Set_AbsoluteDropMode; property _2DPosition: Boolean read F2DPosition write Set2DPosition; property LiveResize: Boolean read FLiveResize write SetLiveResize; //the editor will try to load a file from paramstr(1) - has no meaning inside a OCX property ParamLoad: Boolean read FParamLoad write FParamLoad; end; threadVar TheActualAppName: String; procedure Register; implementation uses SysUtils, dialogs, FileCtrl, ComObj, {$IFDEF EDUNDO} UUndo, {$ENDIF} {$IFDEF EDTABLE} EmbedEDTable, {$ENDIF} {$IFDEF EDMONIKER} KS_EDMoniker, {$ENDIF} {$IFDEF EDGLYPHS} CustomGlyphs, {$ENDIF} {$IFDEF EDLIB} EDLIB, {$ENDIF} {$IFDEF EDPARSER} KSIEParser, {$ENDIF} {$IFDEF EDDRAGDROP} dragdrop, {$ENDIF} {$IFDEF EDZINDEX} UZindex, {$ENDIF} math, //kt {$IFDEF EDDESIGNER} UEditDesigner, {$ENDIF} UEditHost, KS_Procs, KS_Procs2, IEDispConst, RegFuncs; const DLCTL_DLIMAGES = $00000010; DLCTL_VIDEOS = $00000020; DLCTL_BGSOUNDS = $00000040; DLCTL_PRAGMA_NO_CACHE = $00004000; CancelPosible: Boolean = true; //------------------------------------------------------------------------------ procedure Register; begin RegisterComponents('KS', [TEmbeddedED]); end; //------------------------------------------------------------------------------ constructor TEmbeddedED.Create(Owner: TComponent); begin //asm int 3 end; //trap inherited Create(Owner); FContextMenu := TPopupMenu.Create(nil); FStyles := TStringList.Create; FStyles.Sorted := true; FStyles.Duplicates := dupIgnore; FGridX := 50; //default values on startup FGridY := 50; FSnapEnabled := true; FUserInterfaceOptions := []; // default = Border, ScrollBar, 3DScrollBar, NoDivBlockOnReturn FGenerator := 'KS MSHTML Edit 1.0'; //set default value {$IFDEF DEBUG} FDEbug := True; {$ENDIF} end; //------------------------------------------------------------------------------ destructor TEmbeddedED.Destroy; var CP: ICOnnectionPoint; begin //asm int 3 end; //trap FDestroyng := true; UnSubClassMsHTML; //just in case FOleInPlaceActiveObject := nil; if (DWEBbrowserEvents2Cookie <> 0) and GetWebBrowserConnectionPoint(CP) then CP.UnAdvise(DWEBbrowserEvents2Cookie); FContextMenu.free; if assigned(FEditHost) then TObject(FEditHost).free; if FEdit <> nil then TObject(FEdit).Free; if FTUndo <> nil then TObject(FTUndo).Free; if FTZindex <> nil then TObject(FTZindex).Free; if FTtable <> nil then TObject(FTtable).Free; FStyles.free; FFonts.free; inherited Destroy; end; //------------------------------------------------------------------------------ function TEmbeddedED.ComponentInDesignMode: Boolean; begin //asm int 3 end; //trap result := (csDesigning in ComponentState); {$IFDEF EDOCX} if Assigned(FAXCtrl) then begin //we are using the component from an OCX try result := not (TActiveXControl(FAXCtrl).ClientSite as IAmbientDispatch).UserMode; except //just catch any error - we are NOT in design mode result := false; end; end; {$ENDIF} end; //------------------------------------------------------------------------------ procedure TEmbeddedED.loaded; var CP: ICOnnectionPoint; begin //asm int 3 end; //trap inherited loaded; if ComponentInDesignMode then exit; { TEmbeddedED's OnDocumentComplete override TWebbrowser's OnDocumentComplete We sink all DWEBbrowserEvents2 - although we only use OnDocumentComplete } if GetWebBrowserConnectionPoint(CP) then CP.Advise(self, DWEBbrowserEvents2Cookie) //send events to TEmbeddedED.Invoke else KSMessageE('TWebBrowser''s ICOnnectionPoint could not be found'); //set standard Download Control Values FDownloadControlValue := DLCTL_BGSOUNDS + //download sounds DLCTL_DLIMAGES + //download images DLCTL_VIDEOS + //download videos DLCTL_PRAGMA_NO_CACHE; //don't use the cache SetUserInterfaceValue; //linking in the EditHost FEditHost := TEditHost.Create(self); TEditHost(FEditHost).FSnapEnabled := FSnapEnabled; TEditHost(FEditHost).FGridX := FGridX; TEditHost(FEditHost).FGridY := FGridY; //ktTEditHost(FEditHost).FExtSnapRect := FExtSnapRect; TEditHost(FEditHost).FOnPreDrag := FOnPreDrag; {$IFDEF EDDESIGNER} //linking in the EditDesigner FEdit := Pointer(TEditDesigner.Create(self)); TEditDesigner(FEdit).FPreHandleEvent := FPreHandleEvent; TEditDesigner(FEdit).FPostHandleEvent := FPostHandleEvent; TEditDesigner(FEdit).FPostEditorEventNotify := FPostEditorEventNotify; TEditDesigner(FEdit).FOnDblClick := FOnDblClick; TEditDesigner(FEdit).FOnClick := FOnClick; TEditDesigner(FEdit).FOnKeyPress := FOnKeyPress; TEditDesigner(FEdit).FOnReadystatechange := FOnReadystatechange; TEditDesigner(FEdit).FEDTranslateAccelerator := FEDTranslateAccelerator; TEditDesigner(FEdit).FDebug := FDebug; TEditDesigner(FEdit).FOnMouseMove := FOnMouseMove; TEditDesigner(FEdit).FOnMouseUp := FOnMouseUp; TEditDesigner(FEdit).FOnMouseDown := FOnMouseDown; TEditDesigner(FEdit).FOnKeyUp := FOnKeyUp; TEditDesigner(FEdit).FOnKeyDown := FOnKeyDown; TEditDesigner(FEdit).FOnmouseout := FOnmouseOut; TEditDesigner(FEdit).FOnmouseover := EDOnmouseover; {$ENDIF} {$IFDEF EDZINDEX} FTZindex := Pointer(TZindex.Create(self)); {$ENDIF} {$IFDEF EDTABLE} FTtable := Pointer(TTable.Create(self)); {$ENDIF} FIEVersion := ReadRegString(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Internet Explorer\', 'Version'); if length(FIEVersion) > 0 then begin FIE6 := FIEVersion[1] >= '6'; if (not FIE6) then begin if (FIEVersion[1] < '5') or (FIEVersion[3] < '5') then KSMessageE('This HTML-editor Component '+CrLf+'need IE 5.5 or higher'); end; end; FWarmingUp := true; AssignDocument; //basic initialisation of MSHTML FWarmingUp := false; GetInPlaceActiveObject; //initialise FOleInPlaceActiveObject if FShowBorders then CmdSet_B(IDM_SHOWZEROBORDERATDESIGNTIME, true); if FEditMode then begin //initialisation of MSHTML edit mode {$IFDEF EDLIB} InitializeGenerator(Self); {$ENDIF} DOC.designMode := 'On'; //CmdSet(IDM_EDITMODE); //Not currently supported - but it works !! end; if FAXCtrl = nil //Only do this in VCL mode, the OCX needs a later initialization then EditInitialize; end; //------------------------------------------------------------------------------ procedure TEmbeddedED.EditInitialize; var aFile: String; begin //asm int 3 end; //trap if ComponentInDesignMode then exit; aFile := ''; //get a file to open at start-up if Assigned(FOnInitialize) then FOnInitialize(Self, aFile); //get a initial file name if FParamLoad and (aFile = '') //if no file yet, look for a param - NB will not work inside an OCX then aFile := Paramstr(1); if aFile <> '' then begin if S_OK <> LoadFile(aFile) //load a "command line" / initial file - if any then aFile := ''; end; if aFile = '' then NewDocument; //load an empty document _GetBuildInStyles; FSetInitialFocus := true; end; //------------------------------------------------------------------------------ procedure TEmbeddedED.SetUserInterfaceValue; begin //asm int 3 end; //trap FUserInterfaceValue := 0; if NoBorder in FUserInterfaceOptions then Inc(FUserInterfaceValue, DOCHOSTUIFLAG_NO3DBORDER); if NoScrollBar in FUserInterfaceOptions then Inc(FUserInterfaceValue, DOCHOSTUIFLAG_SCROLL_NO); if FlatScrollBar in FUserInterfaceOptions then Inc(FUserInterfaceValue, DOCHOSTUIFLAG_FLAT_SCROLLBAR); if DivBlockOnReturn in FUserInterfaceOptions then Inc(FUserInterfaceValue, DOCHOSTUIFLAG_DIV_BLOCKDEFAULT); end; //------------------------------------------------------------------------------ procedure TEmbeddedED.SubClassMsHTML; begin //asm int 3 end; //trap { We hook into the message chain in front of the MSHTML window after the hook is in place all massages send to MSHTML will be passed to EDMessageHandler first } if (GetInPlaceActiveObject <> nil) and (FmsHTMLwinHandle <> 0) then begin if EDMessageHandlerPtr <> nil then UnSubClassMsHTML; //create handle to EDMessageHandler EDMessageHandlerPtr := MakeObjectInstance(EDMessageHandler); //save pointer to the FmsHTMLwinHandle window FmsHTMLwinPtr := Pointer(SetWindowLong(FmsHTMLwinHandle, GWL_WNDPROC, LongInt(EDMessageHandlerPtr))); end; end; //------------------------------------------------------------------------------ procedure TEmbeddedED.UnSubClassMsHTML; begin //asm int 3 end; //trap if (GetInPlaceActiveObject <> nil) and (FmsHTMLwinHandle <> 0) and (EDMessageHandlerPtr <> nil) then begin //restore old MSHTML window as target SetWindowLong(FmsHTMLwinHandle, GWL_WNDPROC, LongInt(FmsHTMLwinPtr)); FreeObjectInstance(EDMessageHandlerPtr); EDMessageHandlerPtr := nil; end; end; //------------------------------------------------------------------------------ procedure TEmbeddedED.SubMessageHandler(var Message: TMessage); begin //overridden by derived components end; function TEmbeddedED.SubFocusHandler(fGotFocus: BOOL): HResult; //kt added begin //overridden by derived components end; //------------------------------------------------------------------------------ procedure TEmbeddedED.EDMessageHandler(var Message: TMessage); var WinMsg: TMsg; handled: boolean; transformed: boolean; //---------------------------------------------------------- function HandlingDone(handled: Boolean): boolean; begin if handled then Message.Result := 1; result := handled; end; //---------------------------------------------------------- procedure transformMessage; begin if transformed then exit; WinMsg.HWnd := Handle; WinMsg.Message := Message.Msg ; WinMsg.WParam := Message.WParam; WinMsg.LParam := Message.LParam; WinMsg.Time := GetMessageTime; GetCursorPos(WinMsg.Pt); transformed := true; end; //---------------------------------------------------------- begin //asm int 3 end; //trap {when key messages arrives heir from a VCL implementation hey they are offset with CN_BASE but can come by a second time with no CN_BASE offset. OCX implementation they are not offset } { all messages to MSHTML comes through here - KEEP IT LEAN. if Handled is not set to true then the message is dispatched back to MSHTML. } transformed := false; Handled := false; if assigned(FMessageHandler) //external assigned message handler then begin FMessageHandler(Self, Message.Msg, Message.WParam, Message.LParam, Message.Result); if Message.Result = 1 then exit; end; if assigned(FEDMessageHandler) //external assigned message handler then begin transformMessage; FEDMessageHandler(WinMsg, handled); if HandlingDone(handled) then exit; end; {$IFDEF EDTABLE} //let the "table unit" have a look at the message if assigned(FTtable) and (Not FDestroyng) and (TTable(FTtable).CheckMessage(Message)) then exit; {$ENDIF} {$IFDEF EDZINDEX} //let the "UZindex unit" have a look at the message if assigned(FTZindex) and (Not FDestroyng) and (TZindex(FTZindex).CheckMessage(Message)) then exit; {$ENDIF} SubMessageHandler(Message); if Message.Result = 1 then exit; //send the message back to the subclassed MSHTML window Message.Result := CallWindowProc(FmsHTMLwinPtr, FmsHTMLwinHandle, Message.Msg, Message.WParam, Message.LParam); end; //------------------------------------------------------------------------------ function TEmbeddedED.GetWebBrowserConnectionPoint(var CP: ICOnnectionPoint): boolean; var CPC: IConnectionPointContainer; begin //asm int 3 end; //trap TwebBrowser(Self).ControlInterface.QueryInterface(IConnectionPointContainer, CPC); if assigned(CPC) then CPC.FindConnectionPoint(DWEBbrowserEvents2, CP); result := Assigned(CP); end; //------------------------------------------------------------------------------ function TEmbeddedED.Invoke(DispID: Integer; const IID: TGUID; LocaleID: Integer; Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer): HResult; var dps: TDispParams absolute Params; pDispIds: PDispIdList; iDispIdsSize: integer; handled: Boolean; //------------------------------------------- procedure BuildPositionalDispIds; var i: integer; begin pDispIds := nil; iDispIdsSize := dps.cArgs * SizeOf(TDispId); GetMem(pDispIds, iDispIdsSize); // by default, directly arrange in reverse order for i := 0 to dps.cArgs - 1 do pDispIds^[i] := dps.cArgs - 1 - i; if (dps.cNamedArgs > 0) // check for named args then begin // parse named args for i := 0 to dps.cNamedArgs - 1 do pDispIds^[dps.rgdispidNamedArgs^[i]] := i; end; end; //------------------------------------------- begin //asm int 3 end; //trap Result := S_OK; case Dispid of DISPID_AMBIENT_DLCONTROL: if (Flags and DISPATCH_PROPERTYGET <> 0) and (VarResult <> nil) then begin PVariant(VarResult)^ := FDownloadControlValue; Exit; end; 259: //DWebBrowserEvents2.OnDocumentComplete if dps.cArgs > 0 then begin BuildPositionalDispIds; //call the our DocumentComplete event handler DocumentComplete(self, //Sender: TObject IDispatch(dps.rgvarg^[pDispIds^[0]].dispval), //pDisp: IDispatch POleVariant(dps.rgvarg^[pDispIds^[1]].pvarval)^, //URL: OleVariant handled); FreeMem (pDispIds, iDispIdsSize); Exit; end; 104 : //DWebBrowserEvents2.DownloadComplete begin EDOnDownloadComplete(Self); Exit; end; DISPID_HTMLWINDOWEVENTS2_ONBLUR: if dps.cArgs > 0 then begin BuildPositionalDispIds; EDOnDocBlur(self, //Sender: TObject IHTMLEventObj(dps.rgvarg^[pDispIds^[0]].dispval)); //pEvtObj: IHTMLEventObj FreeMem (pDispIds, iDispIdsSize); Exit; end; DISPID_HTMLWINDOWEVENTS2_ONUNLOAD: if dps.cArgs > 0 then begin BuildPositionalDispIds; EDOnUnloadDoc(self, //Sender: TObject IHTMLEventObj(dps.rgvarg^[pDispIds^[0]].dispval)); //pEvtObj: IHTMLEventObj FreeMem (pDispIds, iDispIdsSize); Exit;; end; DISPID_HTMLWINDOWEVENTS2_ONAFTERPRINT: if dps.cArgs > 0 then begin BuildPositionalDispIds; EDAfterPrint(self, //Sender: TObject IHTMLEventObj(dps.rgvarg^[pDispIds^[0]].dispval)); //pEvtObj: IHTMLEventObj FreeMem (pDispIds, iDispIdsSize); Exit; end; DISPID_HTMLWINDOWEVENTS2_ONBEFOREPRINT: if dps.cArgs > 0 then begin BuildPositionalDispIds; EDBeforePrint(self, //Sender: TObject IHTMLEventObj(dps.rgvarg^[pDispIds^[0]].dispval)); //pEvtObj: IHTMLEventObj FreeMem (pDispIds, iDispIdsSize); Exit; end; DISPID_HTMLDOCUMENTEVENTS2_ONDRAGSTART: if dps.cArgs > 0 then begin BuildPositionalDispIds; EDBeforeDragStart(self, //Sender: TObject IHTMLEventObj(dps.rgvarg^[pDispIds^[0]].dispval)); //pEvtObj: IHTMLEventObj FreeMem (pDispIds, iDispIdsSize); Exit; end; DISPID_HTMLELEMENTEVENTS2_ONMOVESTART: Beep; (* //return S_OK for unhandled members of HTMLWindowEvents2 1002, 1003, 1014, 1016, 1017, -2147418102, -2147418111: exit; //return S_OK for unhandled members of DWebBrowserEvents2 102, 105, 106, 108, 112, 113, 250, 251, 252, 253, 254, 255, 256, 257, 258, 260, 262, 236, 234, 265, 266, 267, 268, 269, 270 : exit; *) end; //case //let TOleControl handle the invoke Result := inherited Invoke(DispID, IID, LocaleID, Flags, Params, VarResult, ExcepInfo, ArgErr); end; //------------------------------------------------------------------------------ function TEmbeddedED.GetTypeInfoCount(out Count: Integer): HResult; begin //asm int 3 end; //trap Result := inherited GetTypeInfoCount(Count); end; //------------------------------------------------------------------------------ function TEmbeddedED.GetTypeInfo(Index, LocaleID: Integer; out TypeInfo): HResult; begin //asm int 3 end; //trap Result := inherited GetTypeInfo(Index, LocaleID, TypeInfo); end; //------------------------------------------------------------------------------ function TEmbeddedED.GetIDsOfNames(const IID: TGUID; Names: Pointer; NameCount, LocaleID: Integer; DispIDs: Pointer): HResult; begin //asm int 3 end; //trap Result := inherited GetIDsOfNames(IID, Names, NameCount, LocaleID, DispIDs); end; //------------------------------------------------------------------------------ function TEmbeddedED.OnChanged(dispid: TDispID): HResult; var dp: TDispParams; vResult: OleVariant; begin //asm int 3 end; //trap { Dispid = Dispatch identifier of the property that changed, or DISPID_UNKNOWN if multiple properties have changed. } if (TwebBrowser(Self).Document <> nil) and (DISPID_READYSTATE = Dispid) then begin if SUCCEEDED(Doc.Invoke(DISPID_READYSTATE, GUID_null, LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET, dp, @vresult, nil, nil)) then FReadyState := Integer(vresult); end; result := inherited OnChanged(dispid); end; //------------------------------------------------------------------------------ function TEmbeddedED.OnRequestEdit(dispid: TDispID): HResult; begin //asm int 3 end; //trap result := inherited OnRequestEdit(dispid); end; //------------------------------------------------------------------------------ procedure TEmbeddedED.EDBeforeDragStart(Sender: TObject; const pEvtObj: IHTMLEventObj); var Done: Boolean; begin //asm int 3 end; //trap beep; if assigned(FonBeforePrint) then begin Done := false; beep; //FonBeforePrint(self, Done); if Done then pEvtObj.returnValue := True; end; end; //------------------------------------------------------------------------------ procedure TEmbeddedED.EDBeforePrint(Sender: TObject; const pEvtObj: IHTMLEventObj); var Done: Boolean; begin //asm int 3 end; //trap if assigned(FonBeforePrint) then begin Done := false; FonBeforePrint(self, Done); if Done then pEvtObj.returnValue := True; end; end; //------------------------------------------------------------------------------ procedure TEmbeddedED.EDAfterPrint(Sender: TObject; const pEvtObj: IHTMLEventObj); { MSHTML stores a copy of the HTML source in a cache from where it is printed. EDAfterPrint is fired when MSHTML has finished saving the document, at the state it vas in, into cache } var Done: Boolean; begin //asm int 3 end; //trap FPrintFinished := true; if assigned(FonAfterPrint) then begin Done := false; FonAfterPrint(self, Done); if Done then pEvtObj.returnValue := True; end; end; //------------------------------------------------------------------------------ procedure TEmbeddedED.EDOnUnloadDoc(Sender: TObject; const pEvtObj: IHTMLEventObj); var Done: Boolean; begin //asm int 3 end; //trap FStylesRefreshed := False; //we need to load a fresh set together with the next document if assigned(FOnUnloadDoc) then begin Done := false; FOnUnloadDoc(self, Done); if Done then pEvtObj.returnValue := True; end; end; //------------------------------------------------------------------------------ procedure TEmbeddedED.EDOnDocBlur(Sender: TObject; const pEvtObj: IHTMLEventObj); begin //asm int 3 end; //trap if FWarmingUp then exit; {$IFDEF EDLIB} KeepSelection(Self); {$ENDIF} {$IFDEF EDTABLE} if assigned(FTtable) and (Not FDestroyng) then TTable(FTtable).TblOnBlur; {$ENDIF} if Assigned(FOnBlur) then FOnBlur(Self); end; //------------------------------------------------------------------------------ procedure TEmbeddedED.EDOnDownloadComplete(Sender: TObject); var aURL: OleVariant; handled: Boolean; begin //asm int 3 end; //trap if FRefreshing //Refresh page and some other things don't result in a Document complete then begin FRefreshing := False; aURL := Doc.URL; DocumentComplete(Self, nil, aURL, handled); If Assigned(FOnRefreshEnd) then FOnRefreshEnd(Self); end; end; //------------------------------------------------------------------------------ procedure TEmbeddedED.WaitAsync; begin //asm int 3 end; //trap FWaitMessage := false; PostMessage(FMainWinHandle, WaitAsync_MESSAGE, 0, 0); while not FWaitMessage do SafeYield; end; //------------------------------------------------------------------------------ Procedure TEmbeddedED.GetSourceSnapShot; {$IFNDEF EDLIB} var TempStream: TMemoryStream; {$ENDIF} begin //asm int 3 end; //trap {$IFNDEF EDLIB} { First we need to force MSHTML to tidy up the source the way it wants. MSHTML inserts and updates certain elements in the
when it saves the file } TempStream := TMemoryStream.Create; try //just a dummy save PersistStream.save(TStreamAdapter.Create(TempStream), true); finally TempStream.free; end; {$ENDIF} FHTMLImage := KS_Lib.GetHTMLtext(DOC); //Get Snapshot of HTML Source end; //------------------------------------------------------------------------------ procedure TEmbeddedED.ShowCaret; begin //asm int 3 end; //trap FCaret.Show(0); end; //------------------------------------------------------------------------------ procedure TEmbeddedED.GetBaseTag(var BaseTagInDoc: Boolean; var BaseUrl: String); var aElement: IHTMLElement; aCollection: IHTMLElementCollection; aDomNode, HTMLF, HTMLP: IHTMLDomNode; i: integer; DOC3: IHTMLDocument3; S: String; I2: Integer; DESIGNTIMEBASEURLfound: Boolean; begin //asm int 3 end; //trap { if the source have a'; result := ''+CrLf+ '