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; } }
static public void ImportWidget(ObjectWrapper wrapper, XmlElement elem) { string className = elem.GetAttribute("class"); if (className == null) { throw new GladeException("<widget> node with no class name"); } ClassDescriptor klassBase = Registry.LookupClassByCName(className); if (klassBase == null) { throw new GladeException("No stetic ClassDescriptor for " + className); } TypedClassDescriptor klass = klassBase as TypedClassDescriptor; if (klass == null) { throw new GladeException("The widget class " + className + " is not supported by Glade"); } ReadSignals(klass, wrapper, elem); Hashtable rawProps, overrideProps; ExtractProperties(klass, elem, out rawProps, out overrideProps); string[] propNames; GLib.Value[] propVals; ParseProperties(klass.WrappedType, false, rawProps.Values, out propNames, out propVals); Gtk.Widget widget; if (wrapper.Wrapped == null) { if (className == "GtkWindow" || className == "GtkDialog") { widget = (Gtk.Widget)klass.CreateInstance(wrapper.Project); ObjectWrapper.Bind(wrapper.Project, klass, wrapper, widget, true); SetProperties(klass, widget, propNames, propVals); } else { IntPtr raw = gtksharp_object_newv(klass.GType.Val, propNames.Length, propNames, propVals); if (raw == IntPtr.Zero) { throw new GladeException("Could not create widget", className); } widget = (Gtk.Widget)GLib.Object.GetObject(raw, true); if (widget == null) { gtk_object_sink(raw); throw new GladeException("Could not create gtk# wrapper", className); } ObjectWrapper.Bind(wrapper.Project, klass, wrapper, widget, true); } } else { widget = (Gtk.Widget)wrapper.Wrapped; for (int i = 0; i < propNames.Length; i++) { g_object_set_property(widget.Handle, propNames[i], ref propVals[i]); } } MarkTranslatables(widget, rawProps); widget.Name = elem.GetAttribute("id"); SetOverrideProperties(wrapper, overrideProps); MarkTranslatables(widget, overrideProps); }
public TypedClassDescriptor(Assembly assembly, XmlElement elem) { bool inheritedWrapper = false; wrapped = Registry.GetType(elem.GetAttribute("type"), true); 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); }