private SidebarControl GetSidebarForCurrentSelection(object selection) { IHtmlEditorSelection htmlSelection = selection as IHtmlEditorSelection; if (selection == null || (!htmlSelection.IsValid && !InlineEditField.IsEditField(selection))) { return(_defaultSidebarControl); } foreach (SidebarEntry sidebarEntry in _sidebars) { ISidebar sidebar = sidebarEntry.Sidebar; if (sidebar.AppliesToSelection(selection)) { SidebarControl sidebarControl = sidebarEntry.SidebarControl; if (sidebarControl == null) { // demand-create sidebar sidebarEntry.SidebarControl = CreateAndInitializeSidebar(sidebar); sidebarEntry.SidebarControl.Visible = sidebarEntry.SidebarControl.Controls.Count > 0; } return(sidebarEntry.SidebarControl); } } // got this far so no active sidebar for current selection return(_defaultSidebarControl); }
private bool IsValidInsertionPoint(IHTMLElement e, MarkupPointer p) { if (InlineEditField.IsEditField(p.CurrentScope)) { return(true); } IHTMLElement contentEditableParent = null; IHTMLElement parent = e; while (parent != null) { if ((parent as IHTMLElement3).isContentEditable) { contentEditableParent = parent; } else if (contentEditableParent != null) { break; //we hit the top-most editable parent. } parent = parent.parentElement; } if (contentEditableParent != null) { MarkupRange range = EditorContext.MarkupServices.CreateMarkupRange(contentEditableParent, false); return(range.InRange(p)); } else { return(false); } }
void EditorContext_SelectionChanged(object sender, EventArgs e) { if (Attached) { MarkupRange range = EditorContext.Selection.SelectedMarkupRange; IHTMLElement element = GetSelectedChildEditField(HTMLElement, range); if (element != null) { if (_findCommandExecuting) { return; } InlineEditField field = new InlineEditField(element, SmartContent, EditorContext, HTMLElement, this); field.ClearDefaultText(); field.PersistFieldValueToContent(true); } else { if (_checkSpellingCommandExecuting) { return; } PersistAllEditFields(); } } }
public static IHTMLElement GetSelectedChildEditField(IHTMLElement parent, MarkupRange selection) { if (selection == null || !selection.Positioned) { Trace.Fail("Selection is invalid!"); return(null); } IHTMLElement element = selection.ParentElement(); if (element == null || !HTMLElementHelper.IsChildOrSameElement(parent, element)) { return(null); } do { if (InlineEditField.IsEditField(element)) { return(element); } element = element.parentElement; } while (element != null && element.sourceIndex != parent.sourceIndex); return(null); }
private void PersistSelectedEditField(IHTMLElement editFieldElement) { SmartContent content = SmartContent; InlineEditField field = new InlineEditField(editFieldElement, content, EditorContext, HTMLElement, this); field.PersistFieldValueToContent(true); }
protected override bool DoInsertData(DataAction action, MarkupPointer begin, MarkupPointer end) { // get a reference to the underlying data object IDataObject dataObject = DataMeister.IDataObject; string dataObjectInstanceId = dataObject.GetData(SmartContentDataObject.INSTANCE_ID_DATAFORMAT) as string; if (EditorContext.EditorId.Equals(dataObjectInstanceId)) { // get the internal items out of the data object string smartContentElementId = (string)dataObject.GetData(SmartContentDataObject.INTERNAL_SMART_CONTENT_DATAFORMAT); IHTMLElement element = (EditorContext.HtmlDocument as IHTMLDocument3).getElementById(smartContentElementId); Debug.Assert(element != null, "Invalid smart content item id detected: " + smartContentElementId); if (element != null) { MarkupRange elementRange = EditorContext.MarkupServices.CreateMarkupRange(element, true); MarkupPointer insertionPoint = begin; MarkupPointerMoveHelper.PerformImageBreakout(insertionPoint); insertionPoint.PushCling(false); insertionPoint.PushGravity(_POINTER_GRAVITY.POINTER_GRAVITY_Left); //verify the insertion point is inside of the same content editable parent (bug 290729) if (!IsValidInsertionPoint(element, insertionPoint)) { return(false); } try { if (InlineEditField.IsEditField(insertionPoint.CurrentScope)) { // If we are in an edit field, since we strip the content wdown to plain text we have to use // InsertHtml. However, this means we need to move the content via a string. This sucks because // we break any markup ranges in that area. This is why ignore once will not work in edit fields. EditorContext.MarkupServices.Remove(begin, end); string html = elementRange.HtmlText; EditorContext.MarkupServices.Remove(elementRange.Start, elementRange.End); EditorContext.InsertHtml(insertionPoint, insertionPoint, html, null); } else { EditorContext.MarkupServices.Remove(begin, end); EditorContext.MarkupServices.Move(elementRange.Start, elementRange.End, insertionPoint); } return(true); } finally { insertionPoint.PopCling(); insertionPoint.PopGravity(); } } } return(false); }
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); } }
private void SelectElement(IHTMLElement element) { PersistEditFieldValues(); InlineEditField field = new InlineEditField(element, SmartContent, EditorContext, HTMLElement, this); field.ClearDefaultText(); MarkupRange range = EditorContext.MarkupServices.CreateMarkupRange(element, false); range.ToTextRange().select(); }
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(); } }
public override void UpdateView(object htmlSelection, bool force) { if (htmlSelection == null) //true when the a non-smartcontent element is selected { //reset the selected smart content (fixes bug 492456) _selectedElement = null; _selectedSmartContentId = null; UnloadCurrentEditor(); return; } Debug.Assert(htmlSelection is SmartContentSelection || (htmlSelection is IHtmlEditorSelection && InlineEditField.IsEditField(htmlSelection))); IHTMLElement selectedElement = null; SmartContentSelection smartContentSelection = htmlSelection as SmartContentSelection; if (smartContentSelection != null && smartContentSelection.ContentState == SmartContentState.Enabled) { selectedElement = smartContentSelection.HTMLElement; } else if (htmlSelection is IHtmlEditorSelection) { selectedElement = ContentSourceManager.GetContainingSmartContent( ((IHtmlEditorSelection)(htmlSelection)).SelectedMarkupRange.ParentElement()); } _currentSelection = htmlSelection; if (selectedElement != null) { //if the selected element id is still the same, then the sidebar is currently //in synch with the smart content. //Note: the element id will change each time an edit is made to the smart content if (!force && _selectedElement != null && _selectedSmartContentId != null && selectedElement.id == _selectedSmartContentId) { return; } else { _selectedElement = selectedElement; _selectedSmartContentId = selectedElement.id; if (_currentEditor != null) { UnloadCurrentEditor(); } } ContentSourceManager.ParseContainingElementId(_selectedElement.id, out _contentSourceId, out _contentItemId); SmartContentEditor editor = (SmartContentEditor)_contentSourceControls[_contentSourceId]; ContentSourceInfo contentSource = _contentSourceContext.FindContentSource(_contentSourceId); if (contentSource != null && contentSource.Instance is SmartContentSource) { _contentSource = (SmartContentSource)contentSource.Instance; if (_editableSmartContent != null) { _editableSmartContent.Dispose(); } _editableSmartContent = new EditableSmartContent(_contentSourceContext, _contentSource, _selectedElement); if (editor == null) { editor = _contentSource.CreateEditor(this); if (editor is IActiveSmartContentEditor) { ((IActiveSmartContentEditor)editor).ForceContentEdited += new EventHandler(ContentSourceSidebarControl_ForceContentEdited); } //apply the current scale the new control if (editor != null) { editor.Scale(new SizeF(scale.Width, scale.Height)); } _contentSourceControls[_contentSourceId] = editor; } if (editor != null) { editor.ContentEdited += new EventHandler(_editor_ContentEdited); editor.SelectedContent = _editableSmartContent; EnableableSmartContentEditor enableableSmartContentEditor = editor as EnableableSmartContentEditor; if (enableableSmartContentEditor != null) { enableableSmartContentEditor.ContentEnabled = true; } if (editor != _currentEditor) { if (enableableSmartContentEditor != null) { Controls.Clear(); } else { //load the new editor editor.Dock = DockStyle.Fill; editor.Width = Width - DockPadding.Left - DockPadding.Right; this.Controls.Add(editor); } // set the title caption // Text = String.Format( CultureInfo.CurrentCulture, Res.Get(StringId.PluginSidebarTitle), contentSource.InsertableContentSourceSidebarText ) ; } } } _currentEditor = editor; } else { _currentEditor = null; } }
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); } }
void EditorContext_SelectionChanged(object sender, EventArgs e) { if (Attached) { MarkupRange range = EditorContext.Selection.SelectedMarkupRange; IHTMLElement element = GetSelectedChildEditField(HTMLElement, range); if (element != null) { if (_findCommandExecuting) return; InlineEditField field = new InlineEditField(element, SmartContent, EditorContext, HTMLElement, this); field.ClearDefaultText(); field.PersistFieldValueToContent(true); } else { if (_checkSpellingCommandExecuting) return; PersistAllEditFields(); } } }
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(); } }
protected override int HandlePreHandleEvent(int inEvtDispId, IHTMLEventObj pIEventObj) { if (ShouldProcessEvents(inEvtDispId, pIEventObj)) { IHTMLElement el = pIEventObj.srcElement; if (el != null && InlineEditField.IsWithinEditField(el)) { return(HRESULT.S_FALSE); } if (inEvtDispId == DISPID_HTMLELEMENTEVENTS2.ONBEFOREDEACTIVATE) { return(HRESULT.S_FALSE); } // Allow selection of smart content via mouse click when child edit field is selected. if (inEvtDispId == DISPID_HTMLELEMENTEVENTS2.ONMOUSEDOWN) { leftMouseDown = (Control.MouseButtons & MouseButtons.Left) == MouseButtons.Left; if (Selected && IsChildEditFieldSelected(HTMLElement, EditorContext.Selection.SelectedMarkupRange)) { PersistEditFieldValues(); return(HandlePreHandleEventLeftMouseButtonDown(inEvtDispId, pIEventObj)); } } else if (inEvtDispId == DISPID_HTMLELEMENTEVENTS2.ONMOUSEUP && leftMouseDown) { // Is there a click handler to execute? string clickCommand = pIEventObj.srcElement.getAttribute(CLICK_HANDLER, 0) as string; if (!String.IsNullOrEmpty(clickCommand)) { try { // Only allow click handlers on our built in content sources string contentSourceId = ContentSourceId; foreach (var v in ContentSourceManager.BuiltInContentSources) { if (v.Id == contentSourceId) { int result = base.HandlePreHandleEvent(inEvtDispId, pIEventObj); CommandId commandId = (CommandId)Enum.Parse(typeof(CommandId), clickCommand, true); EditorContext.CommandManager.Get(commandId).PerformExecuteWithArgs(new ExecuteEventHandlerArgs()); return(result); } } } catch (Exception ex) { if (ex is ArgumentException || ex is OverflowException || ex is ArgumentNullException) { Debug.Fail("Failed to parse clickHandler: " + ex); } else { throw; } } } } // Allow the selected edit field to receive keyboard events when the mouse is within // the smart content but outside of the edit field. if ((inEvtDispId == DISPID_HTMLELEMENTEVENTS2.ONKEYPRESS) && IsChildEditFieldSelected(HTMLElement, EditorContext.Selection.SelectedMarkupRange)) { return(HRESULT.S_FALSE); } } else if (Selected && IsChildEditFieldSelected(HTMLElement, EditorContext.Selection.SelectedMarkupRange)) { if (pIEventObj.cancelBubble) { return(HRESULT.S_FALSE); } } return(base.HandlePreHandleEvent(inEvtDispId, pIEventObj)); }
public bool AppliesToSelection(object selection) { if (selection is SmartContentSelection || (selection is IHtmlEditorSelection && InlineEditField.IsEditField(selection))) { SmartContentSelection smartContentSelection = selection as SmartContentSelection; if (smartContentSelection != null && smartContentSelection.ContentState == SmartContentState.Preserve) { return(false); } return(true); } else { return(false); } }