3
using System.Reflection;
5
using System.CodeDom.Compiler;
6
using System.Collections.Generic;
7
using System.Collections;
12
internal static class CodeGeneratorPartialClass
14
public static void GenerateProjectGuiCode (SteticCompilationUnit globalUnit, CodeNamespace globalNs, CodeTypeDeclaration globalType, GenerationOptions options, List<SteticCompilationUnit> units, ProjectBackend[] projects, ArrayList warnings)
16
// Generate code for each project
17
foreach (ProjectBackend gp in projects) {
19
// Generate top levels
20
foreach (Gtk.Widget w in gp.Toplevels)
21
GenerateWidgetCode (globalUnit, globalNs, options, units, w, warnings);
23
// Generate global action groups
24
foreach (Wrapper.ActionGroup agroup in gp.ActionGroups)
25
GenerateGlobalActionGroupCode (globalUnit, globalNs, options, units, agroup, warnings);
29
static CodeTypeDeclaration CreatePartialClass (SteticCompilationUnit globalUnit, List<SteticCompilationUnit> units, GenerationOptions options, string name)
31
SteticCompilationUnit unit;
33
if (options.GenerateSingleFile)
36
unit = new SteticCompilationUnit (name);
41
int i = name.LastIndexOf ('.');
43
ns = name.Substring (0, i);
44
name = name.Substring (i+1);
47
CodeTypeDeclaration type = new CodeTypeDeclaration (name);
48
type.IsPartial = true;
49
type.Attributes = MemberAttributes.Public;
50
type.TypeAttributes = TypeAttributes.Public;
52
CodeNamespace cns = new CodeNamespace (ns);
54
unit.Namespaces.Add (cns);
59
static void GenerateWidgetCode (SteticCompilationUnit globalUnit, CodeNamespace globalNs, GenerationOptions options, List<SteticCompilationUnit> units, Gtk.Widget w, ArrayList warnings)
61
// Generate the build method
63
CodeTypeDeclaration type = CreatePartialClass (globalUnit, units, options, w.Name);
64
CodeMemberMethod met = new CodeMemberMethod ();
66
type.Members.Add (met);
67
met.ReturnType = new CodeTypeReference (typeof(void));
68
met.Attributes = MemberAttributes.Family;
70
if (options.GenerateEmptyBuildMethod) {
71
GenerateWrapperFields (type, Wrapper.Widget.Lookup (w));
76
new CodeMethodInvokeExpression (
77
new CodeTypeReferenceExpression (globalNs.Name + ".Gui"),
79
new CodeThisReferenceExpression ()
83
Stetic.Wrapper.Widget wwidget = Stetic.Wrapper.Widget.Lookup (w);
84
if (wwidget.GeneratePublic)
85
type.TypeAttributes = TypeAttributes.Public;
87
type.TypeAttributes = TypeAttributes.NotPublic;
89
Stetic.WidgetMap map = Stetic.CodeGenerator.GenerateCreationCode (globalNs, type, w, new CodeThisReferenceExpression (), met.Statements, options, warnings);
90
CodeGenerator.BindSignalHandlers (new CodeThisReferenceExpression (), wwidget, map, met.Statements, options);
93
static void GenerateWrapperFields (CodeTypeDeclaration type, ObjectWrapper wrapper)
95
foreach (ObjectBindInfo binfo in CodeGenerator.GetFieldsToBind (wrapper)) {
106
static void GenerateGlobalActionGroupCode (SteticCompilationUnit globalUnit, CodeNamespace globalNs, GenerationOptions options, List<SteticCompilationUnit> units, Wrapper.ActionGroup agroup, ArrayList warnings)
108
CodeTypeDeclaration type = CreatePartialClass (globalUnit, units, options, agroup.Name);
110
// Generate the build method
112
CodeMemberMethod met = new CodeMemberMethod ();
114
type.Members.Add (met);
115
met.ReturnType = new CodeTypeReference (typeof(void));
116
met.Attributes = MemberAttributes.Public;
118
Stetic.WidgetMap map = Stetic.CodeGenerator.GenerateCreationCode (globalNs, type, agroup, new CodeThisReferenceExpression (), met.Statements, options, warnings);
120
foreach (Wrapper.Action ac in agroup.Actions)
121
CodeGenerator.BindSignalHandlers (new CodeThisReferenceExpression (), ac, map, met.Statements, options);