Inheritance: Object, IEditableObject
Example #1
0
        static void ReadSignals(TypedClassDescriptor klass, ObjectWrapper wrapper, XmlElement elem)
        {
            Stetic.Wrapper.Widget ob = wrapper as Stetic.Wrapper.Widget;
            if (ob == null)
            {
                return;
            }

            foreach (ItemGroup group in klass.SignalGroups)
            {
                foreach (TypedSignalDescriptor signal in group)
                {
                    if (signal.GladeName == null)
                    {
                        continue;
                    }

                    XmlElement signal_elem = elem.SelectSingleNode("signal[@name='" + signal.GladeName + "']") as XmlElement;
                    if (signal_elem == null)
                    {
                        continue;
                    }

                    string handler = signal_elem.GetAttribute("handler");
                    bool   after   = signal_elem.GetAttribute("after") == "yes";
                    ob.Signals.Add(new Signal(signal, handler, after));
                }
            }
        }
Example #2
0
		protected override XmlElement WriteChild (ObjectWriter writer, Widget wrapper)
		{
			XmlElement child_elem = base.WriteChild (writer, wrapper);
			if (tabs.Contains (wrapper.Wrapped))
				GladeUtils.SetChildProperty (child_elem, "type", "tab");
			return child_elem;
		}
Example #3
0
        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);
            }
        }
Example #4
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);
                    }
                }
            }
        }
Example #5
0
		protected override XmlElement WriteChild (ObjectWriter writer, Widget wrapper)
		{
			XmlElement child_elem = base.WriteChild (writer, wrapper);
			if (wrapper.Wrapped == expander.LabelWidget)
				GladeUtils.SetChildProperty (child_elem, "type", "label_item");
			return child_elem;
		}
Example #6
0
        public static Stetic.Wrapper.Widget Import(IProject project, XmlDocument doc)
        {
            try {
                doc = XslImportTransform(doc);
            } catch {
                return(null);
            }

            ObjectReader reader = new ObjectReader(project, FileFormat.Glade);

            XmlElement elem = (XmlElement)doc.SelectSingleNode("glade-interface/widget");

            if (elem.GetAttribute("class") != "GtkWindow" ||
                elem.GetAttribute("id") != "glade-dummy-container")
            {
                // Creating a new toplevel
                Stetic.Wrapper.Widget toplevel = (Stetic.Wrapper.Widget)
                                                 Stetic.ObjectWrapper.ReadObject(reader, elem);
                if (toplevel != null)
                {
                    project.AddWindow((Gtk.Window)toplevel.Wrapped);
                }
                return(toplevel);
            }

            return((Stetic.Wrapper.Widget)
                   Stetic.ObjectWrapper.ReadObject(reader, (XmlElement)elem.SelectSingleNode("child/widget")));
        }
Example #7
0
		protected override XmlElement WriteChild (ObjectWriter writer, Widget wrapper)
		{
			if (writer.Format == FileFormat.Glade || Type == ButtonType.Custom)
				return base.WriteChild (writer, wrapper);
			else
				return null;
		}
Example #8
0
        void UpdateSelection(Wrapper.Widget w)
        {
            Clear();
            selection = w;

            if (selection == null)
            {
                combo.SetSelection(null);
                return;
            }

            // Look for the root widget, and only update the bar if the selected
            // widget is a child of the root widget

            while (w != null && !w.IsTopLevel)
            {
                w = Stetic.Wrapper.Container.LookupParent((Gtk.Widget)w.Wrapped);
            }
            if (w == null || w != rootWidget)
            {
                return;
            }

            combo.SetSelection(selection);

            selection.Notify += Notified;
            packingSelection  = Stetic.Wrapper.Container.ChildWrapper(selection);
            if (packingSelection != null)
            {
                packingSelection.Notify += Notified;
            }

            AddWidgetCommands(selection);
            UpdateSensitivity();
        }
Example #9
0
        public override XmlElement WriteObject(ObjectWrapper wrapper)
        {
            Wrapper.Widget ww = wrapper as Wrapper.Widget;

            // If the object is already registered, skip it (just create a dummy object)
            if (allowMarkers && ww != null && undoManager.IsRegistered(ww) && !ww.RequiresUndoStatusUpdate)
            {
                XmlElement marker = XmlDocument.CreateElement("widget");
                marker.SetAttribute("unchanged_marker", "yes");
                return(marker);
            }

            // Don't allow markers in indirect children, since those are not checked
            // when creating the diff
            bool oldAllow = allowMarkers;

            allowMarkers = false;
            XmlElement elem = base.WriteObject(wrapper);

            allowMarkers = oldAllow;

            if (ww != null)
            {
                ww.RequiresUndoStatusUpdate = false;
            }

            // Register the object, so it is correctly bound to this xml element
            if (undoManager.IsRegistered(wrapper))
            {
                undoManager.UnregisterObject(wrapper);
            }
            undoManager.RegisterObject(wrapper, elem);

            return(elem);
        }
Example #10
0
 internal ActionToolItem(Widget wrapper, ActionToolbar parent, ActionTreeNode node, uint itemSpacing)
     : base(node, parent, itemSpacing)
 {
     this.parentToolbar = parent;
     this.wrapper = wrapper;
     CreateControls ();
 }
        static MenuItem LabelItem(Gtk.Widget widget)
        {
            ImageMenuItem item;
            Label         label;

            label = new Label(widget is Placeholder ? Catalog.GetString("Placeholder") : widget.Name);
            label.UseUnderline = false;
            label.SetAlignment(0.0f, 0.5f);
            item = new ImageMenuItem();
            item.Add(label);

            Wrapper.Widget wrapper = Stetic.Wrapper.Widget.Lookup(widget);

            if (wrapper != null)
            {
                ClassDescriptor klass = wrapper.ClassDescriptor;
                if (klass != null)
                {
                    Gdk.Pixbuf pixbuf = klass.Icon;
                    int        width, height;
                    Gtk.Icon.SizeLookup(Gtk.IconSize.Menu, out width, out height);
                    item.Image = new Gtk.Image(pixbuf.ScaleSimple(width, height, Gdk.InterpType.Bilinear));
                }
            }

            return(item);
        }
Example #12
0
 void WidgetSelected(object s, Wrapper.WidgetEventArgs args)
 {
     if (!syncing)
     {
         syncing = true;
         if (args.Widget != null)
         {
             Wrapper.Widget w = Wrapper.Widget.Lookup(args.Widget);
             if (w != null)
             {
                 TreeIter?it = FindNode(w, true);
                 if (it != null)
                 {
                     ExpandToPath(store.GetPath(it.Value));
                     Selection.SelectIter(it.Value);
                     ScrollToCell(store.GetPath(it.Value), Columns[0], false, 0, 0);
                     NotifySelectionChanged(w);
                 }
             }
         }
         else
         {
             Selection.UnselectAll();
             NotifySelectionChanged(null);
         }
         syncing = false;
     }
 }
Example #13
0
        public CodeExpression GenerateNewInstanceCode(Wrapper.Widget widget)
        {
            CodeExpression exp = widget.GenerateObjectCreation(this);
            CodeExpression var = GenerateInstanceExpression(widget, exp);

            GenerateBuildCode(widget, var);
            return(var);
        }
 void UpdateSelection(Wrapper.Widget sel)
 {
     selection = sel;
     if (localActionsBox != null)
     {
         localActionsBox.SetActionGroups(selection != null ? selection.LocalActionGroups : null);
     }
     ShowAll();
 }
Example #15
0
        static void GenerateComponentCode(object component, SteticCompilationUnit globalUnit, CodeNamespace globalNs, CodeExpression cobj, CodeStatementCollection statements, CodeTypeDeclaration globalType, GenerationOptions options, List <SteticCompilationUnit> units, CodeIdentifiers ids, ArrayList warnings)
        {
            Gtk.Widget          widget  = component as Gtk.Widget;
            Wrapper.Widget      wwidget = Stetic.Wrapper.Widget.Lookup(widget);
            Wrapper.ActionGroup agroup  = component as Wrapper.ActionGroup;

            string name = widget != null ? widget.Name : agroup.Name;
            string internalClassName = ids.MakeUnique(CodeIdentifier.MakeValid(name));

            string typeName = widget != null ? wwidget.WrappedTypeName : "Gtk.ActionGroup";
            // Create the build method for the top level

            CodeMemberMethod met;

            met = GetBuildMethod(name, internalClassName, typeName, globalUnit, options, units);

            // Generate the build code

            CodeVariableDeclarationStatement varDecHash = new CodeVariableDeclarationStatement(typeof(System.Collections.Hashtable), "bindings");

            met.Statements.Add(varDecHash);
            varDecHash.InitExpression = new CodeObjectCreateExpression(
                typeof(System.Collections.Hashtable),
                new CodeExpression [0]
                );

            CodeVariableReferenceExpression targetObjectVar = new CodeVariableReferenceExpression("cobj");

            Stetic.WidgetMap map;

            if (widget != null)
            {
                map = Stetic.CodeGenerator.GenerateCreationCode(globalNs, globalType, widget, targetObjectVar, met.Statements, options, warnings);
                CodeGenerator.BindSignalHandlers(targetObjectVar, wwidget, map, met.Statements, options);
            }
            else
            {
                map = Stetic.CodeGenerator.GenerateCreationCode(globalNs, globalType, agroup, targetObjectVar, met.Statements, options, warnings);
                foreach (Wrapper.Action ac in agroup.Actions)
                {
                    CodeGenerator.BindSignalHandlers(targetObjectVar, ac, map, met.Statements, options);
                }
            }

            GenerateBindFieldCode(met.Statements, cobj);

            // Add a method call to the build method

            statements.Add(
                new CodeMethodInvokeExpression(
                    new CodeTypeReferenceExpression(options.GlobalNamespace + ".SteticGenerated." + internalClassName),
                    "Build",
                    new CodeCastExpression(typeName, cobj)
                    )
                );
        }
 void IProject.NotifyWidgetContentsChanged(Wrapper.Widget w)
 {
     if (loading)
     {
         return;
     }
     if (WidgetContentsChanged != null)
     {
         WidgetContentsChanged(this, new Wrapper.WidgetEventArgs(w));
     }
 }
Example #17
0
        void RefreshNode(TreeIter it)
        {
            Wrapper.Widget wrapper = (Wrapper.Widget)store.GetValue(it, ColWrapper);
            store.SetValue(it, ColName, wrapper.Wrapped.Name);
            TreeIter cit;

            while (store.IterChildren(out cit, it))
            {
                store.Remove(ref cit);
            }
            FillChildren(it, wrapper);
        }
 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);
     }
 }
Example #19
0
 public override void Clear()
 {
     base.Clear();
     Wrapper.Widget selWidget = selection as Wrapper.Widget;
     if (selWidget != null)
     {
         selWidget.Notify -= Notified;
     }
     if (packingSelection != null)
     {
         packingSelection.Notify -= Notified;
     }
 }
        public void CopyWidgetToProject(string name, ProjectBackend other, string replacedName)
        {
            WidgetData wdata = GetWidgetData(name);

            if (name == null)
            {
                throw new InvalidOperationException("Component not found: " + name);
            }

            XmlElement data;

            if (wdata.Widget != null)
            {
                data = Stetic.WidgetUtils.ExportWidget(wdata.Widget);
            }
            else
            {
                data = (XmlElement)wdata.XmlData.Clone();
            }

            // If widget already exist, replace it
            wdata = other.GetWidgetData(replacedName);
            if (wdata == null)
            {
                wdata = new WidgetData(name, data, null);
                other.topLevels.Add(wdata);
            }
            else
            {
                if (wdata.Widget != null)
                {
                    // If a widget instance already exist, load the new data on it
                    Wrapper.Widget sw = Wrapper.Widget.Lookup(wdata.Widget);
                    sw.Read(new ObjectReader(other, FileFormat.Native), data);
                    sw.NotifyChanged();
                    if (name != replacedName)
                    {
                        other.OnWidgetNameChanged(new Wrapper.WidgetNameChangedArgs(sw, replacedName, name), true);
                    }
                }
                else
                {
                    wdata.SetXmlData(name, data);
                    if (name != replacedName)
                    {
                        other.OnWidgetNameChanged(new Wrapper.WidgetNameChangedArgs(null, replacedName, name), true);
                    }
                }
            }
        }
Example #21
0
        public static XmlElement ExportWidget(Gtk.Widget widget)
        {
            XmlDocument doc = new XmlDocument();

            Stetic.Wrapper.Widget wrapper = Stetic.Wrapper.Widget.Lookup(widget);
            if (wrapper == null)
            {
                throw new InvalidOperationException();
            }

            XmlElement elem = wrapper.Write(new ObjectWriter(doc, FileFormat.Native));

            doc.AppendChild(elem);
            return(doc.DocumentElement);
        }
Example #22
0
		protected override void GenerateChildBuildCode (GeneratorContext ctx, CodeExpression parentVar, Widget wrapper)
		{
			if (wrapper.Wrapped == expander.LabelWidget) {
				CodeExpression var = ctx.GenerateNewInstanceCode (wrapper);
				CodeAssignStatement assign = new CodeAssignStatement (
					new CodePropertyReferenceExpression (
						parentVar,
						"LabelWidget"
					),
					var
				);
				ctx.Statements.Add (assign);
			} else
				base.GenerateChildBuildCode (ctx, parentVar, wrapper);
		}
Example #23
0
		protected override void GenerateChildBuildCode (GeneratorContext ctx, CodeExpression parentVar, Widget wrapper)
		{
			if (!HasLabel) {
				// CheckButton generates a label by default. Remove it if it is not required.
				ctx.Statements.Add (
					new CodeMethodInvokeExpression (
						parentVar,
						"Remove",
						new CodePropertyReferenceExpression (
							parentVar,
							"Child"
						)
					)
				);
			}
			base.GenerateChildBuildCode (ctx, parentVar, wrapper);
		}
Example #24
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 = new CodeDelegateCreateExpression(
                    new CodeTypeReference(descriptor.HandlerTypeName, CodeTypeReferenceOptions.GlobalReference),
                    new CodeThisReferenceExpression(),
                    signal.Handler);

                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);
                    }
                }
            }
        }
Example #25
0
 void FillChildren(TreeIter it, Wrapper.Widget wrapper)
 {
     Stetic.Wrapper.Container container = wrapper as Wrapper.Container;
     if (container != null)
     {
         foreach (Gtk.Widget w in container.RealChildren)
         {
             Stetic.Wrapper.Widget ww = GetVisibleWrapper(w);
             if (ww != null)
             {
                 // Add a dummy node to allow lazy loading
                 store.SetValue(it, ColFilled, false);
                 store.AppendValues(it, null, "", null, false);
                 return;
             }
         }
     }
     store.SetValue(it, ColFilled, true);
 }
Example #26
0
		public override void Dispose ()
		{
			Registry.RegistryChanged -= OnRegistryChanged;
			
			foreach (PaletteGroup grp in groups.Values)
				grp.Destroy ();

			if (localActionsBox != null) {
				localActionsBox.Destroy ();
				localActionsBox = null;
			}
			if (globalActionsBox != null) {
				globalActionsBox.Destroy ();
				globalActionsBox = null;
			}
			
			project = null;
			selection = null;
			base.Dispose ();
		}
Example #27
0
		internal ActionMenu (Widget wrapper, IMenuItemContainer parentMenu, ActionTreeNode node)
		{
			DND.DestSet (this, true);
			parentNode = node;
			this.parentMenu = parentMenu;
			this.wrapper = wrapper;
			this.nodes = node.Children;
			table = new Gtk.Table (0, 0, false);
			table.ColumnSpacing = 5;
			table.RowSpacing = 5;
			table.BorderWidth = 5;
			this.AppPaintable = true;
			
			Add (table);
			
			Fill ();
			
			parentNode.ChildNodeAdded += OnChildAdded;
			parentNode.ChildNodeRemoved += OnChildRemoved;
		}
Example #28
0
        internal ArrayList GetWidgetChildren(Wrapper.Widget ww)
        {
            Stetic.Wrapper.Container cw = ww as Stetic.Wrapper.Container;
            if (cw == null)
            {
                return(null);
            }

            ArrayList list = new ArrayList();

            foreach (object ob in cw.RealChildren)
            {
                ObjectWrapper ow = ObjectWrapper.Lookup(ob);
                if (ow != null)
                {
                    list.Add(Component.GetSafeReference(ow));
                }
            }
            return(list);
        }
Example #29
0
        string GetHandlerName(string signalName)
        {
            Wrapper.Widget selWidget = selection as Wrapper.Widget;
            if (selWidget != null)
            {
//				if (selWidget.IsTopLevel)
//					return "On" + signalName;
//				else
//					return "On" + GetIdentifier (selWidget.Wrapped.Name) + signalName;
                return(string.Format("{0}_{1}",
                                     GetIdentifier(selWidget.Wrapped.Name), signalName));
            }

            Wrapper.Action action = selection as Wrapper.Action;
            if (action != null)
            {
                return("On" + GetIdentifier(action.Name) + signalName);
            }

            return("On" + signalName);
        }
        protected override bool OnKeyPressEvent(Gdk.EventKey ev)
        {
            switch (ev.Key)
            {
            case Gdk.Key.Delete:
            case Gdk.Key.KP_Delete:
                IObjectSelection sel = GetSelection();
                if (sel != null && sel.DataObject != null)
                {
                    Wrapper.Widget wrapper = Wrapper.Widget.Lookup(sel.DataObject) as Wrapper.Widget;
                    if (wrapper != null)
                    {
                        wrapper.Delete();
                    }
                }
                return(true);

            default:
                return(base.OnKeyPressEvent(ev));
            }
        }
Example #31
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);
        }
Example #32
0
        TreeIter?FindNode(Wrapper.Widget w, bool loadBranches)
        {
            Wrapper.Widget parent = w.ParentWrapper;
            TreeIter       it;

            if (parent == null)
            {
                if (!store.GetIterFirst(out it))
                {
                    return(null);
                }
            }
            else
            {
                TreeIter?pi = FindNode(parent, loadBranches);
                if (pi == null)
                {
                    return(null);
                }
                if (loadBranches)
                {
                    EnsureFilled(pi.Value);
                }
                if (!store.IterChildren(out it, pi.Value))
                {
                    return(null);
                }
            }

            do
            {
                Wrapper.Widget cw = (Wrapper.Widget)store.GetValue(it, ColWrapper);
                if (cw == w)
                {
                    return(it);
                }
            } while (store.IterNext(ref it));

            return(null);
        }
Example #33
0
        string GetHandlerName(string signalName)
        {
            Wrapper.Widget selWidget = selection as Wrapper.Widget;
            if (selWidget != null)
            {
                if (selWidget.IsTopLevel)
                {
                    return("On" + signalName);
                }
                else
                {
                    return("On" + GetIdentifier(selWidget.Wrapped.Name) + signalName);
                }
            }

            Wrapper.Action action = selection as Wrapper.Action;
            if (action != null)
            {
                return("On" + GetIdentifier(action.Name) + signalName);
            }

            return("On" + signalName);
        }
        public override void Dispose()
        {
            Registry.RegistryChanged -= OnRegistryChanged;

            foreach (PaletteGroup grp in groups.Values)
            {
                grp.Destroy();
            }

            if (localActionsBox != null)
            {
                localActionsBox.Destroy();
                localActionsBox = null;
            }
            if (globalActionsBox != null)
            {
                globalActionsBox.Destroy();
                globalActionsBox = null;
            }

            project   = null;
            selection = null;
            base.Dispose();
        }
Example #35
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);
        }
Example #36
0
		public XmlElement WriteContainerChild (ObjectWriter writer, Widget wrapper)
		{
			return WriteChild (writer, wrapper);
		}
Example #37
0
		protected override void GenerateChildBuildCode (GeneratorContext ctx, CodeExpression parentExp, Widget wrapper)
		{
			Gtk.Widget child = (Gtk.Widget) wrapper.Wrapped;
			
			if (notebook.PageNum (child) == -1) {
				// It's a tab
				
				ctx.Statements.Add (new CodeCommentStatement ("Notebook tab"));
				Gtk.Widget page = null;
				CodeExpression pageVar;
				
				// Look for the page widget contained in this tab
				for (int n=0; n < notebook.NPages; n++) {
					if (notebook.GetTabLabel (notebook.GetNthPage (n)) == child) {
						page = notebook.GetNthPage (n);
						break;
					}
				}
				
				// If the page contains a placeholder, generate a dummy page
				if (page is Stetic.Placeholder) {
					CodeVariableDeclarationStatement dvar = new CodeVariableDeclarationStatement (
						"Gtk.Label".ToGlobalTypeRef (),
						ctx.NewId (),
						new CodeObjectCreateExpression ("Gtk.Label".ToGlobalTypeRef ())
					);
					ctx.Statements.Add (dvar);
					ctx.Statements.Add (
						new CodeAssignStatement (
							new CodePropertyReferenceExpression (
								new CodeVariableReferenceExpression (dvar.Name),
								"Visible"
							),
							new CodePrimitiveExpression (true)
						)
					);
					ctx.Statements.Add (
						new CodeMethodInvokeExpression (
							parentExp,
							"Add",
							new CodeVariableReferenceExpression (dvar.Name)
						)
					);
					pageVar = new CodeVariableReferenceExpression (dvar.Name);
				} else
					pageVar = ctx.WidgetMap.GetWidgetExp (page);
				
				// Generate code for the tab
				CodeExpression var = ctx.GenerateNewInstanceCode (wrapper);
				
				// Assign the tab to the page
				CodeMethodInvokeExpression invoke = new CodeMethodInvokeExpression (
					parentExp,
					"SetTabLabel",
					pageVar,
					var
				);
				ctx.Statements.Add (invoke);
				
				// Workaround for GTK bug. ShowAll is not propagated to tab labels.
				invoke = new CodeMethodInvokeExpression (
					var,
					"ShowAll"
				);
				ctx.Statements.Add (invoke);
			} else
				base.GenerateChildBuildCode (ctx, parentExp, wrapper);
		}
Example #38
0
 internal Wrapper.ActionGroup[] GetActionGroups(Wrapper.Widget widget)
 {
     return(widget.LocalActionGroups.ToArray());
 }
Example #39
0
		protected virtual void GenerateChildBuildCode (GeneratorContext ctx, CodeExpression parentVar, Widget wrapper)
		{
			ObjectWrapper childwrapper = ChildWrapper (wrapper);
			if (childwrapper != null) {
				ctx.Statements.Add (new CodeCommentStatement ("Container child " + Wrapped.Name + "." + childwrapper.Wrapped.GetType ()));
				CodeExpression var = ctx.GenerateNewInstanceCode (wrapper);
				CodeMethodInvokeExpression invoke = new CodeMethodInvokeExpression (
					parentVar,
					"Add",
					var
				);
				ctx.Statements.Add (invoke);

				GenerateSetPacking (ctx, parentVar, var, childwrapper);
			}
		}
		public static void Add (Widget wrapper)
		{
			Gtk.Widget widget = wrapper.Wrapped;

			widget.SizeAllocated += Insensitive_SizeAllocate;
			widget.Realized += Insensitive_Realized;
			widget.Unrealized += Insensitive_Unrealized;
			widget.Mapped += Insensitive_Mapped;
			widget.Unmapped += Insensitive_Unmapped;

			if (widget.IsRealized)
				Insensitive_Realized (widget, EventArgs.Empty);
			if (widget.IsMapped)
				Insensitive_Mapped (widget, EventArgs.Empty);
		}
Example #41
0
		void UpdateSelection (Wrapper.Widget sel)
		{
			selection = sel;
			if (localActionsBox != null)
				localActionsBox.SetActionGroups (selection != null ? selection.LocalActionGroups : null);
			ShowAll ();
		}
Example #42
0
 protected override void GenerateChildBuildCode(GeneratorContext ctx, CodeExpression parentVar, Widget wrapper)
 {
     Gtk.Viewport vp = wrapper.Wrapped as Gtk.Viewport;
     if (vp == null || (vp.Child != null && !(vp.Child is Placeholder)))
         base.GenerateChildBuildCode (ctx, parentVar, wrapper);
 }
Example #43
0
		internal ActionMenuItem (Widget wrapper, IMenuItemContainer parent, ActionTreeNode node)
		: this (wrapper, parent, node, 0)
		{
		}
Example #44
0
		internal ActionMenuItem (Widget wrapper, IMenuItemContainer parent, ActionTreeNode node, uint itemSpacing): base (node, parent, itemSpacing)
		{
			this.wrapper = wrapper;
			CreateControls ();
		}
Example #45
0
		protected override void GenerateChildBuildCode (GeneratorContext ctx, CodeExpression parentVar, Widget wrapper)
		{
			if (actionDialog != null && wrapper is Button) {
			
				// If this is the action area of a dialog, buttons must be added using AddActionWidget,
				// so they are properly registered.
				
				ObjectWrapper childwrapper = ChildWrapper (wrapper);
				Button button = wrapper as Button;
				
				if (childwrapper != null) {
					CodeExpression dialogVar = ctx.WidgetMap.GetWidgetExp (actionDialog);
					ctx.Statements.Add (new CodeCommentStatement ("Container child " + Wrapped.Name + "." + childwrapper.Wrapped.GetType ()));
					CodeExpression var = ctx.GenerateNewInstanceCode (wrapper);
					if (button.ResponseId != (int) Gtk.ResponseType.None) {
						CodeMethodInvokeExpression invoke = new CodeMethodInvokeExpression (
							dialogVar,
							"AddActionWidget",
							var,
							new CodePrimitiveExpression (button.ResponseId)
						);
						ctx.Statements.Add (invoke);
					}
					else {
						CodeMethodInvokeExpression invoke = new CodeMethodInvokeExpression (
							parentVar,
							"Add",
							var
						);
						ctx.Statements.Add (invoke);
					}
					GenerateSetPacking (ctx, parentVar, var, childwrapper);
				}
			} else
				base.GenerateChildBuildCode (ctx, parentVar, wrapper);
		}
		internal ActionToolItem (Widget wrapper, ActionToolbar parent, ActionTreeNode node)
		: this (wrapper, parent, node, 0)
		{
		}
Example #47
0
 internal void GenerateTooltip(GeneratorContext ctx, Widget widget)
 {
     if (generatedTooltips == null) {
         string tid = ctx.NewId ();
         CodeVariableDeclarationStatement vardec = new CodeVariableDeclarationStatement (
             typeof(Gtk.Tooltips),
             tid,
             new CodeObjectCreateExpression (typeof(Gtk.Tooltips))
         );
         ctx.Statements.Add (vardec);
         generatedTooltips = new CodeVariableReferenceExpression (tid);
     }
     ctx.Statements.Add (
         new CodeMethodInvokeExpression (
             generatedTooltips,
             "SetTip",
             ctx.WidgetMap.GetWidgetExp (widget),
             new CodePrimitiveExpression (widget.Tooltip),
             new CodePrimitiveExpression (widget.Tooltip)
         )
     );
 }
Example #48
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;
//			}
        }
Example #49
0
		protected virtual XmlElement WriteChild (ObjectWriter writer, Widget wrapper)
		{
			XmlElement child_elem = writer.XmlDocument.CreateElement ("child");
			XmlElement widget_elem = writer.WriteObject (wrapper);
			child_elem.AppendChild (widget_elem);

			Container.ContainerChild childwrapper = ChildWrapper (wrapper);
			if (childwrapper != null) {
				XmlElement packing_elem;
				
				if (writer.Format == FileFormat.Glade)
					packing_elem = GladeUtils.CreatePacking (writer.XmlDocument, childwrapper);
				else
					packing_elem = WidgetUtils.CreatePacking (writer.XmlDocument, childwrapper);
				
				// Sets the child Id to be used in undo/redo operations
				if (writer.CreateUndoInfo)
					child_elem.SetAttribute ("undoId", childwrapper.UndoId);

				if (packing_elem.HasChildNodes)
					child_elem.AppendChild (packing_elem);
			} else {
				// There is no container child, so make up an id.
				if (writer.CreateUndoInfo)
					child_elem.SetAttribute ("undoId", "0");
			}

			return child_elem;
		}
Example #50
0
		internal void GenerateTooltip (GeneratorContext ctx, Widget widget)
		{
			if (WidgetUtils.CompareVersions (Project.TargetGtkVersion, "2.12") <= 0) {
				ctx.Statements.Add (
					new CodeAssignStatement (
						new CodePropertyReferenceExpression (ctx.WidgetMap.GetWidgetExp (widget), "TooltipMarkup"),
						new CodePrimitiveExpression (widget.Tooltip)
					)
				);
				return;
			}
 
			if (generatedTooltips == null) {
				string tid = ctx.NewId ();
				Type t = typeof(Gtk.Widget).Assembly.GetType ("Gtk.Tooltips");
				CodeVariableDeclarationStatement vardec = new CodeVariableDeclarationStatement (
					t.ToGlobalTypeRef (), tid, new CodeObjectCreateExpression (t)
				);
				ctx.Statements.Add (vardec);
				generatedTooltips = new CodeVariableReferenceExpression (tid);
			}
			ctx.Statements.Add (
				new CodeMethodInvokeExpression (
					generatedTooltips,
					"SetTip",
					ctx.WidgetMap.GetWidgetExp (widget),
					new CodePrimitiveExpression (widget.Tooltip),
					new CodePrimitiveExpression (widget.Tooltip)
				)
			);
		}
Example #51
0
 internal void RenameWidget(Wrapper.Widget w, string newName)
 {
     w.Wrapped.Name = newName;
 }
		public static void Remove (Widget wrapper)
		{
			Gtk.Widget widget = wrapper.Wrapped;
			Gdk.Window win = (Gdk.Window)map[widget];
			if (win != null) {
				map.Remove (widget);
				map.Remove (win);
				win.Destroy ();
			}
			widget.SizeAllocated -= Insensitive_SizeAllocate;
			widget.Realized -= Insensitive_Realized;
			widget.Unrealized -= Insensitive_Unrealized;
			widget.Mapped -= Insensitive_Mapped;
			widget.Unmapped -= Insensitive_Unmapped;
		}