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); }
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; }
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" ); } }
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; }
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)); }
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); }
internal protected virtual void GeneratePostBuildCode (GeneratorContext ctx, CodeExpression var) { }
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 ()); }
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); } } }
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); } }
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); }
internal protected virtual void GeneratePostBuildCode(GeneratorContext ctx, CodeExpression var) { }