Example #1
0
            private void OnPalettePropertyChanged(object sender, PropertyEventArgs evtArgs)
            {
                if (this.Tag == evtArgs.Node)
                {
                    this.Text = evtArgs.Node.Name;

                    PaletteGroupView groupView = this.GroupView as PaletteGroupView;
                    SymbolModel      symModel  = evtArgs.Node as SymbolModel;
                    if (groupView != null && symModel != null)
                    {
                        if (evtArgs.PropertyName == "LargeIcon" && !groupView.SmallImageView)
                        {
                            if (symModel.LargeIcon != null)
                            {
                                this.ImageIndex = groupView.AddLargeIcon(symModel.LargeIcon);
                            }
                            else
                            {
                                this.ImageIndex = 0;
                            }
                        }
                        else if (evtArgs.PropertyName == "SmallIcon" && groupView.SmallImageView)
                        {
                            if (symModel.SmallIcon != null)
                            {
                                this.ImageIndex = groupView.AddLargeIcon(symModel.SmallIcon);
                            }
                            else
                            {
                                this.ImageIndex = 0;
                            }
                        }
                    }
                }
            }
Example #2
0
        /// <summary>
        /// Deserializes a PaletteGroupView object from the code DOM.
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="codeObject"></param>
        /// <returns></returns>
        public override object Deserialize(IDesignerSerializationManager manager, object codeObject)
        {
            object retVal = null;

            // Get base class serializer
            CodeDomSerializer baseSerializer = (CodeDomSerializer)manager.GetSerializer(typeof(GroupView), typeof(CodeDomSerializer));

            if (baseSerializer != null)
            {
                // Deserialize palette group view using base class serializer
                retVal = baseSerializer.Deserialize(manager, codeObject);

                if (retVal != null)
                {
                    // Downcast to PaletteGroupView
                    PaletteGroupView palGrpVw = retVal as PaletteGroupView;

                    if (palGrpVw != null)
                    {
                        // Load symbol palette from the resource file and attach
                        // to the palette group view
                        string resName = palGrpVw.Name + "." + "Palette";
                        System.ComponentModel.Design.IResourceService resSvc = manager.GetService(typeof(System.ComponentModel.Design.IResourceService)) as System.ComponentModel.Design.IResourceService;
                        if (resSvc != null)
                        {
                            System.Resources.IResourceReader resReader = resSvc.GetResourceReader(System.Globalization.CultureInfo.InvariantCulture);
                            if (resReader != null)
                            {
                                // Iterate through the resource file using the resource
                                // reader and find the byte stream for the palette
                                byte[] strmData = null;
                                bool   resFound = false;
                                IDictionaryEnumerator resEnum = resReader.GetEnumerator();
                                while (resEnum.MoveNext() && !resFound)
                                {
                                    if ((string)resEnum.Key == resName)
                                    {
                                        strmData = (byte[])resEnum.Value;
                                        resFound = true;
                                    }
                                }

                                if (resFound && strmData != null)
                                {
                                    palGrpVw.LoadPalette(strmData);
                                }
                            }
                        }
                    }
                }
            }

            return(retVal);
        }
Example #3
0
        /// <summary>
        /// Serializes a PaletteGroupView object to the code DOM.
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override object Serialize(IDesignerSerializationManager manager, object value)
        {
            object            retVal         = value;
            CodeDomSerializer baseSerializer = (CodeDomSerializer)manager.GetSerializer(typeof(GroupView), typeof(CodeDomSerializer));

            if (baseSerializer != null)
            {
                retVal = baseSerializer.Serialize(manager, value);
                if (retVal != null)
                {
                    System.CodeDom.CodeStatementCollection stmts = retVal as System.CodeDom.CodeStatementCollection;
                    if (stmts != null)
                    {
                        PaletteGroupView palGrpVw = value as PaletteGroupView;
                        if (palGrpVw != null)
                        {
                            SymbolPalette pal = palGrpVw.Palette;
                            if (pal != null)
                            {
                                // Serialize the palette into the resource file

                                BinaryFormatter        formatter = new BinaryFormatter();
                                System.IO.MemoryStream oStream   = new System.IO.MemoryStream();
                                formatter.Serialize(oStream, pal);
                                string resName = palGrpVw.Name + "." + "Palette";
                                this.SerializeResource(manager, resName, oStream.GetBuffer());
                                oStream.Close();

                                // Add statements to CodeDom to load the palette from
                                // the resource file at run-time

                                string        formClassName = "";
                                IDesignerHost designerHost  = manager.GetService(typeof(IDesignerHost)) as IDesignerHost;
                                if (designerHost != null)
                                {
                                    formClassName = designerHost.RootComponentClassName;
                                    CodePropertyReferenceExpression exprRefGroupView = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), palGrpVw.Name);
                                    CodeExpression[] loadPalParams = new CodeExpression[]
                                    {
                                        new CodePropertyReferenceExpression(new CodeTypeOfExpression(formClassName), "Assembly"),
                                        new CodePrimitiveExpression(formClassName),
                                        new CodePrimitiveExpression(resName)
                                    };
                                    CodeMethodInvokeExpression stmtLoadPalette = new CodeMethodInvokeExpression(exprRefGroupView, "LoadPalette", loadPalParams);
                                    stmts.Add(stmtLoadPalette);
                                }
                            }
                        }
                    }
                }
            }
            return(retVal);
        }
Example #4
0
        /// <summary>
        /// Set the selected symbol model to the one matching the given symbol model name.
        /// </summary>
        /// <param name="symbolName">Name of symbol model to select</param>
        public bool SelectSymbolModel(string symbolName)
        {
            bool found = false;

            if (this.SelectedItem < this.GroupBarItems.Count)
            {
                PaletteGroupView curGroupView = this.GroupBarItems[this.SelectedItem].Client as PaletteGroupView;
                if (curGroupView != null)
                {
                    found = curGroupView.SelectSymbolModel(symbolName);
                }
            }

            return(found);
        }
 /// <summary>
 /// Converts a SymbolPalette from other types.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="culture"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
 {
     if (value != null && value.GetType() == typeof(string))
     {
         string           fileName = (string)value;
         PaletteGroupView palGrpVw = context.Instance as PaletteGroupView;
         if (palGrpVw != null)
         {
             if (palGrpVw.LoadPalette(fileName))
             {
                 return(palGrpVw.Palette);
             }
             return(null);
         }
     }
     return(base.ConvertFrom(context, culture, value));
 }
Example #6
0
        /// <summary>
        /// Adds an existing symbol palette to the GroupBar.
        /// </summary>
        /// <param name="palette">Symbol palette to add</param>
        /// <remarks>
        /// <seealso cref="Syncfusion.Windows.Forms.Diagram.SymbolPalette"/>
        /// </remarks>
        public void AddPalette(SymbolPalette palette)
        {
            GroupBarItem paletteBarItem = new GroupBarItem();

            paletteBarItem.Text = palette.Name;
            paletteBarItem.Tag  = palette;

            PaletteGroupView paletteView = new PaletteGroupView();

            paletteView.EditMode                = this.editMode;
            paletteView.ButtonView              = true;
            paletteView.BackColor               = Color.Ivory;
            paletteView.SymbolModelSelected    += new SymbolModelEvent(OnSymbolModelSelected);
            paletteView.SymbolModelDoubleClick += new SymbolModelEvent(OnSymbolModelDoubleClick);

            paletteView.LoadPalette(palette);
            paletteBarItem.Client = paletteView;
            this.GroupBarItems.Add(paletteBarItem);
        }