Example #1
0
 private void setConstructorValues()
 {
     if (_owner != null && _owner.Pointer != null)
     {
         ClassInstancePointer cip = _owner.Pointer as ClassInstancePointer;
         if (cip != null && cip.Host != null)
         {
             ClassPointer cp = cip.Host as ClassPointer;
             if (cp != null)
             {
                 IXType xt = cp.ObjectList.GetObjectByID(cip.MemberId) as IXType;
                 if (xt != null)
                 {
                     Dictionary <string, object> cvs = xt.GetConstructorParameterValues();
                     if (cvs != null)
                     {
                         foreach (KeyValuePair <string, object> kv in cvs)
                         {
                             this.SetConstructorValue(kv.Key, kv.Value);
                         }
                     }
                 }
             }
         }
     }
 }
Example #2
0
 public void OnPostSerialize(XmlSerializer.ObjectIDmap objMap, System.Xml.XmlNode objectNode, bool saved, object serializer)
 {
     if (saved)
     {
     }
     else
     {
         if (_pointer == null && _memberPointer == null)
         {
             XmlNode node = SerializeUtil.GetClassRefNodeByObjectId(objectNode, _memberId);
             if (node != null)
             {
                 XmlObjectReader xr = (XmlObjectReader)serializer;
                 _pointer = xr.ReadObject <ClassInstancePointer>(node, ClassPointer.CreateClassPointer(objMap));
                 //_pointer.ObjectInstance = objMap.GetObjectByID(_pointer.MemberId);
             }
             else
             {
                 _pointer = objMap.GetClassRefById(_memberId) as ClassInstancePointer;
             }
         }
         if (_pointer == null)
         {
             object v = objMap.GetObjectByID(_memberId);
             if (v != null)
             {
                 _memberPointer = new MemberComponentId(objMap.GetTypedData <ClassPointer>(), v, _memberId);
             }
         }
         if (_pointer == null && _memberPointer == null)
         {
             objMap.AddPostProcessor(this);
         }
     }
 }
        public void OnComponentRemoved(object obj)
        {
            ObjectIDmap          map = null;
            ClassInstancePointer cr  = obj as ClassInstancePointer;

            if (cr != null)
            {
                map = _loader.ObjectMap.GetMap(cr.ObjectInstance);
            }
            else
            {
                map = _loader.ObjectMap.GetMap(obj);
            }
            //if (map == null)
            //{
            //    throw new DesignerException("object map not found for {0} when removing component", obj);
            //}
            if (map != null)
            {
                TreeNode node = null;
                if (cr != null)
                {
                    node = _objExplorer.LocateNode(cr);
                }
                else
                {
                    IObjectPointer o = DesignUtil.CreateObjectPointer(map, obj);
                    node = _objExplorer.LocateNode(o);
                }
                if (node != null)
                {
                    node.Remove();
                }
            }
        }
Example #4
0
 public ComponentPointer(ClassInstancePointer cr)
 {
     _pointer = cr;
     if (cr != null)
     {
         _memberId = cr.MemberId;
     }
 }
Example #5
0
 public void OnDeserialize(object context)
 {
     if (_pointer == null)
     {
         ClassPointer cp = (ClassPointer)context;
         _pointer = (ClassInstancePointer)cp.ObjectList.GetClassRefById(_memberId);
         if (_pointer != null)
         {
             if (_pointer.Definition == null)
             {
                 //_pointer.ReplaceDeclaringClassPointer(cp);
             }
         }
     }
 }
Example #6
0
        public object Clone()
        {
            ClassInstancePointer ip = new ClassInstancePointer();

            ip._hostingClass    = _hostingClass;
            ip._definingClass   = _definingClass;
            ip._definingClassId = _definingClassId;
            ip._memberId        = _memberId;
            ip.ImageIcon        = this.ImageIcon;
            ip._name            = _name;
            ip._icon            = _icon;
            ip._typeName        = _typeName;
            ip._site            = _site;
            ip._iconFilename    = _iconFilename;
            ip._properties      = _properties;
            return(ip);
        }
Example #7
0
        public bool IsSameObjectRef(IObjectIdentity objectPointer)
        {
            ClassInstancePointer obj = objectPointer as ClassInstancePointer;

            if (obj != null)
            {
                return(this.WholeId == obj.WholeId);
            }
            MemberComponentId mc = objectPointer as MemberComponentId;

            if (mc != null)
            {
                ClassInstancePointer cr = mc.ObjectInstance as ClassInstancePointer;
                if (cr != null)
                {
                    return(this.WholeId == cr.WholeId);
                }
            }
            return(false);
        }
Example #8
0
        public CodeExpression GetReferenceCode(IMethodCompile method, CodeStatementCollection statements, bool forValue)
        {
            ClassInstancePointer cp = _hostingClass as ClassInstancePointer;

            if (cp != null)
            {
                CodeExpression co = cp.GetReferenceCode(method, statements, forValue);
                return(new CodeFieldReferenceExpression(co, Name));
            }
            else
            {
                if (_memberId == 0)
                {
                    if (_definingClass != null)
                    {
                        if (typeof(DrawingPage).IsAssignableFrom(_definingClass.BaseClassType))
                        {
                            return(new CodePropertyReferenceExpression(new CodeTypeReferenceExpression(_definingClass.TypeString), DrawingPage.DEFAULTFORM));
                        }
                    }
                }
                ClassPointer root = _hostingClass as ClassPointer;
                if (root != null)
                {
                    if (root.IsStatic)
                    {
                        return(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(root.TypeString), Name));
                    }
                    else
                    {
                        return(new CodeArgumentReferenceExpression(Name));
                    }
                }
                else
                {
                    return(new CodeArgumentReferenceExpression(Name));
                }
            }
        }
Example #9
0
        public override object OnGetDropDownControl(ITypeDescriptorContext context, IServiceProvider provider, IWindowsFormsEditorService service, object value)
        {
            ComponentPointer cp = (ComponentPointer)value;
            IComponent       h  = context.Instance as IComponent;

            if (h == null || h.Site == null)
            {
                h = VPL.VPLUtil.GetObject(context.Instance) as IComponent;
            }
            if (h == null || h.Site == null)
            {
                ClassPointer root = context.Instance as ClassPointer;
                if (root != null)
                {
                    h = root.ObjectInstance as IComponent;
                }
            }
            if (h == null || h.Site == null)
            {
                IObjectPointer op = context.Instance as IObjectPointer;
                if (op != null)
                {
                    ClassPointer root = op.RootPointer;
                    if (root != null)
                    {
                        h = root.ObjectInstance as IComponent;
                    }
                }
            }
            if (h != null && h.Site != null)
            {
                ListBox list = new ListBox();
                list.Tag       = service;
                list.Click    += new EventHandler(list_Click);
                list.KeyPress += new KeyPressEventHandler(list_KeyPress);
                foreach (IComponent ic in h.Site.Container.Components)
                {
                    if (ic is T)
                    {
                        list.Items.Add(new ComponentName(ic));
                    }
                    else
                    {
                        Type t = VPL.VPLUtil.GetObjectType(ic);
                        if (typeof(T).IsAssignableFrom(t))
                        {
                            int n = list.Items.Add(new ComponentName(ic));
                            if (cp != null && list.SelectedIndex < 0 && ic.Site != null)
                            {
                                if (cp.Name == ic.Site.Name)
                                {
                                    list.SelectedIndex = n;
                                }
                            }
                        }
                    }
                }
                if (list.Items.Count > 0)
                {
                    service.DropDownControl(list);
                    if (list.SelectedIndex >= 0)
                    {
                        ComponentName c = list.Items[list.SelectedIndex] as ComponentName;
                        if (c != null)
                        {
                            ILimnorDesignerLoader loader = LimnorProject.ActiveDesignerLoader as ILimnorDesignerLoader;
                            UInt32 memberId = loader.ObjectMap.GetObjectID(c.Component);
                            if (memberId != 0)
                            {
                                XmlNode nodeCr = SerializeUtil.GetClassRefNodeByObjectId(loader.Node, memberId);
                                if (nodeCr != null)
                                {
                                    loader.Reader.ResetErrors();
                                    ClassInstancePointer cr = loader.Reader.ReadObject <ClassInstancePointer>(nodeCr, loader.GetRootId());
                                    if (loader.Reader.HasErrors)
                                    {
                                        MathNode.Log(loader.Reader.Errors);
                                    }
                                    ComponentPointer pt = new ComponentPointer(cr);
                                    value = pt;
                                }
                                else
                                {
                                    MemberComponentId cid = new MemberComponentId(loader.GetRootId(), c.Component, memberId);
                                    ComponentPointer  pt  = new ComponentPointer(cid);
                                    value = pt;
                                }
                            }
                        }
                    }
                }
            }
            return(value);
        }
Example #10
0
 public ClassProperties(ClassInstancePointer owner)
 {
     _pointer = owner;
     _owner   = VPLUtil.GetObject(owner.ObjectInstance);
 }
Example #11
0
 public void OnPostSerialize(ObjectIDmap objMap, XmlNode objectNode, bool saved, object serializer)
 {
     if (saved)
     {
         XmlUtil.SetNameAttribute(objectNode, _name);
         XmlUtil.SetAttribute(objectNode, XmlTags.XMLATT_instanceId, _memberId);
         XmlUtil.SetAttribute(objectNode, XmlTags.XMLATT_ClassID, ClassId);
         ClassInstancePointer ip = _hostingClass as ClassInstancePointer;
         if (ip != null)
         {
             XmlNode nd = XmlUtil.CreateSingleNewElement(objectNode, XmlTags.XML_ClassInstance);
             ip.OnPostSerialize(objMap, nd, saved, serializer);
         }
         else
         {
             ClassPointer root = _hostingClass as ClassPointer;
             if (root != null)
             {
                 if (root.ClassId != objMap.ClassId)
                 {
                     XmlUtil.SetAttribute(objectNode, XmlTags.XMLATT_hostClassId, root.ClassId);
                 }
             }
         }
         //save custom property values
         if (_properties != null)
         {
             XmlObjectWriter writer           = (XmlObjectWriter)serializer;
             PropertyDescriptorCollection pdc = new PropertyDescriptorCollection(_properties.ToArray());
             writer.WriteProperties(objectNode, pdc, this, XmlTags.XML_PROPERTY);
         }
     }
     else
     {
         _name = XmlUtil.GetNameAttribute(objectNode);
         if (_memberId == 0)
         {
             _memberId = XmlUtil.GetAttributeUInt(objectNode, XmlTags.XMLATT_instanceId);
         }
         XmlNode nd = objectNode.SelectSingleNode(XmlTags.XML_ClassInstance);
         if (nd == null)
         {
             //load _hostingClass
             if (_hostingClass == null)
             {
                 ClassPointer root;
                 UInt32       hostClassId = XmlUtil.GetAttributeUInt(objectNode, XmlTags.XMLATT_hostClassId);
                 if (hostClassId == 0)
                 {
                     root = ClassPointer.CreateClassPointer(objMap);
                 }
                 else
                 {
                     if (hostClassId == objMap.ClassId)
                     {
                         root = ClassPointer.CreateClassPointer(objMap);
                     }
                     else
                     {
                         root = ClassPointer.CreateClassPointer(hostClassId, objMap.Project);
                     }
                 }
                 if (root == null)
                 {
                     throw new DesignerException("Invalid class id: {0}", hostClassId);
                 }
                 _hostingClass = root;
                 if (_definingClassId == 0)                         //ClassId may be loaded by property deserialize
                 {
                     IClassRef r = root.ObjectList.GetClassRefById(MemberId);
                     if (r != null)
                     {
                         _definingClassId = r.ClassId;
                     }
                 }
             }
             //load _definingClass
             if (_definingClass == null)
             {
                 if (_definingClassId == 0)
                 {
                     _definingClassId = XmlUtil.GetAttributeUInt(objectNode, XmlTags.XMLATT_ClassID);
                 }
                 if (_definingClassId == 0)
                 {
                     ClassPointer root = (ClassPointer)_hostingClass;
                     IClassRef    r    = root.ObjectList.GetClassRefById(MemberId);
                     if (r != null)
                     {
                         _definingClassId = r.ClassId;
                     }
                 }
                 _definingClass = ClassPointer.CreateClassPointer(_definingClassId, objMap.Project);
             }
         }
         else
         {
             _definingClassId = XmlUtil.GetAttributeUInt(objectNode, XmlTags.XMLATT_ClassID);
             ClassInstancePointer ip = new ClassInstancePointer();
             ip.OnPostSerialize(objMap, nd, saved, serializer);
             _hostingClass = ip;
             if (this.ClassId == 0)                     //ClassId may be loaded by property deserialize
             {
                 if (_hostingClass.Definition.ObjectList.Count == 0)
                 {
                     _hostingClass.Definition.ObjectList.LoadObjects();
                     if (_hostingClass.Definition.ObjectList.Reader.HasErrors)
                     {
                         MathNode.Log(_hostingClass.Definition.ObjectList.Reader.Errors);
                         _hostingClass.Definition.ObjectList.Reader.ResetErrors();
                     }
                 }
                 IClassRef r = _hostingClass.Definition.ObjectList.GetClassRefById(_memberId);
                 _definingClassId = r.ClassId;
             }
             if (_definingClass == null)
             {
                 _definingClass = ClassPointer.CreateClassPointer(_definingClassId, objMap.Project);
             }
         }
         if (MemberId == 0 && _definingClassId == 0)
         {
             //backward compatebility
             _definingClassId = XmlUtil.GetAttributeUInt(objectNode, XmlTags.XMLATT_ClassID);
             MemberId         = XmlUtil.GetAttributeUInt(objectNode, XmlTags.XMLATT_ComponentID);
             _definingClass   = objMap.Project.GetTypedData <ClassPointer>(_definingClassId);
             _hostingClass    = objMap.GetTypedData <ClassPointer>();
         }
         if (_definingClass != null)                 //not being deleted
         {
             //load custom property definitions
             XmlObjectReader reader = _definingClass.ObjectList.Reader;
             if (reader == null)
             {
                 reader = (XmlObjectReader)serializer;
             }
             LoadProperties(reader);
             //load custom property values
             LoadCustomPropertyValues(reader, objectNode);
         }
         if (MemberId == 0)
         {
             MemberId = XmlUtil.GetAttributeUInt(objectNode, XmlTags.XMLATT_ComponentID);
         }
     }
 }