Graphviz  2.41.20170921.2350
gvdevice_gtk.c
Go to the documentation of this file.
1 /* $Id$ $Revision$ */
2 /* vim:set shiftwidth=4 ts=8: */
3 
4 /*************************************************************************
5  * Copyright (c) 2011 AT&T Intellectual Property
6  * All rights reserved. This program and the accompanying materials
7  * are made available under the terms of the Eclipse Public License v1.0
8  * which accompanies this distribution, and is available at
9  * http://www.eclipse.org/legal/epl-v10.html
10  *
11  * Contributors: See CVS logs. Details at http://www.graphviz.org/
12  *************************************************************************/
13 
14 #include "config.h"
15 
16 #include <stdint.h>
17 #ifdef HAVE_UNISTD_H
18 #include <unistd.h>
19 #endif
20 
21 #include "gvplugin_device.h"
22 
23 #ifdef HAVE_GTK
24 #include <gtk/gtk.h>
25 
26 #include <cairo.h>
27 #ifdef CAIRO_HAS_XLIB_SURFACE
28 #include <X11/Xlib.h>
29 #include <X11/Xutil.h>
30 
31 #include "interface.h"
32 #include "support.h"
33 
34 // note that we do not own the newly entered string - must copy
35 void
36 attr_value_edited_cb(GtkCellRendererText *renderer, gchar *pathStr, gchar *newText, gpointer data)
37 {
38  GtkTreeModel *model = GTK_TREE_MODEL(data);
39 // GVJ_t *job = (GVJ_t *)g_object_get_data(G_OBJECT(model), "job");
40  GtkTreePath *path;
41  GtkTreeIter iter;
42  gchar *old_attr;
43  gint row;
44 
45  path = gtk_tree_path_new_from_string(pathStr);
46  row = gtk_tree_path_get_indices(path)[0];
47 
48  // need to free old attr value in job and allocate new attr value - how?
49 
50  // free old attr value in model
51  gtk_tree_model_get_iter(model, &iter, path);
52  gtk_tree_model_get(model, &iter, 1, &old_attr, -1);
53  g_free(old_attr);
54 
55  // set new attr value in model
56  gtk_list_store_set(GTK_LIST_STORE(model), &iter, 1, g_strdup(newText), -1);
57 
58  gtk_tree_path_free(path);
59 }
60 
61 static void gtk_initialize(GVJ_t *firstjob)
62 {
63  Display *dpy;
64  const char *display_name = NULL;
65  int scr;
66 // GdkScreen *scr1;
67 // GtkWidget *window1;
68 
69 #if 0
70 #ifdef ENABLE_NLS
71  bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
72  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
73  textdomain (GETTEXT_PACKAGE);
74 #endif
75 #endif
76 
77  gtk_set_locale ();
78 // gtk_init (&argc, &argv);
79  gtk_init (NULL, NULL);
80 
81 // add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps");
82 
83 // window1 = create_window1 ();
84 
85 // scr = gdk_drawable_get_screen (window1);
86 // firstjob->device_dpi.x = gdk_screen_get_width(scr) * 25.4 / gdk_screen_get_width_mm(scr); /* pixels_per_inch */
87 // firstjob->device_dpi.y = gdk_screen_get_height(scr) * 25.4 / gdk_screen_get_height_mm(scr);
88  dpy = XOpenDisplay(display_name);
89  if (dpy == NULL) {
90  fprintf(stderr, "Failed to open XLIB display: %s\n",
91  XDisplayName(NULL));
92  return;
93  }
94  scr = DefaultScreen(dpy);
95  firstjob->device_dpi.x = DisplayWidth(dpy, scr) * 25.4 / DisplayWidthMM(dpy, scr);
96  firstjob->device_dpi.y = DisplayHeight(dpy, scr) * 25.4 / DisplayHeightMM(dpy, scr);
97  firstjob->device_sets_dpi = TRUE;
98 }
99 
100 static void gtk_finalize(GVJ_t *firstjob)
101 {
102  GVJ_t *job;
103  GtkWidget *window1, *drawingarea1, *drawingarea2, *treeview2;
104  GtkListStore *attr_store;
105  GtkCellRenderer *value_renderer;
106 
107  for (job = firstjob; job; job = job->next_active) {
108  window1 = create_window1 ();
109 
110  g_object_set_data(G_OBJECT(window1), "job", (gpointer) job);
111 
112  drawingarea1 = lookup_widget (window1, "drawingarea1"); /* main graph view */
113  g_object_set_data(G_OBJECT(drawingarea1), "job", (gpointer) job);
114 
115  drawingarea2 = lookup_widget (window1, "drawingarea2"); /* keyholeview */
116  g_object_set_data(G_OBJECT(drawingarea2), "job", (gpointer) job);
117 
118  treeview2 = lookup_widget (window1, "treeview2"); /* attribute/value view */
119  g_object_set_data(G_OBJECT(treeview2), "job", (gpointer) job);
120 
121  attr_store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
122 
123  gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview2), -1, "Name",
124  gtk_cell_renderer_text_new(), "text", 0, NULL);
125 
126  value_renderer = gtk_cell_renderer_text_new();
127  g_signal_connect(G_OBJECT(value_renderer), "edited", G_CALLBACK(attr_value_edited_cb), attr_store);
128  g_object_set(G_OBJECT(value_renderer), "editable", TRUE, "wrap-mode", PANGO_WRAP_WORD,
129  "wrap-width", 100, NULL);
130  gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview2), -1, "Value", value_renderer,
131  "text", 1, NULL);
132 
133  gtk_tree_view_set_model(GTK_TREE_VIEW(treeview2), GTK_TREE_MODEL(attr_store));
134  g_object_set_data(G_OBJECT(drawingarea1), "attr_store", attr_store);
135 
136  gtk_widget_show (window1);
137  }
138 
139  gtk_main();
140 }
141 
142 static gvdevice_features_t device_features_gtk = {
144  | GVDEVICE_EVENTS, /* flags */
145  {0.,0.}, /* default margin - points */
146  {0.,0.}, /* default page width, height - points */
147  {96.,96.}, /* dpi */
148 };
149 
150 static gvdevice_engine_t device_engine_gtk = {
151  gtk_initialize,
152  NULL, /* gtk_format */
153  gtk_finalize,
154 };
155 #endif
156 #endif
157 
159 #ifdef HAVE_GTK
160 #ifdef CAIRO_HAS_XLIB_SURFACE
161  {0, "gtk:cairo", 0, &device_engine_gtk, &device_features_gtk},
162 #endif
163 #endif
164  {0, NULL, 0, NULL, NULL}
165 };
pointf device_dpi
Definition: gvcjob.h:298
#define bindtextdomain(Domain, Directory)
Definition: support.h:27
Definition: gvcjob.h:271
struct path path
double y
Definition: geom.h:28
GVJ_t * next_active
Definition: gvcjob.h:274
gvplugin_installed_t gvdevice_types_gtk[]
Definition: gvdevice_gtk.c:158
#define GVDEVICE_EVENTS
Definition: gvcjob.h:91
#define textdomain(String)
Definition: support.h:23
GtkWidget * lookup_widget(GtkWidget *widget, const gchar *widget_name)
Definition: support.c:20
#define NULL
Definition: logic.h:39
boolean device_sets_dpi
Definition: gvcjob.h:299
double x
Definition: geom.h:28
GtkWidget * create_window1(void)
Definition: interface.c:30
Definition: legal.c:60
#define GVDEVICE_DOES_TRUECOLOR
Definition: gvcjob.h:92
#define TRUE
Definition: cgraph.h:38