Graphviz 14.1.3~dev.20260201.2050
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 "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
22void size_change_request(GtkWidget *widget, void *user_data) {
23 (void)widget;
24 (void)user_data;
25}
26
27void 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
32void on_settingsApplyBtn_clicked(GtkWidget *widget, void *user_data) {
33 (void)widget;
34 (void)user_data;
35
39}
40
41void 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
48void 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}
54static void copy_attr(Agraph_t *destG, char *attrib, Agraph_t *g)
55{
56 agattr_text(g, AGRAPH, attrib, agget(destG, attrib));
57}
58
59
60static 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);
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
82static 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
99static 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
108static 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);
116 }
117
118 if (buf) {
119 gtk_entry_set_text((GtkEntry *)
120 glade_xml_get_widget(xml, widget_name), buf);
121 }
122}
123
124static 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);
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
145static 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
154static 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);
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
172static 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}
184static 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
197static 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);
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
215static 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);
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
231static 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
241 Agsym_t *sym = NULL;
242 while ((sym = agnxtattr(view->systemGraphs.attrs_widgets, AGRAPH, sym))) {
243 if (startswith(sym->name, "color_button"))
245 sym->name + strlen("color_button="),
247 if (startswith(sym->name, "check_box"))
248 set_checkbox_widget(sym->name + strlen("check_box="),
250 if (startswith(sym->name, "text_box"))
251 set_text_widget(sym->name + strlen("text_box="),
253 if (startswith(sym->name, "combobox"))
254 set_combobox_widget(sym->name + strlen("combobox="),
256 if (startswith(sym->name, "spin_button"))
257 set_spinbtn_widget(sym->name + strlen("spin_button="),
259 if (startswith(sym->name, "scale_button"))
261 sym->name + strlen("scale_button="),
263 }
264}
265
267 Agsym_t *sym = NULL;
268 while ((sym = agnxtattr(view->systemGraphs.attrs_widgets, AGRAPH, sym))) {
269 if (startswith(sym->name, "color_button"))
271 sym->name + strlen("color_button="),
273 if (startswith(sym->name, "check_box"))
275 sym->name + strlen("check_box="),
277 if (startswith(sym->name, "text_box"))
279 sym->name + strlen("text_box="),
281 if (startswith(sym->name, "combobox"))
283 sym->name + strlen("combobox="),
285 if (startswith(sym->name, "spin_button"))
287 sym->name + strlen("spin_button="),
289 if (startswith(sym->name, "scale_button"))
291 sym->name + strlen("scale_button="),
293 }
294}
295
297
298 if (view->activeGraph >= 0) {
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}
@ RGBA_DOUBLE
Definition color.h:27
void colorxlate(char *str, agxbuf *buf)
Definition colxlate.c:48
node NULL
Definition grammar.y:181
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:336
Agsym_t * agnxtattr(Agraph_t *g, int kind, Agsym_t *attr)
permits traversing the list of attributes of a given type
Definition attr.c:365
char * agget(void *obj, char *name)
Definition attr.c:450
@ AGRAPH
Definition cgraph.h:207
GladeXML * xml
Definition gui.c:24
static void color(Agraph_t *g)
Definition gvcolor.c:118
#define ITOS(i)
Definition itos.h:43
ViewInfo * view
Definition viewport.c:40
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:640
char * name
Definition cgraph.h:642
topview * Topview
Definition smyrnadefs.h:305
Agraph_t ** g
Definition smyrnadefs.h:288
int activeGraph
Definition smyrnadefs.h:292
systemgraphs systemGraphs
Definition smyrnadefs.h:246
double RGBA[4]
Definition color.h:32
union color_s::@40 u
Agraph_t * attrs_widgets
Definition smyrnadefs.h:241
Agraph_t * def_attrs
Definition smyrnadefs.h:240
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:88