LookupClassByName() 공개 정적인 메소드

public static LookupClassByName ( string cname ) : ClassDescriptor
cname string
리턴 ClassDescriptor
예제 #1
0
        static public void Read(ObjectWrapper wrapper, XmlElement elem)
        {
            string className = elem.GetAttribute("class");

            if (className == null)
            {
                throw new GladeException("<widget> node with no class name");
            }

            ClassDescriptor klass = Registry.LookupClassByName(className);

            if (klass == null)
            {
                throw new GladeException("No stetic ClassDescriptor for " + className);
            }

            Gtk.Widget widget = (Gtk.Widget)wrapper.Wrapped;
            if (widget == null)
            {
                widget = (Gtk.Widget)klass.CreateInstance(wrapper.Project);
                ObjectWrapper.Bind(wrapper.Project, klass, wrapper, widget, true);
            }

            widget.Name = elem.GetAttribute("id");

            ReadMembers(klass, wrapper, widget, elem);

            if (!(widget is Gtk.Window))
            {
                widget.ShowAll();
            }
        }
예제 #2
0
        public object[] GetClassDescriptorInitializationValues(string name)
        {
            ClassDescriptor cls  = Registry.LookupClassByName(name);
            ArrayList       list = new ArrayList();

            foreach (Stetic.PropertyDescriptor prop in cls.InitializationProperties)
            {
                if (prop.PropertyType.IsValueType)
                {
                    // Avoid sending to the main process types which should not be loaded there
                    if (prop.PropertyType.Assembly == typeof(object).Assembly ||
                        prop.PropertyType.Assembly == typeof(Gtk.Widget).Assembly ||
                        prop.PropertyType.Assembly == typeof(Gdk.Window).Assembly ||
                        prop.PropertyType.Assembly == typeof(GLib.Object).Assembly)
                    {
                        list.Add(Activator.CreateInstance(prop.PropertyType));
                    }
                    else
                    {
                        return(new object [0]);
                    }
                }
                else
                {
                    list.Add(null);
                }
            }
            return(list.ToArray());
        }
예제 #3
0
        static Gdk.Pixbuf GetEmbeddedIcon(AssemblyDefinition asm, string iconname)
        {
            Gdk.Pixbuf icon = null;
            if (iconname != null && iconname.Length > 0)
            {
                try
                {
                    // Using the pixbuf resource constructor generates a gdk warning.
                    EmbeddedResource res    = GetResource(asm, iconname);
                    Gdk.PixbufLoader loader = new Gdk.PixbufLoader(res.GetResourceData());
                    icon = loader.Pixbuf;
                }
                catch
                {
                    // Ignore
                }
            }

            if (icon == null)
            {
                ClassDescriptor cc = Registry.LookupClassByName("Gtk.Bin");
                icon = cc.Icon;
            }
            return(icon);
        }
예제 #4
0
        public static ObjectWrapper ReadObject(ObjectReader reader, XmlElement elem)
        {
            string          className = elem.GetAttribute("class");
            ClassDescriptor klass;

            if (reader.Format == FileFormat.Native)
            {
                klass = Registry.LookupClassByName(className);
            }
            else
            {
                klass = Registry.LookupClassByCName(className);
            }

            if (klass == null)
            {
                ErrorWidget        we   = new ErrorWidget(className, elem.GetAttribute("id"));
                ErrorWidgetWrapper wrap = (ErrorWidgetWrapper)Create(reader.Project, we);
                wrap.Read(reader, elem);
                return(wrap);
            }
            if (!klass.SupportsGtkVersion(reader.Project.TargetGtkVersion))
            {
                ErrorWidget        we   = new ErrorWidget(className, klass.TargetGtkVersion, reader.Project.TargetGtkVersion, elem.GetAttribute("id"));
                ErrorWidgetWrapper wrap = (ErrorWidgetWrapper)Create(reader.Project, we);
                wrap.Read(reader, elem);
                return(wrap);
            }

            ObjectWrapper wrapper = klass.CreateWrapper();

            wrapper.classDescriptor = klass;
            wrapper.proj            = reader.Project;
            return(ReadObject(reader, elem, wrapper));
        }
예제 #5
0
        public object AddNewWidget(string type, string name)
        {
            ClassDescriptor cls = Registry.LookupClassByName(type);

            Gtk.Widget w = (Gtk.Widget)cls.NewInstance(this);
            w.Name = name;
            this.AddWidget(w);
            return(Component.GetSafeReference(ObjectWrapper.Lookup(w)));
        }
예제 #6
0
        internal override ComponentType CreateComponentType(string typeName)
        {
            ClassDescriptor cls = Registry.LookupClassByName(typeName);

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

            return(new ComponentType(this, typeName, cls.Label, cls.WrappedTypeName, cls.Category, cls.TargetGtkVersion, cls.Library.Name, cls.Icon));
        }
예제 #7
0
        public static ObjectWrapper Create(IProject proj, object wrapped)
        {
            ClassDescriptor klass   = Registry.LookupClassByName(wrapped.GetType().FullName);
            ObjectWrapper   wrapper = klass.CreateWrapper();

            wrapper.Loading         = true;
            wrapper.proj            = proj;
            wrapper.classDescriptor = klass;
            wrapper.Wrap(wrapped, true);
            wrapper.OnWrapped();
            wrapper.Loading = false;
            return(wrapper);
        }
예제 #8
0
        public PropertyGridHeader()
        {
            name = (PropertyDescriptor)Registry.LookupClassByName("Gtk.Widget") ["Name"];
            AppendProperty(name);

            Gtk.HBox box = new Gtk.HBox(false, 6);
            image = new Gtk.Image();
            box.PackStart(image, false, false, 0);
            label = new Gtk.Label();
            box.PackStart(label, false, false, 0);
            box.ShowAll();
            AppendPair("Widget Class", box, null);
        }
예제 #9
0
        public static ObjectWrapper ReadObject(ObjectReader reader, XmlElement elem)
        {
            string          className = elem.GetAttribute("class");
            ClassDescriptor klass;

            if (reader.Format == FileFormat.Native)
            {
                klass = Registry.LookupClassByName(className);
            }
            else
            {
                klass = Registry.LookupClassByCName(className);
            }

            if (klass == null)
            {
                ErrorWidget        we   = new ErrorWidget(className, elem.GetAttribute("id"));
                ErrorWidgetWrapper wrap = (ErrorWidgetWrapper)Create(reader.Project, we);
                wrap.Read(reader, elem);
                return(wrap);
            }
            if (!klass.SupportsGtkVersion(reader.Project.TargetGtkVersion))
            {
                ErrorWidget        we   = new ErrorWidget(className, klass.TargetGtkVersion, reader.Project.TargetGtkVersion, elem.GetAttribute("id"));
                ErrorWidgetWrapper wrap = (ErrorWidgetWrapper)Create(reader.Project, we);
                wrap.Read(reader, elem);
                return(wrap);
            }

            ObjectWrapper wrapper = klass.CreateWrapper();

            wrapper.classDescriptor = klass;
            wrapper.proj            = reader.Project;
            try {
                wrapper.OnBeginRead(reader.Format);
                wrapper.Read(reader, elem);
            } catch (Exception ex) {
                Console.WriteLine(ex);
                ErrorWidget        we   = new ErrorWidget(ex, elem.GetAttribute("id"));
                ErrorWidgetWrapper wrap = (ErrorWidgetWrapper)Create(reader.Project, we);
                wrap.Read(reader, elem);
                return(wrap);
            } finally {
                wrapper.OnEndRead(reader.Format);
            }
            return(wrapper);
        }
예제 #10
0
        public static ObjectWrapper Create(IProject proj, object wrapped, ObjectWrapper root)
        {
            ClassDescriptor klass   = Registry.LookupClassByName(wrapped.GetType().FullName);
            ObjectWrapper   wrapper = klass.CreateWrapper();

            if (root != null)
            {
                wrapper.RootWrapperName = (root.RootWrapperName != null) ? root.RootWrapperName : root.Name;
            }
            wrapper.Loading         = true;
            wrapper.proj            = proj;
            wrapper.classDescriptor = klass;
            wrapper.Wrap(wrapped, true);
            wrapper.OnWrapped();
            wrapper.Loading = false;
            return(wrapper);
        }
예제 #11
0
        internal void BeginComponentDrag(ProjectBackend project, string desc, string className, ObjectWrapper wrapper, Gtk.Widget source, Gdk.DragContext ctx, ComponentDropCallback callback)
        {
            if (wrapper != null)
            {
                Stetic.Wrapper.ActionPaletteItem it = new Stetic.Wrapper.ActionPaletteItem(Gtk.UIManagerItemType.Menuitem, null, (Wrapper.Action)wrapper);
                DND.Drag(source, ctx, it);
            }
            else if (callback != null)
            {
                DND.Drag(source, ctx, delegate()
                {
                    callback();

                    // If the class name has an assembly name, remove it now
                    int i = className.IndexOf(',');
                    if (i != -1)
                    {
                        className = className.Substring(0, i);
                    }

                    ClassDescriptor cls = Registry.LookupClassByName(className);
                    if (cls != null)
                    {
                        return(cls.NewInstance(project) as Gtk.Widget);
                    }
                    else
                    {
                        // Class not found, show an error
                        string msg            = string.Format("The widget '{0}' could not be found.", className);
                        Gtk.MessageDialog dlg = new Gtk.MessageDialog(null, Gtk.DialogFlags.Modal, Gtk.MessageType.Error, Gtk.ButtonsType.Close, msg);
                        dlg.Run();
                        dlg.Destroy();
                        return(null);
                    }
                },
                         (desc != null && desc.Length > 0) ? desc : className
                         );
            }
            else
            {
                ClassDescriptor cls = Registry.LookupClassByName(className);
                DND.Drag(source, ctx, cls.NewInstance(project) as Gtk.Widget);
            }
        }
예제 #12
0
        bool SelectedHandler()
        {
            SaveStatus();

            Clear();

            selection = newSelection;
            if (selection == null || selection.Wrapped is ErrorWidget || project == null)
            {
                return(false);
            }

            Wrapper.Widget selWidget = selection as Wrapper.Widget;
            if (selWidget != null)
            {
                selWidget.Notify += Notified;

                PropertyDescriptor name = (PropertyDescriptor)Registry.LookupClassByName("Gtk.Widget") ["Name"];
                AppendProperty(name, selection.Wrapped);
            }

            AddProperties(selection.ClassDescriptor.ItemGroups, selection.Wrapped, project.TargetGtkVersion);

            if (selWidget != null)
            {
                packingSelection = Stetic.Wrapper.Container.ChildWrapper(selWidget);
                if (packingSelection != null)
                {
                    ClassDescriptor childklass = packingSelection.ClassDescriptor;
                    if (childklass.ItemGroups.Count > 0)
                    {
                        AddProperties(childklass.ItemGroups, packingSelection.Wrapped, project.TargetGtkVersion);
                        packingSelection.Notify += Notified;
                    }
                }
            }

            RestoreStatus();
            return(false);
        }
예제 #13
0
        public bool GetClassDescriptorInfo(string name, out string desc, out string className, out string category, out string targetGtkVersion, out string library, out byte[] icon)
        {
            ClassDescriptor cls = Registry.LookupClassByName(name);

            if (cls == null)
            {
                icon             = null;
                desc             = null;
                className        = null;
                category         = null;
                targetGtkVersion = null;
                library          = null;
                return(false);
            }
            desc             = cls.Label;
            className        = cls.WrappedTypeName;
            category         = cls.Category;
            targetGtkVersion = cls.TargetGtkVersion;
            library          = cls.Library.Name;
            icon             = cls.Icon != null?cls.Icon.SaveToBuffer("png") : null;

            return(true);
        }
        public TypedClassDescriptor(Assembly assembly, XmlElement elem)
        {
            bool inheritedWrapper = false;

            wrapped = Registry.GetType(elem.GetAttribute("type"), true);
            if (wrapped != null)
            {
                ConstructorInfo[] cInfos = wrapped.GetConstructors();
                foreach (ConstructorInfo ci in cInfos)
                {
                    if (ci.GetParameters().Length == 0)
                    {
                        cinfoNoParams = ci;
                        break;
                    }
                }
            }

            if (elem.HasAttribute("wrapper"))
            {
                wrapper = Registry.GetType(elem.GetAttribute("wrapper"), true);
            }
            else
            {
                inheritedWrapper = true;
                string baseClass = elem.GetAttribute("base-type");
                if (baseClass.Length > 0)
                {
                    // If a base type is specified, use the wrapper of that base type
                    TypedClassDescriptor parent = Registry.LookupClassByName(baseClass) as TypedClassDescriptor;
                    if (parent != null)
                    {
                        wrapper = parent.WrapperType;
                    }
                }
                else
                {
                    for (Type type = wrapped.BaseType; type != null; type = type.BaseType)
                    {
                        TypedClassDescriptor parent = Registry.LookupClassByName(type.FullName) as TypedClassDescriptor;
                        if (parent != null)
                        {
                            wrapper = parent.WrapperType;
                            break;
                        }
                    }
                }
                if (wrapper == null)
                {
                    throw new ArgumentException(string.Format("No wrapper type for class {0}", wrapped.FullName));
                }
            }

            gtype = (GLib.GType)wrapped;
            cname = gtype.ToString();

            string iconname = elem.GetAttribute("icon");

            if (iconname.Length > 0)
            {
                try {
                    // Using the pixbuf resource constructor generates a gdk warning.
                    Gdk.PixbufLoader loader = new Gdk.PixbufLoader(assembly, iconname);
                    icon = loader.Pixbuf;
                } catch {
                    Console.WriteLine("Could not load icon: " + iconname);
                    icon = GetDefaultIcon();
                }
            }
            else
            {
                icon = GetDefaultIcon();
            }

            BindingFlags flags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly;

            // If the wrapper is inherited from a base class, ignore the CreateInstance method
            // since it is going to create an instance of the base class.
            if (!inheritedWrapper)
            {
                ctorMethodInfoWithClass = wrapper.GetMethod("CreateInstance", flags, null, new Type[] { typeof(ClassDescriptor) }, null);
                if (ctorMethodInfoWithClass == null)
                {
                    ctorMethodInfo = wrapper.GetMethod("CreateInstance", flags, null, Type.EmptyTypes, null);
                }
            }

            // Look for a constructor even if a CreateInstance method was
            // found, since it may return null.
            cinfo = wrapped.GetConstructor(Type.EmptyTypes);
            if (cinfo == null)
            {
                useGTypeCtor = true;
                cinfo        = wrapped.GetConstructor(new Type[] { typeof(IntPtr) });
            }

            Load(elem);
        }
예제 #15
0
        public CecilClassDescriptor(CecilWidgetLibrary lib, XmlElement element, ClassDescriptor typeClassDescriptor, XmlElement steticDefinition, TypeDefinition cls)
        {
            this.cecilLib            = lib;
            this.steticDefinition    = steticDefinition;
            this.typeClassDescriptor = typeClassDescriptor;
            wrappedTypeName          = element.GetAttribute("type");
            type = cls;
            Load(element);
            type            = null;
            canGenerateCode = true;

            string baseType = element.GetAttribute("base-type");

            if (baseType.Length > 0)
            {
                wrapperClassDescriptor = Registry.LookupClassByName(baseType);
                if (wrapperClassDescriptor == null)
                {
                    throw new InvalidOperationException("Unknown base type: " + baseType);
                }
            }
            else
            {
                wrapperClassDescriptor = typeClassDescriptor;
            }

            if (steticDefinition == null && !AllowChildren && NeedsBlackBox(typeClassDescriptor.Name))
            {
                // It is not possible to create instances of that widget, instead we'll have
                // to create the typical custom widget black box.

                if (!CanCreateWidgetInstance(wrapperClassDescriptor.Name))
                {
                    throw new InvalidOperationException("Can't load widget type '" + Name + "'. Instances of that type can't be created because the type can't be loaded into the process.");
                }

                useCustomWidgetBox = true;
            }

            widgetId = Name.ToLower();
            int i = widgetId.LastIndexOf('.');

            if (i != -1)
            {
                if (i != widgetId.Length - 1)
                {
                    widgetId = widgetId.Substring(i + 1);
                }
                else
                {
                    widgetId = widgetId.Replace(".", "");
                }
            }

            string iconName = element.GetAttribute("icon");

            icon = lib.GetEmbeddedIcon(iconName);

            // If the class is a custom widget created using stetic, it means that it has
            // simple property and there is no custom logic, so it is safe to generate code
            // for this class.
            if (steticDefinition != null)
            {
                canGenerateCode = true;
            }

            // If it has a custom wrapper, then it definitely has custom logic, so it can't generate code
            if (element.HasAttribute("wrapper"))
            {
                canGenerateCode = false;
            }
        }
        protected void Load(XmlElement elem)
        {
            if (elem.HasAttribute("cname"))
            {
                cname = elem.GetAttribute("cname");
            }
            else if (cname == null)
            {
                cname = elem.GetAttribute("type");
            }

            label = elem.GetAttribute("label");
            if (label == "")
            {
                label = WrappedTypeName;
                int i = label.LastIndexOf('.');
                if (i != -1)
                {
                    label = label.Substring(i + 1);
                }
            }

            if (elem.HasAttribute("allow-children"))
            {
                allowChildren = elem.GetAttribute("allow-children") == "yes" || elem.GetAttribute("allow-children") == "true";
            }

            category = elem.GetAttribute("palette-category");

            if (elem.HasAttribute("deprecated"))
            {
                deprecated = true;
            }
            if (elem.HasAttribute("hexpandable"))
            {
                hexpandable = true;
            }
            if (elem.HasAttribute("vexpandable"))
            {
                vexpandable = true;
            }
            if (elem.GetAttribute("internal") == "true")
            {
                isInternal = true;
            }

            contextMenu = ItemGroup.Empty;

            baseType = elem.GetAttribute("base-type");
            if (baseType.Length > 0)
            {
                ClassDescriptor basec = Registry.LookupClassByName(baseType);
                if (basec == null)
                {
                    throw new InvalidOperationException("Base type '" + baseType + "' not found.");
                }
                foreach (ItemGroup group in basec.ItemGroups)
                {
                    groups.Add(group);
                }
                foreach (ItemGroup group in basec.SignalGroups)
                {
                    signals.Add(group);
                }
                contextMenu = basec.ContextMenu;
            }
            else
            {
                baseType = null;
            }

            XmlElement groupsElem = elem["itemgroups"];

            if (groupsElem != null)
            {
                foreach (XmlElement groupElem in groupsElem.SelectNodes("itemgroup"))
                {
                    ItemGroup itemgroup;

                    if (groupElem.HasAttribute("ref"))
                    {
                        string refname = groupElem.GetAttribute("ref");
                        itemgroup = Registry.LookupItemGroup(refname);
                    }
                    else
                    {
                        itemgroup = new ItemGroup(groupElem, this);
                    }
                    groups.Add(itemgroup);

                    if (groupElem.HasAttribute("important"))
                    {
                        if (groupElem.GetAttribute("important") == "true")
                        {
                            importantGroups++;
                        }
                    }
                    else if (groups.Count == 1)
                    {
                        importantGroups++;
                    }
                }
            }

            XmlElement signalsElem = elem["signals"];

            if (signalsElem != null)
            {
                foreach (XmlElement groupElem in signalsElem.SelectNodes("itemgroup"))
                {
                    ItemGroup itemgroup;
                    if (groupElem.HasAttribute("ref"))
                    {
                        string refname = groupElem.GetAttribute("ref");
                        itemgroup = Registry.LookupSignalGroup(refname);
                    }
                    else
                    {
                        itemgroup = new ItemGroup(groupElem, this);
                    }
                    signals.Add(itemgroup);
                }
            }

            XmlElement contextElem = elem["contextmenu"];

            if (contextElem != null)
            {
                if (contextElem.HasAttribute("ref"))
                {
                    string refname = contextElem.GetAttribute("ref");
                    contextMenu = Registry.LookupContextMenu(refname);
                }
                else
                {
                    contextMenu = new ItemGroup(contextElem, this);
                }
            }

            XmlElement ichildElem = elem["internal-children"];

            if (ichildElem != null)
            {
                internalChildren = new ItemGroup(ichildElem, this);
            }
            else
            {
                internalChildren = ItemGroup.Empty;
            }

            string initProps = elem.GetAttribute("init-properties");

            if (initProps.Length > 0)
            {
                string[]  props = initProps.Split(' ');
                ArrayList list  = new ArrayList();
                foreach (string prop in props)
                {
                    PropertyDescriptor idesc = this [prop] as PropertyDescriptor;
                    if (idesc == null)
                    {
                        throw new InvalidOperationException("Initialization property not found: " + prop);
                    }
                    list.Add(idesc);
                }
                initializationProperties = (PropertyDescriptor[])list.ToArray(typeof(PropertyDescriptor));
            }
            else
            {
                initializationProperties = emptyPropArray;
            }

            targetGtkVersion = elem.GetAttribute("gtk-version");
            if (targetGtkVersion.Length == 0)
            {
                targetGtkVersion = null;
            }
        }