Beispiel #1
0
        private void LoadStyleItems()
        {
            ICollection styles = _styleSheet.Styles;

            foreach (String key in styles)
            {
                Style style    = (Style)_styleSheet[key];
                Style newStyle = (Style)Activator.CreateInstance(style.GetType());

                PropertyDescriptorCollection propDescs = TypeDescriptor.GetProperties(style);

                for (int i = 0; i < propDescs.Count; i++)
                {
                    if (propDescs[i].Name.Equals("Font"))
                    {
                        foreach (PropertyDescriptor desc in TypeDescriptor.GetProperties(style.Font))
                        {
                            desc.SetValue(newStyle.Font, desc.GetValue(style.Font));
                        }
                    }
                    else if (!propDescs[i].IsReadOnly)
                    {
                        propDescs[i].SetValue(newStyle, propDescs[i].GetValue(style));
                    }
                }

                _tempStyleSheet[newStyle.Name] = newStyle;
                newStyle.SetControl(_tempStyleSheet);

                StyleNode newStyleItem = new StyleNode(newStyle);
                _tvDefinedStyles.Nodes.Add(newStyleItem);
            }
        }
Beispiel #2
0
 protected override void AddParsedSubObject(Object o)
 {
     if (o is Style)
     {
         Style style = (Style)o;
         style.SetControl(this);
         String name = style.Name;
         if (name == null || name == String.Empty)
         {
             throw new Exception(
                 SR.GetString(SR.StyleSheet_MustContainID));
         }
         // Remember any duplicate styles we encounter.  Validate()
         // will throw if this list is not empty.
         String lowerName = name.ToLower(CultureInfo.InvariantCulture);
         if (_styles[lowerName] != null)
         {
             _duplicateStyles.Add(style);
         }
         else
         {
             // Do not overwrite hash table with duplicate style or we
             // will loose the overwritten style in the designer.
             this[name] = style;
         }
     }
     else
     {
         base.AddParsedSubObject(o);
     }
 }
Beispiel #3
0
        protected override void LoadViewState(Object savedState)
        {
            if (savedState != null)
            {
                Object[] o = (Object[])savedState;
                base.LoadViewState(o[0]);

                if (o[2] != null)
                {
                    bool savedAll = (bool)o[1];
                    Object[] stylesState = (Object[])o[2];

                    if (savedAll)
                    {
                        _saveAll = true;
                        _styles.Clear();
                    }

                    int stylesCount = _styles.Count;
                    for (int i = 0; i < stylesState.Length; i++)
                    {
                        if (i >= stylesCount)
                        {
                            Style style = new Style();
                            IStateManager styleStateMgr = (IStateManager)style;

                            styleStateMgr.LoadViewState(stylesState[i]);
                            styleStateMgr.TrackViewState();
                            style.SetControl(this);
                            _styles[style.Name.ToLower(CultureInfo.InvariantCulture)] = style;
                        }
                        else if (stylesState != null)
                        {
                            ((IStateManager)_styles.GetAt(i)).LoadViewState(stylesState[i]);
                        }
                    }
                }
            }
        }
Beispiel #4
0
        private void OnCreateNewStyle()
        {
            String newStyleAutoID = AutoIDStyle();

            Style newStyle = (Style)Activator.CreateInstance(_currentNewStyleType);

            Debug.Assert(newStyle != null);
            newStyle.Name = newStyleAutoID;

            // Add this style to StyleSheet
            _tempStyleSheet[newStyle.Name] = newStyle;
            newStyle.SetControl(_tempStyleSheet);

            StyleNode newStyleItem = new StyleNode(newStyle);

            _tvDefinedStyles.Enabled = true;
            _propertyBrowser.Enabled = true;
            _tvDefinedStyles.Nodes.Add(newStyleItem);
            SelectedStyle = newStyleItem;

            UpdateSamplePreview();
            UpdateButtonsEnabling();
        }
        /// <include file='doc\StyleSheet.uex' path='docs/doc[@for="StyleSheet.LoadViewState"]/*' />
        protected override void LoadViewState(Object savedState)
        {
            if (savedState != null)
            {
                Object[] o = (Object[])savedState;
                base.LoadViewState(o[0]);

                if (o[2] != null)
                {
                    bool savedAll = (bool)o[1];
                    Object[] stylesState = (Object[])o[2];

                    if (savedAll)
                    {
                        _saveAll = true;
                        _styles.Clear();
                    }

                    int stylesCount = _styles.Count;
                    for (int i = 0; i < stylesState.Length; i++)
                    {
                        if (i >= stylesCount)
                        {
                            Style style = new Style();
                            IStateManager styleStateMgr = (IStateManager)style;

                            styleStateMgr.LoadViewState(stylesState[i]);
                            styleStateMgr.TrackViewState();
                            style.SetControl(this);
                            _styles[style.Name.ToLower(CultureInfo.InvariantCulture)] = style;
                        }
                        else if (stylesState != null)
                        {
                            ((IStateManager)_styles.GetAt(i)).LoadViewState(stylesState[i]);
                        }
                    }
                }
            }
        }