Index: src_plugins/hid_gtk/gtkhid-main.c =================================================================== --- src_plugins/hid_gtk/gtkhid-main.c (revision 6706) +++ src_plugins/hid_gtk/gtkhid-main.c (revision 6707) @@ -270,189 +270,13 @@ pcb_gtk_dlg_propedit_prop_add(&ghidgui->propedit_dlg, propname, most_common, min, max, avg); } -typedef struct { - GtkWidget *del; - GtkWidget *w_name; - GtkWidget *w_value; -} AttrRow; - -static AttrRow *attr_row = 0; -static int attr_num_rows = 0; -static int attr_max_rows = 0; -static pcb_attribute_list_t *attributes_list; -static GtkWidget *attributes_dialog, *attr_table; - -static void attributes_delete_callback(GtkWidget * w, void *v); - -#define GA_RESPONSE_REVERT 1 -#define GA_RESPONSE_NEW 2 - -static void ghid_attr_set_table_size() +static void ghid_attributes(const char *owner, pcb_attribute_list_t * attrs) { - gtk_table_resize(GTK_TABLE(attr_table), attr_num_rows > 0 ? attr_num_rows : 1, 3); + pcb_gtk_dlg_attributes(ghid_port.top_window, owner, attrs); } -static void ghid_attributes_need_rows(int new_max) -{ - if (attr_max_rows < new_max) { - if (attr_row) - attr_row = (AttrRow *) realloc(attr_row, new_max * sizeof(AttrRow)); - else - attr_row = (AttrRow *) malloc(new_max * sizeof(AttrRow)); - } - while (attr_max_rows < new_max) { - /* add [attr_max_rows] */ - attr_row[attr_max_rows].del = gtk_button_new_with_label("del"); - gtk_table_attach(GTK_TABLE(attr_table), attr_row[attr_max_rows].del, - 0, 1, attr_max_rows, attr_max_rows + 1, (GtkAttachOptions) (GTK_FILL | GTK_EXPAND), GTK_FILL, 0, 0); - g_signal_connect(G_OBJECT(attr_row[attr_max_rows].del), "clicked", - G_CALLBACK(attributes_delete_callback), GINT_TO_POINTER(attr_max_rows)); - attr_row[attr_max_rows].w_name = gtk_entry_new(); - gtk_table_attach(GTK_TABLE(attr_table), attr_row[attr_max_rows].w_name, - 1, 2, attr_max_rows, attr_max_rows + 1, (GtkAttachOptions) (GTK_FILL | GTK_EXPAND), GTK_FILL, 0, 0); - attr_row[attr_max_rows].w_value = gtk_entry_new(); - gtk_table_attach(GTK_TABLE(attr_table), attr_row[attr_max_rows].w_value, - 2, 3, attr_max_rows, attr_max_rows + 1, (GtkAttachOptions) (GTK_FILL | GTK_EXPAND), GTK_FILL, 0, 0); - - attr_max_rows++; - } - - /* Manage any previously unused rows we now need to show. */ - while (attr_num_rows < new_max) { - /* manage attr_num_rows */ - gtk_widget_show(attr_row[attr_num_rows].del); - gtk_widget_show(attr_row[attr_num_rows].w_name); - gtk_widget_show(attr_row[attr_num_rows].w_value); - attr_num_rows++; - } -} - -static void ghid_attributes_revert() -{ - int i; - - ghid_attributes_need_rows(attributes_list->Number); - - /* Unmanage any previously used rows we don't need. */ - while (attr_num_rows > attributes_list->Number) { - attr_num_rows--; - gtk_widget_hide(attr_row[attr_num_rows].del); - gtk_widget_hide(attr_row[attr_num_rows].w_name); - gtk_widget_hide(attr_row[attr_num_rows].w_value); - } - - /* Fill in values */ - for (i = 0; i < attributes_list->Number; i++) { - /* create row [i] */ - gtk_entry_set_text(GTK_ENTRY(attr_row[i].w_name), attributes_list->List[i].name); - gtk_entry_set_text(GTK_ENTRY(attr_row[i].w_value), attributes_list->List[i].value); -#if 0 -#endif - } - ghid_attr_set_table_size(); -} - -static void attributes_delete_callback(GtkWidget * w, void *v) -{ - int i, n; - - n = GPOINTER_TO_INT(v); - - for (i = n; i < attr_num_rows - 1; i++) { - gtk_entry_set_text(GTK_ENTRY(attr_row[i].w_name), gtk_entry_get_text(GTK_ENTRY(attr_row[i + 1].w_name))); - gtk_entry_set_text(GTK_ENTRY(attr_row[i].w_value), gtk_entry_get_text(GTK_ENTRY(attr_row[i + 1].w_value))); - } - attr_num_rows--; - - gtk_widget_hide(attr_row[attr_num_rows].del); - gtk_widget_hide(attr_row[attr_num_rows].w_name); - gtk_widget_hide(attr_row[attr_num_rows].w_value); - - ghid_attr_set_table_size(); -} - -static void ghid_attributes(const char *owner, pcb_attribute_list_t * attrs) -{ - GtkWidget *content_area; - int response; - - attributes_list = attrs; - - attr_max_rows = 0; - attr_num_rows = 0; - - attributes_dialog = gtk_dialog_new_with_buttons(owner, - GTK_WINDOW(ghid_port.top_window), - GTK_DIALOG_MODAL, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - "Revert", GA_RESPONSE_REVERT, - "New", GA_RESPONSE_NEW, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); - - attr_table = gtk_table_new(attrs->Number, 3, 0); - - content_area = gtk_dialog_get_content_area(GTK_DIALOG(attributes_dialog)); - gtk_box_pack_start(GTK_BOX(content_area), attr_table, FALSE, FALSE, 0); - - gtk_widget_show(attr_table); - - ghid_attributes_revert(); - - while (1) { - response = gtk_dialog_run(GTK_DIALOG(attributes_dialog)); - - if (response == GTK_RESPONSE_CANCEL) - break; - - if (response == GTK_RESPONSE_OK) { - int i; - /* Copy the values back */ - for (i = 0; i < attributes_list->Number; i++) { - if (attributes_list->List[i].name) - free(attributes_list->List[i].name); - if (attributes_list->List[i].value) - free(attributes_list->List[i].value); - } - if (attributes_list->Max < attr_num_rows) { - int sz = attr_num_rows * sizeof(pcb_attribute_t); - if (attributes_list->List == NULL) - attributes_list->List = (pcb_attribute_t *) malloc(sz); - else - attributes_list->List = (pcb_attribute_t *) realloc(attributes_list->List, sz); - attributes_list->Max = attr_num_rows; - } - for (i = 0; i < attr_num_rows; i++) { - attributes_list->List[i].name = pcb_strdup(gtk_entry_get_text(GTK_ENTRY(attr_row[i].w_name))); - attributes_list->List[i].value = pcb_strdup(gtk_entry_get_text(GTK_ENTRY(attr_row[i].w_value))); - attributes_list->Number = attr_num_rows; - } - - break; - } - - if (response == GA_RESPONSE_REVERT) { - /* Revert */ - ghid_attributes_revert(); - } - - if (response == GA_RESPONSE_NEW) { - ghid_attributes_need_rows(attr_num_rows + 1); /* also bumps attr_num_rows */ - - gtk_entry_set_text(GTK_ENTRY(attr_row[attr_num_rows - 1].w_name), ""); - gtk_entry_set_text(GTK_ENTRY(attr_row[attr_num_rows - 1].w_value), ""); - - ghid_attr_set_table_size(); - } - } - - gtk_widget_destroy(attributes_dialog); - free(attr_row); - attr_row = NULL; -} - -/* ---------------------------------------------------------------------- */ - pcb_hid_drc_gui_t ghid_drc_gui = { 1, /* log_drc_overview */ 0, /* log_drc_details */ Index: src_plugins/lib_gtk_common/dlg_attribute.c =================================================================== --- src_plugins/lib_gtk_common/dlg_attribute.c (revision 6706) +++ src_plugins/lib_gtk_common/dlg_attribute.c (revision 6707) @@ -316,3 +316,182 @@ return rc; } + +typedef struct { + GtkWidget *del; + GtkWidget *w_name; + GtkWidget *w_value; +} AttrRow; + +static AttrRow *attr_row = 0; +static int attr_num_rows = 0; +static int attr_max_rows = 0; +static pcb_attribute_list_t *attributes_list; +static GtkWidget *attributes_dialog, *attr_table; + +static void attributes_delete_callback(GtkWidget * w, void *v); + +#define GA_RESPONSE_REVERT 1 +#define GA_RESPONSE_NEW 2 + +static void ghid_attr_set_table_size() +{ + gtk_table_resize(GTK_TABLE(attr_table), attr_num_rows > 0 ? attr_num_rows : 1, 3); +} + +static void ghid_attributes_need_rows(int new_max) +{ + if (attr_max_rows < new_max) { + if (attr_row) + attr_row = (AttrRow *) realloc(attr_row, new_max * sizeof(AttrRow)); + else + attr_row = (AttrRow *) malloc(new_max * sizeof(AttrRow)); + } + while (attr_max_rows < new_max) { + /* add [attr_max_rows] */ + attr_row[attr_max_rows].del = gtk_button_new_with_label("del"); + gtk_table_attach(GTK_TABLE(attr_table), attr_row[attr_max_rows].del, + 0, 1, attr_max_rows, attr_max_rows + 1, (GtkAttachOptions) (GTK_FILL | GTK_EXPAND), GTK_FILL, 0, 0); + g_signal_connect(G_OBJECT(attr_row[attr_max_rows].del), "clicked", + G_CALLBACK(attributes_delete_callback), GINT_TO_POINTER(attr_max_rows)); + + attr_row[attr_max_rows].w_name = gtk_entry_new(); + gtk_table_attach(GTK_TABLE(attr_table), attr_row[attr_max_rows].w_name, + 1, 2, attr_max_rows, attr_max_rows + 1, (GtkAttachOptions) (GTK_FILL | GTK_EXPAND), GTK_FILL, 0, 0); + + attr_row[attr_max_rows].w_value = gtk_entry_new(); + gtk_table_attach(GTK_TABLE(attr_table), attr_row[attr_max_rows].w_value, + 2, 3, attr_max_rows, attr_max_rows + 1, (GtkAttachOptions) (GTK_FILL | GTK_EXPAND), GTK_FILL, 0, 0); + + attr_max_rows++; + } + + /* Manage any previously unused rows we now need to show. */ + while (attr_num_rows < new_max) { + /* manage attr_num_rows */ + gtk_widget_show(attr_row[attr_num_rows].del); + gtk_widget_show(attr_row[attr_num_rows].w_name); + gtk_widget_show(attr_row[attr_num_rows].w_value); + attr_num_rows++; + } +} + +static void ghid_attributes_revert() +{ + int i; + + ghid_attributes_need_rows(attributes_list->Number); + + /* Unmanage any previously used rows we don't need. */ + while (attr_num_rows > attributes_list->Number) { + attr_num_rows--; + gtk_widget_hide(attr_row[attr_num_rows].del); + gtk_widget_hide(attr_row[attr_num_rows].w_name); + gtk_widget_hide(attr_row[attr_num_rows].w_value); + } + + /* Fill in values */ + for (i = 0; i < attributes_list->Number; i++) { + /* create row [i] */ + gtk_entry_set_text(GTK_ENTRY(attr_row[i].w_name), attributes_list->List[i].name); + gtk_entry_set_text(GTK_ENTRY(attr_row[i].w_value), attributes_list->List[i].value); + } + ghid_attr_set_table_size(); +} + +static void attributes_delete_callback(GtkWidget * w, void *v) +{ + int i, n; + + n = GPOINTER_TO_INT(v); + + for (i = n; i < attr_num_rows - 1; i++) { + gtk_entry_set_text(GTK_ENTRY(attr_row[i].w_name), gtk_entry_get_text(GTK_ENTRY(attr_row[i + 1].w_name))); + gtk_entry_set_text(GTK_ENTRY(attr_row[i].w_value), gtk_entry_get_text(GTK_ENTRY(attr_row[i + 1].w_value))); + } + attr_num_rows--; + + gtk_widget_hide(attr_row[attr_num_rows].del); + gtk_widget_hide(attr_row[attr_num_rows].w_name); + gtk_widget_hide(attr_row[attr_num_rows].w_value); + + ghid_attr_set_table_size(); +} + +void pcb_gtk_dlg_attributes(GtkWidget *top_window, const char *owner, pcb_attribute_list_t * attrs) +{ + GtkWidget *content_area; + int response; + + attributes_list = attrs; + + attr_max_rows = 0; + attr_num_rows = 0; + + attributes_dialog = gtk_dialog_new_with_buttons(owner, + GTK_WINDOW(top_window), + GTK_DIALOG_MODAL, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + "Revert", GA_RESPONSE_REVERT, + "New", GA_RESPONSE_NEW, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); + + attr_table = gtk_table_new(attrs->Number, 3, 0); + + content_area = gtk_dialog_get_content_area(GTK_DIALOG(attributes_dialog)); + gtk_box_pack_start(GTK_BOX(content_area), attr_table, FALSE, FALSE, 0); + + gtk_widget_show(attr_table); + + ghid_attributes_revert(); + + while (1) { + response = gtk_dialog_run(GTK_DIALOG(attributes_dialog)); + + if (response == GTK_RESPONSE_CANCEL) + break; + + if (response == GTK_RESPONSE_OK) { + int i; + /* Copy the values back */ + for (i = 0; i < attributes_list->Number; i++) { + if (attributes_list->List[i].name) + free(attributes_list->List[i].name); + if (attributes_list->List[i].value) + free(attributes_list->List[i].value); + } + if (attributes_list->Max < attr_num_rows) { + int sz = attr_num_rows * sizeof(pcb_attribute_t); + if (attributes_list->List == NULL) + attributes_list->List = (pcb_attribute_t *) malloc(sz); + else + attributes_list->List = (pcb_attribute_t *) realloc(attributes_list->List, sz); + attributes_list->Max = attr_num_rows; + } + for (i = 0; i < attr_num_rows; i++) { + attributes_list->List[i].name = pcb_strdup(gtk_entry_get_text(GTK_ENTRY(attr_row[i].w_name))); + attributes_list->List[i].value = pcb_strdup(gtk_entry_get_text(GTK_ENTRY(attr_row[i].w_value))); + attributes_list->Number = attr_num_rows; + } + + break; + } + + if (response == GA_RESPONSE_REVERT) { + /* Revert */ + ghid_attributes_revert(); + } + + if (response == GA_RESPONSE_NEW) { + ghid_attributes_need_rows(attr_num_rows + 1); /* also bumps attr_num_rows */ + + gtk_entry_set_text(GTK_ENTRY(attr_row[attr_num_rows - 1].w_name), ""); + gtk_entry_set_text(GTK_ENTRY(attr_row[attr_num_rows - 1].w_value), ""); + + ghid_attr_set_table_size(); + } + } + + gtk_widget_destroy(attributes_dialog); + free(attr_row); + attr_row = NULL; +} Index: src_plugins/lib_gtk_common/dlg_attribute.h =================================================================== --- src_plugins/lib_gtk_common/dlg_attribute.h (revision 6706) +++ src_plugins/lib_gtk_common/dlg_attribute.h (revision 6707) @@ -3,6 +3,8 @@ int ghid_attribute_dialog(GtkWidget *top_window, pcb_hid_attribute_t * attrs, int n_attrs, pcb_hid_attr_val_t * results, const char *title, const char *descr); +void pcb_gtk_dlg_attributes(GtkWidget *top_window, const char *owner, pcb_attribute_list_t * attrs); +