/*-- exclusion_ui.c --*/ /* This software may only be used by you under license from AT&T Corp. ("AT&T"). A copy of AT&T's Source Code Agreement is available at AT&T's Internet website having the URL: If you received this software without first entering into a license with AT&T, you have an infringing copy of this software and cannot use it without violating AT&T's intellectual property rights. */ #include #include "vars.h" #include "externs.h" static gint exclusion_symbol_show (GtkWidget *w, GdkEventExpose *event, gpointer cbd) { gint k = GPOINTER_TO_INT (cbd); ggobid *gg = GGobiFromWidget (w, true); icoords pos; glyphv g; datad *d = datad_get_from_notebook (gg->exclusion_ui.notebook, gg); /*-- fill in the background color --*/ gdk_gc_set_foreground (gg->plot_GC, &gg->bg_color); gdk_draw_rectangle (w->window, gg->plot_GC, true, 0, 0, w->allocation.width, w->allocation.height); /*-- draw the appropriate symbol in the appropriate color --*/ gdk_gc_set_foreground (gg->plot_GC, &gg->default_color_table[d->clusv[k].color]); g.type = d->clusv[k].glyphtype; g.size = d->clusv[k].glyphsize; pos.x = w->allocation.width / 2; pos.y = w->allocation.height / 2; draw_glyph (w->window, &g, &pos, 0, gg); return FALSE; } static gint hide_cluster_cb (GtkToggleButton *btn, gpointer cbd) { gint k = GPOINTER_TO_INT (cbd); gint i; ggobid *gg = GGobiFromWidget (GTK_WIDGET (btn), true); datad *d = datad_get_from_notebook (gg->exclusion_ui.notebook, gg); d->clusv[k].hidden = btn->active; for (i=0; inrows; i++) { if (d->sampled.els[i]) { if (d->clusterid.els[i] == k) { d->hidden.els[i] = d->hidden_now.els[i] = btn->active; } } } displays_plot (NULL, FULL, gg); return false; } static gint exclude_cluster_cb (GtkToggleButton *btn, gpointer cbd) { gint k = GPOINTER_TO_INT (cbd); ggobid *gg = GGobiFromWidget (GTK_WIDGET (btn), true); gint i; datad *d = datad_get_from_notebook (gg->exclusion_ui.notebook, gg); d->clusv[k].included = !btn->active; for (i=0; inrows; i++) { if (d->sampled.els[i]) { if (d->clusterid.els[i] == k) { d->included.els[i] = d->included.els[i] = !btn->active; } } } rows_in_plot_set (d, gg); /*-- should be exactly what happens in subset_apply --*/ /*vartable_lim_update (d, gg);*/ /*-- seems to assume rescaling --*/ /*-- computes new limits, raw and tform --*/ limits_set (true, true, d); /*-- set the ranges and statistics in the variable stats table --*/ vartable_limits_set (d); vartable_stats_set (d); tform_to_world (d, gg); displays_tailpipe (REDISPLAY_ALL, gg); /* assign_points_to_bins ();*/ return false; } static gint exclusion_symbol_cb (GtkWidget *w, GdkEventExpose *event, gpointer cbd) { return false; } void exclusion_cluster_add (gint k, datad *d, ggobid *gg) { gchar *str; gint dawidth = 2*NGLYPHSIZES+1 + 10; /*-- use margin = 5 --*/ d->clusv[k].da = gtk_drawing_area_new (); gtk_drawing_area_size (GTK_DRAWING_AREA (d->clusv[k].da), dawidth, dawidth); gtk_widget_set_events (d->clusv[k].da, GDK_EXPOSURE_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_PRESS_MASK); gtk_signal_connect (GTK_OBJECT (d->clusv[k].da), "expose_event", GTK_SIGNAL_FUNC (exclusion_symbol_show), GINT_TO_POINTER (k)); gtk_signal_connect (GTK_OBJECT (d->clusv[k].da), "button_press_event", GTK_SIGNAL_FUNC (exclusion_symbol_cb), GINT_TO_POINTER (k)); GGobi_widget_set (d->clusv[k].da, gg, true); gtk_table_attach (GTK_TABLE (d->exclusion_table), d->clusv[k].da, 0, 1, k+1, k+2, (GtkAttachOptions)0, (GtkAttachOptions)0, 5, 2); /*-- don't fill --*/ d->clusv[k].hide_tgl = gtk_check_button_new (); GTK_TOGGLE_BUTTON (d->clusv[k].hide_tgl)->active = d->clusv[k].hidden; gtk_signal_connect (GTK_OBJECT (d->clusv[k].hide_tgl), "toggled", GTK_SIGNAL_FUNC (hide_cluster_cb), GINT_TO_POINTER (k)); GGobi_widget_set (d->clusv[k].hide_tgl, gg, true); gtk_table_attach (GTK_TABLE (d->exclusion_table), d->clusv[k].hide_tgl, 1, 2, k+1, k+2, GTK_FILL, GTK_FILL, 5, 2); d->clusv[k].exclude_tgl = gtk_check_button_new (); GTK_TOGGLE_BUTTON (d->clusv[k].exclude_tgl)->active = !d->clusv[k].included; gtk_signal_connect (GTK_OBJECT (d->clusv[k].exclude_tgl), "toggled", GTK_SIGNAL_FUNC (exclude_cluster_cb), GINT_TO_POINTER (k)); GGobi_widget_set (d->clusv[k].exclude_tgl, gg, true); gtk_table_attach (GTK_TABLE (d->exclusion_table), d->clusv[k].exclude_tgl, 2, 3, k+1, k+2, GTK_FILL, GTK_FILL, 5, 2); str = g_strdup_printf ("%ld", d->clusv[k].n); d->clusv[k].lbl = gtk_label_new (str); gtk_table_attach (GTK_TABLE (d->exclusion_table), d->clusv[k].lbl, 3, 4, k+1, k+2, GTK_FILL, GTK_FILL, 5, 2); g_free (str); } static void destroyit (gboolean kill, ggobid *gg) { gint n; GSList *l; datad *d; for (l = gg->d; l; l = l->next) { d = (datad *) l->data; for (n=0; nnclusters; n++) cluster_free (n, d, gg); } if (kill) { gtk_widget_destroy (gg->exclusion_ui.window); gg->exclusion_ui.window = NULL; } else { /*-- the window should have just one child. Find it and kill it --*/ GList* gl = gtk_container_children (GTK_CONTAINER(gg->exclusion_ui.window)); GtkWidget *child = (GtkWidget *) gl->data; gtk_widget_destroy (child); } } void update_cluster_table (datad *d, ggobid *gg) { gint k, table_rows; /*-- destroy all the widgets that were in the table --*/ table_rows = GTK_TABLE (d->exclusion_table)->nrows; for (k=0; kexclusion_table), 1, 4); gtk_table_resize (GTK_TABLE (d->exclusion_table), d->nclusters+1, 4); /*-- add the cluster rows, one by one --*/ for (k=0; knclusters; k++) exclusion_cluster_add (k, d, gg); } /*-- to update it, just start fresh --*/ static void update_cb (GtkWidget *w, ggobid *gg) { exclusion_window_open (gg); } /*-- called when closed from the close button --*/ static void close_cb (GtkWidget *w, ggobid *gg) { destroyit (true, gg); } /*-- called when closed from the window manager --*/ static void delete_cb (GtkWidget *w, GdkEvent *event, ggobid *gg) { destroyit (true, gg); } void exclusion_window_open (ggobid *gg) { GtkWidget *scrolled_window; GtkWidget *vbox, *ebox, *btn, *hbox; gint k; GSList *l; datad *d; /*-- if it isn't NULL, then destroy it and start afresh --*/ if (gg->exclusion_ui.window != NULL) { destroyit (false, gg); /*-- don't kill the whole thing --*/ } if (gg->exclusion_ui.window == NULL || !GTK_WIDGET_REALIZED (gg->exclusion_ui.window)) { gg->exclusion_ui.window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_signal_connect (GTK_OBJECT (gg->exclusion_ui.window), "delete_event", GTK_SIGNAL_FUNC (delete_cb), (gpointer) gg); gtk_window_set_title (GTK_WINDOW (gg->exclusion_ui.window), "ggobi hide/exclude window"); } vbox = gtk_vbox_new (false, 5); gtk_container_set_border_width (GTK_CONTAINER (vbox), 5); gtk_container_add (GTK_CONTAINER (gg->exclusion_ui.window), vbox); ebox = gtk_event_box_new (); gtk_box_pack_start (GTK_BOX (vbox), ebox, true, true, 2); /* Create a notebook, set the position of the tabs */ gg->exclusion_ui.notebook = gtk_notebook_new (); gtk_notebook_set_tab_pos (GTK_NOTEBOOK (gg->exclusion_ui.notebook), GTK_POS_TOP); gtk_notebook_set_show_tabs (GTK_NOTEBOOK (gg->exclusion_ui.notebook), g_slist_length (gg->d) > 1); gtk_container_add (GTK_CONTAINER (ebox), gg->exclusion_ui.notebook); for (l = gg->d; l; l = l->next) { d = (datad *) l->data; clusters_set (d, gg); /* Create a scrolled window to hold the table */ scrolled_window = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); gtk_notebook_append_page (GTK_NOTEBOOK (gg->exclusion_ui.notebook), scrolled_window, gtk_label_new (d->name)); gtk_widget_show (scrolled_window); d->exclusion_table = gtk_table_new (d->nclusters+1, 4, false); gtk_scrolled_window_add_with_viewport ( GTK_SCROLLED_WINDOW (scrolled_window), d->exclusion_table); /*-- add the row of titles --*/ gtk_table_attach (GTK_TABLE (d->exclusion_table), gtk_label_new ("Symbol"), 0, 1, 0, 1, /*-- left, right, top, bottom --*/ GTK_FILL, GTK_FILL, 5, 2); gtk_table_attach (GTK_TABLE (d->exclusion_table), gtk_label_new ("Hidden"), 1, 2, 0, 1, GTK_FILL, GTK_FILL, 5, 2); gtk_table_attach (GTK_TABLE (d->exclusion_table), gtk_label_new ("Excluded"), 2, 3, 0, 1, GTK_FILL, GTK_FILL, 5, 2); gtk_table_attach (GTK_TABLE (d->exclusion_table), gtk_label_new ("N elements"), 3, 4, 0, 1, GTK_FILL, GTK_FILL, 5, 2); /*-- add the cluster rows, one by one --*/ for (k=0; knclusters; k++) exclusion_cluster_add (k, d, gg); } /*-- give the window an initial height --*/ gtk_widget_set_usize (GTK_WIDGET (scrolled_window), -1, 150); /*-- horizontal box to hold a few buttons --*/ hbox = gtk_hbox_new (false, 2); gtk_box_pack_start (GTK_BOX (vbox), hbox, false, false, 0); /*-- Update button --*/ btn = gtk_button_new_with_label ("Update"); gtk_signal_connect (GTK_OBJECT (btn), "clicked", GTK_SIGNAL_FUNC (update_cb), (gpointer) gg); gtk_box_pack_start (GTK_BOX (hbox), btn, true, true, 0); /*-- Close button --*/ btn = gtk_button_new_with_label ("Close"); gtk_signal_connect (GTK_OBJECT (btn), "clicked", GTK_SIGNAL_FUNC (close_cb), (gpointer) gg); gtk_box_pack_start (GTK_BOX (hbox), btn, true, true, 0); gtk_widget_show_all (gg->exclusion_ui.window); gdk_window_raise (gg->exclusion_ui.window->window); }