Пример #1
0
        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));
        }
Пример #2
0
        /*
         * 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));
        }
Пример #3
0
        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));
        }
Пример #4
0
        /// <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);
                }
            }
        }
        /// <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());
            }
        }