I need to be able to act on labels texts, lists contents, buttons states... on external events. There is no way for now to access the required widgets, so I added one. The patch adds a "Visibility" C property which can either "static" or "extern". "static" is the good old way. "extern" adds a extern GtkWidget *blah; in the interface.h file, and a GtkWidget *blah; in the interface.c file. OG.
diff -ru glade-0.5.7/glade/gbsource.c glade-new/glade/gbsource.c --- glade-0.5.7/glade/gbsource.c Sun Nov 14 18:01:40 1999 +++ glade-new/glade/gbsource.c Thu Apr 27 02:20:57 2000 @@ -210,11 +210,15 @@ /* FIXME: unfinished. public fields were to be added to the component struct. Private fields would just be declared within the creation function. */ - if (wdata->public_field) + if (data->use_component_struct && wdata->public_field) source_add_decl (data, " GtkWidget *%s;\n", data->real_wname); - else + else if(wdata->c_visibility == 0) source_add_decl (data, " GtkWidget *%s;\n", data->real_wname); - + else + { + source_add_src_globals (data, "GtkWidget *%s;\n", data->real_wname); + source_add_hdr_globals (data, "extern GtkWidget *%s;\n", data->real_wname); + } if (data->set_widget_names) source_add (data, " gtk_widget_set_name (%s, \"%s\");\n", data->wname, data->real_wname); diff -ru glade-0.5.7/glade/gbsource.h glade-new/glade/gbsource.h --- glade-0.5.7/glade/gbsource.h Sun Oct 10 16:24:06 1999 +++ glade-new/glade/gbsource.h Thu Apr 27 02:14:50 2000 @@ -23,28 +23,27 @@ #endif /* __cplusplus */ -/* These identify each of the source code buffers. New buffers can easily be - added by increasing GLADE_NUM_SOURCE_BUFFERS and adding an id here. */ -#define GLADE_NUM_SOURCE_BUFFERS 7 +/* These identify each of the source code buffers. New buffers can easily by + adding an id here. */ typedef enum { - GLADE_UIINFO = 0, /* GnomeUIInfo structs, which are - output before the function as - static structs. */ - GLADE_DECLARATIONS = 1, /* The declarations of the widgets - and temporary variables in the - function to create a component. */ - GLADE_SOURCE = 2, /* The main code which creates the - widgets in a component. */ - GLADE_SIGNAL_CONNECTIONS = 3, /* Code to connect signal handlers. */ - GLADE_ACCELERATORS = 4, /* Code to setup accelerator keys, used - when the target widget is different - from the source (i.e. the label). */ + GLADE_SOURCE_GLOBALS, /* Global structs and declarations in the .c +file. */ + GLADE_HEADER_GLOBALS, /* Global structs and declarations in the .h +file. */ + GLADE_DECLARATIONS, /* The declarations of the widgets + and temporary variables in the + function to create a component. */ + GLADE_SOURCE, /* The main code which creates the + widgets in a component. */ + GLADE_SIGNAL_CONNECTIONS, /* Code to connect signal handlers. */ + GLADE_ACCELERATORS, /* Code to setup accelerator keys, used + when the target widget is different + from the source (i.e. the label). */ - GLADE_CALLBACK_DECLARATIONS = 5, /* Declarations of signal handler - functions and callbacks. */ - GLADE_CALLBACK_SOURCE = 6 /* Source code of signal handlers or - callbacks. */ + GLADE_CALLBACK_DECLARATIONS, /* Declarations of signal handler + functions and callbacks. */ + GLADE_CALLBACK_SOURCE, /* Source code of signal handlers or + callbacks. */ + GLADE_NUM_SOURCE_BUFFERS } GladeSourceBuffer; diff -ru glade-0.5.7/glade/gbwidget.c glade-new/glade/gbwidget.c --- glade-0.5.7/glade/gbwidget.c Thu Feb 3 07:41:44 2000 +++ glade-new/glade/gbwidget.c Thu Apr 27 01:22:30 2000 @@ -463,6 +463,7 @@ /* C options. */ widget_data->source_file = NULL; widget_data->public_field = 1; + widget_data->c_visibility = 0; /* C++ options. */ widget_data->cxx_separate_file = 0; @@ -2986,6 +2987,13 @@ gb_widget_output_filename (data, GbCSourceFile, wdata->source_file); if (action != GB_SAVING || wdata->public_field == 0) gb_widget_output_bool (data, GbCPublic, wdata->public_field); + if (action != GB_SAVING || wdata->c_visibility != 0) + for (i = 0; GbCVisibilityChoices[i]; i++) + { + if (GbCVisibilityValues[i] == wdata->c_visibility) + gb_widget_output_choice (data, GbCVisibility, i, + GbCVisibilitySymbols[i]); + } if (data->action == GB_SHOWING) { /* We only want the source file set for toplevel widgets. */ @@ -3019,6 +3027,7 @@ GbWidgetData *wdata = data->widget_data; gchar *filename; gboolean public_field; + gchar *c_visibility; gboolean cxx_separate_file, cxx_use_heap, cxx_separate_class; gchar *cxx_visibility; @@ -3032,6 +3041,19 @@ public_field = gb_widget_input_bool (data, GbCPublic); if (data->apply) wdata->public_field = public_field ? 1 : 0; + c_visibility = gb_widget_input_choice (data, GbCVisibility); + if (data->apply) + { guint i; + for (i = 0; GbCVisibilityChoices[i]; i++) + { + if (!strcmp (c_visibility, GbCVisibilityChoices[i]) + || !strcmp (c_visibility, GbCVisibilitySymbols[i])) + { + wdata->c_visibility = GbCVisibilityValues[i]; + break; + } + } + } /* C++ options. */ cxx_separate_file = gb_widget_input_bool (data, GbCxxSeparateFile); diff -ru glade-0.5.7/glade/gbwidget.h glade-new/glade/gbwidget.h --- glade-0.5.7/glade/gbwidget.h Sat Nov 6 08:16:16 1999 +++ glade-new/glade/gbwidget.h Wed Apr 26 23:07:30 2000 @@ -96,6 +96,7 @@ /* C options. */ gchar *source_file; guint public_field : 1; + guint c_visibility : 1; /* C++ options. */ guint cxx_separate_file : 1; diff -ru glade-0.5.7/glade/property.c glade-new/glade/property.c --- glade-0.5.7/glade/property.c Sun Jan 23 16:53:58 2000 +++ glade-new/glade/property.c Thu Apr 27 01:17:22 2000 @@ -61,6 +61,19 @@ /* C-specific properties. */ const gchar *GbCSourceFile = "GtkWidget::c_source_file"; const gchar *GbCPublic = "GtkWidget::c_public"; +const gchar *GbCVisibility = "GtkWidget::c_visibility"; + +/* C visibility choices data */ +const gchar *GbCVisibilityChoices[] = +{N_("static"), N_("extern"), NULL}; +const gint GbCVisibilityValues[] = +{ 0, 1 +}; +const gchar *GbCVisibilitySymbols[] = +{ + "static", + "extern" +}; /* C++-specific properties. */ const gchar *GbCxxSeparateFile = "GtkWidget::cxx_separate_file"; @@ -68,7 +81,7 @@ const gchar *GbCxxSeparateClass = "GtkWidget::cxx_separate_class"; const gchar *GbCxxVisibility = "GtkWidget::cxx_visibility"; -/* Visibility choices data */ +/* C++ visibility choices data */ const gchar *GbCxxVisibilityChoices[] = {N_("private"), N_("protected"), N_("public"), NULL}; const gint GbCxxVisibilityValues[] = @@ -863,6 +876,9 @@ _("The file to write source code into")); property_add_bool (GbCPublic, _("Public:"), _("If the widget is added to the component's data structure")); + property_add_choice (GbCVisibility, _("Visibility:"), + _("Visibility of widgets. Extern widgets are accessible as +global variables."), + GbCVisibilityChoices); /* Create table for C++-specific properties. */ table = gtk_table_new (3, 3, FALSE); @@ -969,7 +985,7 @@ if (lang_specific_properties[i]) { /* FIXME: show the C language properties when we support them. */ - if (i == language && i != GLADE_LANGUAGE_C) + if (i == language) gtk_widget_show (lang_specific_properties[i]); else gtk_widget_hide (lang_specific_properties[i]); Only in glade-new/glade: property.c~ diff -ru glade-0.5.7/glade/property.h glade-new/glade/property.h --- glade-0.5.7/glade/property.h Thu Sep 23 09:34:45 1999 +++ glade-new/glade/property.h Wed Apr 26 23:12:37 2000 @@ -67,6 +67,11 @@ /* C-specific properties. */ extern const gchar* GbCSourceFile; extern const gchar* GbCPublic; +extern const gchar* GbCVisibility; + +extern const gchar* GbCVisibilityChoices[]; +extern const gint GbCVisibilityValues[]; +extern const gchar* GbCVisibilitySymbols[]; /* C++-specific properties. */ extern const gchar* GbCxxSeparateFile; diff -ru glade-0.5.7/glade/source.c glade-new/glade/source.c --- glade-0.5.7/glade/source.c Sat Feb 19 10:28:51 2000 +++ glade-new/glade/source.c Thu Apr 27 02:15:37 2000 @@ -488,6 +488,9 @@ * Output interface.h */ + /* Output any global structs/declarations. */ + fprintf (interface_h_fp, "%s", data->source_buffers[GLADE_HEADER_GLOBALS]->str); + /* Output the declaration of the function to create the component in the header file. */ fprintf (interface_h_fp, "GtkWidget* create_%s (void);\n", @@ -498,8 +501,8 @@ * Output interface.c */ - /* Output any GnomeUIInfo structs. */ - fprintf (interface_c_fp, "%s", data->source_buffers[GLADE_UIINFO]->str); + /* Output any global structs/declarations. */ + fprintf (interface_c_fp, "%s", data->source_buffers[GLADE_SOURCE_GLOBALS]->str); fprintf (interface_c_fp, "GtkWidget*\n" @@ -2506,7 +2509,7 @@ } -/* Convenience functions to add to the 2 main source buffers, containing +/* Convenience functions to add to the 3 main source buffers, containing the code which creates the widgets and the declarations of the widgets. */ void source_add (GbWidgetWriteSourceData * data, const gchar * fmt, ...) @@ -2526,6 +2529,28 @@ va_start (args, fmt); source_add_to_buffer_v (data, GLADE_DECLARATIONS, fmt, args); + va_end (args); +} + + +void +source_add_src_globals (GbWidgetWriteSourceData * data, const gchar * fmt, ...) +{ + va_list args; + + va_start (args, fmt); + source_add_to_buffer_v (data, GLADE_SOURCE_GLOBALS, fmt, args); + va_end (args); +} + + +void +source_add_hdr_globals (GbWidgetWriteSourceData * data, const gchar * fmt, ...) +{ + va_list args; + + va_start (args, fmt); + source_add_to_buffer_v (data, GLADE_HEADER_GLOBALS, fmt, args); va_end (args); } diff -ru glade-0.5.7/glade/source.h glade-new/glade/source.h --- glade-0.5.7/glade/source.h Wed Sep 1 09:50:34 1999 +++ glade-new/glade/source.h Thu Apr 27 02:15:05 2000 @@ -45,12 +45,18 @@ const gchar *fmt, va_list args); -/* Convenience functions to add to the 2 main source buffers, containing +/* Convenience functions to add to the 4 main source buffers, containing the code which creates the widgets and the declarations of the widgets. */ void source_add (GbWidgetWriteSourceData *data, const gchar *fmt, ...) G_GNUC_PRINTF (2, 3); void source_add_decl (GbWidgetWriteSourceData *data, + const gchar *fmt, + ...) G_GNUC_PRINTF (2, 3); +void source_add_src_globals (GbWidgetWriteSourceData *data, + const gchar *fmt, + ...) G_GNUC_PRINTF (2, 3); +void source_add_hdr_globals (GbWidgetWriteSourceData *data, const gchar *fmt, ...) G_GNUC_PRINTF (2, 3);