5 public class JsRender.NodeToGtk : Object {
9 Gee.ArrayList<string> els;
10 //Gee.ArrayList<string> skip;
11 Gee.HashMap<string,string> ar_props;
12 public static int vcnt = 0;
14 public NodeToGtk( Node node)
17 this.els = new Gee.ArrayList<string>();
18 //this.skip = new Gee.ArrayList<string>();
19 this.ar_props = new Gee.HashMap<string,string>();
23 public Object? munge ( )
26 return this.mungeNode (null);
30 public Object? mungeChild( Node cnode)
32 var x = new NodeToGtk(cnode);
33 return x.mungeNode(this);
36 public Object? mungeNode(NodeToGtk? parentObj)
39 var parent = parentObj != null ? parentObj.wrapped_object : null;
40 var cls = this.node.fqn().replace(".", "");
41 var ns = this.node.fqn().split(".")[0];
42 var gtkbuilder = new global::Gtk.Builder();
44 var cls_gtype = gtkbuilder.get_type_from_name(cls);
45 print("Type: %s ?= %s\n", this.node.fqn(), cls_gtype.name());
47 if (cls_gtype == GLib.Type.INVALID) {
48 print("SKIP - gtype is invalid\n");
51 // if it's a window...
53 if (cls_gtype.is_a(typeof(global::Gtk.Window))) {
54 // what if it has none...
55 if (this.node.items.size < 1) {
58 return this.mungeChild(this.node.items.get(0));
61 var ret = Object.new(cls_gtype);
62 ret.ref(); //??? problematic?
63 this.wrapped_object = ret;
68 case "GtkTreeStore": // top level.. - named and referenced
69 case "GtkListStore": // top level.. - named and referenced
70 case "GtkTreeViewColumn": // part of liststore?!?!
71 case "GtkMenu": // top level..
72 case "GtkCellRendererText":
73 case "GtkSourceBuffer":
74 case "GtkClutterActor"://fixme..
75 ///case "GtkClutterEmbed"://fixme..
82 if (!cls_gtype.is_a(typeof(global::Gtk.Buildable))) {
83 print("skipping pack %s is not a buildable..\n", cls);
87 //print("skipping pack %s is not a buildable..\n", cls);
89 } else if (!parent.get_type().is_a(typeof(global::Gtk.Buildable))) {
90 print("skipping pack parent:%s is not a buildable..\n", parent.get_type().name());
94 // at present we are setting the packing / fill / expand as
95 // arguments to pack_start etc...
97 var parent_gir = parentObj == null ? null : Palete.Gir.factoryFqn(parentObj.node.fqn());
99 // let's test just setting expand to false...
100 var cls_methods = parent_gir == null ? null : parent_gir.methods;
102 // pack on a container..
105 ((global::Gtk.Buildable)parent).add_child(gtkbuilder, ret, null);
109 this.node.props.has_key("* pack")
113 parent.get_type().is_a(typeof(global::Gtk.Container))) {
114 var pack = this.node.props.get("* pack").split(",");
117 if (cls_methods.has_key(pack[0])) {
118 var mparams = cls_methods.get(pack[0]).paramset.params;
119 for (var i = 1; i < mparams.size; i++ ) {
120 if (i > (pack.length -1)) {
124 var k = mparams.get(i).name;
128 var type = mparams.get(i).type;
129 type = Palete.Gir.fqtypeLookup(type, ns);
131 var val = this.toValue(pack[i].strip(), type);
133 print("skip (failed to transform value %s type = %s from %s\n",
134 cls + "." + k, type, pack[i].strip());
137 print ("pack:set_property ( %s , %s / %s)\n", k, pack[i].strip(), val.strdup_contents());
139 ((global::Gtk.Container)parent).child_set_property((global::Gtk.Widget)ret, k, val);
151 var cls_gir =Palete.Gir.factoryFqn(this.node.fqn());
153 //var id = this.node.uid();
154 //var ret = @"$pad<object class=\"$cls\" id=\"$id\">\n";
156 var props = cls_gir.props;
159 var pviter = props.map_iterator();
160 while (pviter.next()) {
162 // print("Check: " +cls + "::(" + pviter.get_value().propertyof + ")" + pviter.get_key() + " " );
163 var k = pviter.get_key();
164 // skip items we have already handled..
165 if (!this.node.has(k)) {
168 // find out the type of the property...
169 var type = pviter.get_value().type;
170 type = Palete.Gir.fqtypeLookup(type, ns);
172 var val = this.toValue(this.node.get(k).strip(), type);
174 print("skip (failed to transform value %s type = %s from %s\n",
175 cls + "." + k, type, this.node.get(k).strip());
178 print ("set_property ( %s , %s / %s)\n", k, this.node.get(k).strip(), val.strdup_contents());
181 ret.set_property(k, val);
186 // for now... - just try the builder style packing
190 if (this.node.items.size < 1) {
194 for (var i = 0; i < this.node.items.size; i++ ) {
196 this.mungeChild(this.node.items.get(i));
207 public GLib.Value? toValue(string val, string type) {
209 var gtkbuilder = new global::Gtk.Builder();
211 if (type == "utf8") {
212 var qret = new GLib.Value(typeof(string));
213 qret.set_string(val);
217 var prop_gtype = gtkbuilder.get_type_from_name(type);
220 if (prop_gtype == GLib.Type.INVALID) {
226 var ret = new GLib.Value(prop_gtype);
231 ret.set_boolean(val.down() == "false" ? false : true);
234 ret.set_uint(int.parse(val));
238 ret.set_int(int.parse(val));
242 ret.set_float(long.parse(val));
251 var sval =new GLib.Value(typeof(string));
252 sval.set_string(val);
254 if (!sval.transform(ref ret)) {