Graphviz 13.0.0~dev.20241220.2304
Loading...
Searching...
No Matches
topviewsettings.c
Go to the documentation of this file.
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 "topviewfuncs.h"
12#include "topviewsettings.h"
13#include "gui.h"
14#include <common/colorprocs.h>
15#include <stdint.h>
16#include <util/startswith.h>
17#include "viewport.h"
18
19void size_change_request(GtkWidget *widget, void *user_data) {
20 (void)widget;
21 (void)user_data;
22}
23
24void on_settingsOKBtn_clicked(GtkWidget *widget, void *user_data) {
25 on_settingsApplyBtn_clicked(widget, user_data);
26 gtk_widget_hide(glade_xml_get_widget(xml, "dlgSettings"));
27}
28
29void on_settingsApplyBtn_clicked(GtkWidget *widget, void *user_data) {
30 (void)widget;
31 (void)user_data;
32
36}
37
38void on_dlgSettings_close(GtkWidget *widget, void *user_data) {
39 (void)widget;
40 (void)user_data;
41
42 gtk_widget_hide(glade_xml_get_widget(xml, "dlgSettings"));
43}
44
45void on_settingsCancelBtn_clicked(GtkWidget *widget, void *user_data) {
46 (void)widget;
47 (void)user_data;
48
49 gtk_widget_hide(glade_xml_get_widget(xml, "dlgSettings"));
50}
51static void copy_attr(Agraph_t *destG, char *attrib, Agraph_t *g)
52{
53 agattr(g, AGRAPH, attrib, agget(destG, attrib));
54}
55
56
57static void set_color_button_widget(char *attrib, char *widget_name) {
58 GdkColor color;
59 gvcolor_t cl;
60
61 const char *buf = agget(view->g[view->activeGraph], attrib);
62 if ((!buf) || (strcmp(buf, "") == 0))
63 {
64 buf = agget(view->systemGraphs.def_attrs, attrib);
66 }
67 if (buf) {
68 colorxlate(buf, &cl, RGBA_DOUBLE);
69 color.red = (uint16_t)(cl.u.RGBA[0] * 65535.0);
70 color.green = (uint16_t)(cl.u.RGBA[1] * 65535.0);
71 color.blue = (uint16_t)(cl.u.RGBA[2] * 65535.0);
72 gtk_color_button_set_color((GtkColorButton *)
73 glade_xml_get_widget(xml, widget_name),
74 &color);
75
76 }
77}
78
79static void get_color_button_widget_to_attribute(char *attrib,
80 char *widget_name,
81 Agraph_t * g)
82{
83 GdkColor color;
84 char buf[256];
85
86 gtk_color_button_get_color((GtkColorButton *)
87 glade_xml_get_widget(xml, widget_name),
88 &color);
89 snprintf(buf, sizeof(buf), "#%02x%02x%02x",
90 (int) ((float) color.red / 65535.0 * 255.0),
91 (int) ((float) color.green / 65535.0 * 255.0),
92 (int) ((float) color.blue / 65535.0 * 255.0));
93 agattr(g, AGRAPH, attrib, buf);
94}
95
96static void get_text_widget_to_attribute(char *attrib, char *widget_name,
97 Agraph_t * g)
98{
99 if (strlen(attrib) > 512)
100 return;
101 agattr(g, AGRAPH, attrib, gtk_entry_get_text((GtkEntry*)
102 glade_xml_get_widget(xml, widget_name)));
103}
104
105static void set_text_widget(char *attrib, char *widget_name) {
106 char *buf;
107
108 buf = agget(view->g[view->activeGraph], attrib);
109 if ((!buf) || (strcmp(buf, "") == 0))
110 {
111 buf = agget(view->systemGraphs.def_attrs, attrib);
113 }
114
115 if (buf) {
116 gtk_entry_set_text((GtkEntry *)
117 glade_xml_get_widget(xml, widget_name), buf);
118 }
119}
120
121static void set_checkbox_widget(char *attrib, char *widget_name) {
122 char *buf;
123 int value;
124
125 buf = agget(view->g[view->activeGraph], attrib);
126 if ((!buf) || (strcmp(buf, "") == 0))
127 {
128 buf = agget(view->systemGraphs.def_attrs, attrib);
130 }
131
132
133 if (buf) {
134 value = atoi(buf);
135 gtk_toggle_button_set_active((GtkToggleButton *)
136 glade_xml_get_widget(xml,
137 widget_name),
138 value);
139 }
140}
141
142static void get_checkbox_widget_to_attribute(char *attrib, char *widget_name,
143 Agraph_t * g)
144{
145 int value;
146 char buf[100];
147
148 value = (int) gtk_toggle_button_get_active((GtkToggleButton *)
149 glade_xml_get_widget(xml,
150 widget_name));
151 snprintf(buf, sizeof(buf), "%d", value);
152 agattr(g, AGRAPH, attrib, buf);
153}
154
155static void set_spinbtn_widget(char *attrib, char *widget_name) {
156 char *buf;
157 float value;
158
159 buf = agget(view->g[view->activeGraph], attrib);
160 if ((!buf) || (strcmp(buf, "") == 0))
161 {
162 buf = agget(view->systemGraphs.def_attrs, attrib);
164 }
165 if (buf) {
166 value = (float) atof(buf);
167 gtk_spin_button_set_value((GtkSpinButton *)
168 glade_xml_get_widget(xml, widget_name),
169 value);
170 }
171}
172
173static void get_spinbtn_widget_to_attribute(char *attrib,
174 char *widget_name, Agraph_t * g)
175{
176 float value;
177 char buf[25];
178
179 value = (float) gtk_spin_button_get_value((GtkSpinButton *)
180 glade_xml_get_widget(xml,
181 widget_name));
182 snprintf(buf, sizeof(buf), "%f", value);
183 agattr(g, AGRAPH, attrib, buf);
184}
185static void get_scalebtn_widget_to_attribute(char *attrib, char *widget_name,
186 Agraph_t * g)
187{
188 float value;
189 char buf[25];
190
191 value = (float) gtk_range_get_value((GtkRange *)
192 glade_xml_get_widget(xml,
193 widget_name));
194 snprintf(buf, sizeof(buf), "%f", value);
195 agattr(g, AGRAPH, attrib, buf);
196}
197
198static void set_scalebtn_widget_to_attribute(char *attrib, char *widget_name) {
199 char *buf;
200 float value;
201 buf = agget(view->g[view->activeGraph], attrib);
202
203 if ((!buf) || (strcmp(buf, "") == 0))
204 {
205 buf = agget(view->systemGraphs.def_attrs, attrib);
207
208 }
209 if (buf) {
210 value = (float) atof(buf);
211 gtk_range_set_value((GtkRange *)
212 glade_xml_get_widget(xml, widget_name), value);
213 }
214}
215
216static void set_combobox_widget(char *attrib, char *widget_name) {
217 char *buf;
218 int value;
219 buf = agget(view->g[view->activeGraph], attrib);
220 if ((!buf) || (strcmp(buf, "") == 0))
221 {
222 buf = agget(view->systemGraphs.def_attrs, attrib);
224 }
225 if (buf) {
226 value = atoi(buf);
227 gtk_combo_box_set_active((GtkComboBox *)
228 glade_xml_get_widget(xml, widget_name), value);
229 }
230}
231
232static void get_combobox_widget_to_attribute(char *attrib, char *widget_name,
233 Agraph_t * g)
234{
235 char buf[25];
236 int value;
237
238 value = (int)
239 gtk_combo_box_get_active((GtkComboBox *)
240 glade_xml_get_widget(xml, widget_name));
241
242 snprintf(buf, sizeof(buf), "%d", value);
243 agattr(g, AGRAPH, attrib, buf);
244}
245
247 Agsym_t *sym = NULL;
248 while ((sym = agnxtattr(view->systemGraphs.attrs_widgets, AGRAPH, sym))) {
249 if (startswith(sym->name, "color_button"))
251 sym->name + strlen("color_button="),
253 if (startswith(sym->name, "check_box"))
254 set_checkbox_widget(sym->name + strlen("check_box="),
256 if (startswith(sym->name, "text_box"))
257 set_text_widget(sym->name + strlen("text_box="),
259 if (startswith(sym->name, "combobox"))
260 set_combobox_widget(sym->name + strlen("combobox="),
262 if (startswith(sym->name, "spin_button"))
263 set_spinbtn_widget(sym->name + strlen("spin_button="),
265 if (startswith(sym->name, "scale_button"))
267 sym->name + strlen("scale_button="),
269 }
270}
271
273 Agsym_t *sym = NULL;
274 while ((sym = agnxtattr(view->systemGraphs.attrs_widgets, AGRAPH, sym))) {
275 if (startswith(sym->name, "color_button"))
277 sym->name + strlen("color_button="),
279 if (startswith(sym->name, "check_box"))
281 sym->name + strlen("check_box="),
283 if (startswith(sym->name, "text_box"))
285 sym->name + strlen("text_box="),
287 if (startswith(sym->name, "combobox"))
289 sym->name + strlen("combobox="),
291 if (startswith(sym->name, "spin_button"))
293 sym->name + strlen("spin_button="),
295 if (startswith(sym->name, "scale_button"))
297 sym->name + strlen("scale_button="),
299 }
300}
301
303
304 if (view->activeGraph >= 0) {
306 gtk_widget_hide(glade_xml_get_widget(xml, "dlgSettings"));
307 gtk_widget_show(glade_xml_get_widget(xml, "dlgSettings"));
308 gtk_window_set_keep_above((GtkWindow *)
309 glade_xml_get_widget(xml, "dlgSettings"),
310 1);
311 } else {
312 void *dlg = gtk_message_dialog_new(NULL,
313 GTK_DIALOG_MODAL,
314 GTK_MESSAGE_QUESTION,
315 GTK_BUTTONS_OK,
316 "No active graph");
317 gtk_dialog_run(dlg);
318 gtk_widget_hide(dlg);
319 }
320}
@ RGBA_DOUBLE
Definition color.h:27
void colorxlate(char *str, agxbuf *buf)
Definition colxlate.c:46
node NULL
Definition grammar.y:163
Agsym_t * agattr(Agraph_t *g, int kind, char *name, const char *value)
creates or looks up attributes of a graph
Definition attr.c:338
Agsym_t * agnxtattr(Agraph_t *g, int kind, Agsym_t *attr)
permits traversing the list of attributes of a given type
Definition attr.c:353
char * agget(void *obj, char *name)
Definition attr.c:439
@ AGRAPH
Definition cgraph.h:207
GladeXML * xml
Definition gui.c:22
static void color(Agraph_t *g)
Definition gvcolor.c:129
ViewInfo * view
Definition viewport.c:37
static bool startswith(const char *s, const char *prefix)
does the string s begin with the string prefix?
Definition startswith.h:11
graph or subgraph
Definition cgraph.h:425
string attribute descriptor symbol in Agattr_s.dict
Definition cgraph.h:637
char * name
Definition cgraph.h:639
topview * Topview
Definition smyrnadefs.h:313
Agraph_t ** g
Definition smyrnadefs.h:296
int activeGraph
Definition smyrnadefs.h:300
systemgraphs systemGraphs
Definition smyrnadefs.h:253
double RGBA[4]
Definition color.h:32
union color_s::@71 u
Agraph_t * attrs_widgets
Definition smyrnadefs.h:248
Agraph_t * def_attrs
Definition smyrnadefs.h:247
void updateSmGraph(Agraph_t *g, topview *t)
static void get_text_widget_to_attribute(char *attrib, char *widget_name, Agraph_t *g)
void on_settingsCancelBtn_clicked(GtkWidget *widget, void *user_data)
static void copy_attr(Agraph_t *destG, char *attrib, Agraph_t *g)
static void get_scalebtn_widget_to_attribute(char *attrib, char *widget_name, Agraph_t *g)
static void set_color_button_widget(char *attrib, char *widget_name)
static void set_checkbox_widget(char *attrib, char *widget_name)
void load_settings_from_graph(void)
static void get_color_button_widget_to_attribute(char *attrib, char *widget_name, Agraph_t *g)
void on_settingsOKBtn_clicked(GtkWidget *widget, void *user_data)
static void set_scalebtn_widget_to_attribute(char *attrib, char *widget_name)
void size_change_request(GtkWidget *widget, void *user_data)
void update_graph_from_settings(Agraph_t *g)
void on_settingsApplyBtn_clicked(GtkWidget *widget, void *user_data)
static void set_text_widget(char *attrib, char *widget_name)
static void get_combobox_widget_to_attribute(char *attrib, char *widget_name, Agraph_t *g)
void on_dlgSettings_close(GtkWidget *widget, void *user_data)
static void set_combobox_widget(char *attrib, char *widget_name)
static void set_spinbtn_widget(char *attrib, char *widget_name)
static void get_checkbox_widget_to_attribute(char *attrib, char *widget_name, Agraph_t *g)
static void get_spinbtn_widget_to_attribute(char *attrib, char *widget_name, Agraph_t *g)
void show_settings_form(void)
void set_viewport_settings_from_template(ViewInfo *vi, Agraph_t *g)
Definition viewport.c:85