summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile38
-rw-r--r--callbacks-gtk.h2
-rw-r--r--display-gtk.h6
-rw-r--r--download-dialog.c7
-rw-r--r--equipment.c85
-rw-r--r--gps.c2
-rw-r--r--gtk-gui.c117
-rw-r--r--info.c34
-rw-r--r--planner.c15
-rw-r--r--print.c2
-rw-r--r--statistics.c2
11 files changed, 167 insertions, 143 deletions
diff --git a/Makefile b/Makefile
index 660c2ff8a..8ddce2696 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
VERSION=2.1
CC=gcc
-CFLAGS=-Wall -Wno-pointer-sign -g $(CLCFLAGS)
+CFLAGS=-Wall -Wno-pointer-sign -g $(CLCFLAGS) -DGSEAL_ENABLE
INSTALL=install
PKGCONFIG=pkg-config
XML2CONFIG=xml2-config
@@ -90,7 +90,7 @@ LIBXML2 = $(shell $(XML2CONFIG) --libs)
LIBXSLT = $(shell $(XSLCONFIG) --libs)
XML2CFLAGS = $(shell $(XML2CONFIG) --cflags)
GLIB2CFLAGS = $(shell $(PKGCONFIG) --cflags glib-2.0)
-GTK2CFLAGS = $(shell $(PKGCONFIG) --cflags gtk+-2.0)
+GTKCFLAGS = $(shell $(PKGCONFIG) --cflags gtk+-2.0)
CFLAGS += $(shell $(XSLCONFIG) --cflags)
OSMGPSMAPFLAGS += $(shell $(PKGCONFIG) --cflags osmgpsmap)
LIBOSMGPSMAP += $(shell $(PKGCONFIG) --libs osmgpsmap 2> /dev/null)
@@ -110,10 +110,10 @@ ifeq ($(UNAME), linux)
LIBGCONF2 = $(shell $(PKGCONFIG) --libs gconf-2.0)
GCONF2CFLAGS = $(shell $(PKGCONFIG) --cflags gconf-2.0)
OSSUPPORT = linux
- OSSUPPORT_CFLAGS = $(GTK2CFLAGS) $(GCONF2CFLAGS)
+ OSSUPPORT_CFLAGS = $(GTKCFLAGS) $(GCONF2CFLAGS)
else ifeq ($(UNAME), darwin)
OSSUPPORT = macos
- OSSUPPORT_CFLAGS = $(GTK2CFLAGS)
+ OSSUPPORT_CFLAGS = $(GTKCFLAGS)
MACOSXINSTALL = /Applications/Subsurface.app
MACOSXFILES = packaging/macosx
MACOSXSTAGING = $(MACOSXFILES)/Subsurface.app
@@ -123,7 +123,7 @@ else ifeq ($(UNAME), darwin)
GTK_MAC_BUNDLER = ~/.local/bin/gtk-mac-bundler
else
OSSUPPORT = windows
- OSSUPPORT_CFLAGS = $(GTK2CFLAGS)
+ OSSUPPORT_CFLAGS = $(GTKCFLAGS)
WINDOWSSTAGING = ./packaging/windows
WINMSGDIRS=$(addprefix share/locale/,$(shell ls po/*.po | sed -e 's/po\/\(..\)_.*/\1\/LC_MESSAGES/'))
NSIINPUTFILE = $(WINDOWSSTAGING)/subsurface.nsi.in
@@ -249,19 +249,19 @@ main.o: main.c dive.h display.h divelist.h
$(CC) $(CFLAGS) $(GLIB2CFLAGS) $(GCONF2CFLAGS) $(XML2CFLAGS) -c main.c
profile.o: profile.c dive.h display.h divelist.h
- $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c profile.c
+ $(CC) $(CFLAGS) $(GTKCFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c profile.c
info.o: info.c dive.h display.h display-gtk.h divelist.h
- $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c info.c
+ $(CC) $(CFLAGS) $(GTKCFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c info.c
equipment.o: equipment.c dive.h display.h divelist.h
- $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c equipment.c
+ $(CC) $(CFLAGS) $(GTKCFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c equipment.c
statistics.o: statistics.c dive.h display.h divelist.h
- $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c statistics.c
+ $(CC) $(CFLAGS) $(GTKCFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c statistics.c
gps.o: gps.c dive.h display.h divelist.h
- $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) $(OSMGPSMAPFLAGS) -c gps.c
+ $(CC) $(CFLAGS) $(GTKCFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) $(OSMGPSMAPFLAGS) -c gps.c
# this should work but it doesn't preserve the transparancy - so I manually converted with gimp
# satellite.png: satellite.svg
@@ -271,36 +271,36 @@ gps.o: gps.c dive.h display.h divelist.h
# gdk-pixbuf-csource --struct satellite.png > satellite.h
divelist.o: divelist.c dive.h display.h divelist.h satellite.h
- $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c divelist.c
+ $(CC) $(CFLAGS) $(GTKCFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c divelist.c
print.o: print.c dive.h display.h display-gtk.h
- $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c print.c
+ $(CC) $(CFLAGS) $(GTKCFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c print.c
deco.o: deco.c dive.h
$(CC) $(CFLAGS) $(GLIB2CFLAGS) -c deco.c
planner.o: planner.c dive.h divelist.h display-gtk.h
- $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) -c planner.c
+ $(CC) $(CFLAGS) $(GTKCFLAGS) $(GLIB2CFLAGS) -c planner.c
download-dialog.o: download-dialog.c dive.h divelist.h display-gtk.h callbacks-gtk.h
- $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) -c download-dialog.c
+ $(CC) $(CFLAGS) $(GTKCFLAGS) $(GLIB2CFLAGS) -c download-dialog.c
libdivecomputer.o: libdivecomputer.c dive.h display.h display-gtk.h libdivecomputer.h device.h
- $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) \
+ $(CC) $(CFLAGS) $(GTKCFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) \
$(LIBDIVECOMPUTERCFLAGS) \
-c libdivecomputer.c
gtk-gui.o: gtk-gui.c dive.h display.h divelist.h display-gtk.h libdivecomputer.h device.h callbacks-gtk.h Makefile
- $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(GCONF2CFLAGS) $(XML2CFLAGS) \
+ $(CC) $(CFLAGS) $(GTKCFLAGS) $(GLIB2CFLAGS) $(GCONF2CFLAGS) $(XML2CFLAGS) \
$(LIBDIVECOMPUTERCFLAGS) \
-DVERSION_STRING='"$(VERSION_STRING)"' \
-c gtk-gui.c
uemis.o: uemis.c dive.h uemis.h
- $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) $(LIBDIVECOMPUTERCFLAGS) -c uemis.c
+ $(CC) $(CFLAGS) $(GTKCFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) $(LIBDIVECOMPUTERCFLAGS) -c uemis.c
uemis-downloader.o: uemis-downloader.c dive.h uemis.h
- $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c uemis-downloader.c
+ $(CC) $(CFLAGS) $(GTKCFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c uemis-downloader.c
device.o: device.c device.h dive.h
$(CC) $(CFLAGS) $(GLIB2CFLAGS) -c device.c
@@ -309,7 +309,7 @@ prefs.o: prefs.c dive.h pref.h
$(CC) $(CFLAGS) $(GLIB2CFLAGS) -c prefs.c
webservice.o: webservice.c webservice.h dive.h display-gtk.h
- $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) $(LIBSOUPCFLAGS) -c webservice.c
+ $(CC) $(CFLAGS) $(GTKCFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) $(LIBSOUPCFLAGS) -c webservice.c
$(OSSUPPORT).o: $(OSSUPPORT).c display-gtk.h
$(CC) $(CFLAGS) $(OSSUPPORT_CFLAGS) -c $(OSSUPPORT).c
diff --git a/callbacks-gtk.h b/callbacks-gtk.h
index 017a8c0ae..08c159b4d 100644
--- a/callbacks-gtk.h
+++ b/callbacks-gtk.h
@@ -10,7 +10,7 @@ static void name(GtkWidget *w, gpointer data) \
static void name(GtkWidget *w, gpointer data) \
{ \
GtkWidget **entry = data; \
- option = GTK_TOGGLE_BUTTON(w)->active; \
+ option = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)); \
update_screen(); \
if (entry) \
gtk_widget_set_sensitive(*entry, option);\
diff --git a/display-gtk.h b/display-gtk.h
index 07dc58123..dcab97aa0 100644
--- a/display-gtk.h
+++ b/display-gtk.h
@@ -73,6 +73,12 @@ extern GtkWidget *dive_list_create(void);
extern void dive_list_destroy(void);
extern GdkPixbuf *get_gps_icon(void);
+/* Helper functions for gtk combo boxes */
+extern GtkEntry *get_entry(GtkComboBox *);
+extern const char *get_active_text(GtkComboBox *);
+extern void set_active_text(GtkComboBox *, const char *);
+extern GtkWidget *combo_box_with_model_and_entry(GtkListStore *);
+
extern gboolean icon_click_cb(GtkWidget *w, GdkEventButton *event, gpointer data);
unsigned int amount_selected;
diff --git a/download-dialog.c b/download-dialog.c
index 73ed4bac9..6237004d9 100644
--- a/download-dialog.c
+++ b/download-dialog.c
@@ -330,7 +330,7 @@ static GtkComboBox *dc_device_selector(GtkWidget *vbox)
frame = gtk_frame_new(_("Device or mount point"));
gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, TRUE, 3);
- combo_box = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(model), 0);
+ combo_box = combo_box_with_model_and_entry(model);
gtk_container_add(GTK_CONTAINER(frame), combo_box);
renderer = gtk_cell_renderer_text_new();
@@ -340,8 +340,7 @@ static GtkComboBox *dc_device_selector(GtkWidget *vbox)
gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), default_index);
else
if (default_dive_computer_device)
- gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo_box))),
- default_dive_computer_device);
+ set_active_text(GTK_COMBO_BOX(combo_box), default_dive_computer_device);
return GTK_COMBO_BOX(combo_box);
}
@@ -430,7 +429,7 @@ repeat:
set_default_dive_computer(vendor, product);
/* get the device name from the combo box entry and set as default */
- devname = strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(device)))));
+ devname = strdup(get_active_text(device));
set_default_dive_computer_device(devname);
/* clear leading and trailing white space from the device name and also
* everything after (and including) the first '(' char. */
diff --git a/equipment.c b/equipment.c
index 7f69e5c70..98162c9b9 100644
--- a/equipment.c
+++ b/equipment.c
@@ -119,6 +119,12 @@ static int convert_weight(int grams, double *m)
return decimals;
}
+static void set_cylinder_description(struct cylinder_widget *cylinder, const char *desc)
+{
+ set_active_text(cylinder->description, desc);
+}
+
+
static void set_cylinder_type_spinbuttons(struct cylinder_widget *cylinder, int ml, int mbar)
{
double volume, pressure;
@@ -151,6 +157,11 @@ static void set_cylinder_pressure_spinbuttons(struct cylinder_widget *cylinder,
gtk_spin_button_set_value(GTK_SPIN_BUTTON(cylinder->end), pressure);
}
+static void set_weight_description(struct ws_widget *ws_widget, const char *desc)
+{
+ set_active_text(ws_widget->description, desc);
+}
+
static void set_weight_weight_spinbutton(struct ws_widget *ws_widget, int grams)
{
double weight;
@@ -185,17 +196,16 @@ static gboolean match_desc(GtkTreeModel *model, GtkTreePath *path,
static int get_active_item(GtkComboBox *combo_box, GtkTreeIter *iter, GtkListStore *model)
{
- char *desc;
+ const char *desc;
if (gtk_combo_box_get_active_iter(combo_box, iter))
return TRUE;
- desc = gtk_combo_box_get_active_text(combo_box);
+ desc = get_active_text(combo_box);
found_match = NULL;
gtk_tree_model_foreach(GTK_TREE_MODEL(model), match_desc, (void *)desc);
- g_free(desc);
if (!found_match)
return FALSE;
@@ -232,10 +242,9 @@ static void cylinder_cb(GtkComboBox *combo_box, gpointer data)
*/
if (!cylinder->changed && cyl->type.description) {
int same;
- char *desc = gtk_combo_box_get_active_text(combo_box);
+ const char *desc = get_active_text(combo_box);
same = !strcmp(desc, cyl->type.description);
- g_free(desc);
if (same)
return;
}
@@ -276,10 +285,9 @@ static void weight_cb(GtkComboBox *combo_box, gpointer data)
*/
if (!ws_widget->changed && ws->description) {
int same;
- char *desc = gtk_combo_box_get_active_text(combo_box);
+ const char *desc = get_active_text(combo_box);
same = !strcmp(desc, ws->description);
- g_free(desc);
if (same)
return;
}
@@ -361,12 +369,10 @@ void add_cylinder_description(cylinder_type_t *type)
static void add_cylinder(struct cylinder_widget *cylinder, const char *desc, int ml, int mbar)
{
- GtkTreeIter iter, *match;
+ GtkTreeIter iter;
cylinder->name = desc;
- match = add_cylinder_type(desc, ml, mbar, &iter);
- if (match)
- gtk_combo_box_set_active_iter(cylinder->description, match);
+ add_cylinder_type(desc, ml, mbar, &iter);
}
void add_weightsystem_description(weightsystem_t *weightsystem)
@@ -384,12 +390,10 @@ void add_weightsystem_description(weightsystem_t *weightsystem)
static void add_weightsystem(struct ws_widget *ws_widget, const char *desc, int weight)
{
- GtkTreeIter iter, *match;
+ GtkTreeIter iter;
ws_widget->name = desc;
- match = add_weightsystem_type(desc, weight, &iter);
- if (match)
- gtk_combo_box_set_active_iter(ws_widget->description, match);
+ add_weightsystem_type(desc, weight, &iter);
}
static void show_cylinder(cylinder_t *cyl, struct cylinder_widget *cylinder)
@@ -410,6 +414,7 @@ static void show_cylinder(cylinder_t *cyl, struct cylinder_widget *cylinder)
mbar = cyl->type.workingpressure.mbar;
add_cylinder(cylinder, desc, ml, mbar);
+ set_cylinder_description(cylinder, desc);
set_cylinder_type_spinbuttons(cylinder,
cyl->type.size.mliter, cyl->type.workingpressure.mbar);
set_cylinder_pressure_spinbuttons(cylinder, cyl);
@@ -442,6 +447,7 @@ static void show_weightsystem(weightsystem_t *ws, struct ws_widget *weightsystem
grams = ws->weight.grams;
add_weightsystem(weightsystem_widget, desc, grams);
+ set_weight_description(weightsystem_widget, desc);
set_weight_weight_spinbutton(weightsystem_widget, ws->weight.grams);
}
@@ -679,7 +685,7 @@ static void record_cylinder_changes(cylinder_t *cyl, struct cylinder_widget *cyl
if (!box)
return;
- desc = gtk_combo_box_get_active_text(box);
+ desc = strdup(get_active_text(box));
volume = gtk_spin_button_get_value(cylinder->size);
pressure = gtk_spin_button_get_value(cylinder->pressure);
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cylinder->pressure_button))) {
@@ -711,7 +717,7 @@ static void record_weightsystem_changes(weightsystem_t *ws, struct ws_widget *we
if (!box)
return;
- desc = gtk_combo_box_get_active_text(box);
+ desc = strdup(get_active_text(box));
value = gtk_spin_button_get_value(weightsystem_widget->weight);
if (prefs.units.weight == LBS)
@@ -869,16 +875,6 @@ static void pressure_cb(GtkToggleButton *button, gpointer data)
gtk_widget_set_sensitive(cylinder->end, state);
}
-static gboolean completion_cb(GtkEntryCompletion *widget, GtkTreeModel *model, GtkTreeIter *iter, struct cylinder_widget *cylinder)
-{
- const char *desc;
- unsigned int ml, mbar;
-
- gtk_tree_model_get(model, iter, CYL_DESC, &desc, CYL_SIZE, &ml, CYL_WORKP, &mbar, -1);
- add_cylinder(cylinder, desc, ml, mbar);
- return TRUE;
-}
-
static void cylinder_activate_cb(GtkComboBox *combo_box, gpointer data)
{
struct cylinder_widget *cylinder = data;
@@ -923,8 +919,6 @@ static GtkWidget *labeled_spinbutton(GtkWidget *box, const char *name, double mi
static void cylinder_widget(GtkWidget *vbox, struct cylinder_widget *cylinder, GtkListStore *model)
{
GtkWidget *frame, *hbox;
- GtkEntry *entry;
- GtkEntryCompletion *completion;
GtkWidget *widget;
/*
@@ -936,21 +930,13 @@ static void cylinder_widget(GtkWidget *vbox, struct cylinder_widget *cylinder, G
hbox = gtk_hbox_new(FALSE, 3);
gtk_container_add(GTK_CONTAINER(frame), hbox);
- widget = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(model), 0);
+ widget = combo_box_with_model_and_entry(model);
gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
cylinder->description = GTK_COMBO_BOX(widget);
g_signal_connect(widget, "changed", G_CALLBACK(cylinder_cb), cylinder);
- entry = GTK_ENTRY(GTK_BIN(widget)->child);
- g_signal_connect(entry, "activate", G_CALLBACK(cylinder_activate_cb), cylinder);
-
- completion = gtk_entry_completion_new();
- gtk_entry_completion_set_text_column(completion, 0);
- gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(model));
- g_signal_connect(completion, "match-selected", G_CALLBACK(completion_cb), cylinder);
- gtk_entry_set_completion(entry, completion);
- g_object_unref(completion);
+ g_signal_connect(get_entry(GTK_COMBO_BOX(widget)), "activate", G_CALLBACK(cylinder_activate_cb), cylinder);
hbox = gtk_hbox_new(FALSE, 3);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
@@ -991,16 +977,6 @@ static void cylinder_widget(GtkWidget *vbox, struct cylinder_widget *cylinder, G
g_signal_connect(cylinder->gasmix_button, "toggled", G_CALLBACK(gasmix_cb), cylinder);
}
-static gboolean weight_completion_cb(GtkEntryCompletion *widget, GtkTreeModel *model, GtkTreeIter *iter, struct ws_widget *ws_widget)
-{
- const char *desc;
- unsigned int weight;
-
- gtk_tree_model_get(model, iter, WS_DESC, &desc, WS_WEIGHT, &weight, -1);
- add_weightsystem(ws_widget, desc, weight);
- return TRUE;
-}
-
static void weight_activate_cb(GtkComboBox *combo_box, gpointer data)
{
struct ws_widget *ws_widget = data;
@@ -1010,7 +986,6 @@ static void weight_activate_cb(GtkComboBox *combo_box, gpointer data)
static void ws_widget(GtkWidget *vbox, struct ws_widget *ws_widget, GtkListStore *model)
{
GtkWidget *frame, *hbox;
- GtkEntryCompletion *completion;
GtkWidget *widget;
GtkEntry *entry;
@@ -1022,21 +997,15 @@ static void ws_widget(GtkWidget *vbox, struct ws_widget *ws_widget, GtkListStore
hbox = gtk_hbox_new(FALSE, 3);
gtk_container_add(GTK_CONTAINER(frame), hbox);
- widget = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(model), 0);
+ widget = combo_box_with_model_and_entry(model);
gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
ws_widget->description = GTK_COMBO_BOX(widget);
g_signal_connect(widget, "changed", G_CALLBACK(weight_cb), ws_widget);
- entry = GTK_ENTRY(GTK_BIN(widget)->child);
+ entry = get_entry(GTK_COMBO_BOX(widget));
g_signal_connect(entry, "activate", G_CALLBACK(weight_activate_cb), ws_widget);
- completion = gtk_entry_completion_new();
- gtk_entry_completion_set_text_column(completion, 0);
- gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(model));
- g_signal_connect(completion, "match-selected", G_CALLBACK(weight_completion_cb), ws_widget);
- gtk_entry_set_completion(entry, completion);
-
hbox = gtk_hbox_new(FALSE, 3);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, TRUE, 0);
diff --git a/gps.c b/gps.c
index 4a2b527b8..3fd6fd67c 100644
--- a/gps.c
+++ b/gps.c
@@ -181,7 +181,7 @@ void show_map(OsmGpsMap *map, GtkWidget **window, struct dive *dive, void (*call
gtk_window_set_default_size(GTK_WINDOW(*window), 640, 480);
gtk_window_set_title(GTK_WINDOW(*window), _("Dives locations"));
gtk_container_set_border_width(GTK_CONTAINER(*window), 5);
- GTK_WINDOW(*window)->allow_shrink = TRUE;
+ gtk_window_set_resizable(GTK_WINDOW(*window), TRUE);
gtk_container_add(GTK_CONTAINER(*window), GTK_WIDGET(map));
g_signal_connect(*window, "destroy", G_CALLBACK(on_close), (gpointer)window);
g_signal_connect(G_OBJECT(map), "scroll-event", G_CALLBACK(scroll_cb), NULL);
diff --git a/gtk-gui.c b/gtk-gui.c
index f6d81aca9..d4f6acd53 100644
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -121,7 +121,7 @@ void report_error(GError* error)
error_count++;
char buffer[256];
snprintf(buffer, sizeof(buffer), _("Failed to open %i files."), error_count);
- gtk_label_set(GTK_LABEL(error_label), buffer);
+ gtk_label_set_text(GTK_LABEL(error_label), buffer);
}
}
@@ -397,7 +397,6 @@ GtkTreeViewColumn *tree_view_column(GtkWidget *tree_view, int index, const char
gtk_tree_view_column_set_cell_data_func(col, renderer, data_func, (void *)(long)index, NULL);
else
gtk_tree_view_column_add_attribute(col, renderer, "text", index);
- gtk_object_set(GTK_OBJECT(renderer), "alignment", align, NULL);
switch (align) {
case PANGO_ALIGN_LEFT:
xalign = 0.0;
@@ -415,6 +414,42 @@ GtkTreeViewColumn *tree_view_column(GtkWidget *tree_view, int index, const char
return col;
}
+/* Helper functions for gtk combo boxes */
+GtkEntry *get_entry(GtkComboBox *combo_box)
+{
+ return GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo_box)));
+}
+
+const char *get_active_text(GtkComboBox *combo_box)
+{
+ return gtk_entry_get_text(get_entry(combo_box));
+}
+
+void set_active_text(GtkComboBox *combo_box, const char *text)
+{
+ gtk_entry_set_text(get_entry(combo_box), text);
+}
+
+GtkWidget *combo_box_with_model_and_entry(GtkListStore *model)
+{
+ GtkWidget *widget;
+ GtkEntryCompletion *completion;
+
+ widget = gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL(model));
+ gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(widget), 0);
+
+ completion = gtk_entry_completion_new();
+ gtk_entry_completion_set_text_column(completion, 0);
+ gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(model));
+ gtk_entry_completion_set_inline_completion(completion, TRUE);
+ gtk_entry_completion_set_inline_selection(completion, TRUE);
+ gtk_entry_completion_set_popup_single_match(completion, FALSE);
+ gtk_entry_set_completion(get_entry(GTK_COMBO_BOX(widget)), completion);
+ g_object_unref(completion);
+
+ return widget;
+}
+
static void create_radio(GtkWidget *vbox, const char *w_name, ...)
{
va_list args;
@@ -514,7 +549,7 @@ static void event_toggle(GtkWidget *w, gpointer _data)
{
gboolean *plot_ev = _data;
- *plot_ev = GTK_TOGGLE_BUTTON(w)->active;
+ *plot_ev = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w));
}
static void pick_default_file(GtkWidget *w, GtkButton *button)
@@ -584,7 +619,8 @@ static void preferences_dialog(GtkWidget *w, gpointer data)
/* create the notebook for the preferences and attach it to dialog */
notebook = gtk_notebook_new();
- gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), notebook, FALSE, FALSE, 5);
+ vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+ gtk_box_pack_start(GTK_BOX(vbox), notebook, FALSE, FALSE, 5);
/* vbox that holds the first notebook page */
vbox = gtk_vbox_new(FALSE, 6);
@@ -1005,6 +1041,7 @@ static void about_dialog(GtkWidget *w, gpointer data)
{
const char *logo_property = NULL;
GdkPixbuf *logo = NULL;
+ GtkWidget * dialog;
if (need_icon) {
GtkWidget *image = gtk_image_new_from_file(subsurface_icon_name());
@@ -1014,6 +1051,12 @@ static void about_dialog(GtkWidget *w, gpointer data)
logo_property = "logo";
}
}
+ dialog = gtk_about_dialog_new();
+#if !GTK_CHECK_VERSION(2,24,0) /* F*cking gtk */
+ gtk_about_dialog_set_url_hook(about_dialog_link_cb, NULL, NULL);
+#else
+ g_signal_connect(GTK_ABOUT_DIALOG(dialog), "activate-link", G_CALLBACK(about_dialog_link_cb), NULL);
+#endif
gtk_show_about_dialog(NULL,
"title", _("About Subsurface"),
"program-name", "Subsurface",
@@ -1028,7 +1071,6 @@ static void about_dialog(GtkWidget *w, gpointer data)
/* Must be last: */
logo_property, logo,
NULL);
- gtk_about_dialog_set_url_hook(about_dialog_link_cb, NULL, NULL);
}
static void view_list(GtkWidget *w, gpointer data)
@@ -1659,29 +1701,23 @@ static gboolean profile_tooltip (GtkWidget *widget, gint x, gint y,
static double zoom_factor = 1.0;
static int zoom_x = -1, zoom_y = -1;
-static gboolean expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data)
+static gboolean common_drawing_function(GtkWidget *widget, struct graphics_context *gc)
{
int i = 0;
struct dive *dive = current_dive;
- static struct graphics_context gc = { .printer = 0 };
- /* the drawing area gives TOTAL width * height - x,y is used as the topx/topy offset
- * so effective drawing area is width-2x * height-2y */
- gc.drawing_area.width = widget->allocation.width;
- gc.drawing_area.height = widget->allocation.height;
- gc.drawing_area.x = MIN(50,gc.drawing_area.width / 20.0);
- gc.drawing_area.y = MIN(50,gc.drawing_area.height / 20.0);
+ gc->drawing_area.x = MIN(50,gc->drawing_area.width / 20.0);
+ gc->drawing_area.y = MIN(50,gc->drawing_area.height / 20.0);
- gc.cr = gdk_cairo_create(widget->window);
g_object_set(widget, "has-tooltip", TRUE, NULL);
- g_signal_connect(widget, "query-tooltip", G_CALLBACK(profile_tooltip), &gc);
- init_profile_background(&gc);
- cairo_paint(gc.cr);
+ g_signal_connect(widget, "query-tooltip", G_CALLBACK(profile_tooltip), gc);
+ init_profile_background(gc);
+ cairo_paint(gc->cr);
if (zoom_factor > 1.0) {
double n = -(zoom_factor-1);
- cairo_translate(gc.cr, n*zoom_x, n*zoom_y);
- cairo_scale(gc.cr, zoom_factor, zoom_factor);
+ cairo_translate(gc->cr, n*zoom_x, n*zoom_y);
+ cairo_scale(gc->cr, zoom_factor, zoom_factor);
}
if (dive) {
@@ -1695,13 +1731,48 @@ static gboolean expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer
tooltip_rects = NULL;
}
tooltips = 0;
- plot(&gc, dive, SC_SCREEN);
+ plot(gc, dive, SC_SCREEN);
}
- cairo_destroy(gc.cr);
return FALSE;
}
+#if GTK_CHECK_VERSION(3,0,0)
+
+static gboolean draw_callback(GtkWidget *widget, cairo_t *cr, gpointer data)
+{
+ guint width, height;
+ static struct graphics_context gc = { .printer = 0 };
+
+ width = gtk_widget_get_allocated_width(widget);
+ height = gtk_widget_get_allocated_height(widget);
+
+ gc.drawing_area.width = width;
+ gc.drawing_area.height = height;
+ gc.cr = cr;
+
+ return common_drawing_function(widget, &gc);
+}
+
+#else /* gtk2 */
+
+static gboolean expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data)
+{
+ GtkAllocation allocation;
+ static struct graphics_context gc = { .printer = 0 };
+
+ /* the drawing area gives TOTAL width * height - x,y is used as the topx/topy offset
+ * so effective drawing area is width-2x * height-2y */
+ gtk_widget_get_allocation(widget, &allocation);
+ gc.drawing_area.width = allocation.width;
+ gc.drawing_area.height = allocation.height;
+ gc.cr = gdk_cairo_create(gtk_widget_get_window(widget));
+
+ return common_drawing_function(widget, &gc);
+}
+
+#endif
+
static void zoom_event(int x, int y, double inc)
{
zoom_x = x;
@@ -1776,7 +1847,11 @@ GtkWidget *dive_profile_widget(void)
da = gtk_drawing_area_new();
gtk_widget_set_size_request(da, 350, 250);
+#if GTK_CHECK_VERSION(3,0,0)
+ g_signal_connect(da, "draw", G_CALLBACK (draw_callback), NULL);
+#else
g_signal_connect(da, "expose_event", G_CALLBACK(expose_event), NULL);
+#endif
g_signal_connect(da, "button-press-event", G_CALLBACK(clicked), NULL);
g_signal_connect(da, "scroll-event", G_CALLBACK(scroll_event), NULL);
g_signal_connect(da, "button-release-event", G_CALLBACK(released), NULL);
diff --git a/info.c b/info.c
index ed7f954dc..e4f62e091 100644
--- a/info.c
+++ b/info.c
@@ -61,12 +61,11 @@ static const char *skip_space(const char *str)
* The "master" string is the string of the current dive - we only consider it
* changed if the old string is either empty, or matches that master string.
*/
-static char *get_combo_box_entry_text(GtkComboBoxEntry *combo_box, char **textp, const char *master)
+static char *get_combo_box_entry_text(GtkComboBox *combo_box, char **textp, const char *master)
{
char *old = *textp;
const char *old_text;
const gchar *new;
- GtkEntry *entry;
old_text = skip_space(old);
master = skip_space(master);
@@ -81,8 +80,7 @@ static char *get_combo_box_entry_text(GtkComboBoxEntry *combo_box, char **textp,
if (strcmp(master, old_text))
return NULL;
- entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo_box)));
- new = gtk_entry_get_text(entry);
+ new = get_active_text(combo_box);
while (isspace(*new))
new++;
/* If the master string didn't change, don't change other dives either! */
@@ -202,7 +200,7 @@ static void info_menu_edit_cb(GtkMenuItem *menuitem, gpointer user_data)
edit_multi_dive_info(NULL);
}
-static void add_menu_item(GtkMenu *menu, const char *label, const char *icon, void (*cb)(GtkMenuItem *, gpointer))
+static void add_menu_item(GtkMenuShell *menu, const char *label, const char *icon, void (*cb)(GtkMenuItem *, gpointer))
{
GtkWidget *item;
if (icon) {
@@ -215,10 +213,10 @@ static void add_menu_item(GtkMenu *menu, const char *label, const char *icon, vo
}
g_signal_connect(item, "activate", G_CALLBACK(cb), NULL);
gtk_widget_show(item); /* Yes, really */
- gtk_menu_prepend(menu, item);
+ gtk_menu_shell_prepend(menu, item);
}
-static void populate_popup_cb(GtkTextView *entry, GtkMenu *menu, gpointer user_data)
+static void populate_popup_cb(GtkTextView *entry, GtkMenuShell *menu, gpointer user_data)
{
if (amount_selected)
add_menu_item(menu, _("Edit"), GTK_STOCK_EDIT, info_menu_edit_cb);
@@ -251,32 +249,20 @@ static GtkEntry *single_text_entry(GtkWidget *box, const char *label, const char
return entry;
}
-static GtkComboBoxEntry *text_entry(GtkWidget *box, const char *label, GtkListStore *completions, const char *text)
+static GtkComboBox *text_entry(GtkWidget *box, const char *label, GtkListStore *completions, const char *text)
{
- GtkEntry *entry;
GtkWidget *combo_box;
GtkWidget *frame = gtk_frame_new(label);
- GtkEntryCompletion *completion;
gtk_box_pack_start(GTK_BOX(box), frame, FALSE, TRUE, 0);
- combo_box = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(completions), 0);
+ combo_box = combo_box_with_model_and_entry(completions);
gtk_container_add(GTK_CONTAINER(frame), combo_box);
- entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo_box)));
if (text && *text)
- gtk_entry_set_text(entry, text);
-
- completion = gtk_entry_completion_new();
- gtk_entry_completion_set_text_column(completion, 0);
- gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(completions));
- gtk_entry_completion_set_inline_completion(completion, TRUE);
- gtk_entry_completion_set_inline_selection(completion, TRUE);
- gtk_entry_completion_set_popup_single_match(completion, FALSE);
- gtk_entry_set_completion(entry, completion);
- g_object_unref(completion);
+ set_active_text(GTK_COMBO_BOX(combo_box), text);
- return GTK_COMBO_BOX_ENTRY(combo_box);
+ return GTK_COMBO_BOX(combo_box);
}
enum writable {
@@ -518,7 +504,7 @@ static gboolean gps_changed(struct dive *dive, struct dive *master, const char *
}
struct dive_info {
- GtkComboBoxEntry *location, *divemaster, *buddy, *rating, *suit, *viz;
+ GtkComboBox *location, *divemaster, *buddy, *rating, *suit, *viz;
GtkEntry *airtemp, *gps;
GtkWidget *gps_icon;
GtkTextView *notes;
diff --git a/planner.c b/planner.c
index f58eec537..1b63a768f 100644
--- a/planner.c
+++ b/planner.c
@@ -931,7 +931,7 @@ static void gas_changed_cb(GtkWidget *combo, gpointer data)
int o2, he;
int idx = data - NULL;
- gastext = gtk_combo_box_get_active_text(GTK_COMBO_BOX(combo));
+ gastext = get_active_text(GTK_COMBO_BOX(combo));
/* stupidly this gets called for two reasons:
* a) any keystroke into the entry field
* b) mouse selection of a dropdown
@@ -1045,8 +1045,6 @@ static gboolean gf_focus_out_cb(GtkWidget *entry, GdkEvent * event, gpointer dat
static GtkWidget *add_gas_combobox_to_box(GtkWidget *box, const char *label, int idx)
{
GtkWidget *frame, *combo;
- GtkEntryCompletion *completion;
- GtkEntry *entry;
if (!gas_model) {
gas_model = gtk_list_store_new(1, G_TYPE_STRING);
@@ -1054,7 +1052,7 @@ static GtkWidget *add_gas_combobox_to_box(GtkWidget *box, const char *label, int
add_string_list_entry("EAN32", gas_model);
add_string_list_entry("EAN36 @ 1.6", gas_model);
}
- combo = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(gas_model), 0);
+ combo = combo_box_with_model_and_entry(gas_model);
gtk_widget_add_events(combo, GDK_FOCUS_CHANGE_MASK);
g_signal_connect(gtk_bin_get_child(GTK_BIN(combo)), "focus-out-event", G_CALLBACK(gas_focus_out_cb), NULL + idx);
g_signal_connect(combo, "changed", G_CALLBACK(gas_changed_cb), NULL + idx);
@@ -1065,15 +1063,6 @@ static GtkWidget *add_gas_combobox_to_box(GtkWidget *box, const char *label, int
} else {
gtk_box_pack_start(GTK_BOX(box), combo, FALSE, FALSE, 2);
}
- entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo)));
- completion = gtk_entry_completion_new();
- gtk_entry_completion_set_text_column(completion, 0);
- gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(gas_model));
- gtk_entry_completion_set_inline_completion(completion, TRUE);
- gtk_entry_completion_set_inline_selection(completion, TRUE);
- gtk_entry_completion_set_popup_single_match(completion, FALSE);
- gtk_entry_set_completion(entry, completion);
- g_object_unref(completion);
return combo;
}
diff --git a/print.c b/print.c
index c2a71a1e4..eb6c2af79 100644
--- a/print.c
+++ b/print.c
@@ -877,7 +877,7 @@ OPTIONCALLBACK(set_oneperpage, type, ONEPERPAGE)
#define OPTIONSELECTEDCALLBACK(name, option) \
static void name(GtkWidget *w, gpointer data) \
{ \
- option = GTK_TOGGLE_BUTTON(w)->active; \
+ option = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)); \
}
OPTIONSELECTEDCALLBACK(print_selection_toggle, print_options.print_selected)
diff --git a/statistics.c b/statistics.c
index 2efc3947a..794678bc2 100644
--- a/statistics.c
+++ b/statistics.c
@@ -395,7 +395,7 @@ void show_yearly_stats()
gtk_window_set_default_size(GTK_WINDOW(window), 640, 480);
gtk_window_set_title(GTK_WINDOW(window), _("Yearly Statistics"));
gtk_container_set_border_width(GTK_CONTAINER(window), 5);
- GTK_WINDOW(window)->allow_shrink = TRUE;
+ gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_ETCHED_IN);