1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
|
//------------------------------------------------------------------------------
// <copyright file="MSHTMLHost.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
// MSHTMLHost.cs
//
// 12/17/98: Created: Microsoft
//
namespace System.Web.UI.Design.MobileControls.Util {
using System.Runtime.Serialization.Formatters;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Diagnostics;
using System;
using Microsoft.Win32;
using System.Windows.Forms;
/// <include file='doc\MSHTMLHost.uex' path='docs/doc[@for="MSHTMLHost"]/*' />
/// <devdoc>
/// Control that hosts a Trident DocObject.
/// </devdoc>
/// <internalonly/>
//
[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)]
[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.")]
internal sealed class MSHTMLHost : Control {
private TridentSite tridentSite;
internal MSHTMLHost() : base() {
}
public NativeMethods.IHTMLDocument2 GetDocument() {
Debug.Assert(tridentSite != null,
"Cannot call getDocument before calling createTrident");
return tridentSite.GetDocument();
}
protected override CreateParams CreateParams {
get {
CreateParams cp = base.CreateParams;
cp.ExStyle |= NativeMethods.WS_EX_STATICEDGE;
return cp;
}
}
internal bool CreateTrident() {
Debug.Assert(Handle != IntPtr.Zero,
"MSHTMLHost must first be created before createTrident is called");
try {
tridentSite = new TridentSite(this);
}
catch (Exception e) {
Debug.WriteLine("Exception caught in MSHTMLHost::CreateTrident\n\t" + e.ToString());
return false;
}
return true;
}
internal void ActivateTrident() {
Debug.Assert(tridentSite != null,
"cannot call activateTrident before calling createTrident");
tridentSite.Activate();
}
}
/// <include file='doc\MSHTMLHost.uex' path='docs/doc[@for="TridentSite"]/*' />
/// <devdoc>
/// Implements the client site for Trident DocObject
/// </devdoc>
[ClassInterface(ClassInterfaceType.None)]
[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.")]
internal class TridentSite : NativeMethods.IOleClientSite, NativeMethods.IOleDocumentSite, NativeMethods.IOleInPlaceSite, NativeMethods.IOleInPlaceFrame, NativeMethods.IDocHostUIHandler {
protected Control parentControl;
protected NativeMethods.IOleDocumentView tridentView;
protected NativeMethods.IOleObject tridentOleObject;
protected NativeMethods.IHTMLDocument2 tridentDocument;
protected EventHandler resizeHandler;
internal TridentSite(Control parent) {
Debug.Assert((parent != null) && (parent.Handle != IntPtr.Zero),
"Invalid control passed in as parent of Trident window");
parentControl = parent;
resizeHandler = new EventHandler(this.OnParentResize);
parentControl.Resize += resizeHandler;
CreateDocument();
}
public NativeMethods.IHTMLDocument2 GetDocument() {
return tridentDocument;
}
internal void Activate() {
ActivateDocument();
}
protected virtual void OnParentResize(object src, EventArgs e) {
if (tridentView != null) {
NativeMethods.COMRECT r = new NativeMethods.COMRECT();
NativeMethods.GetClientRect(parentControl.Handle, r);
tridentView.SetRect(r);
}
}
///////////////////////////////////////////////////////////////////////////
// IOleClientSite Implementation
public virtual void SaveObject() {
}
public virtual object GetMoniker(int dwAssign, int dwWhichMoniker) {
throw new COMException(String.Empty, NativeMethods.E_NOTIMPL);
}
public virtual int GetContainer(out NativeMethods.IOleContainer ppContainer) {
ppContainer = null;
return NativeMethods.E_NOINTERFACE;
}
public virtual void ShowObject() {
}
public virtual void OnShowWindow(int fShow) {
}
public virtual void RequestNewObjectLayout() {
}
///////////////////////////////////////////////////////////////////////////
// IOleDocumentSite Implementation
public virtual int ActivateMe(NativeMethods.IOleDocumentView pViewToActivate) {
Debug.Assert(pViewToActivate != null,
"Expected the view to be non-null");
if (pViewToActivate == null)
return NativeMethods.E_INVALIDARG;
NativeMethods.COMRECT r = new NativeMethods.COMRECT();
NativeMethods.GetClientRect(parentControl.Handle, r);
tridentView = pViewToActivate;
tridentView.SetInPlaceSite((NativeMethods.IOleInPlaceSite)this);
tridentView.UIActivate(1);
tridentView.SetRect(r);
tridentView.Show(1);
return NativeMethods.S_OK;
}
///////////////////////////////////////////////////////////////////////////
// IOleInPlaceSite Implementation
public virtual IntPtr GetWindow() {
return parentControl.Handle;
}
public virtual void ContextSensitiveHelp(int fEnterMode) {
throw new COMException(String.Empty, NativeMethods.E_NOTIMPL);
}
public virtual int CanInPlaceActivate() {
return NativeMethods.S_OK;
}
public virtual void OnInPlaceActivate() {
}
public virtual void OnUIActivate() {
}
public virtual void GetWindowContext(out NativeMethods.IOleInPlaceFrame ppFrame, out NativeMethods.IOleInPlaceUIWindow ppDoc, NativeMethods.COMRECT lprcPosRect, NativeMethods.COMRECT lprcClipRect, NativeMethods.tagOIFI lpFrameInfo) {
ppFrame = (NativeMethods.IOleInPlaceFrame)this;
ppDoc = null;
NativeMethods.GetClientRect(parentControl.Handle, lprcPosRect);
NativeMethods.GetClientRect(parentControl.Handle, lprcClipRect);
lpFrameInfo.cb = System.Runtime.InteropServices.Marshal.SizeOf(typeof(NativeMethods.tagOIFI));
lpFrameInfo.fMDIApp = 0;
lpFrameInfo.hwndFrame = parentControl.Handle;
lpFrameInfo.hAccel = IntPtr.Zero;
lpFrameInfo.cAccelEntries = 0;
}
public virtual int Scroll(NativeMethods.tagSIZE scrollExtant) {
return(NativeMethods.E_NOTIMPL);
}
public virtual void OnUIDeactivate(int fUndoable) {
// NOTE, Microsoft, 7/99: Don't return E_NOTIMPL. Somehow doing nothing and returning S_OK
// fixes trident hosting in Win2000.
}
public virtual void OnInPlaceDeactivate() {
}
public virtual void DiscardUndoState() {
throw new COMException(SR.GetString(SR.MSHTMLHost_Not_Implemented), NativeMethods.E_NOTIMPL);
}
public virtual void DeactivateAndUndo() {
}
public virtual int OnPosRectChange(NativeMethods.COMRECT lprcPosRect) {
return NativeMethods.S_OK;
}
///////////////////////////////////////////////////////////////////////////
// IOleInPlaceFrame Implementation
public virtual void GetBorder(NativeMethods.COMRECT lprectBorder) {
throw new COMException(String.Empty, NativeMethods.E_NOTIMPL);
}
public virtual void RequestBorderSpace(NativeMethods.COMRECT pborderwidths) {
throw new COMException(String.Empty, NativeMethods.E_NOTIMPL);
}
public virtual void SetBorderSpace(NativeMethods.COMRECT pborderwidths) {
throw new COMException(String.Empty, NativeMethods.E_NOTIMPL);
}
public virtual void SetActiveObject(NativeMethods.IOleInPlaceActiveObject pActiveObject, string pszObjName) {
// NOTE, Microsoft, 7/99: Don't return E_NOTIMPL. Somehow doing nothing and returning S_OK
// fixes trident hosting in Win2000.
// throw new COMException(String.Empty, NativeMethods.E_NOTIMPL);
}
public virtual void InsertMenus(IntPtr hmenuShared, object lpMenuWidths) {
throw new COMException(String.Empty, NativeMethods.E_NOTIMPL);
}
public virtual void SetMenu(IntPtr hmenuShared, IntPtr holemenu, IntPtr hwndActiveObject) {
throw new COMException(String.Empty, NativeMethods.E_NOTIMPL);
}
public virtual void RemoveMenus(IntPtr hmenuShared) {
throw new COMException(String.Empty, NativeMethods.E_NOTIMPL);
}
public virtual void SetStatusText(string pszStatusText) {
}
public virtual void EnableModeless(int fEnable) {
}
public virtual int TranslateAccelerator(ref NativeMethods.MSG lpmsg, short wID) {
return NativeMethods.S_FALSE;
}
///////////////////////////////////////////////////////////////////////////
// IDocHostUIHandler Implementation
public virtual int ShowContextMenu(int dwID, NativeMethods.POINT pt, object pcmdtReserved, object pdispReserved) {
return NativeMethods.S_OK;
}
public virtual int GetHostInfo(NativeMethods.DOCHOSTUIINFO info) {
info.dwDoubleClick = NativeMethods.DOCHOSTUIDBLCLICK.DEFAULT;
info.dwFlags = NativeMethods.DOCHOSTUIFLAG.FLAT_SCROLLBAR |
NativeMethods.DOCHOSTUIFLAG.NO3DBORDER |
NativeMethods.DOCHOSTUIFLAG.DIALOG |
NativeMethods.DOCHOSTUIFLAG.DISABLE_SCRIPT_INACTIVE;
return NativeMethods.S_OK;
}
public virtual int EnableModeless(bool fEnable) {
return NativeMethods.S_OK;
}
public virtual int ShowUI(int dwID, NativeMethods.IOleInPlaceActiveObject activeObject, NativeMethods.IOleCommandTarget commandTarget, NativeMethods.IOleInPlaceFrame frame, NativeMethods.IOleInPlaceUIWindow doc) {
return NativeMethods.S_OK;
}
public virtual int HideUI() {
return NativeMethods.S_OK;
}
public virtual int UpdateUI() {
return NativeMethods.S_OK;
}
public virtual int OnDocWindowActivate(bool fActivate) {
return NativeMethods.E_NOTIMPL;
}
public virtual int OnFrameWindowActivate(bool fActivate) {
return NativeMethods.E_NOTIMPL;
}
public virtual int ResizeBorder(NativeMethods.COMRECT rect, NativeMethods.IOleInPlaceUIWindow doc, bool fFrameWindow) {
return NativeMethods.E_NOTIMPL;
}
public virtual int GetOptionKeyPath(string[] pbstrKey, int dw) {
pbstrKey[0] = null;
return NativeMethods.S_OK;
}
public virtual int GetDropTarget(NativeMethods.IOleDropTarget pDropTarget, out NativeMethods.IOleDropTarget ppDropTarget) {
ppDropTarget = null;
return NativeMethods.S_FALSE;
}
public virtual int GetExternal(out object ppDispatch) {
ppDispatch = null;
return NativeMethods.S_OK;
}
public virtual int TranslateAccelerator(ref NativeMethods.MSG msg, ref Guid group, int nCmdID) {
return NativeMethods.S_OK;
}
public virtual int TranslateUrl(int dwTranslate, string strUrlIn, out string pstrUrlOut) {
pstrUrlOut = null;
return NativeMethods.E_NOTIMPL;
}
public virtual int FilterDataObject(NativeMethods.IOleDataObject pDO, out NativeMethods.IOleDataObject ppDORet) {
ppDORet = null;
return NativeMethods.S_OK;
}
///////////////////////////////////////////////////////////////////////////
// Implementation
/// <include file='doc\MSHTMLHost.uex' path='docs/doc[@for="TridentSite.CreateDocument"]/*' />
/// <devdoc>
/// Creates a new instance of mshtml and initializes it as a new document
/// using its IPersistStreamInit.
/// </devdoc>
protected void CreateDocument() {
try {
// Create an instance of Trident
tridentDocument = (NativeMethods.IHTMLDocument2)new NativeMethods.HTMLDocument();
tridentOleObject = (NativeMethods.IOleObject)tridentDocument;
// Initialize its client site
tridentOleObject.SetClientSite((NativeMethods.IOleClientSite)this);
// Initialize it
NativeMethods.IPersistStreamInit psi = (NativeMethods.IPersistStreamInit)tridentDocument;
psi.InitNew();
}
catch (Exception e) {
Debug.Fail(e.ToString());
throw e;
}
}
/// <include file='doc\MSHTMLHost.uex' path='docs/doc[@for="TridentSite.ActivateDocument"]/*' />
/// <devdoc>
/// Activates the mshtml instance
/// </devdoc>
protected void ActivateDocument() {
Debug.Assert(tridentOleObject != null,
"How'd we get here when trident is null!");
try {
NativeMethods.COMRECT r = new NativeMethods.COMRECT();
NativeMethods.GetClientRect(parentControl.Handle, r);
tridentOleObject.DoVerb(NativeMethods.OLEIVERB_UIACTIVATE, IntPtr.Zero, (NativeMethods.IOleClientSite)this, 0, parentControl.Handle, r);
}
catch (Exception e) {
Debug.Fail(e.ToString());
}
}
}
}
|