internal static void SetStandardStyleAttributes(IHtmlControlDesignerBehavior behavior,
                                                        ContainmentStatus containmentStatus)
        {
            if (behavior == null)
            {
                return;
            }

            bool controlAtTopLevel = (containmentStatus == ContainmentStatus.AtTopLevel);

            Color cw = SystemColors.Window;
            Color ct = SystemColors.WindowText;
            Color c  = Color.FromArgb((Int16)(ct.R * 0.1 + cw.R * 0.9),
                                      (Int16)(ct.G * 0.1 + cw.G * 0.9),
                                      (Int16)(ct.B * 0.1 + cw.B * 0.9));

            behavior.SetStyleAttribute("borderColor", true, ColorTranslator.ToHtml(c), true);
            behavior.SetStyleAttribute("borderStyle", true, "solid", true);

            behavior.SetStyleAttribute("borderWidth", true, "1px", true);
            behavior.SetStyleAttribute("marginLeft", true, "5px", true);
            behavior.SetStyleAttribute("marginRight", true, controlAtTopLevel ? "30%" : "5px", true);
            behavior.SetStyleAttribute("marginTop", true, controlAtTopLevel ? "5px" : "2px", true);
            behavior.SetStyleAttribute("marginBottom", true, controlAtTopLevel ? "5px" : "2px", true);
        }
        internal static String GetDesignTimeErrorHtml(
            String errorMessage,
            bool infoMode,
            Control control,
            IHtmlControlDesignerBehavior behavior,
            ContainmentStatus containmentStatus)
        {
            String id = String.Empty;

            Debug.Assert(control != null, "control is null");

            if (control.Site != null)
            {
                id = control.Site.Name;
            }

            if (behavior != null)
            {
                behavior.SetStyleAttribute("borderWidth", true, "0px", true);
            }

            return(String.Format(CultureInfo.CurrentCulture,
                                 MobileControlDesigner.defaultErrorDesignTimeHTML,
                                 new Object[]
            {
                control.GetType().Name,
                id,
                errorMessage,
                infoMode? MobileControlDesigner.infoIcon : MobileControlDesigner.errorIcon,
                ((containmentStatus == ContainmentStatus.AtTopLevel) ?
                 Constants.ControlSizeAtToplevelInErrormode :
                 Constants.ControlSizeInContainer)
            }));
        }
Beispiel #3
0
        /// <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);
        }
Beispiel #4
0
        /// <summary>
        ///    <para>
        ///       Notification that is called when the designer is attached to the behavior.
        ///    </para>
        /// </summary>
        protected override void OnBehaviorAttached()
        {
            Debug.Assert(_cachedBehavior == null);
            _cachedBehavior = Behavior;

            PrefixDeviceSpecificTags();
            base.OnBehaviorAttached();

            // Reload the original state if an old Behavior is cached.
            if (_hasAttributesCached)
            {
                ReloadBehaviorState();
            }
        }
        /// <include file='doc\UserControlDesigner.uex' path='docs/doc[@for="ControlDesigner.UpdateDesignTimeHtml"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Updates the design time HTML.
        ///    </para>
        /// </devdoc>
        public virtual void UpdateDesignTimeHtml()
        {
            if (IsWebControl && fRemoveInitialSize)
            {
                fRemoveInitialSize = false;
                RemoveSizeAttributes();
            }

            IHtmlControlDesignerBehavior behavior = Behavior;

            if (behavior != null && ReadOnly)
            {
                Debug.Assert(behavior is IControlDesignerBehavior, "Unexpected type of behavior for custom control");
                ((IControlDesignerBehavior)behavior).DesignTimeHtml = GetDesignTimeHtml();
            }
        }
Beispiel #6
0
        protected override void OnBindingsCollectionChanged(string propName)
        {
            // This method actually forms an DataBindingExpression of the design time and associates it to the Property of the Control.
            IHtmlControlDesignerBehavior myHtmlControlDesignBehavior = Behavior;
            DataBindingCollection        myDataBindingCollection;
            DataBinding myDataBinding1, myDataBinding2;
            String      myStringReplace1, myDataBindingExpression1, removedBinding, removedBindingAfterReplace, myDataBindingExpression2, myStringReplace2;

            string[]    removedBindings1, removedBindings2;
            Int32       temp;
            IEnumerator myEnumerator;

            if (myHtmlControlDesignBehavior == null)
            {
                return;
            }
// <Snippet8>
            DataBindingCollection myDataBindingCollection1 = new DataBindingCollection();

            myDataBindingCollection1 = myDataBindingCollection = DataBindings;
// </Snippet8>

            if (propName != null)
            {
                myDataBinding1   = myDataBindingCollection[propName];
                myStringReplace1 = propName.Replace(".", "-");
                if (myDataBinding1 == null)
                {
                    myHtmlControlDesignBehavior.RemoveAttribute(myStringReplace1, true);
                    return;
                }
                // DataBinding is not null.
                myDataBindingExpression1 = String.Concat("<%#", myDataBinding1.Expression, "%>");
                myHtmlControlDesignBehavior.SetAttribute(myStringReplace1, myDataBindingExpression1, true);
                int index = myStringReplace1.IndexOf("-");
            }
            else
            {
// <Snippet9>
                removedBindings2 = removedBindings1 = DataBindings.RemovedBindings;
// </Snippet9>
                temp = 0;
                while (removedBindings2.Length > temp)
                {
                    removedBinding             = removedBindings2[temp];
                    removedBindingAfterReplace = removedBinding.Replace('.', '-');
                    myHtmlControlDesignBehavior.RemoveAttribute(removedBindingAfterReplace, true);
                    temp = temp + 1;
                }
// <Snippet10>
                myDataBindingCollection = DataBindings;
                myEnumerator            = myDataBindingCollection.GetEnumerator();
                while (myEnumerator.MoveNext())
                {
// <Snippet11>
// <Snippet12>
                    myDataBinding2 = (DataBinding)myEnumerator.Current;
                    String dataBindingOutput1, dataBindingOutput2, dataBindingOutput3;
                    dataBindingOutput1 = String.Concat("The property name is ", myDataBinding2.PropertyName);
                    dataBindingOutput2 = String.Concat("The property type is ", myDataBinding2.PropertyType.ToString(), "-", dataBindingOutput1);
                    dataBindingOutput3 = String.Concat("The expression is ", myDataBinding2.Expression, "-", dataBindingOutput2);
                    WriteToFile(dataBindingOutput3);
// </Snippet12>
// </Snippet11>
                    myDataBindingExpression2 = String.Concat("<%#", myDataBinding2.Expression, "%>");
                    myStringReplace2         = myDataBinding2.PropertyName.Replace(".", "-");
                    myHtmlControlDesignBehavior.SetAttribute(myStringReplace2, myDataBindingExpression2, true);
                    int index = myStringReplace2.IndexOf('-');
                }// while loop ends
// </Snippet10>
// <Snippet13>
// <Snippet14>
// <Snippet15>
                string dataBindingOutput4, dataBindingOutput5, dataBindingOutput6, dataBindingOutput7, dataBindingOutput8;
                dataBindingOutput4 = String.Concat("The Count of the collection is ", myDataBindingCollection1.Count);
                dataBindingOutput5 = String.Concat("The IsSynchronised property of the collection is ", myDataBindingCollection1.IsSynchronized, "-", dataBindingOutput4);
                dataBindingOutput6 = String.Concat("The IsReadOnly property of the collection is ", myDataBindingCollection1.IsReadOnly, "-", dataBindingOutput5);
                WriteToFile(dataBindingOutput6);
// </Snippet15>
// </Snippet14>
// </Snippet13>

// <Snippet16>
                System.Array dataBindingCollectionArray = Array.CreateInstance(typeof(object), myDataBindingCollection1.Count);
                myDataBindingCollection1.CopyTo(dataBindingCollectionArray, 0);
                dataBindingOutput7 = String.Concat("The count of DataBindingArray is  ", dataBindingCollectionArray.Length);
                WriteToFile(dataBindingOutput7);
// </Snippet16>
                IEnumerator myEnumerator1 = myDataBindingCollection1.GetEnumerator();
                if (myEnumerator1.MoveNext())
                {
// <Snippet17>

                    myDataBinding1     = (DataBinding)myEnumerator1.Current;
                    dataBindingOutput8 = String.Concat("The HashCode is", myDataBinding1.GetHashCode().ToString());
                    WriteToFile(dataBindingOutput8);
// <Snippet18>
                    myDataBindingCollection1.Remove(myDataBinding1);
                    dataBindingOutput8 = String.Concat("The Count of the collection after DataBinding is removed is  ", myDataBindingCollection1.Count);
                    WriteToFile(dataBindingOutput8);
// </Snippet18>
// </Snippet17>
                }
                else
                {
                    myDataBinding1 = (DataBinding)myEnumerator1.Current;
// <Snippet19>
                    myDataBindingCollection1.Remove("Text", true);
                    dataBindingOutput8 = String.Concat("The Count of the collection after DataBinding is removed is  ", myDataBindingCollection1.Count);
                    WriteToFile(dataBindingOutput8);
// </Snippet19>
// <Snippet20>
                    myDataBindingCollection1.Clear();
                    dataBindingOutput8 = String.Concat("The Count of the collection after clear method is called  ", myDataBindingCollection1.Count);
                    WriteToFile(dataBindingOutput8);
// </Snippet20>
                }
            } // else ends here.
        }
Beispiel #7
0
 /// <summary>
 ///    Notification that is called when the behavior is detached from designer
 /// </summary>
 protected override void OnBehaviorDetaching()
 {
     // dispose the cached behavior.
     _cachedBehavior = null;
 }
        internal static  String GetDesignTimeErrorHtml(
            String errorMessage, 
            bool infoMode,
            Control control,
            IHtmlControlDesignerBehavior behavior,
            ContainmentStatus containmentStatus)
        {
            String id = String.Empty;
            Debug.Assert(control != null, "control is null");

            if (control.Site != null)
            {
                id = control.Site.Name;
            }

            if (behavior != null) {
                behavior.SetStyleAttribute("borderWidth", true, "0px", true);
            }

            return String.Format(CultureInfo.CurrentCulture,
                MobileControlDesigner.defaultErrorDesignTimeHTML,
                new Object[]
                {
                    control.GetType().Name,
                    id,
                    errorMessage,
                    infoMode? MobileControlDesigner.infoIcon : MobileControlDesigner.errorIcon,
                    ((containmentStatus == ContainmentStatus.AtTopLevel) ? 
                    Constants.ControlSizeAtToplevelInErrormode : 
                    Constants.ControlSizeInContainer)
                });
        }
        internal static  void SetStandardStyleAttributes(IHtmlControlDesignerBehavior behavior, 
                                                      ContainmentStatus containmentStatus)
        {
            if (behavior == null) {
                return;
            }

            bool controlAtTopLevel = (containmentStatus == ContainmentStatus.AtTopLevel);

            Color cw = SystemColors.Window;
            Color ct = SystemColors.WindowText;
            Color c = Color.FromArgb((Int16)(ct.R * 0.1 + cw.R * 0.9),
                (Int16)(ct.G * 0.1 + cw.G * 0.9),
                (Int16)(ct.B * 0.1 + cw.B * 0.9));
            behavior.SetStyleAttribute("borderColor", true, ColorTranslator.ToHtml(c), true);
            behavior.SetStyleAttribute("borderStyle", true, "solid", true);
                        
            behavior.SetStyleAttribute("borderWidth", true, "1px", true);
            behavior.SetStyleAttribute("marginLeft", true, "5px", true);
            behavior.SetStyleAttribute("marginRight", true, controlAtTopLevel ? "30%" : "5px", true);
            behavior.SetStyleAttribute("marginTop", true, controlAtTopLevel ? "5px" : "2px", true);
            behavior.SetStyleAttribute("marginBottom", true, controlAtTopLevel ? "5px" : "2px", true);
        }
Beispiel #10
0
 internal static void SetStandardStyleAttributes(IHtmlControlDesignerBehavior behavior, ContainmentStatus containmentStatus)
 {
     bool flag = containmentStatus == ContainmentStatus.AtTopLevel;
     Color window = SystemColors.Window;
     Color windowText = SystemColors.WindowText;
     Color c = Color.FromArgb((short) ((windowText.R * 0.1) + (window.R * 0.9)), (short) ((windowText.G * 0.1) + (window.G * 0.9)), (short) ((windowText.B * 0.1) + (window.B * 0.9)));
     behavior.SetStyleAttribute("borderColor", true, ColorTranslator.ToHtml(c), true);
     behavior.SetStyleAttribute("borderStyle", true, "solid", true);
     behavior.SetStyleAttribute("borderWidth", true, "1px", true);
     behavior.SetStyleAttribute("marginLeft", true, "5px", true);
     behavior.SetStyleAttribute("marginRight", true, flag ? "30%" : "5px", true);
     behavior.SetStyleAttribute("marginTop", true, flag ? "5px" : "2px", true);
     behavior.SetStyleAttribute("marginBottom", true, flag ? "5px" : "2px", true);
 }
Beispiel #11
0
 internal static string GetDesignTimeErrorHtml(string errorMessage, bool infoMode, Control control, IHtmlControlDesignerBehavior behavior, ContainmentStatus containmentStatus)
 {
     string name = string.Empty;
     if (control.Site != null)
     {
         name = control.Site.Name;
     }
     behavior.SetStyleAttribute("borderWidth", true, "0px", true);
     return string.Format(Constants.DefaultErrorDesignTimeHTML, new object[] { control.GetType().Name, name, errorMessage, infoMode ? Constants.InfoIconUrl : Constants.ErrorIconUrl, (containmentStatus == ContainmentStatus.AtTopLevel) ? Constants.ControlSizeAtToplevelInErrormode : Constants.ControlSizeInContainer });
 }
Beispiel #12
0
        /// <summary>
        /// Makes a association between an element and a native element class.
        /// </summary><remarks>
        /// In case of an already created object the object is returned instead of creating a new one.
        /// This class returns <see cref="System.Web.UI.Control">Control</see>, but all element classes internally
        /// used are using IElement, too. So in any case an internal HTML element object is being retrieved, it's
        /// possible to cast to IElement instead. In case of a plug-in this is not required, because plug-ins may handle
        /// their elements differently and such a cast is not appropriate. Consult the documentation of the plug-in to
        /// understand the requirements for object handling.
        /// </remarks>
        /// <param name="el">The element for that a native object is needed.</param>
        /// <returns>System.Web.UI.Control if creating or retrieving was successful, otherwise <c>null</c>. The caller is responsible to cast to the right class type.</returns>
        public Control CreateElement(Interop.IHTMLElement el)
        {
            if (el == null)
            {
                return(null);
            }

            Type    type    = null;
            Control element = null;
            // each element will be stored in a hashtable to increase performance, subsequent calls
            // to this factory will retrieve stored objects instead of creating new ones.
            string uniqueName;

            ((Interop.IHTMLUniqueName)el).uniqueID(out uniqueName);
            // look whether we have it already in the designer
            if (designerHost[uniqueName] is Control)
            {
                Control returnEl = designerHost[uniqueName] as Control;
                if (returnEl is IElement)
                {
                    ((IElement)returnEl).HtmlEditor = this.htmlEditor;
                }
                return(returnEl);
            }
            // if not, try plug-ins, and finally add
            try
            {
                // get tag name
                type = GetElementType(el);
                ConstructorInfo cinfo;
                if (type != null)
                {
                    // default ctor
                    cinfo = type.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(Interop.IHTMLElement), typeof(IHtmlEditor) }, null);
                    // not found - get it from plug-in
                    if (cinfo == null)
                    {
                        // probably an plugin-driven control, plug-ins register their elements in designer host
                        foreach (IComponent icomp in designerHost.Container.Components)
                        {
                            IDesigner id = designerHost.GetDesigner(icomp);
                            if (id == null)
                            {
                                continue;
                            }
                            if (id is ControlDesigner)
                            {
                                IHtmlControlDesignerBehavior db = ((ControlDesigner)id).Behavior as IHtmlControlDesignerBehavior;
                                if (db != null && db.DesignTimeElement.Equals(el))
                                {
                                    element = icomp as Control;
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        // usually, we get and invoke here
                        element = (Control)cinfo.Invoke(new object[] { el, htmlEditor });
                    }
                    // still not found, try other ctors plugins- could usually define
                    while (element == null)
                    {
                        //throw new NotSupportedException("Element " + ns + ":" + str1 + " not supported. Did you miss a registration?");
                        cinfo = type.GetConstructor(new Type[] { typeof(Interop.IHTMLElement), typeof(IHtmlEditor) });
                        if (cinfo != null)
                        {
                            element = (Control)cinfo.Invoke(new object[] { el, htmlEditor });
                            break;
                        }
                        cinfo = type.GetConstructor(new Type[] { typeof(IHtmlEditor) });
                        if (cinfo != null)
                        {
                            element = (Control)cinfo.Invoke(new object[] { htmlEditor });
                            break;
                        }
                        cinfo = type.GetConstructor(Type.EmptyTypes);
                        if (cinfo != null)
                        {
                            element = (Control)cinfo.Invoke(null);
                            break;
                        }
                    }
                }
            }
            catch
            {
                // whatever is goind wrong we don't care, returning null is "bad state" for caller
                //return null;
                throw;
            }
            finally
            {
                if (element != null)
                {
                    if (element is IElement)
                    {
                        ((IElement)element).HtmlEditor = this.htmlEditor;
                    }
                    // not there, then we add it
                    if (designerHost[uniqueName] == null)
                    {
                        designerHost.Add(element, uniqueName);
                        ((HtmlEditor)htmlEditor).OnElementCreated(element);
                    }
                }
            }
            return(element);
        }
 /// <summary>
 ///    Notification that is called when the behavior is detached from designer
 /// </summary>
 protected override void OnBehaviorDetaching()
 {
     // dispose the cached behavior.
     _cachedBehavior = null;
 }
        /// <summary>
        ///    <para>
        ///       Notification that is called when the designer is attached to the behavior.
        ///    </para>
        /// </summary>
        protected override void OnBehaviorAttached()
        {
            Debug.Assert(_cachedBehavior == null);
            _cachedBehavior = Behavior;

            PrefixDeviceSpecificTags();
            base.OnBehaviorAttached();

            // Reload the original state if an old Behavior is cached.
            if (_hasAttributesCached)
            {
                ReloadBehaviorState();
            }
        }
 protected override void OnBehaviorDetaching()
 {
     this._cachedBehavior = null;
 }
 protected override void OnBehaviorAttached()
 {
     this._cachedBehavior = base.Behavior;
     this.PrefixDeviceSpecificTags();
     base.OnBehaviorAttached();
     if (this._hasAttributesCached)
     {
         this.ReloadBehaviorState();
     }
 }