2012-01-29 15:42:34 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 2012 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2012-01-29 15:42:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2012-02-09 00:36:10 +00:00
|
|
|
#include "gtkcolorswatchprivate.h"
|
2012-02-04 05:02:49 +00:00
|
|
|
|
2012-02-14 17:16:56 +00:00
|
|
|
#include "gtkcolorchooserprivate.h"
|
2012-01-29 15:42:34 +00:00
|
|
|
#include "gtkdnd.h"
|
|
|
|
#include "gtkicontheme.h"
|
2012-01-30 14:56:20 +00:00
|
|
|
#include "gtkmain.h"
|
|
|
|
#include "gtkmenu.h"
|
|
|
|
#include "gtkmenuitem.h"
|
|
|
|
#include "gtkmenushell.h"
|
2012-01-29 15:42:34 +00:00
|
|
|
#include "gtkprivate.h"
|
|
|
|
#include "gtkintl.h"
|
2016-01-08 00:20:55 +00:00
|
|
|
#include "gtkiconhelperprivate.h"
|
2015-10-31 01:29:46 +00:00
|
|
|
#include "gtkcssnodeprivate.h"
|
2015-12-14 21:10:28 +00:00
|
|
|
#include "gtkcsscustomgadgetprivate.h"
|
2016-12-19 18:19:15 +00:00
|
|
|
#include "gtkroundedboxprivate.h"
|
2014-06-12 12:39:12 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2015-10-31 02:16:18 +00:00
|
|
|
#include "gtkstylecontextprivate.h"
|
2012-12-27 17:11:12 +00:00
|
|
|
#include "a11y/gtkcolorswatchaccessibleprivate.h"
|
2012-01-29 15:42:34 +00:00
|
|
|
|
2016-12-19 18:19:15 +00:00
|
|
|
#include "gsk/gskroundedrectprivate.h"
|
2012-01-29 15:42:34 +00:00
|
|
|
|
2015-10-31 01:29:46 +00:00
|
|
|
/*
|
|
|
|
* GtkColorSwatch has two CSS nodes, the main one named colorswatch
|
2015-10-31 01:43:50 +00:00
|
|
|
* and a subnode named overlay. The main node gets the .light or .dark
|
2015-10-31 01:29:46 +00:00
|
|
|
* style classes added depending on the brightness of the color that
|
|
|
|
* the swatch is showing.
|
2015-10-31 02:16:18 +00:00
|
|
|
*
|
|
|
|
* The color swatch has the .activatable style class by default. It can
|
|
|
|
* be removed for non-activatable swatches.
|
2015-10-31 01:29:46 +00:00
|
|
|
*/
|
|
|
|
|
2012-01-29 15:42:34 +00:00
|
|
|
struct _GtkColorSwatchPrivate
|
|
|
|
{
|
|
|
|
GdkRGBA color;
|
|
|
|
gdouble radius[4];
|
|
|
|
gchar *icon;
|
|
|
|
guint has_color : 1;
|
2012-02-03 23:34:33 +00:00
|
|
|
guint use_alpha : 1;
|
2012-02-17 16:01:50 +00:00
|
|
|
guint selectable : 1;
|
2015-06-14 01:56:41 +00:00
|
|
|
guint has_menu : 1;
|
2012-02-20 12:45:58 +00:00
|
|
|
|
|
|
|
GdkWindow *event_window;
|
2012-03-03 06:48:55 +00:00
|
|
|
|
2014-04-08 19:18:38 +00:00
|
|
|
GtkGesture *long_press_gesture;
|
|
|
|
GtkGesture *multipress_gesture;
|
2015-12-14 21:10:28 +00:00
|
|
|
GtkCssGadget *gadget;
|
|
|
|
GtkCssGadget *overlay_gadget;
|
2015-08-05 02:58:40 +00:00
|
|
|
|
|
|
|
GtkWidget *popover;
|
2012-01-29 15:42:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_ZERO,
|
2012-02-17 16:01:50 +00:00
|
|
|
PROP_RGBA,
|
2015-06-14 01:56:41 +00:00
|
|
|
PROP_SELECTABLE,
|
|
|
|
PROP_HAS_MENU
|
2012-01-29 15:42:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
ACTIVATE,
|
|
|
|
CUSTOMIZE,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL];
|
|
|
|
|
2014-04-08 19:18:38 +00:00
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkColorSwatch, gtk_color_swatch, GTK_TYPE_WIDGET)
|
2012-01-29 15:42:34 +00:00
|
|
|
|
2016-12-19 18:30:55 +00:00
|
|
|
static void
|
|
|
|
swatch_snapshot (GtkWidget *widget,
|
|
|
|
GtkSnapshot *snapshot)
|
2012-01-29 15:42:34 +00:00
|
|
|
{
|
2016-12-19 18:30:55 +00:00
|
|
|
gtk_css_gadget_snapshot (GTK_COLOR_SWATCH (widget)->priv->gadget, snapshot);
|
2012-01-29 15:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define INTENSITY(r, g, b) ((r) * 0.30 + (g) * 0.59 + (b) * 0.11)
|
|
|
|
|
|
|
|
static gboolean
|
2015-12-14 21:10:28 +00:00
|
|
|
gtk_color_swatch_render (GtkCssGadget *gadget,
|
2016-12-19 18:30:55 +00:00
|
|
|
GtkSnapshot *snapshot,
|
2015-12-14 21:10:28 +00:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
gpointer data)
|
2012-01-29 15:42:34 +00:00
|
|
|
{
|
2015-12-14 21:10:28 +00:00
|
|
|
GtkWidget *widget;
|
|
|
|
GtkColorSwatch *swatch;
|
2012-01-29 15:42:34 +00:00
|
|
|
GtkStyleContext *context;
|
|
|
|
|
2015-12-14 21:10:28 +00:00
|
|
|
widget = gtk_css_gadget_get_owner (gadget);
|
|
|
|
swatch = GTK_COLOR_SWATCH (widget);
|
2012-01-29 15:42:34 +00:00
|
|
|
context = gtk_widget_get_style_context (widget);
|
2012-01-31 07:05:37 +00:00
|
|
|
|
2012-01-29 15:42:34 +00:00
|
|
|
if (swatch->priv->has_color)
|
|
|
|
{
|
2012-01-31 05:58:07 +00:00
|
|
|
cairo_pattern_t *pattern;
|
|
|
|
cairo_matrix_t matrix;
|
2016-01-08 22:58:25 +00:00
|
|
|
GtkAllocation allocation, border_allocation;
|
2016-12-19 18:19:15 +00:00
|
|
|
GskRoundedRect content_box;
|
2016-01-08 22:58:25 +00:00
|
|
|
|
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
|
|
|
gtk_css_gadget_get_border_allocation (gadget, &border_allocation, NULL);
|
|
|
|
|
|
|
|
border_allocation.x -= allocation.x;
|
|
|
|
border_allocation.y -= allocation.y;
|
2016-01-07 23:38:31 +00:00
|
|
|
|
2016-12-19 18:19:15 +00:00
|
|
|
gtk_rounded_boxes_init_for_style (NULL,
|
|
|
|
NULL,
|
|
|
|
&content_box,
|
|
|
|
gtk_style_context_lookup_style (context),
|
|
|
|
border_allocation.x,
|
|
|
|
border_allocation.y,
|
|
|
|
border_allocation.width,
|
|
|
|
border_allocation.height);
|
2016-12-19 18:30:55 +00:00
|
|
|
gtk_snapshot_push_rounded_clip (snapshot,
|
|
|
|
&content_box,
|
|
|
|
"ColorSwatchClip");
|
2014-10-07 21:24:51 +00:00
|
|
|
|
2016-12-19 18:30:55 +00:00
|
|
|
if (swatch->priv->use_alpha && !gdk_rgba_is_opaque (&swatch->priv->color))
|
2012-01-31 07:05:37 +00:00
|
|
|
{
|
2016-12-19 18:30:55 +00:00
|
|
|
cairo_t *cr;
|
2012-02-08 21:37:25 +00:00
|
|
|
|
2017-01-13 03:46:09 +00:00
|
|
|
cr = gtk_snapshot_append_cairo (snapshot,
|
|
|
|
&content_box.bounds,
|
|
|
|
"CheckeredBackground");
|
2012-01-31 07:05:37 +00:00
|
|
|
cairo_set_source_rgb (cr, 0.33, 0.33, 0.33);
|
2016-12-19 18:30:55 +00:00
|
|
|
cairo_paint (cr);
|
2012-01-31 05:58:07 +00:00
|
|
|
|
2012-02-14 17:16:56 +00:00
|
|
|
pattern = _gtk_color_chooser_get_checkered_pattern ();
|
2012-01-31 07:05:37 +00:00
|
|
|
cairo_matrix_init_scale (&matrix, 0.125, 0.125);
|
|
|
|
cairo_pattern_set_matrix (pattern, &matrix);
|
2012-02-08 21:37:25 +00:00
|
|
|
|
|
|
|
cairo_set_source_rgb (cr, 0.66, 0.66, 0.66);
|
2012-01-31 07:05:37 +00:00
|
|
|
cairo_mask (cr, pattern);
|
|
|
|
cairo_pattern_destroy (pattern);
|
2012-01-31 05:58:07 +00:00
|
|
|
|
2016-12-19 18:30:55 +00:00
|
|
|
cairo_destroy (cr);
|
2012-02-08 21:37:25 +00:00
|
|
|
|
2017-01-13 03:46:09 +00:00
|
|
|
gtk_snapshot_append_color (snapshot,
|
|
|
|
&swatch->priv->color,
|
|
|
|
&content_box.bounds,
|
|
|
|
"ColorSwatch Color");
|
2012-01-31 07:05:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-19 18:30:55 +00:00
|
|
|
GdkRGBA color = swatch->priv->color;
|
|
|
|
|
|
|
|
color.alpha = 1.0;
|
|
|
|
|
2017-01-13 03:46:09 +00:00
|
|
|
gtk_snapshot_append_color (snapshot,
|
|
|
|
&color,
|
|
|
|
&content_box.bounds,
|
|
|
|
"ColorSwatch Opaque Color");
|
2012-01-31 07:05:37 +00:00
|
|
|
}
|
2012-02-08 21:37:25 +00:00
|
|
|
|
2017-01-12 23:39:59 +00:00
|
|
|
gtk_snapshot_pop (snapshot);
|
2012-01-29 15:42:34 +00:00
|
|
|
}
|
|
|
|
|
2016-12-19 18:30:55 +00:00
|
|
|
gtk_css_gadget_snapshot (swatch->priv->overlay_gadget, snapshot);
|
2015-12-14 21:10:28 +00:00
|
|
|
|
|
|
|
return gtk_widget_has_visible_focus (widget);
|
|
|
|
}
|
|
|
|
|
2012-01-29 15:42:34 +00:00
|
|
|
static void
|
|
|
|
drag_set_color_icon (GdkDragContext *context,
|
|
|
|
const GdkRGBA *color)
|
|
|
|
{
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
cairo_t *cr;
|
|
|
|
|
|
|
|
surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 48, 32);
|
|
|
|
cr = cairo_create (surface);
|
|
|
|
gdk_cairo_set_source_rgba (cr, color);
|
|
|
|
cairo_paint (cr);
|
|
|
|
|
2012-02-04 05:02:49 +00:00
|
|
|
cairo_surface_set_device_offset (surface, -4, -4);
|
2012-01-29 15:42:34 +00:00
|
|
|
gtk_drag_set_icon_surface (context, surface);
|
|
|
|
|
|
|
|
cairo_destroy (cr);
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
swatch_drag_begin (GtkWidget *widget,
|
|
|
|
GdkDragContext *context)
|
|
|
|
{
|
|
|
|
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
|
|
|
|
GdkRGBA color;
|
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_swatch_get_rgba (swatch, &color);
|
2012-01-29 15:42:34 +00:00
|
|
|
drag_set_color_icon (context, &color);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
swatch_drag_data_get (GtkWidget *widget,
|
|
|
|
GdkDragContext *context,
|
|
|
|
GtkSelectionData *selection_data,
|
|
|
|
guint info,
|
|
|
|
guint time)
|
|
|
|
{
|
|
|
|
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
|
|
|
|
guint16 vals[4];
|
|
|
|
GdkRGBA color;
|
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_swatch_get_rgba (swatch, &color);
|
2012-01-29 15:42:34 +00:00
|
|
|
|
|
|
|
vals[0] = color.red * 0xffff;
|
|
|
|
vals[1] = color.green * 0xffff;
|
|
|
|
vals[2] = color.blue * 0xffff;
|
|
|
|
vals[3] = color.alpha * 0xffff;
|
|
|
|
|
|
|
|
gtk_selection_data_set (selection_data,
|
|
|
|
gdk_atom_intern_static_string ("application/x-color"),
|
|
|
|
16, (guchar *)vals, 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
swatch_drag_data_received (GtkWidget *widget,
|
|
|
|
GdkDragContext *context,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
GtkSelectionData *selection_data,
|
|
|
|
guint info,
|
|
|
|
guint time)
|
|
|
|
{
|
|
|
|
gint length;
|
|
|
|
guint16 *vals;
|
|
|
|
GdkRGBA color;
|
|
|
|
|
|
|
|
length = gtk_selection_data_get_length (selection_data);
|
|
|
|
|
|
|
|
if (length < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* We accept drops with the wrong format, since the KDE color
|
|
|
|
* chooser incorrectly drops application/x-color with format 8.
|
|
|
|
*/
|
|
|
|
if (length != 8)
|
|
|
|
{
|
2016-02-28 16:06:25 +00:00
|
|
|
g_warning ("Received invalid color data");
|
2012-01-29 15:42:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
vals = (guint16 *) gtk_selection_data_get_data (selection_data);
|
|
|
|
|
|
|
|
color.red = (gdouble)vals[0] / 0xffff;
|
|
|
|
color.green = (gdouble)vals[1] / 0xffff;
|
|
|
|
color.blue = (gdouble)vals[2] / 0xffff;
|
|
|
|
color.alpha = (gdouble)vals[3] / 0xffff;
|
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (widget), &color);
|
2012-01-29 15:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-12-14 21:10:28 +00:00
|
|
|
gtk_color_swatch_measure (GtkCssGadget *gadget,
|
|
|
|
GtkOrientation orientation,
|
|
|
|
int for_size,
|
|
|
|
int *minimum,
|
|
|
|
int *natural,
|
|
|
|
int *minimum_baseline,
|
|
|
|
int *natural_baseline,
|
|
|
|
gpointer unused)
|
2012-01-29 15:42:34 +00:00
|
|
|
{
|
2015-12-14 21:10:28 +00:00
|
|
|
GtkWidget *widget;
|
|
|
|
GtkColorSwatch *swatch;
|
|
|
|
gint w, h, min;
|
2014-07-10 00:44:06 +00:00
|
|
|
|
2015-12-14 21:10:28 +00:00
|
|
|
widget = gtk_css_gadget_get_owner (gadget);
|
|
|
|
swatch = GTK_COLOR_SWATCH (widget);
|
|
|
|
|
|
|
|
gtk_css_gadget_get_preferred_size (swatch->priv->overlay_gadget,
|
|
|
|
orientation,
|
|
|
|
-1,
|
|
|
|
minimum, natural,
|
|
|
|
NULL, NULL);
|
2014-07-10 00:44:06 +00:00
|
|
|
|
2015-12-14 21:10:28 +00:00
|
|
|
gtk_widget_get_size_request (widget, &w, &h);
|
|
|
|
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
min = w < 0 ? 48 : w;
|
|
|
|
else
|
|
|
|
min = h < 0 ? 32 : h;
|
2014-07-10 00:44:06 +00:00
|
|
|
|
2015-12-14 21:10:28 +00:00
|
|
|
*minimum = MAX (*minimum, min);
|
|
|
|
*natural = MAX (*natural, min);
|
2012-01-29 15:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
swatch_key_press (GtkWidget *widget,
|
|
|
|
GdkEventKey *event)
|
|
|
|
{
|
|
|
|
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
|
|
|
|
|
|
|
|
if (event->keyval == GDK_KEY_space ||
|
|
|
|
event->keyval == GDK_KEY_Return ||
|
|
|
|
event->keyval == GDK_KEY_ISO_Enter||
|
|
|
|
event->keyval == GDK_KEY_KP_Enter ||
|
|
|
|
event->keyval == GDK_KEY_KP_Space)
|
|
|
|
{
|
2015-06-14 01:56:41 +00:00
|
|
|
if (swatch->priv->has_color &&
|
2012-02-17 16:01:50 +00:00
|
|
|
swatch->priv->selectable &&
|
|
|
|
(gtk_widget_get_state_flags (widget) & GTK_STATE_FLAG_SELECTED) == 0)
|
2012-02-09 04:48:11 +00:00
|
|
|
gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_SELECTED, FALSE);
|
2012-01-29 15:42:34 +00:00
|
|
|
else
|
|
|
|
g_signal_emit (swatch, signals[ACTIVATE], 0);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-01-30 14:56:20 +00:00
|
|
|
if (GTK_WIDGET_CLASS (gtk_color_swatch_parent_class)->key_press_event (widget, event))
|
|
|
|
return TRUE;
|
|
|
|
|
2012-01-29 15:42:34 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-02-04 05:02:49 +00:00
|
|
|
swatch_enter_notify (GtkWidget *widget,
|
|
|
|
GdkEventCrossing *event)
|
2012-01-29 15:42:34 +00:00
|
|
|
{
|
2012-02-21 17:13:58 +00:00
|
|
|
gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_PRELIGHT, FALSE);
|
|
|
|
|
2012-01-29 15:42:34 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-02-04 05:02:49 +00:00
|
|
|
swatch_leave_notify (GtkWidget *widget,
|
|
|
|
GdkEventCrossing *event)
|
2012-01-29 15:42:34 +00:00
|
|
|
{
|
2012-02-21 17:13:58 +00:00
|
|
|
gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_PRELIGHT);
|
|
|
|
|
2012-01-29 15:42:34 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-01-30 14:56:20 +00:00
|
|
|
static void
|
|
|
|
emit_customize (GtkColorSwatch *swatch)
|
|
|
|
{
|
|
|
|
g_signal_emit (swatch, signals[CUSTOMIZE], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-08-05 02:58:40 +00:00
|
|
|
do_popup (GtkColorSwatch *swatch)
|
2012-01-30 14:56:20 +00:00
|
|
|
{
|
2015-08-05 02:58:40 +00:00
|
|
|
if (swatch->priv->popover == NULL)
|
|
|
|
{
|
|
|
|
GtkWidget *box;
|
|
|
|
GtkWidget *item;
|
|
|
|
|
|
|
|
swatch->priv->popover = gtk_popover_new (GTK_WIDGET (swatch));
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
|
|
|
gtk_container_add (GTK_CONTAINER (swatch->priv->popover), box);
|
|
|
|
g_object_set (box, "margin", 10, NULL);
|
|
|
|
item = g_object_new (GTK_TYPE_MODEL_BUTTON,
|
|
|
|
"text", _("C_ustomize"),
|
|
|
|
NULL);
|
|
|
|
g_signal_connect_swapped (item, "clicked",
|
|
|
|
G_CALLBACK (emit_customize), swatch);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), item);
|
|
|
|
}
|
2012-01-30 14:56:20 +00:00
|
|
|
|
2016-08-10 17:18:27 +00:00
|
|
|
gtk_popover_popup (GTK_POPOVER (swatch->priv->popover));
|
2012-01-29 15:42:34 +00:00
|
|
|
}
|
|
|
|
|
2012-03-03 06:48:55 +00:00
|
|
|
static gboolean
|
|
|
|
swatch_primary_action (GtkColorSwatch *swatch)
|
|
|
|
{
|
|
|
|
GtkWidget *widget = (GtkWidget *)swatch;
|
|
|
|
GtkStateFlags flags;
|
|
|
|
|
|
|
|
flags = gtk_widget_get_state_flags (widget);
|
|
|
|
if (!swatch->priv->has_color)
|
|
|
|
{
|
|
|
|
g_signal_emit (swatch, signals[ACTIVATE], 0);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else if (swatch->priv->selectable &&
|
|
|
|
(flags & GTK_STATE_FLAG_SELECTED) == 0)
|
|
|
|
{
|
|
|
|
gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_SELECTED, FALSE);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-04-08 19:18:38 +00:00
|
|
|
hold_action (GtkGestureLongPress *gesture,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
GtkColorSwatch *swatch)
|
2012-03-03 06:48:55 +00:00
|
|
|
{
|
2015-08-05 02:58:40 +00:00
|
|
|
do_popup (swatch);
|
2014-04-08 19:18:38 +00:00
|
|
|
gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
|
2012-03-03 06:48:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-04-08 19:18:38 +00:00
|
|
|
tap_action (GtkGestureMultiPress *gesture,
|
|
|
|
gint n_press,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
GtkColorSwatch *swatch)
|
|
|
|
{
|
2014-05-09 23:24:27 +00:00
|
|
|
guint button;
|
|
|
|
|
|
|
|
button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture));
|
|
|
|
|
|
|
|
if (button == GDK_BUTTON_PRIMARY)
|
|
|
|
{
|
|
|
|
if (n_press == 1)
|
|
|
|
swatch_primary_action (swatch);
|
|
|
|
else if (n_press > 1)
|
|
|
|
g_signal_emit (swatch, signals[ACTIVATE], 0);
|
|
|
|
}
|
|
|
|
else if (button == GDK_BUTTON_SECONDARY)
|
|
|
|
{
|
2015-06-14 01:56:41 +00:00
|
|
|
if (swatch->priv->has_color && swatch->priv->has_menu)
|
2015-08-05 02:58:40 +00:00
|
|
|
do_popup (swatch);
|
2014-05-09 23:24:27 +00:00
|
|
|
}
|
2012-01-29 15:42:34 +00:00
|
|
|
}
|
|
|
|
|
2012-02-20 12:45:58 +00:00
|
|
|
static void
|
|
|
|
swatch_map (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_color_swatch_parent_class)->map (widget);
|
|
|
|
|
|
|
|
if (swatch->priv->event_window)
|
|
|
|
gdk_window_show (swatch->priv->event_window);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
swatch_unmap (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
|
|
|
|
|
|
|
|
if (swatch->priv->event_window)
|
|
|
|
gdk_window_hide (swatch->priv->event_window);
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_color_swatch_parent_class)->unmap (widget);
|
|
|
|
}
|
|
|
|
|
2012-02-17 17:31:19 +00:00
|
|
|
static void
|
|
|
|
swatch_realize (GtkWidget *widget)
|
|
|
|
{
|
2012-02-20 12:45:58 +00:00
|
|
|
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
|
2012-02-17 17:31:19 +00:00
|
|
|
GtkAllocation allocation;
|
|
|
|
|
2016-11-02 06:16:08 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_color_swatch_parent_class)->realize (widget);
|
2012-02-17 17:31:19 +00:00
|
|
|
|
2016-11-02 23:38:48 +00:00
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
|
|
|
|
2016-11-02 06:16:08 +00:00
|
|
|
swatch->priv->event_window = gdk_window_new_input (gtk_widget_get_window (widget),
|
2016-10-17 18:14:32 +00:00
|
|
|
gtk_widget_get_events (widget)
|
|
|
|
| GDK_BUTTON_PRESS_MASK
|
|
|
|
| GDK_BUTTON_RELEASE_MASK
|
|
|
|
| GDK_ENTER_NOTIFY_MASK
|
|
|
|
| GDK_LEAVE_NOTIFY_MASK
|
|
|
|
| GDK_TOUCH_MASK,
|
|
|
|
&allocation);
|
2013-02-05 08:36:49 +00:00
|
|
|
gtk_widget_register_window (widget, swatch->priv->event_window);
|
2012-02-20 12:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
swatch_unrealize (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
|
|
|
|
|
|
|
|
if (swatch->priv->event_window)
|
|
|
|
{
|
2013-02-05 08:36:49 +00:00
|
|
|
gtk_widget_unregister_window (widget, swatch->priv->event_window);
|
2012-02-20 12:45:58 +00:00
|
|
|
gdk_window_destroy (swatch->priv->event_window);
|
|
|
|
swatch->priv->event_window = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_color_swatch_parent_class)->unrealize (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-08-05 02:58:40 +00:00
|
|
|
swatch_size_allocate (GtkWidget *widget,
|
2012-02-20 12:45:58 +00:00
|
|
|
GtkAllocation *allocation)
|
|
|
|
{
|
|
|
|
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
|
2016-01-08 00:20:55 +00:00
|
|
|
GtkAllocation clip, clip2;
|
2012-02-20 12:45:58 +00:00
|
|
|
|
|
|
|
gtk_widget_set_allocation (widget, allocation);
|
|
|
|
|
2015-12-14 21:10:28 +00:00
|
|
|
gtk_css_gadget_allocate (swatch->priv->gadget,
|
|
|
|
allocation,
|
|
|
|
gtk_widget_get_allocated_baseline (widget),
|
|
|
|
&clip);
|
2016-01-08 00:20:55 +00:00
|
|
|
gtk_css_gadget_allocate (swatch->priv->overlay_gadget,
|
|
|
|
allocation,
|
|
|
|
gtk_widget_get_allocated_baseline (widget),
|
|
|
|
&clip2);
|
2015-12-14 21:10:28 +00:00
|
|
|
|
2016-01-08 00:20:55 +00:00
|
|
|
gdk_rectangle_union (&clip, &clip2, &clip);
|
2015-12-14 21:10:28 +00:00
|
|
|
|
2016-01-08 00:20:55 +00:00
|
|
|
gtk_widget_set_clip (widget, &clip);
|
2016-01-13 18:58:52 +00:00
|
|
|
|
|
|
|
if (gtk_widget_get_realized (widget))
|
|
|
|
{
|
|
|
|
GtkAllocation border_allocation;
|
|
|
|
gtk_css_gadget_get_border_allocation(swatch->priv->gadget, &border_allocation, NULL);
|
|
|
|
gdk_window_move_resize (swatch->priv->event_window,
|
|
|
|
border_allocation.x,
|
|
|
|
border_allocation.y,
|
|
|
|
border_allocation.width,
|
|
|
|
border_allocation.height);
|
|
|
|
}
|
|
|
|
|
2015-12-14 21:10:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-10-22 14:06:14 +00:00
|
|
|
gtk_color_swatch_measure_ (GtkWidget *widget,
|
|
|
|
GtkOrientation orientation,
|
|
|
|
int for_size,
|
|
|
|
int *minimum,
|
|
|
|
int *natural,
|
|
|
|
int *minimum_baseline,
|
|
|
|
int *natural_baseline)
|
2015-12-14 21:10:28 +00:00
|
|
|
{
|
|
|
|
gtk_css_gadget_get_preferred_size (GTK_COLOR_SWATCH (widget)->priv->gadget,
|
2016-10-22 14:06:14 +00:00
|
|
|
orientation,
|
|
|
|
for_size,
|
2015-12-14 21:10:28 +00:00
|
|
|
minimum, natural,
|
2016-10-22 14:06:14 +00:00
|
|
|
minimum_baseline, natural_baseline);
|
2015-12-14 21:10:28 +00:00
|
|
|
}
|
|
|
|
|
2016-10-22 14:06:14 +00:00
|
|
|
|
2012-02-17 17:31:19 +00:00
|
|
|
|
2012-01-30 14:56:20 +00:00
|
|
|
static gboolean
|
2015-08-05 02:58:40 +00:00
|
|
|
swatch_popup_menu (GtkWidget *widget)
|
2012-01-30 14:56:20 +00:00
|
|
|
{
|
2015-08-05 02:58:40 +00:00
|
|
|
do_popup (GTK_COLOR_SWATCH (widget));
|
2012-01-30 14:56:20 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-01-08 00:20:55 +00:00
|
|
|
static void
|
|
|
|
update_icon (GtkColorSwatch *swatch)
|
|
|
|
{
|
|
|
|
GtkIconHelper *icon_helper = GTK_ICON_HELPER (swatch->priv->overlay_gadget);
|
|
|
|
|
|
|
|
if (swatch->priv->icon)
|
|
|
|
_gtk_icon_helper_set_icon_name (icon_helper, swatch->priv->icon, GTK_ICON_SIZE_BUTTON);
|
|
|
|
else if (gtk_widget_get_state_flags (GTK_WIDGET (swatch)) & GTK_STATE_FLAG_SELECTED)
|
|
|
|
_gtk_icon_helper_set_icon_name (icon_helper, "object-select-symbolic", GTK_ICON_SIZE_BUTTON);
|
|
|
|
else
|
|
|
|
_gtk_icon_helper_clear (icon_helper);
|
|
|
|
}
|
|
|
|
|
2015-10-31 01:29:46 +00:00
|
|
|
static void
|
|
|
|
swatch_state_flags_changed (GtkWidget *widget,
|
|
|
|
GtkStateFlags previous_state)
|
|
|
|
{
|
|
|
|
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
|
|
|
|
|
2016-01-13 05:05:16 +00:00
|
|
|
gtk_css_gadget_set_state (swatch->priv->gadget, gtk_widget_get_state_flags (widget));
|
|
|
|
gtk_css_gadget_set_state (swatch->priv->overlay_gadget, gtk_widget_get_state_flags (widget));
|
2015-12-02 03:36:31 +00:00
|
|
|
|
2016-01-08 00:20:55 +00:00
|
|
|
update_icon (swatch);
|
|
|
|
|
2015-12-02 03:36:31 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_color_swatch_parent_class)->state_flags_changed (widget, previous_state);
|
2015-10-31 01:29:46 +00:00
|
|
|
}
|
|
|
|
|
2012-02-04 05:02:49 +00:00
|
|
|
/* GObject implementation {{{1 */
|
|
|
|
|
|
|
|
static void
|
|
|
|
swatch_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (object);
|
|
|
|
GdkRGBA color;
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_RGBA:
|
|
|
|
gtk_color_swatch_get_rgba (swatch, &color);
|
|
|
|
g_value_set_boxed (value, &color);
|
|
|
|
break;
|
2012-02-17 16:01:50 +00:00
|
|
|
case PROP_SELECTABLE:
|
|
|
|
g_value_set_boolean (value, gtk_color_swatch_get_selectable (swatch));
|
|
|
|
break;
|
2015-06-14 01:56:41 +00:00
|
|
|
case PROP_HAS_MENU:
|
|
|
|
g_value_set_boolean (value, swatch->priv->has_menu);
|
|
|
|
break;
|
2012-02-04 05:02:49 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
swatch_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_RGBA:
|
|
|
|
gtk_color_swatch_set_rgba (swatch, g_value_get_boxed (value));
|
|
|
|
break;
|
2012-02-17 16:01:50 +00:00
|
|
|
case PROP_SELECTABLE:
|
|
|
|
gtk_color_swatch_set_selectable (swatch, g_value_get_boolean (value));
|
|
|
|
break;
|
2015-06-14 01:56:41 +00:00
|
|
|
case PROP_HAS_MENU:
|
|
|
|
swatch->priv->has_menu = g_value_get_boolean (value);
|
|
|
|
break;
|
2012-02-04 05:02:49 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
swatch_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (object);
|
|
|
|
|
|
|
|
g_free (swatch->priv->icon);
|
2015-12-14 21:10:28 +00:00
|
|
|
g_clear_object (&swatch->priv->gadget);
|
|
|
|
g_clear_object (&swatch->priv->overlay_gadget);
|
2014-04-08 19:18:38 +00:00
|
|
|
|
2012-02-04 05:02:49 +00:00
|
|
|
G_OBJECT_CLASS (gtk_color_swatch_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2015-08-05 02:58:40 +00:00
|
|
|
static void
|
|
|
|
swatch_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (object);
|
|
|
|
|
|
|
|
if (swatch->priv->popover)
|
|
|
|
{
|
|
|
|
gtk_widget_destroy (swatch->priv->popover);
|
|
|
|
swatch->priv->popover = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_clear_object (&swatch->priv->long_press_gesture);
|
|
|
|
g_clear_object (&swatch->priv->multipress_gesture);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_color_swatch_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2012-01-29 15:42:34 +00:00
|
|
|
static void
|
|
|
|
gtk_color_swatch_class_init (GtkColorSwatchClass *class)
|
|
|
|
{
|
|
|
|
GtkWidgetClass *widget_class = (GtkWidgetClass *)class;
|
|
|
|
GObjectClass *object_class = (GObjectClass *)class;
|
|
|
|
|
|
|
|
object_class->get_property = swatch_get_property;
|
|
|
|
object_class->set_property = swatch_set_property;
|
|
|
|
object_class->finalize = swatch_finalize;
|
2015-08-05 02:58:40 +00:00
|
|
|
object_class->dispose = swatch_dispose;
|
2012-01-29 15:42:34 +00:00
|
|
|
|
2016-10-22 14:06:14 +00:00
|
|
|
widget_class->measure = gtk_color_swatch_measure_;
|
2016-12-19 18:30:55 +00:00
|
|
|
widget_class->snapshot = swatch_snapshot;
|
2012-01-29 15:42:34 +00:00
|
|
|
widget_class->drag_begin = swatch_drag_begin;
|
|
|
|
widget_class->drag_data_get = swatch_drag_data_get;
|
|
|
|
widget_class->drag_data_received = swatch_drag_data_received;
|
|
|
|
widget_class->key_press_event = swatch_key_press;
|
2012-02-04 05:02:49 +00:00
|
|
|
widget_class->popup_menu = swatch_popup_menu;
|
|
|
|
widget_class->enter_notify_event = swatch_enter_notify;
|
|
|
|
widget_class->leave_notify_event = swatch_leave_notify;
|
2012-02-17 17:31:19 +00:00
|
|
|
widget_class->realize = swatch_realize;
|
2012-02-20 12:45:58 +00:00
|
|
|
widget_class->unrealize = swatch_unrealize;
|
|
|
|
widget_class->map = swatch_map;
|
|
|
|
widget_class->unmap = swatch_unmap;
|
|
|
|
widget_class->size_allocate = swatch_size_allocate;
|
2015-10-31 01:29:46 +00:00
|
|
|
widget_class->state_flags_changed = swatch_state_flags_changed;
|
2012-01-29 15:42:34 +00:00
|
|
|
|
|
|
|
signals[ACTIVATE] =
|
2015-09-12 13:13:00 +00:00
|
|
|
g_signal_new (I_("activate"),
|
2012-01-29 15:42:34 +00:00
|
|
|
GTK_TYPE_COLOR_SWATCH,
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GtkColorSwatchClass, activate),
|
|
|
|
NULL, NULL, NULL, G_TYPE_NONE, 0);
|
|
|
|
|
|
|
|
signals[CUSTOMIZE] =
|
2015-09-12 13:13:00 +00:00
|
|
|
g_signal_new (I_("customize"),
|
2012-01-29 15:42:34 +00:00
|
|
|
GTK_TYPE_COLOR_SWATCH,
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GtkColorSwatchClass, customize),
|
|
|
|
NULL, NULL, NULL, G_TYPE_NONE, 0);
|
|
|
|
|
2012-02-03 23:34:33 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_RGBA,
|
|
|
|
g_param_spec_boxed ("rgba", P_("RGBA Color"), P_("Color as RGBA"),
|
2012-01-29 15:42:34 +00:00
|
|
|
GDK_TYPE_RGBA, GTK_PARAM_READWRITE));
|
2012-02-17 16:01:50 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_SELECTABLE,
|
|
|
|
g_param_spec_boolean ("selectable", P_("Selectable"), P_("Whether the swatch is selectable"),
|
|
|
|
TRUE, GTK_PARAM_READWRITE));
|
2015-06-14 01:56:41 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_HAS_MENU,
|
|
|
|
g_param_spec_boolean ("has-menu", P_("Has Menu"), P_("Whether the swatch should offer customization"),
|
|
|
|
TRUE, GTK_PARAM_READWRITE));
|
2012-01-29 15:42:34 +00:00
|
|
|
|
2012-02-15 02:03:11 +00:00
|
|
|
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_COLOR_SWATCH_ACCESSIBLE);
|
2015-10-31 01:29:46 +00:00
|
|
|
gtk_widget_class_set_css_name (widget_class, "colorswatch");
|
2012-01-29 15:42:34 +00:00
|
|
|
}
|
|
|
|
|
2015-12-14 21:10:28 +00:00
|
|
|
static void
|
|
|
|
gtk_color_swatch_init (GtkColorSwatch *swatch)
|
|
|
|
{
|
|
|
|
GtkCssNode *widget_node;
|
|
|
|
|
|
|
|
swatch->priv = gtk_color_swatch_get_instance_private (swatch);
|
|
|
|
swatch->priv->use_alpha = TRUE;
|
|
|
|
swatch->priv->selectable = TRUE;
|
|
|
|
swatch->priv->has_menu = TRUE;
|
|
|
|
|
|
|
|
gtk_widget_set_can_focus (GTK_WIDGET (swatch), TRUE);
|
|
|
|
gtk_widget_set_has_window (GTK_WIDGET (swatch), FALSE);
|
|
|
|
|
|
|
|
swatch->priv->long_press_gesture = gtk_gesture_long_press_new (GTK_WIDGET (swatch));
|
|
|
|
gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (swatch->priv->long_press_gesture),
|
|
|
|
TRUE);
|
|
|
|
g_signal_connect (swatch->priv->long_press_gesture, "pressed",
|
|
|
|
G_CALLBACK (hold_action), swatch);
|
|
|
|
|
|
|
|
swatch->priv->multipress_gesture = gtk_gesture_multi_press_new (GTK_WIDGET (swatch));
|
|
|
|
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (swatch->priv->multipress_gesture), 0);
|
|
|
|
g_signal_connect (swatch->priv->multipress_gesture, "pressed",
|
|
|
|
G_CALLBACK (tap_action), swatch);
|
|
|
|
|
|
|
|
widget_node = gtk_widget_get_css_node (GTK_WIDGET (swatch));
|
|
|
|
swatch->priv->gadget = gtk_css_custom_gadget_new_for_node (widget_node,
|
|
|
|
GTK_WIDGET (swatch),
|
|
|
|
gtk_color_swatch_measure,
|
2016-01-08 00:20:55 +00:00
|
|
|
NULL,
|
2016-12-19 18:30:55 +00:00
|
|
|
gtk_color_swatch_render,
|
2016-11-13 20:08:34 +00:00
|
|
|
NULL,
|
2015-12-14 21:10:28 +00:00
|
|
|
NULL);
|
|
|
|
gtk_css_gadget_add_class (swatch->priv->gadget, "activatable");
|
2016-01-08 00:20:55 +00:00
|
|
|
|
|
|
|
swatch->priv->overlay_gadget = gtk_icon_helper_new_named ("overlay", GTK_WIDGET (swatch));
|
|
|
|
_gtk_icon_helper_set_force_scale_pixbuf (GTK_ICON_HELPER (swatch->priv->overlay_gadget), TRUE);
|
|
|
|
gtk_css_node_set_parent (gtk_css_gadget_get_node (swatch->priv->overlay_gadget), widget_node);
|
|
|
|
|
2015-12-14 21:10:28 +00:00
|
|
|
}
|
2015-06-14 01:56:41 +00:00
|
|
|
|
2012-01-29 15:42:34 +00:00
|
|
|
/* Public API {{{1 */
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
gtk_color_swatch_new (void)
|
|
|
|
{
|
|
|
|
return (GtkWidget *) g_object_new (GTK_TYPE_COLOR_SWATCH, NULL);
|
|
|
|
}
|
|
|
|
|
2012-02-04 05:02:49 +00:00
|
|
|
static const GtkTargetEntry dnd_targets[] = {
|
2016-10-15 20:24:42 +00:00
|
|
|
{ (char *) "application/x-color", 0 }
|
2012-02-04 05:02:49 +00:00
|
|
|
};
|
|
|
|
|
2012-01-29 15:42:34 +00:00
|
|
|
void
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_swatch_set_rgba (GtkColorSwatch *swatch,
|
|
|
|
const GdkRGBA *color)
|
2012-01-29 15:42:34 +00:00
|
|
|
{
|
2012-02-08 21:35:57 +00:00
|
|
|
GtkStyleContext *context;
|
|
|
|
|
|
|
|
context = gtk_widget_get_style_context (GTK_WIDGET (swatch));
|
|
|
|
|
2012-01-29 15:42:34 +00:00
|
|
|
if (!swatch->priv->has_color)
|
2012-02-08 21:35:57 +00:00
|
|
|
{
|
|
|
|
gtk_drag_source_set (GTK_WIDGET (swatch),
|
|
|
|
GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
|
|
|
|
dnd_targets, G_N_ELEMENTS (dnd_targets),
|
|
|
|
GDK_ACTION_COPY | GDK_ACTION_MOVE);
|
|
|
|
}
|
2012-01-29 15:42:34 +00:00
|
|
|
|
|
|
|
swatch->priv->has_color = TRUE;
|
2012-02-04 05:02:49 +00:00
|
|
|
swatch->priv->color = *color;
|
2012-01-29 15:42:34 +00:00
|
|
|
|
2012-02-08 21:35:57 +00:00
|
|
|
if (INTENSITY (swatch->priv->color.red, swatch->priv->color.green, swatch->priv->color.blue) > 0.5)
|
2015-10-31 01:29:46 +00:00
|
|
|
{
|
|
|
|
gtk_style_context_add_class (context, "light");
|
|
|
|
gtk_style_context_remove_class (context, "dark");
|
|
|
|
}
|
2012-02-08 21:35:57 +00:00
|
|
|
else
|
2015-10-31 01:29:46 +00:00
|
|
|
{
|
|
|
|
gtk_style_context_add_class (context, "dark");
|
|
|
|
gtk_style_context_remove_class (context, "light");
|
|
|
|
}
|
2012-02-08 21:35:57 +00:00
|
|
|
|
2012-01-29 15:42:34 +00:00
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (swatch));
|
2012-02-03 23:34:33 +00:00
|
|
|
g_object_notify (G_OBJECT (swatch), "rgba");
|
2012-01-29 15:42:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_swatch_get_rgba (GtkColorSwatch *swatch,
|
|
|
|
GdkRGBA *color)
|
2012-01-29 15:42:34 +00:00
|
|
|
{
|
|
|
|
if (swatch->priv->has_color)
|
|
|
|
{
|
|
|
|
color->red = swatch->priv->color.red;
|
|
|
|
color->green = swatch->priv->color.green;
|
|
|
|
color->blue = swatch->priv->color.blue;
|
|
|
|
color->alpha = swatch->priv->color.alpha;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
color->red = 1.0;
|
|
|
|
color->green = 1.0;
|
|
|
|
color->blue = 1.0;
|
|
|
|
color->alpha = 1.0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_color_swatch_set_icon (GtkColorSwatch *swatch,
|
|
|
|
const gchar *icon)
|
|
|
|
{
|
|
|
|
swatch->priv->icon = g_strdup (icon);
|
2016-01-08 00:20:55 +00:00
|
|
|
update_icon (swatch);
|
2012-01-29 15:42:34 +00:00
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (swatch));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_color_swatch_set_can_drop (GtkColorSwatch *swatch,
|
|
|
|
gboolean can_drop)
|
|
|
|
{
|
2012-02-09 03:56:14 +00:00
|
|
|
if (can_drop)
|
|
|
|
{
|
|
|
|
gtk_drag_dest_set (GTK_WIDGET (swatch),
|
|
|
|
GTK_DEST_DEFAULT_HIGHLIGHT |
|
|
|
|
GTK_DEST_DEFAULT_MOTION |
|
|
|
|
GTK_DEST_DEFAULT_DROP,
|
|
|
|
dnd_targets, G_N_ELEMENTS (dnd_targets),
|
|
|
|
GDK_ACTION_COPY);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_drag_dest_unset (GTK_WIDGET (swatch));
|
|
|
|
}
|
2012-01-29 15:42:34 +00:00
|
|
|
}
|
|
|
|
|
2012-01-31 07:05:37 +00:00
|
|
|
void
|
2012-02-03 23:34:33 +00:00
|
|
|
gtk_color_swatch_set_use_alpha (GtkColorSwatch *swatch,
|
2012-02-04 05:02:49 +00:00
|
|
|
gboolean use_alpha)
|
2012-01-31 07:05:37 +00:00
|
|
|
{
|
2012-02-03 23:34:33 +00:00
|
|
|
swatch->priv->use_alpha = use_alpha;
|
2012-01-31 07:05:37 +00:00
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (swatch));
|
|
|
|
}
|
|
|
|
|
2012-02-17 16:01:50 +00:00
|
|
|
void
|
|
|
|
gtk_color_swatch_set_selectable (GtkColorSwatch *swatch,
|
|
|
|
gboolean selectable)
|
|
|
|
{
|
|
|
|
if (selectable == swatch->priv->selectable)
|
|
|
|
return;
|
|
|
|
|
|
|
|
swatch->priv->selectable = selectable;
|
|
|
|
g_object_notify (G_OBJECT (swatch), "selectable");
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gtk_color_swatch_get_selectable (GtkColorSwatch *swatch)
|
|
|
|
{
|
|
|
|
return swatch->priv->selectable;
|
|
|
|
}
|
|
|
|
|
2012-01-29 15:42:34 +00:00
|
|
|
/* vim:set foldmethod=marker: */
|