1 /* ppcorr_ui.c */
2 /*
3  * ggobi
4  * Copyright (C) AT&T, Duncan Temple Lang, Dianne Cook 1999-2005
5  *
6  * ggobi is free software; you may use, redistribute, and/or modify it
7  * under the terms of the Eclipse Public License, which is distributed
8  * with the source code and displayed on the ggobi web site,
9  * www.ggobi.org.  For more information, contact the authors:
10  *
11  *   Deborah F. Swayne   dfs@research.att.com
12  *   Di Cook             dicook@iastate.edu
13  *   Duncan Temple Lang  duncan@wald.ucdavis.edu
14  *   Andreas Buja        andreas.buja@wharton.upenn.edu
15 */
16 
17 #include <gtk/gtk.h>
18 #include "vars.h"
19 #include "externs.h"
20 
21 #define WIDTH   600
22 #define HEIGHT  300
23 
24 static GtkWidget *window = NULL;
25 static GtkWidget *control_frame;
26 static GtkWidget *mbar;
27 //static GtkAccelGroup *cpp_accel_group;
28 
29 static void
hide_cb(GtkAction * action,GtkWidget * window)30 hide_cb (GtkAction * action, GtkWidget * window)
31 {
32   gtk_widget_hide (window);
33 }
34 
35 static void
optimize_cb(GtkToggleButton * w)36 optimize_cb (GtkToggleButton * w)
37 {
38   g_printerr ("optimize?  %d\n", w->active);
39 }
40 
41 static const gchar *ui_str =
42   "<ui>"
43   "	<menubar>"
44   "		<menu action='File'/>"
45   "			<menuitem action='Close'/>" "		</menu>" "	</menubar>" "</ui>";
46 
47 static GtkActionEntry entries[] = {
48   {"File", NULL, "_File"},
49   {"Close", GTK_STOCK_CLOSE, "_Close", "<control>C",
50    "Hide the projection pursuit window", G_CALLBACK (hide_cb)
51    }
52 };
53 static guint n_entries = G_N_ELEMENTS (entries);
54 /*
55 static GtkItemFactoryEntry menu_items[] = {
56   { "/_File",         NULL,         NULL, 0, "<Branch>" },
57   { "/File/Close",
58          "",         (GtkItemFactoryCallback) hide_cb,        0, "<Item>" },
59 };*/
60 
61 void
ctourpp_window_open(ggobid * gg)62 ctourpp_window_open (ggobid * gg)
63 {
64   GtkWidget *hbox, *vbox, *vbc, *frame, *tgl, *entry;
65   GtkWidget *da, *label, *hb;
66 
67   if (window == NULL) {
68     GtkActionGroup *actions = gtk_action_group_new ("PPActions");
69     GtkUIManager *manager = gtk_ui_manager_new ();
70 
71     window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
72     g_signal_connect (G_OBJECT (window), "delete_event",
73                       G_CALLBACK (hide_cb), (gpointer) NULL);
74     gtk_window_set_title (GTK_WINDOW (window), "Projection Pursuit");
75     //gtk_window_set_policy (GTK_WINDOW (window), true, true, false);
76     gtk_container_set_border_width (GTK_CONTAINER (window), 5);
77 
78 /*
79  * Add the main menu bar
80 */
81     vbox = gtk_vbox_new (FALSE, 1);
82     gtk_container_set_border_width (GTK_CONTAINER (vbox), 1);
83     gtk_container_add (GTK_CONTAINER (window), vbox);
84 /*
85     cpp_accel_group = gtk_accel_group_new ();
86     get_main_menu (menu_items, sizeof (menu_items) / sizeof (menu_items[0]),
87                    cpp_accel_group, window, &mbar, (gpointer) window);
88 */
89 
90     gtk_action_group_add_actions (actions, entries, n_entries, window);
91     gtk_ui_manager_insert_action_group (manager, actions, 0);
92     mbar = create_menu_bar (manager, ui_str, window);
93     g_object_unref (G_OBJECT (actions));
94 
95     gtk_box_pack_start (GTK_BOX (vbox), mbar, false, true, 0);
96 
97 /*
98  * Divide the window:  controls on the left, plot on the right
99 */
100     hbox = gtk_hbox_new (false, 1);
101     gtk_container_set_border_width (GTK_CONTAINER (hbox), 1);
102     gtk_box_pack_start (GTK_BOX (vbox), hbox, true, true, 1);
103 
104 /*
105  * Controls
106 */
107     control_frame = gtk_frame_new (NULL);
108     //gtk_frame_set_shadow_type (GTK_FRAME (control_frame), GTK_SHADOW_IN);
109     gtk_container_set_border_width (GTK_CONTAINER (control_frame), 5);
110     gtk_box_pack_start (GTK_BOX (hbox), control_frame, false, false, 1);
111 
112     vbc = gtk_vbox_new (false, 5);
113     gtk_container_set_border_width (GTK_CONTAINER (vbc), 5);
114     gtk_container_add (GTK_CONTAINER (control_frame), vbc);
115 
116 /*
117  * Optimize toggle
118 */
119     tgl = gtk_check_button_new_with_mnemonic ("_Optimize");
120     gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), tgl,
121                           "Guide the tour using projection pursuit optimization or tour passively",
122                           NULL);
123     g_signal_connect (G_OBJECT (tgl), "toggled",
124                       G_CALLBACK (optimize_cb), (gpointer) NULL);
125     gtk_box_pack_start (GTK_BOX (vbc), tgl, false, false, 1);
126 
127 /*
128  * Index value with label
129 */
130     hb = gtk_hbox_new (false, 3);
131     gtk_box_pack_start (GTK_BOX (vbc), hb, false, false, 2);
132 
133     label = gtk_label_new ("PP index:");
134     gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
135     gtk_box_pack_start (GTK_BOX (hb), label, false, false, 0);
136 
137     entry = gtk_entry_new ();
138     gtk_entry_set_max_length (GTK_ENTRY (entry), 32);
139     gtk_editable_set_editable (GTK_EDITABLE (entry), false);
140     gtk_tooltips_set_tip (GTK_TOOLTIPS (gg->tips), entry,
141                           "The value of the projection pursuit index for the current projection",
142                           NULL);
143     gtk_box_pack_start (GTK_BOX (hb), entry, false, false, 2);
144 
145 /*
146  * Drawing area in a frame
147 */
148     frame = gtk_frame_new (NULL);
149     //gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
150     gtk_container_set_border_width (GTK_CONTAINER (frame), 5);
151     gtk_box_pack_start (GTK_BOX (hbox), frame, true, true, 1);
152 
153     da = gtk_drawing_area_new ();
154     gtk_widget_set_double_buffered (da, false);
155     gtk_widget_set_size_request (GTK_WIDGET (da), WIDTH, HEIGHT);
156     gtk_container_add (GTK_CONTAINER (frame), da);
157   }
158 
159   gtk_widget_show_all (window);
160 }
161