Index: work/gtk/propedit.c =================================================================== --- work/gtk/propedit.c (revision 2752) +++ work/gtk/propedit.c (revision 2753) @@ -3,6 +3,9 @@ #include typedef struct { + /* property list */ + GtkWidget *tree; /* property list widget */ + GtkListStore *props; /* list model of properties */ /* value entry */ GtkWidget *entry_val; /* text entry */ @@ -30,17 +33,32 @@ dlg->stock_val = 0; } +static void val_combo_reset(propedit_dialog_t *dlg) +{ + gtk_list_store_clear(dlg->vals); +} -static void add_hdr(GtkWidget *tree, const char *name) +static void val_combo_add(propedit_dialog_t *dlg, const char *val) { - GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); - gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(tree), -1, name, renderer, "text", 0, NULL); + gtk_list_store_insert_with_values(dlg->vals, NULL, -1, 0, val, -1); } +static void prop_add(propedit_dialog_t *dlg, const char *name, const char *common, const char *min, const char *max, const char *avg) +{ + GtkTreeIter i; + gtk_list_store_insert_with_values(dlg->props, &i, -1, 0,name, 1,common, 2,min, 3,max, 4,avg, -1); +} + +static void hdr_add(propedit_dialog_t *dlg, const char *name, int col) +{ + GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); + gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(dlg->tree), -1, name, renderer, "text", col, NULL); +} + int main(int argc, char *argv[]) { static propedit_dialog_t dlg; - GtkWidget *window, *vbox_tree, *vbox_edit, *hbox_win, *label, *tree; + GtkWidget *window, *vbox_tree, *vbox_edit, *hbox_win, *label; gtk_init(&argc, &argv); @@ -62,24 +80,22 @@ label = gtk_label_new("Properies"); gtk_box_pack_start(GTK_BOX(vbox_tree), label, FALSE, FALSE, 4); - tree = gtk_tree_view_new(); - gtk_box_pack_start(GTK_BOX(vbox_tree), tree, FALSE, TRUE, 4); + dlg.tree = gtk_tree_view_new(); + gtk_box_pack_start(GTK_BOX(vbox_tree), dlg.tree, FALSE, TRUE, 4); - GType *ty; - GtkListStore *lm; + GType ty[5]; + int n; - ty = malloc(sizeof(GType) * 5); for(n = 0; n < 5; n++) ty[n] = G_TYPE_STRING; - lm = gtk_list_store_newv(5, ty); - free(ty); - gtk_tree_view_set_model(GTK_TREE_VIEW(tree), GTK_TREE_MODEL(lm)); + dlg.props = gtk_list_store_newv(5, ty); + gtk_tree_view_set_model(GTK_TREE_VIEW(dlg.tree), GTK_TREE_MODEL(dlg.props)); - add_hdr(tree, "property"); - add_hdr(tree, "common"); - add_hdr(tree, "min"); - add_hdr(tree, "max"); - add_hdr(tree, "avg"); + hdr_add(&dlg, "property", 0); + hdr_add(&dlg, "common", 1); + hdr_add(&dlg, "min", 2); + hdr_add(&dlg, "max", 3); + hdr_add(&dlg, "avg", 4); label = gtk_label_new("(preview)"); gtk_box_pack_start(GTK_BOX(vbox_edit), label, TRUE, TRUE, 4); @@ -87,6 +103,9 @@ label = gtk_label_new("Change value"); gtk_box_pack_start(GTK_BOX(vbox_edit), label, FALSE, TRUE, 4); + prop_add(&dlg, "foo/bar", "15", "10", "20", "17.2"); + prop_add(&dlg, "foo/baz", "1", "1", "2", "1.2"); + prop_add(&dlg, "string", "ho", NULL, NULL, NULL); /* value edit */ GtkWidget *hbox_val_edit; @@ -98,8 +117,9 @@ gtk_box_pack_start(GTK_BOX(vbox_edit), hbox_val_edit, FALSE, TRUE, 4); /* combo */ - gtk_list_store_insert_with_values(dlg.vals, NULL, -1, 0, "val0", -1); - gtk_list_store_insert_with_values(dlg.vals, NULL, -1, 0, "val1", -1); + val_combo_reset(&dlg); + val_combo_add(&dlg, "val0"); + val_combo_add(&dlg, "val1"); dlg.val_box = gtk_combo_box_new_with_model(GTK_TREE_MODEL(dlg.vals)); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(dlg.val_box), renderer, TRUE);