/** * */ internal StyleTable CreateProtoChainRoot(bool registerClone = true) { StyleTable root = new StyleTable(); // If there's a defaultFactory for this style sheet, // then add the object it produces to the root. if (null != Set1) { root = root.CloneAndOverrideWith(Set1.Produce()); } // If there's a factory for this style sheet, // then add the object it produces to the root. if (null != Set2) { root = root.CloneAndOverrideWith(Set2.Produce()); } if (registerClone) { _clones.Add(root); } return(root); }
/// <summary> /// Gets the style /// </summary> /// <param name="styleProp"></param> /// <returns></returns> // ReSharper disable MemberCanBePrivate.Global public object GetStyle(string styleProp) // ReSharper restore MemberCanBePrivate.Global { // First look in the overrides, in case setStyle() // has been called on this StyleDeclaration. if (null != _overrides) { // If the property exists in our overrides, but // has 'undefined' as its value, it has been // cleared from this stylesheet so return // undefined. /*if (_overrides.ContainsKey(styleProp) && UNDEFINED.Equals(_overrides[styleProp])) * { * return UNDEFINED; * }*/ if (_overrides.ContainsKey(styleProp)) { var v = _overrides[styleProp]; if (!UNDEFINED.Equals(v)) // must use !== { return(v); } } } // not found in overrides if (null != Set2) { StyleTable o = Set2.Produce(); object v = o.GetValue(styleProp); if (!UNDEFINED.Equals(v)) { return(v); } } // not found in stylesheet if (null != Set1) { StyleTable o = Set1.Produce(); object v = o.GetValue(styleProp); if (!UNDEFINED.Equals(v)) { return(v); } } // not faund in default values // so return null return(UNDEFINED); }
// ReSharper restore UnassignedField.Global #endif ///<summary> ///</summary> ///<param name="chain">Replikativni Dictionary</param> ///<param name="target"></param> ///<returns></returns> internal virtual StyleTable AddStyleToProtoChain(StyleTable chain, object target /*, object filterMap*/) { //Debug.Log("AddStyleToProtoChain: chain: " + chain + "; target: " + target); bool nodeAddedToChain = false; //var originalChain = chain; //if (filterMap) //{ // chain = {}; //} #if DEBUG if (!string.IsNullOrEmpty(DebugId)) { Debug.Log(DebugId + " 0. " + chain); } #endif // If there's a defaultFactory for this style sheet, // then add the object it produces to the chain. if (null != Set1) { chain = chain.CloneAndOverrideWith(Set1.Produce()); nodeAddedToChain = true; } #if DEBUG if (!string.IsNullOrEmpty(DebugId)) { Debug.Log(DebugId + " 1. " + chain); } #endif // If there's a factory for this style sheet, // then add the object it produces to the chain. if (null != Set2) { chain = chain.CloneAndOverrideWith(Set2.Produce()); nodeAddedToChain = true; } #if DEBUG if (!string.IsNullOrEmpty(DebugId)) { Debug.Log(DebugId + " 2. " + chain); } #endif //Debug.Log("-- chain: " + chain); // If someone has called setStyle() on this StyleDeclaration, // then some of the values returned from the factory are // out-of-date. Overwrite them with the up-to-date values. if (null != _overrides) { // Before we add our overrides to the object at the head of // the chain, make sure that we added an object at the head // of the chain. if (null == Set1 && null == Set2) { chain = (StyleTable)chain.Clone(); nodeAddedToChain = true; } foreach (string p in _overrides.Keys) { if (!UNDEFINED.Equals(_overrides[p])) { chain[p] = _overrides[p]; } /*if (UNDEFINED.Equals(_overrides[p])) * chain.Remove(p); * else * chain[p] = _overrides[p];*/ } } #if DEBUG if (!string.IsNullOrEmpty(DebugId)) { Debug.Log(DebugId + " 3. " + chain); } #endif #region _complex ////if (filterMap) ////{ // if (nodeAddedToChain) // { // //Debug.Log("nodeAddedToChain"); // //var filteredChain = new Dictionary<string, object>(); // //for (string i in chain) // //{ // // if (filterMap[i] != null) // // { // // filteredChain[filterMap[i]] = chain[i]; // // } // //} // //var f = new StyleTableValuesFactory(originalChain); // chain = (StyleTable) originalChain.Clone(); // //chain = originalChain; // //chain = filteredChain; // //chain = f.Produce(); // //chain[FILTERMAP_PROP] = filterMap; // } // else // { // chain = originalChain; // } ////} #endregion if (nodeAddedToChain) { _clones.Add(chain); } return(chain); }
/// <summary> /// Private /// </summary> /// <param name="styleProp"></param> /// <param name="value"></param> internal void SetLocalStyle(string styleProp, object value) { //object oldValue = GetStyle(styleProp); if (UNDEFINED.Equals(value)) { ClearStyleAttr(styleProp); return; } StyleTable o; if (null != Set1) { o = Set1.Produce(); if (!o.ContainsKey(styleProp) || o[styleProp] != value) // Defaultni factory nema taj stil ili ga ima ali s različitom vrijednošću { /** * Defaultni factory ima različitu vrijednost ovog stila, znači radi se o overrideu * Kreirajmo overrides tablicu i u njoj setirajmo stil * */ if (null == _overrides) { _overrides = new StyleTable(); } _overrides[styleProp] = value; } else if (null != _overrides && _overrides.ContainsKey(styleProp)) // Defaultni factory ima taj stil i to sa istom vrijednošću { /** * Obrišimo ga u overrides tabeli * */ _overrides.Remove(styleProp); } } if (null != Set2) { o = Set2.Produce(); if (!o.ContainsKey(styleProp) || o[styleProp] != value) { if (null == _overrides) { _overrides = new StyleTable(); } _overrides[styleProp] = value; } else if (null != _overrides && _overrides.ContainsKey(styleProp)) { _overrides.Remove(styleProp); } } if (null == Set1 && null == Set2) // Ne postoji niti jedan factory (ni metadata, ni stylesheet) { if (null == _overrides) { _overrides = new StyleTable(); } _overrides[styleProp] = value; } UpdateClones(styleProp, value); }