Blame gtk/gtkcolorsel.c

Packit Service fb6fa5
/* GTK - The GIMP Toolkit
Packit Service fb6fa5
 * Copyright (C) 2000 Red Hat, Inc.
Packit Service fb6fa5
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * This library is free software; you can redistribute it and/or
Packit Service fb6fa5
 * modify it under the terms of the GNU Lesser General Public
Packit Service fb6fa5
 * License as published by the Free Software Foundation; either
Packit Service fb6fa5
 * version 2 of the License, or (at your option) any later version.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * This library is distributed in the hope that it will be useful,
Packit Service fb6fa5
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service fb6fa5
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service fb6fa5
 * Lesser General Public License for more details.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * You should have received a copy of the GNU Lesser General Public
Packit Service fb6fa5
 * License along with this library; if not, write to the
Packit Service fb6fa5
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit Service fb6fa5
 * Boston, MA 02111-1307, USA.
Packit Service fb6fa5
 */
Packit Service fb6fa5
Packit Service fb6fa5
/*
Packit Service fb6fa5
 * Modified by the GTK+ Team and others 1997-2001.  See the AUTHORS
Packit Service fb6fa5
 * file for a list of people on the GTK+ Team.  See the ChangeLog
Packit Service fb6fa5
 * files for a list of changes.  These files are distributed with
Packit Service fb6fa5
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
Packit Service fb6fa5
 */
Packit Service fb6fa5
Packit Service fb6fa5
#include "config.h"
Packit Service fb6fa5
#include <math.h>
Packit Service fb6fa5
#include <string.h>
Packit Service fb6fa5
Packit Service fb6fa5
#include "gdkconfig.h"
Packit Service fb6fa5
#include "gdk/gdkkeysyms.h"
Packit Service fb6fa5
#include "gtkcolorsel.h"
Packit Service fb6fa5
#include "gtkhsv.h"
Packit Service fb6fa5
#include "gtkwindow.h"
Packit Service fb6fa5
#include "gtkselection.h"
Packit Service fb6fa5
#include "gtkdnd.h"
Packit Service fb6fa5
#include "gtkdrawingarea.h"
Packit Service fb6fa5
#include "gtkhbox.h"
Packit Service fb6fa5
#include "gtkhbbox.h"
Packit Service fb6fa5
#include "gtkrc.h"
Packit Service fb6fa5
#include "gtkframe.h"
Packit Service fb6fa5
#include "gtktable.h"
Packit Service fb6fa5
#include "gtklabel.h"
Packit Service fb6fa5
#include "gtkmarshalers.h"
Packit Service fb6fa5
#include "gtkimage.h"
Packit Service fb6fa5
#include "gtkspinbutton.h"
Packit Service fb6fa5
#include "gtkrange.h"
Packit Service fb6fa5
#include "gtkhscale.h"
Packit Service fb6fa5
#include "gtkentry.h"
Packit Service fb6fa5
#include "gtkbutton.h"
Packit Service fb6fa5
#include "gtkhseparator.h"
Packit Service fb6fa5
#include "gtkinvisible.h"
Packit Service fb6fa5
#include "gtkmenuitem.h"
Packit Service fb6fa5
#include "gtkmain.h"
Packit Service fb6fa5
#include "gtksettings.h"
Packit Service fb6fa5
#include "gtkstock.h"
Packit Service fb6fa5
#include "gtkaccessible.h"
Packit Service fb6fa5
#include "gtkprivate.h"
Packit Service fb6fa5
#include "gtkintl.h"
Packit Service fb6fa5
#include "gtkalias.h"
Packit Service fb6fa5
Packit Service fb6fa5
/* Keep it in sync with gtksettings.c:default_color_palette */
Packit Service fb6fa5
#define DEFAULT_COLOR_PALETTE   "black:white:gray50:red:purple:blue:light blue:green:yellow:orange:lavender:brown:goldenrod4:dodger blue:pink:light green:gray10:gray30:gray75:gray90"
Packit Service fb6fa5
Packit Service fb6fa5
/* Number of elements in the custom palatte */
Packit Service fb6fa5
#define GTK_CUSTOM_PALETTE_WIDTH 10
Packit Service fb6fa5
#define GTK_CUSTOM_PALETTE_HEIGHT 2
Packit Service fb6fa5
Packit Service fb6fa5
#define CUSTOM_PALETTE_ENTRY_WIDTH   20
Packit Service fb6fa5
#define CUSTOM_PALETTE_ENTRY_HEIGHT  20
Packit Service fb6fa5
Packit Service fb6fa5
/* The cursor for the dropper */
Packit Service fb6fa5
#define DROPPER_WIDTH 17
Packit Service fb6fa5
#define DROPPER_HEIGHT 17
Packit Service fb6fa5
#define DROPPER_STRIDE 4
Packit Service fb6fa5
#define DROPPER_X_HOT 2
Packit Service fb6fa5
#define DROPPER_Y_HOT 16
Packit Service fb6fa5
Packit Service fb6fa5
#define SAMPLE_WIDTH  64
Packit Service fb6fa5
#define SAMPLE_HEIGHT 28
Packit Service fb6fa5
#define CHECK_SIZE 16  
Packit Service fb6fa5
#define BIG_STEP 20
Packit Service fb6fa5
Packit Service fb6fa5
/* Conversion between 0->1 double and and guint16. See
Packit Service fb6fa5
 * scale_round() below for more general conversions
Packit Service fb6fa5
 */
Packit Service fb6fa5
#define SCALE(i) (i / 65535.)
Packit Service fb6fa5
#define UNSCALE(d) ((guint16)(d * 65535 + 0.5))
Packit Service fb6fa5
#define INTENSITY(r, g, b) ((r) * 0.30 + (g) * 0.59 + (b) * 0.11)
Packit Service fb6fa5
Packit Service fb6fa5
enum {
Packit Service fb6fa5
  COLOR_CHANGED,
Packit Service fb6fa5
  LAST_SIGNAL
Packit Service fb6fa5
};
Packit Service fb6fa5
Packit Service fb6fa5
enum {
Packit Service fb6fa5
  PROP_0,
Packit Service fb6fa5
  PROP_HAS_PALETTE,
Packit Service fb6fa5
  PROP_HAS_OPACITY_CONTROL,
Packit Service fb6fa5
  PROP_CURRENT_COLOR,
Packit Service fb6fa5
  PROP_CURRENT_ALPHA
Packit Service fb6fa5
};
Packit Service fb6fa5
Packit Service fb6fa5
enum {
Packit Service fb6fa5
  COLORSEL_RED = 0,
Packit Service fb6fa5
  COLORSEL_GREEN = 1,
Packit Service fb6fa5
  COLORSEL_BLUE = 2,
Packit Service fb6fa5
  COLORSEL_OPACITY = 3,
Packit Service fb6fa5
  COLORSEL_HUE,
Packit Service fb6fa5
  COLORSEL_SATURATION,
Packit Service fb6fa5
  COLORSEL_VALUE,
Packit Service fb6fa5
  COLORSEL_NUM_CHANNELS
Packit Service fb6fa5
};
Packit Service fb6fa5
Packit Service fb6fa5
typedef struct _ColorSelectionPrivate ColorSelectionPrivate;
Packit Service fb6fa5
Packit Service fb6fa5
struct _ColorSelectionPrivate
Packit Service fb6fa5
{
Packit Service fb6fa5
  guint has_opacity : 1;
Packit Service fb6fa5
  guint has_palette : 1;
Packit Service fb6fa5
  guint changing : 1;
Packit Service fb6fa5
  guint default_set : 1;
Packit Service fb6fa5
  guint default_alpha_set : 1;
Packit Service fb6fa5
  guint has_grab : 1;
Packit Service fb6fa5
  
Packit Service fb6fa5
  gdouble color[COLORSEL_NUM_CHANNELS];
Packit Service fb6fa5
  gdouble old_color[COLORSEL_NUM_CHANNELS];
Packit Service fb6fa5
  
Packit Service fb6fa5
  GtkWidget *triangle_colorsel;
Packit Service fb6fa5
  GtkWidget *hue_spinbutton;
Packit Service fb6fa5
  GtkWidget *sat_spinbutton;
Packit Service fb6fa5
  GtkWidget *val_spinbutton;
Packit Service fb6fa5
  GtkWidget *red_spinbutton;
Packit Service fb6fa5
  GtkWidget *green_spinbutton;
Packit Service fb6fa5
  GtkWidget *blue_spinbutton;
Packit Service fb6fa5
  GtkWidget *opacity_slider;
Packit Service fb6fa5
  GtkWidget *opacity_label;
Packit Service fb6fa5
  GtkWidget *opacity_entry;
Packit Service fb6fa5
  GtkWidget *palette_frame;
Packit Service fb6fa5
  GtkWidget *hex_entry;
Packit Service fb6fa5
  
Packit Service fb6fa5
  /* The Palette code */
Packit Service fb6fa5
  GtkWidget *custom_palette [GTK_CUSTOM_PALETTE_WIDTH][GTK_CUSTOM_PALETTE_HEIGHT];
Packit Service fb6fa5
  
Packit Service fb6fa5
  /* The color_sample stuff */
Packit Service fb6fa5
  GtkWidget *sample_area;
Packit Service fb6fa5
  GtkWidget *old_sample;
Packit Service fb6fa5
  GtkWidget *cur_sample;
Packit Service fb6fa5
  GtkWidget *colorsel;
Packit Service fb6fa5
Packit Service fb6fa5
  /* Window for grabbing on */
Packit Service fb6fa5
  GtkWidget *dropper_grab_widget;
Packit Service fb6fa5
  guint32    grab_time;
Packit Service fb6fa5
Packit Service fb6fa5
  /* Connection to settings */
Packit Service fb6fa5
  gulong settings_connection;
Packit Service fb6fa5
};
Packit Service fb6fa5
Packit Service fb6fa5
Packit Service fb6fa5
static void gtk_color_selection_destroy		(GtkObject		 *object);
Packit Service fb6fa5
static void gtk_color_selection_finalize        (GObject		 *object);
Packit Service fb6fa5
static void update_color			(GtkColorSelection	 *colorsel);
Packit Service fb6fa5
static void gtk_color_selection_set_property    (GObject                 *object,
Packit Service fb6fa5
					         guint                    prop_id,
Packit Service fb6fa5
					         const GValue            *value,
Packit Service fb6fa5
					         GParamSpec              *pspec);
Packit Service fb6fa5
static void gtk_color_selection_get_property    (GObject                 *object,
Packit Service fb6fa5
					         guint                    prop_id,
Packit Service fb6fa5
					         GValue                  *value,
Packit Service fb6fa5
					         GParamSpec              *pspec);
Packit Service fb6fa5
Packit Service fb6fa5
static void gtk_color_selection_realize         (GtkWidget               *widget);
Packit Service fb6fa5
static void gtk_color_selection_unrealize       (GtkWidget               *widget);
Packit Service fb6fa5
static void gtk_color_selection_show_all        (GtkWidget               *widget);
Packit Service fb6fa5
static gboolean gtk_color_selection_grab_broken (GtkWidget               *widget,
Packit Service fb6fa5
						 GdkEventGrabBroken      *event);
Packit Service fb6fa5
Packit Service fb6fa5
static void     gtk_color_selection_set_palette_color   (GtkColorSelection *colorsel,
Packit Service fb6fa5
                                                         gint               index,
Packit Service fb6fa5
                                                         GdkColor          *color);
Packit Service fb6fa5
static void     set_focus_line_attributes               (GtkWidget         *drawing_area,
Packit Service fb6fa5
							 cairo_t           *cr,
Packit Service fb6fa5
							 gint              *focus_width);
Packit Service fb6fa5
static void     default_noscreen_change_palette_func    (const GdkColor    *colors,
Packit Service fb6fa5
							 gint               n_colors);
Packit Service fb6fa5
static void     default_change_palette_func             (GdkScreen	   *screen,
Packit Service fb6fa5
							 const GdkColor    *colors,
Packit Service fb6fa5
							 gint               n_colors);
Packit Service fb6fa5
static void     make_control_relations                  (AtkObject         *atk_obj,
Packit Service fb6fa5
                                                         GtkWidget         *widget);
Packit Service fb6fa5
static void     make_all_relations                      (AtkObject         *atk_obj,
Packit Service fb6fa5
                                                         ColorSelectionPrivate *priv);
Packit Service fb6fa5
Packit Service fb6fa5
static void 	hsv_changed                             (GtkWidget         *hsv,
Packit Service fb6fa5
							 gpointer           data);
Packit Service fb6fa5
static void 	get_screen_color                        (GtkWidget         *button);
Packit Service fb6fa5
static void 	adjustment_changed                      (GtkAdjustment     *adjustment,
Packit Service fb6fa5
							 gpointer           data);
Packit Service fb6fa5
static void 	opacity_entry_changed                   (GtkWidget 	   *opacity_entry,
Packit Service fb6fa5
							 gpointer  	    data);
Packit Service fb6fa5
static void 	hex_changed                             (GtkWidget 	   *hex_entry,
Packit Service fb6fa5
							 gpointer  	    data);
Packit Service fb6fa5
static gboolean hex_focus_out                           (GtkWidget     	   *hex_entry, 
Packit Service fb6fa5
							 GdkEventFocus 	   *event,
Packit Service fb6fa5
							 gpointer      	    data);
Packit Service fb6fa5
static void 	color_sample_new                        (GtkColorSelection *colorsel);
Packit Service fb6fa5
static void 	make_label_spinbutton     		(GtkColorSelection *colorsel,
Packit Service fb6fa5
	    				  		 GtkWidget        **spinbutton,
Packit Service fb6fa5
	    				  		 gchar             *text,
Packit Service fb6fa5
	    				  		 GtkWidget         *table,
Packit Service fb6fa5
	    				  		 gint               i,
Packit Service fb6fa5
	    				  		 gint               j,
Packit Service fb6fa5
	    				  		 gint               channel_type,
Packit Service fb6fa5
	    				  		 const gchar       *tooltip);
Packit Service fb6fa5
static void 	make_palette_frame                      (GtkColorSelection *colorsel,
Packit Service fb6fa5
							 GtkWidget         *table,
Packit Service fb6fa5
							 gint               i,
Packit Service fb6fa5
							 gint               j);
Packit Service fb6fa5
static void 	set_selected_palette                    (GtkColorSelection *colorsel,
Packit Service fb6fa5
							 int                x,
Packit Service fb6fa5
							 int                y);
Packit Service fb6fa5
static void 	set_focus_line_attributes               (GtkWidget 	   *drawing_area,
Packit Service fb6fa5
							 cairo_t   	   *cr,
Packit Service fb6fa5
							 gint      	   *focus_width);
Packit Service fb6fa5
static gboolean mouse_press 		     	       	(GtkWidget         *invisible,
Packit Service fb6fa5
                            		     	       	 GdkEventButton    *event,
Packit Service fb6fa5
                            		     	       	 gpointer           data);
Packit Service fb6fa5
static void  palette_change_notify_instance (GObject    *object,
Packit Service fb6fa5
					     GParamSpec *pspec,
Packit Service fb6fa5
					     gpointer    data);
Packit Service fb6fa5
static void update_palette (GtkColorSelection *colorsel);
Packit Service fb6fa5
static void shutdown_eyedropper (GtkWidget *widget);
Packit Service fb6fa5
Packit Service fb6fa5
static guint color_selection_signals[LAST_SIGNAL] = { 0 };
Packit Service fb6fa5
Packit Service fb6fa5
static GtkColorSelectionChangePaletteFunc noscreen_change_palette_hook = default_noscreen_change_palette_func;
Packit Service fb6fa5
static GtkColorSelectionChangePaletteWithScreenFunc change_palette_hook = default_change_palette_func;
Packit Service fb6fa5
Packit Service fb6fa5
static const guchar dropper_bits[] = {
Packit Service fb6fa5
  0xff, 0x8f, 0x01, 0x00,  0xff, 0x77, 0x01, 0x00,
Packit Service fb6fa5
  0xff, 0xfb, 0x00, 0x00,  0xff, 0xf8, 0x00, 0x00,
Packit Service fb6fa5
  0x7f, 0xff, 0x00, 0x00,  0xff, 0x7e, 0x01, 0x00,
Packit Service fb6fa5
  0xff, 0x9d, 0x01, 0x00,  0xff, 0xd8, 0x01, 0x00,
Packit Service fb6fa5
  0x7f, 0xd4, 0x01, 0x00,  0x3f, 0xee, 0x01, 0x00,
Packit Service fb6fa5
  0x1f, 0xff, 0x01, 0x00,  0x8f, 0xff, 0x01, 0x00,
Packit Service fb6fa5
  0xc7, 0xff, 0x01, 0x00,  0xe3, 0xff, 0x01, 0x00,
Packit Service fb6fa5
  0xf3, 0xff, 0x01, 0x00,  0xfd, 0xff, 0x01, 0x00,
Packit Service fb6fa5
  0xff, 0xff, 0x01, 0x00 };
Packit Service fb6fa5
Packit Service fb6fa5
static const guchar dropper_mask[] = {
Packit Service fb6fa5
  0x00, 0x70, 0x00, 0x00,  0x00, 0xf8, 0x00, 0x00,
Packit Service fb6fa5
  0x00, 0xfc, 0x01, 0x00,  0x00, 0xff, 0x01, 0x00,
Packit Service fb6fa5
  0x80, 0xff, 0x01, 0x00,  0x00, 0xff, 0x00, 0x00,
Packit Service fb6fa5
  0x00, 0x7f, 0x00, 0x00,  0x80, 0x3f, 0x00, 0x00,
Packit Service fb6fa5
  0xc0, 0x3f, 0x00, 0x00,  0xe0, 0x13, 0x00, 0x00,
Packit Service fb6fa5
  0xf0, 0x01, 0x00, 0x00,  0xf8, 0x00, 0x00, 0x00,
Packit Service fb6fa5
  0x7c, 0x00, 0x00, 0x00,  0x3e, 0x00, 0x00, 0x00,
Packit Service fb6fa5
  0x1e, 0x00, 0x00, 0x00,  0x0d, 0x00, 0x00, 0x00,
Packit Service fb6fa5
  0x02, 0x00, 0x00, 0x00 };
Packit Service fb6fa5
Packit Service fb6fa5
G_DEFINE_TYPE (GtkColorSelection, gtk_color_selection, GTK_TYPE_VBOX)
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_color_selection_class_init (GtkColorSelectionClass *klass)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GObjectClass *gobject_class;
Packit Service fb6fa5
  GtkObjectClass *object_class;
Packit Service fb6fa5
  GtkWidgetClass *widget_class;
Packit Service fb6fa5
  
Packit Service fb6fa5
  gobject_class = G_OBJECT_CLASS (klass);
Packit Service fb6fa5
  gobject_class->finalize = gtk_color_selection_finalize;
Packit Service fb6fa5
  gobject_class->set_property = gtk_color_selection_set_property;
Packit Service fb6fa5
  gobject_class->get_property = gtk_color_selection_get_property;
Packit Service fb6fa5
Packit Service fb6fa5
  object_class = GTK_OBJECT_CLASS (klass);
Packit Service fb6fa5
  object_class->destroy = gtk_color_selection_destroy;
Packit Service fb6fa5
  
Packit Service fb6fa5
  widget_class = GTK_WIDGET_CLASS (klass);
Packit Service fb6fa5
  widget_class->realize = gtk_color_selection_realize;
Packit Service fb6fa5
  widget_class->unrealize = gtk_color_selection_unrealize;
Packit Service fb6fa5
  widget_class->show_all = gtk_color_selection_show_all;
Packit Service fb6fa5
  widget_class->grab_broken_event = gtk_color_selection_grab_broken;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_object_class_install_property (gobject_class,
Packit Service fb6fa5
                                   PROP_HAS_OPACITY_CONTROL,
Packit Service fb6fa5
                                   g_param_spec_boolean ("has-opacity-control",
Packit Service fb6fa5
							 P_("Has Opacity Control"),
Packit Service fb6fa5
							 P_("Whether the color selector should allow setting opacity"),
Packit Service fb6fa5
							 FALSE,
Packit Service fb6fa5
							 GTK_PARAM_READWRITE));
Packit Service fb6fa5
  g_object_class_install_property (gobject_class,
Packit Service fb6fa5
                                   PROP_HAS_PALETTE,
Packit Service fb6fa5
                                   g_param_spec_boolean ("has-palette",
Packit Service fb6fa5
							 P_("Has palette"),
Packit Service fb6fa5
							 P_("Whether a palette should be used"),
Packit Service fb6fa5
							 FALSE,
Packit Service fb6fa5
							 GTK_PARAM_READWRITE));
Packit Service fb6fa5
  g_object_class_install_property (gobject_class,
Packit Service fb6fa5
                                   PROP_CURRENT_COLOR,
Packit Service fb6fa5
                                   g_param_spec_boxed ("current-color",
Packit Service fb6fa5
                                                       P_("Current Color"),
Packit Service fb6fa5
                                                       P_("The current color"),
Packit Service fb6fa5
                                                       GDK_TYPE_COLOR,
Packit Service fb6fa5
                                                       GTK_PARAM_READWRITE));
Packit Service fb6fa5
  g_object_class_install_property (gobject_class,
Packit Service fb6fa5
                                   PROP_CURRENT_ALPHA,
Packit Service fb6fa5
                                   g_param_spec_uint ("current-alpha",
Packit Service fb6fa5
						      P_("Current Alpha"),
Packit Service fb6fa5
						      P_("The current opacity value (0 fully transparent, 65535 fully opaque)"),
Packit Service fb6fa5
						      0, 65535, 65535,
Packit Service fb6fa5
						      GTK_PARAM_READWRITE));
Packit Service fb6fa5
  
Packit Service fb6fa5
  color_selection_signals[COLOR_CHANGED] =
Packit Service fb6fa5
    g_signal_new (I_("color-changed"),
Packit Service fb6fa5
		  G_OBJECT_CLASS_TYPE (object_class),
Packit Service fb6fa5
		  G_SIGNAL_RUN_FIRST,
Packit Service fb6fa5
		  G_STRUCT_OFFSET (GtkColorSelectionClass, color_changed),
Packit Service fb6fa5
		  NULL, NULL,
Packit Service fb6fa5
		  _gtk_marshal_VOID__VOID,
Packit Service fb6fa5
		  G_TYPE_NONE, 0);
Packit Service fb6fa5
Packit Service fb6fa5
  g_type_class_add_private (gobject_class, sizeof (ColorSelectionPrivate));
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_color_selection_init (GtkColorSelection *colorsel)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkWidget *top_hbox;
Packit Service fb6fa5
  GtkWidget *top_right_vbox;
Packit Service fb6fa5
  GtkWidget *table, *label, *hbox, *frame, *vbox, *button;
Packit Service fb6fa5
  GtkAdjustment *adjust;
Packit Service fb6fa5
  GtkWidget *picker_image;
Packit Service fb6fa5
  gint i, j;
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  AtkObject *atk_obj;
Packit Service fb6fa5
  GList *focus_chain = NULL;
Packit Service fb6fa5
  
Packit Service fb6fa5
  gtk_widget_push_composite_child ();
Packit Service fb6fa5
Packit Service fb6fa5
  priv = colorsel->private_data = G_TYPE_INSTANCE_GET_PRIVATE (colorsel, GTK_TYPE_COLOR_SELECTION, ColorSelectionPrivate);
Packit Service fb6fa5
  priv->changing = FALSE;
Packit Service fb6fa5
  priv->default_set = FALSE;
Packit Service fb6fa5
  priv->default_alpha_set = FALSE;
Packit Service fb6fa5
  
Packit Service fb6fa5
  top_hbox = gtk_hbox_new (FALSE, 12);
Packit Service fb6fa5
  gtk_box_pack_start (GTK_BOX (colorsel), top_hbox, FALSE, FALSE, 0);
Packit Service fb6fa5
  
Packit Service fb6fa5
  vbox = gtk_vbox_new (FALSE, 6);
Packit Service fb6fa5
  priv->triangle_colorsel = gtk_hsv_new ();
Packit Service fb6fa5
  g_signal_connect (priv->triangle_colorsel, "changed",
Packit Service fb6fa5
                    G_CALLBACK (hsv_changed), colorsel);
Packit Service fb6fa5
  gtk_hsv_set_metrics (GTK_HSV (priv->triangle_colorsel), 174, 15);
Packit Service fb6fa5
  gtk_box_pack_start (GTK_BOX (top_hbox), vbox, FALSE, FALSE, 0);
Packit Service fb6fa5
  gtk_box_pack_start (GTK_BOX (vbox), priv->triangle_colorsel, FALSE, FALSE, 0);
Packit Service fb6fa5
  gtk_widget_set_tooltip_text (priv->triangle_colorsel,
Packit Service fb6fa5
                        _("Select the color you want from the outer ring. Select the darkness or lightness of that color using the inner triangle."));
Packit Service fb6fa5
  
Packit Service fb6fa5
  hbox = gtk_hbox_new (FALSE, 6);
Packit Service fb6fa5
  gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
Packit Service fb6fa5
  
Packit Service fb6fa5
  frame = gtk_frame_new (NULL);
Packit Service fb6fa5
  gtk_widget_set_size_request (frame, -1, 30);
Packit Service fb6fa5
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
Packit Service fb6fa5
  color_sample_new (colorsel);
Packit Service fb6fa5
  gtk_container_add (GTK_CONTAINER (frame), priv->sample_area);
Packit Service fb6fa5
  gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
Packit Service fb6fa5
  
Packit Service fb6fa5
  button = gtk_button_new ();
Packit Service fb6fa5
Packit Service fb6fa5
  gtk_widget_set_events (button, GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
Packit Service fb6fa5
  g_object_set_data (G_OBJECT (button), I_("COLORSEL"), colorsel); 
Packit Service fb6fa5
  g_signal_connect (button, "clicked",
Packit Service fb6fa5
                    G_CALLBACK (get_screen_color), NULL);
Packit Service fb6fa5
  picker_image = gtk_image_new_from_stock (GTK_STOCK_COLOR_PICKER, GTK_ICON_SIZE_BUTTON);
Packit Service fb6fa5
  gtk_container_add (GTK_CONTAINER (button), picker_image);
Packit Service fb6fa5
  gtk_widget_show (GTK_WIDGET (picker_image));
Packit Service fb6fa5
  gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
Packit Service fb6fa5
Packit Service fb6fa5
  gtk_widget_set_tooltip_text (button,
Packit Service fb6fa5
                        _("Click the eyedropper, then click a color anywhere on your screen to select that color."));
Packit Service fb6fa5
  
Packit Service fb6fa5
  top_right_vbox = gtk_vbox_new (FALSE, 6);
Packit Service fb6fa5
  gtk_box_pack_start (GTK_BOX (top_hbox), top_right_vbox, FALSE, FALSE, 0);
Packit Service fb6fa5
  table = gtk_table_new (8, 6, FALSE);
Packit Service fb6fa5
  gtk_box_pack_start (GTK_BOX (top_right_vbox), table, FALSE, FALSE, 0);
Packit Service fb6fa5
  gtk_table_set_row_spacings (GTK_TABLE (table), 6);
Packit Service fb6fa5
  gtk_table_set_col_spacings (GTK_TABLE (table), 12);
Packit Service fb6fa5
  
Packit Service fb6fa5
  make_label_spinbutton (colorsel, &priv->hue_spinbutton, _("_Hue:"), table, 0, 0, COLORSEL_HUE,
Packit Service fb6fa5
                         _("Position on the color wheel."));
Packit Service fb6fa5
  gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (priv->hue_spinbutton), TRUE);
Packit Service fb6fa5
  make_label_spinbutton (colorsel, &priv->sat_spinbutton, _("_Saturation:"), table, 0, 1, COLORSEL_SATURATION,
Packit Service fb6fa5
                         _("\"Deepness\" of the color."));
Packit Service fb6fa5
  make_label_spinbutton (colorsel, &priv->val_spinbutton, _("_Value:"), table, 0, 2, COLORSEL_VALUE,
Packit Service fb6fa5
                         _("Brightness of the color."));
Packit Service fb6fa5
  make_label_spinbutton (colorsel, &priv->red_spinbutton, _("_Red:"), table, 6, 0, COLORSEL_RED,
Packit Service fb6fa5
                         _("Amount of red light in the color."));
Packit Service fb6fa5
  make_label_spinbutton (colorsel, &priv->green_spinbutton, _("_Green:"), table, 6, 1, COLORSEL_GREEN,
Packit Service fb6fa5
                         _("Amount of green light in the color."));
Packit Service fb6fa5
  make_label_spinbutton (colorsel, &priv->blue_spinbutton, _("_Blue:"), table, 6, 2, COLORSEL_BLUE,
Packit Service fb6fa5
                         _("Amount of blue light in the color."));
Packit Service fb6fa5
  gtk_table_attach_defaults (GTK_TABLE (table), gtk_hseparator_new (), 0, 8, 3, 4); 
Packit Service fb6fa5
Packit Service fb6fa5
  priv->opacity_label = gtk_label_new_with_mnemonic (_("Op_acity:")); 
Packit Service fb6fa5
  gtk_misc_set_alignment (GTK_MISC (priv->opacity_label), 0.0, 0.5); 
Packit Service fb6fa5
  gtk_table_attach_defaults (GTK_TABLE (table), priv->opacity_label, 0, 1, 4, 5); 
Packit Service fb6fa5
  adjust = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 255.0, 1.0, 1.0, 0.0)); 
Packit Service fb6fa5
  g_object_set_data (G_OBJECT (adjust), I_("COLORSEL"), colorsel); 
Packit Service fb6fa5
  priv->opacity_slider = gtk_hscale_new (adjust);
Packit Service fb6fa5
  gtk_widget_set_tooltip_text (priv->opacity_slider,
Packit Service fb6fa5
                        _("Transparency of the color."));
Packit Service fb6fa5
  gtk_label_set_mnemonic_widget (GTK_LABEL (priv->opacity_label),
Packit Service fb6fa5
                                 priv->opacity_slider);
Packit Service fb6fa5
  gtk_scale_set_draw_value (GTK_SCALE (priv->opacity_slider), FALSE);
Packit Service fb6fa5
  g_signal_connect (adjust, "value-changed",
Packit Service fb6fa5
                    G_CALLBACK (adjustment_changed),
Packit Service fb6fa5
                    GINT_TO_POINTER (COLORSEL_OPACITY));
Packit Service fb6fa5
  gtk_table_attach_defaults (GTK_TABLE (table), priv->opacity_slider, 1, 7, 4, 5); 
Packit Service fb6fa5
  priv->opacity_entry = gtk_entry_new (); 
Packit Service fb6fa5
  gtk_widget_set_tooltip_text (priv->opacity_entry,
Packit Service fb6fa5
                        _("Transparency of the color."));
Packit Service fb6fa5
  gtk_widget_set_size_request (priv->opacity_entry, 40, -1); 
Packit Service fb6fa5
Packit Service fb6fa5
  g_signal_connect (priv->opacity_entry, "activate",
Packit Service fb6fa5
                    G_CALLBACK (opacity_entry_changed), colorsel);
Packit Service fb6fa5
  gtk_table_attach_defaults (GTK_TABLE (table), priv->opacity_entry, 7, 8, 4, 5);
Packit Service fb6fa5
  
Packit Service fb6fa5
  label = gtk_label_new_with_mnemonic (_("Color _name:"));
Packit Service fb6fa5
  gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 5, 6);
Packit Service fb6fa5
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
Packit Service fb6fa5
  priv->hex_entry = gtk_entry_new ();
Packit Service fb6fa5
Packit Service fb6fa5
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), priv->hex_entry);
Packit Service fb6fa5
Packit Service fb6fa5
  g_signal_connect (priv->hex_entry, "activate",
Packit Service fb6fa5
                    G_CALLBACK (hex_changed), colorsel);
Packit Service fb6fa5
Packit Service fb6fa5
  g_signal_connect (priv->hex_entry, "focus-out-event",
Packit Service fb6fa5
                    G_CALLBACK (hex_focus_out), colorsel);
Packit Service fb6fa5
Packit Service fb6fa5
  gtk_widget_set_tooltip_text (priv->hex_entry,
Packit Service fb6fa5
                        _("You can enter an HTML-style hexadecimal color value, or simply a color name such as 'orange' in this entry."));
Packit Service fb6fa5
  
Packit Service fb6fa5
  gtk_entry_set_width_chars (GTK_ENTRY (priv->hex_entry), 7);
Packit Service fb6fa5
  gtk_table_attach_defaults (GTK_TABLE (table), priv->hex_entry, 1, 5, 5, 6);
Packit Service fb6fa5
Packit Service fb6fa5
  focus_chain = g_list_append (focus_chain, priv->hue_spinbutton);
Packit Service fb6fa5
  focus_chain = g_list_append (focus_chain, priv->sat_spinbutton);
Packit Service fb6fa5
  focus_chain = g_list_append (focus_chain, priv->val_spinbutton);
Packit Service fb6fa5
  focus_chain = g_list_append (focus_chain, priv->red_spinbutton);
Packit Service fb6fa5
  focus_chain = g_list_append (focus_chain, priv->green_spinbutton);
Packit Service fb6fa5
  focus_chain = g_list_append (focus_chain, priv->blue_spinbutton);
Packit Service fb6fa5
  focus_chain = g_list_append (focus_chain, priv->opacity_slider);
Packit Service fb6fa5
  focus_chain = g_list_append (focus_chain, priv->opacity_entry);
Packit Service fb6fa5
  focus_chain = g_list_append (focus_chain, priv->hex_entry);
Packit Service fb6fa5
  gtk_container_set_focus_chain (GTK_CONTAINER (table), focus_chain);
Packit Service fb6fa5
  g_list_free (focus_chain);
Packit Service fb6fa5
Packit Service fb6fa5
  /* Set up the palette */
Packit Service fb6fa5
  table = gtk_table_new (GTK_CUSTOM_PALETTE_HEIGHT, GTK_CUSTOM_PALETTE_WIDTH, TRUE);
Packit Service fb6fa5
  gtk_table_set_row_spacings (GTK_TABLE (table), 1);
Packit Service fb6fa5
  gtk_table_set_col_spacings (GTK_TABLE (table), 1);
Packit Service fb6fa5
  for (i = 0; i < GTK_CUSTOM_PALETTE_WIDTH; i++)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      for (j = 0; j < GTK_CUSTOM_PALETTE_HEIGHT; j++)
Packit Service fb6fa5
	{
Packit Service fb6fa5
	  make_palette_frame (colorsel, table, i, j);
Packit Service fb6fa5
	}
Packit Service fb6fa5
    }
Packit Service fb6fa5
  set_selected_palette (colorsel, 0, 0);
Packit Service fb6fa5
  priv->palette_frame = gtk_vbox_new (FALSE, 6);
Packit Service fb6fa5
  label = gtk_label_new_with_mnemonic (_("_Palette:"));
Packit Service fb6fa5
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
Packit Service fb6fa5
  gtk_box_pack_start (GTK_BOX (priv->palette_frame), label, FALSE, FALSE, 0);
Packit Service fb6fa5
Packit Service fb6fa5
  gtk_label_set_mnemonic_widget (GTK_LABEL (label),
Packit Service fb6fa5
                                 priv->custom_palette[0][0]);
Packit Service fb6fa5
  
Packit Service fb6fa5
  gtk_box_pack_end (GTK_BOX (top_right_vbox), priv->palette_frame, FALSE, FALSE, 0);
Packit Service fb6fa5
  gtk_box_pack_start (GTK_BOX (priv->palette_frame), table, FALSE, FALSE, 0);
Packit Service fb6fa5
  
Packit Service fb6fa5
  gtk_widget_show_all (top_hbox);
Packit Service fb6fa5
Packit Service fb6fa5
  /* hide unused stuff */
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (priv->has_opacity == FALSE)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      gtk_widget_hide (priv->opacity_label);
Packit Service fb6fa5
      gtk_widget_hide (priv->opacity_slider);
Packit Service fb6fa5
      gtk_widget_hide (priv->opacity_entry);
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (priv->has_palette == FALSE)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      gtk_widget_hide (priv->palette_frame);
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  atk_obj = gtk_widget_get_accessible (priv->triangle_colorsel);
Packit Service fb6fa5
  if (GTK_IS_ACCESSIBLE (atk_obj))
Packit Service fb6fa5
    {
Packit Service fb6fa5
      atk_object_set_name (atk_obj, _("Color Wheel"));
Packit Service fb6fa5
      atk_object_set_role (gtk_widget_get_accessible (GTK_WIDGET (colorsel)), ATK_ROLE_COLOR_CHOOSER);
Packit Service fb6fa5
      make_all_relations (atk_obj, priv);
Packit Service fb6fa5
    } 
Packit Service fb6fa5
Packit Service fb6fa5
  gtk_widget_pop_composite_child ();
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/* GObject methods */
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_color_selection_finalize (GObject *object)
Packit Service fb6fa5
{
Packit Service fb6fa5
  G_OBJECT_CLASS (gtk_color_selection_parent_class)->finalize (object);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_color_selection_set_property (GObject         *object,
Packit Service fb6fa5
				  guint            prop_id,
Packit Service fb6fa5
				  const GValue    *value,
Packit Service fb6fa5
				  GParamSpec      *pspec)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkColorSelection *colorsel = GTK_COLOR_SELECTION (object);
Packit Service fb6fa5
  
Packit Service fb6fa5
  switch (prop_id)
Packit Service fb6fa5
    {
Packit Service fb6fa5
    case PROP_HAS_OPACITY_CONTROL:
Packit Service fb6fa5
      gtk_color_selection_set_has_opacity_control (colorsel, 
Packit Service fb6fa5
						   g_value_get_boolean (value));
Packit Service fb6fa5
      break;
Packit Service fb6fa5
    case PROP_HAS_PALETTE:
Packit Service fb6fa5
      gtk_color_selection_set_has_palette (colorsel, 
Packit Service fb6fa5
					   g_value_get_boolean (value));
Packit Service fb6fa5
      break;
Packit Service fb6fa5
    case PROP_CURRENT_COLOR:
Packit Service fb6fa5
      gtk_color_selection_set_current_color (colorsel, g_value_get_boxed (value));
Packit Service fb6fa5
      break;
Packit Service fb6fa5
    case PROP_CURRENT_ALPHA:
Packit Service fb6fa5
      gtk_color_selection_set_current_alpha (colorsel, g_value_get_uint (value));
Packit Service fb6fa5
      break;
Packit Service fb6fa5
    default:
Packit Service fb6fa5
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
Packit Service fb6fa5
      break;
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_color_selection_get_property (GObject     *object,
Packit Service fb6fa5
				  guint        prop_id,
Packit Service fb6fa5
				  GValue      *value,
Packit Service fb6fa5
				  GParamSpec  *pspec)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkColorSelection *colorsel = GTK_COLOR_SELECTION (object);
Packit Service fb6fa5
  GdkColor color;
Packit Service fb6fa5
  
Packit Service fb6fa5
  switch (prop_id)
Packit Service fb6fa5
    {
Packit Service fb6fa5
    case PROP_HAS_OPACITY_CONTROL:
Packit Service fb6fa5
      g_value_set_boolean (value, gtk_color_selection_get_has_opacity_control (colorsel));
Packit Service fb6fa5
      break;
Packit Service fb6fa5
    case PROP_HAS_PALETTE:
Packit Service fb6fa5
      g_value_set_boolean (value, gtk_color_selection_get_has_palette (colorsel));
Packit Service fb6fa5
      break;
Packit Service fb6fa5
    case PROP_CURRENT_COLOR:
Packit Service fb6fa5
      gtk_color_selection_get_current_color (colorsel, &color;;
Packit Service fb6fa5
      g_value_set_boxed (value, &color;;
Packit Service fb6fa5
      break;
Packit Service fb6fa5
    case PROP_CURRENT_ALPHA:
Packit Service fb6fa5
      g_value_set_uint (value, gtk_color_selection_get_current_alpha (colorsel));
Packit Service fb6fa5
      break;
Packit Service fb6fa5
    default:
Packit Service fb6fa5
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
Packit Service fb6fa5
      break;
Packit Service fb6fa5
    }
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/* GtkObject methods */
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_color_selection_destroy (GtkObject *object)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkColorSelection *cselection = GTK_COLOR_SELECTION (object);
Packit Service fb6fa5
  ColorSelectionPrivate *priv = cselection->private_data;
Packit Service fb6fa5
Packit Service fb6fa5
  if (priv->dropper_grab_widget)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      gtk_widget_destroy (priv->dropper_grab_widget);
Packit Service fb6fa5
      priv->dropper_grab_widget = NULL;
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  GTK_OBJECT_CLASS (gtk_color_selection_parent_class)->destroy (object);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/* GtkWidget methods */
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_color_selection_realize (GtkWidget *widget)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkColorSelection *colorsel = GTK_COLOR_SELECTION (widget);
Packit Service fb6fa5
  ColorSelectionPrivate *priv = colorsel->private_data;
Packit Service fb6fa5
  GtkSettings *settings = gtk_widget_get_settings (widget);
Packit Service fb6fa5
Packit Service fb6fa5
  priv->settings_connection =  g_signal_connect (settings,
Packit Service fb6fa5
						 "notify::gtk-color-palette",
Packit Service fb6fa5
						 G_CALLBACK (palette_change_notify_instance),
Packit Service fb6fa5
						 widget);
Packit Service fb6fa5
  update_palette (colorsel);
Packit Service fb6fa5
Packit Service fb6fa5
  GTK_WIDGET_CLASS (gtk_color_selection_parent_class)->realize (widget);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_color_selection_unrealize (GtkWidget *widget)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkColorSelection *colorsel = GTK_COLOR_SELECTION (widget);
Packit Service fb6fa5
  ColorSelectionPrivate *priv = colorsel->private_data;
Packit Service fb6fa5
  GtkSettings *settings = gtk_widget_get_settings (widget);
Packit Service fb6fa5
Packit Service fb6fa5
  g_signal_handler_disconnect (settings, priv->settings_connection);
Packit Service fb6fa5
Packit Service fb6fa5
  GTK_WIDGET_CLASS (gtk_color_selection_parent_class)->unrealize (widget);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/* We override show-all since we have internal widgets that
Packit Service fb6fa5
 * shouldn't be shown when you call show_all(), like the
Packit Service fb6fa5
 * palette and opacity sliders.
Packit Service fb6fa5
 */
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_color_selection_show_all (GtkWidget *widget)
Packit Service fb6fa5
{
Packit Service fb6fa5
  gtk_widget_show (widget);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static gboolean 
Packit Service fb6fa5
gtk_color_selection_grab_broken (GtkWidget          *widget,
Packit Service fb6fa5
				 GdkEventGrabBroken *event)
Packit Service fb6fa5
{
Packit Service fb6fa5
  shutdown_eyedropper (widget);
Packit Service fb6fa5
Packit Service fb6fa5
  return TRUE;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/*
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * The Sample Color
Packit Service fb6fa5
 *
Packit Service fb6fa5
 */
Packit Service fb6fa5
Packit Service fb6fa5
static void color_sample_draw_sample (GtkColorSelection *colorsel, int which);
Packit Service fb6fa5
static void color_sample_update_samples (GtkColorSelection *colorsel);
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
set_color_internal (GtkColorSelection *colorsel,
Packit Service fb6fa5
		    gdouble           *color)
Packit Service fb6fa5
{
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  gint i;
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  priv->changing = TRUE;
Packit Service fb6fa5
  priv->color[COLORSEL_RED] = color[0];
Packit Service fb6fa5
  priv->color[COLORSEL_GREEN] = color[1];
Packit Service fb6fa5
  priv->color[COLORSEL_BLUE] = color[2];
Packit Service fb6fa5
  priv->color[COLORSEL_OPACITY] = color[3];
Packit Service fb6fa5
  gtk_rgb_to_hsv (priv->color[COLORSEL_RED],
Packit Service fb6fa5
		  priv->color[COLORSEL_GREEN],
Packit Service fb6fa5
		  priv->color[COLORSEL_BLUE],
Packit Service fb6fa5
		  &priv->color[COLORSEL_HUE],
Packit Service fb6fa5
		  &priv->color[COLORSEL_SATURATION],
Packit Service fb6fa5
		  &priv->color[COLORSEL_VALUE]);
Packit Service fb6fa5
  if (priv->default_set == FALSE)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      for (i = 0; i < COLORSEL_NUM_CHANNELS; i++)
Packit Service fb6fa5
	priv->old_color[i] = priv->color[i];
Packit Service fb6fa5
    }
Packit Service fb6fa5
  priv->default_set = TRUE;
Packit Service fb6fa5
  priv->default_alpha_set = TRUE;
Packit Service fb6fa5
  update_color (colorsel);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
set_color_icon (GdkDragContext *context,
Packit Service fb6fa5
		gdouble        *colors)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GdkPixbuf *pixbuf;
Packit Service fb6fa5
  guint32 pixel;
Packit Service fb6fa5
Packit Service fb6fa5
  pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE,
Packit Service fb6fa5
			   8, 48, 32);
Packit Service fb6fa5
Packit Service fb6fa5
  pixel = (((UNSCALE (colors[COLORSEL_RED])   & 0xff00) << 16) |
Packit Service fb6fa5
	   ((UNSCALE (colors[COLORSEL_GREEN]) & 0xff00) << 8) |
Packit Service fb6fa5
	   ((UNSCALE (colors[COLORSEL_BLUE])  & 0xff00)));
Packit Service fb6fa5
Packit Service fb6fa5
  gdk_pixbuf_fill (pixbuf, pixel);
Packit Service fb6fa5
  
Packit Service fb6fa5
  gtk_drag_set_icon_pixbuf (context, pixbuf, -2, -2);
Packit Service fb6fa5
  g_object_unref (pixbuf);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
color_sample_drag_begin (GtkWidget      *widget,
Packit Service fb6fa5
			 GdkDragContext *context,
Packit Service fb6fa5
			 gpointer        data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkColorSelection *colorsel = data;
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  gdouble *colsrc;
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (widget == priv->old_sample)
Packit Service fb6fa5
    colsrc = priv->old_color;
Packit Service fb6fa5
  else
Packit Service fb6fa5
    colsrc = priv->color;
Packit Service fb6fa5
Packit Service fb6fa5
  set_color_icon (context, colsrc);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
color_sample_drag_end (GtkWidget      *widget,
Packit Service fb6fa5
		       GdkDragContext *context,
Packit Service fb6fa5
		       gpointer        data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  g_object_set_data (G_OBJECT (widget), I_("gtk-color-selection-drag-window"), NULL);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
color_sample_drop_handle (GtkWidget        *widget,
Packit Service fb6fa5
			  GdkDragContext   *context,
Packit Service fb6fa5
			  gint              x,
Packit Service fb6fa5
			  gint              y,
Packit Service fb6fa5
			  GtkSelectionData *selection_data,
Packit Service fb6fa5
			  guint             info,
Packit Service fb6fa5
			  guint             time,
Packit Service fb6fa5
			  gpointer          data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkColorSelection *colorsel = data;
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  guint16 *vals;
Packit Service fb6fa5
  gdouble color[4];
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  
Packit Service fb6fa5
  /* This is currently a guint16 array of the format:
Packit Service fb6fa5
   * R
Packit Service fb6fa5
   * G
Packit Service fb6fa5
   * B
Packit Service fb6fa5
   * opacity
Packit Service fb6fa5
   */
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (selection_data->length < 0)
Packit Service fb6fa5
    return;
Packit Service fb6fa5
  
Packit Service fb6fa5
  /* We accept drops with the wrong format, since the KDE color
Packit Service fb6fa5
   * chooser incorrectly drops application/x-color with format 8.
Packit Service fb6fa5
   */
Packit Service fb6fa5
  if (selection_data->length != 8)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      g_warning ("Received invalid color data\n");
Packit Service fb6fa5
      return;
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
  vals = (guint16 *)selection_data->data;
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (widget == priv->cur_sample)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      color[0] = (gdouble)vals[0] / 0xffff;
Packit Service fb6fa5
      color[1] = (gdouble)vals[1] / 0xffff;
Packit Service fb6fa5
      color[2] = (gdouble)vals[2] / 0xffff;
Packit Service fb6fa5
      color[3] = (gdouble)vals[3] / 0xffff;
Packit Service fb6fa5
      
Packit Service fb6fa5
      set_color_internal (colorsel, color);
Packit Service fb6fa5
    }
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
color_sample_drag_handle (GtkWidget        *widget,
Packit Service fb6fa5
			  GdkDragContext   *context,
Packit Service fb6fa5
			  GtkSelectionData *selection_data,
Packit Service fb6fa5
			  guint             info,
Packit Service fb6fa5
			  guint             time,
Packit Service fb6fa5
			  gpointer          data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkColorSelection *colorsel = data;
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  guint16 vals[4];
Packit Service fb6fa5
  gdouble *colsrc;
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (widget == priv->old_sample)
Packit Service fb6fa5
    colsrc = priv->old_color;
Packit Service fb6fa5
  else
Packit Service fb6fa5
    colsrc = priv->color;
Packit Service fb6fa5
  
Packit Service fb6fa5
  vals[0] = colsrc[COLORSEL_RED] * 0xffff;
Packit Service fb6fa5
  vals[1] = colsrc[COLORSEL_GREEN] * 0xffff;
Packit Service fb6fa5
  vals[2] = colsrc[COLORSEL_BLUE] * 0xffff;
Packit Service fb6fa5
  vals[3] = priv->has_opacity ? colsrc[COLORSEL_OPACITY] * 0xffff : 0xffff;
Packit Service fb6fa5
  
Packit Service fb6fa5
  gtk_selection_data_set (selection_data,
Packit Service fb6fa5
			  gdk_atom_intern_static_string ("application/x-color"),
Packit Service fb6fa5
			  16, (guchar *)vals, 8);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/* which = 0 means draw old sample, which = 1 means draw new */
Packit Service fb6fa5
static void
Packit Service fb6fa5
color_sample_draw_sample (GtkColorSelection *colorsel, int which)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkWidget *da;
Packit Service fb6fa5
  gint x, y, wid, heig, goff;
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  cairo_t *cr;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_if_fail (colorsel != NULL);
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_if_fail (priv->sample_area != NULL);
Packit Service fb6fa5
  if (!gtk_widget_is_drawable (priv->sample_area))
Packit Service fb6fa5
    return;
Packit Service fb6fa5
Packit Service fb6fa5
  if (which == 0)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      da = priv->old_sample;
Packit Service fb6fa5
      goff = 0;
Packit Service fb6fa5
    }
Packit Service fb6fa5
  else
Packit Service fb6fa5
    {
Packit Service fb6fa5
      da = priv->cur_sample;
Packit Service fb6fa5
      goff =  priv->old_sample->allocation.width % 32;
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  cr = gdk_cairo_create (da->window);
Packit Service fb6fa5
  
Packit Service fb6fa5
  wid = da->allocation.width;
Packit Service fb6fa5
  heig = da->allocation.height;
Packit Service fb6fa5
Packit Service fb6fa5
  /* Below needs tweaking for non-power-of-two */  
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (priv->has_opacity)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      /* Draw checks in background */
Packit Service fb6fa5
Packit Service fb6fa5
      cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
Packit Service fb6fa5
      cairo_rectangle (cr, 0, 0, wid, heig);
Packit Service fb6fa5
      cairo_fill (cr);
Packit Service fb6fa5
Packit Service fb6fa5
      cairo_set_source_rgb (cr, 0.75, 0.75, 0.75);
Packit Service fb6fa5
      for (x = goff & -CHECK_SIZE; x < goff + wid; x += CHECK_SIZE)
Packit Service fb6fa5
	for (y = 0; y < heig; y += CHECK_SIZE)
Packit Service fb6fa5
	  if ((x / CHECK_SIZE + y / CHECK_SIZE) % 2 == 0)
Packit Service fb6fa5
	    cairo_rectangle (cr, x - goff, y, CHECK_SIZE, CHECK_SIZE);
Packit Service fb6fa5
      cairo_fill (cr);
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  if (which == 0)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      cairo_set_source_rgba (cr,
Packit Service fb6fa5
			     priv->old_color[COLORSEL_RED], 
Packit Service fb6fa5
			     priv->old_color[COLORSEL_GREEN], 
Packit Service fb6fa5
			     priv->old_color[COLORSEL_BLUE],
Packit Service fb6fa5
			     priv->has_opacity ?
Packit Service fb6fa5
			        priv->old_color[COLORSEL_OPACITY] : 1.0);
Packit Service fb6fa5
    }
Packit Service fb6fa5
  else
Packit Service fb6fa5
    {
Packit Service fb6fa5
      cairo_set_source_rgba (cr,
Packit Service fb6fa5
			     priv->color[COLORSEL_RED], 
Packit Service fb6fa5
			     priv->color[COLORSEL_GREEN], 
Packit Service fb6fa5
			     priv->color[COLORSEL_BLUE],
Packit Service fb6fa5
			     priv->has_opacity ?
Packit Service fb6fa5
			       priv->color[COLORSEL_OPACITY] : 1.0);
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  cairo_rectangle (cr, 0, 0, wid, heig);
Packit Service fb6fa5
  cairo_fill (cr);
Packit Service fb6fa5
Packit Service fb6fa5
  cairo_destroy (cr);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
color_sample_update_samples (GtkColorSelection *colorsel)
Packit Service fb6fa5
{
Packit Service fb6fa5
  ColorSelectionPrivate *priv = colorsel->private_data;
Packit Service fb6fa5
  gtk_widget_queue_draw (priv->old_sample);
Packit Service fb6fa5
  gtk_widget_queue_draw (priv->cur_sample);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static gboolean
Packit Service fb6fa5
color_old_sample_expose (GtkWidget         *da,
Packit Service fb6fa5
			 GdkEventExpose    *event,
Packit Service fb6fa5
			 GtkColorSelection *colorsel)
Packit Service fb6fa5
{
Packit Service fb6fa5
  color_sample_draw_sample (colorsel, 0);
Packit Service fb6fa5
  return FALSE;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
Packit Service fb6fa5
static gboolean
Packit Service fb6fa5
color_cur_sample_expose (GtkWidget         *da,
Packit Service fb6fa5
			 GdkEventExpose    *event,
Packit Service fb6fa5
			 GtkColorSelection *colorsel)
Packit Service fb6fa5
{
Packit Service fb6fa5
  color_sample_draw_sample (colorsel, 1);
Packit Service fb6fa5
  return FALSE;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
color_sample_setup_dnd (GtkColorSelection *colorsel, GtkWidget *sample)
Packit Service fb6fa5
{
Packit Service fb6fa5
  static const GtkTargetEntry targets[] = {
Packit Service fb6fa5
    { "application/x-color", 0 }
Packit Service fb6fa5
  };
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  
Packit Service fb6fa5
  gtk_drag_source_set (sample,
Packit Service fb6fa5
		       GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
Packit Service fb6fa5
		       targets, 1,
Packit Service fb6fa5
		       GDK_ACTION_COPY | GDK_ACTION_MOVE);
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_signal_connect (sample, "drag-begin",
Packit Service fb6fa5
		    G_CALLBACK (color_sample_drag_begin),
Packit Service fb6fa5
		    colorsel);
Packit Service fb6fa5
  if (sample == priv->cur_sample)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      
Packit Service fb6fa5
      gtk_drag_dest_set (sample,
Packit Service fb6fa5
			 GTK_DEST_DEFAULT_HIGHLIGHT |
Packit Service fb6fa5
			 GTK_DEST_DEFAULT_MOTION |
Packit Service fb6fa5
			 GTK_DEST_DEFAULT_DROP,
Packit Service fb6fa5
			 targets, 1,
Packit Service fb6fa5
			 GDK_ACTION_COPY);
Packit Service fb6fa5
      
Packit Service fb6fa5
      g_signal_connect (sample, "drag-end",
Packit Service fb6fa5
			G_CALLBACK (color_sample_drag_end),
Packit Service fb6fa5
			colorsel);
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_signal_connect (sample, "drag-data-get",
Packit Service fb6fa5
		    G_CALLBACK (color_sample_drag_handle),
Packit Service fb6fa5
		    colorsel);
Packit Service fb6fa5
  g_signal_connect (sample, "drag-data-received",
Packit Service fb6fa5
		    G_CALLBACK (color_sample_drop_handle),
Packit Service fb6fa5
		    colorsel);
Packit Service fb6fa5
  
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
update_tooltips (GtkColorSelection *colorsel)
Packit Service fb6fa5
{
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
Packit Service fb6fa5
  if (priv->has_palette == TRUE)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      gtk_widget_set_tooltip_text (priv->old_sample,
Packit Service fb6fa5
                            _("The previously-selected color, for comparison to the color you're selecting now. You can drag this color to a palette entry, or select this color as current by dragging it to the other color swatch alongside."));
Packit Service fb6fa5
Packit Service fb6fa5
      gtk_widget_set_tooltip_text (priv->cur_sample,
Packit Service fb6fa5
                            _("The color you've chosen. You can drag this color to a palette entry to save it for use in the future."));
Packit Service fb6fa5
    }
Packit Service fb6fa5
  else
Packit Service fb6fa5
    {
Packit Service fb6fa5
      gtk_widget_set_tooltip_text (priv->old_sample,
Packit Service fb6fa5
                            _("The previously-selected color, for comparison to the color you're selecting now."));
Packit Service fb6fa5
Packit Service fb6fa5
      gtk_widget_set_tooltip_text (priv->cur_sample,
Packit Service fb6fa5
                            _("The color you've chosen."));
Packit Service fb6fa5
    }
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
color_sample_new (GtkColorSelection *colorsel)
Packit Service fb6fa5
{
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv->sample_area = gtk_hbox_new (FALSE, 0);
Packit Service fb6fa5
  priv->old_sample = gtk_drawing_area_new ();
Packit Service fb6fa5
  priv->cur_sample = gtk_drawing_area_new ();
Packit Service fb6fa5
Packit Service fb6fa5
  gtk_box_pack_start (GTK_BOX (priv->sample_area), priv->old_sample,
Packit Service fb6fa5
		      TRUE, TRUE, 0);
Packit Service fb6fa5
  gtk_box_pack_start (GTK_BOX (priv->sample_area), priv->cur_sample,
Packit Service fb6fa5
		      TRUE, TRUE, 0);
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_signal_connect (priv->old_sample, "expose-event",
Packit Service fb6fa5
		    G_CALLBACK (color_old_sample_expose),
Packit Service fb6fa5
		    colorsel);
Packit Service fb6fa5
  g_signal_connect (priv->cur_sample, "expose-event",
Packit Service fb6fa5
		    G_CALLBACK (color_cur_sample_expose),
Packit Service fb6fa5
		    colorsel);
Packit Service fb6fa5
  
Packit Service fb6fa5
  color_sample_setup_dnd (colorsel, priv->old_sample);
Packit Service fb6fa5
  color_sample_setup_dnd (colorsel, priv->cur_sample);
Packit Service fb6fa5
Packit Service fb6fa5
  update_tooltips (colorsel);
Packit Service fb6fa5
Packit Service fb6fa5
  gtk_widget_show_all (priv->sample_area);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
Packit Service fb6fa5
/*
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * The palette area code
Packit Service fb6fa5
 *
Packit Service fb6fa5
 */
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
palette_get_color (GtkWidget *drawing_area, gdouble *color)
Packit Service fb6fa5
{
Packit Service fb6fa5
  gdouble *color_val;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_if_fail (color != NULL);
Packit Service fb6fa5
  
Packit Service fb6fa5
  color_val = g_object_get_data (G_OBJECT (drawing_area), "color_val");
Packit Service fb6fa5
  if (color_val == NULL)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      /* Default to white for no good reason */
Packit Service fb6fa5
      color[0] = 1.0;
Packit Service fb6fa5
      color[1] = 1.0;
Packit Service fb6fa5
      color[2] = 1.0;
Packit Service fb6fa5
      color[3] = 1.0;
Packit Service fb6fa5
      return;
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
  color[0] = color_val[0];
Packit Service fb6fa5
  color[1] = color_val[1];
Packit Service fb6fa5
  color[2] = color_val[2];
Packit Service fb6fa5
  color[3] = 1.0;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
palette_paint (GtkWidget    *drawing_area,
Packit Service fb6fa5
	       GdkRectangle *area,
Packit Service fb6fa5
	       gpointer      data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  cairo_t *cr;
Packit Service fb6fa5
  gint focus_width;
Packit Service fb6fa5
    
Packit Service fb6fa5
  if (drawing_area->window == NULL)
Packit Service fb6fa5
    return;
Packit Service fb6fa5
Packit Service fb6fa5
  cr = gdk_cairo_create (drawing_area->window);
Packit Service fb6fa5
Packit Service fb6fa5
  gdk_cairo_set_source_color (cr, &drawing_area->style->bg[GTK_STATE_NORMAL]);
Packit Service fb6fa5
  gdk_cairo_rectangle (cr, area);
Packit Service fb6fa5
  cairo_fill (cr);
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (gtk_widget_has_focus (drawing_area))
Packit Service fb6fa5
    {
Packit Service fb6fa5
      set_focus_line_attributes (drawing_area, cr, &focus_width);
Packit Service fb6fa5
Packit Service fb6fa5
      cairo_rectangle (cr,
Packit Service fb6fa5
		       focus_width / 2., focus_width / 2.,
Packit Service fb6fa5
		       drawing_area->allocation.width - focus_width,
Packit Service fb6fa5
		       drawing_area->allocation.height - focus_width);
Packit Service fb6fa5
      cairo_stroke (cr);
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  cairo_destroy (cr);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
set_focus_line_attributes (GtkWidget *drawing_area,
Packit Service fb6fa5
			   cairo_t   *cr,
Packit Service fb6fa5
			   gint      *focus_width)
Packit Service fb6fa5
{
Packit Service fb6fa5
  gdouble color[4];
Packit Service fb6fa5
  gint8 *dash_list;
Packit Service fb6fa5
  
Packit Service fb6fa5
  gtk_widget_style_get (drawing_area,
Packit Service fb6fa5
			"focus-line-width", focus_width,
Packit Service fb6fa5
			"focus-line-pattern", (gchar *)&dash_list,
Packit Service fb6fa5
			NULL);
Packit Service fb6fa5
      
Packit Service fb6fa5
  palette_get_color (drawing_area, color);
Packit Service fb6fa5
Packit Service fb6fa5
  if (INTENSITY (color[0], color[1], color[2]) > 0.5)
Packit Service fb6fa5
    cairo_set_source_rgb (cr, 0., 0., 0.);
Packit Service fb6fa5
  else
Packit Service fb6fa5
    cairo_set_source_rgb (cr, 1., 1., 1.);
Packit Service fb6fa5
Packit Service fb6fa5
  cairo_set_line_width (cr, *focus_width);
Packit Service fb6fa5
Packit Service fb6fa5
  if (dash_list[0])
Packit Service fb6fa5
    {
Packit Service fb6fa5
      gint n_dashes = strlen ((gchar *)dash_list);
Packit Service fb6fa5
      gdouble *dashes = g_new (gdouble, n_dashes);
Packit Service fb6fa5
      gdouble total_length = 0;
Packit Service fb6fa5
      gdouble dash_offset;
Packit Service fb6fa5
      gint i;
Packit Service fb6fa5
Packit Service fb6fa5
      for (i = 0; i < n_dashes; i++)
Packit Service fb6fa5
	{
Packit Service fb6fa5
	  dashes[i] = dash_list[i];
Packit Service fb6fa5
	  total_length += dash_list[i];
Packit Service fb6fa5
	}
Packit Service fb6fa5
Packit Service fb6fa5
      /* The dash offset here aligns the pattern to integer pixels
Packit Service fb6fa5
       * by starting the dash at the right side of the left border
Packit Service fb6fa5
       * Negative dash offsets in cairo don't work
Packit Service fb6fa5
       * (https://bugs.freedesktop.org/show_bug.cgi?id=2729)
Packit Service fb6fa5
       */
Packit Service fb6fa5
      dash_offset = - *focus_width / 2.;
Packit Service fb6fa5
      while (dash_offset < 0)
Packit Service fb6fa5
	dash_offset += total_length;
Packit Service fb6fa5
      
Packit Service fb6fa5
      cairo_set_dash (cr, dashes, n_dashes, dash_offset);
Packit Service fb6fa5
      g_free (dashes);
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  g_free (dash_list);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
palette_drag_begin (GtkWidget      *widget,
Packit Service fb6fa5
		    GdkDragContext *context,
Packit Service fb6fa5
		    gpointer        data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  gdouble colors[4];
Packit Service fb6fa5
  
Packit Service fb6fa5
  palette_get_color (widget, colors);
Packit Service fb6fa5
  set_color_icon (context, colors);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
palette_drag_handle (GtkWidget        *widget,
Packit Service fb6fa5
		     GdkDragContext   *context,
Packit Service fb6fa5
		     GtkSelectionData *selection_data,
Packit Service fb6fa5
		     guint             info,
Packit Service fb6fa5
		     guint             time,
Packit Service fb6fa5
		     gpointer          data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  guint16 vals[4];
Packit Service fb6fa5
  gdouble colsrc[4];
Packit Service fb6fa5
  
Packit Service fb6fa5
  palette_get_color (widget, colsrc);
Packit Service fb6fa5
  
Packit Service fb6fa5
  vals[0] = colsrc[COLORSEL_RED] * 0xffff;
Packit Service fb6fa5
  vals[1] = colsrc[COLORSEL_GREEN] * 0xffff;
Packit Service fb6fa5
  vals[2] = colsrc[COLORSEL_BLUE] * 0xffff;
Packit Service fb6fa5
  vals[3] = 0xffff;
Packit Service fb6fa5
  
Packit Service fb6fa5
  gtk_selection_data_set (selection_data,
Packit Service fb6fa5
			  gdk_atom_intern_static_string ("application/x-color"),
Packit Service fb6fa5
			  16, (guchar *)vals, 8);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
palette_drag_end (GtkWidget      *widget,
Packit Service fb6fa5
		  GdkDragContext *context,
Packit Service fb6fa5
		  gpointer        data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  g_object_set_data (G_OBJECT (widget), I_("gtk-color-selection-drag-window"), NULL);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static GdkColor *
Packit Service fb6fa5
get_current_colors (GtkColorSelection *colorsel)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkSettings *settings;
Packit Service fb6fa5
  GdkColor *colors = NULL;
Packit Service fb6fa5
  gint n_colors = 0;
Packit Service fb6fa5
  gchar *palette;
Packit Service fb6fa5
Packit Service fb6fa5
  settings = gtk_widget_get_settings (GTK_WIDGET (colorsel));
Packit Service fb6fa5
  g_object_get (settings, "gtk-color-palette", &palette, NULL);
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (!gtk_color_selection_palette_from_string (palette, &colors, &n_colors))
Packit Service fb6fa5
    {
Packit Service fb6fa5
      gtk_color_selection_palette_from_string (DEFAULT_COLOR_PALETTE,
Packit Service fb6fa5
                                               &colors,
Packit Service fb6fa5
                                               &n_colors);
Packit Service fb6fa5
    }
Packit Service fb6fa5
  else
Packit Service fb6fa5
    {
Packit Service fb6fa5
      /* If there are less colors provided than the number of slots in the
Packit Service fb6fa5
       * color selection, we fill in the rest from the defaults.
Packit Service fb6fa5
       */
Packit Service fb6fa5
      if (n_colors < (GTK_CUSTOM_PALETTE_WIDTH * GTK_CUSTOM_PALETTE_HEIGHT))
Packit Service fb6fa5
	{
Packit Service fb6fa5
	  GdkColor *tmp_colors = colors;
Packit Service fb6fa5
	  gint tmp_n_colors = n_colors;
Packit Service fb6fa5
	  
Packit Service fb6fa5
	  gtk_color_selection_palette_from_string (DEFAULT_COLOR_PALETTE,
Packit Service fb6fa5
                                                   &colors,
Packit Service fb6fa5
                                                   &n_colors);
Packit Service fb6fa5
	  memcpy (colors, tmp_colors, sizeof (GdkColor) * tmp_n_colors);
Packit Service fb6fa5
Packit Service fb6fa5
	  g_free (tmp_colors);
Packit Service fb6fa5
	}
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  /* make sure that we fill every slot */
Packit Service fb6fa5
  g_assert (n_colors == GTK_CUSTOM_PALETTE_WIDTH * GTK_CUSTOM_PALETTE_HEIGHT);
Packit Service fb6fa5
  g_free (palette);
Packit Service fb6fa5
  
Packit Service fb6fa5
  return colors;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/* Changes the model color */
Packit Service fb6fa5
static void
Packit Service fb6fa5
palette_change_color (GtkWidget         *drawing_area,
Packit Service fb6fa5
                      GtkColorSelection *colorsel,
Packit Service fb6fa5
                      gdouble           *color)
Packit Service fb6fa5
{
Packit Service fb6fa5
  gint x, y;
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  GdkColor gdk_color;
Packit Service fb6fa5
  GdkColor *current_colors;
Packit Service fb6fa5
  GdkScreen *screen;
Packit Service fb6fa5
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_DRAWING_AREA (drawing_area));
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  
Packit Service fb6fa5
  gdk_color.red = UNSCALE (color[0]);
Packit Service fb6fa5
  gdk_color.green = UNSCALE (color[1]);
Packit Service fb6fa5
  gdk_color.blue = UNSCALE (color[2]);
Packit Service fb6fa5
  gdk_color.pixel = 0;
Packit Service fb6fa5
Packit Service fb6fa5
  x = 0;
Packit Service fb6fa5
  y = 0;			/* Quiet GCC */
Packit Service fb6fa5
  while (x < GTK_CUSTOM_PALETTE_WIDTH)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      y = 0;
Packit Service fb6fa5
      while (y < GTK_CUSTOM_PALETTE_HEIGHT)
Packit Service fb6fa5
        {
Packit Service fb6fa5
          if (priv->custom_palette[x][y] == drawing_area)
Packit Service fb6fa5
            goto out;
Packit Service fb6fa5
          
Packit Service fb6fa5
          ++y;
Packit Service fb6fa5
        }
Packit Service fb6fa5
Packit Service fb6fa5
      ++x;
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
 out:
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_assert (x < GTK_CUSTOM_PALETTE_WIDTH || y < GTK_CUSTOM_PALETTE_HEIGHT);
Packit Service fb6fa5
Packit Service fb6fa5
  current_colors = get_current_colors (colorsel);
Packit Service fb6fa5
  current_colors[y * GTK_CUSTOM_PALETTE_WIDTH + x] = gdk_color;
Packit Service fb6fa5
Packit Service fb6fa5
  screen = gtk_widget_get_screen (GTK_WIDGET (colorsel));
Packit Service fb6fa5
  if (change_palette_hook != default_change_palette_func)
Packit Service fb6fa5
    (* change_palette_hook) (screen, current_colors, 
Packit Service fb6fa5
			     GTK_CUSTOM_PALETTE_WIDTH * GTK_CUSTOM_PALETTE_HEIGHT);
Packit Service fb6fa5
  else if (noscreen_change_palette_hook != default_noscreen_change_palette_func)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      if (screen != gdk_screen_get_default ())
Packit Service fb6fa5
	g_warning ("gtk_color_selection_set_change_palette_hook used by widget is not on the default screen.");
Packit Service fb6fa5
      (* noscreen_change_palette_hook) (current_colors, 
Packit Service fb6fa5
					GTK_CUSTOM_PALETTE_WIDTH * GTK_CUSTOM_PALETTE_HEIGHT);
Packit Service fb6fa5
    }
Packit Service fb6fa5
  else
Packit Service fb6fa5
    (* change_palette_hook) (screen, current_colors, 
Packit Service fb6fa5
			     GTK_CUSTOM_PALETTE_WIDTH * GTK_CUSTOM_PALETTE_HEIGHT);
Packit Service fb6fa5
Packit Service fb6fa5
  g_free (current_colors);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/* Changes the view color */
Packit Service fb6fa5
static void
Packit Service fb6fa5
palette_set_color (GtkWidget         *drawing_area,
Packit Service fb6fa5
		   GtkColorSelection *colorsel,
Packit Service fb6fa5
		   gdouble           *color)
Packit Service fb6fa5
{
Packit Service fb6fa5
  gdouble *new_color = g_new (double, 4);
Packit Service fb6fa5
  GdkColor gdk_color;
Packit Service fb6fa5
  
Packit Service fb6fa5
  gdk_color.red = UNSCALE (color[0]);
Packit Service fb6fa5
  gdk_color.green = UNSCALE (color[1]);
Packit Service fb6fa5
  gdk_color.blue = UNSCALE (color[2]);
Packit Service fb6fa5
Packit Service fb6fa5
  gtk_widget_modify_bg (drawing_area, GTK_STATE_NORMAL, &gdk_color);
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (drawing_area), "color_set")) == 0)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      static const GtkTargetEntry targets[] = {
Packit Service fb6fa5
	{ "application/x-color", 0 }
Packit Service fb6fa5
      };
Packit Service fb6fa5
      gtk_drag_source_set (drawing_area,
Packit Service fb6fa5
			   GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
Packit Service fb6fa5
			   targets, 1,
Packit Service fb6fa5
			   GDK_ACTION_COPY | GDK_ACTION_MOVE);
Packit Service fb6fa5
      
Packit Service fb6fa5
      g_signal_connect (drawing_area, "drag-begin",
Packit Service fb6fa5
			G_CALLBACK (palette_drag_begin),
Packit Service fb6fa5
			colorsel);
Packit Service fb6fa5
      g_signal_connect (drawing_area, "drag-data-get",
Packit Service fb6fa5
			G_CALLBACK (palette_drag_handle),
Packit Service fb6fa5
			colorsel);
Packit Service fb6fa5
      
Packit Service fb6fa5
      g_object_set_data (G_OBJECT (drawing_area), I_("color_set"),
Packit Service fb6fa5
			 GINT_TO_POINTER (1));
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  new_color[0] = color[0];
Packit Service fb6fa5
  new_color[1] = color[1];
Packit Service fb6fa5
  new_color[2] = color[2];
Packit Service fb6fa5
  new_color[3] = 1.0;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_object_set_data_full (G_OBJECT (drawing_area), I_("color_val"), new_color, (GDestroyNotify)g_free);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static gboolean
Packit Service fb6fa5
palette_expose (GtkWidget      *drawing_area,
Packit Service fb6fa5
		GdkEventExpose *event,
Packit Service fb6fa5
		gpointer        data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  if (drawing_area->window == NULL)
Packit Service fb6fa5
    return FALSE;
Packit Service fb6fa5
  
Packit Service fb6fa5
  palette_paint (drawing_area, &(event->area), data);
Packit Service fb6fa5
  
Packit Service fb6fa5
  return FALSE;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
popup_position_func (GtkMenu   *menu,
Packit Service fb6fa5
                     gint      *x,
Packit Service fb6fa5
                     gint      *y,
Packit Service fb6fa5
                     gboolean  *push_in,
Packit Service fb6fa5
                     gpointer	user_data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkWidget *widget;
Packit Service fb6fa5
  GtkRequisition req;      
Packit Service fb6fa5
  gint root_x, root_y;
Packit Service fb6fa5
  GdkScreen *screen;
Packit Service fb6fa5
  
Packit Service fb6fa5
  widget = GTK_WIDGET (user_data);
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_if_fail (gtk_widget_get_realized (widget));
Packit Service fb6fa5
Packit Service fb6fa5
  gdk_window_get_origin (widget->window, &root_x, &root_y);
Packit Service fb6fa5
  
Packit Service fb6fa5
  gtk_widget_size_request (GTK_WIDGET (menu), &req;;
Packit Service fb6fa5
Packit Service fb6fa5
  /* Put corner of menu centered on color cell */
Packit Service fb6fa5
  *x = root_x + widget->allocation.width / 2;
Packit Service fb6fa5
  *y = root_y + widget->allocation.height / 2;
Packit Service fb6fa5
Packit Service fb6fa5
  /* Ensure sanity */
Packit Service fb6fa5
  screen = gtk_widget_get_screen (widget);
Packit Service fb6fa5
  *x = CLAMP (*x, 0, MAX (0, gdk_screen_get_width (screen) - req.width));
Packit Service fb6fa5
  *y = CLAMP (*y, 0, MAX (0, gdk_screen_get_height (screen) - req.height));
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
save_color_selected (GtkWidget *menuitem,
Packit Service fb6fa5
                     gpointer   data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkColorSelection *colorsel;
Packit Service fb6fa5
  GtkWidget *drawing_area;
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
Packit Service fb6fa5
  drawing_area = GTK_WIDGET (data);
Packit Service fb6fa5
  
Packit Service fb6fa5
  colorsel = GTK_COLOR_SELECTION (g_object_get_data (G_OBJECT (drawing_area),
Packit Service fb6fa5
                                                     "gtk-color-sel"));
Packit Service fb6fa5
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  
Packit Service fb6fa5
  palette_change_color (drawing_area, colorsel, priv->color);  
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
do_popup (GtkColorSelection *colorsel,
Packit Service fb6fa5
          GtkWidget         *drawing_area,
Packit Service fb6fa5
          guint32            timestamp)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkWidget *menu;
Packit Service fb6fa5
  GtkWidget *mi;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_object_set_data (G_OBJECT (drawing_area),
Packit Service fb6fa5
                     I_("gtk-color-sel"),
Packit Service fb6fa5
                     colorsel);
Packit Service fb6fa5
  
Packit Service fb6fa5
  menu = gtk_menu_new ();
Packit Service fb6fa5
Packit Service fb6fa5
  mi = gtk_menu_item_new_with_mnemonic (_("_Save color here"));
Packit Service fb6fa5
Packit Service fb6fa5
  g_signal_connect (mi, "activate",
Packit Service fb6fa5
                    G_CALLBACK (save_color_selected),
Packit Service fb6fa5
                    drawing_area);
Packit Service fb6fa5
  
Packit Service fb6fa5
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
Packit Service fb6fa5
Packit Service fb6fa5
  gtk_widget_show_all (mi);
Packit Service fb6fa5
Packit Service fb6fa5
  gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
Packit Service fb6fa5
                  popup_position_func, drawing_area,
Packit Service fb6fa5
                  3, timestamp);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
Packit Service fb6fa5
static gboolean
Packit Service fb6fa5
palette_enter (GtkWidget        *drawing_area,
Packit Service fb6fa5
	       GdkEventCrossing *event,
Packit Service fb6fa5
	       gpointer        data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  g_object_set_data (G_OBJECT (drawing_area),
Packit Service fb6fa5
		     I_("gtk-colorsel-have-pointer"),
Packit Service fb6fa5
		     GUINT_TO_POINTER (TRUE));
Packit Service fb6fa5
Packit Service fb6fa5
  return FALSE;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static gboolean
Packit Service fb6fa5
palette_leave (GtkWidget        *drawing_area,
Packit Service fb6fa5
	       GdkEventCrossing *event,
Packit Service fb6fa5
	       gpointer        data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  g_object_set_data (G_OBJECT (drawing_area),
Packit Service fb6fa5
		     I_("gtk-colorsel-have-pointer"),
Packit Service fb6fa5
		     NULL);
Packit Service fb6fa5
Packit Service fb6fa5
  return FALSE;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static gboolean
Packit Service fb6fa5
palette_press (GtkWidget      *drawing_area,
Packit Service fb6fa5
	       GdkEventButton *event,
Packit Service fb6fa5
	       gpointer        data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkColorSelection *colorsel = GTK_COLOR_SELECTION (data);
Packit Service fb6fa5
Packit Service fb6fa5
  gtk_widget_grab_focus (drawing_area);
Packit Service fb6fa5
Packit Service fb6fa5
  if (_gtk_button_event_triggers_context_menu (event))
Packit Service fb6fa5
    {
Packit Service fb6fa5
      do_popup (colorsel, drawing_area, event->time);
Packit Service fb6fa5
      return TRUE;
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  return FALSE;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static gboolean
Packit Service fb6fa5
palette_release (GtkWidget      *drawing_area,
Packit Service fb6fa5
		 GdkEventButton *event,
Packit Service fb6fa5
		 gpointer        data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkColorSelection *colorsel = GTK_COLOR_SELECTION (data);
Packit Service fb6fa5
Packit Service fb6fa5
  gtk_widget_grab_focus (drawing_area);
Packit Service fb6fa5
Packit Service fb6fa5
  if (event->button == 1 &&
Packit Service fb6fa5
      g_object_get_data (G_OBJECT (drawing_area),
Packit Service fb6fa5
			 "gtk-colorsel-have-pointer") != NULL)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (drawing_area), "color_set")) != 0)
Packit Service fb6fa5
        {
Packit Service fb6fa5
          gdouble color[4];
Packit Service fb6fa5
          palette_get_color (drawing_area, color);
Packit Service fb6fa5
          set_color_internal (colorsel, color);
Packit Service fb6fa5
        }
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  return FALSE;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
palette_drop_handle (GtkWidget        *widget,
Packit Service fb6fa5
		     GdkDragContext   *context,
Packit Service fb6fa5
		     gint              x,
Packit Service fb6fa5
		     gint              y,
Packit Service fb6fa5
		     GtkSelectionData *selection_data,
Packit Service fb6fa5
		     guint             info,
Packit Service fb6fa5
		     guint             time,
Packit Service fb6fa5
		     gpointer          data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkColorSelection *colorsel = GTK_COLOR_SELECTION (data);
Packit Service fb6fa5
  guint16 *vals;
Packit Service fb6fa5
  gdouble color[4];
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (selection_data->length < 0)
Packit Service fb6fa5
    return;
Packit Service fb6fa5
  
Packit Service fb6fa5
  /* We accept drops with the wrong format, since the KDE color
Packit Service fb6fa5
   * chooser incorrectly drops application/x-color with format 8.
Packit Service fb6fa5
   */
Packit Service fb6fa5
  if (selection_data->length != 8)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      g_warning ("Received invalid color data\n");
Packit Service fb6fa5
      return;
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
  vals = (guint16 *)selection_data->data;
Packit Service fb6fa5
  
Packit Service fb6fa5
  color[0] = (gdouble)vals[0] / 0xffff;
Packit Service fb6fa5
  color[1] = (gdouble)vals[1] / 0xffff;
Packit Service fb6fa5
  color[2] = (gdouble)vals[2] / 0xffff;
Packit Service fb6fa5
  color[3] = (gdouble)vals[3] / 0xffff;
Packit Service fb6fa5
  palette_change_color (widget, colorsel, color);
Packit Service fb6fa5
  set_color_internal (colorsel, color);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static gint
Packit Service fb6fa5
palette_activate (GtkWidget   *widget,
Packit Service fb6fa5
		  GdkEventKey *event,
Packit Service fb6fa5
		  gpointer     data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  /* should have a drawing area subclass with an activate signal */
Packit Service fb6fa5
  if ((event->keyval == GDK_space) ||
Packit Service fb6fa5
      (event->keyval == GDK_Return) ||
Packit Service fb6fa5
      (event->keyval == GDK_ISO_Enter) ||
Packit Service fb6fa5
      (event->keyval == GDK_KP_Enter) ||
Packit Service fb6fa5
      (event->keyval == GDK_KP_Space))
Packit Service fb6fa5
    {
Packit Service fb6fa5
      if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), "color_set")) != 0)
Packit Service fb6fa5
        {
Packit Service fb6fa5
          gdouble color[4];
Packit Service fb6fa5
          palette_get_color (widget, color);
Packit Service fb6fa5
          set_color_internal (GTK_COLOR_SELECTION (data), color);
Packit Service fb6fa5
        }
Packit Service fb6fa5
      return TRUE;
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
  return FALSE;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static gboolean
Packit Service fb6fa5
palette_popup (GtkWidget *widget,
Packit Service fb6fa5
               gpointer   data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkColorSelection *colorsel = GTK_COLOR_SELECTION (data);
Packit Service fb6fa5
Packit Service fb6fa5
  do_popup (colorsel, widget, GDK_CURRENT_TIME);
Packit Service fb6fa5
  return TRUE;
Packit Service fb6fa5
}
Packit Service fb6fa5
               
Packit Service fb6fa5
Packit Service fb6fa5
static GtkWidget*
Packit Service fb6fa5
palette_new (GtkColorSelection *colorsel)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkWidget *retval;
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  
Packit Service fb6fa5
  static const GtkTargetEntry targets[] = {
Packit Service fb6fa5
    { "application/x-color", 0 }
Packit Service fb6fa5
  };
Packit Service fb6fa5
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  
Packit Service fb6fa5
  retval = gtk_drawing_area_new ();
Packit Service fb6fa5
Packit Service fb6fa5
  gtk_widget_set_can_focus (retval, TRUE);
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_object_set_data (G_OBJECT (retval), I_("color_set"), GINT_TO_POINTER (0)); 
Packit Service fb6fa5
  gtk_widget_set_events (retval, GDK_BUTTON_PRESS_MASK
Packit Service fb6fa5
                         | GDK_BUTTON_RELEASE_MASK
Packit Service fb6fa5
                         | GDK_EXPOSURE_MASK
Packit Service fb6fa5
                         | GDK_ENTER_NOTIFY_MASK
Packit Service fb6fa5
                         | GDK_LEAVE_NOTIFY_MASK);
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_signal_connect (retval, "expose-event",
Packit Service fb6fa5
		    G_CALLBACK (palette_expose), colorsel);
Packit Service fb6fa5
  g_signal_connect (retval, "button-press-event",
Packit Service fb6fa5
		    G_CALLBACK (palette_press), colorsel);
Packit Service fb6fa5
  g_signal_connect (retval, "button-release-event",
Packit Service fb6fa5
		    G_CALLBACK (palette_release), colorsel);
Packit Service fb6fa5
  g_signal_connect (retval, "enter-notify-event",
Packit Service fb6fa5
		    G_CALLBACK (palette_enter), colorsel);
Packit Service fb6fa5
  g_signal_connect (retval, "leave-notify-event",
Packit Service fb6fa5
		    G_CALLBACK (palette_leave), colorsel);
Packit Service fb6fa5
  g_signal_connect (retval, "key-press-event",
Packit Service fb6fa5
		    G_CALLBACK (palette_activate), colorsel);
Packit Service fb6fa5
  g_signal_connect (retval, "popup-menu",
Packit Service fb6fa5
		    G_CALLBACK (palette_popup), colorsel);
Packit Service fb6fa5
  
Packit Service fb6fa5
  gtk_drag_dest_set (retval,
Packit Service fb6fa5
		     GTK_DEST_DEFAULT_HIGHLIGHT |
Packit Service fb6fa5
		     GTK_DEST_DEFAULT_MOTION |
Packit Service fb6fa5
		     GTK_DEST_DEFAULT_DROP,
Packit Service fb6fa5
		     targets, 1,
Packit Service fb6fa5
		     GDK_ACTION_COPY);
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_signal_connect (retval, "drag-end",
Packit Service fb6fa5
                    G_CALLBACK (palette_drag_end), NULL);
Packit Service fb6fa5
  g_signal_connect (retval, "drag-data-received",
Packit Service fb6fa5
                    G_CALLBACK (palette_drop_handle), colorsel);
Packit Service fb6fa5
Packit Service fb6fa5
  gtk_widget_set_tooltip_text (retval,
Packit Service fb6fa5
                        _("Click this palette entry to make it the current color. To change this entry, drag a color swatch here or right-click it and select \"Save color here.\""));
Packit Service fb6fa5
  return retval;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
Packit Service fb6fa5
/*
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * The actual GtkColorSelection widget
Packit Service fb6fa5
 *
Packit Service fb6fa5
 */
Packit Service fb6fa5
Packit Service fb6fa5
static GdkCursor *
Packit Service fb6fa5
make_picker_cursor (GdkScreen *screen)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GdkCursor *cursor;
Packit Service fb6fa5
Packit Service fb6fa5
  cursor = gdk_cursor_new_from_name (gdk_screen_get_display (screen),
Packit Service fb6fa5
				     "color-picker");
Packit Service fb6fa5
Packit Service fb6fa5
  if (!cursor)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      GdkColor bg = { 0, 0xffff, 0xffff, 0xffff };
Packit Service fb6fa5
      GdkColor fg = { 0, 0x0000, 0x0000, 0x0000 };
Packit Service fb6fa5
      GdkWindow *window;
Packit Service fb6fa5
      GdkPixmap *pixmap, *mask;
Packit Service fb6fa5
      cairo_surface_t *image;
Packit Service fb6fa5
      cairo_t *cr;
Packit Service fb6fa5
Packit Service fb6fa5
      window = gdk_screen_get_root_window (screen);
Packit Service fb6fa5
      
Packit Service fb6fa5
Packit Service fb6fa5
      pixmap = gdk_pixmap_new (window, DROPPER_WIDTH, DROPPER_HEIGHT, 1);
Packit Service fb6fa5
Packit Service fb6fa5
      cr = gdk_cairo_create (pixmap);
Packit Service fb6fa5
      cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
Packit Service fb6fa5
      image = cairo_image_surface_create_for_data ((guchar *) dropper_bits,
Packit Service fb6fa5
                                                   CAIRO_FORMAT_A1,
Packit Service fb6fa5
                                                   DROPPER_WIDTH,
Packit Service fb6fa5
                                                   DROPPER_HEIGHT,
Packit Service fb6fa5
                                                   DROPPER_STRIDE);
Packit Service fb6fa5
      cairo_set_source_surface (cr, image, 0, 0);
Packit Service fb6fa5
      cairo_surface_destroy (image);
Packit Service fb6fa5
      cairo_paint (cr);
Packit Service fb6fa5
      cairo_destroy (cr);
Packit Service fb6fa5
      
Packit Service fb6fa5
Packit Service fb6fa5
      mask = gdk_pixmap_new (window, DROPPER_WIDTH, DROPPER_HEIGHT, 1);
Packit Service fb6fa5
Packit Service fb6fa5
      cr = gdk_cairo_create (mask);
Packit Service fb6fa5
      cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
Packit Service fb6fa5
      image = cairo_image_surface_create_for_data ((guchar *) dropper_mask,
Packit Service fb6fa5
                                                   CAIRO_FORMAT_A1,
Packit Service fb6fa5
                                                   DROPPER_WIDTH,
Packit Service fb6fa5
                                                   DROPPER_HEIGHT,
Packit Service fb6fa5
                                                   DROPPER_STRIDE);
Packit Service fb6fa5
      cairo_set_source_surface (cr, image, 0, 0);
Packit Service fb6fa5
      cairo_surface_destroy (image);
Packit Service fb6fa5
      cairo_paint (cr);
Packit Service fb6fa5
      cairo_destroy (cr);
Packit Service fb6fa5
      
Packit Service fb6fa5
      cursor = gdk_cursor_new_from_pixmap (pixmap, mask, &fg, &bg,
Packit Service fb6fa5
					   DROPPER_X_HOT, DROPPER_Y_HOT);
Packit Service fb6fa5
      
Packit Service fb6fa5
      g_object_unref (pixmap);
Packit Service fb6fa5
      g_object_unref (mask);
Packit Service fb6fa5
    }
Packit Service fb6fa5
      
Packit Service fb6fa5
  return cursor;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
grab_color_at_mouse (GdkScreen *screen,
Packit Service fb6fa5
		     gint       x_root,
Packit Service fb6fa5
		     gint       y_root,
Packit Service fb6fa5
		     gpointer   data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GdkPixbuf *pixbuf;
Packit Service fb6fa5
  guchar *pixels;
Packit Service fb6fa5
  GtkColorSelection *colorsel = data;
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  GdkColor color;
Packit Service fb6fa5
  GdkWindow *root_window = gdk_screen_get_root_window (screen);
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  
Packit Service fb6fa5
  pixbuf = gdk_pixbuf_get_from_drawable (NULL, root_window, NULL,
Packit Service fb6fa5
                                         x_root, y_root,
Packit Service fb6fa5
                                         0, 0,
Packit Service fb6fa5
                                         1, 1);
Packit Service fb6fa5
  if (!pixbuf)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      gint x, y;
Packit Service fb6fa5
      GdkDisplay *display = gdk_screen_get_display (screen);
Packit Service fb6fa5
      GdkWindow *window = gdk_display_get_window_at_pointer (display, &x, &y);
Packit Service fb6fa5
      if (!window)
Packit Service fb6fa5
	return;
Packit Service fb6fa5
      pixbuf = gdk_pixbuf_get_from_drawable (NULL, window, NULL,
Packit Service fb6fa5
                                             x, y,
Packit Service fb6fa5
                                             0, 0,
Packit Service fb6fa5
                                             1, 1);
Packit Service fb6fa5
      if (!pixbuf)
Packit Service fb6fa5
	return;
Packit Service fb6fa5
    }
Packit Service fb6fa5
  pixels = gdk_pixbuf_get_pixels (pixbuf);
Packit Service fb6fa5
  color.red = pixels[0] * 0x101;
Packit Service fb6fa5
  color.green = pixels[1] * 0x101;
Packit Service fb6fa5
  color.blue = pixels[2] * 0x101;
Packit Service fb6fa5
  g_object_unref (pixbuf);
Packit Service fb6fa5
Packit Service fb6fa5
  priv->color[COLORSEL_RED] = SCALE (color.red);
Packit Service fb6fa5
  priv->color[COLORSEL_GREEN] = SCALE (color.green);
Packit Service fb6fa5
  priv->color[COLORSEL_BLUE] = SCALE (color.blue);
Packit Service fb6fa5
  
Packit Service fb6fa5
  gtk_rgb_to_hsv (priv->color[COLORSEL_RED],
Packit Service fb6fa5
		  priv->color[COLORSEL_GREEN],
Packit Service fb6fa5
		  priv->color[COLORSEL_BLUE],
Packit Service fb6fa5
		  &priv->color[COLORSEL_HUE],
Packit Service fb6fa5
		  &priv->color[COLORSEL_SATURATION],
Packit Service fb6fa5
		  &priv->color[COLORSEL_VALUE]);
Packit Service fb6fa5
Packit Service fb6fa5
  update_color (colorsel);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
shutdown_eyedropper (GtkWidget *widget)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkColorSelection *colorsel;
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  GdkDisplay *display = gtk_widget_get_display (widget);
Packit Service fb6fa5
Packit Service fb6fa5
  colorsel = GTK_COLOR_SELECTION (widget);
Packit Service fb6fa5
  priv = colorsel->private_data;    
Packit Service fb6fa5
Packit Service fb6fa5
  if (priv->has_grab)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      gdk_display_keyboard_ungrab (display, priv->grab_time);
Packit Service fb6fa5
      gdk_display_pointer_ungrab (display, priv->grab_time);
Packit Service fb6fa5
      gtk_grab_remove (priv->dropper_grab_widget);
Packit Service fb6fa5
Packit Service fb6fa5
      priv->has_grab = FALSE;
Packit Service fb6fa5
    }
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
mouse_motion (GtkWidget      *invisible,
Packit Service fb6fa5
	      GdkEventMotion *event,
Packit Service fb6fa5
	      gpointer        data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  grab_color_at_mouse (gdk_event_get_screen ((GdkEvent *)event),
Packit Service fb6fa5
		       event->x_root, event->y_root, data); 
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static gboolean
Packit Service fb6fa5
mouse_release (GtkWidget      *invisible,
Packit Service fb6fa5
	       GdkEventButton *event,
Packit Service fb6fa5
	       gpointer        data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  /* GtkColorSelection *colorsel = data; */
Packit Service fb6fa5
Packit Service fb6fa5
  if (event->button != 1)
Packit Service fb6fa5
    return FALSE;
Packit Service fb6fa5
Packit Service fb6fa5
  grab_color_at_mouse (gdk_event_get_screen ((GdkEvent *)event),
Packit Service fb6fa5
		       event->x_root, event->y_root, data);
Packit Service fb6fa5
Packit Service fb6fa5
  shutdown_eyedropper (GTK_WIDGET (data));
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_signal_handlers_disconnect_by_func (invisible,
Packit Service fb6fa5
					mouse_motion,
Packit Service fb6fa5
					data);
Packit Service fb6fa5
  g_signal_handlers_disconnect_by_func (invisible,
Packit Service fb6fa5
					mouse_release,
Packit Service fb6fa5
					data);
Packit Service fb6fa5
Packit Service fb6fa5
  return TRUE;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/* Helper Functions */
Packit Service fb6fa5
Packit Service fb6fa5
static gboolean
Packit Service fb6fa5
key_press (GtkWidget   *invisible,
Packit Service fb6fa5
           GdkEventKey *event,
Packit Service fb6fa5
           gpointer     data)
Packit Service fb6fa5
{  
Packit Service fb6fa5
  GdkDisplay *display = gtk_widget_get_display (invisible);
Packit Service fb6fa5
  GdkScreen *screen = gdk_event_get_screen ((GdkEvent *)event);
Packit Service fb6fa5
  guint state = event->state & gtk_accelerator_get_default_mod_mask ();
Packit Service fb6fa5
  gint x, y;
Packit Service fb6fa5
  gint dx, dy;
Packit Service fb6fa5
Packit Service fb6fa5
  gdk_display_get_pointer (display, NULL, &x, &y, NULL);
Packit Service fb6fa5
Packit Service fb6fa5
  dx = 0;
Packit Service fb6fa5
  dy = 0;
Packit Service fb6fa5
Packit Service fb6fa5
  switch (event->keyval) 
Packit Service fb6fa5
    {
Packit Service fb6fa5
    case GDK_space:
Packit Service fb6fa5
    case GDK_Return:
Packit Service fb6fa5
    case GDK_ISO_Enter:
Packit Service fb6fa5
    case GDK_KP_Enter:
Packit Service fb6fa5
    case GDK_KP_Space:
Packit Service fb6fa5
      grab_color_at_mouse (screen, x, y, data);
Packit Service fb6fa5
      /* fall through */
Packit Service fb6fa5
Packit Service fb6fa5
    case GDK_Escape:
Packit Service fb6fa5
      shutdown_eyedropper (data);
Packit Service fb6fa5
      
Packit Service fb6fa5
      g_signal_handlers_disconnect_by_func (invisible,
Packit Service fb6fa5
					    mouse_press,
Packit Service fb6fa5
					    data);
Packit Service fb6fa5
      g_signal_handlers_disconnect_by_func (invisible,
Packit Service fb6fa5
					    key_press,
Packit Service fb6fa5
					    data);
Packit Service fb6fa5
      
Packit Service fb6fa5
      return TRUE;
Packit Service fb6fa5
Packit Service fb6fa5
#if defined GDK_WINDOWING_X11 || defined GDK_WINDOWING_WIN32
Packit Service fb6fa5
    case GDK_Up:
Packit Service fb6fa5
    case GDK_KP_Up:
Packit Service fb6fa5
      dy = state == GDK_MOD1_MASK ? -BIG_STEP : -1;
Packit Service fb6fa5
      break;
Packit Service fb6fa5
Packit Service fb6fa5
    case GDK_Down:
Packit Service fb6fa5
    case GDK_KP_Down:
Packit Service fb6fa5
      dy = state == GDK_MOD1_MASK ? BIG_STEP : 1;
Packit Service fb6fa5
      break;
Packit Service fb6fa5
Packit Service fb6fa5
    case GDK_Left:
Packit Service fb6fa5
    case GDK_KP_Left:
Packit Service fb6fa5
      dx = state == GDK_MOD1_MASK ? -BIG_STEP : -1;
Packit Service fb6fa5
      break;
Packit Service fb6fa5
Packit Service fb6fa5
    case GDK_Right:
Packit Service fb6fa5
    case GDK_KP_Right:
Packit Service fb6fa5
      dx = state == GDK_MOD1_MASK ? BIG_STEP : 1;
Packit Service fb6fa5
      break;
Packit Service fb6fa5
#endif
Packit Service fb6fa5
Packit Service fb6fa5
    default:
Packit Service fb6fa5
      return FALSE;
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  gdk_display_warp_pointer (display, screen, x + dx, y + dy);
Packit Service fb6fa5
  
Packit Service fb6fa5
  return TRUE;
Packit Service fb6fa5
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static gboolean
Packit Service fb6fa5
mouse_press (GtkWidget      *invisible,
Packit Service fb6fa5
	     GdkEventButton *event,
Packit Service fb6fa5
	     gpointer        data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  /* GtkColorSelection *colorsel = data; */
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (event->type == GDK_BUTTON_PRESS &&
Packit Service fb6fa5
      event->button == 1)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      g_signal_connect (invisible, "motion-notify-event",
Packit Service fb6fa5
                        G_CALLBACK (mouse_motion),
Packit Service fb6fa5
                        data);
Packit Service fb6fa5
      g_signal_connect (invisible, "button-release-event",
Packit Service fb6fa5
                        G_CALLBACK (mouse_release),
Packit Service fb6fa5
                        data);
Packit Service fb6fa5
      g_signal_handlers_disconnect_by_func (invisible,
Packit Service fb6fa5
					    mouse_press,
Packit Service fb6fa5
					    data);
Packit Service fb6fa5
      g_signal_handlers_disconnect_by_func (invisible,
Packit Service fb6fa5
					    key_press,
Packit Service fb6fa5
					    data);
Packit Service fb6fa5
      return TRUE;
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  return FALSE;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/* when the button is clicked */
Packit Service fb6fa5
static void
Packit Service fb6fa5
get_screen_color (GtkWidget *button)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkColorSelection *colorsel = g_object_get_data (G_OBJECT (button), "COLORSEL");
Packit Service fb6fa5
  ColorSelectionPrivate *priv = colorsel->private_data;
Packit Service fb6fa5
  GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (button));
Packit Service fb6fa5
  GdkCursor *picker_cursor;
Packit Service fb6fa5
  GdkGrabStatus grab_status;
Packit Service fb6fa5
  GtkWidget *grab_widget, *toplevel;
Packit Service fb6fa5
Packit Service fb6fa5
  guint32 time = gtk_get_current_event_time ();
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (priv->dropper_grab_widget == NULL)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      grab_widget = gtk_window_new (GTK_WINDOW_POPUP);
Packit Service fb6fa5
      gtk_window_set_screen (GTK_WINDOW (grab_widget), screen);
Packit Service fb6fa5
      gtk_window_resize (GTK_WINDOW (grab_widget), 1, 1);
Packit Service fb6fa5
      gtk_window_move (GTK_WINDOW (grab_widget), -100, -100);
Packit Service fb6fa5
      gtk_widget_show (grab_widget);
Packit Service fb6fa5
Packit Service fb6fa5
      gtk_widget_add_events (grab_widget,
Packit Service fb6fa5
                             GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
Packit Service fb6fa5
      
Packit Service fb6fa5
      toplevel = gtk_widget_get_toplevel (GTK_WIDGET (colorsel));
Packit Service fb6fa5
  
Packit Service fb6fa5
      if (GTK_IS_WINDOW (toplevel))
Packit Service fb6fa5
	{
Packit Service fb6fa5
	  if (GTK_WINDOW (toplevel)->group)
Packit Service fb6fa5
	    gtk_window_group_add_window (GTK_WINDOW (toplevel)->group, 
Packit Service fb6fa5
					 GTK_WINDOW (grab_widget));
Packit Service fb6fa5
	}
Packit Service fb6fa5
Packit Service fb6fa5
      priv->dropper_grab_widget = grab_widget;
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  if (gdk_keyboard_grab (priv->dropper_grab_widget->window,
Packit Service fb6fa5
                         FALSE, time) != GDK_GRAB_SUCCESS)
Packit Service fb6fa5
    return;
Packit Service fb6fa5
  
Packit Service fb6fa5
  picker_cursor = make_picker_cursor (screen);
Packit Service fb6fa5
  grab_status = gdk_pointer_grab (priv->dropper_grab_widget->window,
Packit Service fb6fa5
				  FALSE,
Packit Service fb6fa5
				  GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK,
Packit Service fb6fa5
				  NULL,
Packit Service fb6fa5
				  picker_cursor,
Packit Service fb6fa5
				  time);
Packit Service fb6fa5
  gdk_cursor_unref (picker_cursor);
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (grab_status != GDK_GRAB_SUCCESS)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      gdk_display_keyboard_ungrab (gtk_widget_get_display (button), time);
Packit Service fb6fa5
      return;
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  gtk_grab_add (priv->dropper_grab_widget);
Packit Service fb6fa5
  priv->grab_time = time;
Packit Service fb6fa5
  priv->has_grab = TRUE;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_signal_connect (priv->dropper_grab_widget, "button-press-event",
Packit Service fb6fa5
                    G_CALLBACK (mouse_press), colorsel);
Packit Service fb6fa5
  g_signal_connect (priv->dropper_grab_widget, "key-press-event",
Packit Service fb6fa5
                    G_CALLBACK (key_press), colorsel);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
hex_changed (GtkWidget *hex_entry,
Packit Service fb6fa5
	     gpointer   data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkColorSelection *colorsel;
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  GdkColor color;
Packit Service fb6fa5
  gchar *text;
Packit Service fb6fa5
  
Packit Service fb6fa5
  colorsel = GTK_COLOR_SELECTION (data);
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (priv->changing)
Packit Service fb6fa5
    return;
Packit Service fb6fa5
  
Packit Service fb6fa5
  text = gtk_editable_get_chars (GTK_EDITABLE (priv->hex_entry), 0, -1);
Packit Service fb6fa5
  if (gdk_color_parse (text, &color))
Packit Service fb6fa5
    {
Packit Service fb6fa5
      priv->color[COLORSEL_RED] = CLAMP (color.red/65535.0, 0.0, 1.0);
Packit Service fb6fa5
      priv->color[COLORSEL_GREEN] = CLAMP (color.green/65535.0, 0.0, 1.0);
Packit Service fb6fa5
      priv->color[COLORSEL_BLUE] = CLAMP (color.blue/65535.0, 0.0, 1.0);
Packit Service fb6fa5
      gtk_rgb_to_hsv (priv->color[COLORSEL_RED],
Packit Service fb6fa5
		      priv->color[COLORSEL_GREEN],
Packit Service fb6fa5
		      priv->color[COLORSEL_BLUE],
Packit Service fb6fa5
		      &priv->color[COLORSEL_HUE],
Packit Service fb6fa5
		      &priv->color[COLORSEL_SATURATION],
Packit Service fb6fa5
		      &priv->color[COLORSEL_VALUE]);
Packit Service fb6fa5
      update_color (colorsel);
Packit Service fb6fa5
    }
Packit Service fb6fa5
  g_free (text);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static gboolean
Packit Service fb6fa5
hex_focus_out (GtkWidget     *hex_entry, 
Packit Service fb6fa5
	       GdkEventFocus *event,
Packit Service fb6fa5
	       gpointer       data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  hex_changed (hex_entry, data);
Packit Service fb6fa5
  
Packit Service fb6fa5
  return FALSE;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
hsv_changed (GtkWidget *hsv,
Packit Service fb6fa5
	     gpointer   data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkColorSelection *colorsel;
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  
Packit Service fb6fa5
  colorsel = GTK_COLOR_SELECTION (data);
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (priv->changing)
Packit Service fb6fa5
    return;
Packit Service fb6fa5
  
Packit Service fb6fa5
  gtk_hsv_get_color (GTK_HSV (hsv),
Packit Service fb6fa5
		     &priv->color[COLORSEL_HUE],
Packit Service fb6fa5
		     &priv->color[COLORSEL_SATURATION],
Packit Service fb6fa5
		     &priv->color[COLORSEL_VALUE]);
Packit Service fb6fa5
  gtk_hsv_to_rgb (priv->color[COLORSEL_HUE],
Packit Service fb6fa5
		  priv->color[COLORSEL_SATURATION],
Packit Service fb6fa5
		  priv->color[COLORSEL_VALUE],
Packit Service fb6fa5
		  &priv->color[COLORSEL_RED],
Packit Service fb6fa5
		  &priv->color[COLORSEL_GREEN],
Packit Service fb6fa5
		  &priv->color[COLORSEL_BLUE]);
Packit Service fb6fa5
  update_color (colorsel);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
adjustment_changed (GtkAdjustment *adjustment,
Packit Service fb6fa5
		    gpointer       data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkColorSelection *colorsel;
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  
Packit Service fb6fa5
  colorsel = GTK_COLOR_SELECTION (g_object_get_data (G_OBJECT (adjustment), "COLORSEL"));
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (priv->changing)
Packit Service fb6fa5
    return;
Packit Service fb6fa5
  
Packit Service fb6fa5
  switch (GPOINTER_TO_INT (data))
Packit Service fb6fa5
    {
Packit Service fb6fa5
    case COLORSEL_SATURATION:
Packit Service fb6fa5
    case COLORSEL_VALUE:
Packit Service fb6fa5
      priv->color[GPOINTER_TO_INT (data)] = adjustment->value / 100;
Packit Service fb6fa5
      gtk_hsv_to_rgb (priv->color[COLORSEL_HUE],
Packit Service fb6fa5
		      priv->color[COLORSEL_SATURATION],
Packit Service fb6fa5
		      priv->color[COLORSEL_VALUE],
Packit Service fb6fa5
		      &priv->color[COLORSEL_RED],
Packit Service fb6fa5
		      &priv->color[COLORSEL_GREEN],
Packit Service fb6fa5
		      &priv->color[COLORSEL_BLUE]);
Packit Service fb6fa5
      break;
Packit Service fb6fa5
    case COLORSEL_HUE:
Packit Service fb6fa5
      priv->color[GPOINTER_TO_INT (data)] = adjustment->value / 360;
Packit Service fb6fa5
      gtk_hsv_to_rgb (priv->color[COLORSEL_HUE],
Packit Service fb6fa5
		      priv->color[COLORSEL_SATURATION],
Packit Service fb6fa5
		      priv->color[COLORSEL_VALUE],
Packit Service fb6fa5
		      &priv->color[COLORSEL_RED],
Packit Service fb6fa5
		      &priv->color[COLORSEL_GREEN],
Packit Service fb6fa5
		      &priv->color[COLORSEL_BLUE]);
Packit Service fb6fa5
      break;
Packit Service fb6fa5
    case COLORSEL_RED:
Packit Service fb6fa5
    case COLORSEL_GREEN:
Packit Service fb6fa5
    case COLORSEL_BLUE:
Packit Service fb6fa5
      priv->color[GPOINTER_TO_INT (data)] = adjustment->value / 255;
Packit Service fb6fa5
      
Packit Service fb6fa5
      gtk_rgb_to_hsv (priv->color[COLORSEL_RED],
Packit Service fb6fa5
		      priv->color[COLORSEL_GREEN],
Packit Service fb6fa5
		      priv->color[COLORSEL_BLUE],
Packit Service fb6fa5
		      &priv->color[COLORSEL_HUE],
Packit Service fb6fa5
		      &priv->color[COLORSEL_SATURATION],
Packit Service fb6fa5
		      &priv->color[COLORSEL_VALUE]);
Packit Service fb6fa5
      break;
Packit Service fb6fa5
    default:
Packit Service fb6fa5
      priv->color[GPOINTER_TO_INT (data)] = adjustment->value / 255;
Packit Service fb6fa5
      break;
Packit Service fb6fa5
    }
Packit Service fb6fa5
  update_color (colorsel);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void 
Packit Service fb6fa5
opacity_entry_changed (GtkWidget *opacity_entry,
Packit Service fb6fa5
		       gpointer   data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkColorSelection *colorsel;
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  GtkAdjustment *adj;
Packit Service fb6fa5
  gchar *text;
Packit Service fb6fa5
  
Packit Service fb6fa5
  colorsel = GTK_COLOR_SELECTION (data);
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (priv->changing)
Packit Service fb6fa5
    return;
Packit Service fb6fa5
  
Packit Service fb6fa5
  text = gtk_editable_get_chars (GTK_EDITABLE (priv->opacity_entry), 0, -1);
Packit Service fb6fa5
  adj = gtk_range_get_adjustment (GTK_RANGE (priv->opacity_slider));
Packit Service fb6fa5
  gtk_adjustment_set_value (adj, g_strtod (text, NULL)); 
Packit Service fb6fa5
  
Packit Service fb6fa5
  update_color (colorsel);
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_free (text);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
make_label_spinbutton (GtkColorSelection *colorsel,
Packit Service fb6fa5
		       GtkWidget        **spinbutton,
Packit Service fb6fa5
		       gchar             *text,
Packit Service fb6fa5
		       GtkWidget         *table,
Packit Service fb6fa5
		       gint               i,
Packit Service fb6fa5
		       gint               j,
Packit Service fb6fa5
		       gint               channel_type,
Packit Service fb6fa5
                       const gchar       *tooltip)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkWidget *label;
Packit Service fb6fa5
  GtkAdjustment *adjust;
Packit Service fb6fa5
Packit Service fb6fa5
  if (channel_type == COLORSEL_HUE)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      adjust = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 360.0, 1.0, 1.0, 0.0));
Packit Service fb6fa5
    }
Packit Service fb6fa5
  else if (channel_type == COLORSEL_SATURATION ||
Packit Service fb6fa5
	   channel_type == COLORSEL_VALUE)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      adjust = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 100.0, 1.0, 1.0, 0.0));
Packit Service fb6fa5
    }
Packit Service fb6fa5
  else
Packit Service fb6fa5
    {
Packit Service fb6fa5
      adjust = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 255.0, 1.0, 1.0, 0.0));
Packit Service fb6fa5
    }
Packit Service fb6fa5
  g_object_set_data (G_OBJECT (adjust), I_("COLORSEL"), colorsel);
Packit Service fb6fa5
  *spinbutton = gtk_spin_button_new (adjust, 10.0, 0);
Packit Service fb6fa5
Packit Service fb6fa5
  gtk_widget_set_tooltip_text (*spinbutton, tooltip);  
Packit Service fb6fa5
Packit Service fb6fa5
  g_signal_connect (adjust, "value-changed",
Packit Service fb6fa5
                    G_CALLBACK (adjustment_changed),
Packit Service fb6fa5
                    GINT_TO_POINTER (channel_type));
Packit Service fb6fa5
  label = gtk_label_new_with_mnemonic (text);
Packit Service fb6fa5
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), *spinbutton);
Packit Service fb6fa5
Packit Service fb6fa5
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
Packit Service fb6fa5
  gtk_table_attach_defaults (GTK_TABLE (table), label, i, i+1, j, j+1);
Packit Service fb6fa5
  gtk_table_attach_defaults (GTK_TABLE (table), *spinbutton, i+1, i+2, j, j+1);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
make_palette_frame (GtkColorSelection *colorsel,
Packit Service fb6fa5
		    GtkWidget         *table,
Packit Service fb6fa5
		    gint               i,
Packit Service fb6fa5
		    gint               j)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkWidget *frame;
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  frame = gtk_frame_new (NULL);
Packit Service fb6fa5
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
Packit Service fb6fa5
  priv->custom_palette[i][j] = palette_new (colorsel);
Packit Service fb6fa5
  gtk_widget_set_size_request (priv->custom_palette[i][j], CUSTOM_PALETTE_ENTRY_WIDTH, CUSTOM_PALETTE_ENTRY_HEIGHT);
Packit Service fb6fa5
  gtk_container_add (GTK_CONTAINER (frame), priv->custom_palette[i][j]);
Packit Service fb6fa5
  gtk_table_attach_defaults (GTK_TABLE (table), frame, i, i+1, j, j+1);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/* Set the palette entry [x][y] to be the currently selected one. */
Packit Service fb6fa5
static void 
Packit Service fb6fa5
set_selected_palette (GtkColorSelection *colorsel, int x, int y)
Packit Service fb6fa5
{
Packit Service fb6fa5
  ColorSelectionPrivate *priv = colorsel->private_data; 
Packit Service fb6fa5
Packit Service fb6fa5
  gtk_widget_grab_focus (priv->custom_palette[x][y]);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static double
Packit Service fb6fa5
scale_round (double val, double factor)
Packit Service fb6fa5
{
Packit Service fb6fa5
  val = floor (val * factor + 0.5);
Packit Service fb6fa5
  val = MAX (val, 0);
Packit Service fb6fa5
  val = MIN (val, factor);
Packit Service fb6fa5
  return val;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
update_color (GtkColorSelection *colorsel)
Packit Service fb6fa5
{
Packit Service fb6fa5
  ColorSelectionPrivate *priv = colorsel->private_data;
Packit Service fb6fa5
  gchar entryval[12];
Packit Service fb6fa5
  gchar opacity_text[32];
Packit Service fb6fa5
  gchar *ptr;
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv->changing = TRUE;
Packit Service fb6fa5
  color_sample_update_samples (colorsel);
Packit Service fb6fa5
  
Packit Service fb6fa5
  gtk_hsv_set_color (GTK_HSV (priv->triangle_colorsel),
Packit Service fb6fa5
		     priv->color[COLORSEL_HUE],
Packit Service fb6fa5
		     priv->color[COLORSEL_SATURATION],
Packit Service fb6fa5
		     priv->color[COLORSEL_VALUE]);
Packit Service fb6fa5
  gtk_adjustment_set_value (gtk_spin_button_get_adjustment
Packit Service fb6fa5
			    (GTK_SPIN_BUTTON (priv->hue_spinbutton)),
Packit Service fb6fa5
			    scale_round (priv->color[COLORSEL_HUE], 360));
Packit Service fb6fa5
  gtk_adjustment_set_value (gtk_spin_button_get_adjustment
Packit Service fb6fa5
			    (GTK_SPIN_BUTTON (priv->sat_spinbutton)),
Packit Service fb6fa5
			    scale_round (priv->color[COLORSEL_SATURATION], 100));
Packit Service fb6fa5
  gtk_adjustment_set_value (gtk_spin_button_get_adjustment
Packit Service fb6fa5
			    (GTK_SPIN_BUTTON (priv->val_spinbutton)),
Packit Service fb6fa5
			    scale_round (priv->color[COLORSEL_VALUE], 100));
Packit Service fb6fa5
  gtk_adjustment_set_value (gtk_spin_button_get_adjustment
Packit Service fb6fa5
			    (GTK_SPIN_BUTTON (priv->red_spinbutton)),
Packit Service fb6fa5
			    scale_round (priv->color[COLORSEL_RED], 255));
Packit Service fb6fa5
  gtk_adjustment_set_value (gtk_spin_button_get_adjustment
Packit Service fb6fa5
			    (GTK_SPIN_BUTTON (priv->green_spinbutton)),
Packit Service fb6fa5
			    scale_round (priv->color[COLORSEL_GREEN], 255));
Packit Service fb6fa5
  gtk_adjustment_set_value (gtk_spin_button_get_adjustment
Packit Service fb6fa5
			    (GTK_SPIN_BUTTON (priv->blue_spinbutton)),
Packit Service fb6fa5
			    scale_round (priv->color[COLORSEL_BLUE], 255));
Packit Service fb6fa5
  gtk_adjustment_set_value (gtk_range_get_adjustment
Packit Service fb6fa5
			    (GTK_RANGE (priv->opacity_slider)),
Packit Service fb6fa5
			    scale_round (priv->color[COLORSEL_OPACITY], 255));
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_snprintf (opacity_text, 32, "%.0f", scale_round (priv->color[COLORSEL_OPACITY], 255));
Packit Service fb6fa5
  gtk_entry_set_text (GTK_ENTRY (priv->opacity_entry), opacity_text);
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_snprintf (entryval, 11, "#%2X%2X%2X",
Packit Service fb6fa5
	      (guint) (scale_round (priv->color[COLORSEL_RED], 255)),
Packit Service fb6fa5
	      (guint) (scale_round (priv->color[COLORSEL_GREEN], 255)),
Packit Service fb6fa5
	      (guint) (scale_round (priv->color[COLORSEL_BLUE], 255)));
Packit Service fb6fa5
  
Packit Service fb6fa5
  for (ptr = entryval; *ptr; ptr++)
Packit Service fb6fa5
    if (*ptr == ' ')
Packit Service fb6fa5
      *ptr = '0';
Packit Service fb6fa5
  gtk_entry_set_text (GTK_ENTRY (priv->hex_entry), entryval);
Packit Service fb6fa5
  priv->changing = FALSE;
Packit Service fb6fa5
Packit Service fb6fa5
  g_object_ref (colorsel);
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_signal_emit (colorsel, color_selection_signals[COLOR_CHANGED], 0);
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_object_freeze_notify (G_OBJECT (colorsel));
Packit Service fb6fa5
  g_object_notify (G_OBJECT (colorsel), "current-color");
Packit Service fb6fa5
  g_object_notify (G_OBJECT (colorsel), "current-alpha");
Packit Service fb6fa5
  g_object_thaw_notify (G_OBJECT (colorsel));
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_object_unref (colorsel);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
update_palette (GtkColorSelection *colorsel)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GdkColor *current_colors;
Packit Service fb6fa5
  gint i, j;
Packit Service fb6fa5
Packit Service fb6fa5
  current_colors = get_current_colors (colorsel);
Packit Service fb6fa5
  
Packit Service fb6fa5
  for (i = 0; i < GTK_CUSTOM_PALETTE_HEIGHT; i++)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      for (j = 0; j < GTK_CUSTOM_PALETTE_WIDTH; j++)
Packit Service fb6fa5
	{
Packit Service fb6fa5
          gint index;
Packit Service fb6fa5
Packit Service fb6fa5
          index = i * GTK_CUSTOM_PALETTE_WIDTH + j;
Packit Service fb6fa5
          
Packit Service fb6fa5
          gtk_color_selection_set_palette_color (colorsel,
Packit Service fb6fa5
                                                 index,
Packit Service fb6fa5
                                                 &current_colors[index]);
Packit Service fb6fa5
	}
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  g_free (current_colors);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
palette_change_notify_instance (GObject    *object,
Packit Service fb6fa5
                                GParamSpec *pspec,
Packit Service fb6fa5
                                gpointer    data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  update_palette (GTK_COLOR_SELECTION (data));
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
default_noscreen_change_palette_func (const GdkColor *colors,
Packit Service fb6fa5
				      gint            n_colors)
Packit Service fb6fa5
{
Packit Service fb6fa5
  default_change_palette_func (gdk_screen_get_default (), colors, n_colors);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
default_change_palette_func (GdkScreen	    *screen,
Packit Service fb6fa5
			     const GdkColor *colors,
Packit Service fb6fa5
                             gint            n_colors)
Packit Service fb6fa5
{
Packit Service fb6fa5
  gchar *str;
Packit Service fb6fa5
  
Packit Service fb6fa5
  str = gtk_color_selection_palette_to_string (colors, n_colors);
Packit Service fb6fa5
Packit Service fb6fa5
  gtk_settings_set_string_property (gtk_settings_get_for_screen (screen),
Packit Service fb6fa5
                                    "gtk-color-palette",
Packit Service fb6fa5
                                    str,
Packit Service fb6fa5
                                    "gtk_color_selection_palette_to_string");
Packit Service fb6fa5
Packit Service fb6fa5
  g_free (str);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_color_selection_new:
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Creates a new GtkColorSelection.
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Return value: a new #GtkColorSelection
Packit Service fb6fa5
 **/
Packit Service fb6fa5
GtkWidget *
Packit Service fb6fa5
gtk_color_selection_new (void)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkColorSelection *colorsel;
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  gdouble color[4];
Packit Service fb6fa5
  color[0] = 1.0;
Packit Service fb6fa5
  color[1] = 1.0;
Packit Service fb6fa5
  color[2] = 1.0;
Packit Service fb6fa5
  color[3] = 1.0;
Packit Service fb6fa5
  
Packit Service fb6fa5
  colorsel = g_object_new (GTK_TYPE_COLOR_SELECTION, NULL);
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  set_color_internal (colorsel, color);
Packit Service fb6fa5
  gtk_color_selection_set_has_opacity_control (colorsel, TRUE);
Packit Service fb6fa5
  
Packit Service fb6fa5
  /* We want to make sure that default_set is FALSE */
Packit Service fb6fa5
  /* This way the user can still set it */
Packit Service fb6fa5
  priv->default_set = FALSE;
Packit Service fb6fa5
  priv->default_alpha_set = FALSE;
Packit Service fb6fa5
  
Packit Service fb6fa5
  return GTK_WIDGET (colorsel);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_color_selection_set_update_policy (GtkColorSelection *colorsel,
Packit Service fb6fa5
				       GtkUpdateType      policy)
Packit Service fb6fa5
{
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_color_selection_get_has_opacity_control:
Packit Service fb6fa5
 * @colorsel: a #GtkColorSelection.
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Determines whether the colorsel has an opacity control.
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Return value: %TRUE if the @colorsel has an opacity control.  %FALSE if it does't.
Packit Service fb6fa5
 **/
Packit Service fb6fa5
gboolean
Packit Service fb6fa5
gtk_color_selection_get_has_opacity_control (GtkColorSelection *colorsel)
Packit Service fb6fa5
{
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_val_if_fail (GTK_IS_COLOR_SELECTION (colorsel), FALSE);
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  
Packit Service fb6fa5
  return priv->has_opacity;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_color_selection_set_has_opacity_control:
Packit Service fb6fa5
 * @colorsel: a #GtkColorSelection.
Packit Service fb6fa5
 * @has_opacity: %TRUE if @colorsel can set the opacity, %FALSE otherwise.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Sets the @colorsel to use or not use opacity.
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 **/
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_color_selection_set_has_opacity_control (GtkColorSelection *colorsel,
Packit Service fb6fa5
					     gboolean           has_opacity)
Packit Service fb6fa5
{
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  has_opacity = has_opacity != FALSE;
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (priv->has_opacity != has_opacity)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      priv->has_opacity = has_opacity;
Packit Service fb6fa5
      if (has_opacity)
Packit Service fb6fa5
	{
Packit Service fb6fa5
	  gtk_widget_show (priv->opacity_slider);
Packit Service fb6fa5
	  gtk_widget_show (priv->opacity_label);
Packit Service fb6fa5
	  gtk_widget_show (priv->opacity_entry);
Packit Service fb6fa5
	}
Packit Service fb6fa5
      else
Packit Service fb6fa5
	{
Packit Service fb6fa5
	  gtk_widget_hide (priv->opacity_slider);
Packit Service fb6fa5
	  gtk_widget_hide (priv->opacity_label);
Packit Service fb6fa5
	  gtk_widget_hide (priv->opacity_entry);
Packit Service fb6fa5
	}
Packit Service fb6fa5
      color_sample_update_samples (colorsel);
Packit Service fb6fa5
      
Packit Service fb6fa5
      g_object_notify (G_OBJECT (colorsel), "has-opacity-control");
Packit Service fb6fa5
    }
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_color_selection_get_has_palette:
Packit Service fb6fa5
 * @colorsel: a #GtkColorSelection.
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Determines whether the color selector has a color palette.
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Return value: %TRUE if the selector has a palette.  %FALSE if it hasn't.
Packit Service fb6fa5
 **/
Packit Service fb6fa5
gboolean
Packit Service fb6fa5
gtk_color_selection_get_has_palette (GtkColorSelection *colorsel)
Packit Service fb6fa5
{
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_val_if_fail (GTK_IS_COLOR_SELECTION (colorsel), FALSE);
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  
Packit Service fb6fa5
  return priv->has_palette;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_color_selection_set_has_palette:
Packit Service fb6fa5
 * @colorsel: a #GtkColorSelection.
Packit Service fb6fa5
 * @has_palette: %TRUE if palette is to be visible, %FALSE otherwise.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Shows and hides the palette based upon the value of @has_palette.
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 **/
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_color_selection_set_has_palette (GtkColorSelection *colorsel,
Packit Service fb6fa5
				     gboolean           has_palette)
Packit Service fb6fa5
{
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  has_palette = has_palette != FALSE;
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (priv->has_palette != has_palette)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      priv->has_palette = has_palette;
Packit Service fb6fa5
      if (has_palette)
Packit Service fb6fa5
	gtk_widget_show (priv->palette_frame);
Packit Service fb6fa5
      else
Packit Service fb6fa5
	gtk_widget_hide (priv->palette_frame);
Packit Service fb6fa5
Packit Service fb6fa5
      update_tooltips (colorsel);
Packit Service fb6fa5
Packit Service fb6fa5
      g_object_notify (G_OBJECT (colorsel), "has-palette");
Packit Service fb6fa5
    }
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_color_selection_set_current_color:
Packit Service fb6fa5
 * @colorsel: a #GtkColorSelection.
Packit Service fb6fa5
 * @color: A #GdkColor to set the current color with.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Sets the current color to be @color.  The first time this is called, it will
Packit Service fb6fa5
 * also set the original color to be @color too.
Packit Service fb6fa5
 **/
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_color_selection_set_current_color (GtkColorSelection *colorsel,
Packit Service fb6fa5
				       const GdkColor    *color)
Packit Service fb6fa5
{
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  gint i;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
Packit Service fb6fa5
  g_return_if_fail (color != NULL);
Packit Service fb6fa5
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  priv->changing = TRUE;
Packit Service fb6fa5
  priv->color[COLORSEL_RED] = SCALE (color->red);
Packit Service fb6fa5
  priv->color[COLORSEL_GREEN] = SCALE (color->green);
Packit Service fb6fa5
  priv->color[COLORSEL_BLUE] = SCALE (color->blue);
Packit Service fb6fa5
  gtk_rgb_to_hsv (priv->color[COLORSEL_RED],
Packit Service fb6fa5
		  priv->color[COLORSEL_GREEN],
Packit Service fb6fa5
		  priv->color[COLORSEL_BLUE],
Packit Service fb6fa5
		  &priv->color[COLORSEL_HUE],
Packit Service fb6fa5
		  &priv->color[COLORSEL_SATURATION],
Packit Service fb6fa5
		  &priv->color[COLORSEL_VALUE]);
Packit Service fb6fa5
  if (priv->default_set == FALSE)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      for (i = 0; i < COLORSEL_NUM_CHANNELS; i++)
Packit Service fb6fa5
	priv->old_color[i] = priv->color[i];
Packit Service fb6fa5
    }
Packit Service fb6fa5
  priv->default_set = TRUE;
Packit Service fb6fa5
  update_color (colorsel);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_color_selection_set_current_alpha:
Packit Service fb6fa5
 * @colorsel: a #GtkColorSelection.
Packit Service fb6fa5
 * @alpha: an integer between 0 and 65535.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Sets the current opacity to be @alpha.  The first time this is called, it will
Packit Service fb6fa5
 * also set the original opacity to be @alpha too.
Packit Service fb6fa5
 **/
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_color_selection_set_current_alpha (GtkColorSelection *colorsel,
Packit Service fb6fa5
				       guint16            alpha)
Packit Service fb6fa5
{
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  gint i;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  priv->changing = TRUE;
Packit Service fb6fa5
  priv->color[COLORSEL_OPACITY] = SCALE (alpha);
Packit Service fb6fa5
  if (priv->default_alpha_set == FALSE)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      for (i = 0; i < COLORSEL_NUM_CHANNELS; i++)
Packit Service fb6fa5
	priv->old_color[i] = priv->color[i];
Packit Service fb6fa5
    }
Packit Service fb6fa5
  priv->default_alpha_set = TRUE;
Packit Service fb6fa5
  update_color (colorsel);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_color_selection_set_color:
Packit Service fb6fa5
 * @colorsel: a #GtkColorSelection.
Packit Service fb6fa5
 * @color: an array of 4 doubles specifying the red, green, blue and opacity 
Packit Service fb6fa5
 *   to set the current color to.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Sets the current color to be @color.  The first time this is called, it will
Packit Service fb6fa5
 * also set the original color to be @color too.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Deprecated: 2.0: Use gtk_color_selection_set_current_color() instead.
Packit Service fb6fa5
 **/
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_color_selection_set_color (GtkColorSelection    *colorsel,
Packit Service fb6fa5
			       gdouble              *color)
Packit Service fb6fa5
{
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
Packit Service fb6fa5
Packit Service fb6fa5
  set_color_internal (colorsel, color);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_color_selection_get_current_color:
Packit Service fb6fa5
 * @colorsel: a #GtkColorSelection.
Packit Service fb6fa5
 * @color: (out): a #GdkColor to fill in with the current color.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Sets @color to be the current color in the GtkColorSelection widget.
Packit Service fb6fa5
 **/
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_color_selection_get_current_color (GtkColorSelection *colorsel,
Packit Service fb6fa5
				       GdkColor          *color)
Packit Service fb6fa5
{
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
Packit Service fb6fa5
  g_return_if_fail (color != NULL);
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  color->red = UNSCALE (priv->color[COLORSEL_RED]);
Packit Service fb6fa5
  color->green = UNSCALE (priv->color[COLORSEL_GREEN]);
Packit Service fb6fa5
  color->blue = UNSCALE (priv->color[COLORSEL_BLUE]);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_color_selection_get_current_alpha:
Packit Service fb6fa5
 * @colorsel: a #GtkColorSelection.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Returns the current alpha value.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: an integer between 0 and 65535.
Packit Service fb6fa5
 **/
Packit Service fb6fa5
guint16
Packit Service fb6fa5
gtk_color_selection_get_current_alpha (GtkColorSelection *colorsel)
Packit Service fb6fa5
{
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_val_if_fail (GTK_IS_COLOR_SELECTION (colorsel), 0);
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  return priv->has_opacity ? UNSCALE (priv->color[COLORSEL_OPACITY]) : 65535;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_color_selection_get_color:
Packit Service fb6fa5
 * @colorsel: a #GtkColorSelection.
Packit Service fb6fa5
 * @color: an array of 4 #gdouble to fill in with the current color.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Sets @color to be the current color in the GtkColorSelection widget.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Deprecated: 2.0: Use gtk_color_selection_get_current_color() instead.
Packit Service fb6fa5
 **/
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_color_selection_get_color (GtkColorSelection *colorsel,
Packit Service fb6fa5
			       gdouble           *color)
Packit Service fb6fa5
{
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  color[0] = priv->color[COLORSEL_RED];
Packit Service fb6fa5
  color[1] = priv->color[COLORSEL_GREEN];
Packit Service fb6fa5
  color[2] = priv->color[COLORSEL_BLUE];
Packit Service fb6fa5
  color[3] = priv->has_opacity ? priv->color[COLORSEL_OPACITY] : 65535;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_color_selection_set_previous_color:
Packit Service fb6fa5
 * @colorsel: a #GtkColorSelection.
Packit Service fb6fa5
 * @color: a #GdkColor to set the previous color with.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Sets the 'previous' color to be @color.  This function should be called with
Packit Service fb6fa5
 * some hesitations, as it might seem confusing to have that color change.
Packit Service fb6fa5
 * Calling gtk_color_selection_set_current_color() will also set this color the first
Packit Service fb6fa5
 * time it is called.
Packit Service fb6fa5
 **/
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_color_selection_set_previous_color (GtkColorSelection *colorsel,
Packit Service fb6fa5
					const GdkColor    *color)
Packit Service fb6fa5
{
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
Packit Service fb6fa5
  g_return_if_fail (color != NULL);
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  priv->changing = TRUE;
Packit Service fb6fa5
  priv->old_color[COLORSEL_RED] = SCALE (color->red);
Packit Service fb6fa5
  priv->old_color[COLORSEL_GREEN] = SCALE (color->green);
Packit Service fb6fa5
  priv->old_color[COLORSEL_BLUE] = SCALE (color->blue);
Packit Service fb6fa5
  gtk_rgb_to_hsv (priv->old_color[COLORSEL_RED],
Packit Service fb6fa5
		  priv->old_color[COLORSEL_GREEN],
Packit Service fb6fa5
		  priv->old_color[COLORSEL_BLUE],
Packit Service fb6fa5
		  &priv->old_color[COLORSEL_HUE],
Packit Service fb6fa5
		  &priv->old_color[COLORSEL_SATURATION],
Packit Service fb6fa5
		  &priv->old_color[COLORSEL_VALUE]);
Packit Service fb6fa5
  color_sample_update_samples (colorsel);
Packit Service fb6fa5
  priv->default_set = TRUE;
Packit Service fb6fa5
  priv->changing = FALSE;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_color_selection_set_previous_alpha:
Packit Service fb6fa5
 * @colorsel: a #GtkColorSelection.
Packit Service fb6fa5
 * @alpha: an integer between 0 and 65535.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Sets the 'previous' alpha to be @alpha.  This function should be called with
Packit Service fb6fa5
 * some hesitations, as it might seem confusing to have that alpha change.
Packit Service fb6fa5
 **/
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_color_selection_set_previous_alpha (GtkColorSelection *colorsel,
Packit Service fb6fa5
					guint16            alpha)
Packit Service fb6fa5
{
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  priv->changing = TRUE;
Packit Service fb6fa5
  priv->old_color[COLORSEL_OPACITY] = SCALE (alpha);
Packit Service fb6fa5
  color_sample_update_samples (colorsel);
Packit Service fb6fa5
  priv->default_alpha_set = TRUE;
Packit Service fb6fa5
  priv->changing = FALSE;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_color_selection_get_previous_color:
Packit Service fb6fa5
 * @colorsel: a #GtkColorSelection.
Packit Service fb6fa5
 * @color: (out): a #GdkColor to fill in with the original color value.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Fills @color in with the original color value.
Packit Service fb6fa5
 **/
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_color_selection_get_previous_color (GtkColorSelection *colorsel,
Packit Service fb6fa5
					GdkColor           *color)
Packit Service fb6fa5
{
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
Packit Service fb6fa5
  g_return_if_fail (color != NULL);
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  color->red = UNSCALE (priv->old_color[COLORSEL_RED]);
Packit Service fb6fa5
  color->green = UNSCALE (priv->old_color[COLORSEL_GREEN]);
Packit Service fb6fa5
  color->blue = UNSCALE (priv->old_color[COLORSEL_BLUE]);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_color_selection_get_previous_alpha:
Packit Service fb6fa5
 * @colorsel: a #GtkColorSelection.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Returns the previous alpha value.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: an integer between 0 and 65535.
Packit Service fb6fa5
 **/
Packit Service fb6fa5
guint16
Packit Service fb6fa5
gtk_color_selection_get_previous_alpha (GtkColorSelection *colorsel)
Packit Service fb6fa5
{
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_val_if_fail (GTK_IS_COLOR_SELECTION (colorsel), 0);
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  return priv->has_opacity ? UNSCALE (priv->old_color[COLORSEL_OPACITY]) : 65535;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_color_selection_set_palette_color:
Packit Service fb6fa5
 * @colorsel: a #GtkColorSelection.
Packit Service fb6fa5
 * @index: the color index of the palette.
Packit Service fb6fa5
 * @color: A #GdkColor to set the palette with.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Sets the palette located at @index to have @color as its color.
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 **/
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_color_selection_set_palette_color (GtkColorSelection   *colorsel,
Packit Service fb6fa5
				       gint                 index,
Packit Service fb6fa5
				       GdkColor            *color)
Packit Service fb6fa5
{
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  gint x, y;
Packit Service fb6fa5
  gdouble col[3];
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
Packit Service fb6fa5
  g_return_if_fail (index >= 0  && index < GTK_CUSTOM_PALETTE_WIDTH*GTK_CUSTOM_PALETTE_HEIGHT);
Packit Service fb6fa5
Packit Service fb6fa5
  x = index % GTK_CUSTOM_PALETTE_WIDTH;
Packit Service fb6fa5
  y = index / GTK_CUSTOM_PALETTE_WIDTH;
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  col[0] = SCALE (color->red);
Packit Service fb6fa5
  col[1] = SCALE (color->green);
Packit Service fb6fa5
  col[2] = SCALE (color->blue);
Packit Service fb6fa5
  
Packit Service fb6fa5
  palette_set_color (priv->custom_palette[x][y], colorsel, col);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_color_selection_is_adjusting:
Packit Service fb6fa5
 * @colorsel: a #GtkColorSelection.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Gets the current state of the @colorsel.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: %TRUE if the user is currently dragging a color around, and %FALSE
Packit Service fb6fa5
 * if the selection has stopped.
Packit Service fb6fa5
 **/
Packit Service fb6fa5
gboolean
Packit Service fb6fa5
gtk_color_selection_is_adjusting (GtkColorSelection *colorsel)
Packit Service fb6fa5
{
Packit Service fb6fa5
  ColorSelectionPrivate *priv;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_val_if_fail (GTK_IS_COLOR_SELECTION (colorsel), FALSE);
Packit Service fb6fa5
  
Packit Service fb6fa5
  priv = colorsel->private_data;
Packit Service fb6fa5
  
Packit Service fb6fa5
  return (gtk_hsv_is_adjusting (GTK_HSV (priv->triangle_colorsel)));
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_color_selection_palette_from_string:
Packit Service fb6fa5
 * @str: a string encoding a color palette.
Packit Service fb6fa5
 * @colors: (out) (array length=n_colors): return location for allocated
Packit Service fb6fa5
 *          array of #GdkColor.
Packit Service fb6fa5
 * @n_colors: return location for length of array.
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Parses a color palette string; the string is a colon-separated
Packit Service fb6fa5
 * list of color names readable by gdk_color_parse().
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Return value: %TRUE if a palette was successfully parsed.
Packit Service fb6fa5
 **/
Packit Service fb6fa5
gboolean
Packit Service fb6fa5
gtk_color_selection_palette_from_string (const gchar *str,
Packit Service fb6fa5
                                         GdkColor   **colors,
Packit Service fb6fa5
                                         gint        *n_colors)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GdkColor *retval;
Packit Service fb6fa5
  gint count;
Packit Service fb6fa5
  gchar *p;
Packit Service fb6fa5
  gchar *start;
Packit Service fb6fa5
  gchar *copy;
Packit Service fb6fa5
  
Packit Service fb6fa5
  count = 0;
Packit Service fb6fa5
  retval = NULL;
Packit Service fb6fa5
  copy = g_strdup (str);
Packit Service fb6fa5
Packit Service fb6fa5
  start = copy;
Packit Service fb6fa5
  p = copy;
Packit Service fb6fa5
  while (TRUE)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      if (*p == ':' || *p == '\0')
Packit Service fb6fa5
        {
Packit Service fb6fa5
          gboolean done = TRUE;
Packit Service fb6fa5
Packit Service fb6fa5
          if (start == p)
Packit Service fb6fa5
            {
Packit Service fb6fa5
              goto failed; /* empty entry */
Packit Service fb6fa5
            }
Packit Service fb6fa5
              
Packit Service fb6fa5
          if (*p)
Packit Service fb6fa5
            {
Packit Service fb6fa5
              *p = '\0';
Packit Service fb6fa5
              done = FALSE;
Packit Service fb6fa5
            }
Packit Service fb6fa5
Packit Service fb6fa5
          retval = g_renew (GdkColor, retval, count + 1);
Packit Service fb6fa5
          if (!gdk_color_parse (start, retval + count))
Packit Service fb6fa5
            {
Packit Service fb6fa5
              goto failed;
Packit Service fb6fa5
            }
Packit Service fb6fa5
Packit Service fb6fa5
          ++count;
Packit Service fb6fa5
Packit Service fb6fa5
          if (done)
Packit Service fb6fa5
            break;
Packit Service fb6fa5
          else
Packit Service fb6fa5
            start = p + 1;
Packit Service fb6fa5
        }
Packit Service fb6fa5
Packit Service fb6fa5
      ++p;
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  g_free (copy);
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (colors)
Packit Service fb6fa5
    *colors = retval;
Packit Service fb6fa5
  else
Packit Service fb6fa5
    g_free (retval);
Packit Service fb6fa5
Packit Service fb6fa5
  if (n_colors)
Packit Service fb6fa5
    *n_colors = count;
Packit Service fb6fa5
Packit Service fb6fa5
  return TRUE;
Packit Service fb6fa5
  
Packit Service fb6fa5
 failed:
Packit Service fb6fa5
  g_free (copy);
Packit Service fb6fa5
  g_free (retval);
Packit Service fb6fa5
Packit Service fb6fa5
  if (colors)
Packit Service fb6fa5
    *colors = NULL;
Packit Service fb6fa5
  if (n_colors)
Packit Service fb6fa5
    *n_colors = 0;
Packit Service fb6fa5
Packit Service fb6fa5
  return FALSE;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_color_selection_palette_to_string:
Packit Service fb6fa5
 * @colors: (array length=n_colors): an array of colors.
Packit Service fb6fa5
 * @n_colors: length of the array.
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Encodes a palette as a string, useful for persistent storage.
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Return value: allocated string encoding the palette.
Packit Service fb6fa5
 **/
Packit Service fb6fa5
gchar*
Packit Service fb6fa5
gtk_color_selection_palette_to_string (const GdkColor *colors,
Packit Service fb6fa5
                                       gint            n_colors)
Packit Service fb6fa5
{
Packit Service fb6fa5
  gint i;
Packit Service fb6fa5
  gchar **strs = NULL;
Packit Service fb6fa5
  gchar *retval;
Packit Service fb6fa5
  
Packit Service fb6fa5
  if (n_colors == 0)
Packit Service fb6fa5
    return g_strdup ("");
Packit Service fb6fa5
Packit Service fb6fa5
  strs = g_new0 (gchar*, n_colors + 1);
Packit Service fb6fa5
Packit Service fb6fa5
  i = 0;
Packit Service fb6fa5
  while (i < n_colors)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      gchar *ptr;
Packit Service fb6fa5
      
Packit Service fb6fa5
      strs[i] =
Packit Service fb6fa5
        g_strdup_printf ("#%2X%2X%2X",
Packit Service fb6fa5
                         colors[i].red / 256,
Packit Service fb6fa5
                         colors[i].green / 256,
Packit Service fb6fa5
                         colors[i].blue / 256);
Packit Service fb6fa5
Packit Service fb6fa5
      for (ptr = strs[i]; *ptr; ptr++)
Packit Service fb6fa5
        if (*ptr == ' ')
Packit Service fb6fa5
          *ptr = '0';
Packit Service fb6fa5
      
Packit Service fb6fa5
      ++i;
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  retval = g_strjoinv (":", strs);
Packit Service fb6fa5
Packit Service fb6fa5
  g_strfreev (strs);
Packit Service fb6fa5
Packit Service fb6fa5
  return retval;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_color_selection_set_change_palette_hook:
Packit Service fb6fa5
 * @func: a function to call when the custom palette needs saving.
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Installs a global function to be called whenever the user tries to
Packit Service fb6fa5
 * modify the palette in a color selection. This function should save
Packit Service fb6fa5
 * the new palette contents, and update the GtkSettings property
Packit Service fb6fa5
 * "gtk-color-palette" so all GtkColorSelection widgets will be modified.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: the previous change palette hook (that was replaced).
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Deprecated: 2.4: This function does not work in multihead environments.
Packit Service fb6fa5
 *     Use gtk_color_selection_set_change_palette_with_screen_hook() instead. 
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 **/
Packit Service fb6fa5
GtkColorSelectionChangePaletteFunc
Packit Service fb6fa5
gtk_color_selection_set_change_palette_hook (GtkColorSelectionChangePaletteFunc func)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkColorSelectionChangePaletteFunc old;
Packit Service fb6fa5
Packit Service fb6fa5
  old = noscreen_change_palette_hook;
Packit Service fb6fa5
Packit Service fb6fa5
  noscreen_change_palette_hook = func;
Packit Service fb6fa5
Packit Service fb6fa5
  return old;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_color_selection_set_change_palette_with_screen_hook:
Packit Service fb6fa5
 * @func: a function to call when the custom palette needs saving.
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Installs a global function to be called whenever the user tries to
Packit Service fb6fa5
 * modify the palette in a color selection. This function should save
Packit Service fb6fa5
 * the new palette contents, and update the GtkSettings property
Packit Service fb6fa5
 * "gtk-color-palette" so all GtkColorSelection widgets will be modified.
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Return value: the previous change palette hook (that was replaced).
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.2
Packit Service fb6fa5
 **/
Packit Service fb6fa5
GtkColorSelectionChangePaletteWithScreenFunc
Packit Service fb6fa5
gtk_color_selection_set_change_palette_with_screen_hook (GtkColorSelectionChangePaletteWithScreenFunc func)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkColorSelectionChangePaletteWithScreenFunc old;
Packit Service fb6fa5
Packit Service fb6fa5
  old = change_palette_hook;
Packit Service fb6fa5
Packit Service fb6fa5
  change_palette_hook = func;
Packit Service fb6fa5
Packit Service fb6fa5
  return old;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
make_control_relations (AtkObject *atk_obj,
Packit Service fb6fa5
                        GtkWidget *widget)
Packit Service fb6fa5
{
Packit Service fb6fa5
  AtkObject *obj;
Packit Service fb6fa5
Packit Service fb6fa5
  obj = gtk_widget_get_accessible (widget);
Packit Service fb6fa5
  atk_object_add_relationship (atk_obj, ATK_RELATION_CONTROLLED_BY, obj);
Packit Service fb6fa5
  atk_object_add_relationship (obj, ATK_RELATION_CONTROLLER_FOR, atk_obj);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
make_all_relations (AtkObject *atk_obj,
Packit Service fb6fa5
                    ColorSelectionPrivate *priv)
Packit Service fb6fa5
{
Packit Service fb6fa5
  make_control_relations (atk_obj, priv->hue_spinbutton);
Packit Service fb6fa5
  make_control_relations (atk_obj, priv->sat_spinbutton);
Packit Service fb6fa5
  make_control_relations (atk_obj, priv->val_spinbutton);
Packit Service fb6fa5
  make_control_relations (atk_obj, priv->red_spinbutton);
Packit Service fb6fa5
  make_control_relations (atk_obj, priv->green_spinbutton);
Packit Service fb6fa5
  make_control_relations (atk_obj, priv->blue_spinbutton);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
#define __GTK_COLOR_SELECTION_C__
Packit Service fb6fa5
#include "gtkaliasdef.c"
Packit Service fb6fa5