Inheritance: System.MarshalByRefObject, IDisposable
		protected override object GetDiff (ObjectWrapper w)
		{
			// Only track changes in widgets.
			Wrapper.Widget widget = w as Wrapper.Widget;
			if (widget != null) return w.GetUndoDiff ();
			else return null;
		}
		public virtual CodeExpression GenerateInstanceExpression (ObjectWrapper wrapper, CodeExpression newObject)
		{
			string varName = NewId ();
			CodeVariableDeclarationStatement varDec = new CodeVariableDeclarationStatement (wrapper.WrappedTypeName.ToGlobalTypeRef (), varName);
			varDec.InitExpression = newObject;
			statements.Add (varDec);
			return new CodeVariableReferenceExpression (varName);
		}
示例#3
0
		internal bool CanNotifyChanged (ObjectWrapper wrapper)
		{
			if (!InAtomicChange) {
				if (IsRegistered (wrapper) && UndoCheckpoint != null)
					UndoCheckpoint (this, new UndoCheckpointEventArgs (new ObjectWrapper[] { wrapper }));
				return true;
			} else
				return atomicChangeTracker.ProcessChange (wrapper);
		}
示例#4
0
		public void SetRoot (ObjectWrapper wrapper)
		{
			root = wrapper;
			wrapper.UndoManager = this;
			elements.Clear ();
			
			doc = new XmlDocument ();
			UndoWriter writer = new UndoWriter (doc, this);
			writer.WriteObject (wrapper);
		}
示例#5
0
		// This method can be called by containers to register new objects in the tree.
		// Unless an object is registered in this way, no status will be tracked for it.
		// The provided status element must be a direct or indirect child of the parent status.
		internal void RegisterObject (ObjectWrapper w, XmlElement status)
		{
			VerifyManager ();
				
			if (IsRegistered (w))
				throw new InvalidOperationException ("Object already registered: " + w.GetType ());

			elements [w] = GetLocalElement (status);
			
			w.Disposed += OnObjectDisposed;
		}
示例#6
0
		public static XmlElement Write (ObjectWrapper wrapper, XmlDocument doc)
		{
			ClassDescriptor klass = wrapper.ClassDescriptor;

			XmlElement elem = doc.CreateElement ("widget");
			elem.SetAttribute ("class", klass.Name);
			elem.SetAttribute ("id", ((Gtk.Widget)wrapper.Wrapped).Name);

			GetProps (wrapper, elem);
			GetSignals (wrapper, elem);
			return elem;
		}
示例#7
0
        internal WidgetDesignerBackend(Gtk.Container container, int designWidth, int designHeight)
        {
            ShadowType = ShadowType.None;
            HscrollbarPolicy = PolicyType.Automatic;
            VscrollbarPolicy = PolicyType.Automatic;

            resizableFixed = new ResizableFixed ();
            resizableFixed.ObjectViewer = defaultObjectViewer;

            wrapper = ObjectWrapper.Lookup (container);
            Gtk.Window window = container as Gtk.Window;

            if (window != null) {
                try {
                    metacityPreview = CreateMetacityPreview (window);
                    preview = metacityPreview;
                    if (wrapper != null)
                        wrapper.Notify += OnWindowPropChange;
                } catch {
                    // If metacity is not available, use a regular box.
                    EventBox eventBox = new EventBox ();
                    eventBox.Add (container);
                    preview = eventBox;
                }

            } else {
                EventBox eventBox = new EventBox ();
                eventBox.Add (container);
                preview = eventBox;
            }

            resizableFixed.Put (preview, container);

            if (designWidth != -1) {
                preview.WidthRequest = designWidth;
                preview.HeightRequest = designHeight;
                resizableFixed.AllowResize = true;
            } else {
                resizableFixed.AllowResize = false;
            }

            preview.SizeAllocated += new Gtk.SizeAllocatedHandler (OnResized);

            AddWithViewport (resizableFixed);

            if (wrapper != null)
                wrapper.AttachDesigner (resizableFixed);

            resizableFixed.SelectionChanged += OnSelectionChanged;
        }
示例#8
0
		public static void GetProps (ObjectWrapper wrapper, XmlElement parent_elem)
		{
			ClassDescriptor klass = wrapper.ClassDescriptor;

			foreach (ItemGroup group in klass.ItemGroups) {
				foreach (ItemDescriptor item in group) {
					PropertyDescriptor prop = item as PropertyDescriptor;
					if (prop == null)
						continue;
					if (!prop.VisibleFor (wrapper.Wrapped) || !prop.CanWrite || prop.Name == "Name")	// Name is written in the id attribute
						continue;

					object value = prop.GetValue (wrapper.Wrapped);
					
					// If the property has its default value, we don't need to write it
					if (value == null || (prop.HasDefault && prop.IsDefaultValue (value)))
						continue;
				
					string val = prop.ValueToString (value);
					if (val == null)
						continue;

					XmlElement prop_elem = parent_elem.OwnerDocument.CreateElement ("property");
					prop_elem.SetAttribute ("name", prop.Name);
					if (val.Length > 0)
						prop_elem.InnerText = val;

					if (prop.Translatable && prop.IsTranslated (wrapper.Wrapped)) {
						prop_elem.SetAttribute ("translatable", "yes");
						string tcx = prop.TranslationContext (wrapper.Wrapped);
						if (tcx != null && tcx.Length > 0) {
							prop_elem.SetAttribute ("context", "yes");
							prop_elem.InnerText = tcx + "|" + prop_elem.InnerText;
						}
						string tcm = prop.TranslationComment (wrapper.Wrapped);
						if (tcm != null && tcm.Length > 0)
							prop_elem.SetAttribute ("comments", prop.TranslationComment (wrapper.Wrapped));
					}

					parent_elem.AppendChild (prop_elem);
				}
			}
		}
示例#9
0
        internal static void BindSignalHandlers(CodeExpression targetObjectVar, ObjectWrapper wrapper, Stetic.WidgetMap map, CodeStatementCollection statements, GenerationOptions options)
        {
            foreach (Signal signal in wrapper.Signals)
            {
                SignalDescriptor descriptor = signal.SignalDescriptor;

                CodeExpression createDelegate;

                if (options.UsePartialClasses)
                {
                    createDelegate =
                        new CodeDelegateCreateExpression(
                            new CodeTypeReference(descriptor.HandlerTypeName, CodeTypeReferenceOptions.GlobalReference),
                            new CodeThisReferenceExpression(),
                            signal.Handler);
                }
                else
                {
                    createDelegate =
                        new CodeMethodInvokeExpression(
                            new CodeTypeReferenceExpression(new CodeTypeReference(typeof(Delegate), CodeTypeReferenceOptions.GlobalReference)),
                            "CreateDelegate",
                            new CodeTypeOfExpression(descriptor.HandlerTypeName),
                            targetObjectVar,
                            new CodePrimitiveExpression(signal.Handler));

                    createDelegate = new CodeCastExpression(descriptor.HandlerTypeName.ToGlobalTypeRef(), createDelegate);
                }

                CodeAttachEventStatement cevent = new CodeAttachEventStatement(
                    new CodeEventReferenceExpression(
                        map.GetWidgetExp(wrapper),
                        descriptor.Name),
                    createDelegate);

                statements.Add(cevent);
            }

            Wrapper.Widget widget = wrapper as Wrapper.Widget;
            if (widget != null && widget.IsTopLevel)
            {
                // Bind local action signals
                foreach (Wrapper.ActionGroup grp in widget.LocalActionGroups)
                {
                    foreach (Wrapper.Action ac in grp.Actions)
                    {
                        BindSignalHandlers(targetObjectVar, ac, map, statements, options);
                    }
                }
            }

            Gtk.Container cont = wrapper.Wrapped as Gtk.Container;
            if (cont != null)
            {
                foreach (Gtk.Widget child in cont.AllChildren)
                {
                    Stetic.Wrapper.Widget ww = Stetic.Wrapper.Widget.Lookup(child);
                    if (ww != null)
                    {
                        BindSignalHandlers(targetObjectVar, ww, map, statements, options);
                    }
                }
            }
        }
		public virtual void GenerateBuildCode (ObjectWrapper wrapper, CodeExpression var)
		{
			vars [wrapper] = var;
			wrapper.GenerateBuildCode (this, var);
			generatedWrappers.Add (wrapper);
		}
示例#11
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);
			}
		}
示例#12
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"));
				}
			}
		}
示例#13
0
		public override CodeExpression GenerateInstanceExpression (ObjectWrapper wrapper, CodeExpression newObject)
		{
			string typeName = wrapper.WrappedTypeName;
			string memberName = null;
			if (wrapper is Wrapper.Widget)
				memberName = ((Wrapper.Widget) wrapper).Wrapped.Name;
			else if (wrapper is Wrapper.Action)
				memberName = ((Wrapper.Action) wrapper).Name;
			
			if (memberName == null)
				return base.GenerateInstanceExpression (wrapper, newObject);
			
			if (Options.UsePartialClasses) {
				// Don't generate fields for top level widgets and for widgets accessible
				// through other widget's properties
				Wrapper.Widget ww = wrapper as Wrapper.Widget;
				if (ww == null || (!ww.IsTopLevel && ww.InternalChildProperty == null && !ww.Unselectable)) {
					type.Members.Add (
						new CodeMemberField (
							new CodeTypeReference (typeName, CodeTypeReferenceOptions.GlobalReference),
							memberName
						)
					);
					CodeExpression var = new CodeFieldReferenceExpression (
					                          new CodeThisReferenceExpression (),
					                          memberName
					);

					Statements.Add (
						new CodeAssignStatement (
							var,
							newObject
						)
					);
					return var;
				} else 
					return base.GenerateInstanceExpression (wrapper, newObject);
			} else {
				CodeExpression var = base.GenerateInstanceExpression (wrapper, newObject);
				Statements.Add (
					new CodeAssignStatement (
						new CodeIndexerExpression (
							new CodeVariableReferenceExpression ("bindings"),
							new CodePrimitiveExpression (memberName)
						),
						var
					)
				);
				return var;
			}
		}
示例#14
0
		public static void GetSignals (ObjectWrapper ob, XmlElement parent_elem)
		{
			foreach (Signal signal in ob.Signals) {
				if (!signal.SignalDescriptor.VisibleFor (ob.Wrapped))
					continue;

				XmlElement signal_elem = parent_elem.OwnerDocument.CreateElement ("signal");
				signal_elem.SetAttribute ("name", signal.SignalDescriptor.Name);
				signal_elem.SetAttribute ("handler", signal.Handler);
				if (signal.After)
					signal_elem.SetAttribute ("after", "yes");
				parent_elem.AppendChild (signal_elem);
			}
		}
示例#15
0
		public void Dispose ()
		{
			rootObject = null;
			if (queue != null)
				queue.Purge ();
		}
示例#16
0
 internal ObjectBindInfo[] GetBoundComponents(ObjectWrapper wrapper)
 {
     return(CodeGenerator.GetFieldsToBind(wrapper).ToArray());
 }
 internal void UnregisterObject(ObjectWrapper w)
 {
     VerifyManager();
     elements.Remove(w);
 }
 internal bool IsRegistered(ObjectWrapper w)
 {
     return(elements.ContainsKey(w));
 }
 public CodeExpression GetWidgetExp(ObjectWrapper wrapper)
 {
     return((CodeExpression)vars [wrapper]);
 }
 public virtual void GenerateCreationCode(ObjectWrapper wrapper, CodeExpression varExp)
 {
     rootObject = varExp;
     wrapper.GenerateInitCode(this, varExp);
     GenerateBuildCode(wrapper, varExp);
 }
示例#21
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);
            }
        }
示例#22
0
		void AddChange (ObjectWrapper[] obs)
		{
			if (updating || queue == null)
				return;

			ObjectWrapperUndoRedoChange firstChange = null;
			ObjectWrapperUndoRedoChange lastChange = null;
			
//			Console.WriteLine ("** UNDO CHECKPOINT: {0} objects", obs.Length);
			
			foreach (ObjectWrapper ob in obs) {
			
				// Get the diff for going from the new status to the old status
				object diff = GetDiff (ob);
				
				if (diff == null)	// No differences
					continue;
				
//				Console.WriteLine ("ADDCHANGE " + ob + " uid:" + ob.UndoId);
//				PrintPatch (diff);
				
				if (ob.UndoId == null || ob.UndoId.Length == 0)
					throw new InvalidOperationException ("Object of type '" + ob.GetType () + "' does not have an undo id.");

				ObjectWrapperUndoRedoChange change = new ObjectWrapperUndoRedoChange (this, ob.UndoId, diff);
				if (lastChange == null)
					lastChange = firstChange = change;
				else {
					lastChange.Next = change;
					lastChange = change;
				}
			}
			if (firstChange != null)
				queue.AddChange (firstChange);
		}
示例#23
0
		internal static List<ObjectBindInfo> GetFieldsToBind (ObjectWrapper wrapper)
		{
			List<ObjectBindInfo> tobind = new List<ObjectBindInfo> ();
			GetFieldsToBind (tobind, wrapper);
			return tobind;
		}
示例#24
0
		protected virtual object GetDiff (ObjectWrapper w)
		{
			return w.GetUndoDiff ();
		}
示例#25
0
        public override CodeExpression GenerateInstanceExpression(ObjectWrapper wrapper, CodeExpression newObject)
        {
            string typeName   = wrapper.WrappedTypeName;
            string memberName = null;

            if (wrapper is Wrapper.Widget)
            {
                memberName = ((Wrapper.Widget)wrapper).Wrapped.Name;
            }
            else if (wrapper is Wrapper.Action)
            {
                memberName = ((Wrapper.Action)wrapper).Name;
            }

            if (memberName == null)
            {
                return(base.GenerateInstanceExpression(wrapper, newObject));
            }

            if (Options.UsePartialClasses)
            {
                // Don't generate fields for top level widgets and for widgets accessible
                // through other widget's properties
                Wrapper.Widget ww = wrapper as Wrapper.Widget;
                if (ww == null || (!ww.IsTopLevel && ww.InternalChildProperty == null && !ww.Unselectable))
                {
                    type.Members.Add(
                        new CodeMemberField(
                            new CodeTypeReference(typeName, CodeTypeReferenceOptions.GlobalReference),
                            memberName
                            )
                        );
                    CodeExpression var = new CodeFieldReferenceExpression(
                        new CodeThisReferenceExpression(),
                        memberName
                        );

                    Statements.Add(
                        new CodeAssignStatement(
                            var,
                            newObject
                            )
                        );
                    return(var);
                }
                else
                {
                    return(base.GenerateInstanceExpression(wrapper, newObject));
                }
            }
            else
            {
                CodeExpression var = base.GenerateInstanceExpression(wrapper, newObject);
                Statements.Add(
                    new CodeAssignStatement(
                        new CodeIndexerExpression(
                            new CodeVariableReferenceExpression("bindings"),
                            new CodePrimitiveExpression(memberName)
                            ),
                        var
                        )
                    );
                return(var);
            }
        }
示例#26
0
		internal static void BindSignalHandlers (CodeExpression targetObjectVar, ObjectWrapper wrapper, Stetic.WidgetMap map, CodeStatementCollection statements, GenerationOptions options)
		{
			foreach (Signal signal in wrapper.Signals) {
				SignalDescriptor descriptor = signal.SignalDescriptor;
				
				CodeExpression createDelegate;
				
				if (options.UsePartialClasses) {
					createDelegate =
						new CodeDelegateCreateExpression (
							new CodeTypeReference (descriptor.HandlerTypeName, CodeTypeReferenceOptions.GlobalReference),
							new CodeThisReferenceExpression (),
							signal.Handler);
				} else {
					createDelegate =
						new CodeMethodInvokeExpression (
							new CodeTypeReferenceExpression (new CodeTypeReference (typeof(Delegate), CodeTypeReferenceOptions.GlobalReference)),
							"CreateDelegate",
							new CodeTypeOfExpression (descriptor.HandlerTypeName),
							targetObjectVar,
							new CodePrimitiveExpression (signal.Handler));
					
					createDelegate = new CodeCastExpression (descriptor.HandlerTypeName.ToGlobalTypeRef (), createDelegate);
				}
				
				CodeAttachEventStatement cevent = new CodeAttachEventStatement (
					new CodeEventReferenceExpression (
						map.GetWidgetExp (wrapper),
						descriptor.Name),
					createDelegate);
				
				statements.Add (cevent);
			}
			
			Wrapper.Widget widget = wrapper as Wrapper.Widget;
			if (widget != null && widget.IsTopLevel) {
				// Bind local action signals
				foreach (Wrapper.ActionGroup grp in widget.LocalActionGroups) {
					foreach (Wrapper.Action ac in grp.Actions)
						BindSignalHandlers (targetObjectVar, ac, map, statements, options);
				}
			}
			
			Gtk.Container cont = wrapper.Wrapped as Gtk.Container;
			if (cont != null) {
				foreach (Gtk.Widget child in cont.AllChildren) {
					Stetic.Wrapper.Widget ww = Stetic.Wrapper.Widget.Lookup (child);
					if (ww != null)
						BindSignalHandlers (targetObjectVar, ww, map, statements, options);
				}
			}
			
		}
		static public void GetProps (ObjectWrapper wrapper, XmlElement parent_elem)
		{
			ClassDescriptor klass = wrapper.ClassDescriptor;

			foreach (ItemGroup group in klass.ItemGroups) {
				foreach (ItemDescriptor item in group) {
					TypedPropertyDescriptor prop = item as TypedPropertyDescriptor;
					if (prop == null)
						continue;
					prop = prop.GladeProperty;
					if (prop.GladeName == null)
						continue;
					if (!prop.VisibleFor (wrapper.Wrapped))
						continue;

					string val = PropToString (wrapper, prop);
					if (val == null)
						continue;

					XmlElement prop_elem = parent_elem.OwnerDocument.CreateElement ("property");
					prop_elem.SetAttribute ("name", prop.GladeName);
					if (val.Length > 0)
						prop_elem.InnerText = val;

					if (prop.Translatable && prop.IsTranslated (wrapper.Wrapped)) {
						prop_elem.SetAttribute ("translatable", "yes");
						if (prop.TranslationContext (wrapper.Wrapped) != null) {
							prop_elem.SetAttribute ("context", "yes");
							prop_elem.InnerText = prop.TranslationContext (wrapper.Wrapped) + "|" + prop_elem.InnerText;
						}
						if (prop.TranslationComment (wrapper.Wrapped) != null)
							prop_elem.SetAttribute ("comments", prop.TranslationComment (wrapper.Wrapped));
					}

					parent_elem.AppendChild (prop_elem);
				}
			}
		}
示例#28
0
		static void GetFieldsToBind (List<ObjectBindInfo> tobind, ObjectWrapper wrapper)
		{
			string memberName = null;
			
			if (wrapper is Wrapper.Widget) {
				Wrapper.Widget ww = wrapper as Wrapper.Widget;
				if (!String.IsNullOrEmpty (ww.UIManagerName)) 
					tobind.Add (new ObjectBindInfo ("Gtk.UIManager", ww.UIManagerName));

				if (!ww.IsTopLevel && ww.InternalChildProperty == null && !ww.Unselectable)
					memberName = ((Wrapper.Widget) wrapper).Wrapped.Name;
			}
			else if (wrapper is Wrapper.Action)
				memberName = ((Wrapper.Action) wrapper).Name;
			
			if (memberName != null) {
				ObjectBindInfo binfo = new ObjectBindInfo (wrapper.WrappedTypeName, memberName);
				tobind.Add (binfo);
			}
			
			Wrapper.ActionGroup agroup = wrapper as Wrapper.ActionGroup;
			if (agroup != null) {
				foreach (Wrapper.Action ac in agroup.Actions)
					GetFieldsToBind (tobind, ac);
			}
			
			Wrapper.Widget widget = wrapper as Wrapper.Widget;
			if (widget != null && widget.IsTopLevel) {
				// Generate fields for local actions
				foreach (Wrapper.ActionGroup grp in widget.LocalActionGroups) {
					GetFieldsToBind (tobind, grp);
				}
			}
			
			Gtk.Container cont = wrapper.Wrapped as Gtk.Container;
			if (cont != null) {
				foreach (Gtk.Widget child in cont.AllChildren) {
					Stetic.Wrapper.Widget ww = Stetic.Wrapper.Widget.Lookup (child);
					if (ww != null)
						GetFieldsToBind (tobind, ww);
				}
			}
		}
		static public void GetSignals (ObjectWrapper wrapper, XmlElement parent_elem)
		{
			Stetic.Wrapper.Widget ob = wrapper as Stetic.Wrapper.Widget;
			if (ob == null) return;
			
			foreach (Signal signal in ob.Signals) {
				if (((TypedSignalDescriptor)signal.SignalDescriptor).GladeName == null)
					continue;
				if (!signal.SignalDescriptor.VisibleFor (wrapper.Wrapped))
					continue;

				XmlElement signal_elem = parent_elem.OwnerDocument.CreateElement ("signal");
				signal_elem.SetAttribute ("name", ((TypedSignalDescriptor)signal.SignalDescriptor).GladeName);
				signal_elem.SetAttribute ("handler", signal.Handler);
				if (signal.After)
					signal_elem.SetAttribute ("after", "yes");
				parent_elem.AppendChild (signal_elem);
			}
		}
示例#30
0
		internal SignalCollection (ObjectWrapper owner)
		{
			this.owner = owner;
		}
示例#31
0
		protected override void OnDestroyed ()
		{
			if (preview != null) {
				if (wrapper != null)
					wrapper.DetachDesigner (resizableFixed);
				preview.SizeAllocated -= new Gtk.SizeAllocatedHandler (OnResized);
				resizableFixed.SelectionChanged -= OnSelectionChanged;
				resizableFixed = null;
				preview = null;
				wrapper = null;
			}
			base.OnDestroyed ();
		}
示例#32
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);
				//set name before binding to ensure 
				//that ObjectWrapper.RootWrapperName will be valid
				widget.Name = elem.GetAttribute ("id");
				ObjectWrapper.Bind (wrapper.Project, klass, wrapper, widget, true);
			} else {
				widget.Name = elem.GetAttribute ("id");
			}
			
			ReadMembers (klass, wrapper, widget, elem);
			
			if (!(widget is Gtk.Window))
				widget.ShowAll ();
		}
示例#33
0
        static string PropToString(ObjectWrapper wrapper, TypedPropertyDescriptor prop)
        {
            object value;

            if (!prop.GladeOverride)
            {
                Stetic.Wrapper.Container.ContainerChild ccwrap = wrapper as Stetic.Wrapper.Container.ContainerChild;
                GLib.Value gval;

                if (ccwrap != null)
                {
                    Gtk.Container.ContainerChild cc = (Gtk.Container.ContainerChild)ccwrap.Wrapped;
                    gval = new GLib.Value((GLib.GType)prop.PropertyType);
                    gtk_container_child_get_property(cc.Parent.Handle, cc.Child.Handle, prop.GladeName, ref gval);
                }
                else
                {
                    Gtk.Widget widget = wrapper.Wrapped as Gtk.Widget;
                    gval = new GLib.Value(widget, prop.GladeName);
                    g_object_get_property(widget.Handle, prop.GladeName, ref gval);
                }
                value = gval.Val;
            }
            else
            {
                value = prop.GetValue(wrapper.Wrapped);
            }
            if (value == null)
            {
                return(null);
            }

            // If the property has its default value, we don't need to write it
            if (prop.HasDefault && prop.ParamSpec.IsDefaultValue(value))
            {
                return(null);
            }

            if (value is Gtk.Adjustment)
            {
                Gtk.Adjustment adj = value as Gtk.Adjustment;
                return(String.Format("{0:G} {1:G} {2:G} {3:G} {4:G} {5:G}",
                                     adj.Value, adj.Lower, adj.Upper,
                                     adj.StepIncrement, adj.PageIncrement,
                                     adj.PageSize));
            }
            else if (value is Enum && prop.ParamSpec != null)
            {
                IntPtr klass = g_type_class_ref(((GLib.GType)prop.PropertyType).Val);

                if (prop.PropertyType.IsDefined(typeof(FlagsAttribute), false))
                {
                    System.Text.StringBuilder sb = new System.Text.StringBuilder();
                    uint val = (uint)System.Convert.ChangeType(value, typeof(uint));

                    while (val != 0)
                    {
                        IntPtr flags_value = g_flags_get_first_value(klass, val);
                        if (flags_value == IntPtr.Zero)
                        {
                            break;
                        }
                        IntPtr fval = Marshal.ReadIntPtr(flags_value);
                        val &= ~(uint)fval;

                        IntPtr name = Marshal.ReadIntPtr(flags_value, Marshal.SizeOf(typeof(IntPtr)));
                        if (name != IntPtr.Zero)
                        {
                            if (sb.Length != 0)
                            {
                                sb.Append('|');
                            }
                            sb.Append(GLib.Marshaller.Utf8PtrToString(name));
                        }
                    }

                    g_type_class_unref(klass);
                    return(sb.ToString());
                }
                else
                {
                    int    val        = (int)System.Convert.ChangeType(value, typeof(int));
                    IntPtr enum_value = g_enum_get_value(klass, val);
                    g_type_class_unref(klass);

                    IntPtr name = Marshal.ReadIntPtr(enum_value, Marshal.SizeOf(typeof(IntPtr)));
                    return(GLib.Marshaller.Utf8PtrToString(name));
                }
            }
            else if (value is bool)
            {
                return((bool)value ? "True" : "False");
            }
            else
            {
                return(value.ToString());
            }
        }
示例#34
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));
			}
		}
		public virtual void GenerateCreationCode (ObjectWrapper wrapper, CodeExpression varExp)
		{
			rootObject = varExp;
			wrapper.GenerateInitCode (this, varExp);
			GenerateBuildCode (wrapper, varExp);
		}
		static void GenerateWrapperFields (CodeTypeDeclaration type, ObjectWrapper wrapper)
		{
			foreach (ObjectBindInfo binfo in CodeGenerator.GetFieldsToBind (wrapper)) {
				type.Members.Add (
					new CodeMemberField (
						new CodeTypeReference (binfo.TypeName, CodeTypeReferenceOptions.GlobalReference),
						binfo.Name
					)
				);
			}
		}
 public virtual void GenerateBuildCode(ObjectWrapper wrapper, CodeExpression var)
 {
     vars [wrapper] = var;
     wrapper.GenerateBuildCode(this, var);
     generatedWrappers.Add(wrapper);
 }
示例#38
0
		public virtual XmlElement WriteObject (ObjectWrapper wrapper)
		{
			return wrapper.Write (this);
		}
		public CodeExpression GetWidgetExp (ObjectWrapper wrapper)
		{
			return (CodeExpression) vars [wrapper];
		}
示例#40
0
文件: DND.cs 项目: mono/stetic
        // Call this from a DragDrop event to receive the dragged widget
        public static void Drop(Gdk.DragContext ctx, uint time, ObjectWrapper targetWrapper, string dropData)
        {
            if (dropCallback == null) {
                Gtk.Widget w = Drop (ctx, (Gtk.Widget) targetWrapper.Wrapped, time);
                targetWrapper.DropObject (dropData, w);
                return;
            }

            Cancel ();
            Gtk.Drag.Finish (ctx, true, true, time);

            Gtk.Application.Invoke (delegate {
                IProject project = targetWrapper.Project;
                string uid = targetWrapper.UndoId;
                string tname = ((Wrapper.Widget)targetWrapper).GetTopLevel ().Wrapped.Name;

                // This call may cause the project to be reloaded
                dragWidget = dropCallback ();
                if (dragWidget == null)
                    return;

                if (targetWrapper.IsDisposed) {
                    // The project has been reloaded. Find the wrapper again.
                    Gtk.Widget twidget = project.GetTopLevel (tname);
                    ObjectWrapper ow = ObjectWrapper.Lookup (twidget);
                    if (ow != null)
                        targetWrapper = ow.FindObjectByUndoId (uid);
                    else
                        targetWrapper = null;

                    if (targetWrapper == null) {
                        // Target wrapper not found. Just ignore the drop.
                        return;
                    }
                }

                targetWrapper.DropObject (dropData, dragWidget);
            });
        }
示例#41
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);
        }