/// <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; }
/// <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()); } }