aboutsummaryrefslogtreecommitdiff
path: root/src/cell_explorer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cell_explorer.c')
-rw-r--r--src/cell_explorer.c109
1 files changed, 75 insertions, 34 deletions
diff --git a/src/cell_explorer.c b/src/cell_explorer.c
index 94e7e985..69dd7178 100644
--- a/src/cell_explorer.c
+++ b/src/cell_explorer.c
@@ -37,7 +37,7 @@
#include <string.h>
#include <gtk/gtk.h>
#include <math.h>
-#include <gdk/gdkkeysyms.h>
+#include <gdk/gdkkeysyms-compat.h>
#include <gsl/gsl_multifit_nlin.h>
#include "stream.h"
@@ -189,6 +189,12 @@ static void set_col(cairo_t *cr, CellWindow *w, int cat)
static gboolean destroy_sig(GtkWidget *da, CellWindow *w)
{
+ multihistogram_free(w->hist_a->h);
+ multihistogram_free(w->hist_b->h);
+ multihistogram_free(w->hist_c->h);
+ multihistogram_free(w->hist_al->h);
+ multihistogram_free(w->hist_be->h);
+ multihistogram_free(w->hist_ga->h);
gtk_main_quit();
return FALSE;
}
@@ -315,21 +321,20 @@ static void draw_label(cairo_t *cr, HistoBox *b, int width, int height)
}
-static gboolean draw_sig(GtkWidget *da, GdkEventExpose *event, HistoBox *b)
+static gboolean draw_sig(GtkWidget *da, cairo_t *cr, HistoBox *b)
{
int width, height;
int i, max;
double h_height;
- cairo_t *cr;
double gstep;
int *data_p, *data_a, *data_b, *data_c, *data_i, *data_f;
int *data_r, *data_h, *data_excl;
int start, stop;
+ GtkAllocation allocation;
- cr = gdk_cairo_create(da->window);
-
- width = da->allocation.width;
- height = da->allocation.height;
+ gtk_widget_get_allocation(da, &allocation);
+ width = allocation.width;
+ height = allocation.height;
b->width = width; /* Store for later use when dragging */
/* Overall background */
@@ -478,8 +483,16 @@ static gboolean draw_sig(GtkWidget *da, GdkEventExpose *event, HistoBox *b)
draw_axis(cr, b, width, height);
draw_label(cr, b, width, height);
- cairo_destroy(cr);
+ return FALSE;
+}
+
+static gboolean expose_sig(GtkWidget *da, GdkEventExpose *event, HistoBox *b)
+{
+ cairo_t *cr;
+ cr = gdk_cairo_create(gtk_widget_get_window(da));
+ draw_sig(da, cr, b);
+ cairo_destroy(cr);
return FALSE;
}
@@ -510,11 +523,13 @@ static gint keyclick_sig(GtkWidget *widget, GdkEventButton *event,
CellWindow *w)
{
int width, cat;
+ GtkAllocation alloc;
/* Ignore extra events for double click */
if ( event->type != GDK_BUTTON_PRESS ) return FALSE;
- width = widget->allocation.width;
+ gtk_widget_get_allocation(widget, &alloc);
+ width = alloc.width;
cat = 8*event->x / width;
@@ -534,16 +549,15 @@ static gint keyclick_sig(GtkWidget *widget, GdkEventButton *event,
-static gboolean keydraw_sig(GtkWidget *da, GdkEventExpose *event, CellWindow *w)
+static gboolean keydraw_sig(GtkWidget *da, cairo_t *cr, CellWindow *w)
{
int width, height;
- cairo_t *cr;
double x;
+ GtkAllocation allocation;
- cr = gdk_cairo_create(da->window);
-
- width = da->allocation.width;
- height = da->allocation.height;
+ gtk_widget_get_allocation(da, &allocation);
+ width = allocation.width;
+ height = allocation.height;
/* Overall background */
cairo_rectangle(cr, 0.0, 0.0, width, height);
@@ -602,6 +616,17 @@ static gboolean keydraw_sig(GtkWidget *da, GdkEventExpose *event, CellWindow *w)
}
+static gboolean keyexpose_sig(GtkWidget *da, GdkEventExpose *event,
+ CellWindow *w)
+{
+ cairo_t *cr;
+ cr = gdk_cairo_create(gtk_widget_get_window(da));
+ keydraw_sig(da, cr, w);
+ cairo_destroy(cr);
+ return FALSE;
+}
+
+
static int check_exclude(HistoBox *h, double v)
{
double min, max;
@@ -647,7 +672,7 @@ static void scan_cells(CellWindow *w)
for ( i=0; i<n_cells; i++ ) {
double a, b, c, al, be, ga;
- int cat, j;
+ unsigned int cat, j;
int ignore = 0;
for ( j=0; j<w->n_unique_indms; j++ ) {
@@ -687,7 +712,7 @@ static void scan_cells(CellWindow *w)
check_exclude(w->hist_be, be) ||
check_exclude(w->hist_ga, ga) )
{
- cat = 1<<CAT_EXCLUDE;
+ cat = (unsigned)1<<CAT_EXCLUDE;
n_excl++;
}
@@ -1162,8 +1187,8 @@ static int write_cell_to_file(UnitCell *cell, const char *filename)
static gint savecell_sig(GtkWidget *widget, CellWindow *w)
{
GtkWidget *d;
- gchar *output_filename;
UnitCell *cell;
+ gint r;
cell = get_cell(w);
if ( cell == NULL ) return FALSE;
@@ -1176,19 +1201,19 @@ static gint savecell_sig(GtkWidget *widget, CellWindow *w)
NULL);
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(d),
TRUE);
+ r = gtk_dialog_run(GTK_DIALOG(d));
+ if ( r == GTK_RESPONSE_ACCEPT ) {
- if ( gtk_dialog_run(GTK_DIALOG(d)) == GTK_RESPONSE_CANCEL ) {
- gtk_widget_destroy(d);
- return FALSE;
- }
- output_filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(d));
+ gchar *output_filename;
- if ( write_cell_to_file(cell, output_filename) ) {
- error_box(w, "Failed to save unit cell");
- }
+ output_filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(d));
+ if ( write_cell_to_file(cell, output_filename) ) {
+ error_box(w, "Failed to save unit cell");
+ }
+ g_free(output_filename);
+ }
gtk_widget_destroy(d);
- g_free(output_filename);
return FALSE;
}
@@ -1205,7 +1230,7 @@ static gint about_sig(GtkWidget *widget, CellWindow *w)
window = gtk_about_dialog_new();
gtk_window_set_transient_for(GTK_WINDOW(window), GTK_WINDOW(w->window));
- gtk_about_dialog_set_name(GTK_ABOUT_DIALOG(window),
+ gtk_about_dialog_set_program_name(GTK_ABOUT_DIALOG(window),
"Unit Cell Explorer");
gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(window), "0.0.1");
gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(window),
@@ -1336,8 +1361,11 @@ static gint motion_sig(GtkWidget *da, GdkEventMotion *event, HistoBox *h)
gtk_widget_queue_draw(h->da);
- if ( event->is_hint ) gdk_window_get_pointer(da->window,
- NULL, NULL, NULL);
+ if ( event->is_hint ) {
+ gdk_window_get_pointer(gtk_widget_get_window(da),
+ NULL, NULL, NULL);
+ }
+
return TRUE;
}
@@ -1419,8 +1447,14 @@ static HistoBox *histobox_new(CellWindow *w, const char *units, const char *n)
| GDK_SCROLL_MASK
| GDK_KEY_PRESS_MASK);
- g_signal_connect(G_OBJECT(h->da), "expose_event", G_CALLBACK(draw_sig),
- h);
+ if ( g_signal_lookup("draw", GTK_TYPE_DRAWING_AREA) ) {
+ g_signal_connect(G_OBJECT(h->da), "draw",
+ G_CALLBACK(draw_sig), h);
+ } else {
+ g_signal_connect(G_OBJECT(h->da), "expose-event",
+ G_CALLBACK(expose_sig), h);
+ }
+
g_signal_connect(G_OBJECT(h->da), "button-press-event",
G_CALLBACK(press_sig), h);
g_signal_connect(G_OBJECT(h->da), "button-release-event",
@@ -1466,8 +1500,15 @@ static void indexing_method_list(CellWindow *w, GtkWidget *vbox)
key = gtk_drawing_area_new();
gtk_box_pack_end(GTK_BOX(w->indmlist), key, FALSE, FALSE, 5.0);
gtk_widget_add_events(GTK_WIDGET(key), GDK_BUTTON_PRESS_MASK);
- g_signal_connect(G_OBJECT(key), "expose_event", G_CALLBACK(keydraw_sig),
- w);
+
+ if ( g_signal_lookup("draw", GTK_TYPE_DRAWING_AREA) ) {
+ g_signal_connect(G_OBJECT(key), "draw",
+ G_CALLBACK(keydraw_sig), w);
+ } else {
+ g_signal_connect(G_OBJECT(key), "expose-event",
+ G_CALLBACK(keyexpose_sig), w);
+ }
+
g_signal_connect(G_OBJECT(key), "configure-event",
G_CALLBACK(keyconf_sig), w);
g_signal_connect(G_OBJECT(key), "button-press-event",