private bool InsertSmartContentFromLiveClipboard(ContentSourceInfo contentSource, XmlDocument lcDocument) { SmartContentSource smartSource = contentSource.Instance as SmartContentSource; if (smartSource == null) { Trace.Fail("Unexpected failure to get live clipboard content-source!"); return(false); } // create the smart content IExtensionData extensionData = _contentSourceSite.CreateExtensionData(Guid.NewGuid().ToString()); ISmartContent smartContent = new SmartContent(extensionData); if (smartSource.CreateContentFromLiveClipboard(EditorContext.FrameWindow, lcDocument, smartContent) == DialogResult.OK) { // generate html and insert it string content = smartSource.GenerateEditorHtml(smartContent, _contentSourceSite); if (content != null) { _contentSourceSite.InsertContent(contentSource.Id, content, extensionData); return(true); } else { return(false); } } else { return(false); } }
private bool InsertSmartContentFromEmbed(string embed) { ContentSourceInfo contentSource = ContentSourceManager.FindContentSource(typeof(VideoContentSource)); if (contentSource != null) { SmartContentSource smartSource = contentSource.Instance as SmartContentSource; VideoContentSource videoSource = smartSource as VideoContentSource; IExtensionData extensionData = _contentSourceSite.CreateExtensionData(Guid.NewGuid().ToString()); ISmartContent smartContent = new SmartContent(extensionData); videoSource.CreateContentFromEmbed(embed, smartContent); // generate html and insert it string content = videoSource.GenerateEditorHtml(smartContent, _contentSourceSite); if (content != null) { _contentSourceSite.InsertContent(VideoContentSource.ID, content, extensionData); return(true); } else { Trace.Fail("Video Source content generated from embed tag was empty"); return(false); } } Trace.Fail("Cannot find the video plugin"); return(false); }
private void PersistSelectedEditField(IHTMLElement editFieldElement) { SmartContent content = SmartContent; InlineEditField field = new InlineEditField(editFieldElement, content, EditorContext, HTMLElement, this); field.PersistFieldValueToContent(true); }
private void PersistAllEditFields() { SmartContent content = SmartContent; foreach (IHTMLElement el in EditFields) { InlineEditField field = new InlineEditField(el, content, EditorContext, HTMLElement, this); field.SetDefaultText(); field.PersistFieldValueToContent(false); } }
protected override void OnResizeStart(Size size, bool preserveAspectRatio) { _resizeUndo = EditorContext.CreateUndoUnit(); base.OnResizeStart(size, preserveAspectRatio); // save references _initialParentSize = size; _preserveAspectRatio = preserveAspectRatio; // initialize smart content string contentSourceId; string contentId; ContentSourceManager.ParseContainingElementId(HTMLElement.id, out contentSourceId, out contentId); // clone the smart content for resizing so that settings changes made during the resize //operation are undoable String newContentId = Guid.NewGuid().ToString(); SmartContent content = (SmartContent)_contentSourceContext.CloneSmartContent(contentId, newContentId); if (content == null) { Trace.WriteLine("Could not clone smart content for resize."); return; } HTMLElement.id = ContentSourceManager.MakeContainingElementId(contentSourceId, newContentId); // call sizer ResizeOptions resizeOptions = new ResizeOptions(); _contentSource.OnResizeStart(content, resizeOptions); // determine the target size IHTMLElement targetSizeElement = GetResizeTargetElement(resizeOptions.ResizeableElementId); _initialTargetSize = new Size(targetSizeElement.offsetWidth, targetSizeElement.offsetHeight); // Account for areas of the smart content that are not being scaled when preserving aspect ratio. // For example, in YouTube plugin, label text below the image. UpdateResizerAspectRatioOffset(_initialParentSize - _initialTargetSize); // determine the aspect ratio if (resizeOptions.AspectRatio > 0) { _aspectRatio = resizeOptions.AspectRatio; } else { _aspectRatio = ((double)_initialTargetSize.Width) / _initialTargetSize.Height; } }
private void PersistEditFieldValues() { SmartContent content = SmartContent; if (content == null) { return; } foreach (IHTMLElement el in EditFields) { InlineEditField field = new InlineEditField(el, content, EditorContext, HTMLElement, this); field.PersistFieldValueToContent(true); } }
protected override void OnElementAttached() { SmartContent content = SmartContent; if (content == null) { return; } ContentSourceInfo contentSourceInfo = _contentSourceContext.FindContentSource(ContentSourceId); _contentSource = contentSourceInfo.Instance as SmartContentSource; if (_contentSource != null && _contentSource.ResizeCapabilities != ResizeCapabilities.None) { Resizable = true; PreserveAspectRatio = ResizeCapabilities.PreserveAspectRatio == (_contentSource.ResizeCapabilities & ResizeCapabilities.PreserveAspectRatio); _realtimeResizing = ResizeCapabilities.LiveResize == (_contentSource.ResizeCapabilities & ResizeCapabilities.LiveResize); } else { Resizable = false; } EditorContext.CommandKey += new KeyEventHandler(EditorContext_CommandKey); EditorContext.DocumentEvents.DoubleClick += new HtmlEventHandler(EditorContext_DoubleClick); EditorContext.SelectionChanged += new EventHandler(EditorContext_SelectionChanged); EditorContext.PostEventNotify += new MshtmlEditor.EditDesignerEventHandler(EditorContext_PostEventNotify); EditorContext.CommandManager.BeforeExecute += new CommandManagerExecuteEventHandler(CommandManager_BeforeExecute); EditorContext.CommandManager.AfterExecute += new CommandManagerExecuteEventHandler(CommandManager_AfterExecute); EditorContext.HtmlInserted += new EventHandler(EditorContext_HtmlInserted); base.OnElementAttached(); foreach (IHTMLElement el in EditFields) { InlineEditField field = new InlineEditField(el, content, EditorContext, HTMLElement, this); if (!field.ContentEditable && EditorContext.EditMode) { field.ContentEditable = true; } field.SetDefaultText(); } }
private Size UpdateHtmlForResize(Size newSize, bool isComplete) { Size targetElementSize = newSize; if (_contentSource.ResizeCapabilities != ResizeCapabilities.None) { SmartContent content = SmartContent; //base the new size on target element preferred by the source //(apply the difference in size to the last known size of the target element) targetElementSize = new Size( Math.Max(1, _initialTargetSize.Width + (newSize.Width - _initialParentSize.Width)), Math.Max(1, _initialTargetSize.Height + (newSize.Height - _initialParentSize.Height)) ); if (_preserveAspectRatio) { targetElementSize = Utility.GetScaledMaxSize(_aspectRatio, targetElementSize.Width, targetElementSize.Height); } //let the resizer know about the new size, and regenerate the content if (isComplete) { _contentSource.OnResizeComplete(content, targetElementSize); } else { _contentSource.OnResizing(content, targetElementSize); } //insert the new content into the DOM (TODO: need undo support for this) SmartContentInsertionHelper.InsertEditorHtmlIntoElement(_contentSourceContext, _contentSource, content, HTMLElement); Invalidate(); if (_resizedListener != null) { _resizedListener(newSize, isComplete); } EditorContext.DamageServices.AddDamage(EditorContext.MarkupServices.CreateMarkupRange(HTMLElement, false)); } return(targetElementSize); }
private bool InsertSmartContentFromUrl(ContentSourceInfo contentSource, string url) { SmartContentSource smartSource = contentSource.Instance as SmartContentSource; string title = String.Empty; IExtensionData extensionData = _contentSourceSite.CreateExtensionData(Guid.NewGuid().ToString()); ISmartContent smartContent = new SmartContent(extensionData); if (UrlContentRetreivalWithProgress.ExecuteSmartContentRetreival( EditorContext.FrameWindow, contentSource, url, ref title, smartContent)) { string content = smartSource.GenerateEditorHtml(smartContent, _contentSourceSite); if (content != null) { _contentSourceSite.InsertContent(contentSource.Id, content, extensionData); } return(true); } else { return(false); } }