Debian Codegraph @

cmd/smyrna/gui/topviewsettings.c

raw
1 /*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11 #include "config.h"
12
13 #include "topviewfuncs.h"
14 #include "topviewsettings.h"
15 #include "gui.h"
16 #include <common/colorprocs.h>
17 #include <stdint.h>
18 #include <util/itos.h>
19 #include <util/startswith.h>
20 #include "viewport.h"
21
22 void size_change_request(GtkWidget *widget, void *user_data) {
23 (void)widget;
24 (void)user_data;
25 }
26
27 void on_settingsOKBtn_clicked(GtkWidget *widget, void *user_data) {
28 on_settingsApplyBtn_clicked(widget, user_data);
29 gtk_widget_hide(glade_xml_get_widget(xml, "dlgSettings"));
30 }
31
32 void on_settingsApplyBtn_clicked(GtkWidget *widget, void *user_data) {
33 (void)widget;
34 (void)user_data;
35
36 update_graph_from_settings(view->g[view->activeGraph]);
37 set_viewport_settings_from_template(view, view->g[view->activeGraph]);
38 updateSmGraph(view->g[view->activeGraph],view->Topview);
39 }
40
41 void on_dlgSettings_close(GtkWidget *widget, void *user_data) {
42 (void)widget;
43 (void)user_data;
44
45 gtk_widget_hide(glade_xml_get_widget(xml, "dlgSettings"));
46 }
47
48 void on_settingsCancelBtn_clicked(GtkWidget *widget, void *user_data) {
49 (void)widget;
50 (void)user_data;
51
52 gtk_widget_hide(glade_xml_get_widget(xml, "dlgSettings"));
53 }
54 static void copy_attr(Agraph_t *destG, char *attrib, Agraph_t *g)
55 {
56 agattr_text(g, AGRAPH, attrib, agget(destG, attrib));
57 }
58
59
60 static void set_color_button_widget(char *attrib, char *widget_name) {
61 GdkColor color;
62 gvcolor_t cl;
63
64 const char *buf = agget(view->g[view->activeGraph], attrib);
65 if ((!buf) || (strcmp(buf, "") == 0))
66 {
67 buf = agget(view->systemGraphs.def_attrs, attrib);
68 copy_attr(view->systemGraphs.def_attrs, attrib, view->g[view->activeGraph]);
69 }
70 if (buf) {
71 colorxlate(buf, &cl, RGBA_DOUBLE);
72 color.red = (uint16_t)(cl.u.RGBA[0] * 65535.0);
73 color.green = (uint16_t)(cl.u.RGBA[1] * 65535.0);
74 color.blue = (uint16_t)(cl.u.RGBA[2] * 65535.0);
75 gtk_color_button_set_color((GtkColorButton *)
76 glade_xml_get_widget(xml, widget_name),
77 &color);
78
79 }
80 }
81
82 static void get_color_button_widget_to_attribute(char *attrib,
83 char *widget_name,
84 Agraph_t * g)
85 {
86 GdkColor color;
87 char buf[256];
88
89 gtk_color_button_get_color((GtkColorButton *)
90 glade_xml_get_widget(xml, widget_name),
91 &color);
92 snprintf(buf, sizeof(buf), "#%02x%02x%02x",
93 (int) ((float) color.red / 65535.0 * 255.0),
94 (int) ((float) color.green / 65535.0 * 255.0),
95 (int) ((float) color.blue / 65535.0 * 255.0));
96 agattr_text(g, AGRAPH, attrib, buf);
97 }
98
99 static void get_text_widget_to_attribute(char *attrib, char *widget_name,
100 Agraph_t * g)
101 {
102 if (strlen(attrib) > 512)
103 return;
104 agattr_text(g, AGRAPH, attrib, gtk_entry_get_text((GtkEntry*)
105 glade_xml_get_widget(xml, widget_name)));
106 }
107
108 static void set_text_widget(char *attrib, char *widget_name) {
109 char *buf;
110
111 buf = agget(view->g[view->activeGraph], attrib);
112 if ((!buf) || (strcmp(buf, "") == 0))
113 {
114 buf = agget(view->systemGraphs.def_attrs, attrib);
115 copy_attr(view->systemGraphs.def_attrs, attrib, view->g[view->activeGraph]);
116 }
117
118 if (buf) {
119 gtk_entry_set_text((GtkEntry *)
120 glade_xml_get_widget(xml, widget_name), buf);
121 }
122 }
123
124 static void set_checkbox_widget(char *attrib, char *widget_name) {
125 char *buf;
126 int value;
127
128 buf = agget(view->g[view->activeGraph], attrib);
129 if ((!buf) || (strcmp(buf, "") == 0))
130 {
131 buf = agget(view->systemGraphs.def_attrs, attrib);
132 copy_attr(view->systemGraphs.def_attrs, attrib, view->g[view->activeGraph]);
133 }
134
135
136 if (buf) {
137 value = atoi(buf);
138 gtk_toggle_button_set_active((GtkToggleButton *)
139 glade_xml_get_widget(xml,
140 widget_name),
141 value);
142 }
143 }
144
145 static void get_checkbox_widget_to_attribute(char *attrib, char *widget_name,
146 Agraph_t * g)
147 {
148 const int value = (int)gtk_toggle_button_get_active((GtkToggleButton *)
149 glade_xml_get_widget(xml,
150 widget_name));
151 agattr_text(g, AGRAPH, attrib, ITOS(value));
152 }
153
154 static void set_spinbtn_widget(char *attrib, char *widget_name) {
155 char *buf;
156 float value;
157
158 buf = agget(view->g[view->activeGraph], attrib);
159 if ((!buf) || (strcmp(buf, "") == 0))
160 {
161 buf = agget(view->systemGraphs.def_attrs, attrib);
162 copy_attr(view->systemGraphs.def_attrs, attrib, view->g[view->activeGraph]);
163 }
164 if (buf) {
165 value = (float) atof(buf);
166 gtk_spin_button_set_value((GtkSpinButton *)
167 glade_xml_get_widget(xml, widget_name),
168 value);
169 }
170 }
171
172 static void get_spinbtn_widget_to_attribute(char *attrib,
173 char *widget_name, Agraph_t * g)
174 {
175 float value;
176 char buf[25];
177
178 value = (float) gtk_spin_button_get_value((GtkSpinButton *)
179 glade_xml_get_widget(xml,
180 widget_name));
181 snprintf(buf, sizeof(buf), "%f", value);
182 agattr_text(g, AGRAPH, attrib, buf);
183 }
184 static void get_scalebtn_widget_to_attribute(char *attrib, char *widget_name,
185 Agraph_t * g)
186 {
187 float value;
188 char buf[25];
189
190 value = (float) gtk_range_get_value((GtkRange *)
191 glade_xml_get_widget(xml,
192 widget_name));
193 snprintf(buf, sizeof(buf), "%f", value);
194 agattr_text(g, AGRAPH, attrib, buf);
195 }
196
197 static void set_scalebtn_widget_to_attribute(char *attrib, char *widget_name) {
198 char *buf;
199 float value;
200 buf = agget(view->g[view->activeGraph], attrib);
201
202 if ((!buf) || (strcmp(buf, "") == 0))
203 {
204 buf = agget(view->systemGraphs.def_attrs, attrib);
205 copy_attr(view->systemGraphs.def_attrs, attrib, view->g[view->activeGraph]);
206
207 }
208 if (buf) {
209 value = (float) atof(buf);
210 gtk_range_set_value((GtkRange *)
211 glade_xml_get_widget(xml, widget_name), value);
212 }
213 }
214
215 static void set_combobox_widget(char *attrib, char *widget_name) {
216 char *buf;
217 int value;
218 buf = agget(view->g[view->activeGraph], attrib);
219 if ((!buf) || (strcmp(buf, "") == 0))
220 {
221 buf = agget(view->systemGraphs.def_attrs, attrib);
222 copy_attr(view->systemGraphs.def_attrs, attrib, view->g[view->activeGraph]);
223 }
224 if (buf) {
225 value = atoi(buf);
226 gtk_combo_box_set_active((GtkComboBox *)
227 glade_xml_get_widget(xml, widget_name), value);
228 }
229 }
230
231 static void get_combobox_widget_to_attribute(char *attrib, char *widget_name,
232 Agraph_t * g)
233 {
234 const int value = (int)gtk_combo_box_get_active((GtkComboBox *)
235 glade_xml_get_widget(xml, widget_name));
236
237 agattr_text(g, AGRAPH, attrib, ITOS(value));
238 }
239
240 void load_settings_from_graph(void) {
241 Agsym_t *sym = NULL;
242 while ((sym = agnxtattr(view->systemGraphs.attrs_widgets, AGRAPH, sym))) {
243 if (startswith(sym->name, "color_button"))
244 set_color_button_widget(
245 sym->name + strlen("color_button="),
246 agget(view->systemGraphs.attrs_widgets, sym->name));
247 if (startswith(sym->name, "check_box"))
248 set_checkbox_widget(sym->name + strlen("check_box="),
249 agget(view->systemGraphs.attrs_widgets, sym->name));
250 if (startswith(sym->name, "text_box"))
251 set_text_widget(sym->name + strlen("text_box="),
252 agget(view->systemGraphs.attrs_widgets, sym->name));
253 if (startswith(sym->name, "combobox"))
254 set_combobox_widget(sym->name + strlen("combobox="),
255 agget(view->systemGraphs.attrs_widgets, sym->name));
256 if (startswith(sym->name, "spin_button"))
257 set_spinbtn_widget(sym->name + strlen("spin_button="),
258 agget(view->systemGraphs.attrs_widgets, sym->name));
259 if (startswith(sym->name, "scale_button"))
260 set_scalebtn_widget_to_attribute(
261 sym->name + strlen("scale_button="),
262 agget(view->systemGraphs.attrs_widgets, sym->name));
263 }
264 }
265
266 void update_graph_from_settings(Agraph_t *g) {
267 Agsym_t *sym = NULL;
268 while ((sym = agnxtattr(view->systemGraphs.attrs_widgets, AGRAPH, sym))) {
269 if (startswith(sym->name, "color_button"))
270 get_color_button_widget_to_attribute(
271 sym->name + strlen("color_button="),
272 agget(view->systemGraphs.attrs_widgets, sym->name), g);
273 if (startswith(sym->name, "check_box"))
274 get_checkbox_widget_to_attribute(
275 sym->name + strlen("check_box="),
276 agget(view->systemGraphs.attrs_widgets, sym->name), g);
277 if (startswith(sym->name, "text_box"))
278 get_text_widget_to_attribute(
279 sym->name + strlen("text_box="),
280 agget(view->systemGraphs.attrs_widgets, sym->name), g);
281 if (startswith(sym->name, "combobox"))
282 get_combobox_widget_to_attribute(
283 sym->name + strlen("combobox="),
284 agget(view->systemGraphs.attrs_widgets, sym->name), g);
285 if (startswith(sym->name, "spin_button"))
286 get_spinbtn_widget_to_attribute(
287 sym->name + strlen("spin_button="),
288 agget(view->systemGraphs.attrs_widgets, sym->name), g);
289 if (startswith(sym->name, "scale_button"))
290 get_scalebtn_widget_to_attribute(
291 sym->name + strlen("scale_button="),
292 agget(view->systemGraphs.attrs_widgets, sym->name), g);
293 }
294 }
295
296 void show_settings_form(void) {
297
298 if (view->activeGraph >= 0) {
299 load_settings_from_graph();
300 gtk_widget_hide(glade_xml_get_widget(xml, "dlgSettings"));
301 gtk_widget_show(glade_xml_get_widget(xml, "dlgSettings"));
302 gtk_window_set_keep_above((GtkWindow *)
303 glade_xml_get_widget(xml, "dlgSettings"),
304 1);
305 } else {
306 void *dlg = gtk_message_dialog_new(NULL,
307 GTK_DIALOG_MODAL,
308 GTK_MESSAGE_QUESTION,
309 GTK_BUTTONS_OK,
310 "No active graph");
311 gtk_dialog_run(dlg);
312 gtk_widget_destroy(dlg);
313 }
314 }