00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00032 #include <gtk/gtk.h>
00033
00034 #include <graphviz/gvc.h>
00035 #include <graphviz/gvplugin.h>
00036 #include <graphviz/gvplugin_device.h>
00037 #include <graphviz/types.h>
00038
00039 #include <inttypes.h>
00040
00041 #include <cairo.h>
00042
00043 #include <iostream>
00044
00045 #include <X11/Xlib.h>
00046 #include <X11/Xutil.h>
00047
00048 #include <signal.h>
00049 #include <unistd.h>
00050 #include <sys/time.h>
00051 #include <stdio.h>
00052 #include <string.h>
00053
00054 #include "callbacks.h"
00055
00063 #define GLADE_HOOKUP_OBJECT(component,widget,name) \
00064 g_object_set_data_full (G_OBJECT (component), name, \
00065 gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref)
00066
00073 #define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \
00074 g_object_set_data (G_OBJECT (component), name, widget)
00075
00086 GtkWidget*lookup_widget(GtkWidget*widget,const gchar*widget_name)
00087 {
00088 GtkWidget *parent, *found_widget;
00089
00090 for (;;)
00091 {
00092 if (GTK_IS_MENU (widget))
00093 parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
00094 else
00095 parent = widget->parent;
00096
00097 if (!parent)
00098 parent = (GtkWidget*) g_object_get_data (G_OBJECT (widget), "GladeParentKey");
00099
00100 if (parent == NULL)
00101 break;
00102
00103 widget = parent;
00104 }
00105
00106 found_widget = (GtkWidget*) g_object_get_data (G_OBJECT (widget),widget_name);
00107
00108 if (!found_widget)
00109 g_warning ("Widget not found: %s", widget_name);
00110
00111 return found_widget;
00112 }
00113
00120 GtkWidget*create_window(void)
00121 {
00122 GtkWidget *window;
00123 GtkWidget *drawingarea;
00124
00125 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
00126 gtk_window_set_title (GTK_WINDOW (window), "Tree Graph");
00127
00128 drawingarea = gtk_drawing_area_new ();
00129 gtk_widget_show (drawingarea);
00130 gtk_widget_set_size_request (drawingarea, 800, 800);
00131 gtk_container_add (GTK_CONTAINER (window), drawingarea);
00132
00133 g_signal_connect ((gpointer) window, "delete_event",G_CALLBACK (WindowDeleteEvent),NULL);
00134 g_signal_connect ((gpointer) drawingarea, "expose_event",G_CALLBACK (DrawingareaExposeEvent),NULL);
00135 g_signal_connect ((gpointer) drawingarea, "motion_notify_event",G_CALLBACK (DrawingareaMotionNotifyEvent),NULL);
00136 g_signal_connect ((gpointer) drawingarea, "configure_event",G_CALLBACK (DrawingareaConfigureEvent),NULL);
00137 g_signal_connect ((gpointer) drawingarea, "button-press-event",G_CALLBACK (DrawingareaButtonPressEvent),NULL);
00138 g_signal_connect ((gpointer) drawingarea, "button-release-event",G_CALLBACK (DrawingareaButtonPressEvent),NULL);
00139 g_signal_connect ((gpointer) drawingarea, "scroll-event",G_CALLBACK (DrawingareaScrollEvent),NULL);
00140
00141 gtk_widget_set_events (drawingarea, GDK_ENTER_NOTIFY_MASK |GDK_EXPOSURE_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
00142
00143
00144 GLADE_HOOKUP_OBJECT_NO_REF (window, window, "window");
00145 GLADE_HOOKUP_OBJECT (window, drawingarea, "drawingarea");
00146
00147 return window;
00148 }
00149
00157 gboolean Redraw(gpointer data)
00158 {
00159 GtkWidget*window=(GtkWidget*)data;
00160 GtkWidget*drawingarea = lookup_widget (window, "drawingarea");
00161
00162 if(drawGraph())
00163 gdk_window_invalidate_rect(drawingarea->window,&drawingarea->allocation,FALSE);
00164 return 1;
00165 }
00166
00176 static void gtk_initialize(GVJ_t *firstjob)
00177 {
00178 Display *dpy;
00179 const char *display_name = NULL;
00180 int scr;
00181
00182 gtk_set_locale ();
00183 gtk_init (NULL, NULL);
00184
00185 dpy = XOpenDisplay(display_name);
00186 if (dpy == NULL) {
00187 fprintf(stderr, "Failed to open XLIB display: %s\n",
00188 XDisplayName(NULL));
00189 return;
00190 }
00191 scr = DefaultScreen(dpy);
00192
00193 firstjob->device_dpi.x = DisplayWidth(dpy, scr) * 25.4 / DisplayWidthMM(dpy, scr);
00194 firstjob->device_dpi.y = DisplayHeight(dpy, scr) * 25.4 / DisplayHeightMM(dpy, scr);
00195
00196 firstjob->device_sets_dpi = TRUE;
00197 }
00198
00206 static void gtk_finalize(GVJ_t *firstjob)
00207 {
00208 GVJ_t *job;
00209 GtkWidget *window, *drawingarea;
00210
00211 for (job = firstjob; job; job = job->next_active)
00212 {
00213 window = create_window();
00214
00215 g_object_set_data(G_OBJECT(window), "job", (gpointer) job);
00216
00217 drawingarea = lookup_widget (window, "drawingarea");
00218 g_object_set_data(G_OBJECT(drawingarea), "job", (gpointer) job);
00219
00220 g_timeout_add(50,Redraw,window);
00221
00222 gtk_widget_show (window);
00223 }
00224
00225 gtk_main();
00226 }
00227
00229 static gvdevice_engine_t device_engine_xgtk = {
00230 gtk_initialize,
00231 NULL,
00232 gtk_finalize,
00233 };
00234
00236 static gvdevice_features_t device_features_xgtk = {
00237 GVDEVICE_DOES_TRUECOLOR | GVDEVICE_EVENTS ,
00238 {0.,0.},
00239 {100.,100.},
00240 {96.,96.},
00241 };
00242
00244 gvplugin_installed_t gvdevice_types_xgtk[] = {
00245 {0,(char*)"xgtk:cairo", 0, &device_engine_xgtk, &device_features_xgtk},
00246 {0, NULL, 0, NULL, NULL}
00247 };
00248
00250 static gvplugin_api_t apis[] = {
00251 {API_device, gvdevice_types_xgtk},
00252 {(api_t)0, 0},
00253 };
00254
00256 gvplugin_library_t gvplugin_xgtk_LTX_library = {(char*)"xgtk", apis };