1 //------------------------------------------------------------------------------
2 // <copyright file="MSHTMLHost.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //------------------------------------------------------------------------------
9 // 12/17/98: Created: [....]
12 namespace System.Web.UI.Design.MobileControls.Util {
13 using System.Runtime.Serialization.Formatters;
15 using System.Runtime.InteropServices;
16 using System.ComponentModel;
18 using System.Diagnostics;
22 using Microsoft.Win32;
23 using System.Windows.Forms;
25 /// <include file='doc\MSHTMLHost.uex' path='docs/doc[@for="MSHTMLHost"]/*' />
27 /// Control that hosts a Trident DocObject.
33 [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)]
34 [Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
35 internal sealed class MSHTMLHost : Control {
36 private TridentSite tridentSite;
38 internal MSHTMLHost() : base() {
41 public NativeMethods.IHTMLDocument2 GetDocument() {
42 Debug.Assert(tridentSite != null,
43 "Cannot call getDocument before calling createTrident");
45 return tridentSite.GetDocument();
48 protected override CreateParams CreateParams {
50 CreateParams cp = base.CreateParams;
52 cp.ExStyle |= NativeMethods.WS_EX_STATICEDGE;
57 internal bool CreateTrident() {
58 Debug.Assert(Handle != IntPtr.Zero,
59 "MSHTMLHost must first be created before createTrident is called");
62 tridentSite = new TridentSite(this);
65 Debug.WriteLine("Exception caught in MSHTMLHost::CreateTrident\n\t" + e.ToString());
71 internal void ActivateTrident() {
72 Debug.Assert(tridentSite != null,
73 "cannot call activateTrident before calling createTrident");
75 tridentSite.Activate();
80 /// <include file='doc\MSHTMLHost.uex' path='docs/doc[@for="TridentSite"]/*' />
82 /// Implements the client site for Trident DocObject
84 [ClassInterface(ClassInterfaceType.None)]
85 [Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
86 internal class TridentSite : NativeMethods.IOleClientSite, NativeMethods.IOleDocumentSite, NativeMethods.IOleInPlaceSite, NativeMethods.IOleInPlaceFrame, NativeMethods.IDocHostUIHandler {
88 protected Control parentControl;
89 protected NativeMethods.IOleDocumentView tridentView;
90 protected NativeMethods.IOleObject tridentOleObject;
91 protected NativeMethods.IHTMLDocument2 tridentDocument;
93 protected EventHandler resizeHandler;
95 internal TridentSite(Control parent) {
96 Debug.Assert((parent != null) && (parent.Handle != IntPtr.Zero),
97 "Invalid control passed in as parent of Trident window");
99 parentControl = parent;
100 resizeHandler = new EventHandler(this.OnParentResize);
101 parentControl.Resize += resizeHandler;
106 public NativeMethods.IHTMLDocument2 GetDocument() {
107 return tridentDocument;
110 internal void Activate() {
114 protected virtual void OnParentResize(object src, EventArgs e) {
115 if (tridentView != null) {
116 NativeMethods.COMRECT r = new NativeMethods.COMRECT();
118 NativeMethods.GetClientRect(parentControl.Handle, r);
119 tridentView.SetRect(r);
124 ///////////////////////////////////////////////////////////////////////////
125 // IOleClientSite Implementation
127 public virtual void SaveObject() {
130 public virtual object GetMoniker(int dwAssign, int dwWhichMoniker) {
131 throw new COMException(String.Empty, NativeMethods.E_NOTIMPL);
134 public virtual int GetContainer(out NativeMethods.IOleContainer ppContainer) {
136 return NativeMethods.E_NOINTERFACE;
139 public virtual void ShowObject() {
142 public virtual void OnShowWindow(int fShow) {
145 public virtual void RequestNewObjectLayout() {
149 ///////////////////////////////////////////////////////////////////////////
150 // IOleDocumentSite Implementation
152 public virtual int ActivateMe(NativeMethods.IOleDocumentView pViewToActivate) {
153 Debug.Assert(pViewToActivate != null,
154 "Expected the view to be non-null");
155 if (pViewToActivate == null)
156 return NativeMethods.E_INVALIDARG;
158 NativeMethods.COMRECT r = new NativeMethods.COMRECT();
160 NativeMethods.GetClientRect(parentControl.Handle, r);
162 tridentView = pViewToActivate;
163 tridentView.SetInPlaceSite((NativeMethods.IOleInPlaceSite)this);
164 tridentView.UIActivate(1);
165 tridentView.SetRect(r);
168 return NativeMethods.S_OK;
172 ///////////////////////////////////////////////////////////////////////////
173 // IOleInPlaceSite Implementation
175 public virtual IntPtr GetWindow() {
176 return parentControl.Handle;
179 public virtual void ContextSensitiveHelp(int fEnterMode) {
180 throw new COMException(String.Empty, NativeMethods.E_NOTIMPL);
183 public virtual int CanInPlaceActivate() {
184 return NativeMethods.S_OK;
187 public virtual void OnInPlaceActivate() {
190 public virtual void OnUIActivate() {
193 public virtual void GetWindowContext(out NativeMethods.IOleInPlaceFrame ppFrame, out NativeMethods.IOleInPlaceUIWindow ppDoc, NativeMethods.COMRECT lprcPosRect, NativeMethods.COMRECT lprcClipRect, NativeMethods.tagOIFI lpFrameInfo) {
195 ppFrame = (NativeMethods.IOleInPlaceFrame)this;
198 NativeMethods.GetClientRect(parentControl.Handle, lprcPosRect);
199 NativeMethods.GetClientRect(parentControl.Handle, lprcClipRect);
201 lpFrameInfo.cb = System.Runtime.InteropServices.Marshal.SizeOf(typeof(NativeMethods.tagOIFI));
202 lpFrameInfo.fMDIApp = 0;
203 lpFrameInfo.hwndFrame = parentControl.Handle;
204 lpFrameInfo.hAccel = IntPtr.Zero;
205 lpFrameInfo.cAccelEntries = 0;
208 public virtual int Scroll(NativeMethods.tagSIZE scrollExtant) {
209 return(NativeMethods.E_NOTIMPL);
212 public virtual void OnUIDeactivate(int fUndoable) {
213 // NOTE, [....], 7/99: Don't return E_NOTIMPL. Somehow doing nothing and returning S_OK
214 // fixes trident hosting in Win2000.
217 public virtual void OnInPlaceDeactivate() {
220 public virtual void DiscardUndoState() {
221 throw new COMException(SR.GetString(SR.MSHTMLHost_Not_Implemented), NativeMethods.E_NOTIMPL);
224 public virtual void DeactivateAndUndo() {
227 public virtual int OnPosRectChange(NativeMethods.COMRECT lprcPosRect) {
228 return NativeMethods.S_OK;
232 ///////////////////////////////////////////////////////////////////////////
233 // IOleInPlaceFrame Implementation
235 public virtual void GetBorder(NativeMethods.COMRECT lprectBorder) {
236 throw new COMException(String.Empty, NativeMethods.E_NOTIMPL);
239 public virtual void RequestBorderSpace(NativeMethods.COMRECT pborderwidths) {
240 throw new COMException(String.Empty, NativeMethods.E_NOTIMPL);
243 public virtual void SetBorderSpace(NativeMethods.COMRECT pborderwidths) {
244 throw new COMException(String.Empty, NativeMethods.E_NOTIMPL);
247 public virtual void SetActiveObject(NativeMethods.IOleInPlaceActiveObject pActiveObject, string pszObjName) {
248 // NOTE, [....], 7/99: Don't return E_NOTIMPL. Somehow doing nothing and returning S_OK
249 // fixes trident hosting in Win2000.
250 // throw new COMException(String.Empty, NativeMethods.E_NOTIMPL);
253 public virtual void InsertMenus(IntPtr hmenuShared, object lpMenuWidths) {
254 throw new COMException(String.Empty, NativeMethods.E_NOTIMPL);
257 public virtual void SetMenu(IntPtr hmenuShared, IntPtr holemenu, IntPtr hwndActiveObject) {
258 throw new COMException(String.Empty, NativeMethods.E_NOTIMPL);
261 public virtual void RemoveMenus(IntPtr hmenuShared) {
262 throw new COMException(String.Empty, NativeMethods.E_NOTIMPL);
265 public virtual void SetStatusText(string pszStatusText) {
268 public virtual void EnableModeless(int fEnable) {
271 public virtual int TranslateAccelerator(ref NativeMethods.MSG lpmsg, short wID) {
272 return NativeMethods.S_FALSE;
276 ///////////////////////////////////////////////////////////////////////////
277 // IDocHostUIHandler Implementation
279 public virtual int ShowContextMenu(int dwID, NativeMethods.POINT pt, object pcmdtReserved, object pdispReserved) {
280 return NativeMethods.S_OK;
283 public virtual int GetHostInfo(NativeMethods.DOCHOSTUIINFO info) {
284 info.dwDoubleClick = NativeMethods.DOCHOSTUIDBLCLICK.DEFAULT;
285 info.dwFlags = NativeMethods.DOCHOSTUIFLAG.FLAT_SCROLLBAR |
286 NativeMethods.DOCHOSTUIFLAG.NO3DBORDER |
287 NativeMethods.DOCHOSTUIFLAG.DIALOG |
288 NativeMethods.DOCHOSTUIFLAG.DISABLE_SCRIPT_INACTIVE;
290 return NativeMethods.S_OK;
293 public virtual int EnableModeless(bool fEnable) {
294 return NativeMethods.S_OK;
297 public virtual int ShowUI(int dwID, NativeMethods.IOleInPlaceActiveObject activeObject, NativeMethods.IOleCommandTarget commandTarget, NativeMethods.IOleInPlaceFrame frame, NativeMethods.IOleInPlaceUIWindow doc) {
298 return NativeMethods.S_OK;
301 public virtual int HideUI() {
302 return NativeMethods.S_OK;
305 public virtual int UpdateUI() {
306 return NativeMethods.S_OK;
309 public virtual int OnDocWindowActivate(bool fActivate) {
310 return NativeMethods.E_NOTIMPL;
313 public virtual int OnFrameWindowActivate(bool fActivate) {
314 return NativeMethods.E_NOTIMPL;
317 public virtual int ResizeBorder(NativeMethods.COMRECT rect, NativeMethods.IOleInPlaceUIWindow doc, bool fFrameWindow) {
318 return NativeMethods.E_NOTIMPL;
321 public virtual int GetOptionKeyPath(string[] pbstrKey, int dw) {
323 return NativeMethods.S_OK;
326 public virtual int GetDropTarget(NativeMethods.IOleDropTarget pDropTarget, out NativeMethods.IOleDropTarget ppDropTarget) {
328 return NativeMethods.S_FALSE;
331 public virtual int GetExternal(out object ppDispatch) {
333 return NativeMethods.S_OK;
336 public virtual int TranslateAccelerator(ref NativeMethods.MSG msg, ref Guid group, int nCmdID) {
337 return NativeMethods.S_OK;
340 public virtual int TranslateUrl(int dwTranslate, string strUrlIn, out string pstrUrlOut) {
342 return NativeMethods.E_NOTIMPL;
345 public virtual int FilterDataObject(NativeMethods.IOleDataObject pDO, out NativeMethods.IOleDataObject ppDORet) {
347 return NativeMethods.S_OK;
351 ///////////////////////////////////////////////////////////////////////////
354 /// <include file='doc\MSHTMLHost.uex' path='docs/doc[@for="TridentSite.CreateDocument"]/*' />
356 /// Creates a new instance of mshtml and initializes it as a new document
357 /// using its IPersistStreamInit.
359 protected void CreateDocument() {
362 // Create an instance of Trident
363 tridentDocument = (NativeMethods.IHTMLDocument2)new NativeMethods.HTMLDocument();
364 tridentOleObject = (NativeMethods.IOleObject)tridentDocument;
366 // Initialize its client site
367 tridentOleObject.SetClientSite((NativeMethods.IOleClientSite)this);
370 NativeMethods.IPersistStreamInit psi = (NativeMethods.IPersistStreamInit)tridentDocument;
373 catch (Exception e) {
374 Debug.Fail(e.ToString());
379 /// <include file='doc\MSHTMLHost.uex' path='docs/doc[@for="TridentSite.ActivateDocument"]/*' />
381 /// Activates the mshtml instance
383 protected void ActivateDocument() {
384 Debug.Assert(tridentOleObject != null,
385 "How'd we get here when trident is null!");
388 NativeMethods.COMRECT r = new NativeMethods.COMRECT();
390 NativeMethods.GetClientRect(parentControl.Handle, r);
391 tridentOleObject.DoVerb(NativeMethods.OLEIVERB_UIACTIVATE, IntPtr.Zero, (NativeMethods.IOleClientSite)this, 0, parentControl.Handle, r);
393 catch (Exception e) {
394 Debug.Fail(e.ToString());