Commit 4cbc0191 authored by Matthias Clasen's avatar Matthias Clasen

widget-factory: Example for edge-overshot

For extra fun, make some noise.
parent 7b28b1c9
......@@ -1672,6 +1672,16 @@ if test "$have_colord" = "yes"; then
fi
AM_CONDITIONAL(HAVE_COLORD, test "x$have_colord" = "xyes")
##################################################
# Check for libcanberra (only used in examples)
##################################################
PKG_CHECK_MODULES(LIBCANBERRA, libcanberra-gtk3,
have_libcanberra=yes, have_libcanberra=no)
if test "$have_libcanberra" = "yes"; then
AC_DEFINE(HAVE_LIBCANBERRA, 1, [define if we have libcanberra])
fi
##################################################
# Checks for gtk-doc and docbook-tools
##################################################
......
......@@ -18,12 +18,14 @@ gtk3_widget_factory_DEPENDENCIES = \
gtk3_widget_factory_CPPFLAGS = \
-I$(top_srcdir) \
$(GTK_DEBUG_FLAGS) \
$(GTK_DEP_CFLAGS)
$(GTK_DEP_CFLAGS) \
$(LIBCANBERRA_CFLAGS)
gtk3_widget_factory_LDADD = \
$(top_builddir)/gdk/libgdk-3.la \
$(top_builddir)/gtk/libgtk-3.la \
$(GTK_DEP_LIBS)
$(GTK_DEP_LIBS) \
$(LIBCANBERRA_LIBS)
widget_factory_resources.c: widget-factory.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/widget-factory.gresource.xml)
$(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source $<
......
......@@ -19,8 +19,12 @@
*/
#include "config.h"
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#ifdef HAVE_LIBCANBERRA
#include <canberra-gtk.h>
#endif
static void
change_theme_state (GSimpleAction *action,
......@@ -574,6 +578,82 @@ update_title_header (GtkListBoxRow *row,
}
}
static void
overshot (GtkScrolledWindow *sw, GtkPositionType pos, GtkWidget *widget)
{
GtkWidget *box, *row, *label, *swatch;
GdkRGBA rgba;
const gchar *color;
gchar *text;
GtkWidget *silver;
GtkWidget *gold;
silver = GTK_WIDGET (g_object_get_data (G_OBJECT (widget), "Silver"));
gold = GTK_WIDGET (g_object_get_data (G_OBJECT (widget), "Gold"));
if (pos == GTK_POS_TOP)
{
if (silver)
{
gtk_container_remove (GTK_CONTAINER (widget), silver);
g_object_set_data (G_OBJECT (widget), "Silver", NULL);
}
if (gold)
{
gtk_container_remove (GTK_CONTAINER (widget), gold);
g_object_set_data (G_OBJECT (widget), "Gold", NULL);
}
#ifdef HAVE_LIBCANBERRA
if (silver || gold)
ca_gtk_play_for_widget (widget, 0, "event.id", "message", NULL);
#endif
return;
}
if (gold)
return;
else if (silver)
color = "Gold";
else
color = "Silver";
row = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 20);
text = g_strconcat ("<b>", color, "</b>", NULL);
label = gtk_label_new (text);
g_free (text);
g_object_set (label,
"use-markup", TRUE,
"halign", GTK_ALIGN_START,
"valign", GTK_ALIGN_CENTER,
"margin", 6,
"xalign", 0.0,
NULL);
gtk_box_pack_start (GTK_BOX (row), label, TRUE, TRUE, 0);
gdk_rgba_parse (&rgba, color);
swatch = g_object_new (g_type_from_name ("GtkColorSwatch"),
"rgba", &rgba,
"selectable", FALSE,
"halign", GTK_ALIGN_END,
"valign", GTK_ALIGN_CENTER,
"margin", 6,
"height-request", 24,
NULL);
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_container_add (GTK_CONTAINER (box), swatch);
gtk_box_pack_start (GTK_BOX (row), box, FALSE, FALSE, 0);
gtk_widget_show_all (row);
gtk_list_box_insert (GTK_LIST_BOX (widget), row, -1);
row = gtk_widget_get_parent (row);
gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (row), FALSE);
g_object_set_data (G_OBJECT (widget), color, row);
#ifdef HAVE_LIBCANBERRA
ca_gtk_play_for_widget (widget, 0, "event.id", "complete", NULL);
#endif
}
static void
populate_colors (GtkWidget *widget)
{
......@@ -621,6 +701,7 @@ populate_colors (GtkWidget *widget)
};
gint i;
GtkWidget *row, *box, *label, *swatch;
GtkWidget *sw;
GdkRGBA rgba;
gtk_list_box_set_header_func (GTK_LIST_BOX (widget), update_title_header, NULL, NULL);
......@@ -657,6 +738,9 @@ populate_colors (GtkWidget *widget)
}
gtk_list_box_invalidate_headers (GTK_LIST_BOX (widget));
sw = gtk_widget_get_ancestor (widget, GTK_TYPE_SCROLLED_WINDOW);
g_signal_connect (sw, "edge-overshot", G_CALLBACK (overshot), widget);
}
typedef struct {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment