? .anjuta ? .tm_project2.cache ? TODO.tasks ? gob.anjuta ? examples/glb-page.c ? examples/glb-page.h ? examples/my-glade.gob ? examples/my-glade.c ? examples/my-glade.h ? examples/my-glade-private.h ? examples/glb-page.gob Index: ChangeLog =================================================================== RCS file: /cvs/gnome/gob/ChangeLog,v retrieving revision 1.230 diff -u -r1.230 ChangeLog --- ChangeLog 23 Dec 2004 22:43:36 -0000 1.230 +++ ChangeLog 22 May 2005 16:50:03 -0000 @@ -1,3 +1,7 @@ +Sun May 22 18:45:19 2005 gandalfn + * src/check.[ch], src/lexer.l, src/main.[ch], src/parse.y, + src/treefuncs.[ch],src/treefuncs.def: Add liglade support + Thu Dec 23 14:35:12 2004 George Lebl * src/main.[ch], src/lexer.l: Add support for prealloc and add @@ -142,7 +146,7 @@ by tweaking the includes and removing the -W options from AM_CFLAGS as those are supported only by gcc -2003-02-08 Tomasz Kłoczko +2003-02-08 Tomasz KÂłoczko * gob2.m4: Trivial fix: added missing [] quotation macro name defined in AC_DEFUN() (neccessary for aclocal from automake 1.8.x Index: src/checks.c =================================================================== RCS file: /cvs/gnome/gob/src/checks.c,v retrieving revision 1.16 diff -u -r1.16 checks.c --- src/checks.c 31 Mar 2004 01:27:38 -0000 1.16 +++ src/checks.c 22 May 2005 16:50:04 -0000 @@ -676,6 +676,22 @@ return num; } +int +count_glade_widgets (Class *c) +{ + int num = 0; + GList *li; + for (li = c->nodes; li != NULL; li = li->next) { + Node *n = li->data; + if (n->type == VARIABLE_NODE) { + Variable *v = (Variable *)n; + if (v->glade_widget) + num++; + } + } + return num; +} + gboolean find_get_type (Class *c) { Index: src/checks.h =================================================================== RCS file: /cvs/gnome/gob/src/checks.h,v retrieving revision 1.10 diff -u -r1.10 checks.h --- src/checks.h 31 Mar 2004 01:27:38 -0000 1.10 +++ src/checks.h 22 May 2005 16:50:04 -0000 @@ -49,6 +49,7 @@ int count_unreftors (Class *c); int count_destructors (Class *c); int count_initializers (Class *c); +int count_glade_widgets (Class *c); gboolean find_get_type (Class *c); #endif Index: src/lexer.l =================================================================== RCS file: /cvs/gnome/gob/src/lexer.l,v retrieving revision 1.40 diff -u -r1.40 lexer.l --- src/lexer.l 23 Dec 2004 22:43:36 -0000 1.40 +++ src/lexer.l 22 May 2005 16:50:05 -0000 @@ -104,6 +104,7 @@ %x C_CODE %x CODE_STRING %x CLASS_CODE +%x CLASS_STRING %x CLASS_CODE_I %x PROPERTY_CODE %x PROPERTY_CODE_I @@ -473,6 +474,22 @@ } from {return FROM;} +\" { + BEGIN(CLASS_STRING); + before_string = CLASS_CODE; + add_to_cbuf(yytext); + } +\\. { add_to_cbuf(yytext); } +\" { + BEGIN(before_string); + add_to_cbuf(yytext); + yylval.id = cbuf->str; + g_string_free (cbuf, FALSE); + cbuf = NULL; + return STRING; + } +. { add_to_cbuf(yytext); } +\n { add_to_cbuf(yytext); } void {return VOID;} struct {return STRUCT;} @@ -487,6 +504,7 @@ double {return DOUBLE;} char {return CHAR;} const {return CONST;} +GladeWidget {return GLADEWIDGET;} \.\.\. {return THREEDOTS;} Index: src/main.c =================================================================== RCS file: /cvs/gnome/gob/src/main.c,v retrieving revision 1.127 diff -u -r1.127 main.c --- src/main.c 23 Dec 2004 22:43:36 -0000 1.127 +++ src/main.c 22 May 2005 16:50:12 -0000 @@ -77,6 +77,7 @@ static int unreftors = 0; /* number of variable unreffing destructors */ static int destructors = 0; /* number of variable non-unreffing destructors */ static int initializers = 0; /* number of variable initializers */ +static int glade_widgets = 0; /* number of glade widgets */ static gboolean overrode_get_type = FALSE; /* provided your won _get_type */ static gboolean made_aliases = FALSE; /* if we made any shorthand aliases @@ -2025,8 +2026,11 @@ if(v->initializer_line > 0) out_addline_infile(out, v->initializer_line); - out_printf(out, "\t%s->%s = %s;\n", + if (v->initializer_simple) + out_printf(out, "\t%s->%s = %s;\n", root, v->id, v->initializer); + else + out_printf(out,v->initializer); if(v->initializer_line > 0) out_addline_outfile(out); @@ -2035,6 +2039,28 @@ } static void +print_glade_widget(Method *m, Variable *v) +{ + char *root; + char *cast; + + if(!v->glade_widget) + return; + + if(v->scope == PRIVATE_SCOPE) + root = g_strconcat(((FuncArg *)m->args->data)->name, + "->_priv", NULL); + else + root = g_strdup(((FuncArg *)m->args->data)->name); + + cast = get_type(v->vtype, FALSE); + out_printf(out, "\t%s->%s = (%s)glade_xml_get_widget(%s->_glade_xml, \"%s\");\n", + root, v->id, cast, root, v->id); + + g_free(root); +} + +static void print_destructor (Variable *v) { const char *root; @@ -2272,6 +2298,19 @@ print_initializer(m, v); } } + if(glade_widgets > 0) { + GList *li; + for(li = ((Class *)class)->nodes; + li != NULL; + li = li->next) { + Node *n = li->data; + Variable *v = (Variable *)n; + if(n->type != VARIABLE_NODE || + v->scope == CLASS_SCOPE) + continue; + print_glade_widget(m, v); + } + } } else if(m->method == CLASS_INIT_METHOD) { gboolean did_base_obj = FALSE; @@ -3258,6 +3297,12 @@ char *s; gboolean printed_private = FALSE; + if (c->glade_xml) + { + out_printf(outph ? outph : outh, "#include \n"); + out_printf(outph ? outph : outh, "#include \n\n"); + } + if(any_special) { out_printf(out, "/* utility types we may need */\n"); if(special_array[SPECIAL_2POINTER]) @@ -3384,16 +3429,19 @@ out_printf (outfp, "struct _%sPrivate {\n", typebase); - for(li=c->nodes; li; li=li->next) { - Node *n = li->data; - Variable *v = (Variable *)n; - if(n->type == VARIABLE_NODE && - v->scope == PRIVATE_SCOPE) { - out_addline_infile(outfp, v->line_no); - put_variable(v, outfp); + if (privates > 0) + { + for(li=c->nodes; li; li=li->next) { + Node *n = li->data; + Variable *v = (Variable *)n; + if(n->type == VARIABLE_NODE && + v->scope == PRIVATE_SCOPE) { + out_addline_infile(outfp, v->line_no); + put_variable(v, outfp); + } } + out_addline_outfile(outfp); } - out_addline_outfile(outfp); out_printf(outfp, "};\n"); } @@ -3539,6 +3587,44 @@ no_gnu ? "" : " G_GNUC_UNUSED", typebase, typebase, typebase, funcbase); + if (c->glade_xml) + { + out_printf (out, "/* a function to connect glade callback */\n"); + out_printf (out,"static void\n" + "___glade_xml_connect_foreach(const gchar *handler_name,\n" + "GObject *object,\n" + "const gchar *signal_name,\n" + "const gchar *signal_data,\n" + "GObject *connect_object,\n" + "gboolean after,\n" + "gpointer user_data)\n" + "{\n" + "\tstatic GModule * allsymbols = NULL;\n" + " \n" + "\tif (!allsymbols) allsymbols = g_module_open(NULL, 0);\n" + "\tif (allsymbols)\n" + "\t{\n" + "\t\tgchar * func_name = g_strdup_printf(\"%s_%%s\", handler_name);\n" + "\t\tGCallback func;\n" + "\n" + "\t\tif (!g_module_symbol(allsymbols, func_name, (gpointer)&func)){\n" + "\t\t\tif (!g_module_symbol(allsymbols, handler_name, (gpointer)&func)) {\n" + "\t\t\t\tg_warning(\"could not find signal handler '%%s'.\", func_name);\n" + "\t\t\t\tg_free(func_name);\n" + "\t\t\t\treturn;\n" + "\t\t\t}\n" + "\t\t}\n" + "\t\tif (after)\n" + "\t\t\tg_signal_connect_data(object, signal_name, func, user_data, NULL, G_CONNECT_AFTER | G_CONNECT_SWAPPED);\n" + "\t\telse\n" + "\t\t\tg_signal_connect_data(object, signal_name, func, user_data, NULL, G_CONNECT_SWAPPED);\n" + "\t\tg_free(func_name);\n" + "\t}\n" + "}\n" + "\n", + funcbase); + } + if (need_dispose) add_dispose (c); @@ -4291,6 +4377,7 @@ unreftors = count_unreftors ((Class *)class); destructors = count_destructors ((Class *)class); initializers = count_initializers ((Class *)class); + glade_widgets = count_glade_widgets ((Class *)class); overrode_get_type = find_get_type ((Class *)class); make_bases (); Index: src/parse.y =================================================================== RCS file: /cvs/gnome/gob/src/parse.y,v retrieving revision 1.65 diff -u -r1.65 parse.y --- src/parse.y 23 Sep 2004 00:21:23 -0000 1.65 +++ src/parse.y 22 May 2005 16:50:15 -0000 @@ -46,6 +46,7 @@ static char *chunk_size = NULL; static char *bonobo_object_class = NULL; +static int glade_xml = FALSE; static GList *interfaces = NULL; static GList *typestack = NULL; static GList *funcargs = NULL; @@ -61,6 +62,7 @@ static gboolean destructor_simple = TRUE; static char *initializer = NULL; static int initializer_line = 0; +static int glade_widget = FALSE; static char *onerror = NULL; static char *defreturn = NULL; @@ -126,6 +128,7 @@ var = node_new (VARIABLE_NODE, "scope", scope, "vtype:steal", type, + "glade_widget", glade_widget, "id:steal", name, "line_no", line_no, "destructor_unref", destructor_unref, @@ -134,8 +137,10 @@ "destructor_simple", destructor_simple, "initializer:steal", initializer, "initializer_line", initializer_line, + "initializer_simple", TRUE, NULL); class_nodes = g_list_append(class_nodes, var); + glade_widget = FALSE; } static void @@ -463,6 +468,41 @@ } static void +add_construct_glade (char * file, char * root, char * domain) +{ + Node *var; + Type * type; + GList * flags = NULL; + char * set; + + type = (Type *)node_new (TYPE_NODE, + "name", "GladeXML", + "pointer", "*", + NULL); + initializer = g_strdup_printf("\t{\n" + "\tGtkWidget * root;\n" + "\to->_priv->_glade_xml = glade_xml_new(%s, %s, %s);\n" + "\troot = glade_xml_get_widget(o->_priv->_glade_xml, %s);\n" + "\tgtk_widget_show(root);\n" + "\tgtk_container_add(GTK_CONTAINER(o), root);\n" + "\tglade_xml_signal_autoconnect_full(o->_priv->_glade_xml, (GladeXMLConnectFunc)___glade_xml_connect_foreach, (gpointer)o);\n" + "}\n", file, root, domain ? domain : "NULL", root); + + var = node_new (VARIABLE_NODE, + "scope", PRIVATE_SCOPE, + "vtype:steal", type, + "glade_widget", FALSE, + "id:steal", "_glade_xml", + "destructor_unref", FALSE, + "destructor", "g_object_unref", + "destructor_simple", TRUE, + "initializer", initializer, + "initializer_simple", FALSE, + NULL); + class_nodes = g_list_prepend(class_nodes, var); +} + +static void property_link_and_export (Node *node) { Property *prop = (Property *)node; @@ -635,7 +675,7 @@ %token CLASS FROM %token CONST VOID STRUCT UNION ENUM THREEDOTS -%token SIGNED UNSIGNED LONG SHORT INT FLOAT DOUBLE CHAR +%token SIGNED UNSIGNED LONG SHORT INT FLOAT DOUBLE CHAR GLADEWIDGET %token TOKEN NUMBER TYPETOKEN ARRAY_DIM SINGLE_CHAR %token CCODE HTCODE PHCODE HCODE ACODE ATCODE STRING @@ -735,10 +775,12 @@ "otype:steal", $2, "ptype:steal", $4, "bonobo_object_class:steal", bonobo_object_class, + "glade_xml", glade_xml, "interfaces:steal", interfaces, "chunk_size:steal", chunk_size, NULL); bonobo_object_class = NULL; + glade_xml = FALSE; chunk_size = NULL; interfaces = NULL; } @@ -778,6 +820,24 @@ YYERROR; } } + | '(' TOKEN STRING STRING ')' classflags { + if (strcmp ($2, "GladeXML") == 0) { + glade_xml = TRUE; + add_construct_glade($3, $4, NULL); + } else { + yyerror(_("parse error")); + YYERROR; + } + } + | '(' TOKEN STRING STRING STRING ')' classflags { + if (strcmp ($2, "GladeXML") == 0) { + glade_xml = TRUE; + add_construct_glade($3, $4, $5); + } else { + yyerror(_("parse error")); + YYERROR; + } + } ; classcode: classcode thing { ; } @@ -1481,6 +1541,12 @@ | DOUBLE { $$ = "double"; } | SIGNED { $$ = "signed"; } | UNSIGNED { $$ = "unsigned"; } + | ARRAY_DIM { char * tmp = g_strdup($1 + 1); + tmp[strlen(tmp) - 1] = '\0'; + $$ = g_strdup_printf("Gtk%s *", tmp); + g_free(tmp); + glade_widget = TRUE; + } ; strunionenum: STRUCT { $$ = "struct"; } Index: src/treefuncs.c =================================================================== RCS file: /cvs/gnome/gob/src/treefuncs.c,v retrieving revision 1.10 diff -u -r1.10 treefuncs.c --- src/treefuncs.c 10 Aug 2004 23:41:05 -0000 1.10 +++ src/treefuncs.c 22 May 2005 16:50:18 -0000 @@ -98,6 +98,7 @@ QUARK_ptype_STEAL, QUARK_bonobo_object_class, QUARK_bonobo_object_class_STEAL, + QUARK_glade_xml, QUARK_chunk_size, QUARK_chunk_size_STEAL, QUARK_interfaces, @@ -168,6 +169,7 @@ QUARK_interface_STEAL, QUARK_vtype, QUARK_vtype_STEAL, + QUARK_glade_widget, QUARK_destructor_unref, QUARK_destructor, QUARK_destructor_STEAL, @@ -176,6 +178,7 @@ QUARK_initializer, QUARK_initializer_STEAL, QUARK_initializer_line, + QUARK_initializer_simple, QUARK_etype, QUARK_etype_STEAL, QUARK_prefix, @@ -202,6 +205,7 @@ g_hash_table_insert (quark_ht, "ptype:steal", GINT_TO_POINTER (QUARK_ptype_STEAL)); g_hash_table_insert (quark_ht, "bonobo_object_class", GINT_TO_POINTER (QUARK_bonobo_object_class)); g_hash_table_insert (quark_ht, "bonobo_object_class:steal", GINT_TO_POINTER (QUARK_bonobo_object_class_STEAL)); + g_hash_table_insert (quark_ht, "glade_xml", GINT_TO_POINTER (QUARK_glade_xml)); g_hash_table_insert (quark_ht, "chunk_size", GINT_TO_POINTER (QUARK_chunk_size)); g_hash_table_insert (quark_ht, "chunk_size:steal", GINT_TO_POINTER (QUARK_chunk_size_STEAL)); g_hash_table_insert (quark_ht, "interfaces", GINT_TO_POINTER (QUARK_interfaces)); @@ -272,6 +276,7 @@ g_hash_table_insert (quark_ht, "interface:steal", GINT_TO_POINTER (QUARK_interface_STEAL)); g_hash_table_insert (quark_ht, "vtype", GINT_TO_POINTER (QUARK_vtype)); g_hash_table_insert (quark_ht, "vtype:steal", GINT_TO_POINTER (QUARK_vtype_STEAL)); + g_hash_table_insert (quark_ht, "glade_widget", GINT_TO_POINTER (QUARK_glade_widget)); g_hash_table_insert (quark_ht, "destructor_unref", GINT_TO_POINTER (QUARK_destructor_unref)); g_hash_table_insert (quark_ht, "destructor", GINT_TO_POINTER (QUARK_destructor)); g_hash_table_insert (quark_ht, "destructor:steal", GINT_TO_POINTER (QUARK_destructor_STEAL)); @@ -280,6 +285,7 @@ g_hash_table_insert (quark_ht, "initializer", GINT_TO_POINTER (QUARK_initializer)); g_hash_table_insert (quark_ht, "initializer:steal", GINT_TO_POINTER (QUARK_initializer_STEAL)); g_hash_table_insert (quark_ht, "initializer_line", GINT_TO_POINTER (QUARK_initializer_line)); + g_hash_table_insert (quark_ht, "initializer_simple", GINT_TO_POINTER (QUARK_initializer_simple)); g_hash_table_insert (quark_ht, "etype", GINT_TO_POINTER (QUARK_etype)); g_hash_table_insert (quark_ht, "etype:steal", GINT_TO_POINTER (QUARK_etype_STEAL)); g_hash_table_insert (quark_ht, "prefix", GINT_TO_POINTER (QUARK_prefix)); @@ -350,6 +356,7 @@ new->otype = g_strdup (self->otype); new->ptype = g_strdup (self->ptype); new->bonobo_object_class = g_strdup (self->bonobo_object_class); + new->glade_xml = self->glade_xml; new->chunk_size = g_strdup (self->chunk_size); new->interfaces = g_list_copy (self->interfaces); COPY_LIST_VALS(new->interfaces, g_strdup); new->nodes = node_list_copy (self->nodes); @@ -506,6 +513,7 @@ new->type = VARIABLE_NODE; new->scope = self->scope; new->vtype = copy_type (self->vtype); + new->glade_widget = self->glade_widget; new->id = g_strdup (self->id); new->line_no = self->line_no; new->destructor_unref = self->destructor_unref; @@ -514,6 +522,7 @@ new->destructor_simple = self->destructor_simple; new->initializer = g_strdup (self->initializer); new->initializer_line = self->initializer_line; + new->initializer_simple = self->initializer_simple; return new; } @@ -897,6 +906,11 @@ self->bonobo_object_class = bonobo_object_class; break; } + case QUARK_glade_xml: { + gboolean glade_xml = va_arg (__ap, gboolean); + self->glade_xml = glade_xml; + break; + } case QUARK_chunk_size: { char * chunk_size = va_arg (__ap, char *); char * __old_value = self->chunk_size; @@ -1627,6 +1641,11 @@ self->vtype = vtype; break; } + case QUARK_glade_widget: { + gboolean glade_widget = va_arg (__ap, gboolean); + self->glade_widget = glade_widget; + break; + } case QUARK_id: { char * id = va_arg (__ap, char *); char * __old_value = self->id; @@ -1688,6 +1707,11 @@ self->initializer_line = initializer_line; break; } + case QUARK_initializer_simple: { + gboolean initializer_simple = va_arg (__ap, gboolean); + self->initializer_simple = initializer_simple; + break; + } default: g_warning ("Argument named 'Variable::%s' does not exist", arg); break; Index: src/treefuncs.def =================================================================== RCS file: /cvs/gnome/gob/src/treefuncs.def,v retrieving revision 1.11 diff -u -r1.11 treefuncs.def --- src/treefuncs.def 10 Aug 2004 23:41:06 -0000 1.11 +++ src/treefuncs.def 22 May 2005 16:50:18 -0000 @@ -52,6 +52,7 @@ STRING otype # this object class type STRING ptype # parent class type STRING bonobo_object_class # Class for BonoboObject + BOOL glade_xml # Glade XML Class STRING chunk_size # if the object should be allocated with mem_chunks STRINGLIST interfaces # GObject interfaces this class exports NODELIST nodes @@ -130,12 +131,13 @@ BOOL vararg INT unique_id # A unique id for new methods BOOL bonobo_object_func # Function for BonoboObject - STRING interface # interface this belongs to + STRING interface # interface this belongs to ENDCLASS CLASS Variable INT scope TYPE vtype + BOOL glade_widget STRING id INT line_no BOOL destructor_unref @@ -144,6 +146,7 @@ BOOL destructor_simple STRING initializer INT initializer_line + BOOL initializer_simple ENDCLASS CLASS EnumDef Index: src/treefuncs.h =================================================================== RCS file: /cvs/gnome/gob/src/treefuncs.h,v retrieving revision 1.11 diff -u -r1.11 treefuncs.h --- src/treefuncs.h 10 Aug 2004 23:41:06 -0000 1.11 +++ src/treefuncs.h 22 May 2005 16:50:19 -0000 @@ -114,6 +114,7 @@ char * otype; char * ptype; char * bonobo_object_class; + gboolean glade_xml; char * chunk_size; GList * interfaces; GList * nodes; @@ -207,6 +208,7 @@ NodeType type; int scope; Type * vtype; + gboolean glade_widget; char * id; int line_no; gboolean destructor_unref; @@ -215,6 +217,7 @@ gboolean destructor_simple; char * initializer; int initializer_line; + gboolean initializer_simple; }; union _Node {