Пример #1
0
        private void AddElementCore(RadElement addedElement)
        {
            this.RemapStylesToElementsRecursive(addedElement);
            //test if element needs style from its parent
            if (addedElement.Style != null)
            {
                return;
            }

            bool parentNotPropagateStyleToChildren;

            StyleMap styleMap = this.FindStyleMapForElement(addedElement, out parentNotPropagateStyleToChildren);

            if (styleMap != null)
            {
                styleMap.OnElementAdded(addedElement);
            }
            else
            {
                //TODO: elaborate more on this case
                if (!parentNotPropagateStyleToChildren && this.styleElementMap.Count > 0)
                {
                    //this happens when the control does not have any Style, like RadCarousel in the QSF
                    //Debug.Fail("Elemenet style not found");
                }
            }
        }
Пример #2
0
        private void ElementStyleChanged(RadElement element, RadPropertyChangedEventArgs changeArgs)
        {
            StyleMap styleMap;

            this.styleElementMap.TryGetValue(element.GetHashCode(), out styleMap);

#if DEBUG
            if (changeArgs.NewValue != null && element.IsThemeApplied)
            {
                for (RadElement toTest = element.Parent; toTest != null; toTest = toTest.Parent)
                {
                    if (!toTest.IsThemeApplied ||
                        !toTest.PropagateStyleToChildren)
                    {
                        break;
                    }

                    //Parent Style alredy set
                    if (toTest.Style != null)
                    {
                        StyleMap parentStyleMap = null;
                        this.styleElementMap.TryGetValue(toTest.GetHashCode(), out parentStyleMap);
                        if (styleMap != null)
                        {
                            styleMap.OnElementRemoved(element);
                        }
                        else if (this.state != StyleManagerState.Attaching)
                        {
                            Debug.Fail("Unknown Style instance found");
                        }
                    }
                }
            }
#endif

            if (changeArgs.NewValue == null)
            {
                if (styleMap != null)
                {
                    styleMap.SetStyleSheet(null);
                    this.styleElementMap.Remove(element.GetHashCode());
                }
            }
            else
            {
                if (styleMap == null)
                {
                    styleMap = new StyleMap(this, (StyleSheet)changeArgs.NewValue, element);
                    this.styleElementMap.Add(element.GetHashCode(), styleMap);
                }
                else
                {
                    styleMap.SetStyleSheet((StyleSheet)changeArgs.NewValue);
                }
            }
        }
Пример #3
0
        private void ElementStyleSelectorKeyPropertyChanged(RadElement element, RadPropertyChangedEventArgs changeArgs)
        {
            if (this.state != StyleManagerState.Attached || this.styleElementMap.Count == 0 ||
                element.IsDisposing || element.IsDisposed)
            {
                return;
            }

            bool parentNotPropagateStyleToChildren;

            StyleMap styleMap = this.FindStyleMapForElement(element, out parentNotPropagateStyleToChildren);

            if (styleMap != null)
            {
                styleMap.OnElementStyleSelectorKeyPropertyChanged(element, changeArgs);
            }
        }
Пример #4
0
        public StylesheetTree GetStylesheetTree(RadElement element)
        {
            if (this.state != StyleManagerState.Attached)
            {
                return(null);
            }

            bool     parentNotPropagateStyleToChildren;
            StyleMap map = this.FindStyleMapForElement(element, out parentNotPropagateStyleToChildren);

            if (map != null)
            {
                return(map.StylesheetTree);
            }

            return(null);
        }
Пример #5
0
        protected StyleMap MapStyleToElement(RadElement element)
        {
            //reset any style
            element.Style = null;

            StyleBuilder builder = ThemeResolutionService.GetStyleSheetBuilder(element);

            if (builder == null)
            {
                return(null);
            }

            StyleMap styleMap = new StyleMap(this, builder, element);

            this.styleElementMap[element.GetHashCode()] = styleMap;

            return(styleMap);
        }
Пример #6
0
        /// <summary>
        /// Traverse element ierarchy and attach style to each element according to info in ThemeRsolutionService
        /// </summary>
        /// <param name="element"></param>
        private void MapStylesToElementsRecursive(RadElement element)
        {
            StyleMap elementStyleMap = null;

            if (element.CanHaveOwnStyle && element.ElementTree != null) //by default Styles should be applied only on RadItems
            {
                if (element.ElementTree.ComponentTreeHandler != null)
                {
                    element.ElementTree.ComponentTreeHandler.SuspendUpdate();
                    if (!element.UseNewLayoutSystem)
                    {
                        element.ElementTree.RootElement.SuspendLayout();
                    }
                }

                elementStyleMap = this.MapStyleToElement(element);

                if (element.ElementTree.Control != null)
                {
                    if (!element.UseNewLayoutSystem)
                    {
                        element.ElementTree.RootElement.ResumeLayout(true);
                    }

                    element.ElementTree.ComponentTreeHandler.ResumeUpdate();
                }
            }

            if (element.PropagateStyleToChildren)
            {
                for (int i = 0; i < element.Children.Count; i++)
                {
                    this.MapStylesToElementsRecursive(element.Children[i]);
                }
            }

            if (elementStyleMap != null)
            {
                //BuildStyle would generaly set element's Style property to the corresponding StyleSheet
                elementStyleMap.BuildStyle();
            }

            element.IsThemeApplied = true;
        }
Пример #7
0
        public void ApplyStyleToVirtualElement(RadElement element)
        {
            if (!element.IsInValidState(false))
            {
                return;
            }

            if (!element.PropagateStyleToChildren || element.IsThemeRefreshSuspended)
            {
                return;
            }

            if (this.state == StyleManagerState.Detaching || this.state == StyleManagerState.Detached)
            {
                return;
            }

            ComponentThemableElementTree oldTree = element.ElementTree;

            element.UpdateReferences(this.owner.ElementTree, false, true);

            this.MapStylesToElementsRecursive(element);

            bool     parentNotPropagateStyleToChildren;
            StyleMap map = this.FindStyleMapForElement(element, out parentNotPropagateStyleToChildren);

            if (map != null)
            {
                if (this.styleElementMap.ContainsKey(element.GetHashCode()))
                {
                    this.styleElementMap.Remove(element.GetHashCode());
                }
                else
                {
                    map.BuildStyle();
                    map.SetStyleSheet(element.ComposeStyle());
                }
                map.OnElementRemoved(element);
            }

            element.UpdateReferences(oldTree, false, true);
        }
Пример #8
0
        private void RemoveElementCore(RadElement formerParent, RadElement removedElement)
        {
            if (removedElement.Style != null)
            {
                this.RemoveStyleOwner(removedElement);
                return;
            }

            StyleMap styleMap = null;

            if (formerParent != null)
            {
                bool parentNotPropagateStyleToChildren;
                styleMap = this.FindStyleMapForElement(formerParent, out parentNotPropagateStyleToChildren);
            }
            if (styleMap != null)
            {
                styleMap.OnElementRemoved(removedElement);
            }
        }
Пример #9
0
        public void ReApplyStyle(RadElement radElement, bool traverseElementTree)
        {
            if (this.state != StyleManagerState.Attached || this.styleElementMap.Count == 0)
            {
                return;
            }

            if (!this.ShouldProcessElement(radElement))
            {
                return;
            }

            bool     parentNotPropagateStyleToChildren;
            StyleMap styleMap = this.FindStyleMapForElement(radElement, out parentNotPropagateStyleToChildren);

            if (styleMap != null)
            {
                styleMap.RemapElement(radElement);
            }

            if (traverseElementTree)
            {
                int elementHash = radElement.GetHashCode();
                foreach (KeyValuePair <int, StyleMap> mapEntry in this.styleElementMap)
                {
                    if (elementHash == mapEntry.Key)
                    {
                        continue;
                    }

                    if (radElement.IsAncestorOf(mapEntry.Value.StyleRootElement))
                    {
                        mapEntry.Value.RemapElement(null);
                    }
                }
            }
        }
Пример #10
0
        private StyleMap FindStyleMapForElement(RadElement radElement, out bool parentNotPropagateStyleToChildren)
        {
            parentNotPropagateStyleToChildren = false;
            StyleMap styleMap = null;

            for (RadElement toTest = radElement; toTest != null; toTest = toTest.Parent)
            {
                if (!toTest.PropagateStyleToChildren)
                {
                    parentNotPropagateStyleToChildren = true;
                    break;
                }

                if (toTest.Style == null)
                {
                    continue;
                }

                this.styleElementMap.TryGetValue(toTest.GetHashCode(), out styleMap);
                break;
            }

            return(styleMap);
        }
Пример #11
0
 /// <summary>
 /// Creates an instance of the <see cref="StylesheetTree"/> class.
 /// This class represents a parent-child selector hierarchy that
 /// comes from the loaded stylesheet.
 /// </summary>
 /// <param name="ownerStyeMap">ownerMap is used only for legacy </param>
 public StylesheetTree(StyleMap ownerStyeMap)
 {
     this.ownerStyleMap = ownerStyeMap;
     rootNode           = new StylesheetTreeNode(this, null);
 }