private TemplatedControlDesigner owner; // The owner templated control designer. /// <include file='doc\TemplateEditingFrame.uex' path='docs/doc[@for="TemplateEditingFrame.TemplateEditingFrame"]/*' /> /// <devdoc> /// <para> /// Initializes a new instance of the <see cref='System.Web.UI.Design.TemplateEditingFrame'/> class. /// </para> /// </devdoc> public TemplateEditingFrame(TemplatedControlDesigner owner, string frameName, string[] templateNames, Style controlStyle, Style[] templateStyles) { Debug.Assert(owner != null, "Null TemplatedControlDesigner as owner!"); Debug.Assert(frameName != null && frameName.Length > 0, "Invalid template editing frame name!"); Debug.Assert(templateNames != null && templateNames.Length > 0, "Invalid templates names!"); Debug.Assert(templateStyles == null || templateStyles.Length == templateNames.Length, "Invalid template styles"); this.owner = owner; this.frameName = frameName; this.controlStyle = controlStyle; this.templateStyles = templateStyles; this.verb = null; // Clone the template names passed in since the owner might change those dynamically. this.templateNames = (string[])templateNames.Clone(); if (owner.Behavior != null) { NativeMethods.IHTMLElement viewElement = (NativeMethods.IHTMLElement)((IControlDesignerBehavior)owner.Behavior).DesignTimeElementView; Debug.Assert(viewElement != null, "Invalid read-only HTML element associated to the control!"); this.htmlElemParent = viewElement; } this.htmlElemControlName = null; }
/* * protected internal bool GetBooleanAttribute(string attribute) * { * object o = GetAttribute(attribute); * * if (o == null) * { * return false; * } * * Debug.Assert(o is bool, "Attribute " + attribute + " is not of type Boolean"); * if (o is bool) * { * return (bool)o; * } * * return false; * } * * protected internal Color GetColorAttribute(string attribute) * { * string color = GetStringAttribute(attribute); * * if (color.Length == 0) * { * return Color.Empty; * } * else * { * return ColorTranslator.FromHtml(color); * } * } * * protected internal Enum GetEnumAttribute(string attribute, Enum defaultValue) * { * Type enumType = defaultValue.GetType(); * * object o = GetAttribute(attribute); * if (o == null) * { * return defaultValue; * } * * Debug.Assert(o is string, "Attribute " + attribute + " is not of type String"); * string s = o as string; * if ((s == null) || (s.Length == 0)) * { * return defaultValue; * } * * try * { * return (Enum)Enum.Parse(enumType, s, true); * } * catch * { * return defaultValue; * } * } * * protected internal int GetIntegerAttribute(string attribute, int defaultValue) * { * object o = GetAttribute(attribute); * * if (o == null) * { * return defaultValue; * } * if (o is int) * { * return (int)o; * } * if (o is short) * { * return (short)o; * } * if (o is string) * { * string s = (string)o; * if ((s.Length != 0) && (Char.IsDigit(s[0]))) * { * try * { * return Int32.Parse((string)o); * } * catch * { * } * } * } * * Debug.Fail("Attribute " + attribute + " is not an integer"); * return defaultValue; * } */ public HtmlElement GetChild(int index) { NativeMethods.IHTMLElementCollection children = (NativeMethods.IHTMLElementCollection) this.peer.GetChildren(); NativeMethods.IHTMLElement child = (NativeMethods.IHTMLElement)children.Item(null, index); return(new HtmlElement(child, this.owner)); }
/// <include file='doc\TemplateEditingService.uex' path='docs/doc[@for="TemplateEditingService.GetContainingTemplateName"]/*' /> public string GetContainingTemplateName(Control control) { string containingTemplateName = String.Empty; HtmlControlDesigner designer = (HtmlControlDesigner)designerHost.GetDesigner(control); if (designer != null) { IHtmlControlDesignerBehavior behavior = designer.Behavior; NativeMethods.IHTMLElement htmlElement = (NativeMethods.IHTMLElement)behavior.DesignTimeElement; if (htmlElement != null) { object[] varTemplateName = new Object[1]; NativeMethods.IHTMLElement htmlelemParentNext; NativeMethods.IHTMLElement htmlelemParentCur = htmlElement.GetParentElement(); while (htmlelemParentCur != null) { htmlelemParentCur.GetAttribute("templatename", /*lFlags*/ 0, varTemplateName); if (varTemplateName[0] != null && varTemplateName[0].GetType() == typeof(string)) { containingTemplateName = varTemplateName[0].ToString(); break; } htmlelemParentNext = htmlelemParentCur.GetParentElement(); htmlelemParentCur = htmlelemParentNext; } } } return(containingTemplateName); }
/// <include file='doc\TemplateEditingFrame.uex' path='docs/doc[@for="TemplateEditingFrame.Save"]/*' /> /// <devdoc> /// <para> /// Extracts the current contents for the marked template sections in the live tree, /// and notifies the designer with the updated contents for the individual templates. /// </para> /// </devdoc> public void Save() { try { if (templateElements != null) { object[] editable = new object[1]; for (int i = 0; i < templateNames.Length; i++) { if (templateElements[i] != null) { NativeMethods.IHTMLElement htmlElemTemplate = (NativeMethods.IHTMLElement)templateElements[i]; htmlElemTemplate.GetAttribute("contentEditable", /*lFlags*/ 0, editable); if ((editable[0] != null) && (editable[0] is string) && (String.Compare((string)editable[0], "true", true, CultureInfo.InvariantCulture) == 0)) { string templateContent = htmlElemTemplate.GetInnerHTML(); owner.SetTemplateContent(this, templateNames[i], templateContent); } } } } } catch (Exception ex) { Debug.Fail(ex.ToString()); } }
public HtmlElement GetChild(string name) { NativeMethods.IHTMLElementCollection children = (NativeMethods.IHTMLElementCollection) this.peer.GetChildren(); NativeMethods.IHTMLElement child = (NativeMethods.IHTMLElement)children.Item(name, null); return(new HtmlElement(child, this.owner)); }
/// <summary>Convenience method for checking if the specified element is absolutely positioned.</summary> /// <param name="elem"></param> /// <returns></returns> private bool IsElement2DPositioned(NativeMethods.IHTMLElement element) { NativeMethods.IHTMLElement2 elem2 = (NativeMethods.IHTMLElement2)element; NativeMethods.IHTMLCurrentStyle style = elem2.GetCurrentStyle(); string position = style.GetPosition(); return((position != null) && (position.ToLower() == "absolute")); }
/// <include file='doc\TemplateEditingFrame.uex' path='docs/doc[@for="TemplateEditingFrame.ReleaseParentElement"]/*' /> /// <devdoc> /// Release the frame HTML element, its parent element and the element containing /// the control name. /// </devdoc> private void ReleaseParentElement() { this.htmlElemParent = null; this.htmlElemFrame = null; this.htmlElemContent = null; this.htmlElemControlName = null; templateElements = null; fVisible = false; }
// Convenience method for checking if the specified element has a design time lock. private bool IsElementLocked(NativeMethods.IHTMLElement element) { object[] attribute = new object[1]; element.GetAttribute(DesignTimeLockAttribute, 0, attribute); if (attribute[0] == null) { NativeMethods.IHTMLStyle style = element.GetStyle(); attribute[0] = style.GetAttribute(DesignTimeLockAttribute, 0); } return((attribute[0] != null) && (attribute[0] is string)); }
public HtmlElement GetElementByID(string id) { NativeMethods.IHTMLElement body = this.site.Document.GetBody(); NativeMethods.IHTMLElementCollection children = (NativeMethods.IHTMLElementCollection)body.GetAll(); NativeMethods.IHTMLElement element = (NativeMethods.IHTMLElement)children.Item(id, 0); if (element == null) { return(null); } return(new HtmlElement(element, this)); }
/// <include file='doc\UserControlDesigner.uex' path='docs/doc[@for="ControlDesigner.RemoveSizeAttributes"]/*' /> /// <devdoc> /// <para> /// Maps the width, height, left and top style attributes to the respective properties /// on the web control. /// </para> /// </devdoc> private void RemoveSizeAttributes() { Debug.Assert(IsWebControl, "RemoveSizeAttributes should only be called for WebControls"); NativeMethods.IHTMLElement htmlElement = (NativeMethods.IHTMLElement)DesignTimeElement; if (htmlElement == null) { return; } NativeMethods.IHTMLStyle htmlStyle = htmlElement.GetStyle(); if (htmlStyle == null) { return; } try { string cssText = htmlStyle.GetCssText(); if (cssText == null || cssText.Equals(String.Empty)) { return; } WebControl control = (WebControl)Component; // Obtain the left, top and position style attributes from Trident. int width = htmlStyle.GetPixelWidth(); int height = htmlStyle.GetPixelHeight(); if (width > 0) { control.Width = width; htmlElement.SetAttribute("Width", width, 0); } if (height > 0) { control.Height = height; htmlElement.SetAttribute("Height", height, 0); } } catch (Exception ex) { Debug.Fail(ex.ToString()); } // Remove the width and height style attributes. htmlStyle.RemoveAttribute("width", /*lFlags*/ 0); htmlStyle.RemoveAttribute("height", /*lFlags*/ 0); }
private static void CreateControl() { if (null != _tridentControl && null != _htmlBody) { return; } _tridentControl = new MSHTMLHost(); _tridentControl.Size = new Size(CONTROL_WIDTH, CONTROL_HEIGHT); _tridentControl.CreateTrident(); _tridentControl.ActivateTrident(); NativeMethods.IHTMLDocument2 htmlDoc2 = _tridentControl.GetDocument(); _htmlBody = htmlDoc2.GetBody(); }
/// <devdoc> /// <para> /// Toggles the visibility of the frame either by placing it in the view-linked markup /// or by removing it from the live tree. /// </para> /// </devdoc> private void ShowInternal(bool fShow) { // Return immediately either if no frame HTML element exists or if the visibility // of the frame is the same as that of the requested state. if (htmlElemFrame == null || (this.fVisible == fShow)) { return; } // To show the frame, place it within the root view-linked element. // To hide the frame, remove it completely from the view-linked tree. try { NativeMethods.IHTMLDOMNode domNodeFrame = (NativeMethods.IHTMLDOMNode)htmlElemFrame; NativeMethods.IHTMLElement frameElement = (NativeMethods.IHTMLElement)domNodeFrame; NativeMethods.IHTMLStyle frameStyle = frameElement.GetStyle(); if (fShow) { frameStyle.SetDisplay(String.Empty); } else { // Clear the template contents when hiding the frame. This will ensure that // any controls within that template are removed from the designer host, etc. if (templateElements != null) { for (int i = 0; i < templateElements.Length; i++) { if (templateElements[i] != null) { NativeMethods.IHTMLElement htmlElemTemplate = (NativeMethods.IHTMLElement)templateElements[i]; htmlElemTemplate.SetInnerHTML(String.Empty); } } } frameStyle.SetDisplay("none"); } } catch (Exception ex) { Debug.Fail(ex.ToString()); } this.fVisible = fShow; }
internal static void ApplyStyle(String enterStyle, String exitStyle, String cssStyle) { MSHTMLHostUtil.CreateControl(); String bodyInnerHTML = "<div id=__divOuter nowrap style='width:1px; height:10px'>" + enterStyle + "<div id=__divInner" + cssStyle + "></div>" + exitStyle + "</div>"; // MessageBox.Show("Body HTML for empty content: " + bodyInnerHTML); _htmlBody.SetInnerHTML(bodyInnerHTML); NativeMethods.IHTMLDocument3 htmlDoc3 = (NativeMethods.IHTMLDocument3) _tridentControl.GetDocument(); Debug.Assert(null != htmlDoc3); _htmlDivInner = htmlDoc3.GetElementById("__divInner"); _htmlDivOuter = htmlDoc3.GetElementById("__divOuter"); Debug.Assert(null != _htmlDivOuter && null != _htmlDivInner); }
internal static void ApplyStyle(String enterStyle, String exitStyle, String cssStyle) { MSHTMLHostUtil.CreateControl(); String bodyInnerHTML = "<div id=__divOuter nowrap style='width:1px; height:10px'>" + enterStyle + "<div id=__divInner" + cssStyle + "></div>" + exitStyle + "</div>"; // MessageBox.Show("Body HTML for empty content: " + bodyInnerHTML); _htmlBody.SetInnerHTML(bodyInnerHTML); NativeMethods.IHTMLDocument3 htmlDoc3 = (NativeMethods.IHTMLDocument3)_tridentControl.GetDocument(); Debug.Assert(null != htmlDoc3); _htmlDivInner = htmlDoc3.GetElementById("__divInner"); _htmlDivOuter = htmlDoc3.GetElementById("__divOuter"); Debug.Assert(null != _htmlDivOuter && null != _htmlDivInner); }
/// <include file='doc\CalendarAutoFormatDialog.uex' path='docs/doc[@for="CalendarAutoFormatDialog.UpdateSchemePreview"]/*' /> /// <devdoc> /// Update scheme preview /// </devdoc> /// <internalonly/> private void UpdateSchemePreview() { // create a new calendar and apply the scheme to it Calendar wc = GetPreviewCalendar(); // CONSIDER: Its not safe to create a designer and associate it to // a control that is not site'd... // This should use the runtime control directly and call RenderControl instead. // get the design time HTML IDesigner designer = TypeDescriptor.CreateDesigner(wc, typeof(IDesigner)); designer.Initialize(wc); CalendarDesigner wcd = (CalendarDesigner)designer; string designHTML = wcd.GetDesignTimeHtml(); // and show it! NativeMethods.IHTMLDocument2 tridentDocument = schemePreview.GetDocument(); NativeMethods.IHTMLElement documentElement = tridentDocument.GetBody(); documentElement.SetInnerHTML(designHTML); }
public ArrayList GetParentHierarchy(object o) { NativeMethods.IHTMLElement current = this.GetHtmlElement(o); if (current == null) { return(null); } string tagName = current.GetTagName().ToLower(); if (tagName.Equals("body")) { return(null); } ArrayList ancestors = new ArrayList(); current = current.GetParentElement(); while ((current != null) && (current.GetTagName().ToLower().Equals("body") == false)) { HtmlElement element = new HtmlElement(current, this.control); if (IsSelectableElement(element)) { ancestors.Add(element); } current = current.GetParentElement(); } // Don't add the body tag to the hierarchy if we aren't in full document mode if (current != null) { HtmlElement element = new HtmlElement(current, this.control); if (IsSelectableElement(element)) { ancestors.Add(element); } } return(ancestors); }
protected override void OnTemplateModeChanged() { base.OnTemplateModeChanged(); if (InTemplateMode) { // Set xmlns in view linked document to show HTML intrinsic // controls in property grid with same schema used by // Intellisense for current choice tag in HTML view. NativeMethods.IHTMLElement htmlElement = (NativeMethods.IHTMLElement)((IControlDesignerBehavior)Behavior).DesignTimeElementView; Debug.Assert(htmlElement != null, "Invalid HTML element in MobileTemplateControlDesigner.OnTemplateModeChanged"); NativeMethods.IHTMLDocument2 htmlDocument2 = (NativeMethods.IHTMLDocument2)htmlElement.GetDocument(); Debug.Assert(htmlDocument2 != null, "Invalid HTML Document2 in MobileTemplateControlDesigner.OnTemplateModeChanged"); NativeMethods.IHTMLElement htmlBody = (NativeMethods.IHTMLElement)htmlDocument2.GetBody(); Debug.Assert(htmlBody != null, "Invalid HTML Body in MobileTemplateControlDesigner.OnTemplateModeChanged"); htmlBody.SetAttribute("xmlns", (Object)CurrentChoice.Xmlns, 0); } }
public void InsertHtml(string html) { this.Selection.SynchronizeSelection(); if (this.Selection.Type == HtmlSelectionType.ElementSelection) { //If it's a control range, we can only insert if we are in a div or td NativeMethods.IHtmlControlRange controlRange = (NativeMethods.IHtmlControlRange)Selection.Selection; int selectedItemCount = controlRange.GetLength(); if (selectedItemCount == 1) { NativeMethods.IHTMLElement element = controlRange.Item(0); if ((String.Compare(element.GetTagName(), "div", true) == 0) || (String.Compare(element.GetTagName(), "td", true) == 0)) { element.InsertAdjacentHTML("beforeEnd", html); } } } else { NativeMethods.IHTMLTxtRange textRange = (NativeMethods.IHTMLTxtRange)Selection.Selection; textRange.PasteHTML(html); } }
internal HtmlElement(NativeMethods.IHTMLElement peer, HtmlControl owner) { Debug.Assert(peer != null); this.peer = peer; this.owner = owner; }
/// <summary>Synchronizes the selection state held in this object with the selection state in MSHTML.</summary> /// <returns>true if the selection has changed</returns> public bool SynchronizeSelection() { if (this.document == null) { this.document = this.control.HtmlDocument; } NativeMethods.IHTMLSelectionObject selection = this.document.GetSelection(); object currentSelection = null; try { currentSelection = selection.CreateRange(); } catch { } ArrayList oldItems = this.items; HtmlSelectionType oldType = this.type; int oldLength = this.selectionLength; // Default to an empty selection this.type = HtmlSelectionType.Empty; this.selectionLength = 0; if (currentSelection != null) { this.selection = currentSelection; this.items = new ArrayList(); //If it's a text selection if (currentSelection is NativeMethods.IHTMLTxtRange) { NativeMethods.IHTMLTxtRange textRange = (NativeMethods.IHTMLTxtRange)currentSelection; NativeMethods.IHTMLElement parentElement = textRange.ParentElement(); // If the document is in full document mode or we're selecting a non-body tag, allow it to select // otherwise, leave the selection as empty (since we don't want the body tag to be selectable on an ASP.NET User Control) if (this.IsSelectableElement(new HtmlElement(parentElement, this.control))) { // Add the parent of the text selection if (parentElement != null) { this.text = textRange.GetText(); if (this.text != null) { this.selectionLength = this.text.Length; } else { this.selectionLength = 0; } this.type = HtmlSelectionType.TextSelection; this.items.Add(parentElement); } } } // If it is a control selection else if (currentSelection is NativeMethods.IHtmlControlRange) { NativeMethods.IHtmlControlRange controlRange = (NativeMethods.IHtmlControlRange)currentSelection; int selectedCount = controlRange.GetLength(); // Add all elements selected if (selectedCount > 0) { this.type = HtmlSelectionType.ElementSelection; for (int i = 0; i < selectedCount; i++) { NativeMethods.IHTMLElement currentElement = controlRange.Item(i); this.items.Add(currentElement); } this.selectionLength = selectedCount; } } } this.sameParentValid = false; bool selectionChanged = false; //Now check if there was a change of selection //If the two selections have different lengths, then the selection has changed if (this.type != oldType) { selectionChanged = true; } else if (this.selectionLength != oldLength) { selectionChanged = true; } else { if (this.items != null) { //If the two selections have a different element, then the selection has changed for (int i = 0; i < this.items.Count; i++) { if (this.items[i] != oldItems[i]) { selectionChanged = true; break; } } } } if (selectionChanged) { //Set this.elements to null so no one can retrieve a dirty copy of the selection element wrappers this.elements = null; OnSelectionChanged(EventArgs.Empty); return(true); } return(false); }
// /// <summary> // /// Sends all selected items to the back // /// </summary> // public void SendToBack() { // //TODO: How do we compress the ZIndexes so they never go out of the range of an int // SynchronizeSelection(); // if (this.type == HtmlSelectionType.ElementSelection) { // if (this.items.Count > 1) { // //We have to move all items to the back, and maintain their ordering, so // //Find the maximum ZIndex in the group // int max = _minZIndex; // int count = this.items.Count; // NativeMethods.IHTMLStyle[] styles = new NativeMethods.IHTMLStyle[count]; // int[] zIndexes = new int[count]; // for (int i = 0; i < count; i++) { // NativeMethods.IHTMLElement elem = (NativeMethods.IHTMLElement)this.items[i]; // styles[i] = elem.GetStyle(); // zIndexes[i] = (int)styles[i].GetZIndex(); // if (zIndexes[i] > max) { // max = zIndexes[i]; // } // } // //Calculate how far the first element has to be moved in order to be in the back // int offset = max - (_minZIndex - 1); // BatchedUndoUnit unit = this.control.OpenBatchUndo("Align Left"); // try { // //Then send all items in the selection that far back // for (int i = 0; i < count; i++) { // int newPos = zIndexes[i] - offset; // if (zIndexes[i] == _maxZIndex) { // _maxZIndex--; // } // styles[i].SetZIndex(newPos); // if (newPos < _minZIndex) { // _minZIndex = newPos; // } // } // } // catch (Exception e) { // System.Windows.Forms.MessageBox.Show(e.ToString(),"Exception"); // } // finally { // unit.Close(); // } // } // else { // NativeMethods.IHTMLElement elem = (NativeMethods.IHTMLElement)this.items[0]; // object zIndex = elem.GetStyle().GetZIndex(); // if ((zIndex != null) && !(zIndex is DBNull)) { // if ((int)zIndex == _minZIndex) { // // if the element is already in the back do nothing. // return; // } // // if ((int)zIndex == _maxZIndex) { // _maxZIndex--; // } // } // elem.GetStyle().SetZIndex(--_minZIndex); // } // } // } public void SetOuterHtml(string outerHtml) { Debug.Assert(Items.Count == 1, "Can't get OuterHtml of more than one element"); NativeMethods.IHTMLElement element = (NativeMethods.IHTMLElement) this.items[0]; element.SetOuterHTML(outerHtml); }
public bool SelectElements(ICollection elements) { NativeMethods.IHTMLElement body = this.control.HtmlDocument.GetBody(); NativeMethods.IHTMLTextContainer container = body as NativeMethods.IHTMLTextContainer; Debug.Assert(container != null); object controlRange = container.createControlRange(); NativeMethods.IHtmlControlRange htmlControlRange = controlRange as NativeMethods.IHtmlControlRange; Debug.Assert(htmlControlRange != null); if (htmlControlRange == null) { return(false); } NativeMethods.IHtmlControlRange2 htmlControlRange2 = controlRange as NativeMethods.IHtmlControlRange2; Debug.Assert(htmlControlRange2 != null); if (htmlControlRange2 == null) { return(false); } int hr = 0; foreach (object o in elements) { NativeMethods.IHTMLElement element = this.GetHtmlElement(o); if (element == null) { return(false); } hr = htmlControlRange2.addElement(element); if (hr != NativeMethods.S_OK) { break; } } if (hr == NativeMethods.S_OK) { //If it succeeded, simply select the control range htmlControlRange.Select(); } else { // elements like DIV and SPAN, w/o layout, cannot be added to a control selelction. NativeMethods.IHtmlBodyElement bodyElement = (NativeMethods.IHtmlBodyElement)body; NativeMethods.IHTMLTxtRange textRange = bodyElement.createTextRange(); if (textRange != null) { foreach (object o in elements) { try { NativeMethods.IHTMLElement element = this.GetHtmlElement(o); if (element == null) { return(false); } textRange.MoveToElementText(element); } catch { } } textRange.Select(); } } return(true); }
internal object CreateElementWrapper(NativeMethods.IHTMLElement element) { return(new HtmlElement(element, this.control)); }
/// <include file='doc\TemplateEditingFrame.uex' path='docs/doc[@for="TemplateEditingFrame.Open"]/*' /> /// <devdoc> /// <para> /// Opens this frame for editing in the designer. /// </para> /// </devdoc> public void Open() { NativeMethods.IHTMLElement ownerView = (NativeMethods.IHTMLElement)((IControlDesignerBehavior)owner.Behavior).DesignTimeElementView; Debug.Assert(ownerView != null, "Owner doesn't have an associated root view-linked HTML element"); // Reparent the frame when the root element of the view-link tree changes. if (this.htmlElemParent != ownerView) { ReleaseParentElement(); htmlElemParent = ownerView; } // Initialize the frame (will return immediately if already initialized). Initialize(); try { // Place the actual template content (by obtaining it from the owner) within the // marked template sections that are editable in the designer. for (int i = 0; i < templateNames.Length; i++) { if (templateElements[i] != null) { bool allowEditing = true; NativeMethods.IHTMLElement htmlElemTemplate = (NativeMethods.IHTMLElement)templateElements[i]; string templateContent = owner.GetTemplateContent(this, templateNames[i], out allowEditing); htmlElemTemplate.SetAttribute("contentEditable", allowEditing, /*lFlags*/ 0); if (templateContent != null) { // NOTE: (as/urt: 76317) Trident has this weird behavior, where it fails to use the // context available from htmlElemTemplate, and discards everything in // templateContent (such as <%# ... %>) until it finds some plain text or some // html content to create enough context info and conclude that it is parsing html. // // We can't have this data loss, and they can't fix their bug... so we'll // have to workaround it... typical! // Also note that when we save the template, trident does not return the // surrounding <body> tags, so we don't have to strip them out as part of // this workaround. // NOTE: (as/urt: 93784): IME's don't get enabled without the extra contentEditable. templateContent = "<body contentEditable=true>" + templateContent + "</body>"; htmlElemTemplate.SetInnerHTML(templateContent); } } } // Place the control name in the appropriate section if one was provided earlier // in the content. if (this.htmlElemControlName != null) { Debug.Assert(owner.Component != null && owner.Component.Site != null, "Invalid component or an invalid component site"); htmlElemControlName.SetInnerText(owner.Component.Site.Name); } } catch (Exception ex) { Debug.Fail(ex.ToString()); } // Finally make the frame visible by inserting it in the live HTML tree. ShowInternal(true); }
/// <summary> /// dynamically transform DeviceSpecific element to a server control, /// called from OnBehaviorAttached /// </summary> private void PrefixDeviceSpecificTags() { IHTMLElement htmlElement = (IHTMLElement)DesignTimeElementInternal; Debug.Assert(htmlElement != null, "Invalid HTML element in FormDesigner.OnBehaviorAttached"); IWebFormReferenceManager refMgr = (IWebFormReferenceManager)GetService(typeof(IWebFormReferenceManager)); Debug.Assert(refMgr != null, "Did not get back IWebFormReferenceManager service."); String tagPrefix = refMgr.GetTagPrefix(typeof(DeviceSpecific)); Debug.Assert(tagPrefix != null && tagPrefix.Length > 0, "TagPrefix is invalid"); IHTMLElementCollection allChildren = (IHTMLElementCollection)htmlElement.GetChildren(); if (null != allChildren) { bool substitutions = false; int nestingLevel = 0; String modifiedInnerHTML = String.Empty; for (Int32 i = 0; i < allChildren.GetLength(); i++) { IHTMLElement htmlChild = (IHTMLElement)allChildren.Item(i, 0); Debug.Assert(null != htmlChild, "htmlChild is null"); String childContent = htmlChild.GetOuterHTML(); String childUpperContent = childContent.ToUpper(CultureInfo.InvariantCulture); if (childContent.StartsWith("<", StringComparison.Ordinal) && !(childContent.StartsWith("</", StringComparison.Ordinal) || (childContent.EndsWith("/>", StringComparison.Ordinal)))) { if (!childUpperContent.StartsWith("<" + tagPrefix.ToUpper(CultureInfo.InvariantCulture) + ":", StringComparison.Ordinal)) { nestingLevel++; } } else if (childContent.StartsWith("</", StringComparison.Ordinal)) { nestingLevel--; } if (1 == nestingLevel && childUpperContent.StartsWith("<DEVICESPECIFIC", StringComparison.Ordinal) && childUpperContent.EndsWith(">", StringComparison.Ordinal)) { Debug.Assert(substitutions == false, "substitutions is true"); modifiedInnerHTML += "<" + tagPrefix + ":DeviceSpecific runat=\"server\">\r\n"; substitutions = true; } else if (1 == nestingLevel && childUpperContent.StartsWith("<DEVICESPECIFIC", StringComparison.Ordinal) && childUpperContent.EndsWith("/>", StringComparison.Ordinal)) { modifiedInnerHTML += "<" + tagPrefix + ":DeviceSpecific runat=\"server\"></" + tagPrefix + ":DeviceSpecific>\r\n"; substitutions = true; } else if (0 == nestingLevel && 0 == String.Compare(childUpperContent, "</DEVICESPECIFIC>", StringComparison.Ordinal)) { Debug.Assert(substitutions == true, "substitutions is false"); modifiedInnerHTML += "</" + tagPrefix + ":DeviceSpecific>\r\n"; } else { modifiedInnerHTML += childContent + "\r\n"; } } if (substitutions) { _shouldDirtyPage = true; htmlElement.SetInnerHTML(modifiedInnerHTML); } } }
/// <summary> /// Update scheme preview /// </summary> /// <internalonly/> private void UpdateSamplePreview() { if (_firstActivate) { return; } NativeMethods.IHTMLDocument2 tridentDocument = _samplePreview.GetDocument(); NativeMethods.IHTMLElement documentElement = tridentDocument.GetBody(); NativeMethods.IHTMLBodyElement bodyElement; bodyElement = (NativeMethods.IHTMLBodyElement)documentElement; bodyElement.SetScroll("no"); if (SelectedStyle == null) { documentElement.SetInnerHTML(String.Empty); tridentDocument.SetBgColor("buttonface"); return; } else { tridentDocument.SetBgColor(String.Empty); } bool cycle = ReferencesContainCycle(SelectedStyle); if (cycle) { documentElement.SetInnerHTML(String.Empty); return; } // apply the current Style to label ApplyStyle(); DesignerTextWriter tw = new DesignerTextWriter(); //ToolTip tw.AddAttribute("title", ((StyleNode)SelectedStyle).RuntimeStyle.Name); // ForeColor Color c = _previewStyle.ForeColor; if (!c.Equals(Color.Empty)) { tw.AddStyleAttribute("color", ColorTranslator.ToHtml(c)); } // BackColor c = _previewStyle.BackColor; if (!c.Equals(Color.Empty)) { tw.AddStyleAttribute("background-color", ColorTranslator.ToHtml(c)); } // Font Name String name = _previewStyle.Font.Name; if (!name.Equals(String.Empty)) { tw.AddStyleAttribute("font-family", name); } // Font Size switch (_previewStyle.Font.Size) { case FontSize.Large: tw.AddStyleAttribute("font-size", "Medium"); break; case FontSize.Small: tw.AddStyleAttribute("font-size", "X-Small"); break; default: tw.AddStyleAttribute("font-size", "Small"); break; } // Font Style if (_previewStyle.Font.Bold == BooleanOption.True) { tw.AddStyleAttribute("font-weight", "bold"); } if (_previewStyle.Font.Italic == BooleanOption.True) { tw.AddStyleAttribute("font-style", "italic"); } tw.RenderBeginTag("span"); tw.Write(SR.GetString(SR.StylesEditorDialog_PreviewText)); tw.RenderEndTag(); // and show it! String finalHTML = "<div align='center'><table width='100%' height='100%'><tr><td><p align='center'>" + tw.ToString() + "</p></td></tr></table></div>"; documentElement.SetInnerHTML(finalHTML); }
/// <include file='doc\TemplateEditingFrame.uex' path='docs/doc[@for="TemplateEditingFrame.Initialize"]/*' /> /// <devdoc> /// Initialize from content by creating the necessary HTML element tree structure, etc. /// </devdoc> private void Initialize() { if (this.htmlElemFrame != null) { return; } try { NativeMethods.IHTMLDocument2 htmlDocument = (NativeMethods.IHTMLDocument2)htmlElemParent.GetDocument(); // Create an HTML element that would represent the entire template frame. this.htmlElemFrame = htmlDocument.CreateElement("SPAN"); // Place the provided content within the frame htmlElemFrame.SetInnerHTML(this.Content); // Hold on to the top-level HTML element of the template frame content. NativeMethods.IHTMLDOMNode domNodeFrame = (NativeMethods.IHTMLDOMNode)htmlElemFrame; if (domNodeFrame != null) { this.htmlElemContent = (NativeMethods.IHTMLElement)domNodeFrame.GetFirstChild(); } // Mark the frame as not editable! NativeMethods.IHTMLElement3 htmlElement3 = (NativeMethods.IHTMLElement3)htmlElemFrame; if (htmlElement3 != null) { htmlElement3.SetContentEditable("false"); } // Create an array to hold the HTML elements representing the individual templates. templateElements = new object[templateNames.Length]; Object varName; Object varIndex = (int)0; NativeMethods.IHTMLElementCollection allCollection = (NativeMethods.IHTMLElementCollection)htmlElemFrame.GetAll(); // Obtain all the children of the frame and hold on to the ones representing the templates. for (int i = 0; i < templateNames.Length; i++) { try { varName = templateNames[i]; NativeMethods.IHTMLElement htmlElemTemplate = (NativeMethods.IHTMLElement)allCollection.Item(varName, varIndex); // Set an expando attribute (on the above HTML element) called "TemplateName" // which contains the name of the template it corresponds to. htmlElemTemplate.SetAttribute("templatename", varName, /*lFlags*/ 0); // Place an editable DIV within the individual templates. // This is needed in order for, say, TABLEs, TRs, TDs, etc., to be editable in a // view-linked markup. string editableDIV = "<DIV contentEditable=\"true\" style=\"padding:1;height:100%;width:100%\"></DIV>"; htmlElemTemplate.SetInnerHTML(editableDIV); // The first child of the template element will be the above editable SPAN. NativeMethods.IHTMLDOMNode domNodeTemplate = (NativeMethods.IHTMLDOMNode)htmlElemTemplate; if (domNodeTemplate != null) { templateElements[i] = domNodeTemplate.GetFirstChild(); } } catch (Exception ex) { Debug.Fail(ex.ToString()); templateElements[i] = null; } } // Hold on to the HTML element within which the control name should get displayed. // The presence of this element is optional. varName = "idControlName"; this.htmlElemControlName = (NativeMethods.IHTMLElement)allCollection.Item(varName, varIndex); // Retrieve the HTML element within which the template frame name should be displayed. // The presence of this element is optional. // We also don't hold on to it, since the name of the template frame can't be changed. varName = "idFrameName"; object objFrameName = allCollection.Item(varName, varIndex); if (objFrameName != null) { NativeMethods.IHTMLElement htmlElemFrameName = (NativeMethods.IHTMLElement)objFrameName; htmlElemFrameName.SetInnerText(frameName); } NativeMethods.IHTMLDOMNode domNodeParent = (NativeMethods.IHTMLDOMNode)htmlElemParent; if (domNodeParent == null) { return; } domNodeParent.AppendChild(domNodeFrame); } catch (Exception ex) { Debug.Fail(ex.ToString()); } }