Example #1
0
 protected override void ApplyValueProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
 {
     if (value.AsString().HasValue())
     {
         result.Attributes[HtmlAttr.Value] = value.AsString();
     }
 }
        /// <summary>
        /// Aplica a propriedade à saída de um controle.
        /// </summary>
        /// <param name="target">Controle alvo</param>
        /// <param name="property">Propriedade sendo aplicada</param>
        /// <param name="value">Valor da propriedade sendo aplicada</param>
        /// <param name="result">Resultado da saida da renderização atual.</param>
        public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
        {
            var thickness = value as Thickness;

            if (value != null && thickness.IsSetted())
            {
                if (thickness.AllValuesIsSetted())
                {
                    result.Styles[CssAttribute] = thickness.GetAllValuesString();
                }
                else
                {
                    var str = CssAttribute.ToString().ToLower();
                    if (thickness.Top.HasValue)
                    {
                        result.Styles[CssConfig.GetEnumItemFromCssName <CssProperty>(str + "-top")] = thickness.GetTopStringValue();
                    }
                    if (thickness.Bottom.HasValue)
                    {
                        result.Styles[CssConfig.GetEnumItemFromCssName <CssProperty>(str + "-bottom")] = thickness.GetBottomStringValue();
                    }
                    if (thickness.Left.HasValue)
                    {
                        result.Styles[CssConfig.GetEnumItemFromCssName <CssProperty>(str + "-left")] = thickness.GetLeftStringValue();
                    }
                    if (thickness.Right.HasValue)
                    {
                        result.Styles[CssConfig.GetEnumItemFromCssName <CssProperty>(str + "-right")] = thickness.GetRightStringValue();
                    }
                }
            }
        }
        public Meta(HtmlObject obj) : base(obj)
        {
            if (!obj.Name.Equals(this.TagName))
            {
                throw new ValidationException();
            }
            foreach ((string key, string value) in obj.Properties)
            {
                switch (key.Trim())
                {
                case "charset":
                    charset = value;
                    break;

                case "content":
                    content = value;
                    break;

                case "http-equiv":
                    httpequiv = value;
                    break;

                case "name":
                    name = value;
                    break;

                default:
                    //UnknownElementPropertyFound(key, value, this);
                    break;
                }
            }
        }
 public Title(HtmlObject obj) : base(obj)
 {
     if (!obj.Name.Equals(this.TagName))
     {
         throw new ValidationException();
     }
 }
        public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
        {
            if (value.AsString().IsEmpty() || value.AsString() == DefaultValue.AsString())
                return;

            result.Attributes[Attribute.ToString().ToLower()] = value.AsString();
        }
        public void Remove(T node)
        {
            HtmlObject previous = node._previous;
            HtmlObject next     = node._next;

            if (node == _first)
            {
                _first = (T)next;
            }
            if (node == _last)
            {
                _last = (T)previous;
            }
            if (previous != null)
            {
                previous._next = next;
            }
            if (next != null)
            {
                next._previous = previous;
            }
            node._previous = null;
            node._next     = null;
            _count--;
        }
Example #7
0
        public void DetachEvent_Validations()
        {
            HtmlObject ho = HtmlPage.Document.CreateElement("div");

            EventHandler eh = new EventHandler(Handler);

            Assert.Throws <ArgumentNullException> (delegate {
                ho.DetachEvent(null, eh);
            }, "DetachEvent(null,EventHandler)");
            Assert.Throws <ArgumentException> (delegate {
                ho.DetachEvent(String.Empty, eh);
            }, "DetachEvent(Empty,EventHandler)");
            Assert.Throws <ArgumentNullException> (delegate {
                ho.DetachEvent("a", (EventHandler)null);
            }, "DetachEvent(string,null");
            Assert.Throws <ArgumentException> (delegate {
                ho.DetachEvent("a\0b", eh);
            }, "DetachEvent(string-with-null,EventHandler");

            EventHandler <HtmlEventArgs> geh = new EventHandler <HtmlEventArgs> (GenericHandler);

            Assert.Throws <ArgumentNullException> (delegate {
                ho.DetachEvent(null, geh);
            }, "DetachEvent(null,EventHandler<HtmlEventArgs>)");
            Assert.Throws <ArgumentException> (delegate {
                ho.DetachEvent(String.Empty, geh);
            }, "DetachEvent(Empty,EventHandler<HtmlEventArgs>)");
            Assert.Throws <ArgumentNullException> (delegate {
                ho.DetachEvent("a", (EventHandler <HtmlEventArgs>)null);
            }, "DetachEvent(string,EventHandler<HtmlEventArgs>null)");
            Assert.Throws <ArgumentException> (delegate {
                ho.DetachEvent("a\0b", geh);
            }, "DetachEvent(string-with-null,EventHandler<HtmlEventArgs>");
        }
 internal ControlPropertyChangedEventArgs(HtmlObject target, ControlProperty property, Object currentvalue, Object newValue)
 {
     this.Target = target;
     this.Property = property;
     this.OldValue = currentvalue;
     this.NewValue = newValue;
 }
 public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
 {
     var boolValue = ConversionHelper.ToBoolean(value);
     if (boolValue == DefaultValue)
         return;
     result.Attributes[Attribute] = boolValue ? ValueIfTrue : ValueIfFalse;
 }
Example #10
0
 public static object GetBoundMember(HtmlObject obj, string name)
 {
     if (name == "events" || name == "Events")
     {
         return(Events(obj));
     }
     return(ScriptObjectExtension.GetBoundMember(obj, name));
 }
 private void LayerHtml(FastString Page, HtmlObject obj)
 {
     LayerBack(Page, obj,
               GetSpanText(obj, new Utils.FastString(obj.Text),
                           obj.Padding.Top,
                           obj.Width - obj.Padding.Horizontal,
                           0));
 }
 public override void ApplyTemplate(HtmlObject source)
 {
     base.ApplyTemplate(source);
     if (_childrenCollections != null)
         foreach (var c1 in _childrenCollections)
             foreach (var c2 in c1)
                 ((HtmlObject)c2).ApplyTemplate(source);
 }
 private static void ApplyValuePropertyCallback(HtmlObject target, ControlProperty property, Object value, ControlPropertyApplyResult result)
 {
     var applierTarget = target as IValuePropertyApplier;
     if (applierTarget != null)
         applierTarget.ApplyValueProperty(target, property, value, result);
     else
         throw new Exception("The target control must implement IValuePropertyApplier in order to accepted ValueProperty value apply.");
 }
Example #14
0
        /// <summary>
        /// Creates a HtmlObject instance with specified name and parent.
        /// </summary>
        /// <param name="name">The name of the HtmlObject instance.</param>
        /// <param name="parent">The parent of the HtmlObject instance.</param>
        /// <returns>The HtmlObject instance.</returns>
        public static HtmlObject CreateHtmlObject(string name, Base parent)
        {
            HtmlObject html = new HtmlObject();

            html.Name   = name;
            html.Parent = parent;
            return(html);
        }
Example #15
0
 internal HtmlFormControl(HtmlForm form, HtmlObject element, string name, HtmlControlType controlType, HtmlInputType inputType)
 {
     Form        = form;
     Element     = element;
     Name        = name;
     ControlType = controlType;
     InputType   = inputType;
 }
 /// <summary>
 /// Aplica a propriedade à saída de um controle.
 /// </summary>
 /// <param name="target">Controle alvo</param>
 /// <param name="property">Propriedade sendo aplicada</param>
 /// <param name="value">Valor da propriedade sendo aplicada</param>
 /// <param name="result">Resultado da saida da renderização atual.</param>
 public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
 {
     if (value != null && value.AsString() != DefaultValue.AsString())
     {
         var strValue = (value ?? "").ToString();
         if (strValue.HasValue())
             result.Styles[CssProperty] = strValue.ToLowerInvariant();
     }
 }
Example #17
0
        public void DetachEvent()
        {
            HtmlObject   ho = HtmlPage.Document.CreateElement("div");
            EventHandler eh = new EventHandler(Handler);

            // detach inexisting
            ho.DetachEvent("a", eh);
            // detach inexisting
            ho.DetachEvent("a", new EventHandler <HtmlEventArgs> (GenericHandler));
        }
        public void ReplaceAll(HtmlObject[] content)
        {
            HtmlElement parent = new HtmlElement("parent", new HtmlElement("element"), new HtmlAttribute("attribute1"), new HtmlAttribute("attribute2"), new HtmlComment("comment"));

            parent.ReplaceAll(content);
            Assert.Equal(content.OfType<HtmlElement>().ToArray(), parent.Elements().ToArray());
            Assert.Equal(content.OfType<HtmlAttribute>().ToArray(), parent.Attributes().ToArray());
            Assert.Equal(parent.Elements().Count() + parent.Attributes().Count(), parent.ElementsAndAttributes().Count());
            Assert.Equal(parent.Nodes().Count() + parent.Attributes().Count(), parent.NodesAndAttributes().Count());
        }
 /// <summary>
 /// Aplica a propriedade à saída de um controle.
 /// </summary>
 /// <param name="target">Controle alvo</param>
 /// <param name="property">Propriedade sendo aplicada</param>
 /// <param name="value">Valor da propriedade sendo aplicada</param>
 /// <param name="result">Resultado da saida da renderização atual.</param>
 public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
 {
     if (value.AsString().HasValue())
     {
         if (Raw)
             result.RawInnerText.Append(value.AsString());
         else
             result.InnerText.Append(value.AsString());
     }
 }
Example #20
0
 public void Ctor_String_ParamsHtmlObject(HtmlObject[] content)
 {
     HtmlElement element = new HtmlElement("element", content);
     Assert.Equal("element", element.Tag);
     Assert.False(element.IsVoid);
     Assert.Equal(content.OfType<HtmlElement>().ToArray(), element.Elements().ToArray());
     Assert.Equal(content.OfType<HtmlAttribute>().ToArray(), element.Attributes().ToArray());
     Assert.Equal(content.OfType<HtmlNode>().ToArray(), element.Nodes().ToArray());
     Assert.Equal(element.Elements().Count() + element.Attributes().Count(), element.ElementsAndAttributes().Count());
     Assert.Equal(content.Length, element.NodesAndAttributes().Count());
 }
Example #21
0
        public void AttachEvent()
        {
            HtmlObject   ho = HtmlPage.Document.CreateElement("div");
            EventHandler eh = new EventHandler(Handler);

            Assert.IsTrue(ho.AttachEvent("a", eh), "1");
            // twice (same handler)
            Assert.IsTrue(ho.AttachEvent("a", eh), "2");
            // again (different handler)
            Assert.IsTrue(ho.AttachEvent("a", new EventHandler <HtmlEventArgs> (GenericHandler)), "3");
        }
        /// <summary>
        /// Creates a HtmlObject instance with specified name and parent.
        /// </summary>
        /// <param name="name">The name of the HtmlObject instance.</param>
        /// <param name="parent">The parent of the HtmlObject instance.</param>
        /// <returns>The HtmlObject instance.</returns>
        public static HtmlObject CreateHtmlObject(string name, Base parent)
        {
            HtmlObject html = new HtmlObject();

            html.Name = name;
            if ((parent as IParent).CanContain(html))
            {
                html.Parent = parent;
            }
            return(html);
        }
 internal void _RemoveGuestControl(HtmlObject control)
 {
     if (_beforeChildrenGuestControls != null)
     {
         _beforeChildrenGuestControls.Remove(control);
     }
     if (_afterChildrenGuestControls != null)
     {
         _afterChildrenGuestControls.Remove(control);
     }
 }
 public HTMLHeadingElement(HtmlObject obj) : base(obj)
 {
     foreach ((string key, string value) in obj.Properties)
     {
         switch (key)
         {
         case "align":
             align = value;
             break;
         }
     }
 }
Example #25
0
 public HTMLElement(HtmlObject obj) : base(obj)
 {
     foreach ((string key, string value) in obj.Properties)
     {
         switch (key)
         {
         case "InBetweenContent":
             innerText = value;
             break;
         }
     }
 }
Example #26
0
        private static void ApplyValuePropertyCallback(HtmlObject target, ControlProperty property, Object value, ControlPropertyApplyResult result)
        {
            var applierTarget = target as IValuePropertyApplier;

            if (applierTarget != null)
            {
                applierTarget.ApplyValueProperty(target, property, value, result);
            }
            else
            {
                throw new Exception("The target control must implement IValuePropertyApplier in order to accepted ValueProperty value apply.");
            }
        }
        private Tuple <int, HtmlObject> GetProperties(int index, int limit, HtmlObject htmlTag)
        {
            //string propertyName = "";
            //string propertyContent = "";
            int nameBeginning = index;

            while (index < limit && !_content[index].Equals('='))
            {
                //propertyName += this._content[index];
                index++;
            }
            int nameEnding = index - 1;

            while (index < limit && !_content[index].Equals('"'))
            {
                index++;
            }
            index++;

            int ContentBeginning = index;

            while (index < limit && !_content[index].Equals('"'))
            {
                //propertyContent += this._content[index];
                index++;
            }
            int ContentEnding = index - 1;

            while (index < limit && (!_content[index].Equals('>') && (_content[index].Equals(' ') || _content[index].Equals('/'))))
            {
                if (_content[index].Equals('/'))//Self closing tag
                {
                    htmlTag.Type = HtmlObjectType.SelfClosingTag;
                }
                index++;
            }

            try
            {
                string propertyName    = new string(_content, nameBeginning, (nameEnding + 1) - nameBeginning);
                string propertyContent = new string(_content, ContentBeginning, (ContentEnding + 1) - ContentBeginning);
                htmlTag.Properties.Add(propertyName, propertyContent);
            }
            catch (Exception e)
            {
                //Console.WriteLine(e);
            }

            index--;
            return(new Tuple <int, HtmlObject>(index, htmlTag));
        }
 internal void _AddGuestControl(HtmlObject control, bool beforeChildren)
 {
     Assert.NullArgument(control, "control");
     if (beforeChildren)
     {
         _beforeChildrenGuestControls = _beforeChildrenGuestControls ?? new HtmlControlCollection <HtmlObject>();
         _beforeChildrenGuestControls.Add(control);
     }
     else
     {
         _afterChildrenGuestControls = _afterChildrenGuestControls ?? new HtmlControlCollection <HtmlObject>();
         _afterChildrenGuestControls.Add(control);
     }
 }
 public override void ApplyTemplate(HtmlObject source)
 {
     base.ApplyTemplate(source);
     if (_childrenCollections != null)
     {
         foreach (var c1 in _childrenCollections)
         {
             foreach (var c2 in c1)
             {
                 ((HtmlObject)c2).ApplyTemplate(source);
             }
         }
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="i"></param>
        /// <param name="HtmlObjectsList"></param>
        /// <param name="htmlTag"></param>
        /// <returns></returns>
        private int GetInBetweenContentParent(Webpage _webpage, HtmlObject htmlTag)
        {
            int        index = _webpage.Count - 1;
            HtmlObject ho; //get last object
            int        closingPoints = 0;
            int        openingPoints = 0;

            do
            {
                if (index == 1365)
                {
                    int das = 22;
                }

                ho = _webpage[index];
                //Check if HtmlObject is of the same tag type
                if (ho.Name == htmlTag.Name)
                {
                    switch (ho.Type)
                    {
                    case HtmlObjectType.OpeningTag:
                        openingPoints++;
                        break;

                    case HtmlObjectType.ClosingTag:
                        closingPoints++;
                        break;

                    case HtmlObjectType.SelfClosingTag:
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }

                if ((openingPoints - closingPoints > 0 || index == 1))
                {
                    if (index == 1)
                    {
                        int dsadsa = 2;
                    }
                    return(index + 1);
                }

                index--;
            } while (index >= 0);// && index < 100);

            return(-1);
        }
 internal void _AddGuestControl(HtmlObject control, bool beforeChildren)
 {
     Assert.NullArgument(control, "control");
     if (beforeChildren)
     {
         _beforeChildrenGuestControls = _beforeChildrenGuestControls ?? new HtmlControlCollection<HtmlObject>();
         _beforeChildrenGuestControls.Add(control);
     }
     else
     {
         _afterChildrenGuestControls = _afterChildrenGuestControls ?? new HtmlControlCollection<HtmlObject>();
         _afterChildrenGuestControls.Add(control);
     }
 }
 /// <summary>
 /// Aplica a propriedade à saída de um controle.
 /// </summary>
 /// <param name="target">Controle alvo</param>
 /// <param name="property">Propriedade sendo aplicada</param>
 /// <param name="value">Valor da propriedade sendo aplicada</param>
 /// <param name="result">Resultado da saida da renderização atual.</param>
 public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
 {
     if (value.AsString().HasValue())
     {
         if (Raw)
         {
             result.RawInnerText.Append(value.AsString());
         }
         else
         {
             result.InnerText.Append(value.AsString());
         }
     }
 }
 public void Render(HtmlObject control)
 {
     try
     {
         var renderStart = DateTime.Now;
         control.Render(Context);
         RenderCost = DateTime.Now - renderStart;
     }
     catch (Exception e)
     {
         //gravar na saida mais dados sobre o erro.
         Exception ex = new Exception(String.Format("Erro ao renderizar o controle: \n Pilha: {0}", GetStackString()), e);
         throw ex;
     }
 }
        private Tuple <int, HtmlObject> GetInBetweenContentBAD(int index, int limit, HtmlObject htmlTag)
        {
            if (_content[index - 1].Equals('/'))//Not correct : it works if it is like this "/>" but what if spaces exist in-between like "/ >"
            {
                htmlTag.Type = HtmlObjectType.SelfClosingTag;
            }
            else
            {
                int beginning = index;
                //Skip the ">" sign
                index++;
                const string propertyName    = "InBetweenContent";
                string       propertyContent = "";

                bool exitFlag = false;

                while (!(_content[index].Equals('<') && _content[index + 1].Equals('/')) && !exitFlag)
                {
                    //propertyContent += this._content[index];
                    if (_content[index].Equals('<') && propertyContent.Trim().Equals("<"))
                    {
                        exitFlag = true;
                    }
                    else
                    {
                        index++;
                    }
                }
                index--;
                if (!exitFlag)
                {
                    Char[] temp = new char[index - beginning];
                    if (index - beginning > 0)
                    {
                        Array.Copy(_content, beginning + 1, temp, 0, index - beginning);
                        propertyContent = new string(temp);
                    }
                    else
                    {
                        propertyContent = "";
                    }
                    //propertyContent = new string(_content.CopyTo(_content,));
                    //propertyContent = new string(_content[new Range(new Index(beginning + 1, false), new Index(index + 1, false))]);
                    htmlTag.Properties.Add(propertyName, propertyContent);
                }
            }
            return(new Tuple <int, HtmlObject>(index, htmlTag));
        }
        public void Clear()
        {
            HtmlObject current = _first;

            while (current != null)
            {
                HtmlObject next = current._next;
                current._previous = null;
                current._next     = null;

                current = next;
            }
            _count = 0;
            _first = null;
            _last  = null;
        }
        public HTMLLIElement(HtmlObject obj) : base(obj)
        {
            foreach ((string key, string value) in obj.Properties)
            {
                switch (key)
                {
                case "type":
                    type = value;
                    break;

                case "value":
                    this.value = value;
                    break;
                }
            }
        }
Example #37
0
        public HTMLUListElement(HtmlObject obj) : base(obj)
        {
            foreach ((string key, string value) in obj.Properties)
            {
                switch (key)
                {
                case "type":
                    type = value;
                    break;

                case "compact":
                    compact = value;
                    break;
                }
            }
        }
Example #38
0
		internal HtmlEventArgs (HtmlObject source,
					ScriptObject eventObj)
		{
			this.source_element = source;
			this.eventObject = eventObj;

			eventType = (string) eventObject.GetProperty("type");

			if (eventType.StartsWith ("click") ||
			    eventType.StartsWith ("dblclick") ||
			    eventType.StartsWith ("mouse"))
				eventKind = EventKind.Mouse;
			else if (eventType.StartsWith ("key")) {
				eventKind = EventKind.Key;
			}
		}
Example #39
0
 public Head(HtmlObject obj) : base(obj)
 {
     if (!obj.Name.Equals(this.TagName))
     {
         throw new ValidationException();
     }
     foreach ((string key, string value) in obj.Properties)
     {
         switch (key.Trim())
         {
         case "profile":
             profile = value;
             break;
         }
     }
 }
Example #40
0
        private Tuple <int, HtmlObject> GetProperties(int index, int limit, HtmlObject htmlTag)
        {
            string propertyName    = "";
            string propertyContent = "";

            int propertyNameBegining = index;

            while (index < limit && !_content[index].Equals('='))
            {
                //propertyName += this._content[index];
                index++;
            }
            int propertyNameEnding = index - 1;

            while (index < limit && !_content[index].Equals('"'))
            {
                index++;
            }
            index++;

            int propertyContentBegining = index;

            while (index < limit && !_content[index].Equals('"'))
            {
                // propertyContent += this._content[index];
                index++;
            }
            int propertyContentEnding = index - 1;

            while (index < limit && (!_content[index].Equals('>') && (_content[index].Equals(' ') || _content[index].Equals('/'))))
            {
                if (_content[index].Equals('/'))//Self closing tag
                {
                    htmlTag.type = HtmlObjectType.SelfClosingTag;
                }
                index++;
            }

            propertyName    = new string(_content[new Range(new Index(propertyNameBegining, false), new Index(propertyNameEnding + 1, false))]);
            propertyContent = new string(_content[new Range(new Index(propertyContentBegining, false), new Index(propertyContentEnding + 1, false))]);

            htmlTag.Properties.Add(propertyName, propertyContent + '"');

            index--;
            return(new Tuple <int, HtmlObject>(index, htmlTag));
        }
 /// <summary>
 /// Aplica o atributo de visibilidade a um controle.
 /// </summary>
 /// <param name="target"></param>
 /// <param name="property"></param>
 /// <param name="value"></param>
 /// <param name="result"></param>
 public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
 {
     var state = (Visibility)value;
     switch (state)
     {
         case Visibility.Visible:
             result.Styles.Remove(CssProperty.Visibility);
             break;
         case Visibility.Hidden:
             result.Styles[CssProperty.Visibility] = state.ToString().ToLower();
             break;
         case Visibility.None:
             result.Styles.Remove(CssProperty.Visibility);
             result.Styles[CssProperty.Display] = "none";
             break;
     }
 }
Example #42
0
        /// <summary>
        /// Returns the HtmlObject at the given index used for closing tags
        /// </summary>
        /// <param name="index">Beginning location of the Tag</param>
        /// <returns></returns>
        private Tuple <int, HtmlObject> GetClosingTagName(int index)
        {
            HtmlObject htmlTag = new HtmlObject {
                type = HtmlObjectType.ClosingTag
            };

            string ClosingtagName = "";

            while (!(_content[index].Equals('>') || _content[index].Equals(' ')))
            {
                ClosingtagName += _content[index];
                index++;
            }
            index--;
            htmlTag.Name = ClosingtagName;
            return(new Tuple <int, HtmlObject>(index, htmlTag));
        }
        public HTMLAnchorElement(HtmlObject obj) : base(obj)
        {
            foreach ((string key, string value) in obj.Properties)
            {
                switch (key.Trim())
                {
                case "href":
                    href = value;
                    break;

                case "protocol":
                    protocol = value;
                    break;

                case "host":
                    host = value;
                    break;

                case "hostname":
                    hostname = value;
                    break;

                case "search":
                    search = value;
                    break;

                case "hash":
                    hash = value;
                    break;

                case "username":
                    username = value;
                    break;

                case "password":
                    password = value;
                    break;

                case "origin":
                    origin = value;
                    break;
                }
            }
        }
 /// <summary>
 /// Aplica a propriedade à saída de um controle.
 /// </summary>
 /// <param name="target">Controle alvo</param>
 /// <param name="property">Propriedade sendo aplicada</param>
 /// <param name="value">Valor da propriedade sendo aplicada</param>
 /// <param name="result">Resultado da saida da renderização atual.</param>
 public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
 {
     var thickness = value as Thickness;
     if (value != null && thickness.IsSetted())
     {
         if (thickness.AllValuesIsSetted())
             result.Styles[CssAttribute] = thickness.GetAllValuesString();
         else
         {
             var str = CssAttribute.ToString().ToLower();
             if (thickness.Top.HasValue)
                 result.Styles[CssConfig.GetEnumItemFromCssName<CssProperty>(str + "-top")] = thickness.GetTopStringValue();
             if (thickness.Bottom.HasValue)
                 result.Styles[CssConfig.GetEnumItemFromCssName<CssProperty>(str + "-bottom")] = thickness.GetBottomStringValue();
             if (thickness.Left.HasValue)
                 result.Styles[CssConfig.GetEnumItemFromCssName<CssProperty>(str + "-left")] = thickness.GetLeftStringValue();
             if (thickness.Right.HasValue)
                 result.Styles[CssConfig.GetEnumItemFromCssName<CssProperty>(str + "-right")] = thickness.GetRightStringValue();
         }
     }
 }
 public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
 {
     Object getParams = null;
     var urlStr = value.AsString();
     var uri = new Uri(urlStr, UriKind.RelativeOrAbsolute);
     //url.
     if (GetParamsProperty != null)
         getParams = target.GetValue(GetParamsProperty);
     if (getParams != null)
     {
         IDictionary<String, Object> dict = null;
         if (!(getParams is IDictionary<String, Object>))
             dict = ReflectionHelper.AnonymousToDictionary(getParams);
         else
             dict = (IDictionary<String, Object>)getParams;
         if (uri.Query.HasValue())
             urlStr += urlStr + "&" + Utils.EncodeGetParams(dict);
         else
             urlStr += uri.ToString() + "?" + Utils.EncodeGetParams(dict);
     }
     if (urlStr != null)
         result.Attributes[HtmlAttr.Href] = urlStr;
 }
Example #46
0
 protected override void ApplyValueProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
 {
     result.InnerText.Append(value.AsString());
 }
 protected abstract void ApplyValueProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result);
 void IValuePropertyApplier.ApplyValueProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
 {
     this.ApplyValueProperty(target, property, value, result);
 }
 /// <summary>
 /// Aplica a propriedade à saída de um controle.
 /// </summary>
 /// <param name="target">Controle alvo</param>
 /// <param name="property">Propriedade sendo aplicada</param>
 /// <param name="value">Valor da propriedade sendo aplicada</param>
 /// <param name="result">Resultado da saida da renderização atual.</param>
 public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
 {
     Callback.Invoke(target, property, value, result);
 }
 internal void _RemoveGuestControl(HtmlObject control)
 {
     if (_beforeChildrenGuestControls != null)
         _beforeChildrenGuestControls.Remove(control);
     if (_afterChildrenGuestControls != null)
         _afterChildrenGuestControls.Remove(control);
 }
Example #51
0
 protected override void ApplyValueProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
 {
     if (value.AsString().HasValue())
         result.Attributes[HtmlAttr.Value] = value.AsString();
 }
 internal ControlPropertyApplyResult(HtmlObject target)
 {
     this.Target = target;
     this.Attributes = new HtmlAttributeCollection();
     this.Styles = new HtmlStyleCollection();
 }
        private HtmlObject getStyledObject(StyleSpan span, string content, int start, int end, float thisXOffset)
        {
            TextPaint paint = PaintFromHeap;
                    paint.SetTypeface(Typeface.DefaultFromStyle(span.Style));
                    paint.TextSize = mTextsize;
                    paint.Color = mColor;

                    span.UpdateDrawState(paint);
                    span.UpdateMeasureState(paint);
                    HtmlObject obj = new HtmlObject(this, content, start, end, thisXOffset, paint);
                    obj.recycle = true;
                    return obj;
        }
 private HtmlObject getHtmlObject(string content, int start, int end, float thisXOffset)
 {
     HtmlObject obj = new HtmlObject(this, content, start, end, thisXOffset, mTextPaint);
             return obj;
 }
        protected override void OnDraw(Canvas canvas)
        {
            Log.Debug("flowText", "onDraw");

                    base.OnDraw (canvas);

                    mViewWidth = this.Width;
                    int lowestYCoord = 0;
                    boxes.Clear();

                    int childCount = this.ChildCount;
                    for (int i = 0; i < childCount; i++)
                    {
                            View child = GetChildAt(i);
                            if (child.Visibility != ViewStates.Gone)
                            {
                                    Box box = new Box(this);
                                    box.topLeftx = (int) child.Left;
                                    box.topLefty = (int) child.Top;
                                    box.bottomRightx = box.topLeftx + child.Width;
                                    box.bottomRighty = box.topLefty + child.Height;
                                    boxes.Add(box);
                                    if (box.bottomRighty > lowestYCoord)
                                    {
                                        lowestYCoord = box.bottomRighty;
                                    }
                            }
                    }

                    //var blocks = mText.ToString().Split ("\n", true);
                var blocks = mText.ToString ().Split (new[] {"\n"}, StringSplitOptions.RemoveEmptyEntries);

                    var charOffsetStart = 0; // tells us where we are in the original string
                    var charOffsetEnd = 0; // tells us where we are in the original string
                    var lineIndex = 0;
                    float xOffset = 0; // left margin off a given line
                    float maxWidth = mViewWidth; // how far to the right it can strectch
                    float yOffset = 0;
                    string thisLineStr;
                    int chunkSize;
                    int lineHeight = LineHeight;

                    List<HtmlObject> lineObjects = new List<FlowTextViewSharp.HtmlObject>();
                    object[] spans = new object[0];

                    HtmlObject htmlLine; // = new HtmlObject(); // reuse for single plain lines

                    mLinks.Clear();

                    for (int block_no = 0; block_no <= blocks.Length - 1; block_no++)
                    {

                            string thisBlock = blocks[block_no];
                            if (thisBlock.Length <= 0)
                            {
                                    lineIndex++; //is a line break
                                    charOffsetEnd += 2;
                                    charOffsetStart = charOffsetEnd;
                            }
                            else
                            {

                                    while (thisBlock.Length > 0)
                                    {
                                            lineIndex++;
                                            yOffset = lineIndex * lineHeight;
                                            Line thisLine = getLine(yOffset, lineHeight);
                                            xOffset = thisLine.leftBound;
                                            maxWidth = thisLine.rightBound - thisLine.leftBound;
                                            float actualWidth = 0;

                                            do
                                            {
                                                    Log.Debug("tv", "maxWidth: " + maxWidth);
                                                    chunkSize = getChunk(thisBlock, maxWidth);
                                                    int thisCharOffset = charOffsetEnd + chunkSize;

                                                    if (chunkSize > 1)
                                                    {
                                                            thisLineStr = thisBlock.Substring(0, chunkSize);
                                                    }
                                                    else
                                                    {
                                                            thisLineStr = "";
                                                    }

                                                    lineObjects.Clear();

                                                    if (mIsHtml)
                                                    {
                                                            spans = ((ISpanned) mText).GetSpans(charOffsetStart, thisCharOffset, Class.FromType (typeof(object)));
                                                            if (spans.Length > 0)
                                                            {
                                                                    actualWidth = parseSpans(lineObjects, spans, charOffsetStart, thisCharOffset, xOffset);
                                                            }
                                                            else
                                                            {
                                                                    actualWidth = maxWidth; // if no spans then the actual width will be <= maxwidth anyway
                                                            }
                                                    }
                                                    else
                                                    {
                                                            actualWidth = maxWidth; // if not html then the actual width will be <= maxwidth anyway
                                                    }

                                                    Log.Debug("tv", "actualWidth: " + actualWidth);

                                                    if (actualWidth > maxWidth)
                                                    {
                                                            maxWidth -= 5; // if we end up looping - start slicing chars off till we get a suitable size
                                                    }

                                            } while (actualWidth > maxWidth);

                                            // chunk is ok
                                            charOffsetEnd += chunkSize;

                                            Log.Debug("tv", "charOffsetEnd: " + charOffsetEnd);

                                            if (lineObjects.Count <= 0) // no funky objects found, add the whole chunk as one object
                                            {
                                                    htmlLine = new HtmlObject(this, thisLineStr, 0, 0, xOffset, mTextPaint);
                                                    lineObjects.Add(htmlLine);
                                            }

                                            foreach (HtmlObject thisHtmlObject in lineObjects)
                                            {

                                                    if (thisHtmlObject is HtmlLink)
                                                    {
                                                            HtmlLink thisLink = (HtmlLink) thisHtmlObject;
                                                            float thisLinkWidth = thisLink.paint.MeasureText(thisHtmlObject.content);
                                                            addLink(thisLink, yOffset, thisLinkWidth, lineHeight);
                                                    }

                                                    paintObject(canvas, thisHtmlObject.content, thisHtmlObject.xOffset, yOffset, thisHtmlObject.paint);

                                                    if (thisHtmlObject.recycle)
                                                    {
                                                            recyclePaint(thisHtmlObject.paint);
                                                    }
                                            }

                                            if (chunkSize >= 1)
                                            {
                                                thisBlock = thisBlock.Substring(chunkSize, thisBlock.Length - chunkSize);
                                            }

                                            charOffsetStart = charOffsetEnd;
                                    }
                            }
                    }

                    yOffset += (lineHeight / 2);

                    View child1 = GetChildAt(ChildCount - 1);
                    if (child1.Tag != null)
                    {
                        if (child1.Tag.ToString ().Equals ("hideable", StringComparison.CurrentCultureIgnoreCase))
                            {
                                    if (yOffset > pageHeight)
                                    {
                                            if (yOffset < boxes[boxes.Count - 1].topLefty - LineHeight)
                                            {
                                                child1.Visibility = ViewStates.Gone;
                                                    //lowestYCoord = (int) yOffset;
                                            }
                                            else
                                            {
                                                    //lowestYCoord = boxes.get(boxes.size()-1).bottomRighty + getLineHeight();
                                                child1.Visibility = ViewStates.Visible;
                                            }
                                    }
                                    else
                                    {
                                        child1.Visibility = ViewStates.Gone;
                                            //lowestYCoord = (int) yOffset;
                                    }
                            }
                    }

                    mDesiredHeight = Math.Max(lowestYCoord, (int) yOffset);
                    if (needsMeasure)
                    {
                            needsMeasure = false;
                            RequestLayout();
                    }
        }
Example #56
0
 internal void NotifyPropertyChanged(HtmlObject htmlObject, object oldValue, object newValue)
 {
     if (this.PropertyChangedCallback != null)
     {
         var args = new ControlPropertyChangedEventArgs(htmlObject, this, oldValue, newValue);
         this.PropertyChangedCallback.Invoke(args);
     }
 }
 /// <summary>
 /// Aplica a propriedade à saída de um controle.
 /// </summary>
 /// <param name="target">Controle alvo</param>
 /// <param name="property">Propriedade sendo aplicada</param>
 /// <param name="value">Valor da propriedade sendo aplicada</param>
 /// <param name="result">Resultado da saida da renderização atual.</param>
 public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result)
 {
     if (value != null && value.AsString() != DefaultValue.AsString())
         result.Styles[CssProperty] = CssConfig.GetItemNameFromEnum(property.PropertyType, value);
 }
 internal ControlPropertySlot(HtmlObject owner, ControlProperty property)
 {
     _owner = new WeakReference(owner);
     this.Property = property;
 }
Example #59
0
        internal void Resolve(HtmlObject instance, ControlProperty targetProperty)
        {
            Object value = null;
            if (ValueProvider != null)
                value = ValueProvider.GetValue(instance.DataItem);
            else if (_pathParts != null || _resolvePending)
            {
                if (_resolvePending)
                    CompilePropertyPath();
                var data = instance.DataItem;
                for (var i = 0; i < _pathParts.Length; i++)
                {
                    var key = _pathParts[i];
                    try
                    {
                        switch (_resolveMethods[i])
                        {
                            case ResolveMethod.PropertyValue:
                                data = ReflectionHelper.ReadProperty(data, key); break;
                            case ResolveMethod.ViewDataEntry:
                                data = instance.CurrentContext[key]; break;
                            case ResolveMethod.MethodCall:
                                data = ReflectionHelper.InvokeInstanceMethod(data, key); break;
                            case ResolveMethod.CurrentDataItem:
                                data = instance.DataItem; break;
                            case ResolveMethod.VisualTreeObject:
                                throw new NotImplementedException();
                        }
                        if (data == null)
                            break;
                    }
                    catch (Exception ex)
                    {
                        throw new BindingException(String.Format("Error on resolve property path {0} to property {1}.{2}", PropertyPath, instance.GetType().Name, targetProperty.Name), ex);
                    }
                }
                value = data;
            }
            else
                value = instance.DataItem;

            if (Formatter != null)
            {
                value = Formatter.Format(value);
                if (Formatter.Align != TextAlignment.Default)
                    instance.SetValue(HtmlControl.TextAlignProperty, Formatter.Align);
            }
            if (!String.IsNullOrEmpty(FormatString))
                value = String.Format(FormatString, value);

            instance.SetValue(targetProperty, value);
        }