public ItemGroup (XmlElement elem, ClassDescriptor klass)
		{
			declaringType = klass;
			label = elem.GetAttribute ("label");
			name = elem.GetAttribute ("name");

			XmlNodeList nodes = elem.SelectNodes ("property | command | signal");
			for (int i = 0; i < nodes.Count; i++) {
				XmlElement item = (XmlElement)nodes[i];
				string refname = item.GetAttribute ("ref");
				if (refname != "") {
					if (refname.IndexOf ('.') != -1) {
						ItemDescriptor desc = (ItemDescriptor) Registry.LookupItem (refname);
						items [desc.Name] = desc;
					} else {
						ItemDescriptor desc = (ItemDescriptor) klass[refname];
						items [desc.Name] = desc;
					}
					continue;
				}

				ItemDescriptor idesc = klass.CreateItemDescriptor ((XmlElement)item, this);
				if (idesc != null)
					items [idesc.Name] = idesc;
			}
		}
		public CommandDescriptor (XmlElement elem, ItemGroup group, ClassDescriptor klass) : base (elem, group, klass)
		{
			name = elem.GetAttribute ("name");
			label = elem.GetAttribute ("label");
			description = elem.GetAttribute ("description");
			checkName = elem.GetAttribute ("check");
			icon = elem.GetAttribute ("icon");
		}
Beispiel #3
0
		public WidgetFactory (ProjectBackend project, ClassDescriptor klass)
		{
			this.project = project;
			this.klass = klass;
			Initialize (klass.Label, klass.Icon);
			if (project == null)
				Sensitive = false;
		}
Beispiel #4
0
 protected ItemDescriptor(XmlElement elem, ItemGroup group, ClassDescriptor klass)
 {
     this.klass = klass;
     isInternal = elem.HasAttribute ("internal");
     deps = AddSubprops (elem.SelectNodes ("./disabled-if"), group, klass);
     visdeps = AddSubprops (elem.SelectNodes ("./invisible-if"), group, klass);
     targetGtkVersion = elem.GetAttribute ("gtk-version");
     if (targetGtkVersion.Length == 0)
         targetGtkVersion = null;
 }
		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;
		}
Beispiel #6
0
		ArrayList AddSubprops (XmlNodeList nodes, ItemGroup group, ClassDescriptor klass)
		{
			ArrayList list = null;
			
			// Sub-properties can have a name+value (which checks for the value of a
			// property) or a method name, which should return true if the item has
			// to be disabled/hidden.

			foreach (XmlElement elem in nodes) {
				string name = elem.GetAttribute ("name");
				if (name.Length > 0) {
					string value = elem.GetAttribute ("value");

					PropertyDescriptor prop = (PropertyDescriptor)group[name];
					if (prop == null)
						prop = (PropertyDescriptor)klass[name];
					if (prop == null)
						throw new ArgumentException ("Bad sub-prop " + name);
					if (list == null)
						list = new ArrayList ();
						
					DepInfo info = new DepInfo ();
					info.Property = prop;
					info.Value = prop.StringToValue (value);
					list.Add (info);
				} else if ((name = elem.GetAttribute ("check")).Length > 0) {
					DepInfo info = new DepInfo ();
					info.CheckName = name;
					if (list == null)
						list = new ArrayList ();
					list.Add (info);
				} else {
					throw new ArgumentException ("Bad sub-prop");
				}
			}
			return list;
		}
		protected PropertyDescriptor (XmlElement elem, ItemGroup group, ClassDescriptor klass): base (elem, group, klass)
		{
		}
Beispiel #8
0
 protected void AddClass(ClassDescriptor klass)
 {
     if (klass == null)
         return;
     klass.SetLibrary (this);
     classes_by_cname[klass.CName] = klass;
     classes_by_csname[klass.WrappedTypeName] = klass;
 }
 public WindowFactory(ProjectBackend project, ClassDescriptor klass) : base(project, klass)
 {
 }
 protected PropertyDescriptor(XmlElement elem, ItemGroup group, ClassDescriptor klass) : base(elem, group, klass)
 {
 }
Beispiel #11
0
        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 ClassDescriptorWrapper (ClassDescriptor wrapped)
		{
			this.wrapped = wrapped;
			label = wrapped.Label;
			
		}
Beispiel #13
0
		public static void ReadSignal (ClassDescriptor klass, ObjectWrapper ob, XmlElement elem)
		{
			string name = elem.GetAttribute ("name");
			SignalDescriptor signal = klass.SignalGroups.GetItem (name) as SignalDescriptor;
			if (signal != null) {
				string handler = elem.GetAttribute ("handler");
				bool after = elem.GetAttribute ("after") == "yes";
				ob.Signals.Add (new Signal (signal, handler, after));
			}
		}
Beispiel #14
0
		public WindowFactory (ProjectBackend project, ClassDescriptor klass) : base (project, klass) 
		{
		}
        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;
            }
        }
Beispiel #16
0
 public ClassDescriptorWrapper(ClassDescriptor wrapped)
 {
     this.wrapped = wrapped;
     label        = wrapped.Label;
 }
Beispiel #17
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;
            }
        }
		public SignalDescriptor (XmlElement elem, ItemGroup group, ClassDescriptor klass) : base (elem, group, klass)
		{
		}
Beispiel #19
0
		void AppendItemGroups (ClassDescriptor klass, object obj)
		{
			int n = 1;
			foreach (ItemGroup igroup in klass.ItemGroups) {
				PropertyGridGroup grid = (PropertyGridGroup) cachedGroups [igroup];
				if (grid == null) {
					grid = new PropertyGridGroup ();
					grid.AddGroup (igroup);
					cachedGroups [igroup] = grid;
					PackStart (grid, false, false, 0);
				}
				ReorderChild (grid, n++);
				grid.ShowAll ();
				grid.AttachObject (obj);
			}
		}
Beispiel #20
0
		public static void ReadMembers (ClassDescriptor klass, ObjectWrapper wrapper, object wrapped, XmlElement elem)
		{
			foreach (XmlNode node in elem.ChildNodes) {
				XmlElement child = node as XmlElement;
				if (child == null)
					continue;
					
				if (child.LocalName == "signal")
					ReadSignal (klass, wrapper, child);
				else if (child.LocalName == "property")
					ReadProperty (klass, wrapper, wrapped, child);
			}
		}
Beispiel #21
0
		internal static void Bind (IProject proj, ClassDescriptor klass, ObjectWrapper wrapper, object wrapped, bool initialized)
		{
			wrapper.proj = proj;
			wrapper.classDescriptor = klass;
			wrapper.Wrap (wrapped, initialized);
			wrapper.OnWrapped ();
		}
Beispiel #22
0
		public static void ReadProperty (ClassDescriptor klass, ObjectWrapper wrapper, object wrapped, XmlElement prop_node)
		{
			string name = prop_node.GetAttribute ("name");
			PropertyDescriptor prop = klass [name] as PropertyDescriptor;
			if (prop == null || !prop.CanWrite)
				return;

			string strval = prop_node.InnerText;
			
			// Skip translation context
			if (prop_node.GetAttribute ("context") == "yes" && strval.IndexOf ('|') != -1)
				strval = strval.Substring (strval.IndexOf ('|') + 1);
				
			object value = prop.StringToValue (strval);
			prop.SetValue (wrapped, value);
			
			if (prop.Translatable) {
				if (prop_node.GetAttribute ("translatable") != "yes") {
					prop.SetTranslated (wrapped, false);
				}
				else {
					prop.SetTranslated (wrapped, true);
					if (prop_node.GetAttribute ("context") == "yes") {
						strval = prop_node.InnerText;
						int bar = strval.IndexOf ('|');
						if (bar != -1)
							prop.SetTranslationContext (wrapped, strval.Substring (0, bar));
					}

					if (prop_node.HasAttribute ("comments"))
						prop.SetTranslationComment (wrapped, prop_node.GetAttribute ("comments"));
				}
			}
		}
Beispiel #23
0
        public static XmlDocument Export(Gtk.Widget widget)
        {
            Stetic.Wrapper.Widget wrapper = Stetic.Wrapper.Widget.Lookup(widget);
            if (wrapper == null)
            {
                return(null);
            }

            XmlDocument doc = new XmlDocument();

            doc.PreserveWhitespace = true;

            XmlElement toplevel = doc.CreateElement("glade-interface");

            doc.AppendChild(toplevel);

            // For toplevel widgets, glade just saves it as-is. For
            // non-toplevels, it puts the widget into a dummy GtkWindow,
            // but using the packing attributes of the widget's real
            // container (so as to preserve expand/fill settings and the
            // like).

            XmlElement elem;

            Stetic.Wrapper.Container parent = wrapper.ParentWrapper;
            ObjectWriter             writer = new ObjectWriter(doc, FileFormat.Glade);

            if (parent == null)
            {
                elem = wrapper.Write(writer);
                if (elem == null)
                {
                    return(null);
                }
                if (!(widget is Gtk.Window))
                {
                    XmlElement window = doc.CreateElement("widget");
                    window.SetAttribute("class", "GtkWindow");
                    window.SetAttribute("id", "glade-dummy-container");
                    XmlElement child = doc.CreateElement("child");
                    window.AppendChild(child);
                    child.AppendChild(elem);
                    elem = window;
                }
            }
            else
            {
                elem = doc.CreateElement("widget");
                // Set the class correctly (temporarily) so the XSL
                // transforms will work correctly.
                ClassDescriptor klass = parent.ClassDescriptor;
                elem.SetAttribute("class", klass.CName);
                elem.AppendChild(parent.WriteContainerChild(writer, wrapper));
            }
            toplevel.AppendChild(elem);

            doc = XslExportTransform(doc);

            if (parent != null)
            {
                elem = (XmlElement)doc.SelectSingleNode("glade-interface/widget");
                elem.SetAttribute("class", "GtkWindow");
                elem.SetAttribute("id", "glade-dummy-container");
            }
            return(doc);
        }