Debian Codegraph @

cmd/smyrna/gui/gui.c

raw
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 <assert.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include "gui.h"
17 #include <glade/glade.h>
18 #include <gdk/gdkkeysyms.h>
19 #include <gdk/gdk.h>
20 #include "viewport.h"
21 #include <util/alloc.h>
22 #include <util/strview.h>
23
24 GladeXML *xml; //global libglade vars
25
26 void Color_Widget_bg(char *colorstring, GtkWidget * widget)
27 {
28 GdkColor color;
29 gdk_color_parse(colorstring, &color);
30 gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &color);
31 gtk_widget_modify_base(widget, GTK_STATE_NORMAL, &color);
32 }
33
34 void load_graph_properties(void) {
35 //dlgOpenGraph , GtkDialog
36 gtk_entry_set_text((GtkEntry *)
37 glade_xml_get_widget(xml, "entryGraphFileName"),
38 view->Topview->Graphdata.GraphFileName);
39 }
40
41 void show_gui_warning(char *str)
42 {
43 GtkMessageDialog *Dlg = (GtkMessageDialog *)gtk_message_dialog_new(NULL,
44 GTK_DIALOG_MODAL,
45 GTK_MESSAGE_WARNING,
46 GTK_BUTTONS_OK, "%s", str);
47
48 gtk_dialog_run((GtkDialog *) Dlg);
49 gtk_object_destroy((GtkObject *) Dlg);
50 }
51
52
53
54 /*
55 Generic Open File dialog, if a file is selected and return value is 1, else 0
56 file name is copied to char* filename,which should be allocated before using the function
57 */
58 int openfiledlg(char **filename) {
59 assert(filename != NULL);
60
61 GtkWidget *dialog;
62 int rv;
63
64 dialog = gtk_file_chooser_dialog_new("Open File",
65 NULL,
66 GTK_FILE_CHOOSER_ACTION_OPEN,
67 GTK_STOCK_CANCEL,
68 GTK_RESPONSE_CANCEL,
69 GTK_STOCK_OPEN,
70 GTK_RESPONSE_ACCEPT, NULL);
71
72 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
73 *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
74 rv = 1;
75 } else
76 rv = 0;
77
78 gtk_widget_destroy(dialog);
79 return rv;
80 }
81
82 int savefiledlg(char **filename) {
83 assert(filename != NULL);
84
85 GtkWidget *dialog;
86 int rv;
87
88 dialog = gtk_file_chooser_dialog_new("Save File",
89 NULL,
90 GTK_FILE_CHOOSER_ACTION_OPEN,
91 GTK_STOCK_CANCEL,
92 GTK_RESPONSE_CANCEL,
93 GTK_STOCK_OPEN,
94 GTK_RESPONSE_ACCEPT, NULL);
95
96 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
97 *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
98 rv = 1;
99 } else
100 rv = 0;
101
102 gtk_widget_destroy(dialog);
103 return rv;
104 }
105
106 void append_textview(GtkTextView * textv, const char *s, size_t bytes)
107 {
108
109 GtkTextIter endit;
110 GtkTextBuffer *gtkbuf;
111 /*get text view buffer */
112 gtkbuf = gtk_text_view_get_buffer(textv);
113 /*set iterator to the end of the buffer */
114 gtk_text_buffer_get_end_iter(gtkbuf, &endit);
115 /* insert buf to the end */
116 gtk_text_buffer_insert(gtkbuf, &endit, s, (int)bytes);
117
118 }