diff options
author | Philip Chimento <philip@endlessm.com> | 2014-01-08 16:51:39 -0500 |
---|---|---|
committer | Philip Chimento <philip@endlessm.com> | 2015-03-25 17:42:34 -0700 |
commit | 67c212e47a1db5f3e3dd1abaf552052e46512c93 (patch) | |
tree | 84d7d7906b033e502561c4136efeda68312cc6bc /endless/eoscellrenderertextlink.c | |
parent | 88a142a202a3ae5e82f222cbb5ce75372d66e719 (diff) |
Initial implementation of image credits
This is a rough implementation of an "About"-like dialog for image
attribution in SDK applications. You can press the 'secret' hotkey
Shift+Ctrl+A to get a dialog with thumbnails and attribution information
for the images in the app's GResource. Clicking on the thumbnail opens
the image's original URI in the browser, if known. Clicking on the text
opens the image's license text in the browser, if known.
For this, you need to add a JSON file to the app's GResource and pass its
GResource path to the EosApplication:image-attribution-file property. The
format of this JSON file is described in the documentation for
EosApplication.
The dialog uses GtkTreeView because we didn't have GtkListBox when I
started implementing it over a year ago. This places some limitations on
the UI; the links behave weirdly and the mouse pointer doesn't change to
a hand when hovering over the links.
[endlessm/eos-sdk#2934]
Diffstat (limited to 'endless/eoscellrenderertextlink.c')
-rw-r--r-- | endless/eoscellrenderertextlink.c | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/endless/eoscellrenderertextlink.c b/endless/eoscellrenderertextlink.c new file mode 100644 index 0000000..0a783bf --- /dev/null +++ b/endless/eoscellrenderertextlink.c @@ -0,0 +1,85 @@ +/* Copyright 2015 Endless Mobile, Inc. */ + +#include <gtk/gtk.h> + +#include "eoscellrenderertextlink-private.h" + +#define LINK_NORMAL_FOREGROUND_COLOR "#3465a4" /* sky blue 2 */ +#define LINK_HOVER_FOREGROUND_COLOR "#729fcf" /* sky blue 3 */ + +G_DEFINE_TYPE (EosCellRendererTextLink, eos_cell_renderer_text_link, GTK_TYPE_CELL_RENDERER_TEXT) + +enum { + CLICKED, + LAST_SIGNAL +}; + +static guint text_link_signals[LAST_SIGNAL] = { 0 }; + +static void +eos_cell_renderer_text_link_render (GtkCellRenderer *renderer, + cairo_t *cr, + GtkWidget *widget, + const GdkRectangle *background_area, + const GdkRectangle *cell_area, + GtkCellRendererState flags) +{ + /* FIXME: the prelit flag is TRUE when the mouse is over the row that this + renderer is in - even if the mouse is not over the renderer itself. */ + if (flags & GTK_CELL_RENDERER_PRELIT) + g_object_set (renderer, + "foreground", LINK_HOVER_FOREGROUND_COLOR, + NULL); + else + g_object_set (renderer, + "foreground", LINK_NORMAL_FOREGROUND_COLOR, + NULL); + GTK_CELL_RENDERER_CLASS (eos_cell_renderer_text_link_parent_class)-> + render (renderer, cr, widget, background_area, cell_area, flags); +} + +static gboolean +eos_cell_renderer_text_link_activate (GtkCellRenderer *renderer, + GdkEvent *event, + GtkWidget *widget, + const gchar *path, + const GdkRectangle *background_area, + const GdkRectangle *cell_area, + GtkCellRendererState flags) +{ + g_signal_emit (renderer, text_link_signals[CLICKED], 0, path); + return TRUE; +} + +static void +eos_cell_renderer_text_link_class_init (EosCellRendererTextLinkClass *klass) +{ + GtkCellRendererClass *renderer_class = GTK_CELL_RENDERER_CLASS (klass); + + renderer_class->render = eos_cell_renderer_text_link_render; + renderer_class->activate = eos_cell_renderer_text_link_activate; + + text_link_signals[CLICKED] = + g_signal_new ("clicked", EOS_TYPE_CELL_RENDERER_TEXT_LINK, + G_SIGNAL_RUN_FIRST, + 0, + NULL, NULL, + g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, + 1, G_TYPE_STRING); +} + +static void +eos_cell_renderer_text_link_init (EosCellRendererTextLink *self) +{ + g_object_set (self, + "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, + NULL); +} + +GtkCellRenderer * +eos_cell_renderer_text_link_new (void) +{ + return GTK_CELL_RENDERER (g_object_new (EOS_TYPE_CELL_RENDERER_TEXT_LINK, + NULL)); +} |