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