Graphviz 13.0.0~dev.20241220.2304
Loading...
Searching...
No Matches
menucallbacks.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 "menucallbacks.h"
12#include "viewport.h"
13#include "tvnodes.h"
14
15#include "gvprpipe.h"
16#include "topviewsettings.h"
17#include "gltemplate.h"
18#include <common/const.h>
19#include <assert.h>
20#include <ctype.h>
21#include <glib.h>
22#include <stdlib.h>
23#include "frmobjectui.h"
24#include <util/agxbuf.h>
25
26void mAttributesSlot(GtkWidget *widget, void *user_data) {
27 (void)widget;
28 (void)user_data;
29
31}
32
33void mOpenSlot(GtkWidget *widget, void *user_data) {
34 (void)widget;
35 (void)user_data;
36
37 GtkWidget *dialog;
38 GtkFileFilter *filter;
39
40 filter = gtk_file_filter_new();
41 gtk_file_filter_add_pattern(filter, "*.gv");
42 gtk_file_filter_add_pattern(filter, "*.dot");
43 dialog = gtk_file_chooser_dialog_new("Open File",
44 NULL,
45 GTK_FILE_CHOOSER_ACTION_OPEN,
46 GTK_STOCK_CANCEL,
47 GTK_RESPONSE_CANCEL,
48 GTK_STOCK_OPEN,
49 GTK_RESPONSE_ACCEPT, NULL);
50
51 gtk_file_chooser_set_filter((GtkFileChooser *) dialog, filter);
52 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
53 char *filename;
54 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
55
57 g_free(filename);
58 }
59
60 gtk_widget_destroy(dialog);
61}
62
63void mSaveSlot(GtkWidget *widget, void *user_data) {
64 (void)widget;
65 (void)user_data;
66
67 save_graph(); //save without prompt
68}
69
70void mSaveAsSlot(GtkWidget *widget, void *user_data) {
71 (void)widget;
72 (void)user_data;
73
74 save_as_graph(); //save with prompt
75}
76
77void mCloseSlot(GtkWidget *widget, void *user_data) {
78 (void)widget;
79 (void)user_data;
80
81 if (view->activeGraph == 0)
83}
84
85void mOptionsSlot(GtkWidget *widget, void *user_data) {
86 (void)widget;
87 (void)user_data;
88}
89
90void mQuitSlot(GtkWidget *widget, void *user_data) {
91 (void)widget;
92 (void)user_data;
93
95 gtk_main_quit();
96}
97
98//edit
99void mCutSlot(GtkWidget *widget, void *user_data) {
100 (void)widget;
101 (void)user_data;
102}
103
104void mCopySlot(GtkWidget *widget, void *user_data) {
105 (void)widget;
106 (void)user_data;
107}
108
109void mPasteSlot(GtkWidget *widget, void *user_data) {
110 (void)widget;
111 (void)user_data;
112}
113
114void mDeleteSlot(GtkWidget *widget, void *user_data) {
115 (void)widget;
116 (void)user_data;
117}
118void mTopviewSettingsSlot(GtkWidget *widget, void *user_data) {
119 (void)widget;
120 (void)user_data;
122}
123
124//view
125void mShowToolBoxSlot(GtkWidget *widget, void *user_data) {
126 (void)widget;
127 (void)user_data;
128
129 if (!gtk_widget_set_gl_capability
130 (glade_xml_get_widget(xml, "glfixed"), configure_gl(),
131 gtk_widget_get_gl_context(view->drawing_area), 0, 0))
132 printf("glwidget creation failed \n");
133}
134
135void mShowConsoleSlot(GtkWidget *widget, void *user_data) {
136 (void)widget;
137 (void)user_data;
138
139 static int state = 0; // off by default
140
141 if (state) {
142 gtk_widget_hide (glade_xml_get_widget(xml, "vbox13"));
143 gtk_widget_show (glade_xml_get_widget(xml, "show_console1"));
144 gtk_widget_hide (glade_xml_get_widget(xml, "hide_console1"));
145 state = 0;
146 }
147 else {
148 gtk_widget_show (glade_xml_get_widget(xml, "vbox13"));
149 gtk_widget_hide (glade_xml_get_widget(xml, "show_console1"));
150 gtk_widget_show (glade_xml_get_widget(xml, "hide_console1"));
151 state = 1;
152 }
153}
154
155//Graph
156void mNodeListSlot(GtkWidget *widget, void *user_data) {
157 (void)widget;
158 (void)user_data;
159
160 gtk_widget_show(glade_xml_get_widget(xml, "frmTVNodes"));
162}
163
164void mNewNodeSlot(GtkWidget *widget, void *user_data) {
165 (void)widget;
166 (void)user_data;
167}
168
169void mNewEdgeSlot(GtkWidget *widget, void *user_data) {
170 (void)widget;
171 (void)user_data;
172}
173
174void mNewClusterSlot(GtkWidget *widget, void *user_data) {
175 (void)widget;
176 (void)user_data;
177}
178
179void mGraphPropertiesSlot(GtkWidget *widget, void *user_data) {
180 (void)widget;
181 (void)user_data;
182
183 //there has to be an active graph to open the graph prop page
184 if (view->activeGraph > -1) {
185 load_graph_properties(); //load from graph to gui
186 gtk_dialog_set_response_sensitive((GtkDialog *)
187 glade_xml_get_widget(xml,
188 "dlgOpenGraph"),
189 1, 1);
190 gtk_dialog_set_response_sensitive((GtkDialog *)
191 glade_xml_get_widget(xml,
192 "dlgOpenGraph"),
193 2, 1);
194 gtk_dialog_run((GtkDialog *)glade_xml_get_widget(xml, "dlgOpenGraph"));
195 //need to hide the dialog , again freaking GTK!!!!
196 gtk_widget_hide(glade_xml_get_widget(xml, "dlgOpenGraph"));
197 }
198}
199
200void mNodeFindSlot(GtkWidget *widget, void *user_data) {
201 (void)widget;
202 (void)user_data;
203}
204
205static void mPropertiesSlot(void) {
206 if (view->activeGraph >= 0)
207 gtk_widget_hide(glade_xml_get_widget(xml, "frmObject"));
208 gtk_widget_show(glade_xml_get_widget(xml, "frmObject"));
209}
210
211void mClusterPropertiesSlot(GtkWidget *widget, void *user_data) {
212 (void)widget;
213 (void)user_data;
214
216}
217
218void mNodePropertiesSlot(GtkWidget *widget, void *user_data) {
219 (void)widget;
220 (void)user_data;
221
223}
224
225void mEdgePropertiesSlot(GtkWidget *widget, void *user_data) {
226 (void)widget;
227 (void)user_data;
228
230}
231
232void mShowCodeSlot(GtkWidget *widget, void *user_data) {
233 (void)widget;
234 (void)user_data;
235}
236
237void mAbout(GtkWidget *widget, void *user_data) {
238 (void)widget;
239 (void)user_data;
240}
241
242void change_cursor(GdkCursorType C)
243{
244 GdkCursor *cursor;
245 cursor = gdk_cursor_new(C);
246 gdk_window_set_cursor((GdkWindow *) view->drawing_area->window,
247 cursor);
248 gdk_cursor_destroy(cursor);
249}
250
251void mTestgvpr(GtkWidget *widget, void *user_data) {
252 (void)widget;
253 (void)user_data;
254
255 char *bf2;
256 GtkTextBuffer *gtkbuf;
257 GtkTextIter startit;
258 GtkTextIter endit;
259 const char *args;
260 int cloneGraph;
261
262 args =
263 gtk_entry_get_text((GtkEntry *)
264 glade_xml_get_widget(xml, "gvprargs"));
265 gtkbuf =
266 gtk_text_view_get_buffer((GtkTextView *)
267 glade_xml_get_widget(xml,
268 "gvprtextinput"));
269 gtk_text_buffer_get_start_iter(gtkbuf, &startit);
270 gtk_text_buffer_get_end_iter(gtkbuf, &endit);
271 bf2 = gtk_text_buffer_get_text(gtkbuf, &startit, &endit, 0);
272
273 if (*args == '\0' && *bf2 == '\0') {
274 g_free(bf2);
275 return;
276 }
277
278 size_t argc = 1;
279 if (*args != '\0')
280 argc += 2;
281 if (*bf2 != '\0')
282 argc++;
283 if (gtk_toggle_button_get_active
284 ((GtkToggleButton *) glade_xml_get_widget(xml, "gvprapplycb"))) {
285 cloneGraph = 1;
286 argc++;
287 } else
288 cloneGraph = 0;
289 assert(argc <= 5);
290 char *argv[6] = {0};
291 size_t j = 0;
292 argv[j++] = "smyrna";
293 if (cloneGraph)
294 argv[j++] = "-C";
295 if (*args != '\0') {
296 argv[j++] = "-a";
297// Suppress Clang/GCC -Wcast-qual warning. Casting away const here is acceptable
298// as `run_gvpr` does not modify input arguments.
299#ifdef __GNUC__
300#pragma GCC diagnostic push
301#pragma GCC diagnostic ignored "-Wcast-qual"
302#endif
303 argv[j++] = (char*)args;
304#ifdef __GNUC__
305#pragma GCC diagnostic pop
306#endif
307 }
308 if (*bf2 != '\0') {
309 argv[j++] = bf2;
310 }
311 assert(j == argc);
312
313 run_gvpr(view->g[view->activeGraph], argc, argv);
314 g_free(bf2);
315}
316
317/*
318 opens a file open dialog and load a gvpr program to gvpr script text box
319 if the current script is modified, user should be informed about it
320*/
321void on_gvprbuttonload_clicked(GtkWidget *widget, void *user_data) {
322 (void)widget;
323 (void)user_data;
324
325 FILE *input_file = NULL;
326 char *str;
327 agxbuf xbuf = {0};
328 GtkTextBuffer *gtkbuf; /*GTK buffer from glade GUI */
329
330 char buf[BUFSIZ];
331
332 char *filename = NULL;
333 if (openfiledlg(&filename)) {
334 input_file = fopen(filename, "r");
335 g_free(filename);
336 if (input_file) {
337 while (fgets(buf, BUFSIZ, input_file))
338 agxbput(&xbuf, buf);
339 gtkbuf =
340 gtk_text_view_get_buffer((GtkTextView *)
341 glade_xml_get_widget(xml,
342 "gvprtextinput"));
343 str = agxbuse(&xbuf);
344 if (g_utf8_validate(str, -1, NULL)) {
345 gtk_text_buffer_set_text(gtkbuf, str, -1);
346 } else {
347 show_gui_warning("File format is not UTF8!");
348 }
349 fclose(input_file);
350 } else {
351 show_gui_warning("file couldn't be opened\n");
352 }
353 }
354 agxbfree(&xbuf);
355}
356
357/*
358 opens a file save dialog and save a gvpr program from gvpr script text box
359 if the current script is modified, user should be informed about it
360*/
361void on_gvprbuttonsave_clicked(GtkWidget *widget, void *user_data) {
362 (void)widget;
363 (void)user_data;
364
365 FILE *output_file = NULL;
366 GtkTextBuffer *gtkbuf; /*GTK buffer from glade GUI */
367 char *bf2;
368 GtkTextIter startit;
369 GtkTextIter endit;
370
371 char *filename = NULL;
372 if (savefiledlg(&filename)) {
373 output_file = fopen(filename, "w");
374 g_free(filename);
375 if (output_file) {
376 gtkbuf =
377 gtk_text_view_get_buffer((GtkTextView *)
378 glade_xml_get_widget(xml,
379 "gvprtextinput"));
380 gtk_text_buffer_get_start_iter(gtkbuf, &startit);
381 gtk_text_buffer_get_end_iter(gtkbuf, &endit);
382 bf2 = gtk_text_buffer_get_text(gtkbuf, &startit, &endit, 0);
383 fputs(bf2, output_file);
384 free(bf2);
385 fclose(output_file);
386 }
387
388 /*Code has not been completed for this function yet */
389 }
390}
static void agxbfree(agxbuf *xb)
free any malloced resources
Definition agxbuf.h:78
static WUR char * agxbuse(agxbuf *xb)
Definition agxbuf.h:307
void showAttrsWidget(void)
GdkGLConfig * configure_gl(void)
Definition gltemplate.c:310
void free(void *)
node NULL
Definition grammar.y:163
int openfiledlg(char **filename)
Definition gui.c:56
int savefiledlg(char **filename)
Definition gui.c:80
void load_graph_properties(void)
Definition gui.c:32
void show_gui_warning(char *str)
Definition gui.c:39
GladeXML * xml
Definition gui.c:22
agxbput(xb, staging)
static Agraph_t * cloneGraph(std::vector< Agraph_t * > &gs, GVC_t *gvc, Agdesc_t kind)
Definition gvpack.cpp:543
int run_gvpr(Agraph_t *srcGraph, size_t argc, char *argv[])
Definition gvprpipe.c:41
static agxbuf xbuf[NUMXBUFS]
textitem scanner parser str
Definition htmlparse.y:224
void on_gvprbuttonsave_clicked(GtkWidget *widget, void *user_data)
void mCloseSlot(GtkWidget *widget, void *user_data)
void mSaveSlot(GtkWidget *widget, void *user_data)
void mNodeListSlot(GtkWidget *widget, void *user_data)
void mNewClusterSlot(GtkWidget *widget, void *user_data)
void change_cursor(GdkCursorType C)
void mTestgvpr(GtkWidget *widget, void *user_data)
void mOptionsSlot(GtkWidget *widget, void *user_data)
void on_gvprbuttonload_clicked(GtkWidget *widget, void *user_data)
void mShowConsoleSlot(GtkWidget *widget, void *user_data)
void mNodePropertiesSlot(GtkWidget *widget, void *user_data)
void mCutSlot(GtkWidget *widget, void *user_data)
void mTopviewSettingsSlot(GtkWidget *widget, void *user_data)
void mAbout(GtkWidget *widget, void *user_data)
void mNodeFindSlot(GtkWidget *widget, void *user_data)
void mDeleteSlot(GtkWidget *widget, void *user_data)
void mGraphPropertiesSlot(GtkWidget *widget, void *user_data)
void mCopySlot(GtkWidget *widget, void *user_data)
void mNewNodeSlot(GtkWidget *widget, void *user_data)
void mEdgePropertiesSlot(GtkWidget *widget, void *user_data)
void mNewEdgeSlot(GtkWidget *widget, void *user_data)
void mShowCodeSlot(GtkWidget *widget, void *user_data)
void mOpenSlot(GtkWidget *widget, void *user_data)
void mPasteSlot(GtkWidget *widget, void *user_data)
void mSaveAsSlot(GtkWidget *widget, void *user_data)
void mClusterPropertiesSlot(GtkWidget *widget, void *user_data)
void mQuitSlot(GtkWidget *widget, void *user_data)
void mShowToolBoxSlot(GtkWidget *widget, void *user_data)
void mAttributesSlot(GtkWidget *widget, void *user_data)
static void mPropertiesSlot(void)
#define C
Definition pack.c:29
ViewInfo * view
Definition viewport.c:37
Agraph_t ** g
Definition smyrnadefs.h:296
int activeGraph
Definition smyrnadefs.h:300
GtkWidget * drawing_area
open gl canvas
Definition smyrnadefs.h:310
void show_settings_form(void)
void setup_tree(Agraph_t *g)
Definition tvnodes.c:358
void close_graph(ViewInfo *vi)
Definition viewport.c:71
int add_graph_to_viewport_from_file(char *fileName)
Definition viewport.c:364
int save_as_graph(void)
Definition viewport.c:510
int save_graph(void)
Definition viewport.c:490