Beispiel #1
0
        // 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));
        }
 /// <include file='doc\TemplateEditingFrame.uex' path='docs/doc[@for="TemplateEditingFrame.Resize"]/*' />
 /// <devdoc>
 ///    <para>
 ///       Resizes the
 ///       template editing frame.
 ///    </para>
 /// </devdoc>
 public void Resize(int width, int height)
 {
     if (htmlElemContent != null)
     {
         NativeMethods.IHTMLStyle htmlStyle = htmlElemContent.GetStyle();
         if (htmlStyle != null)
         {
             htmlStyle.SetPixelWidth(width);
             htmlStyle.SetPixelHeight(height);
         }
     }
 }
        /// <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);
        }
        /// <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;
        }
Beispiel #5
0
 /// <summary>Toggle the design time lock state of the selected items.</summary>
 public void ToggleLock()
 {
     //Switch the lock on each item
     foreach (NativeMethods.IHTMLElement element in this.items)
     {
         NativeMethods.IHTMLStyle style = element.GetStyle();
         if (IsElementLocked(element))
         {
             // We need to remove attributes off the element and the style because of a bug in Trident
             element.RemoveAttribute(DesignTimeLockAttribute, 0);
             style.RemoveAttribute(DesignTimeLockAttribute, 0);
         }
         else
         {
             //We need to add attributes to the element and the style because of a bug in Trident
             element.SetAttribute(DesignTimeLockAttribute, "true", 0);
             style.SetAttribute(DesignTimeLockAttribute, "true", 0);
         }
     }
 }