1 /*
2 * Grace - GRaphing, Advanced Computation and Exploration of data
3 *
4 * Home page: http://plasma-gate.weizmann.ac.il/Grace/
5 *
6 * Copyright (c) 1991-1995 Paul J Turner, Portland, OR
7 * Copyright (c) 1996-2002 Grace Development Team
8 *
9 * Maintained by Evgeny Stambulchik
10 *
11 *
12 * All Rights Reserved
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 */
28
29 /*
30 *
31 * hot links
32 *
33 */
34
35 #include <config.h>
36
37 #include <stdio.h>
38
39 #include <Xm/Xm.h>
40 #include <Xm/DialogS.h>
41 #include <Xm/Label.h>
42 #include <Xm/PushB.h>
43 #include <Xm/ToggleB.h>
44 #include <Xm/RowColumn.h>
45 #include <Xm/List.h>
46
47 #include "globals.h"
48 #include "graphs.h"
49 #include "parser.h"
50 #include "motifinc.h"
51 #include "protos.h"
52
53 static Widget hotlink_frame = (Widget) NULL;
54 static SetChoiceItem hotlink_set_item;
55 static Widget hotlink_list_item;
56 static Widget hotlink_file_item;
57 static Widget *hotlink_source_item;
58
59 void create_hotfiles_popup(Widget w, XtPointer client_data, XtPointer call_data);
60
61 /*
62 * establish hotlinks by associating a set with a column in a file
63 * or the stdout of a process
64 */
do_hotlink_proc(Widget w,XtPointer client_data,XtPointer call_data)65 static void do_hotlink_proc(Widget w, XtPointer client_data, XtPointer call_data)
66 {
67 int i, numset, src, *sets;
68 char fname[256];
69 char buf[256];
70 XmString xms;
71
72 set_wait_cursor();
73
74 numset = GetSelectedSets(hotlink_set_item, &sets);
75 src = GetChoice(hotlink_source_item);
76 strcpy(fname, xv_getstr(hotlink_file_item));
77
78 if (numset == SET_SELECT_ERROR) {
79 errwin("No set selected");
80 unset_wait_cursor();
81 return;
82 }
83 if (fname[0] == '\0') {
84 errwin("No source selected");
85 unset_wait_cursor();
86 return;
87 }
88
89 for( i=0; i<numset; i++ ) {
90 if( numset == 1 )
91 sprintf(buf, "G%d.S%d -> %s -> %s", get_cg(), sets[i],
92 src==0 ? "DISK" : "PIPE", fname );
93 else
94 sprintf(buf, "G%d.S%d -> %s -> %s:%d", get_cg(), sets[i],
95 src == 0 ? "DISK" : "PIPE", fname, i+1);
96
97 xms = XmStringCreateLocalized(buf);
98 XmListAddItemUnselected(hotlink_list_item, xms, 0);
99 XmStringFree(xms);
100 set_hotlink(get_cg(), sets[i], i+1, fname, src==0?SOURCE_DISK:SOURCE_PIPE);
101 if( numset == 1 )
102 setcomment( get_cg(), sets[i], fname );
103 else {
104 sprintf( buf, "%s:%d", fname, i+1 );
105 setcomment( get_cg(), sets[i], buf );
106 }
107 }
108
109 unset_wait_cursor();
110 }
111
112 /*
113 * unlink sets
114 */
do_hotunlink_proc(Widget w,XtPointer client_data,XtPointer call_data)115 static void do_hotunlink_proc(Widget w, XtPointer client_data, XtPointer call_data)
116 {
117 XmString *s, cs;
118 int cnt, setno;
119 char *cstr;
120
121 set_wait_cursor();
122
123 XtVaGetValues(hotlink_list_item, XmNselectedItemCount, &cnt,
124 XmNselectedItems, &s,
125 NULL);
126 if( cnt ) {
127 for( ; cnt; cnt-- ) {
128 cs = XmStringCopy(s[cnt-1]);
129 if ((cstr = GetStringSimple(cs))) {
130 sscanf(cstr, "G%*d.S%d", &setno);
131 if (setno >= 0 && setno < number_of_sets(get_cg())) {
132 set_hotlink(get_cg(), setno, FALSE, NULL, 0);
133 }
134 }
135 XmStringFree(cs);
136 XtFree(cstr);
137 }
138 update_hotlinks();
139 }
140 unset_wait_cursor();
141 }
142
143 /*
144 * update hot links displayed in scrolled list
145 */
update_hotlinks(void)146 void update_hotlinks(void)
147 {
148 int j;
149 char buf[256];
150 XmString xms;
151
152 if (hotlink_frame != NULL) {
153 set_wait_cursor();
154 XmListDeleteAllItems(hotlink_list_item);
155 for (j = 0; j < number_of_sets(get_cg()); j++) {
156 if (is_hotlinked(get_cg(), j)) {
157 sprintf(buf, "G%d.S%d -> %s -> %s:%d", get_cg(), j,
158 get_hotlink_src(get_cg(), j) == SOURCE_DISK ? "DISK" : "PIPE",
159 get_hotlink_file(get_cg(), j), is_hotlinked(get_cg(),j) );
160 xms = XmStringCreateLocalized(buf);
161 XmListAddItemUnselected(hotlink_list_item, xms, 0);
162 XmStringFree(xms);
163 }
164 }
165 unset_wait_cursor();
166 }
167 }
168
169 /*
170 * update the sets in the current graph
171 */
do_hotupdate_proc(void * data)172 void do_hotupdate_proc(void *data)
173 {
174 int gno, setno;
175
176 set_wait_cursor();
177
178 /* do links */
179 for (gno = 0; gno < number_of_graphs(); gno++) {
180 for (setno = 0; setno < number_of_sets(gno); setno++) {
181 do_update_hotlink(gno, setno);
182 }
183 }
184
185 unset_wait_cursor();
186 xdrawgraph();
187 }
188
189 /*
190 * create the big hot links widget
191 */
create_hotlinks_popup(void * data)192 void create_hotlinks_popup(void *data)
193 {
194 static Widget top, dialog;
195 Arg args[3];
196 set_wait_cursor();
197 if (top == NULL) {
198 char *label1[5];
199 Widget but1[5];
200 label1[0] = "Link";
201 label1[1] = "Files...";
202 label1[2] = "Unlink";
203 label1[3] = "Update";
204 label1[4] = "Close";
205 top = XmCreateDialogShell(app_shell, "Hot links", NULL, 0);
206 handle_close(top);
207 dialog = XmCreateRowColumn(top, "dialog_rc", NULL, 0);
208
209 XtSetArg(args[0], XmNlistSizePolicy, XmRESIZE_IF_POSSIBLE);
210 XtSetArg(args[1], XmNvisibleItemCount, 5);
211 XtSetArg(args[2], XmNselectionPolicy, XmEXTENDED_SELECT );
212 hotlink_list_item = XmCreateScrolledList(dialog, "list", args, 3);
213 ManageChild(hotlink_list_item);
214
215 hotlink_set_item = CreateSetSelector(dialog, "Link set:",
216 SET_SELECT_ACTIVE,
217 FILTER_SELECT_ALL,
218 GRAPH_SELECT_CURRENT,
219 SELECTION_TYPE_MULTIPLE);
220
221 hotlink_file_item = CreateTextItem2(dialog, 30, "To file or SOURCE_PIPE:");
222 hotlink_source_item = CreatePanelChoice(dialog, "Source: ", 3,
223 "Disk file",
224 "Pipe",
225 NULL);
226
227 CreateSeparator(dialog);
228
229 CreateCommandButtons(dialog, 5, but1, label1);
230 XtAddCallback(but1[0], XmNactivateCallback, (XtCallbackProc) do_hotlink_proc,
231 (XtPointer) NULL);
232 XtAddCallback(but1[1], XmNactivateCallback, (XtCallbackProc) create_hotfiles_popup,
233 (XtPointer) NULL);
234 XtAddCallback(but1[2], XmNactivateCallback, (XtCallbackProc) do_hotunlink_proc,
235 (XtPointer) NULL);
236 XtAddCallback(but1[3], XmNactivateCallback, (XtCallbackProc) do_hotupdate_proc,
237 (XtPointer) NULL);
238 XtAddCallback(but1[4], XmNactivateCallback, (XtCallbackProc) destroy_dialog,
239 (XtPointer) top);
240
241 ManageChild(dialog);
242 hotlink_frame = top;
243 }
244 RaiseWindow(top);
245 update_hotlinks();
246 unset_wait_cursor();
247 }
248
249
250 /*
251 * callback for the file selection widget
252 * this routine copies the selected file into the text widget on the main
253 * hot links widget
254 */
do_hotlinkfile_proc(char * filename,void * data)255 static int do_hotlinkfile_proc(char *filename, void *data)
256 {
257 xv_setstr(hotlink_file_item, filename);
258 return TRUE;
259 }
260
261 /*
262 * create file selection pop up to choose the file to hot link
263 */
create_hotfiles_popup(Widget w,XtPointer client_data,XtPointer call_data)264 void create_hotfiles_popup(Widget w, XtPointer client_data, XtPointer call_data)
265 {
266 static FSBStructure *fsb = NULL;
267
268 set_wait_cursor();
269
270 if (fsb == NULL) {
271 fsb = CreateFileSelectionBox(app_shell, "Select hot link file");
272 AddFileSelectionBoxCB(fsb, do_hotlinkfile_proc, NULL);
273 ManageChild(fsb->FSB);
274 }
275
276 RaiseWindow(fsb->dialog);
277
278 unset_wait_cursor();
279 }
280