예제 #1
0
        public void GenerateBuildCode(GeneratorContext ctx)
        {
            string varName = ctx.NewId ();
            CodeVariableDeclarationStatement varDec = new CodeVariableDeclarationStatement (typeof(Gtk.IconFactory), varName);
            varDec.InitExpression = new CodeObjectCreateExpression (typeof(Gtk.IconFactory));
            ctx.Statements.Add (varDec);

            CodeVariableReferenceExpression var = new CodeVariableReferenceExpression (varName);
            foreach (ProjectIconSet icon in icons) {

                CodeExpression exp = new CodeMethodInvokeExpression (
                    var,
                    "Add",
                    new CodePrimitiveExpression (icon.Name),
                    icon.GenerateObjectBuild (ctx)
                );
                ctx.Statements.Add (exp);
            }

            CodeExpression addd = new CodeMethodInvokeExpression (
                var,
                "AddDefault"
            );
            ctx.Statements.Add (addd);
        }
예제 #2
0
        internal CodeExpression GenerateObjectBuild(GeneratorContext ctx)
        {
            string varName = ctx.NewId ();
            CodeVariableDeclarationStatement varDec = new CodeVariableDeclarationStatement (typeof(Gtk.IconSource), varName);
            varDec.InitExpression = new CodeObjectCreateExpression (typeof(Gtk.IconSource));
            ctx.Statements.Add (varDec);

            CodeVariableReferenceExpression var = new CodeVariableReferenceExpression (varName);

            ctx.Statements.Add (new CodeAssignStatement (
                new CodePropertyReferenceExpression (var, "Pixbuf"),
                imageInfo.ToCodeExpression (ctx)
            ));

            if (!SizeWildcarded) {
                ctx.Statements.Add (new CodeAssignStatement (
                    new CodePropertyReferenceExpression (var, "SizeWildcarded"),
                    new CodePrimitiveExpression (false)
                ));
                ctx.Statements.Add (new CodeAssignStatement (
                    new CodePropertyReferenceExpression (var, "Size"),
                    new CodeFieldReferenceExpression (
                        new CodeTypeReferenceExpression ("Gtk.IconSize"),
                        Size.ToString ()
                    )
                ));
            }

            if (!StateWildcarded) {
                ctx.Statements.Add (new CodeAssignStatement (
                    new CodePropertyReferenceExpression (var, "StateWildcarded"),
                    new CodePrimitiveExpression (false)
                ));
                ctx.Statements.Add (new CodeAssignStatement (
                    new CodePropertyReferenceExpression (var, "State"),
                    new CodeFieldReferenceExpression (
                        new CodeTypeReferenceExpression ("Gtk.StateType"),
                        State.ToString ()
                    )
                ));
            }

            if (!DirectionWildcarded) {
                ctx.Statements.Add (new CodeAssignStatement (
                    new CodePropertyReferenceExpression (var, "DirectionWildcarded"),
                    new CodePrimitiveExpression (false)
                ));
                ctx.Statements.Add (new CodeAssignStatement (
                    new CodePropertyReferenceExpression (var, "Direction"),
                    new CodeFieldReferenceExpression (
                        new CodeTypeReferenceExpression ("Gtk.TextDirection"),
                        Direction.ToString ()
                    )
                ));
            }

            return var;
        }
예제 #3
0
        public CodeExpression GenerateGroupExpression(GeneratorContext ctx, Gtk.Widget widget)
        {
            // Returns and expression that represents the group to which the radio belongs.
            // This expression can be an empty SList, if this is the first radio of the
            // group that has been generated, or an SList taken from previously generated
            // radios from the same group.

            RadioGroup group = widgets[widget] as RadioGroup;
            CodeExpression var = null;

            foreach (Gtk.Widget radio in group.Widgets) {
                if (radio == widget)
                    continue;
                var = ctx.WidgetMap.GetWidgetExp (radio);
                if (var != null)
                    break;
            }

            if (var == null) {
                return new CodeObjectCreateExpression (
                    "GLib.SList",
                    new CodePropertyReferenceExpression (
                        new CodeTypeReferenceExpression (typeof(IntPtr)),
                        "Zero"
                    )
                );
            } else {
                return new CodePropertyReferenceExpression (
                    var,
                    "Group"
                );
            }
        }
예제 #4
0
        internal CodeExpression GenerateObjectBuild(GeneratorContext ctx)
        {
            string varName = ctx.NewId ();
            CodeVariableDeclarationStatement varDec = new CodeVariableDeclarationStatement (typeof(Gtk.IconSet), varName);
            ctx.Statements.Add (varDec);

            CodeVariableReferenceExpression var = new CodeVariableReferenceExpression (varName);

            if (sources.Count == 1 && sources[0].AllWildcarded) {
                varDec.InitExpression = new CodeObjectCreateExpression (
                    typeof(Gtk.IconSet),
                    sources[0].Image.ToCodeExpression (ctx)
                );
            } else {
                varDec.InitExpression = new CodeObjectCreateExpression (typeof(Gtk.IconSet));
                foreach (ProjectIconSource src in sources) {
                    CodeExpression exp = new CodeMethodInvokeExpression (
                        var,
                        "AddSource",
                        src.GenerateObjectBuild (ctx)
                    );
                    ctx.Statements.Add (exp);
                }
            }
            return var;
        }
예제 #5
0
		protected virtual void GeneratePropertySet (GeneratorContext ctx, CodeExpression var, PropertyDescriptor prop)
		{
			object oval = prop.GetValue (Wrapped);
			if (oval == null || (prop.HasDefault && prop.IsDefaultValue (oval)))
				return;
				
			CodeExpression val = ctx.GenerateValue (oval, prop.RuntimePropertyType, prop.Translatable && prop.IsTranslated (Wrapped));
			CodeExpression cprop;
			
			TypedPropertyDescriptor tprop = prop as TypedPropertyDescriptor;
			if (tprop == null || tprop.GladeProperty == prop) {
				cprop = new CodePropertyReferenceExpression (var, prop.Name);
			} else {
				cprop = new CodePropertyReferenceExpression (var, tprop.GladeProperty.Name);
				cprop = new CodePropertyReferenceExpression (cprop, prop.Name);
			}
			ctx.Statements.Add (new CodeAssignStatement (cprop, val));
		}
예제 #6
0
파일: ImageInfo.cs 프로젝트: mono/stetic
        public CodeExpression ToCodeExpression(GeneratorContext ctx)
        {
            switch (source) {
                case ImageSource.Resource:
                    return new CodeMethodInvokeExpression (
                        new CodeTypeReferenceExpression (typeof(Gdk.Pixbuf)),
                        "LoadFromResource",
                        new CodePrimitiveExpression (name)
                    );

                case ImageSource.Theme:
                    return ctx.GenerateLoadPixbuf (name, size);

                case ImageSource.File:
                    return new CodeObjectCreateExpression (
                        typeof(Gdk.Pixbuf),
                        new CodeMethodInvokeExpression (
                            new CodeTypeReferenceExpression (typeof(System.IO.Path)),
                            "Combine",
                            new CodePropertyReferenceExpression (
                                new CodePropertyReferenceExpression (
                                    new CodeTypeReferenceExpression (typeof(AppDomain)),
                                    "CurrentDomain"
                                ),
                                "BaseDirectory"
                            ),
                            new CodePrimitiveExpression (name)
                        )
                    );
            }
            return new CodePrimitiveExpression (null);
        }
예제 #7
0
		internal protected virtual void GeneratePostBuildCode (GeneratorContext ctx, CodeExpression var)
		{
		}
예제 #8
0
		internal protected virtual CodeExpression GenerateObjectCreation (GeneratorContext ctx)
		{
			if (ClassDescriptor.InitializationProperties != null) {
				CodeExpression[] paramters = new CodeExpression [ClassDescriptor.InitializationProperties.Length];
				for (int n=0; n < paramters.Length; n++) {
					PropertyDescriptor prop = ClassDescriptor.InitializationProperties [n];
					paramters [n] = ctx.GenerateValue (prop.GetValue (Wrapped), prop.RuntimePropertyType, prop.Translatable && prop.IsTranslated (Wrapped));
				}
				return new CodeObjectCreateExpression (WrappedTypeName.ToGlobalTypeRef (), paramters);
			} else
				return new CodeObjectCreateExpression (WrappedTypeName.ToGlobalTypeRef ());
		}
예제 #9
0
		internal protected virtual void GenerateBuildCode (GeneratorContext ctx, CodeExpression var)
		{
			// Write the widget properties
			foreach (ItemGroup group in ClassDescriptor.ItemGroups) {
				foreach (ItemDescriptor item in group) {
					if (!item.SupportsGtkVersion (Project.TargetGtkVersion))
						continue;
					PropertyDescriptor prop = item as PropertyDescriptor;
					if (prop == null || !prop.IsRuntimeProperty)
						continue;
					if (ClassDescriptor.InitializationProperties != null && Array.IndexOf (ClassDescriptor.InitializationProperties, prop) != -1)
						continue;
					GeneratePropertySet (ctx, var, prop);
				}
			}
		}
예제 #10
0
		internal void GenerateInitCode (GeneratorContext ctx, CodeExpression var)
		{
			// Set the value for initialization properties. The value for those properties is
			// usually set in the constructor, but top levels are created by the user, so
			// those properties need to be explicitely set in the Gui.Build method.
			foreach (PropertyDescriptor prop in ClassDescriptor.InitializationProperties) {
				GeneratePropertySet (ctx, var, prop);
			}
		}
예제 #11
0
파일: ErrorWidget.cs 프로젝트: mono/stetic
        protected internal override CodeExpression GenerateObjectCreation(GeneratorContext ctx)
        {
            ErrorWidget ew = (ErrorWidget) Wrapped;
            string msg;
            if (ew.Exception != null)
                msg = "Could not generate code for an invalid widget. The widget failed to load: " + ew.Exception.Message + ". The generated code may be invalid.";
            else
                msg = "Could not generate code for widgets of type: " + ew.ClassName + ". The widget could not be found in any referenced library. The generated code may be invalid.";

            if (ctx.Options.FailForUnknownWidgets) {
                throw new InvalidOperationException (msg);
            } else {
                ctx.ReportWarning (msg);
                return new CodePrimitiveExpression (null);
            }
        }
        internal CodeExpression GenerateObjectBuild(GeneratorContext ctx)
        {
            string varName = ctx.NewId();
            CodeVariableDeclarationStatement varDec = new CodeVariableDeclarationStatement(typeof(Gtk.IconSource).ToGlobalTypeRef(), varName);

            varDec.InitExpression = new CodeObjectCreateExpression(typeof(Gtk.IconSource).ToGlobalTypeRef());
            ctx.Statements.Add(varDec);

            CodeVariableReferenceExpression var = new CodeVariableReferenceExpression(varName);

            ctx.Statements.Add(new CodeAssignStatement(
                                   new CodePropertyReferenceExpression(var, "Pixbuf"),
                                   imageInfo.ToCodeExpression(ctx)
                                   ));

            if (!SizeWildcarded)
            {
                ctx.Statements.Add(new CodeAssignStatement(
                                       new CodePropertyReferenceExpression(var, "SizeWildcarded"),
                                       new CodePrimitiveExpression(false)
                                       ));
                ctx.Statements.Add(new CodeAssignStatement(
                                       new CodePropertyReferenceExpression(var, "Size"),
                                       new CodeFieldReferenceExpression(
                                           new CodeTypeReferenceExpression(new CodeTypeReference("Gtk.IconSize", CodeTypeReferenceOptions.GlobalReference)),
                                           Size.ToString()
                                           )
                                       ));
            }

            if (!StateWildcarded)
            {
                ctx.Statements.Add(new CodeAssignStatement(
                                       new CodePropertyReferenceExpression(var, "StateWildcarded"),
                                       new CodePrimitiveExpression(false)
                                       ));
                ctx.Statements.Add(new CodeAssignStatement(
                                       new CodePropertyReferenceExpression(var, "State"),
                                       new CodeFieldReferenceExpression(
                                           new CodeTypeReferenceExpression(new CodeTypeReference("Gtk.StateType", CodeTypeReferenceOptions.GlobalReference)),
                                           State.ToString()
                                           )
                                       ));
            }

            if (!DirectionWildcarded)
            {
                ctx.Statements.Add(new CodeAssignStatement(
                                       new CodePropertyReferenceExpression(var, "DirectionWildcarded"),
                                       new CodePrimitiveExpression(false)
                                       ));
                ctx.Statements.Add(new CodeAssignStatement(
                                       new CodePropertyReferenceExpression(var, "Direction"),
                                       new CodeFieldReferenceExpression(
                                           new CodeTypeReferenceExpression(new CodeTypeReference("Gtk.TextDirection", CodeTypeReferenceOptions.GlobalReference)),
                                           Direction.ToString()
                                           )
                                       ));
            }

            return(var);
        }
예제 #13
0
 internal protected virtual void GeneratePostBuildCode(GeneratorContext ctx, CodeExpression var)
 {
 }