Graphviz 12.0.1~dev.20240715.2254
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 <cgraph/startswith.h>
15#include <common/colorprocs.h>
16#include "viewport.h"
17
18void color_change_request(GtkWidget * widget, gpointer user_data)
19{
20 (void)widget;
21 (void)user_data;
22
24}
25void size_change_request(GtkWidget * widget, gpointer user_data)
26{
27 (void)widget;
28 (void)user_data;
29}
30
31void on_settingsOKBtn_clicked(GtkWidget * widget, gpointer user_data)
32{
33 on_settingsApplyBtn_clicked(widget, user_data);
34 gtk_widget_hide(glade_xml_get_widget(xml, "dlgSettings"));
35}
36
37void on_settingsApplyBtn_clicked(GtkWidget * widget, gpointer user_data)
38{
39 (void)widget;
40 (void)user_data;
41
45}
46void on_dlgSettings_close (GtkWidget * widget, gpointer user_data)
47{
48 (void)widget;
49 (void)user_data;
50
51 gtk_widget_hide(glade_xml_get_widget(xml, "dlgSettings"));
52}
53
54void on_settingsCancelBtn_clicked(GtkWidget * widget, gpointer user_data)
55{
56 (void)widget;
57 (void)user_data;
58
59 gtk_widget_hide(glade_xml_get_widget(xml, "dlgSettings"));
60}
61static void copy_attr(Agraph_t *destG, char *attrib, Agraph_t *g)
62{
63 agattr(g, AGRAPH, attrib, agget(destG, attrib));
64}
65
66
67static void set_color_button_widget(char *attrib, char *widget_name) {
68 GdkColor color;
69 gvcolor_t cl;
70
71 char *buf;
72 buf = agget(view->g[view->activeGraph], attrib);
73 if ((!buf) || (strcmp(buf, "") == 0))
74 {
75 buf = agget(view->systemGraphs.def_attrs, attrib);
77 }
78 if (buf) {
79 colorxlate(buf, &cl, RGBA_DOUBLE);
80 color.red = (guint16)(cl.u.RGBA[0] * 65535.0);
81 color.green = (guint16)(cl.u.RGBA[1] * 65535.0);
82 color.blue = (guint16)(cl.u.RGBA[2] * 65535.0);
83 gtk_color_button_set_color((GtkColorButton *)
84 glade_xml_get_widget(xml, widget_name),
85 &color);
86
87 }
88}
89
90static void get_color_button_widget_to_attribute(char *attrib,
91 char *widget_name,
92 Agraph_t * g)
93{
94 GdkColor color;
95 char buf[256];
96
97 gtk_color_button_get_color((GtkColorButton *)
98 glade_xml_get_widget(xml, widget_name),
99 &color);
100 snprintf(buf, sizeof(buf), "#%02x%02x%02x",
101 (int) ((float) color.red / 65535.0 * 255.0),
102 (int) ((float) color.green / 65535.0 * 255.0),
103 (int) ((float) color.blue / 65535.0 * 255.0));
104 agattr(g, AGRAPH, attrib, buf);
105}
106
107static void get_text_widget_to_attribute(char *attrib, char *widget_name,
108 Agraph_t * g)
109{
110 if (strlen(attrib) > 512)
111 return;
112 agattr(g, AGRAPH, attrib, gtk_entry_get_text((GtkEntry*)
113 glade_xml_get_widget(xml, widget_name)));
114}
115
116static void set_text_widget(char *attrib, char *widget_name) {
117 char *buf;
118
119 buf = agget(view->g[view->activeGraph], attrib);
120 if ((!buf) || (strcmp(buf, "") == 0))
121 {
122 buf = agget(view->systemGraphs.def_attrs, attrib);
124 }
125
126 if (buf) {
127 gtk_entry_set_text((GtkEntry *)
128 glade_xml_get_widget(xml, widget_name), buf);
129 }
130}
131
132static void set_checkbox_widget(char *attrib, char *widget_name) {
133 char *buf;
134 int value;
135
136 buf = agget(view->g[view->activeGraph], attrib);
137 if ((!buf) || (strcmp(buf, "") == 0))
138 {
139 buf = agget(view->systemGraphs.def_attrs, attrib);
141 }
142
143
144 if (buf) {
145 value = atoi(buf);
146 gtk_toggle_button_set_active((GtkToggleButton *)
147 glade_xml_get_widget(xml,
148 widget_name),
149 value);
150 }
151}
152
153static void get_checkbox_widget_to_attribute(char *attrib, char *widget_name,
154 Agraph_t * g)
155{
156 int value;
157 char buf[100];
158
159 value = (int) gtk_toggle_button_get_active((GtkToggleButton *)
160 glade_xml_get_widget(xml,
161 widget_name));
162 snprintf(buf, sizeof(buf), "%d", value);
163 agattr(g, AGRAPH, attrib, buf);
164}
165
166static void set_spinbtn_widget(char *attrib, char *widget_name) {
167 char *buf;
168 float value;
169
170 buf = agget(view->g[view->activeGraph], attrib);
171 if ((!buf) || (strcmp(buf, "") == 0))
172 {
173 buf = agget(view->systemGraphs.def_attrs, attrib);
175 }
176 if (buf) {
177 value = (float) atof(buf);
178 gtk_spin_button_set_value((GtkSpinButton *)
179 glade_xml_get_widget(xml, widget_name),
180 value);
181 }
182}
183
184static void get_spinbtn_widget_to_attribute(char *attrib,
185 char *widget_name, Agraph_t * g)
186{
187 float value;
188 char buf[25];
189
190 value = (float) gtk_spin_button_get_value((GtkSpinButton *)
191 glade_xml_get_widget(xml,
192 widget_name));
193 snprintf(buf, sizeof(buf), "%f", value);
194 agattr(g, AGRAPH, attrib, buf);
195}
196static void get_scalebtn_widget_to_attribute(char *attrib, char *widget_name,
197 Agraph_t * g)
198{
199 float value;
200 char buf[25];
201
202 value = (float) gtk_range_get_value((GtkRange *)
203 glade_xml_get_widget(xml,
204 widget_name));
205 snprintf(buf, sizeof(buf), "%f", value);
206 agattr(g, AGRAPH, attrib, buf);
207}
208
209static void set_scalebtn_widget_to_attribute(char *attrib, char *widget_name) {
210 char *buf;
211 float value;
212 buf = agget(view->g[view->activeGraph], attrib);
213
214 if ((!buf) || (strcmp(buf, "") == 0))
215 {
216 buf = agget(view->systemGraphs.def_attrs, attrib);
218
219 }
220 if (buf) {
221 value = (float) atof(buf);
222 gtk_range_set_value((GtkRange *)
223 glade_xml_get_widget(xml, widget_name), value);
224 }
225}
226
227static void set_combobox_widget(char *attrib, char *widget_name) {
228 char *buf;
229 int value;
230 buf = agget(view->g[view->activeGraph], attrib);
231 if ((!buf) || (strcmp(buf, "") == 0))
232 {
233 buf = agget(view->systemGraphs.def_attrs, attrib);
235 }
236 if (buf) {
237 value = atoi(buf);
238 gtk_combo_box_set_active((GtkComboBox *)
239 glade_xml_get_widget(xml, widget_name), value);
240 }
241}
242
243static void get_combobox_widget_to_attribute(char *attrib, char *widget_name,
244 Agraph_t * g)
245{
246 char buf[25];
247 int value;
248
249 value = (int)
250 gtk_combo_box_get_active((GtkComboBox *)
251 glade_xml_get_widget(xml, widget_name));
252
253 snprintf(buf, sizeof(buf), "%d", value);
254 agattr(g, AGRAPH, attrib, buf);
255}
256
258 Agsym_t *sym = NULL;
259 while ((sym = agnxtattr(view->systemGraphs.attrs_widgets, AGRAPH, sym))) {
260 if (startswith(sym->name, "color_button"))
262 sym->name + strlen("color_button="),
264 if (startswith(sym->name, "check_box"))
265 set_checkbox_widget(sym->name + strlen("check_box="),
267 if (startswith(sym->name, "text_box"))
268 set_text_widget(sym->name + strlen("text_box="),
270 if (startswith(sym->name, "combobox"))
271 set_combobox_widget(sym->name + strlen("combobox="),
273 if (startswith(sym->name, "spin_button"))
274 set_spinbtn_widget(sym->name + strlen("spin_button="),
276 if (startswith(sym->name, "scale_button"))
278 sym->name + strlen("scale_button="),
280 }
281}
282
284 Agsym_t *sym = NULL;
285 while ((sym = agnxtattr(view->systemGraphs.attrs_widgets, AGRAPH, sym))) {
286 if (startswith(sym->name, "color_button"))
288 sym->name + strlen("color_button="),
290 if (startswith(sym->name, "check_box"))
292 sym->name + strlen("check_box="),
294 if (startswith(sym->name, "text_box"))
296 sym->name + strlen("text_box="),
298 if (startswith(sym->name, "combobox"))
300 sym->name + strlen("combobox="),
302 if (startswith(sym->name, "spin_button"))
304 sym->name + strlen("spin_button="),
306 if (startswith(sym->name, "scale_button"))
308 sym->name + strlen("scale_button="),
310 }
311}
312
314
315 if (view->activeGraph >= 0) {
317 gtk_widget_hide(glade_xml_get_widget(xml, "dlgSettings"));
318 gtk_widget_show(glade_xml_get_widget(xml, "dlgSettings"));
319 gtk_window_set_keep_above((GtkWindow *)
320 glade_xml_get_widget(xml, "dlgSettings"),
321 1);
322 } else {
323 void *dlg = gtk_message_dialog_new(NULL,
324 GTK_DIALOG_MODAL,
325 GTK_MESSAGE_QUESTION,
326 GTK_BUTTONS_OK,
327 "No active graph");
328 gtk_dialog_run(dlg);
329 gtk_widget_hide(dlg);
330 }
331}
@ RGBA_DOUBLE
Definition color.h:27
void colorxlate(char *str, agxbuf *buf)
Definition colxlate.c:48
node NULL
Definition grammar.y:149
Agsym_t * agattr(Agraph_t *g, int kind, char *name, const char *value)
creates or looks up attributes of a graph
Definition attr.c:341
Agsym_t * agnxtattr(Agraph_t *g, int kind, Agsym_t *attr)
permits traversing the list of attributes of a given type
Definition attr.c:356
char * agget(void *obj, char *name)
Definition attr.c:442
@ AGRAPH
Definition cgraph.h:207
GladeXML * xml
Definition gui.c:22
static void color(Agraph_t *g)
Definition gvcolor.c:128
ViewInfo * view
Definition viewport.c:38
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:639
char * name
Definition cgraph.h:641
topview * Topview
Definition smyrnadefs.h:334
Agraph_t ** g
Definition smyrnadefs.h:313
int activeGraph
Definition smyrnadefs.h:317
systemgraphs systemGraphs
Definition smyrnadefs.h:270
refresh_filter refresh
Definition smyrnadefs.h:369
double RGBA[4]
Definition color.h:32
union color_s::@72 u
Agraph_t * attrs_widgets
Definition smyrnadefs.h:265
Agraph_t * def_attrs
Definition smyrnadefs.h:264
void updateSmGraph(Agraph_t *g, topview *t)
static void get_text_widget_to_attribute(char *attrib, char *widget_name, Agraph_t *g)
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)
void on_dlgSettings_close(GtkWidget *widget, gpointer user_data)
void on_settingsCancelBtn_clicked(GtkWidget *widget, gpointer user_data)
static void set_color_button_widget(char *attrib, char *widget_name)
void on_settingsApplyBtn_clicked(GtkWidget *widget, gpointer user_data)
static void set_checkbox_widget(char *attrib, char *widget_name)
void load_settings_from_graph(void)
void color_change_request(GtkWidget *widget, gpointer user_data)
void size_change_request(GtkWidget *widget, gpointer user_data)
static void get_color_button_widget_to_attribute(char *attrib, char *widget_name, Agraph_t *g)
static void set_scalebtn_widget_to_attribute(char *attrib, char *widget_name)
void update_graph_from_settings(Agraph_t *g)
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)
static void set_combobox_widget(char *attrib, char *widget_name)
void on_settingsOKBtn_clicked(GtkWidget *widget, gpointer user_data)
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